-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (33 loc) · 1.14 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 handlebars = require("handlebars");
const fs = require("fs");
const path = require("path");
const buildDir = "./build";
const jsDir = "./js";
const cssDir = "./css";
const iconDir = "./favicon";
const contentDir = "./content";
const copy = (source, extentions, destination) => {
const files = fs
.readdirSync(source)
.filter((file) =>
[...extentions].includes(path.extname(file).substring(1))
);
files.forEach((file) => {
fs.copyFileSync(path.join(source, file), path.join(destination, file));
});
};
const content = [];
const jsonFiles = fs
.readdirSync(contentDir)
.filter((file) => path.extname(file) === ".json");
jsonFiles.forEach((file) => {
const fileContent = fs.readFileSync(path.join(contentDir, file));
content.push(JSON.parse(fileContent.toString()));
});
fs.rmdirSync(buildDir, { recursive: true, force: true });
fs.mkdirSync(buildDir);
const template = handlebars.compile(fs.readFileSync("./template.hbt", "utf8"));
fs.writeFileSync(`${buildDir}/index.html`, template(content));
copy(jsDir, ["js"], buildDir);
copy(cssDir, ["css"], buildDir);
copy(iconDir, ["png", "xml", "ico", "json"], buildDir);