Add feature to disable component

This commit is contained in:
Pradnya Baviskar 2015-03-05 15:08:27 +05:30
parent bfcd3ff15e
commit 2c4b6f06a4
2 changed files with 33 additions and 13 deletions

View File

@ -480,18 +480,20 @@ function resolveMiddlewareParams(rootDir, params) {
} }
function buildComponentInstructions(rootDir, componentConfig) { function buildComponentInstructions(rootDir, componentConfig) {
return Object.keys(componentConfig).map(function(name) { return Object.keys(componentConfig)
var sourceFile; .filter(function(name) { return !!componentConfig[name]; })
if (name.indexOf('./') === 0 || name.indexOf('../') === 0) { .map(function(name) {
// Relative path var sourceFile;
sourceFile = path.resolve(rootDir, name); if (name.indexOf('./') === 0 || name.indexOf('../') === 0) {
} else { // Relative path
sourceFile = require.resolve(name); sourceFile = path.resolve(rootDir, name);
} } else {
sourceFile = require.resolve(name);
}
return { return {
sourceFile: sourceFile, sourceFile: sourceFile,
config: componentConfig[name] config: componentConfig[name]
}; };
}); });
} }

View File

@ -468,9 +468,27 @@ describe('executor', function() {
boot(app, appdir.PATH); boot(app, appdir.PATH);
expect(Object.keys(require.cache)).to.include(
appdir.resolve('components/test-component/index.js'));
expect(app.componentOptions).to.eql({ option: 'value' }); expect(app.componentOptions).to.eql({ option: 'value' });
}); });
it('disables component when configuration is not set', function() {
appdir.writeConfigFileSync('component-config.json', {
'./components/test-component': false
});
appdir.writeFileSync('components/test-component/index.js',
'module.exports = ' +
'function(app, options) { app.componentOptions = options; }');
boot(app, appdir.PATH);
expect(Object.keys(require.cache)).to.not.include(
appdir.resolve('components/test-component/index.js'));
});
it('configures middleware (that requires `this`)', function(done) { it('configures middleware (that requires `this`)', function(done) {
var passportPath = require.resolve('./fixtures/passport'); var passportPath = require.resolve('./fixtures/passport');