-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
58 lines (50 loc) · 1.23 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { exec } from "child_process";
import fs from "fs";
import path from "path";
import ejs from "ejs";
(async () => {
let start = Date.now();
const renderOptions = { rmWhitespace: true };
const components = {};
const vcomponents = fs.readdirSync("src/sfc/");
for (let i = 0; i < vcomponents.length; i++) {
let f = vcomponents[i];
await new Promise((resolve, reject) => {
ejs.renderFile(
path.resolve("./src/sfc/"+f),
null,
renderOptions,
(e, result) => {
if (e) reject(e);
else {
let [html, js] = result.split("<script>");
js = js.slice(0, js.match("</script>").index);
components[f.slice(0, -4)] = { html, js };
resolve();
}
}
)
});
};
let files = fs.readdirSync("src").filter(f => f.endsWith(".ejs"));
for (let i = 0; i < files.length; i++) {
let f = files[i];
let inp = "./src/"+f;
let out = "dist/"+f.slice(0,-4)+".html";
ejs.renderFile(
inp,
{ components },
renderOptions,
write
);
function write(e, html) {
if (e) {
console.error(e);
} else {
fs.writeFileSync(out, html, "utf-8");
console.log("Completed "+out);
}
}
}
console.log("Done in "+(Date.now()-start)+"ms");
})();