-
Notifications
You must be signed in to change notification settings - Fork 0
/
static_builder.mjs
executable file
·48 lines (40 loc) · 1.3 KB
/
static_builder.mjs
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
#! node
import { StaticBuilder } from "../core/staticBuilder.mjs";
import { readFile } from "node:fs/promises";
const ARGS_MAP = {
"input": ["-i", "--input"],
"output": ["-o", "--output"],
"log": ["-l", "--log", "-lw", "-wl"],
// TODO: implement watch files and its dependencies change
"watch": ["-w", "--watch", "-lw", "-wl"],
// "importMap": ["-m", "--import-map"]
"config": ["-c", "--config"],
"match": ["-m", "--match"]
};
const PLURAL_ARGS = ["input"];
async function getConfig(args = process.argv.slice(2)) {
const params = {};
for (let i = 0; i < args.length; i += 1) {
const values = Object.entries(ARGS_MAP).filter(([param, flags]) => flags.includes(args[i]));
values.forEach(([param]) => {
if (["watch", "log"].includes(param)) {
params[param] = true;
}
else {
i += 1;
const value = args[i];
if (PLURAL_ARGS.includes(param)) {
params[param] = params[param] ? params[param].concat(value) : [value];
}
else {
params[param] = value;
}
}
})
}
const config = params.config ? JSON.parse(await readFile(params.config)) : {};
return { workdir: process.cwd(), ...config, ...params };
}
const builder = new StaticBuilder(await getConfig());
await builder.build();
await builder.output();