inclusion of scripts based on script environment

This commit is contained in:
azivner
2018-03-05 23:09:36 -05:00
parent b3209a9bbf
commit d26170762b
2 changed files with 24 additions and 3 deletions

View File

@@ -60,7 +60,7 @@ async function getRenderScript(note) {
+ bundle.html;
}
async function getScriptBundle(note, includedNoteIds = []) {
async function getScriptBundle(note, scriptEnv, includedNoteIds = []) {
if (!note.isJavaScript() && !note.isHtml() && note.type !== 'render') {
return;
}
@@ -69,6 +69,10 @@ async function getScriptBundle(note, includedNoteIds = []) {
return;
}
if (!scriptEnv) {
scriptEnv = note.getScriptEnv();
}
const bundle = {
note: note,
script: '',
@@ -82,10 +86,16 @@ async function getScriptBundle(note, includedNoteIds = []) {
includedNoteIds.push(note.noteId);
bundle.script = `api.__modules['${note.noteId}'] = { __noteId: '${note.noteId}', __env: '${note.getScriptEnv()}'};`;
if (note.type !== 'file' && scriptEnv !== note.getScriptEnv()) {
return bundle;
}
const modules = [];
for (const child of await note.getChildren()) {
const childBundle = await getScriptBundle(child, includedNoteIds);
const childBundle = await getScriptBundle(child, scriptEnv, includedNoteIds);
if (childBundle) {
modules.push(childBundle.note);
@@ -97,7 +107,6 @@ async function getScriptBundle(note, includedNoteIds = []) {
if (note.isJavaScript()) {
bundle.script += `
api.__modules['${note.noteId}'] = {};
await (async function(exports, module, api, startNote, currentNote` + (modules.length > 0 ? ', ' : '') +
modules.map(child => child.title).join(', ') + `) {
${note.content}