Skip to content

Commit beca9dd

Browse files
authored
Merge pull request #43 from fabrix-app/v1.6
chore(): adds additional types
2 parents 8199198 + f74e0f4 commit beca9dd

24 files changed

+332
-268
lines changed

.circleci/config.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ jobs:
3232
command: npm test
3333
- run:
3434
name: test performance
35-
command: npm run test-performance
35+
command: npm run test:performance
3636
- run:
3737
name: test archetype
38-
command: npm run test-archetype
38+
command: npm run test:archetype
3939
- run:
4040
name: code-coverage
4141
command: './node_modules/.bin/nyc report --reporter=text-lcov'
@@ -88,10 +88,10 @@ jobs:
8888
command: npm test
8989
- run:
9090
name: test performance
91-
command: npm run test-performance
91+
command: npm run test:performance
9292
- run:
9393
name: test archetype
94-
command: npm run test-archetype
94+
command: npm run test:archetype
9595
- run:
9696
name: code-coverage
9797
command: './node_modules/.bin/nyc report --reporter=text-lcov'

lib/Configuration.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,14 @@ export class Configuration extends Map<any, any> {
240240
/**
241241
* Prevent changes to the app configuration
242242
*/
243-
freeze () {
243+
freeze (): void {
244244
this.immutable = true
245245
}
246246

247247
/**
248248
* Allow changes to the app configuration
249249
*/
250-
unfreeze () {
250+
unfreeze (): void {
251251
this.immutable = false
252252
}
253253
}

lib/Core.ts

+38-17
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export const Core = {
267267
mergeExtensions (
268268
app: FabrixApp,
269269
spool: Spool
270-
) {
270+
): void {
271271
const extensions = spool.extensions || {}
272272
for (const ext of Object.keys(extensions)) {
273273
if (!extensions.hasOwnProperty(ext)) {
@@ -313,7 +313,7 @@ export const Core = {
313313
return val
314314
},
315315

316-
isNotCircular: (obj) => {
316+
isNotCircular: (obj): boolean => {
317317
let stack = [[]]
318318

319319
try {
@@ -340,7 +340,7 @@ export const Core = {
340340
/**
341341
* Create configured paths if they don't exist and target is Node.js
342342
*/
343-
async createDefaultPaths (app: FabrixApp) {
343+
async createDefaultPaths (app: FabrixApp): Promise<any> {
344344
const paths: {[key: string]: string} = app.config.get('main.paths') || { }
345345
const target: string = app.config.get('main.target') || 'node'
346346
if (target !== 'browser') {
@@ -358,7 +358,7 @@ export const Core = {
358358
/**
359359
* Bind listeners to fabrix application events
360360
*/
361-
bindApplicationListeners (app: FabrixApp) {
361+
bindApplicationListeners (app: FabrixApp): void {
362362
app.once('spool:all:configured', () => {
363363
if (app.config.get('main.freezeConfig') === false) {
364364
app.log.warn('freezeConfig is disabled. Configuration will not be frozen.')
@@ -397,31 +397,50 @@ export const Core = {
397397
*/
398398
bindSpoolPhaseListeners (
399399
app: FabrixApp,
400-
spools: Spool[]
401-
) {
400+
spools: Spool[] = []
401+
): void {
402+
// TODO, eliminate waiting on lifecycle events that will not exist
403+
// https://github.com/fabrix-app/fabrix/issues/14
402404
const validatedEvents = spools.map(spool => `spool:${spool.name}:validated`)
403405
const configuredEvents = spools.map(spool => `spool:${spool.name}:configured`)
404406
const initializedEvents = spools.map(spool => `spool:${spool.name}:initialized`)
405407
const sanityEvents = spools.map(spool => `spool:${spool.name}:sane`)
406408

407-
app.after(configuredEvents).then(async () => {
408-
await this.createDefaultPaths(app)
409-
app.emit('spool:all:configured')
410-
})
409+
app.after(configuredEvents)
410+
.then(async () => {
411+
await this.createDefaultPaths(app)
412+
app.emit('spool:all:configured')
413+
})
414+
.catch(err => {
415+
app.log.error(err)
416+
throw err
417+
})
411418

412419
app.after(validatedEvents)
413420
.then(() => app.emit('spool:all:validated'))
421+
.catch(err => {
422+
app.log.error(err)
423+
throw err
424+
})
414425

415426
app.after(initializedEvents)
416427
.then(() => {
417428
app.emit('spool:all:initialized')
418429
})
430+
.catch(err => {
431+
app.log.error(err)
432+
throw err
433+
})
419434

420435
app.after(sanityEvents)
421436
.then(() => {
422437
app.emit('spool:all:sane')
423438
app.emit('fabrix:ready')
424439
})
440+
.catch(err => {
441+
app.log.error(err)
442+
throw err
443+
})
425444
},
426445

427446
/**
@@ -440,39 +459,41 @@ export const Core = {
440459
.then(() => spool.sanity())
441460
.then(() => app.emit(`spool:${spool.name}:sane`))
442461
.then(() => spool.stage = 'sane')
443-
.catch(this.handlePromiseRejection)
462+
.catch(err => this.handlePromiseRejection(app, err))
444463

445464
app.after((lifecycle.initialize.listen).concat('spool:all:configured'))
446465
.then(() => app.log.debug('spool: initializing', spool.name))
447466
.then(() => spool.stage = 'initializing')
448467
.then(() => spool.initialize())
449468
.then(() => app.emit(`spool:${spool.name}:initialized`))
450469
.then(() => spool.stage = 'initialized')
451-
.catch(this.handlePromiseRejection)
470+
.catch(err => this.handlePromiseRejection(app, err))
452471

453472
app.after((lifecycle.configure.listen).concat('spool:all:validated'))
454473
.then(() => app.log.debug('spool: configuring', spool.name))
455474
.then(() => spool.stage = 'configuring')
456475
.then(() => spool.configure())
457476
.then(() => app.emit(`spool:${spool.name}:configured`))
458477
.then(() => spool.stage = 'configured')
459-
.catch(this.handlePromiseRejection)
478+
.catch(err => this.handlePromiseRejection(app, err))
460479

461-
app.after('fabrix:start')
480+
app.after(['fabrix:start'])
462481
.then(() => app.log.debug('spool: validating', spool.name))
463482
.then(() => spool.stage = 'validating')
464483
.then(() => spool.validate())
465484
.then(() => app.emit(`spool:${spool.name}:validated`))
466485
.then(() => spool.stage = 'validated')
467-
.catch(this.handlePromiseRejection)
486+
.catch(err => this.handlePromiseRejection(app, err))
468487
},
469488

470489
/**
471490
* Handle a promise rejection
472491
*/
473-
handlePromiseRejection (err: Error): void {
474-
console.error(err)
492+
handlePromiseRejection (app: FabrixApp, err: Error): void {
493+
app.log.error(err)
475494
throw err
495+
496+
return
476497
}
477498

478499
}

0 commit comments

Comments
 (0)