1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- 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.state("installed");
- //context.emit('installed');
- return;
- }
- if(this.runPath == undefined) {
- log.warn("There is no bundlePath configured");
- this.installed = true;
- context.state("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");
- this.installed = true;
- context.state('installed');
- });
- 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;
|