aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backend-ui/build.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backend-ui/build.mjs')
-rwxr-xr-xpackages/merchant-backend-ui/build.mjs23
1 files changed, 14 insertions, 9 deletions
diff --git a/packages/merchant-backend-ui/build.mjs b/packages/merchant-backend-ui/build.mjs
index 21c4068a4..5ca199e2f 100755
--- a/packages/merchant-backend-ui/build.mjs
+++ b/packages/merchant-backend-ui/build.mjs
@@ -74,34 +74,39 @@ function git_hash() {
return fs.readFileSync(path.join(GIT_ROOT, ".git", rev)).toString().trim();
}
}
+function toCamelCaseName(name) {
+ return name
+ .replace(/^[A-Z]/, letter => `${letter.toLowerCase()}`) //first letter lowercase
+ .replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`) //snake case
+ .concat(".en.html"); //extension
+}
function templatePlugin(options) {
return {
name: "template-backend",
setup(build) {
build.onEnd(() => {
- for (const page of options.pages) {
- const css = fs.readFileSync(path.join(build.initialOptions.outdir, `${page}.css`),"utf8").toString()
- const js = fs.readFileSync(path.join(build.initialOptions.outdir, `${page}.js`),"utf8").toString()
- const scripts = `<script>${js}</script>`
- const style = `<style>${css}</style>`
+ for (const pageName of options.pages) {
+ const css = fs.readFileSync(path.join(build.initialOptions.outdir, `${pageName}.css`),"utf8").toString()
+ const js = fs.readFileSync(path.join(build.initialOptions.outdir, `${pageName}.js`),"utf8").toString()
+ const location = path.join(build.initialOptions.outdir, toCamelCaseName(pageName))
const render = new Function(`${js}; return page.buildTimeRendering();`)()
- const html = `
+ const html = `
<!doctype html>
<html>
<head>
${render.head}
- ${style}
+ <style>${css}</style>
</head>
<script id="built_time_data">
</script>
<body>
${render.body}
- ${scripts}
+ <script>${js}</script>
<script>page.mount()</script>
</body>
</html>`
- fs.writeFileSync(path.join(build.initialOptions.outdir, `${page}.html`), html);
+ fs.writeFileSync(location, html);
}
});
},