Skip to content

Commit baa4185

Browse files
authored
Add functionality to install modules during init (#233)
* Add functionality to install modules during init Install modules specified in package.json during initialisation as a alternative to packageing them. Detect if the node_modules directory is missing and installes the node modules. * check if package.json has dependencies and install if required * remove trailing whitespace * read package.json correctly as object
1 parent 7e0173b commit baa4185

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

core/nodejsActionBase/runner.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ function initializeActionHandler(message) {
4646
return Promise.reject('Zipped actions must contain either package.json or index.js at the root.');
4747
}
4848

49+
// install npm modules during init if source code zip doesn´t containt them
50+
// check if package.json exists and node_modules don`t
51+
if (fs.existsSync('package.json') && !fs.existsSync('./node_modules/')) {
52+
var package_json = JSON.parse(fs.readFileSync('package.json', 'utf8'));
53+
if (package_json.hasOwnProperty('dependencies')) {
54+
if (Object.keys(package_json.dependencies).length > 0) {
55+
exec("npm install")
56+
}
57+
}
58+
}
59+
4960
// The module to require.
5061
let whatToRequire = index !== undefined ? path.join(moduleDir, index) : moduleDir;
5162
let handler = eval('require("' + whatToRequire + '").' + main);

0 commit comments

Comments
 (0)