-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·59 lines (48 loc) · 1.11 KB
/
cli.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
#!/usr/bin/env node
import fs from "node:fs/promises";
switch (process.argv[2]) {
case "start":
await start();
break;
case "build":
await build();
break;
case "dev":
await dev();
break;
case "clean":
await clean();
break;
case "help":
console.info(`Usage: jeasx [start|build|dev|clean|help]`);
break;
default:
console.info(
`❌ Error: Unknown command '${process.argv[2]}'.\nUse 'jeasx help' for options.`
);
process.exit(1);
}
async function start() {
await import("./server.js");
}
async function build() {
const argv = [...process.argv];
process.argv = [];
await clean();
await import("./esbuild.config.js");
process.argv = argv;
}
async function dev() {
process.env.NODE_ENV = "development";
// Run build to prepare browser assets for fastify-static
await build();
// Start the dev environment
process.argv[2] = "start";
process.argv[3] ??= "ecosystem.config.cjs";
// @ts-ignore
await import("pm2/bin/pm2-runtime");
}
async function clean() {
await fs.rm("dist", { recursive: true, force: true, maxRetries: 3 });
}
export {};