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);
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ function browserifyTestApp(appDir, next) {
|
||||||
var bundlePath = sandbox.resolve('browser-app-bundle.js');
|
var bundlePath = sandbox.resolve('browser-app-bundle.js');
|
||||||
var out = fs.createWriteStream(bundlePath);
|
var out = fs.createWriteStream(bundlePath);
|
||||||
b.bundle({ debug: true }).pipe(out);
|
b.bundle({ debug: true }).pipe(out);
|
||||||
|
|
||||||
out.on('error', function(err) { return next(err); });
|
out.on('error', function(err) { return next(err); });
|
||||||
out.on('close', function() {
|
out.on('close', function() {
|
||||||
next(null, bundlePath);
|
next(null, bundlePath);
|
||||||
|
|
|
@ -218,6 +218,28 @@ describe('compiler', function() {
|
||||||
var instructions = boot.compile(appdir.PATH);
|
var instructions = boot.compile(appdir.PATH);
|
||||||
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();
|
||||||
|
@ -267,6 +289,31 @@ describe('compiler', function() {
|
||||||
sourceFile: path.resolve(appdir.PATH, 'models', 'car.js')
|
sourceFile: path.resolve(appdir.PATH, 'models', 'car.js')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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({}, {}, {
|
||||||
|
|
Loading…
Reference in New Issue