diff --git a/lib/modules/plugin_cmd/index.js b/lib/modules/plugin_cmd/index.js index a73525744..778144e1d 100644 --- a/lib/modules/plugin_cmd/index.js +++ b/lib/modules/plugin_cmd/index.js @@ -22,6 +22,8 @@ class PluginCommand { } let npmInstall = ['npm', 'install', '--save']; npmInstall = npmInstall.concat(cmdArray.slice(2)); + let npmPackage = npmInstall[3]; + self.embark.logger.info(`Installing npm package ${npmPackage} ...`); async.waterfall([ function npmInstallAsync(cb) { utils.runCmd(npmInstall.join(' '), {silent: false, exitOnError: false}, (err) => { @@ -35,16 +37,15 @@ class PluginCommand { // get the installed package from package.json let packageFile = fs.readJSONSync(self.config.packageFile); let dependencies = Object.keys(packageFile.dependencies); - let npmPackage = npmInstall[3]; let installedPackage = dependencies.filter((dep) => npmPackage.indexOf(dep) >=0); self.embarkConfig.plugins[installedPackage[0]] = {}; fs.writeFile(self.config.embarkConfigFile, JSON.stringify(self.embarkConfig, null, 2), cb); } ], (err) => { if(err) { - return callback(err); + return callback(`Error installing npm package ${npmPackage}. Please visit https://embark.status.im/plugins/ for more info`); } - callback(null, 'npm package successfully installed as a plugin'); + callback(null, `npm package ${npmPackage} successfully installed as a plugin`); }); } }; diff --git a/lib/utils/utils.js b/lib/utils/utils.js index dc11127d2..8eaf99a46 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -131,24 +131,35 @@ function pingEndpoint(host, port, type, protocol, origin, callback) { function runCmd(cmd, options, callback) { const shelljs = require('shelljs'); - options = Object.assign({silent: true, exitOnError: true}, options || {}); - let result = shelljs.exec(cmd); - if (result.code !== 0) { - console.log("error doing.. " + cmd); - console.log(result.output); - if (result.stderr !== undefined) { - console.log(result.stderr); + options = Object.assign({silent: true,exitOnError: true, async: true}, options || {}); + const outputToConsole = !options.silent; + options.silent = true; + let result = shelljs.exec(cmd, options, function (code, stdout) { + if(code !==0) { + if (options.exitOnError) { + return exit(); + } + if(typeof callback === 'function') { + callback(`shell returned code ${code}`); + } + } else { + if(typeof callback === 'function') { + return callback(null, stdout); + } } - if (typeof callback === 'function') { - return callback(result, null); + }); + + result.stdout.on('data', function(data) { + if(outputToConsole) { + console.log(data); } - if (options.exitOnError) { - return exit(); + }); + + result.stderr.on('data', function(data) { + if (outputToConsole) { + console.log(data); } - } - if(typeof callback === 'function') { - return callback(null, result); - } + }); } function cd(folder) {