Permalink
Browse files

npm install from build_app

  • Loading branch information...
1 parent 5c04809 commit 1b68a0e13c6840edb0e86fede6a4898fad89e079 @shackbarth shackbarth committed Jun 10, 2014
Showing with 67 additions and 37 deletions.
  1. +1 −1 .travis.yml
  2. +16 −20 node-datasource/routes/install_extension.js
  3. +50 −16 scripts/lib/build_all.js
View
@@ -12,6 +12,6 @@ before_script:
- "cd .."
script:
- - "npm run-script test"
- "npm run-script test-datasource"
+ - "npm run-script test"
- "npm run-script jshint"
@@ -42,8 +42,6 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
}
});
},
- // TODO: we should re-npm install on every build_app, or possibly just on
- // an npm install
npmLoad = function (callback) {
npm.load(callback);
},
@@ -62,24 +60,22 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
}, callback);
};
- async.series([
- validateInput,
- validateUser,
- npmLoad,
- npmInstall,
- buildExtension
- ], function (err, results) {
- if (err) {
- console.log(err);
- err.isError = true;
- res.send(err);
- return;
- }
- console.log("all done");
- res.send({data: "_success"});
- });
-
-
+ async.series([
+ validateInput,
+ validateUser,
+ npmLoad,
+ npmInstall,
+ buildExtension
+ ], function (err, results) {
+ if (err) {
+ console.log(err);
+ err.isError = true;
+ res.send(err);
+ return;
+ }
+ console.log("all done");
+ res.send({data: "_success"});
+ });
};
}());
View
@@ -10,6 +10,7 @@ var _ = require('underscore'),
dataSource = require('../../node-datasource/lib/ext/datasource').dataSource,
exec = require('child_process').exec,
fs = require('fs'),
+ npm = require('npm'),
path = require('path'),
unregister = buildDatabaseUtil.unregister,
winston = require('winston');
@@ -106,26 +107,59 @@ var _ = require('underscore'),
});
},
buildAll = function (specs, creds, buildAllCallback) {
- buildClient(specs, function (err, res) {
- if (err) {
- buildAllCallback(err);
- return;
- }
- buildDatabase.buildDatabase(specs, creds, function (databaseErr, databaseRes) {
- var returnMessage;
- if (databaseErr) {
- buildAllCallback(databaseErr);
+ async.series([
+ function (done) {
+ // step 1: npm install extension if necessary
+ // an alternate approach would be only npm install these
+ // extensions on an npm install.
+ var allExtensions = _.reduce(specs, function (memo, spec) {
+ memo.push(spec.extensions);
+ return _.flatten(memo);
+ }, []);
+ var npmExtensions = _.filter(allExtensions, function (extName) {
+ return extName.indexOf("node_modules") >= 0;
+ });
+ if (npmExtensions.length === 0) {
+ done();
return;
}
- returnMessage = "\n";
- _.each(specs, function (spec) {
- returnMessage += "Database: " + spec.database + '\nDirectories:\n';
- _.each(spec.extensions, function (ext) {
- returnMessage += ' ' + ext + '\n';
+ npm.load(function (err, res) {
+ if (err) {
+ done(err);
+ return;
+ }
+ npm.on("log", function (message) {
+ // log the progress of the installation
+ console.log(message);
});
+ async.map(npmExtensions, function (extName, next) {
+ npm.commands.install([path.basename(extName)], next);
+ }, done);
});
- buildAllCallback(null, "Build succeeded." + returnMessage);
- });
+ },
+ function (done) {
+ // step 2: build the client
+ buildClient(specs, done);
+ },
+ function (done) {
+ // step 3: build the database
+ buildDatabase.buildDatabase(specs, creds, function (databaseErr, databaseRes) {
+ if (databaseErr) {
+ buildAllCallback(databaseErr);
+ return;
+ }
+ var returnMessage = "\n";
+ _.each(specs, function (spec) {
+ returnMessage += "Database: " + spec.database + '\nDirectories:\n';
+ _.each(spec.extensions, function (ext) {
+ returnMessage += ' ' + ext + '\n';
+ });
+ });
+ done(null, "Build succeeded." + returnMessage);
+ });
+ }
+ ], function (err, results) {
+ buildAllCallback(err, results && results[results.length - 1]);
});
},
config;

0 comments on commit 1b68a0e

Please sign in to comment.