-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (38 loc) · 1.08 KB
/
index.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
const mustache = require("mustache");
const fs = require("fs");
const path = require("path");
const baseTemp = fs.readFileSync(
path.resolve(__dirname, "./must/base.mustache"),
"utf8"
);
const json = JSON.parse(
fs.readFileSync(path.resolve(__dirname, "./must/data.json"))
);
if (Array.isArray(json?.data)) {
const arr = json.data;
json.data.forEach((datum, i) => {
let htmlContent = null;
if (i === 0) {
htmlContent = mustache.render(baseTemp, datum);
} else {
htmlContent = mustache.render(baseTemp, {
...json.data[0],
...datum,
cssFiles: datum?.cssFiles
? [...json.data[0].cssFiles, ...datum?.cssFiles]
: json.data[0].cssFiles,
jsFiles: datum?.jsFiles
? [...json.data[0].jsFiles, ...datum?.jsFiles]
: json.data[0].jsFiles,
});
}
// console.log(htmlContent);
fs.writeFile(`${datum.file}index.html`, htmlContent, (err) => {
if (err) {
console.log(`Probile while writing to ${datum.file}`);
return;
}
// console.log(err);
});
});
}