added require() method for commonJS compliancy

This commit is contained in:
azivner
2018-03-10 11:53:51 -05:00
parent 354999f37a
commit f6c7f6a0f2
3 changed files with 33 additions and 4 deletions

View File

@@ -1,8 +1,22 @@
function ScriptContext(startNote, allNotes) {
const modules = {};
return {
modules: {},
modules: modules,
notes: toObject(allNotes, note => [note.noteId, note]),
apis: toObject(allNotes, note => [note.noteId, ScriptApi(startNote, note)]),
require: moduleNoteIds => {
return moduleName => {
const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId));
const note = candidates.find(c => c.title === moduleName);
if (!note) {
throw new Error("Could not find module note " + moduleName);
}
return modules[note.noteId].exports;
}
}
};
}