diff --git a/Instance.js b/Instance.js index 8b2d6a5..1eab447 100644 --- a/Instance.js +++ b/Instance.js @@ -1,6 +1,10 @@ import Serializable from './Serializable.js'; import minify from './minify.js'; +import debug from 'debug'; +import _ from 'lodash'; +const log = debug('vogue:instance'); + export default class Instance extends Serializable { module = null; @@ -58,10 +62,12 @@ export default class Instance extends Serializable { } invokeInternal(name, ...args) { - // console.log('invoking', name); - const content = this.module.functions[name]; + log('invoking', this.module.name.full + '.' + name, 'with args', args); + const content = this.module.functions[name].code; + const passingArguments = _.zipObject(this.module.functions[name].parameters, args); + log('arguments obj', passingArguments); if(!content) throw new TypeError(name + ' is not a function!'); - return evalInContext(content, this.context, this.locals); + return evalInContext(content, this.context, this.locals, passingArguments); } get link () { @@ -69,21 +75,26 @@ export default class Instance extends Serializable { } } -minify() - -function evalInContext(js, context, locals) { +function evalInContext(js, context, locals, passingArguments) { //# Return the results of the in-line anonymous function we .call with the passed context + log('='.repeat(80) + 'OG Block'); + log(js); + log('='.repeat(80) + 'Arguments'); + log(passingArguments); const that = this; return function() { - const preminJs = ` - 'use strict'; - (() => { - ${locals.map((k) => ` - const ${k} = this.${k}; - `).join('\n')} - ${js}; - })();`; + const preminJs = +`'use strict'; +(() => { + ${locals.map((k) => `const ${k} = this.${k};`).join('\n\t')} + ${Object.keys(passingArguments).map(name => `let ${name} = passingArguments.${name};`).join('\n\t')} + ${js} +})();`; + log('='.repeat(80) + 'preminjs'); + log(preminJs); const newJs = minify(preminJs); + log('='.repeat(80) + 'minjs'); + log(newJs); // newJs should inject into result... let result; eval(newJs); diff --git a/Module.js b/Module.js index c66ac9f..00c2c4e 100644 --- a/Module.js +++ b/Module.js @@ -47,8 +47,11 @@ export default class Module { this.name.full = this.name.space + '.' + this.name.last; } - async function({name, block}) { - this.functions[name] = block; + async function({name, block, parameters}) { + this.functions[name] = { + code: block, + parameters + }; } async import({importName, name}) { diff --git a/minify.js b/minify.js index bfa6e3c..e2ea8d8 100644 --- a/minify.js +++ b/minify.js @@ -1,5 +1,6 @@ import uglify from 'uglify-js'; + export default (code) => { return uglify.minify(code, { compress: { @@ -7,6 +8,9 @@ export default (code) => { global_defs: { DEBUG: false } + }, + sourceMap: { + content: 'inline' } }).code; } \ No newline at end of file diff --git a/test/interface.v b/test/interface.v index 9419f15..e2bf2ae 100644 --- a/test/interface.v +++ b/test/interface.v @@ -3,30 +3,39 @@ static Interface; import 'terminal-kit' as terminalKit; +restore { + const {terminal} = terminalKit; + terminal.grabInput(); + terminal.on('key', function(name, matches, data) { + + if (name === 'CTRL_C') { + process.exit(2); + } + }); +} + choice(message, choices, type) { - console.log('im being called!'); - // const {terminal} = terminalKit; - // type ??= 'string'; + const {terminal} = terminalKit; + type ??= 'string'; - // return new Promise(res => { + return new Promise(res => { - // terminal.saveCursor(); - // // terminal(message.split(/\x1b\[39m/g).join(', ')); - // // const loc = await new Promise (res => terminal.getCursorLocation((err, x, y) => res([x, y]))); - // for(const part of message.split(/\x1b\[39m/g)) { - // terminal.cyan(part); - // } - // terminal.cyan('\n'); + terminal.saveCursor(); - // terminal.singleColumnMenu(choices, (error, response) => { - // terminal.restoreCursor(); - // terminal.cyan(`${message} `); - // terminal(response.selectedText + '\n').eraseDisplayBelow(); - // if(type === 'string') { - // res(response.selectedText); - // } else { - // res(response.selectedIndex); - // } - // }); - // }); + for(const part of message.split(/\x1b\[39m/g)) { + terminal.cyan(part); + } + terminal.cyan('\n'); + + terminal.singleColumnMenu(choices, (error, response) => { + terminal.restoreCursor(); + terminal.cyan(`${message} `); + terminal(response.selectedText + '\n').eraseDisplayBelow(); + if(type === 'string') { + res(response.selectedText); + } else { + res(response.selectedIndex); + } + }); + }); } \ No newline at end of file