Added better error logging, dashboard doesnt break in run mode

This commit is contained in:
Subramanian Venkatesan 2018-09-12 11:27:28 +05:30
parent b3eedc4ba2
commit 1a756e8a05
2 changed files with 30 additions and 18 deletions

View File

@ -22,6 +22,8 @@ class PluginCommand {
} }
let npmInstall = ['npm', 'install', '--save']; let npmInstall = ['npm', 'install', '--save'];
npmInstall = npmInstall.concat(cmdArray.slice(2)); npmInstall = npmInstall.concat(cmdArray.slice(2));
let npmPackage = npmInstall[3];
self.embark.logger.info(`Installing npm package ${npmPackage} ...`);
async.waterfall([ async.waterfall([
function npmInstallAsync(cb) { function npmInstallAsync(cb) {
utils.runCmd(npmInstall.join(' '), {silent: false, exitOnError: false}, (err) => { utils.runCmd(npmInstall.join(' '), {silent: false, exitOnError: false}, (err) => {
@ -35,16 +37,15 @@ class PluginCommand {
// get the installed package from package.json // get the installed package from package.json
let packageFile = fs.readJSONSync(self.config.packageFile); let packageFile = fs.readJSONSync(self.config.packageFile);
let dependencies = Object.keys(packageFile.dependencies); let dependencies = Object.keys(packageFile.dependencies);
let npmPackage = npmInstall[3];
let installedPackage = dependencies.filter((dep) => npmPackage.indexOf(dep) >=0); let installedPackage = dependencies.filter((dep) => npmPackage.indexOf(dep) >=0);
self.embarkConfig.plugins[installedPackage[0]] = {}; self.embarkConfig.plugins[installedPackage[0]] = {};
fs.writeFile(self.config.embarkConfigFile, JSON.stringify(self.embarkConfig, null, 2), cb); fs.writeFile(self.config.embarkConfigFile, JSON.stringify(self.embarkConfig, null, 2), cb);
} }
], (err) => { ], (err) => {
if(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`);
}); });
} }
}; };

View File

@ -131,24 +131,35 @@ function pingEndpoint(host, port, type, protocol, origin, callback) {
function runCmd(cmd, options, callback) { function runCmd(cmd, options, callback) {
const shelljs = require('shelljs'); const shelljs = require('shelljs');
options = Object.assign({silent: true, exitOnError: true}, options || {}); options = Object.assign({silent: true,exitOnError: true, async: true}, options || {});
let result = shelljs.exec(cmd); const outputToConsole = !options.silent;
if (result.code !== 0) { options.silent = true;
console.log("error doing.. " + cmd); let result = shelljs.exec(cmd, options, function (code, stdout) {
console.log(result.output); if(code !==0) {
if (result.stderr !== undefined) { if (options.exitOnError) {
console.log(result.stderr); 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) { function cd(folder) {