@air-jam/server 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { existsSync } from "node:fs";
4
+ import path from "node:path";
5
+ import { spawn } from "node:child_process";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
+
8
+ const packageRoot = path.resolve(
9
+ path.dirname(fileURLToPath(import.meta.url)),
10
+ "..",
11
+ );
12
+ const distEntry = path.join(packageRoot, "dist", "cli.js");
13
+ const sourceEntry = path.join(packageRoot, "src", "cli.ts");
14
+
15
+ const forwardToSourceCli = async () =>
16
+ new Promise((resolve, reject) => {
17
+ const child = spawn(
18
+ process.execPath,
19
+ ["--import", "tsx", sourceEntry, ...process.argv.slice(2)],
20
+ {
21
+ cwd: packageRoot,
22
+ stdio: "inherit",
23
+ env: process.env,
24
+ },
25
+ );
26
+
27
+ child.on("exit", (code, signal) => {
28
+ if (signal) {
29
+ process.kill(process.pid, signal);
30
+ return;
31
+ }
32
+
33
+ process.exitCode = code ?? 0;
34
+ resolve(undefined);
35
+ });
36
+
37
+ child.on("error", reject);
38
+ });
39
+
40
+ if (existsSync(distEntry)) {
41
+ const loaded = await import(pathToFileURL(distEntry).href);
42
+ if (typeof loaded.runServerCli === "function") {
43
+ await loaded.runServerCli();
44
+ } else {
45
+ await forwardToSourceCli();
46
+ }
47
+ } else {
48
+ await forwardToSourceCli();
49
+ }