@@ -52,7 +52,7 @@ include fmt.mk
5252.PHONY : docs-server check-docs-links
5353.PHONY : storybook storybook-build test-storybook chromatic
5454.PHONY : benchmark-terminal
55- .PHONY : ensure-deps rebuild-native
55+ .PHONY : ensure-deps rebuild-native mux
5656.PHONY : check-eager-imports check-bundle-size check-startup
5757
5858# Build tools
@@ -107,6 +107,17 @@ rebuild-native: node_modules/.installed ## Rebuild native modules (node-pty) for
107107 @npx @electron/rebuild -f -m node_modules/node-pty
108108 @echo " Native modules rebuilt successfully"
109109
110+ # Run compiled CLI with trailing arguments (builds only if missing)
111+ mux : # # Run the compiled mux CLI (e.g., make mux server --port 3000)
112+ @test -f dist/cli/index.js || $(MAKE ) build-main
113+ @node dist/cli/index.js $(filter-out $@ ,$(MAKECMDGOALS ) )
114+
115+ # Catch unknown targets passed to mux (prevents "No rule to make target" errors)
116+ ifneq ($(filter mux,$(MAKECMDGOALS ) ) ,)
117+ % :
118+ @:
119+ endif
120+
110121# # Help
111122help : # # Show this help message
112123 @echo ' Usage: make [target]'
@@ -163,13 +174,25 @@ start: node_modules/.installed build-main build-preload build-static ## Build an
163174# # Build targets (can run in parallel)
164175build : node_modules/.installed src/version.ts build-renderer build-main build-preload build-icons build-static # # Build all targets
165176
166- build-main : node_modules/.installed dist/cli/index.js # # Build main process
177+ build-main : node_modules/.installed dist/cli/index.js dist/cli/api.mjs # # Build main process
167178
168179dist/cli/index.js : src/cli/index.ts src/desktop/main.ts src/cli/server.ts src/version.ts tsconfig.main.json tsconfig.json $(TS_SOURCES )
169180 @echo " Building main process..."
170181 @NODE_ENV=production $(TSGO ) -p tsconfig.main.json
171182 @NODE_ENV=production bun x tsc-alias -p tsconfig.main.json
172183
184+ # Build API CLI as ESM bundle (trpc-cli requires ESM with top-level await)
185+ dist/cli/api.mjs : src/cli/api.ts src/cli/proxifyOrpc.ts $(TS_SOURCES )
186+ @echo " Building API CLI (ESM)..."
187+ @bun x esbuild src/cli/api.ts \
188+ --bundle \
189+ --format=esm \
190+ --platform=node \
191+ --outfile=dist/cli/api.mjs \
192+ --external:zod \
193+ --external:commander \
194+ --external:@trpc/server
195+
173196build-preload : node_modules/.installed dist/preload.js # # Build preload script
174197
175198dist/preload.js : src/desktop/preload.ts $(TS_SOURCES )
0 commit comments