@sudajs/cli 0.0.2 → 0.1.0
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.
- package/bin/suda-dev.js +15 -0
- package/bin/suda.js +34 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +633 -15
- package/dist/index.js.map +1 -1
- package/package.json +11 -5
package/bin/suda-dev.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
|
+
|
|
6
|
+
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const sourceEntry = path.resolve(scriptDir, "../src/index.ts");
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
const mod = await import(pathToFileURL(sourceEntry).href);
|
|
11
|
+
await mod.main();
|
|
12
|
+
} catch (error) {
|
|
13
|
+
console.error(error instanceof Error ? error.message : error);
|
|
14
|
+
process.exitCode = 1;
|
|
15
|
+
}
|
package/bin/suda.js
CHANGED
|
@@ -1,15 +1,48 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
3
5
|
import { existsSync } from "node:fs";
|
|
4
6
|
import path from "node:path";
|
|
5
7
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
8
|
|
|
7
9
|
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const sourceEntry = path.resolve(scriptDir, "../src/index.ts");
|
|
11
|
+
const devRunner = path.resolve(scriptDir, "suda-dev.js");
|
|
8
12
|
const distEntry = path.resolve(scriptDir, "../dist/index.js");
|
|
9
13
|
|
|
14
|
+
if (existsSync(sourceEntry)) {
|
|
15
|
+
const require = createRequire(import.meta.url);
|
|
16
|
+
const tsxLoader = require.resolve("tsx");
|
|
17
|
+
const result = spawnSync(
|
|
18
|
+
process.execPath,
|
|
19
|
+
["--conditions=development", "--import", tsxLoader, devRunner, ...process.argv.slice(2)],
|
|
20
|
+
{
|
|
21
|
+
stdio: "inherit",
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (result.error) {
|
|
26
|
+
console.error(result.error.message);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (result.signal) {
|
|
31
|
+
process.kill(process.pid, result.signal);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
process.exit(result.status ?? 1);
|
|
35
|
+
}
|
|
36
|
+
|
|
10
37
|
if (!existsSync(distEntry)) {
|
|
11
38
|
console.error("@sudajs/cli is not built yet. Run `pnpm --filter @sudajs/cli build` first.");
|
|
12
39
|
process.exit(1);
|
|
13
40
|
}
|
|
14
41
|
|
|
15
|
-
await import(pathToFileURL(distEntry).href);
|
|
42
|
+
const mod = await import(pathToFileURL(distEntry).href);
|
|
43
|
+
try {
|
|
44
|
+
await mod.main();
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(error instanceof Error ? error.message : error);
|
|
47
|
+
process.exitCode = 1;
|
|
48
|
+
}
|