@sudajs/cli 0.0.2 → 0.1.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,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,55 @@
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
+ // Run the CLI from its TypeScript sources via tsx, but DO NOT pass
16
+ // `--conditions=development` here. That flag is process-wide and would also
17
+ // affect how the CLI resolves third-party packages (e.g. `@sudajs/theme-engine`)
18
+ // when invoked against an *external* theme project, causing Node to try to
19
+ // import the engine's `src/*.ts` (which does not exist in published packages)
20
+ // instead of its built `dist/*.js`. We only want tsx to transpile the CLI's
21
+ // own TypeScript sources; package resolution must use normal exports.
22
+ const require = createRequire(import.meta.url);
23
+ const tsxLoader = require.resolve("tsx");
24
+ const result = spawnSync(
25
+ process.execPath,
26
+ ["--import", tsxLoader, devRunner, ...process.argv.slice(2)],
27
+ {
28
+ stdio: "inherit",
29
+ },
30
+ );
31
+
32
+ if (result.error) {
33
+ console.error(result.error.message);
34
+ process.exit(1);
35
+ }
36
+
37
+ if (result.signal) {
38
+ process.kill(process.pid, result.signal);
39
+ }
40
+
41
+ process.exit(result.status ?? 1);
42
+ }
43
+
10
44
  if (!existsSync(distEntry)) {
11
45
  console.error("@sudajs/cli is not built yet. Run `pnpm --filter @sudajs/cli build` first.");
12
46
  process.exit(1);
13
47
  }
14
48
 
15
- await import(pathToFileURL(distEntry).href);
49
+ const mod = await import(pathToFileURL(distEntry).href);
50
+ try {
51
+ await mod.main();
52
+ } catch (error) {
53
+ console.error(error instanceof Error ? error.message : error);
54
+ process.exitCode = 1;
55
+ }
package/dist/index.d.ts CHANGED
@@ -1 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+
4
+ declare function buildProgram(): Command;
5
+ declare function main(): Promise<void>;
6
+
7
+ export { buildProgram, main };