2018-03-26 09:29:35 +08:00
|
|
|
import ScriptContext from "./script_context.js";
|
2018-03-27 10:29:14 +08:00
|
|
|
import server from "./server.js";
|
2018-03-26 09:16:57 +08:00
|
|
|
|
|
|
|
async function executeBundle(bundle) {
|
|
|
|
const apiContext = ScriptContext(bundle.note, bundle.allNotes);
|
|
|
|
|
|
|
|
return await (function () {
|
|
|
|
return eval(`const apiContext = this; (async function() { ${bundle.script}\r\n})()`);
|
|
|
|
}.call(apiContext));
|
|
|
|
}
|
|
|
|
|
2018-03-27 10:29:14 +08:00
|
|
|
async function executeStartupBundles() {
|
|
|
|
const scriptBundles = await server.get("script/startup");
|
|
|
|
|
|
|
|
for (const bundle of scriptBundles) {
|
|
|
|
await executeBundle(bundle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-26 09:16:57 +08:00
|
|
|
export default {
|
2018-03-27 10:29:14 +08:00
|
|
|
executeBundle,
|
|
|
|
executeStartupBundles
|
2018-03-26 09:16:57 +08:00
|
|
|
}
|