init database before build client
authorSteve Hackbarth <stephenhackbarth@gmail.com>
Tue, 22 Jul 2014 22:20:35 +0000 (18:20 -0400)
committerSteve Hackbarth <stephenhackbarth@gmail.com>
Tue, 22 Jul 2014 22:20:35 +0000 (18:20 -0400)
scripts/lib/build_all.js
scripts/lib/build_database.js

index 3116b70..611107a 100644 (file)
@@ -53,6 +53,25 @@ var _ = require('underscore'),
       },
       buildAll = function (specs, creds, buildAllCallback) {
         async.series([
+          function (done) {
+            // step 0: init the database, if requested
+
+            if (specs.length === 1 &&
+                specs[0].initialize &&
+                (specs[0].backup || specs[0].source)) {
+
+              // The user wants to initialize the database first (i.e. Step 0)
+              // Do that, then call this function again
+              buildDatabaseUtil.initDatabase(specs[0], creds, function (err, res) {
+                specs[0].wasInitialized = true;
+                done(err, res);
+              });
+              return;
+            } else {
+              done();
+            }
+
+          },
           function (done) {
             // step 1: npm install extension if necessary
             // an alternate approach would be only npm install these
index 62ce3a8..aadd5d0 100644 (file)
@@ -44,29 +44,6 @@ var  async = require('async'),
         host: 'localhost' }
   */
   var buildDatabase = exports.buildDatabase = function (specs, creds, masterCallback) {
-    if (specs.length === 1 &&
-        specs[0].initialize &&
-        (specs[0].backup || specs[0].source)) {
-
-      // The user wants to initialize the database first (i.e. Step 0)
-      // Do that, then call this function again
-      buildDatabaseUtil.initDatabase(specs[0], creds, function (err, res) {
-        if (err) {
-          winston.error("Init database error: ", err);
-          masterCallback(err);
-          return;
-        }
-        // recurse to do the build step. Of course we don't want to initialize a second
-        // time, so destroy those flags.
-        specs[0].initialize = false;
-        specs[0].wasInitialized = true;
-        specs[0].backup = undefined;
-        specs[0].source = undefined;
-        buildDatabase(specs, creds, masterCallback);
-      });
-      return;
-    }
-
     //
     // The function to generate all the scripts for a database
     //