Comparing version 3.0.0-pre.3 to 3.0.0-pre.4
@@ -8,4 +8,4 @@ { | ||
"dependencies": { | ||
"trailpack-router": "^2", | ||
"trails": "^2" | ||
"trailpack-router": "next", | ||
"trails": "next" | ||
}, | ||
@@ -17,3 +17,3 @@ "devDependencies": { | ||
"supertest": "^3", | ||
"trailpack-repl": "^2" | ||
"trailpack-repl": "^3" | ||
}, | ||
@@ -20,0 +20,0 @@ "scripts": { |
12
index.js
@@ -93,2 +93,5 @@ /*eslint no-process-env: 0 */ | ||
const pack = new Pack(this) | ||
this.packs[pack.name] = pack | ||
this.config.merge(pack.config) | ||
lib.Core.mergeApi(this, pack) | ||
lib.Core.bindTrailpackMethodListeners(this, pack) | ||
@@ -104,3 +107,2 @@ } | ||
this.policies = lib.Core.bindMethods(this, 'policies') | ||
this.services = lib.Core.bindMethods(this, 'services') | ||
@@ -163,2 +165,6 @@ lib.Core.bindApplicationListeners(this) | ||
}) | ||
.catch(err => { | ||
this.log.error(err, 'handling onceAny events', events) | ||
throw err | ||
}) | ||
} | ||
@@ -187,2 +193,6 @@ | ||
})) | ||
.catch(err => { | ||
this.log.error(err, 'handling after events', events) | ||
throw err | ||
}) | ||
} | ||
@@ -189,0 +199,0 @@ |
@@ -44,2 +44,15 @@ const merge = require('lodash.merge') | ||
/** | ||
* Merge tree into this configuration. Return overwritten keys | ||
*/ | ||
merge (configTree) { | ||
const configEntries = Object.entries(Configuration.flattenTree(configTree)) | ||
return configEntries.map(([ key, value ]) => { | ||
const hasKey = this.has(key) | ||
this.set(key, value) | ||
return { hasKey, key } | ||
}) | ||
} | ||
/** | ||
* Prevent changes to the app configuration | ||
@@ -123,1 +136,2 @@ */ | ||
} | ||
/*eslint no-console: 0 */ | ||
const fs = require('fs') | ||
//const fs = require('fs') | ||
const mkdirp = require('mkdirp') | ||
@@ -92,2 +92,12 @@ const mapValues = require('lodash.mapvalues') | ||
mergeApi (app, pack) { | ||
console.log('app.api', app.api) | ||
console.log('pack.api', pack.api) | ||
Object.assign(app.api.controllers, pack.api.controllers) | ||
Object.assign(app.api.services, pack.api.services) | ||
Object.assign(app.api.policies, pack.api.policies) | ||
Object.assign(app.api.resolvers, pack.api.resolvers) | ||
Object.assign(app.api.models, pack.api.models) | ||
}, | ||
/** | ||
@@ -99,22 +109,5 @@ * Create configured paths if they don't exist | ||
return Promise.all(Object.entries(paths).map(([ pathName, dir ]) => { | ||
return new Promise((resolve, reject) => { | ||
fs.stat(dir, (err, stats) => { | ||
if (err) { | ||
if (/no such file or directory/.test(err.message)) { | ||
app.log.debug('Trails is creating the path (', pathName, ') at', dir) | ||
} | ||
else { | ||
return reject(err) | ||
} | ||
} | ||
mkdirp(dir, err => { | ||
if (err) return reject(err) | ||
resolve(stats) | ||
}) | ||
}) | ||
}) | ||
})) | ||
for (const [ , dir ] of Object.entries(paths)) { | ||
await mkdirp(dir) | ||
} | ||
}, | ||
@@ -162,8 +155,8 @@ | ||
app.after(configuredEvents) | ||
.then(() => this.createDefaultPaths(app)) | ||
.then(() => app.emit('trailpack:all:configured')) | ||
app.after(configuredEvents).then(async () => { | ||
await this.createDefaultPaths(app) | ||
app.emit('trailpack:all:configured') | ||
}) | ||
app.after(validatedEvents) | ||
.then(() => app.emit('trailpack:all:validated')) | ||
app.after(validatedEvents).then(() => app.emit('trailpack:all:validated')) | ||
@@ -182,3 +175,3 @@ app.after(initializedEvents) | ||
bindTrailpackMethodListeners (app, pack) { | ||
const lifecycle = pack.config.lifecycle | ||
const lifecycle = pack.lifecycle | ||
@@ -189,2 +182,3 @@ app.after(lifecycle.initialize.listen.concat('trailpack:all:configured')) | ||
.then(() => app.emit(`trailpack:${pack.name}:initialized`)) | ||
.catch(this.handlePromiseRejection) | ||
@@ -195,2 +189,3 @@ app.after(lifecycle.configure.listen.concat('trailpack:all:validated')) | ||
.then(() => app.emit(`trailpack:${pack.name}:configured`)) | ||
.catch(this.handlePromiseRejection) | ||
@@ -201,3 +196,10 @@ app.after('trails:start') | ||
.then(() => app.emit(`trailpack:${pack.name}:validated`)) | ||
.catch(this.handlePromiseRejection) | ||
}, | ||
handlePromiseRejection (err) { | ||
console.error(err) | ||
throw err | ||
} | ||
} |
@@ -98,3 +98,3 @@ const Errors = require('./errors') | ||
*/ | ||
getEventProducer (eventName, stageName, packs, path) { | ||
getEventProducer (eventName, stageName, packs, path = [ ]) { | ||
const producers = packs | ||
@@ -101,0 +101,0 @@ .filter(pack => { |
{ | ||
"name": "trails", | ||
"version": "3.0.0-pre.3", | ||
"version": "3.0.0-pre.4", | ||
"description": "Modern Web Application Framework for Node.js", | ||
@@ -21,5 +21,4 @@ "keywords": [ | ||
"scripts": { | ||
"test": "eslint --ignore-path .gitignore . && istanbul cover node_modules/mocha/bin/_mocha", | ||
"test": "eslint --ignore-path .gitignore . && nyc mocha", | ||
"test-performance": "eslint --ignore-path .gitignore . && mocha test-performance", | ||
"coverage": "istanbul cover node_modules/mocha/bin/_mocha", | ||
"ci": "cd .. && ci" | ||
@@ -78,8 +77,8 @@ }, | ||
"eslint-config-trails": "^3", | ||
"istanbul": "^1.1.0-alpha.1", | ||
"mocha": "^3.2.0", | ||
"nyc": "^11.0.2", | ||
"pre-commit": "^1.1.3", | ||
"proxyquire": "^1.7.11", | ||
"smokesignals": "next", | ||
"trailpack": "next", | ||
"trailpack": "3.0.0-pre.5", | ||
"winston": "^2.1.1" | ||
@@ -86,0 +85,0 @@ }, |
@@ -10,3 +10,3 @@ <img src="http://cdn.trailsjs.io/art/logos/trails-horiz-logo-green.svg" height="96px" title="Trails Logo" /> | ||
Trails is a modern, [community-driven](https://opencollective.com/trails) web application framework for node.js. It | ||
Trails is a modern, [community-driven](https://opencollective.com/trails) web application framework for Node.js. It | ||
builds on the pedigree of [Rails](http://rubyonrails.org/) and [Grails](https://grails.org/) | ||
@@ -13,0 +13,0 @@ to accelerate development by adhering to a straightforward, convention-based, |
@@ -277,2 +277,34 @@ const assert = require('assert') | ||
}) | ||
describe('#merge', () => { | ||
const tree = { | ||
foo: true, | ||
bar: [ 1,2,3 ], | ||
level2: { | ||
name: 'alice', | ||
level3: { | ||
a: 1 | ||
} | ||
}, | ||
customObject: { | ||
string: 'b' | ||
} | ||
} | ||
it('should merge nested tree into configuration', () => { | ||
const config = new lib.Configuration(testConfig) | ||
config.merge(tree) | ||
assert.equal(config.get('level2.level3.a'), 1) | ||
assert.equal(config.level2.level3.a, 1) | ||
assert.equal(config.get('customObject.string'), 'b') | ||
assert.equal(config.get('customObject.int'), 1) | ||
}) | ||
it('should return list of merged keys', () => { | ||
const config = new lib.Configuration(testConfig) | ||
const mergeList = config.merge(tree) | ||
console.log('mergeList', mergeList) | ||
assert(mergeList.find(m => m.hasKey && m.key === 'customObject.string')) | ||
}) | ||
}) | ||
}) |
@@ -130,10 +130,8 @@ const EventEmitter = require('events').EventEmitter | ||
config: { | ||
trailpack: { | ||
lifecycle: { | ||
configure: { | ||
emit: [ 'pack1:configured', 'pack1:custom' ] | ||
}, | ||
initialize: { | ||
emit: [ 'pack1:initialized', 'pack1:custom' ] | ||
} | ||
lifecycle: { | ||
configure: { | ||
emit: [ 'pack1:configured', 'pack1:custom' ] | ||
}, | ||
initialize: { | ||
emit: [ 'pack1:initialized', 'pack1:custom' ] | ||
} | ||
@@ -148,10 +146,8 @@ } | ||
config: { | ||
trailpack: { | ||
lifecycle: { | ||
configure: { | ||
emit: [ 'pack2:configured' ] | ||
}, | ||
initialize: { | ||
emit: [ 'pack2:initialized' ] | ||
} | ||
lifecycle: { | ||
configure: { | ||
emit: [ 'pack2:configured' ] | ||
}, | ||
initialize: { | ||
emit: [ 'pack2:initialized' ] | ||
} | ||
@@ -184,12 +180,10 @@ } | ||
config: { | ||
trailpack: { | ||
lifecycle: { | ||
configure: { | ||
listen: [ ], | ||
emit: [ 'pack0:configured' ] | ||
}, | ||
initialize: { | ||
listen: [ ], | ||
emit: [ 'pack0:initialized' ] | ||
} | ||
lifecycle: { | ||
configure: { | ||
listen: [ ], | ||
emit: [ 'pack0:configured' ] | ||
}, | ||
initialize: { | ||
listen: [ ], | ||
emit: [ 'pack0:initialized' ] | ||
} | ||
@@ -205,11 +199,9 @@ } | ||
config: { | ||
trailpack: { | ||
lifecycle: { | ||
configure: { | ||
listen: [ 'pack0:configured' ], | ||
emit: [ 'pack1:configured' ] | ||
}, | ||
initialize: { | ||
emit: [ 'pack1:initialized', 'pack1:custom' ] | ||
} | ||
lifecycle: { | ||
configure: { | ||
listen: [ 'pack0:configured' ], | ||
emit: [ 'pack1:configured' ] | ||
}, | ||
initialize: { | ||
emit: [ 'pack1:initialized', 'pack1:custom' ] | ||
} | ||
@@ -225,12 +217,10 @@ } | ||
config: { | ||
trailpack: { | ||
lifecycle: { | ||
configure: { | ||
listen: [ 'pack1:configured' ], | ||
emit: [ 'pack2:configured' ] | ||
}, | ||
initialize: { | ||
listen: [ 'pack1:initialized', 'pack1:custom' ], | ||
emit: [ 'pack2:initialized' ] | ||
} | ||
lifecycle: { | ||
configure: { | ||
listen: [ 'pack1:configured' ], | ||
emit: [ 'pack2:configured' ] | ||
}, | ||
initialize: { | ||
listen: [ 'pack1:initialized', 'pack1:custom' ], | ||
emit: [ 'pack2:initialized' ] | ||
} | ||
@@ -246,12 +236,10 @@ } | ||
config: { | ||
trailpack: { | ||
lifecycle: { | ||
configure: { | ||
listen: [ 'pack2:configured' ], | ||
emit: [ 'pack3:configured' ] | ||
}, | ||
initialize: { | ||
listen: [ 'pack2:initialized', 'pack1:custom' ], | ||
emit: [ 'pack3:initialized' ] | ||
} | ||
lifecycle: { | ||
configure: { | ||
listen: [ 'pack2:configured' ], | ||
emit: [ 'pack3:configured' ] | ||
}, | ||
initialize: { | ||
listen: [ 'pack2:initialized', 'pack1:custom' ], | ||
emit: [ 'pack3:initialized' ] | ||
} | ||
@@ -267,13 +255,11 @@ } | ||
config: { | ||
trailpack: { | ||
lifecycle: { | ||
// dependency with no route to source | ||
configure: { | ||
listen: [ 'packX:configured' ], | ||
emit: [ 'pack4:configured' ] | ||
}, | ||
// dependency on pack with circular dependency | ||
initialize: { | ||
listen: [ 'pack5:initialized', 'pack0:initialized' ] | ||
} | ||
lifecycle: { | ||
// dependency with no route to source | ||
configure: { | ||
listen: [ 'packX:configured' ], | ||
emit: [ 'pack4:configured' ] | ||
}, | ||
// dependency on pack with circular dependency | ||
initialize: { | ||
listen: [ 'pack5:initialized', 'pack0:initialized' ] | ||
} | ||
@@ -290,12 +276,10 @@ } | ||
config: { | ||
trailpack: { | ||
lifecycle: { | ||
configure: { | ||
listen: [ 'pack5:configured' ], | ||
emit: [ 'pack5:configured' ] | ||
}, | ||
initialize: { | ||
listen: [ 'pack4:initialized' ], | ||
emit: [ 'pack5:initialized' ] | ||
} | ||
lifecycle: { | ||
configure: { | ||
listen: [ 'pack5:configured' ], | ||
emit: [ 'pack5:configured' ] | ||
}, | ||
initialize: { | ||
listen: [ 'pack4:initialized' ], | ||
emit: [ 'pack5:initialized' ] | ||
} | ||
@@ -302,0 +286,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106373
2788
16