Created
April 4, 2018 08:54
-
-
Save bramblex/c927e7724d610ac93d2632ae6022b4f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function startup(zone, module_path) { | |
const code | |
= "eval((function () {" | |
+ " var path = require('path');" | |
+ " var startup_module_path = " + JSON.stringify(module_path) + ";" | |
+ " var startup_module = require(startup_module_path);" | |
+ " var startup_code = Object" | |
+ " .getOwnPropertyNames(startup_module)" | |
+ " .map(function (name) { return { name: name, value: startup_module[name] }; })" | |
+ " .reduce(function (prev, curr) {" | |
+ " if (typeof curr.value === 'function') {" | |
+ " return (prev + 'function ' + curr.name + '() { return require(' + JSON.stringify(startup_module_path) + ').' + curr.name + '.apply(undefined, arguments); };\\n')" | |
+ " } else { return prev; }" | |
+ " }, '');" | |
+ " return startup_code;" | |
+ "})());"; | |
return zone.broadcast(code); | |
} | |
function run(zone, name, args) { | |
return new Promise(function (resolve, reject) { | |
zone.execute(function (_name, _args) { | |
var __args = _args ? _args : []; | |
return global[_name].apply(undefined, _args); | |
}, [name, args]).then(function (result) { | |
resolve(result.value) | |
}).catch(reject) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment