UNPKG

1.67 kBJavaScriptView Raw
1import { commandsAndFlags } from "./lib/commandsAndFlags.js";
2import { createDebugger } from "./lib/createDebugger.js";
3import { hasHelp, hasVersion } from "./lib/hasFlag.js";
4import { pkg } from "./lib/pkg.js";
5const debugCLI = createDebugger("akte:cli");
6const exit = (code) => {
7 debugCLI("done");
8 process.exit(code);
9};
10const displayHelp = () => {
11 debugCLI.log(`
12 Akte CLI
13
14 DOCUMENTATION
15 https://akte.js.org
16
17 VERSION
18 ${pkg.name}@${pkg.version}
19
20 USAGE
21 $ node akte.app.js <command>
22 $ npx tsx akte.app.ts <command>
23
24 COMMANDS
25 build Build Akte to file system
26
27 OPTIONS
28 --silent, -s Silence output
29
30 --help, -h Display CLI help
31 --version, -v Display CLI version
32`);
33 exit(0);
34};
35const displayVersion = () => {
36 debugCLI.log(`${pkg.name}@${pkg.version}`);
37 exit(0);
38};
39const build = async (app) => {
40 debugCLI.log("\nAkte → Beginning build...\n");
41 await app.buildAll();
42 const buildTime = `${Math.ceil(performance.now())}ms`;
43 debugCLI.log("\nAkte → Done in %o", buildTime);
44 return exit(0);
45};
46const runCLI = async (app) => {
47 debugCLI("started");
48 process.title = "Akte CLI";
49 if (hasHelp()) {
50 debugCLI("displaying help");
51 return displayHelp();
52 } else if (hasVersion()) {
53 debugCLI("displaying version");
54 return displayVersion();
55 }
56 const [command] = commandsAndFlags();
57 switch (command) {
58 case "build":
59 debugCLI("running %o command", command);
60 return build(app);
61 default:
62 debugCLI.log(`Akte → Unknown command \`${command}\`, use \`--help\` flag for manual`);
63 exit(2);
64 }
65};
66export {
67 runCLI
68};
69//# sourceMappingURL=runCLI.js.map