This repository has been archived by the owner on Dec 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmod.ts
57 lines (52 loc) · 1.69 KB
/
mod.ts
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
#!/usr/bin/env -S deno --unstable --allow-read --allow-write --allow-net
export { React, ReactDOM, ReactDOMServer } from "./deps.ts";
export { t, Trans } from "./src/plugins/i18n.tsx";
import Gagic from "./src/Gagic.ts";
import { logger } from "./src/utils/mod.ts";
export default Gagic;
export * from "./src/Gagic.ts";
if (import.meta.main) {
const [subCommand, ...restArgs] = Deno.args;
if (subCommand === undefined) {
logger.info(` Miss valid subCommand, known as 'gagic build'.`);
Deno.exit(1);
}
const validSubCommands = ["build"];
if (!validSubCommands.includes(subCommand)) {
throw new Error(`Invalid subCommand ${subCommand}`);
}
const validOptions = ["serve", "watch", "port"];
let options: { [key: string]: any } = {};
for (let i = 0; i < restArgs.length; i++) {
const currentArg = restArgs[i];
const nextArg = restArgs[i + 1];
if (currentArg.startsWith("--")) {
const key = currentArg.slice(2);
if (!validOptions.includes(key)) {
throw new Error(`Invalid option ${key}`);
}
if (typeof nextArg === "undefined" || nextArg.startsWith("-")) {
options[key] = true;
} else {
if (Number(nextArg).toString() === nextArg) {
options[key] = Number(nextArg);
} else {
options[key] = nextArg;
}
i++;
}
} else if (currentArg.startsWith("-")) {
const key = currentArg.slice(1);
if (!validOptions.includes(key)) {
throw new Error(`Invalid option ${key}`);
}
options[key] = true;
} else {
throw new Error(`Invalid args ${currentArg}`);
}
}
const gagic = new Gagic(options);
if (subCommand === "build") {
gagic.build();
}
}