-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-plugin.js
More file actions
35 lines (29 loc) · 948 Bytes
/
install-plugin.js
File metadata and controls
35 lines (29 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// post npm install action
const fs = require('fs');
const exec = require('child_process').exec;
module.exports = class Installer {
constructor () {
this.packagePath = process.cwd() + '/package.json';
this.package = require(this.packagePath);
this.addons = (this.package.addons && this.package.addons.filter && this.package.addons) || [];
}
install () {
this.addons.forEach(addon => this.addToDependencies(addon));
fs.writeFileSync(this.packagePath, JSON.stringify(this.package, null, 2), 'utf8');
this.npmInstall();
}
npmInstall () {
console.log('installing dependencies...');
exec('npm install', { cwd : process.cwd() }, (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
console.log(stdout);
});
}
addToDependencies (addon) {
let addonName = Object.keys(addon)[0];
this.package.dependencies[addonName] = addon[addonName];
}
}