Merge pull request #31 from fabien/fix/compile-options
Implemented modelSources, bootDirs and bootScripts options
This commit is contained in:
commit
51cf0052d0
3
index.js
3
index.js
|
@ -66,6 +66,9 @@ var addInstructionsToBrowserify = require('./lib/bundler');
|
||||||
* `production`; however the applications are free to use any names.
|
* `production`; however the applications are free to use any names.
|
||||||
* @property {Array.<String>} [modelSources] List of directories where to look
|
* @property {Array.<String>} [modelSources] List of directories where to look
|
||||||
* for files containing model definitions.
|
* for files containing model definitions.
|
||||||
|
* @property {Array.<String>} [bootDirs] List of directories where to look
|
||||||
|
* for boot scripts.
|
||||||
|
* @property {Array.<String>} [bootScripts] List of script files to execute on boot.
|
||||||
* @end
|
* @end
|
||||||
*
|
*
|
||||||
* @header boot(app, [options])
|
* @header boot(app, [options])
|
||||||
|
|
|
@ -42,12 +42,18 @@ module.exports = function compile(options) {
|
||||||
assertIsValidConfig('data source', dataSourcesConfig);
|
assertIsValidConfig('data source', dataSourcesConfig);
|
||||||
|
|
||||||
// require directories
|
// require directories
|
||||||
var bootScripts = findScripts(path.join(appRootDir, 'boot'));
|
var bootDirs = options.bootDirs || []; // precedence
|
||||||
|
bootDirs = bootDirs.concat(path.join(appRootDir, 'boot'));
|
||||||
|
|
||||||
|
var bootScripts = options.bootScripts || [];
|
||||||
|
bootDirs.forEach(function(dir) {
|
||||||
|
bootScripts = bootScripts.concat(findScripts(dir));
|
||||||
|
});
|
||||||
|
|
||||||
var modelsMeta = modelsConfig._meta || {};
|
var modelsMeta = modelsConfig._meta || {};
|
||||||
delete modelsConfig._meta;
|
delete modelsConfig._meta;
|
||||||
|
|
||||||
var modelSources = modelsMeta.sources || ['./models'];
|
var modelSources = options.modelSources || modelsMeta.sources || ['./models'];
|
||||||
var modelInstructions = buildAllModelInstructions(
|
var modelInstructions = buildAllModelInstructions(
|
||||||
modelsRootDir, modelsConfig, modelSources);
|
modelsRootDir, modelsConfig, modelSources);
|
||||||
|
|
||||||
|
|
|
@ -219,6 +219,28 @@ describe('compiler', function() {
|
||||||
expect(instructions.files.boot).to.eql([initJs]);
|
expect(instructions.files.boot).to.eql([initJs]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('supports `bootDirs` option', function() {
|
||||||
|
appdir.createConfigFilesSync();
|
||||||
|
var initJs = appdir.writeFileSync('custom-boot/init.js',
|
||||||
|
'module.exports = function(app) { app.fnCalled = true; };');
|
||||||
|
var instructions = boot.compile({
|
||||||
|
appRootDir: appdir.PATH,
|
||||||
|
bootDirs: [path.dirname(initJs)]
|
||||||
|
});
|
||||||
|
expect(instructions.files.boot).to.eql([initJs]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('supports `bootScripts` option', function() {
|
||||||
|
appdir.createConfigFilesSync();
|
||||||
|
var initJs = appdir.writeFileSync('custom-boot/init.js',
|
||||||
|
'module.exports = function(app) { app.fnCalled = true; };');
|
||||||
|
var instructions = boot.compile({
|
||||||
|
appRootDir: appdir.PATH,
|
||||||
|
bootScripts: [initJs]
|
||||||
|
});
|
||||||
|
expect(instructions.files.boot).to.eql([initJs]);
|
||||||
|
});
|
||||||
|
|
||||||
it('ignores models/ subdirectory', function() {
|
it('ignores models/ subdirectory', function() {
|
||||||
appdir.createConfigFilesSync();
|
appdir.createConfigFilesSync();
|
||||||
appdir.writeFileSync('models/my-model.js', '');
|
appdir.writeFileSync('models/my-model.js', '');
|
||||||
|
@ -268,6 +290,31 @@ describe('compiler', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('supports `modelSources` option', function() {
|
||||||
|
appdir.createConfigFilesSync({}, {}, {
|
||||||
|
Car: { dataSource: 'db' }
|
||||||
|
});
|
||||||
|
appdir.writeConfigFileSync('custom-models/car.json', { name: 'Car' });
|
||||||
|
appdir.writeFileSync('custom-models/car.js', '');
|
||||||
|
|
||||||
|
var instructions = boot.compile({
|
||||||
|
appRootDir: appdir.PATH,
|
||||||
|
modelSources: ['./custom-models']
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(instructions.models).to.have.length(1);
|
||||||
|
expect(instructions.models[0]).to.eql({
|
||||||
|
name: 'Car',
|
||||||
|
config: {
|
||||||
|
dataSource: 'db'
|
||||||
|
},
|
||||||
|
definition: {
|
||||||
|
name: 'Car'
|
||||||
|
},
|
||||||
|
sourceFile: path.resolve(appdir.PATH, 'custom-models', 'car.js')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('supports `sources` option in `model-config.json`', function() {
|
it('supports `sources` option in `model-config.json`', function() {
|
||||||
appdir.createConfigFilesSync({}, {}, {
|
appdir.createConfigFilesSync({}, {}, {
|
||||||
_meta: {
|
_meta: {
|
||||||
|
|
Loading…
Reference in New Issue