parameterized function calls! Closes #9
parent
2d7c0442e0
commit
de938bb993
39
Instance.js
39
Instance.js
|
|
@ -1,6 +1,10 @@
|
||||||
|
|
||||||
import Serializable from './Serializable.js';
|
import Serializable from './Serializable.js';
|
||||||
import minify from './minify.js';
|
import minify from './minify.js';
|
||||||
|
import debug from 'debug';
|
||||||
|
import _ from 'lodash';
|
||||||
|
const log = debug('vogue:instance');
|
||||||
|
|
||||||
|
|
||||||
export default class Instance extends Serializable {
|
export default class Instance extends Serializable {
|
||||||
module = null;
|
module = null;
|
||||||
|
|
@ -58,10 +62,12 @@ export default class Instance extends Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
invokeInternal(name, ...args) {
|
invokeInternal(name, ...args) {
|
||||||
// console.log('invoking', name);
|
log('invoking', this.module.name.full + '.' + name, 'with args', args);
|
||||||
const content = this.module.functions[name];
|
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!');
|
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 () {
|
get link () {
|
||||||
|
|
@ -69,21 +75,26 @@ export default class Instance extends Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
minify()
|
function evalInContext(js, context, locals, passingArguments) {
|
||||||
|
|
||||||
function evalInContext(js, context, locals) {
|
|
||||||
//# Return the results of the in-line anonymous function we .call with the passed context
|
//# 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;
|
const that = this;
|
||||||
return function() {
|
return function() {
|
||||||
const preminJs = `
|
const preminJs =
|
||||||
'use strict';
|
`'use strict';
|
||||||
(() => {
|
(() => {
|
||||||
${locals.map((k) => `
|
${locals.map((k) => `const ${k} = this.${k};`).join('\n\t')}
|
||||||
const ${k} = this.${k};
|
${Object.keys(passingArguments).map(name => `let ${name} = passingArguments.${name};`).join('\n\t')}
|
||||||
`).join('\n')}
|
${js}
|
||||||
${js};
|
})();`;
|
||||||
})();`;
|
log('='.repeat(80) + 'preminjs');
|
||||||
|
log(preminJs);
|
||||||
const newJs = minify(preminJs);
|
const newJs = minify(preminJs);
|
||||||
|
log('='.repeat(80) + 'minjs');
|
||||||
|
log(newJs);
|
||||||
// newJs should inject into result...
|
// newJs should inject into result...
|
||||||
let result;
|
let result;
|
||||||
eval(newJs);
|
eval(newJs);
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,11 @@ export default class Module {
|
||||||
this.name.full = this.name.space + '.' + this.name.last;
|
this.name.full = this.name.space + '.' + this.name.last;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function({name, block}) {
|
async function({name, block, parameters}) {
|
||||||
this.functions[name] = block;
|
this.functions[name] = {
|
||||||
|
code: block,
|
||||||
|
parameters
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async import({importName, name}) {
|
async import({importName, name}) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
import uglify from 'uglify-js';
|
import uglify from 'uglify-js';
|
||||||
|
|
||||||
export default (code) => {
|
export default (code) => {
|
||||||
return uglify.minify(code, {
|
return uglify.minify(code, {
|
||||||
compress: {
|
compress: {
|
||||||
|
|
@ -7,6 +8,9 @@ export default (code) => {
|
||||||
global_defs: {
|
global_defs: {
|
||||||
DEBUG: false
|
DEBUG: false
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
sourceMap: {
|
||||||
|
content: 'inline'
|
||||||
}
|
}
|
||||||
}).code;
|
}).code;
|
||||||
}
|
}
|
||||||
|
|
@ -3,30 +3,39 @@ static Interface;
|
||||||
|
|
||||||
import 'terminal-kit' as terminalKit;
|
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) {
|
choice(message, choices, type) {
|
||||||
console.log('im being called!');
|
const {terminal} = terminalKit;
|
||||||
// const {terminal} = terminalKit;
|
type ??= 'string';
|
||||||
// type ??= 'string';
|
|
||||||
|
|
||||||
// return new Promise(res => {
|
return new Promise(res => {
|
||||||
|
|
||||||
// terminal.saveCursor();
|
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.singleColumnMenu(choices, (error, response) => {
|
for(const part of message.split(/\x1b\[39m/g)) {
|
||||||
// terminal.restoreCursor();
|
terminal.cyan(part);
|
||||||
// terminal.cyan(`${message} `);
|
}
|
||||||
// terminal(response.selectedText + '\n').eraseDisplayBelow();
|
terminal.cyan('\n');
|
||||||
// if(type === 'string') {
|
|
||||||
// res(response.selectedText);
|
terminal.singleColumnMenu(choices, (error, response) => {
|
||||||
// } else {
|
terminal.restoreCursor();
|
||||||
// res(response.selectedIndex);
|
terminal.cyan(`${message} `);
|
||||||
// }
|
terminal(response.selectedText + '\n').eraseDisplayBelow();
|
||||||
// });
|
if(type === 'string') {
|
||||||
// });
|
res(response.selectedText);
|
||||||
|
} else {
|
||||||
|
res(response.selectedIndex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Reference in New Issue