mirror of https://github.com/embarklabs/embark.git
Fixes to npm command parsing
This commit is contained in:
parent
78bc27ad95
commit
53de6dcb19
|
@ -132,7 +132,7 @@ class Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginCommandService() {
|
pluginCommandService() {
|
||||||
this.registerModule('plugin_cmd', {embarkConfig: this.embarkConfig});
|
this.registerModule('plugin_cmd', {embarkConfigFile: this.embarkConfig, packageFile: 'package.json'});
|
||||||
}
|
}
|
||||||
|
|
||||||
namingSystem(_options) {
|
namingSystem(_options) {
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
let fs = require('./../../core/fs.js');
|
let fs = require('./../../core/fs.js');
|
||||||
let utils = require('./../../utils/utils.js');
|
let utils = require('./../../utils/utils.js');
|
||||||
let async = require('async');
|
let async = require('async');
|
||||||
|
|
||||||
class PluginCommand {
|
class PluginCommand {
|
||||||
constructor(embark, config) {
|
constructor(embark, config) {
|
||||||
this.embark = embark;
|
this.embark = embark;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.embarkConfig = fs.readJSONSync(this.config.embarkConfig);
|
this.embarkConfig = fs.readJSONSync(this.config.embarkConfigFile);
|
||||||
this.registerCommands();
|
this.registerCommands();
|
||||||
}
|
}
|
||||||
registerCommands() {
|
registerCommands() {
|
||||||
this.embark.registerConsoleCommand((cmd, _options) => {
|
const self = this;
|
||||||
|
self.embark.registerConsoleCommand((cmd, _options) => {
|
||||||
let cmdArray = cmd.split(' ');
|
let cmdArray = cmd.split(' ');
|
||||||
|
cmdArray = cmdArray.filter(cmd => cmd.trim().length > 0);
|
||||||
let cmdName = cmdArray[0];
|
let cmdName = cmdArray[0];
|
||||||
return {
|
return {
|
||||||
match: () => cmdName === 'plugin',
|
match: () => cmdName === 'plugin',
|
||||||
|
@ -24,10 +25,10 @@ class PluginCommand {
|
||||||
if(typeof cmdArray[3] === 'undefined') {
|
if(typeof cmdArray[3] === 'undefined') {
|
||||||
return callback(__('npm package argument missing'));
|
return callback(__('npm package argument missing'));
|
||||||
}
|
}
|
||||||
npmInstall = npmInstall.concat(cmdArray);
|
|
||||||
} else {
|
} else {
|
||||||
npmInstall = npmInstall.concat(['--save'].concat(cmdArray.slice(2)));
|
npmInstall.push('--save');
|
||||||
}
|
}
|
||||||
|
npmInstall = npmInstall.concat(cmdArray.slice(2));
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function npmInstallAsync(cb) {
|
function npmInstallAsync(cb) {
|
||||||
|
@ -39,8 +40,13 @@ class PluginCommand {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function addToEmbarkConfig(cb) {
|
function addToEmbarkConfig(cb) {
|
||||||
//TO DO: read from package.json and update the plugins
|
// get the installed package from package.json
|
||||||
cb();
|
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) => {
|
], (err) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
|
|
Loading…
Reference in New Issue