Bring in some of the good parts of dropfile-updates branch

This commit is contained in:
Bryan Ashby 2018-06-22 23:06:01 -06:00
commit ef12cc0cfb
4 changed files with 207 additions and 236 deletions

View file

@ -2,18 +2,14 @@
'use strict';
const MenuModule = require('./menu_module.js').MenuModule;
const DropFile = require('./dropfile.js').DropFile;
const door = require('./door.js');
const DropFile = require('./dropfile.js');
const Door = require('./door.js');
const theme = require('./theme.js');
const ansi = require('./ansi_term.js');
const async = require('async');
const assert = require('assert');
const paths = require('path');
const _ = require('lodash');
const mkdirs = require('fs-extra').mkdirs;
// :TODO: This should really be a system module... needs a little work to allow for such
const activeDoorNodeInstances = {};
@ -65,6 +61,7 @@ exports.getModule = class AbracadabraModule extends MenuModule {
this.config = options.menuConfig.config;
// :TODO: MenuModule.validateConfig(cb) -- validate config section gracefully instead of asserts! -- { key : type, key2 : type2, ... }
// .. and/or EnigAssert
assert(_.isString(this.config.name, 'Config \'name\' is required'));
assert(_.isString(this.config.dropFileType, 'Config \'dropFileType\' is required'));
assert(_.isString(this.config.cmd, 'Config \'cmd\' is required'));
@ -122,19 +119,17 @@ exports.getModule = class AbracadabraModule extends MenuModule {
callback(null);
}
},
function prepareDoor(callback) {
self.doorInstance = new Door(self.client);
return self.doorInstance.prepare(self.config.io || 'stdio', callback);
},
function generateDropfile(callback) {
self.dropFile = new DropFile(self.client, self.config.dropFileType);
var fullPath = self.dropFile.fullPath;
const dropFileOpts = {
fileType : self.config.dropFileType,
};
mkdirs(paths.dirname(fullPath), function dirCreated(err) {
if(err) {
callback(err);
} else {
self.dropFile.createFile(function created(err) {
callback(err);
});
}
});
self.dropFile = new DropFile(self.client, dropFileOpts);
return self.dropFile.createFile(callback);
}
],
function complete(err) {
@ -150,20 +145,19 @@ exports.getModule = class AbracadabraModule extends MenuModule {
}
runDoor() {
this.client.term.write(ansi.resetScreen());
const exeInfo = {
cmd : this.config.cmd,
args : this.config.args,
io : this.config.io || 'stdio',
encoding : this.config.encoding || this.client.term.outputEncoding,
dropFile : this.dropFile.fileName,
node : this.client.node,
//inhSocket : this.client.output._handle.fd,
cmd : this.config.cmd,
args : this.config.args,
io : this.config.io || 'stdio',
encoding : this.config.encoding || this.client.term.outputEncoding,
dropFile : this.dropFile.fileName,
dropFilePath : this.dropFile.fullPath,
node : this.client.node,
};
const doorInstance = new door.Door(this.client, exeInfo);
doorInstance.once('finished', () => {
this.doorInstance.run(exeInfo, () => {
//
// Try to clean up various settings such as scroll regions that may
// have been set within the door
@ -178,10 +172,6 @@ exports.getModule = class AbracadabraModule extends MenuModule {
this.prevMenu();
});
this.client.term.write(ansi.resetScreen());
doorInstance.run();
}
leave() {