123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- var log = require('hlogger').createLogger("installer");
- var fs = require('fs');
- var path = require('path');
- var unzip = require('unzip');
- var exec = require('child_process').exec;
- var HitCounter = require('./hit-counter');
- var installerActivator = {
- start(context) {
- // With config
- this.deployPath = context.manager.config.deployPath;
- this.runPath = context.manager.config.runPath;
- if(this.deployPath == undefined) {
- log.warn("There is no deploy path configured");
- context.toggleOn('installed');
- return;
- }
- if(this.runPath == undefined) {
- log.warn("There is no bundlePath configured");
- context.toggleOn('installed');
- return;
- }
- var self = this;
- log.info("Deploy: " + this.deployPath +", runPath: " + this.runPath);
- var mods = fs.readdirSync(this.deployPath);
- var hitCounter = new HitCounter(mods.length, () => {
- log.info("Emitting installed");
- context.toggleOn('installed',context);
- });
- for(var v of mods) {
- if(!v.endsWith(".zip")) {
- log.warn("Ignoring file in deploy: " + v);
- hitCounter.hit();
- continue;
- }
- this.installPlugin(path.resolve( path.join(this.deployPath,v)), hitCounter.hit.bind(hitCounter));
- }
- },
- installPlugin(fullPath,cb) {
- log.info("Intalling: " + fullPath);
- var basename = path.basename(fullPath,".zip");
- log.info("Base name: " + basename);
- var sourceZip = fullPath;
- var modTargetPath = path.join(this.runPath,basename);
- if(fs.existsSync(modTargetPath)) {
- log.verb("Already exists ignoring");
- if(!fs.existsSync(modTargetPath + "/node_modules")) {
- installNpm(modTargetPath,cb);
- } else {
- cb();
- }
- return;
- }
- fs.mkdirSync(modTargetPath);
- fs.createReadStream(sourceZip)
- .pipe(unzip.Extract({path: modTargetPath}))
- .on('close',() => {
- this.installNpm(modTargetPath,cb);
- });
- },
- installNpm(modTargetPath,cb) {
- var child = exec("npm install", {cwd: modTargetPath});
- child.on('close',cb);
- child.stdout.pipe(process.stdout);
- child.stderr.pipe(process.stderr);
- }
- }
- module.exports.bundleActivator = installerActivator;
|