tsonic 0.0.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.
Files changed (77) hide show
  1. package/dist/cli/constants.d.ts +5 -0
  2. package/dist/cli/constants.d.ts.map +1 -0
  3. package/dist/cli/constants.js +5 -0
  4. package/dist/cli/constants.js.map +1 -0
  5. package/dist/cli/dispatcher.d.ts +8 -0
  6. package/dist/cli/dispatcher.d.ts.map +1 -0
  7. package/dist/cli/dispatcher.js +98 -0
  8. package/dist/cli/dispatcher.js.map +1 -0
  9. package/dist/cli/help.d.ts +8 -0
  10. package/dist/cli/help.d.ts.map +1 -0
  11. package/dist/cli/help.js +48 -0
  12. package/dist/cli/help.js.map +1 -0
  13. package/dist/cli/index.d.ts +8 -0
  14. package/dist/cli/index.d.ts.map +1 -0
  15. package/dist/cli/index.js +8 -0
  16. package/dist/cli/index.js.map +1 -0
  17. package/dist/cli/parser.d.ts +14 -0
  18. package/dist/cli/parser.d.ts.map +1 -0
  19. package/dist/cli/parser.js +94 -0
  20. package/dist/cli/parser.js.map +1 -0
  21. package/dist/cli/parser.test.d.ts +5 -0
  22. package/dist/cli/parser.test.d.ts.map +1 -0
  23. package/dist/cli/parser.test.js +221 -0
  24. package/dist/cli/parser.test.js.map +1 -0
  25. package/dist/cli.d.ts +6 -0
  26. package/dist/cli.d.ts.map +1 -0
  27. package/dist/cli.js +6 -0
  28. package/dist/cli.js.map +1 -0
  29. package/dist/commands/build.d.ts +11 -0
  30. package/dist/commands/build.d.ts.map +1 -0
  31. package/dist/commands/build.js +99 -0
  32. package/dist/commands/build.js.map +1 -0
  33. package/dist/commands/emit.d.ts +12 -0
  34. package/dist/commands/emit.d.ts.map +1 -0
  35. package/dist/commands/emit.js +170 -0
  36. package/dist/commands/emit.js.map +1 -0
  37. package/dist/commands/init.d.ts +14 -0
  38. package/dist/commands/init.d.ts.map +1 -0
  39. package/dist/commands/init.js +217 -0
  40. package/dist/commands/init.js.map +1 -0
  41. package/dist/commands/run.d.ts +11 -0
  42. package/dist/commands/run.d.ts.map +1 -0
  43. package/dist/commands/run.js +40 -0
  44. package/dist/commands/run.js.map +1 -0
  45. package/dist/config.d.ts +17 -0
  46. package/dist/config.d.ts.map +1 -0
  47. package/dist/config.js +84 -0
  48. package/dist/config.js.map +1 -0
  49. package/dist/config.test.d.ts +5 -0
  50. package/dist/config.test.d.ts.map +1 -0
  51. package/dist/config.test.js +274 -0
  52. package/dist/config.test.js.map +1 -0
  53. package/dist/index.d.ts +8 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +20 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/types.d.ts +74 -0
  58. package/dist/types.d.ts.map +1 -0
  59. package/dist/types.js +5 -0
  60. package/dist/types.js.map +1 -0
  61. package/package.json +38 -0
  62. package/src/cli/constants.ts +5 -0
  63. package/src/cli/dispatcher.ts +115 -0
  64. package/src/cli/help.ts +49 -0
  65. package/src/cli/index.ts +8 -0
  66. package/src/cli/parser.test.ts +259 -0
  67. package/src/cli/parser.ts +109 -0
  68. package/src/cli.ts +6 -0
  69. package/src/commands/build.ts +125 -0
  70. package/src/commands/emit.ts +222 -0
  71. package/src/commands/init.ts +272 -0
  72. package/src/commands/run.ts +51 -0
  73. package/src/config.test.ts +328 -0
  74. package/src/config.ts +105 -0
  75. package/src/index.ts +23 -0
  76. package/src/types.ts +74 -0
  77. package/tsconfig.json +18 -0
