Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
fix(start): use spawn instead of exec
Browse files Browse the repository at this point in the history
  • Loading branch information
tlancina committed Mar 31, 2016
1 parent ff50113 commit 3d41fdd
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,29 @@ var V2_STARTERS = {
tutorial: { "repoName": "ionic2-starter-tutorial" }
}

Start.runExecCommand = function runExecCommand(command) {
Start.runSpawnCommand = function runSpawnCommand(cmd, args) {
var q = Q.defer();
var command = cmd + args.join(' ');
var childProcess = require('child_process');

logging.logger.debug('Running exec command:', command);

childProcess.exec(command, function(err, stdout, stderr) {
if (err) {
Utils.fail('Unable to run exec command' + err);
q.reject(err);
} else {
logging.logger.debug('Completed', stdout);
q.resolve(stdout);
var spawned = childProcess.spawn(cmd, args);
spawned.on('error', function(err){
Utils.fail('Unable to run spawn command' + err);
})
spawned.stdout.on('data', function(data){
logging.logger.debug(data.toString());
});
spawned.stderr.on('data', function(data){
logging.logger.debug(data.toString());
});
spawned.on('exit', function(code){
logging.logger.debug('Spawn command completed');
if (code !== 0) {
return q.reject('There was an error with the spawned command: ' + command);
}
return q.resolve();
});

return q.promise;
Expand Down Expand Up @@ -99,7 +108,7 @@ Start.startApp = function startApp(options) {
.then(function() {
if (!options.skipNpm) {
logging.logger.info('Installing npm packages...'.green);
return Start.runExecCommand('npm install');
return Start.runSpawnCommand('npm', ['install']);
}
})
.then(function(){
Expand Down

0 comments on commit 3d41fdd

Please sign in to comment.