Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Discover and install modules from dependencies listed in package.json #1

Merged
merged 1 commit into from
Sep 30, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Updated afterPluginAddHook.js to discover and install modules from de…
…pendencies listed in package.json
  • Loading branch information
dpa99c committed Sep 27, 2015
commit 4b0c0cf227690144aa7f536334e2c9fdd4cdb050
34 changes: 29 additions & 5 deletions hooks/afterPluginAddHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,34 @@ It will check all necessary module dependencies and install the missing ones loc
*/

var exec = require('child_process').exec,
modules = ['xml2js', 'mkpath', 'rimraf', 'xcode'];
path = require('path'),
cwd = path.resolve(),
modules = ['read-package-json'];

// region NPM specific

/**
* Discovers module dependencies in plugin's package.json and installs those modules.
* @param {String} pluginId - ID of the plugin calling this hook
*/
function getPackagesFromJson(pluginId){
var readJson = require('read-package-json');
readJson(path.join(cwd, 'plugins', pluginId, 'package.json'), console.error, false, function (er, data) {
if (er) {
console.error("There was an error reading the file: "+er);
return;
}
if(data['dependencies']){
for(var k in data['dependencies']){
modules.push(k);
}
installRequiredNodeModules(function(){
console.log('All dependency modules are installed.');
});
}
});
}

/**
* Check if node package is installed.
*
Expand Down Expand Up @@ -49,9 +73,9 @@ function installNodeModule(moduleName, callback) {
/**
* Install all required node packages.
*/
function installRequiredNodeModules() {
function installRequiredNodeModules(callback) {
if (modules.length == 0) {
console.log('All dependency modules are installed.');
callback();
return;
}

Expand All @@ -63,13 +87,13 @@ function installRequiredNodeModules() {
return;
} else {
console.log('Module ' + moduleName + ' is installed');
installRequiredNodeModules();
installRequiredNodeModules(callback);
}
});
}

// endregion

module.exports = function(ctx) {
installRequiredNodeModules();
installRequiredNodeModules(getPackagesFromJson.bind(this, ctx.opts.plugin.id));
};