Fixes to npm command parsing

This commit is contained in:
Subramanian Venkatesan 2018-09-10 16:19:37 +05:30
parent 78bc27ad95
commit 53de6dcb19
2 changed files with 14 additions and 8 deletions

View File

@ -132,7 +132,7 @@ class Engine {
}
pluginCommandService() {
this.registerModule('plugin_cmd', {embarkConfig: this.embarkConfig});
this.registerModule('plugin_cmd', {embarkConfigFile: this.embarkConfig, packageFile: 'package.json'});
}
namingSystem(_options) {

View File

@ -1,17 +1,18 @@
let fs = require('./../../core/fs.js');
let utils = require('./../../utils/utils.js');
let async = require('async');
class PluginCommand {
constructor(embark, config) {
this.embark = embark;
this.config = config;
this.embarkConfig = fs.readJSONSync(this.config.embarkConfig);
this.embarkConfig = fs.readJSONSync(this.config.embarkConfigFile);
this.registerCommands();
}
registerCommands() {
this.embark.registerConsoleCommand((cmd, _options) => {
const self = this;
self.embark.registerConsoleCommand((cmd, _options) => {
let cmdArray = cmd.split(' ');
cmdArray = cmdArray.filter(cmd => cmd.trim().length > 0);
let cmdName = cmdArray[0];
return {
match: () => cmdName === 'plugin',
@ -24,10 +25,10 @@ class PluginCommand {
if(typeof cmdArray[3] === 'undefined') {
return callback(__('npm package argument missing'));
}
npmInstall = npmInstall.concat(cmdArray);
} else {
npmInstall = npmInstall.concat(['--save'].concat(cmdArray.slice(2)));
npmInstall.push('--save');
}
npmInstall = npmInstall.concat(cmdArray.slice(2));
async.waterfall([
function npmInstallAsync(cb) {
@ -39,8 +40,13 @@ class PluginCommand {
});
},
function addToEmbarkConfig(cb) {
//TO DO: read from package.json and update the plugins
cb();
// 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) {