mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-10 22:16:20 +00:00
install npm package using shell.js
This commit is contained in:
parent
c8e812e638
commit
cb751b5213
@ -132,7 +132,7 @@ class Engine {
|
||||
}
|
||||
|
||||
pluginCommandService() {
|
||||
this.registerModule('plugin_cmd');
|
||||
this.registerModule('plugin_cmd', {embarkConfig: this.embarkConfig});
|
||||
}
|
||||
|
||||
namingSystem(_options) {
|
||||
|
@ -1,15 +1,54 @@
|
||||
let fs = require('./../../core/fs.js');
|
||||
let utils = require('./../../utils/utils.js');
|
||||
let async = require('async');
|
||||
|
||||
class PluginCommand {
|
||||
constructor(embark) {
|
||||
constructor(embark, config) {
|
||||
this.embark = embark;
|
||||
this.config = config;
|
||||
this.embarkConfig = fs.readJSONSync(this.config.embarkConfig);
|
||||
this.registerCommands();
|
||||
}
|
||||
registerCommands() {
|
||||
const self = this;
|
||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
||||
this.embark.registerConsoleCommand((cmd, _options) => {
|
||||
let cmdArray = cmd.split(' ');
|
||||
let cmdName = cmdArray[0];
|
||||
return {
|
||||
match: () => cmd === 'plugin',
|
||||
process: (cb) => {
|
||||
//self.events.request('start-webserver', cb)
|
||||
match: () => cmdName === 'plugin',
|
||||
process: (callback) => {
|
||||
if(cmdArray.length < 3 || cmdArray[1] !== 'install' || typeof cmdArray[2] === 'undefined') {
|
||||
return callback(__('arguments to the command are missing or invalid'));
|
||||
}
|
||||
let npmInstall = ['npm', 'install'];
|
||||
if (cmdArray[2] === '--save') {
|
||||
if(typeof cmdArray[3] === 'undefined') {
|
||||
return callback(__('npm package argument missing'));
|
||||
}
|
||||
npmInstall = npmInstall.concat(cmdArray);
|
||||
} else {
|
||||
npmInstall = npmInstall.concat(['--save'].concat(cmdArray.slice(2)));
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function npmInstallAsync(cb) {
|
||||
utils.runCmd(npmInstall.join(' '), {silent: false, exitOnError: false}, (err) => {
|
||||
if(err) {
|
||||
return cb(err);
|
||||
}
|
||||
cb();
|
||||
});
|
||||
},
|
||||
function addToEmbarkConfig(cb) {
|
||||
//TO DO: read from package.json and update the plugins
|
||||
cb();
|
||||
}
|
||||
], (err) => {
|
||||
if(err) {
|
||||
callback(__(err));
|
||||
} else {
|
||||
callback(null, 'npm package successfully installed as a plugin');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -129,17 +129,25 @@ function pingEndpoint(host, port, type, protocol, origin, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function runCmd(cmd, options) {
|
||||
function runCmd(cmd, options, callback) {
|
||||
const shelljs = require('shelljs');
|
||||
let result = shelljs.exec(cmd, options || {silent: true});
|
||||
options = options || {silent: true, exitOnError: true};
|
||||
console.log(cmd, options, typeof callback);
|
||||
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);
|
||||
}
|
||||
exit();
|
||||
if (typeof callback === 'function') {
|
||||
return callback(result, null);
|
||||
}
|
||||
if (options.exitOnError) {
|
||||
exit();
|
||||
}
|
||||
}
|
||||
callback(null, result);
|
||||
}
|
||||
|
||||
function cd(folder) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user