diff --git a/lib/compiler.js b/lib/compiler.js index bca4a85..d29f863 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -57,6 +57,9 @@ module.exports = function compile(options) { var modelInstructions = buildAllModelInstructions( modelsRootDir, modelsConfig, modelSources); + var afterBoot = options.afterBoot || function() {}; + assertIsValidAfterBoot(afterBoot); + // When executor passes the instruction to loopback methods, // loopback modifies the data. Since we are loading the data using `require`, // such change affects also code that calls `require` for the same file. @@ -66,10 +69,16 @@ module.exports = function compile(options) { models: modelInstructions, files: { boot: bootScripts - } + }, + afterBoot: afterBoot }); }; +function assertIsValidAfterBoot(cb) { + assert(cb && typeof cb === 'function', + 'afterBoot callback must be a function'); +} + function assertIsValidConfig(name, config) { if(config) { assert(typeof config === 'object', diff --git a/lib/executor.js b/lib/executor.js index d04e833..839f868 100644 --- a/lib/executor.js +++ b/lib/executor.js @@ -176,13 +176,24 @@ function forEachKeyedObject(obj, fn) { }); } -function runScripts(app, list) { - if (!list || !list.length) return; - list.forEach(function(filepath) { - var exports = tryRequire(filepath); - if (typeof exports === 'function') - exports(app); - }); +function runScripts(app, list, idx, callback) { + if (!list || !list.length) return; + + for (idx; idx