better build pipeline

This commit is contained in:
2021-04-23 13:01:16 +02:00
parent 8b86e8ea40
commit 288927e74c
14 changed files with 134 additions and 83 deletions

35
build/build.js Normal file
View File

@@ -0,0 +1,35 @@
const fs = require("fs")
const Mustache = require('mustache');
// Load template
const htmlTemplate = fs.readFileSync("build/template/editor.html.mustache").toString()
const nodes = fs.readdirSync("src/nodes")
nodes.forEach((e)=>{
// Load html parts
const helpHtml = fs.readFileSync(`src/nodes/${e}/ui/editor.html`)
const editorHtml = fs.readFileSync(`src/nodes/${e}/ui/editor.html`)
// Load complied editor index js/ts
let indexHtml = fs.readFileSync(`dist/nodes/${e}/ui/index.js`).toString()
// Cut first 2 lines because typescript inserts some stuff that the browser does not like
// TODO: is is ugly but it works
const tmp = indexHtml.split("\n")
tmp.splice(0,2)
indexHtml = tmp.join("\n")
// Prepare view object to be injected into render
const view = {
helpHtml,
editorHtml,
indexHtml,
nodeName: e
}
const html = Mustache.render(htmlTemplate, view);
// Write generated html into dist
fs.writeFileSync(`dist/nodes/${e}/${e}.html`,html)
})