diff --git a/src/plugins/compile-time-js.ts b/src/plugins/compile-time-js.ts new file mode 100644 index 0000000..778b1be --- /dev/null +++ b/src/plugins/compile-time-js.ts @@ -0,0 +1,25 @@ +import { Plugin } from ".."; + +export default class CompileTimeJS extends Plugin { + name = "compile-time-js"; + rewriteTriggers = ["html", "*"] + longLasting = false; + build = undefined; + + async rewriteFile(file: string, filePath: string): Promise { + let input = file; + const regex = /{&(.+)&}/gm; + + let m; + + while ((m = regex.exec(file)) !== null) { + if (m.index === regex.lastIndex) { + regex.lastIndex++; + } + + input = file.slice(0, m.index) + eval(m[1]) + file.slice(m.index + m[0].length); + } + + return input; + } +} \ No newline at end of file