-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
64 lines (55 loc) · 1.6 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
59
60
61
62
63
64
/*
Tsukihi: Zenith internal SSG.
(c) 2020 Zenith, the Eclipse developers, and the Parcility developers.
*/
const fs = require('fs-extra');
const path = require('path');
const pug = require('pug');
const { rmrf, readdir, writeFile } = require('./helpers');
const SITE_INPUT_PATH = 'site';
const SITE_OUTPUT_PATH = 'docs';
const CNAME = "zenithdevs.com"
async function main() {
try {
await rmrf(path.resolve(__dirname, SITE_OUTPUT_PATH));
await fs.mkdir(path.resolve(__dirname, SITE_OUTPUT_PATH));
const dir = await readdir(path.resolve(__dirname, SITE_INPUT_PATH));
// Write CNAME
writeFile(
path.join(__dirname, SITE_OUTPUT_PATH, "CNAME"),
CNAME
)
// Output pug files as html
await Promise.all(
dir
.filter((file) => file.split('.').pop() === 'pug')
.map((res) => [
res.replace('.pug', '.html'),
pug.renderFile(
path.resolve(__dirname, SITE_INPUT_PATH, res),
{
"projects": JSON.parse(fs.readFileSync(path.resolve(__dirname, SITE_INPUT_PATH + "/data/projects.json"), 'utf8'))
}
),
])
.map(([name, html]) =>
writeFile(
path.join(__dirname, SITE_OUTPUT_PATH, name),
html
)
)
);
// Copy assets folder
await fs.copy(
path.resolve(__dirname, SITE_INPUT_PATH, 'assets'),
path.resolve(__dirname, SITE_OUTPUT_PATH, 'assets')
);
console.log(
`Successfully built & outputted the website at \x1b[36mdocs/\x1b[0m.`
);
// console.log(`Successfully renamed & moved the directory to \x1b[36mdocs/${dir}\x1b[0m.`);
} catch (error) {
console.error('An error occurred while building the site:', error);
}
}
main();