-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·70 lines (56 loc) · 1.71 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
import util from "util";
import mkdirp from "mkdirp";
import rimrafOrig from "rimraf";
import { Command } from "commander";
import config from "./config.js";
import { copyAssets } from "./lib/assets.js";
import { loadAllPosts, buildAllPosts } from "./lib/posts.js";
import { buildAllIndexes } from "./lib/indexes.js";
const rimraf = util.promisify(rimrafOrig);
const program = new Command();
program.version("0.0.1");
async function main() {
await program.parseAsync(process.argv);
}
program
.command("clean")
.description("clean up an existing build")
.action(cleanBuild);
async function cleanBuild() {
await rimraf(config.buildPath);
await mkdirp(config.buildPath);
}
program
.command("build")
.description("clean and build all posts, indexes, and assets")
.option("-c, --clean", "clean before building and copying assets")
.action(buildAll);
async function buildAll(options) {
if (options.clean) await cleanBuild();
await copyAssets();
const posts = await loadAllPosts();
await buildAllPosts(posts);
await buildAllIndexes(posts);
}
program
.command("build-posts [globs...]")
.description("build posts matching glob (or all posts if omitted)")
.action(buildPosts);
async function buildPosts(postsGlob) {
await buildAllPosts(await loadAllPosts(postsGlob));
}
program
.command("build-indexes [globs...]")
.description(
"build indexes for posts matching glob (or all posts if omitted)"
)
.action(buildIndexes);
async function buildIndexes(postsGlob) {
await buildAllIndexes(await loadAllPosts(postsGlob));
}
program
.command("build-assets")
.description("build shared assets like JS & CSS")
.action(copyAssets);
main().catch((err) => console.error(err));