From d94130adfc035cf55788d63b253ccc3ae74655f6 Mon Sep 17 00:00:00 2001 From: shlomiassaf Date: Fri, 12 Sep 2014 23:23:11 +0300 Subject: [PATCH 1/3] Add support for afterBoot callback Add a callback option that fires when all boot modules with the 'waitForCallback' flag set to true, has finished. --- lib/compiler.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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', From 758809b79a4afeaea41a7bd627d5359fe2fe0678 Mon Sep 17 00:00:00 2001 From: shlomiassaf Date: Fri, 12 Sep 2014 23:24:36 +0300 Subject: [PATCH 2/3] Add support for afterBoot callback --- lib/executor.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/executor.js b/lib/executor.js index d04e833..1f7bdcb 100644 --- a/lib/executor.js +++ b/lib/executor.js @@ -176,13 +176,25 @@ 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 Date: Fri, 19 Sep 2014 14:05:57 +0300 Subject: [PATCH 3/3] Update executor.js Removed forgotten console.log --- lib/executor.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/executor.js b/lib/executor.js index 1f7bdcb..839f868 100644 --- a/lib/executor.js +++ b/lib/executor.js @@ -180,7 +180,6 @@ function runScripts(app, list, idx, callback) { if (!list || !list.length) return; for (idx; idx