-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·46 lines (38 loc) · 1.35 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
44
45
46
#!/usr/bin/env node
const util = require("util");
const path = require("path");
const mkdirp = require("mkdirp");
const rimraf = util.promisify(require("rimraf"));
const { fs } = require("./lib/files");
const { fetchAll } = require("./lib/fetch");
const { buildStyles } = require("./lib/styles");
const { buildAssets } = require("./lib/assets");
const indexTemplate = require("./templates");
const { Command } = require("commander");
const pkgJson = require("./package.json");
const config = require("./config");
const program = new Command();
program.version(pkgJson.version);
async function main() {
await program.parseAsync(process.argv);
}
program.command("clean").description("clean existing build").action(cleanBuild);
program.command("fetch").description("fetch data sources").action(fetchAll);
program.command("build").description("build the page").action(buildAll);
async function buildAll() {
await buildStyles();
await buildAssets();
await buildIndexPage();
}
async function buildIndexPage() {
const data = JSON.parse(
await fs.readFile(path.join(config.buildPath, "index.json"))
);
const html = indexTemplate({ config, data })();
await fs.writeFile(path.join(config.buildPath, "index.html"), html);
}
async function cleanBuild() {
await rimraf(config.buildPath);
await mkdirp(config.buildPath);
}
main().catch((err) => console.error(err));