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'];
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`);
});
}
};

View File

@ -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) {