@@ -0,0 +1,115 @@
1
+ /**
2
+ * CLI command dispatcher
3
+ */
4
+
5
+ import { join } from "node:path";
6
+ import { checkDotnetInstalled } from "@tsonic/backend";
7
+ import { loadConfig, findConfig, resolveConfig } from "../config.js";
8
+ import { initProject } from "../commands/init.js";
9
+ import { emitCommand } from "../commands/emit.js";
10
+ import { buildCommand } from "../commands/build.js";
11
+ import { runCommand } from "../commands/run.js";
12
+ import { VERSION } from "./constants.js";
13
+ import { showHelp } from "./help.js";
14
+ import { parseArgs } from "./parser.js";
15
+
16
+ /**
17
+ * Main CLI entry point
18
+ */
19
+ export const runCli = async (args: string[]): Promise<number> => {
20
+ const parsed = parseArgs(args);
21
+
22
+ // Handle version and help
23
+ if (parsed.command === "version") {
24
+ console.log(`tsonic v${VERSION}`);
25
+ return 0;
26
+ }
27
+
28
+ if (parsed.command === "help" || !parsed.command) {
29
+ showHelp();
30
+ return 0;
31
+ }
32
+
33
+ // Handle project init (doesn't need config)
34
+ if (parsed.command === "project:init") {
35
+ const result = initProject(process.cwd());
36
+ if (!result.ok) {
37
+ console.error(`Error: ${result.error}`);
38
+ return 1;
39
+ }
40
+ console.log("✓ Initialized Tsonic project");
41
+ console.log(" Created: tsonic.json");
42
+ console.log(" Created/Updated: .gitignore");
43
+ console.log("\nNext steps:");
44
+ console.log(" 1. Edit tsonic.json to configure your project");
45
+ console.log(" 2. Create src/main.ts");
46
+ console.log(" 3. Run: tsonic build");
47
+ return 0;
48
+ }
49
+
50
+ // Check for dotnet
51
+ const dotnetResult = checkDotnetInstalled();
52
+ if (!dotnetResult.ok) {
53
+ console.error("Error: .NET SDK not found");
54
+ console.error("Install from: https://dotnet.microsoft.com/download");
55
+ return 8;
56
+ }
57
+
58
+ // Load config
59
+ const configPath = parsed.options.config
60
+ ? join(process.cwd(), parsed.options.config)
61
+ : findConfig(process.cwd());
62
+
63
+ if (!configPath) {
64
+ console.error("Error: No tsonic.json found");
65
+ console.error("Run 'tsonic project init' to initialize a project");
66
+ return 3;
67
+ }
68
+
69
+ const configResult = loadConfig(configPath);
70
+ if (!configResult.ok) {
71
+ console.error(`Error: ${configResult.error}`);
72
+ return 1;
73
+ }
74
+
75
+ const config = resolveConfig(
76
+ configResult.value,
77
+ parsed.options,
78
+ parsed.entryFile
79
+ );
80
+
81
+ // Dispatch to command handlers
82
+ switch (parsed.command) {
83
+ case "emit": {
84
+ const result = emitCommand(config);
85
+ if (!result.ok) {
86
+ console.error(`Error: ${result.error}`);
87
+ return 5;
88
+ }
89
+ return 0;
90
+ }
91
+
92
+ case "build": {
93
+ const result = buildCommand(config);
94
+ if (!result.ok) {
95
+ console.error(`Error: ${result.error}`);
96
+ return 6;
97
+ }
98
+ return 0;
99
+ }
100
+
101
+ case "run": {
102
+ const result = runCommand(config, parsed.programArgs ?? []);
103
+ if (!result.ok) {
104
+ console.error(`Error: ${result.error}`);
105
+ return 7;
106
+ }
107
+ return result.value.exitCode;
108
+ }
109
+
110
+ default:
111
+ console.error(`Error: Unknown command '${parsed.command}'`);
112
+ console.error("Run 'tsonic --help' for usage information");
113
+ return 2;
114
+ }
115
+ };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * CLI help message
3
+ */
4
+
5
+ import { VERSION } from "./constants.js";
6
+
7
+ /**
8
+ * Show help message
9
+ */
10
+ export const showHelp = (): void => {
11
+ console.log(`
12
+ Tsonic - TypeScript to C# to NativeAOT compiler v${VERSION}
13
+
14
+ USAGE:
15
+ tsonic <command> [options]
16
+
17
+ COMMANDS:
18
+ project init Initialize a new Tsonic project
19
+ emit [entry] Generate C# code only
20
+ build [entry] Build native executable
21
+ run [entry] [-- args...] Build and run executable
22
+
23
+ GLOBAL OPTIONS:
24
+ -h, --help Show help
25
+ -v, --version Show version
26
+ -V, --verbose Verbose output
27
+ -q, --quiet Suppress output
28
+ -c, --config <file> Config file path (default: tsonic.json)
29
+
30
+ EMIT/BUILD/RUN OPTIONS:
31
+ -s, --src <dir> Source root directory
32
+ -o, --out <path> Output directory (emit) or file (build)
33
+ -n, --namespace <ns> Root namespace override
34
+ -r, --rid <rid> Runtime identifier (e.g., linux-x64)
35
+ -O, --optimize <level> Optimization: size or speed
36
+ -k, --keep-temp Keep build artifacts
37
+ --no-strip Keep debug symbols
38
+
39
+ EXAMPLES:
40
+ tsonic project init
41
+ tsonic emit src/main.ts
42
+ tsonic build src/main.ts --rid linux-x64
43
+ tsonic run src/main.ts -- --arg1 value1
44
+
45
+ LEARN MORE:
46
+ Documentation: https://tsonic.dev/docs
47
+ GitHub: https://github.com/tsoniclang/tsonic
48
+ `);
49
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * CLI - Public API
3
+ */
4
+
5
+ export { VERSION } from "./constants.js";
6
+ export { showHelp } from "./help.js";
7
+ export { parseArgs } from "./parser.js";
8
+ export { runCli } from "./dispatcher.js";
@@ -0,0 +1,259 @@
1
+ /**
2
+ * Tests for CLI argument parser
3
+ */
4
+
5
+ import { describe, it } from "mocha";
6
+ import { expect } from "chai";
7
+ import { parseArgs } from "./parser.js";
8
+
9
+ describe("CLI Parser", () => {
10
+ describe("parseArgs", () => {
11
+ describe("Commands", () => {
12
+ it("should parse build command", () => {
13
+ const result = parseArgs(["build"]);
14
+ expect(result.command).to.equal("build");
15
+ });
16
+
17
+ it("should parse run command", () => {
18
+ const result = parseArgs(["run"]);
19
+ expect(result.command).to.equal("run");
20
+ });
21
+
22
+ it("should parse emit command", () => {
23
+ const result = parseArgs(["emit"]);
24
+ expect(result.command).to.equal("emit");
25
+ });
26
+
27
+ it("should parse project:init as two-word command", () => {
28
+ const result = parseArgs(["project", "init"]);
29
+ expect(result.command).to.equal("project:init");
30
+ });
31
+
32
+ it("should parse help command from --help", () => {
33
+ const result = parseArgs(["--help"]);
34
+ expect(result.command).to.equal("help");
35
+ });
36
+
37
+ it("should parse help command from -h", () => {
38
+ const result = parseArgs(["-h"]);
39
+ expect(result.command).to.equal("help");
40
+ });
41
+
42
+ it("should parse version command from --version", () => {
43
+ const result = parseArgs(["--version"]);
44
+ expect(result.command).to.equal("version");
45
+ });
46
+
47
+ it("should parse version command from -v", () => {
48
+ const result = parseArgs(["-v"]);
49
+ expect(result.command).to.equal("version");
50
+ });
51
+ });
52
+
53
+ describe("Entry File", () => {
54
+ it("should parse entry file after command", () => {
55
+ const result = parseArgs(["run", "index.ts"]);
56
+ expect(result.command).to.equal("run");
57
+ expect(result.entryFile).to.equal("index.ts");
58
+ });
59
+
60
+ it("should parse entry file with path", () => {
61
+ const result = parseArgs(["build", "src/main.ts"]);
62
+ expect(result.command).to.equal("build");
63
+ expect(result.entryFile).to.equal("src/main.ts");
64
+ });
65
+
66
+ it("should handle no entry file", () => {
67
+ const result = parseArgs(["build"]);
68
+ expect(result.entryFile).to.equal(undefined);
69
+ });
70
+ });
71
+
72
+ describe("Options", () => {
73
+ it("should parse --verbose option", () => {
74
+ const result = parseArgs(["build", "--verbose"]);
75
+ expect(result.options.verbose).to.equal(true);
76
+ });
77
+
78
+ it("should parse -V short option for verbose", () => {
79
+ const result = parseArgs(["build", "-V"]);
80
+ expect(result.options.verbose).to.equal(true);
81
+ });
82
+
83
+ it("should parse --quiet option", () => {
84
+ const result = parseArgs(["build", "--quiet"]);
85
+ expect(result.options.quiet).to.equal(true);
86
+ });
87
+
88
+ it("should parse -q short option for quiet", () => {
89
+ const result = parseArgs(["build", "-q"]);
90
+ expect(result.options.quiet).to.equal(true);
91
+ });
92
+
93
+ it("should parse --config option with value", () => {
94
+ const result = parseArgs(["build", "--config", "tsonic.json"]);
95
+ expect(result.options.config).to.equal("tsonic.json");
96
+ });
97
+
98
+ it("should parse -c short option for config", () => {
99
+ const result = parseArgs(["build", "-c", "custom.json"]);
100
+ expect(result.options.config).to.equal("custom.json");
101
+ });
102
+
103
+ it("should parse --src option with value", () => {
104
+ const result = parseArgs(["build", "--src", "source"]);
105
+ expect(result.options.src).to.equal("source");
106
+ });
107
+
108
+ it("should parse -s short option for src", () => {
109
+ const result = parseArgs(["build", "-s", "app"]);
110
+ expect(result.options.src).to.equal("app");
111
+ });
112
+
113
+ it("should parse --out option with value", () => {
114
+ const result = parseArgs(["build", "--out", "output"]);
115
+ expect(result.options.out).to.equal("output");
116
+ });
117
+
118
+ it("should parse -o short option for out", () => {
119
+ const result = parseArgs(["build", "-o", "dist"]);
120
+ expect(result.options.out).to.equal("dist");
121
+ });
122
+
123
+ it("should parse --namespace option with value", () => {
124
+ const result = parseArgs(["build", "--namespace", "MyApp"]);
125
+ expect(result.options.namespace).to.equal("MyApp");
126
+ });
127
+
128
+ it("should parse -n short option for namespace", () => {
129
+ const result = parseArgs(["build", "-n", "App"]);
130
+ expect(result.options.namespace).to.equal("App");
131
+ });
132
+
133
+ it("should parse --rid option with value", () => {
134
+ const result = parseArgs(["build", "--rid", "linux-x64"]);
135
+ expect(result.options.rid).to.equal("linux-x64");
136
+ });
137
+
138
+ it("should parse -r short option for rid", () => {
139
+ const result = parseArgs(["build", "-r", "win-x64"]);
140
+ expect(result.options.rid).to.equal("win-x64");
141
+ });
142
+
143
+ it("should parse --optimize option with speed", () => {
144
+ const result = parseArgs(["build", "--optimize", "speed"]);
145
+ expect(result.options.optimize).to.equal("speed");
146
+ });
147
+
148
+ it("should parse --optimize option with size", () => {
149
+ const result = parseArgs(["build", "--optimize", "size"]);
150
+ expect(result.options.optimize).to.equal("size");
151
+ });
152
+
153
+ it("should parse -O short option for optimize", () => {
154
+ const result = parseArgs(["build", "-O", "speed"]);
155
+ expect(result.options.optimize).to.equal("speed");
156
+ });
157
+
158
+ it("should parse --keep-temp option", () => {
159
+ const result = parseArgs(["build", "--keep-temp"]);
160
+ expect(result.options.keepTemp).to.equal(true);
161
+ });
162
+
163
+ it("should parse -k short option for keep-temp", () => {
164
+ const result = parseArgs(["build", "-k"]);
165
+ expect(result.options.keepTemp).to.equal(true);
166
+ });
167
+
168
+ it("should parse --no-strip option", () => {
169
+ const result = parseArgs(["build", "--no-strip"]);
170
+ expect(result.options.noStrip).to.equal(true);
171
+ });
172
+ });
173
+
174
+ describe("Program Arguments", () => {
175
+ it("should parse program arguments after --", () => {
176
+ const result = parseArgs(["run", "index.ts", "--", "arg1", "arg2"]);
177
+ expect(result.programArgs).to.deep.equal(["arg1", "arg2"]);
178
+ });
179
+
180
+ it("should handle options in program arguments", () => {
181
+ const result = parseArgs([
182
+ "run",
183
+ "index.ts",
184
+ "--",
185
+ "--verbose",
186
+ "-o",
187
+ "out",
188
+ ]);
189
+ expect(result.programArgs).to.deep.equal(["--verbose", "-o", "out"]);
190
+ });
191
+
192
+ it("should handle empty program arguments", () => {
193
+ const result = parseArgs(["run", "index.ts"]);
194
+ expect(result.programArgs).to.deep.equal([]);
195
+ });
196
+ });
197
+
198
+ describe("Complex Scenarios", () => {
199
+ it("should parse command with entry file and multiple options", () => {
200
+ const result = parseArgs([
201
+ "build",
202
+ "src/main.ts",
203
+ "--namespace",
204
+ "MyApp",
205
+ "--out",
206
+ "dist",
207
+ "--verbose",
208
+ ]);
209
+ expect(result.command).to.equal("build");
210
+ expect(result.entryFile).to.equal("src/main.ts");
211
+ expect(result.options.namespace).to.equal("MyApp");
212
+ expect(result.options.out).to.equal("dist");
213
+ expect(result.options.verbose).to.equal(true);
214
+ });
215
+
216
+ it("should parse run command with entry, options, and program args", () => {
217
+ const result = parseArgs([
218
+ "run",
219
+ "index.ts",
220
+ "--verbose",
221
+ "--",
222
+ "programArg1",
223
+ "programArg2",
224
+ ]);
225
+ expect(result.command).to.equal("run");
226
+ expect(result.entryFile).to.equal("index.ts");
227
+ expect(result.options.verbose).to.equal(true);
228
+ expect(result.programArgs).to.deep.equal([
229
+ "programArg1",
230
+ "programArg2",
231
+ ]);
232
+ });
233
+
234
+ it("should handle empty args array", () => {
235
+ const result = parseArgs([]);
236
+ expect(result.command).to.equal("");
237
+ expect(result.entryFile).to.equal(undefined);
238
+ expect(result.options).to.deep.equal({});
239
+ expect(result.programArgs).to.deep.equal([]);
240
+ });
241
+
242
+ it("should handle mixed short and long options", () => {
243
+ const result = parseArgs([
244
+ "build",
245
+ "-n",
246
+ "App",
247
+ "--out",
248
+ "dist",
249
+ "-V",
250
+ "--keep-temp",
251
+ ]);
252
+ expect(result.options.namespace).to.equal("App");
253
+ expect(result.options.out).to.equal("dist");
254
+ expect(result.options.verbose).to.equal(true);
255
+ expect(result.options.keepTemp).to.equal(true);
256
+ });
257
+ });
258
+ });
259
+ });
@@ -0,0 +1,109 @@
1
+ /**
2
+ * CLI argument parser
3
+ */
4
+
5
+ import type { CliOptions } from "../types.js";
6
+
7
+ /**
8
+ * Parse CLI arguments
9
+ */
10
+ export const parseArgs = (
11
+ args: string[]
12
+ ): {
13
+ command: string;
14
+ entryFile?: string;
15
+ options: CliOptions;
16
+ programArgs?: string[];
17
+ } => {
18
+ const options: CliOptions = {};
19
+ let command = "";
20
+ let entryFile: string | undefined;
21
+ const programArgs: string[] = [];
22
+ let captureProgramArgs = false;
23
+
24
+ for (let i = 0; i < args.length; i++) {
25
+ const arg = args[i];
26
+ if (!arg) continue; // Skip if undefined
27
+
28
+ // Separator for program arguments
29
+ if (arg === "--") {
30
+ captureProgramArgs = true;
31
+ continue;
32
+ }
33
+
34
+ if (captureProgramArgs) {
35
+ programArgs.push(arg);
36
+ continue;
37
+ }
38
+
39
+ // Commands
40
+ if (!command && !arg.startsWith("-")) {
41
+ command = arg;
42
+ // Handle "project init" as two-word command
43
+ const nextArg = args[i + 1];
44
+ if (command === "project" && nextArg === "init") {
45
+ command = "project:init";
46
+ i++;
47
+ }
48
+ continue;
49
+ }
50
+
51
+ // Entry file (first non-option after command)
52
+ if (command && !entryFile && !arg.startsWith("-")) {
53
+ entryFile = arg;
54
+ continue;
55
+ }
56
+
57
+ // Options
58
+ switch (arg) {
59
+ case "-h":
60
+ case "--help":
61
+ options.verbose = true; // reuse for help flag
62
+ return { command: "help", options: {} };
63
+ case "-v":
64
+ case "--version":
65
+ return { command: "version", options: {} };
66
+ case "-V":
67
+ case "--verbose":
68
+ options.verbose = true;
69
+ break;
70
+ case "-q":
71
+ case "--quiet":
72
+ options.quiet = true;
73
+ break;
74
+ case "-c":
75
+ case "--config":
76
+ options.config = args[++i] ?? "";
77
+ break;
78
+ case "-s":
79
+ case "--src":
80
+ options.src = args[++i] ?? "";
81
+ break;
82
+ case "-o":
83
+ case "--out":
84
+ options.out = args[++i] ?? "";
85
+ break;
86
+ case "-n":
87
+ case "--namespace":
88
+ options.namespace = args[++i] ?? "";
89
+ break;
90
+ case "-r":
91
+ case "--rid":
92
+ options.rid = args[++i] ?? "";
93
+ break;
94
+ case "-O":
95
+ case "--optimize":
96
+ options.optimize = (args[++i] ?? "speed") as "size" | "speed";
97
+ break;
98
+ case "-k":
99
+ case "--keep-temp":
100
+ options.keepTemp = true;
101
+ break;
102
+ case "--no-strip":
103
+ options.noStrip = true;
104
+ break;
105
+ }
106
+ }
107
+
108
+ return { command, entryFile, options, programArgs };
109
+ };
package/src/cli.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * CLI argument parsing and command dispatch
3
+ * Main dispatcher - re-exports from cli/ subdirectory
4
+ */
5
+
6
+ export { VERSION, showHelp, parseArgs, runCli } from "./cli/index.js";
@@ -0,0 +1,125 @@
1
+ /**
2
+ * tsonic build command - Build executable
3
+ */
4
+
5
+ import { spawnSync } from "node:child_process";
6
+ import { join, relative } from "node:path";
7
+ import { copyFileSync, chmodSync, existsSync } from "node:fs";
8
+ import type { ResolvedConfig, Result } from "../types.js";
9
+ import { emitCommand } from "./emit.js";
10
+
11
+ /**
12
+ * Build native executable
13
+ */
14
+ export const buildCommand = (
15
+ config: ResolvedConfig
16
+ ): Result<{ outputPath: string }, string> => {
17
+ const { outputDirectory, outputName, rid, quiet, verbose } = config;
18
+
19
+ // Step 1: Emit C# code
20
+ if (!quiet) {
21
+ console.log("Step 1/3: Generating C# code...");
22
+ }
23
+
24
+ const emitResult = emitCommand(config);
25
+ if (!emitResult.ok) {
26
+ return emitResult;
27
+ }
28
+
29
+ const generatedDir = emitResult.value.outputDir;
30
+ const csprojPath = join(generatedDir, "tsonic.csproj");
31
+
32
+ if (!existsSync(csprojPath)) {
33
+ return {
34
+ ok: false,
35
+ error: `No tsonic.csproj found in ${outputDirectory}/. This should have been created by emit.`,
36
+ };
37
+ }
38
+
39
+ // Step 2: Run dotnet publish
40
+ if (!quiet) {
41
+ console.log("Step 2/3: Compiling with dotnet publish...");
42
+ }
43
+
44
+ const publishArgs = [
45
+ "publish",
46
+ "tsonic.csproj",
47
+ "-c",
48
+ "Release",
49
+ "-r",
50
+ rid,
51
+ "--nologo",
52
+ ];
53
+
54
+ if (quiet) {
55
+ publishArgs.push("--verbosity", "quiet");
56
+ } else if (verbose) {
57
+ publishArgs.push("--verbosity", "detailed");
58
+ } else {
59
+ publishArgs.push("--verbosity", "minimal");
60
+ }
61
+
62
+ const publishResult = spawnSync("dotnet", publishArgs, {
63
+ cwd: generatedDir,
64
+ stdio: verbose ? "inherit" : "pipe",
65
+ encoding: "utf-8",
66
+ });
67
+
68
+ if (publishResult.status !== 0) {
69
+ const errorMsg =
70
+ publishResult.stderr || publishResult.stdout || "Unknown error";
71
+ return {
72
+ ok: false,
73
+ error: `dotnet publish failed:\n${errorMsg}`,
74
+ };
75
+ }
76
+
77
+ // Step 3: Copy output binary
78
+ if (!quiet) {
79
+ console.log("Step 3/3: Copying output binary...");
80
+ }
81
+
82
+ const binaryName =
83
+ process.platform === "win32" ? `${outputName}.exe` : outputName;
84
+ const publishDir = join(
85
+ generatedDir,
86
+ "bin",
87
+ "Release",
88
+ config.dotnetVersion,
89
+ rid,
90
+ "publish"
91
+ );
92
+ const sourceBinary = join(publishDir, binaryName);
93
+ const targetBinary = join(process.cwd(), binaryName);
94
+
95
+ if (!existsSync(sourceBinary)) {
96
+ return {
97
+ ok: false,
98
+ error: `Built binary not found at ${sourceBinary}`,
99
+ };
100
+ }
101
+
102
+ try {
103
+ copyFileSync(sourceBinary, targetBinary);
104
+
105
+ // Make executable on Unix
106
+ if (process.platform !== "win32") {
107
+ chmodSync(targetBinary, 0o755);
108
+ }
109
+
110
+ if (!quiet) {
111
+ const relativePath = relative(process.cwd(), targetBinary);
112
+ console.log(`\n✓ Build complete: ${relativePath}`);
113
+ }
114
+
115
+ return {
116
+ ok: true,
117
+ value: { outputPath: targetBinary },
118
+ };
119
+ } catch (error) {
120
+ return {
121
+ ok: false,
122
+ error: `Failed to copy binary: ${error instanceof Error ? error.message : String(error)}`,
123
+ };
124
+ }
125
+ };