Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

build-desktop-artifact.ts

697 lines22.5 KB

1#!/usr/bin/env node
2​
3import { spawnSync } from "node:child_process";
4​
5import rootPackageJson from "../package.json" with { type: "json" };
6import desktopPackageJson from "../apps/desktop/package.json" with { type: "json" };
7import serverPackageJson from "../apps/server/package.json" with { type: "json" };
8​
9import { resolveCatalogDependencies } from "./lib/resolve-catalog.ts";
10​
11import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
12import * as NodeServices from "@effect/platform-node/NodeServices";
13import { Config, Data, Effect, FileSystem, Layer, Logger, Option, Path, Schema } from "effect";
14import { Command, Flag } from "effect/unstable/cli";
15import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
16​
17const BuildPlatform = Schema.Literals(["mac", "linux", "win"]);
18const BuildArch = Schema.Literals(["arm64", "x64", "universal"]);
19​
20const RepoRoot = Effect.service(Path.Path).pipe(
21 Effect.flatMap((path) => path.fromFileUrl(new URL("..", import.meta.url))),
22);
23const IconSource = Effect.zipWith(RepoRoot, Effect.service(Path.Path), (repoRoot, path) =>
24 path.join(repoRoot, "assets/macos-icon-1024.png"),
25);
26const encodeJsonString = Schema.encodeEffect(Schema.UnknownFromJsonString);
27​
28interface PlatformConfig {
29 readonly cliFlag: "--mac" | "--linux" | "--win";
30 readonly defaultTarget: string;
31 readonly archChoices: ReadonlyArray<typeof BuildArch.Type>;
33​
34const PLATFORM_CONFIG: Record<typeof BuildPlatform.Type, PlatformConfig> = {
35 mac: {
36 cliFlag: "--mac",
37 defaultTarget: "dmg",
38 archChoices: ["arm64", "x64", "universal"],
39 },
40 linux: {
41 cliFlag: "--linux",
42 defaultTarget: "AppImage",
43 archChoices: ["x64", "arm64"],
44 },
45 win: {
46 cliFlag: "--win",
47 defaultTarget: "nsis",
48 archChoices: ["x64", "arm64"],
49 },
50};
51​
52interface BuildCliInput {
53 readonly platform: Option.Option<typeof BuildPlatform.Type>;
54 readonly target: Option.Option<string>;
55 readonly arch: Option.Option<typeof BuildArch.Type>;
56 readonly buildVersion: Option.Option<string>;
57 readonly outputDir: Option.Option<string>;
58 readonly skipBuild: Option.Option<boolean>;
59 readonly keepStage: Option.Option<boolean>;
60 readonly signed: Option.Option<boolean>;
61 readonly verbose: Option.Option<boolean>;
63​
64function detectHostBuildPlatform(hostPlatform: string): typeof BuildPlatform.Type | undefined {
65 if (hostPlatform === "darwin") return "mac";
66 if (hostPlatform === "linux") return "linux";
67 if (hostPlatform === "win32") return "win";
68 return undefined;
70​
71function getDefaultArch(platform: typeof BuildPlatform.Type): typeof BuildArch.Type {
72 const config = PLATFORM_CONFIG[platform];
73 if (!config) {
74 return "x64";
75 }
76​
77 if (process.arch === "arm64" && config.archChoices.includes("arm64")) {
78 return "arm64";
79 }
80 if (process.arch === "x64" && config.archChoices.includes("x64")) {
81 return "x64";
82 }
83​
84 return config.archChoices[0] ?? "x64";
86​
87class BuildScriptError extends Data.TaggedError("BuildScriptError")<{
88 readonly message: string;
89 readonly cause?: unknown;
90}> {}
91​
92function resolveGitCommitHash(repoRoot: string): string {
93 const result = spawnSync("git", ["rev-parse", "--short=12", "HEAD"], {
94 cwd: repoRoot,
95 encoding: "utf8",
96 });
97 if (result.status !== 0) {
98 return "unknown";
99 }
100 const hash = result.stdout.trim();
101 if (!/^[0-9a-f]{7,40}$/i.test(hash)) {
102 return "unknown";
103 }
104 return hash.toLowerCase();
106​
107interface ResolvedBuildOptions {
108 readonly platform: typeof BuildPlatform.Type;
109 readonly target: string;
110 readonly arch: typeof BuildArch.Type;
111 readonly version: string | undefined;
112 readonly outputDir: string;
113 readonly skipBuild: boolean;
114 readonly keepStage: boolean;
115 readonly signed: boolean;
116 readonly verbose: boolean;
118​
119interface StagePackageJson {
120 readonly name: string;
121 readonly version: string;
122 readonly buildVersion: string;
123 readonly t3codeCommitHash: string;
124 readonly private: true;
125 readonly description: string;
126 readonly author: string;
127 readonly main: string;
128 readonly build: Record<string, unknown>;
129 readonly dependencies: Record<string, unknown>;
130 readonly devDependencies: {
131 readonly electron: string;
132 };
134​
135const AzureTrustedSigningOptionsConfig = Config.all({
136 publisherName: Config.string("AZURE_TRUSTED_SIGNING_PUBLISHER_NAME"),
137 endpoint: Config.string("AZURE_TRUSTED_SIGNING_ENDPOINT"),
138 certificateProfileName: Config.string("AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME"),
139 codeSigningAccountName: Config.string("AZURE_TRUSTED_SIGNING_ACCOUNT_NAME"),
140 fileDigest: Config.string("AZURE_TRUSTED_SIGNING_FILE_DIGEST").pipe(Config.withDefault("SHA256")),
141 timestampDigest: Config.string("AZURE_TRUSTED_SIGNING_TIMESTAMP_DIGEST").pipe(
142 Config.withDefault("SHA256"),
143 ),
144 timestampRfc3161: Config.string("AZURE_TRUSTED_SIGNING_TIMESTAMP_RFC3161").pipe(
145 Config.withDefault("http://timestamp.acs.microsoft.com"),
146 ),
147});
148​
149const BuildEnvConfig = Config.all({
150 platform: Config.schema(BuildPlatform, "T3CODE_DESKTOP_PLATFORM").pipe(Config.option),
151 target: Config.string("T3CODE_DESKTOP_TARGET").pipe(Config.option),
152 arch: Config.schema(BuildArch, "T3CODE_DESKTOP_ARCH").pipe(Config.option),
153 version: Config.string("T3CODE_DESKTOP_VERSION").pipe(Config.option),
154 outputDir: Config.string("T3CODE_DESKTOP_OUTPUT_DIR").pipe(Config.option),
155 skipBuild: Config.boolean("T3CODE_DESKTOP_SKIP_BUILD").pipe(Config.withDefault(false)),
156 keepStage: Config.boolean("T3CODE_DESKTOP_KEEP_STAGE").pipe(Config.withDefault(false)),
157 signed: Config.boolean("T3CODE_DESKTOP_SIGNED").pipe(Config.withDefault(false)),
158 verbose: Config.boolean("T3CODE_DESKTOP_VERBOSE").pipe(Config.withDefault(false)),
159});
160​
161const resolveBooleanFlag = (flag: Option.Option<boolean>, envValue: boolean) =>
162 Option.getOrElse(Option.filter(flag, Boolean), () => envValue);
163const mergeOptions = <A>(a: Option.Option<A>, b: Option.Option<A>, defaultValue: A) =>
164 Option.getOrElse(a, () => Option.getOrElse(b, () => defaultValue));
165​
166const resolveBuildOptions = Effect.fn("resolveBuildOptions")(function* (input: BuildCliInput) {
167 const path = yield* Path.Path;
168 const repoRoot = yield* RepoRoot;
169 const env = yield* BuildEnvConfig.asEffect();
170​
171 const platform = mergeOptions(
172 input.platform,
173 env.platform,
174 detectHostBuildPlatform(process.platform),
175 );
176​
177 if (!platform) {
178 return yield* new BuildScriptError({
179 message: `Unsupported host platform '${process.platform}'.`,
180 });
181 }
182​
183 const target = mergeOptions(input.target, env.target, PLATFORM_CONFIG[platform].defaultTarget);
184 const arch = mergeOptions(input.arch, env.arch, getDefaultArch(platform));
185 const version = mergeOptions(input.buildVersion, env.version, undefined);
186 const outputDir = path.resolve(repoRoot, mergeOptions(input.outputDir, env.outputDir, "release"));
187​
188 const skipBuild = resolveBooleanFlag(input.skipBuild, env.skipBuild);
189 const keepStage = resolveBooleanFlag(input.keepStage, env.keepStage);
190 const signed = resolveBooleanFlag(input.signed, env.signed);
191 const verbose = resolveBooleanFlag(input.verbose, env.verbose);
192​
193 return {
194 platform,
195 target,
196 arch,
197 version,
198 outputDir,
199 skipBuild,
200 keepStage,
201 signed,
202 verbose,
203 } satisfies ResolvedBuildOptions;
204});
205​
206const commandOutputOptions = (verbose: boolean) =>
207 ({
208 stdout: verbose ? "inherit" : "ignore",
209 stderr: "inherit",
210 }) as const;
211​
212const runCommand = Effect.fn("runCommand")(function* (command: ChildProcess.Command) {
213 const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
214 const child = yield* commandSpawner.spawn(command);
215 const exitCode = yield* child.exitCode;
216​
217 if (exitCode !== 0) {
218 return yield* new BuildScriptError({
219 message: `Command exited with non-zero exit code (${exitCode})`,
220 });
221 }
222});
223​
224function generateMacIconSet(
225 sourcePng: string,
226 targetIcns: string,
227 tmpRoot: string,
228 path: Path.Path,
229 verbose: boolean,
230) {
231 return Effect.gen(function* () {
232 const fs = yield* FileSystem.FileSystem;
233 const iconsetDir = path.join(tmpRoot, "icon.iconset");
234 yield* fs.makeDirectory(iconsetDir, { recursive: true });
235​
236 const iconSizes = [16, 32, 128, 256, 512] as const;
237 for (const size of iconSizes) {
238 yield* runCommand(
239 ChildProcess.make({
240 ...commandOutputOptions(verbose),
241 })`sips -z ${size} ${size} ${sourcePng} --out ${path.join(iconsetDir, `icon_${size}x${size}.png`)}`,
242 );
243​
244 const retinaSize = size * 2;
245 yield* runCommand(
246 ChildProcess.make({
247 ...commandOutputOptions(verbose),
248 })`sips -z ${retinaSize} ${retinaSize} ${sourcePng} --out ${path.join(iconsetDir, `icon_${size}x${size}@2x.png`)}`,
249 );
250 }
251​
252 yield* runCommand(
253 ChildProcess.make({
254 ...commandOutputOptions(verbose),
255 })`iconutil -c icns ${iconsetDir} -o ${targetIcns}`,
256 );
257 });
259​
260function stageMacIcons(stageResourcesDir: string, verbose: boolean) {
261 return Effect.gen(function* () {
262 const fs = yield* FileSystem.FileSystem;
263 const path = yield* Path.Path;
264 const iconSource = yield* IconSource;
265 if (!(yield* fs.exists(iconSource))) {
266 return yield* new BuildScriptError({
267 message: `Production icon source is missing at ${iconSource}`,
268 });
269 }
270​
271 const tmpRoot = yield* fs.makeTempDirectoryScoped({
272 prefix: "t3code-icon-build-",
273 });
274​
275 const iconPngPath = path.join(stageResourcesDir, "icon.png");
276 const iconIcnsPath = path.join(stageResourcesDir, "icon.icns");
277​
278 yield* runCommand(
279 ChildProcess.make({
280 ...commandOutputOptions(verbose),
281 })`sips -z 512 512 ${iconSource} --out ${iconPngPath}`,
282 );
283​
284 yield* generateMacIconSet(iconSource, iconIcnsPath, tmpRoot, path, verbose);
285 });
287​
288function validateBundledClientAssets(clientDir: string) {
289 return Effect.gen(function* () {
290 const fs = yield* FileSystem.FileSystem;
291 const path = yield* Path.Path;
292 const indexPath = path.join(clientDir, "index.html");
293 const indexHtml = yield* fs.readFileString(indexPath);
294 const refs = [...indexHtml.matchAll(/\b(?:src|href)=["']([^"']+)["']/g)]
295 .map((match) => match[1])
296 .filter((value): value is string => value !== undefined);
297 const missing: string[] = [];
298​
299 for (const ref of refs) {
300 const normalizedRef = ref.split("#")[0]?.split("?")[0] ?? "";
301 if (!normalizedRef) continue;
302 if (normalizedRef.startsWith("http://") || normalizedRef.startsWith("https://")) continue;
303 if (normalizedRef.startsWith("data:") || normalizedRef.startsWith("mailto:")) continue;
304​
305 const ext = path.extname(normalizedRef);
306 if (!ext) continue;
307​
308 const relativePath = normalizedRef.replace(/^\/+/, "");
309 const assetPath = path.join(clientDir, relativePath);
310 if (!(yield* fs.exists(assetPath))) {
311 missing.push(normalizedRef);
312 }
313 }
314​
315 if (missing.length > 0) {
316 const preview = missing.slice(0, 6).join(", ");
317 const suffix = missing.length > 6 ? ` (+${missing.length - 6} more)` : "";
318 return yield* new BuildScriptError({
319 message: `Bundled client references missing files in ${indexPath}: ${preview}${suffix}. Rebuild web/server artifacts.`,
320 });
321 }
322 });
324​
325function resolveDesktopRuntimeDependencies(
326 dependencies: Record<string, unknown> | undefined,
327 catalog: Record<string, unknown>,
328): Record<string, unknown> {
329 if (!dependencies || Object.keys(dependencies).length === 0) {
330 return {};
331 }
332​
333 const runtimeDependencies = Object.fromEntries(
334 Object.entries(dependencies).filter(([dependencyName]) => dependencyName !== "electron"),
335 );
336​
337 return resolveCatalogDependencies(runtimeDependencies, catalog, "apps/desktop");
339​
340function resolveGitHubPublishConfig():
341 | {
342 readonly provider: "github";
343 readonly owner: string;
344 readonly repo: string;
345 readonly releaseType: "release";
346 }
347 | undefined {
348 const rawRepo =
349 process.env.T3CODE_DESKTOP_UPDATE_REPOSITORY?.trim() ||
350 process.env.GITHUB_REPOSITORY?.trim() ||
351 "";
352 if (!rawRepo) return undefined;
353​
354 const [owner, repo, ...rest] = rawRepo.split("/");
355 if (!owner || !repo || rest.length > 0) return undefined;
356​
357 return {
358 provider: "github",
359 owner,
360 repo,
361 releaseType: "release",
362 };
364​
365const createBuildConfig = Effect.fn("createBuildConfig")(function* (
366 platform: typeof BuildPlatform.Type,
367 target: string,
368 productName: string,
369 signed: boolean,
370) {
371 const buildConfig: Record<string, unknown> = {
372 appId: "com.t3tools.t3code",
373 productName,
374 artifactName: "T3-Code-${version}-${arch}.${ext}",
375 directories: {
376 buildResources: "apps/desktop/resources",
377 },
378 };
379 const publishConfig = resolveGitHubPublishConfig();
380 if (publishConfig) {
381 buildConfig.publish = [publishConfig];
382 }
383​
384 if (platform === "mac") {
385 buildConfig.mac = {
386 target: target === "dmg" ? [target, "zip"] : [target],
387 icon: "icon.icns",
388 category: "public.app-category.developer-tools",
389 };
390 }
391​
392 if (platform === "linux") {
393 buildConfig.linux = {
394 target: [target],
395 icon: "icon.png",
396 category: "Development",
397 };
398 }
399​
400 if (platform === "win") {
401 const winConfig: Record<string, unknown> = {
402 target: [target],
403 icon: "icon.ico",
404 };
405 if (signed) {
406 winConfig.azureSignOptions = yield* AzureTrustedSigningOptionsConfig;
407 }
408 buildConfig.win = winConfig;
409 }
410​
411 return buildConfig;
412});
413​
414const assertPlatformBuildResources = Effect.fn("assertPlatformBuildResources")(function* (
415 platform: typeof BuildPlatform.Type,
416 stageResourcesDir: string,
417 verbose: boolean,
418) {
419 const fs = yield* FileSystem.FileSystem;
420 const path = yield* Path.Path;
421​
422 if (platform === "mac") {
423 yield* stageMacIcons(stageResourcesDir, verbose);
424 return;
425 }
426​
427 if (platform === "linux") {
428 const iconPath = path.join(stageResourcesDir, "icon.png");
429 if (!(yield* fs.exists(iconPath))) {
430 return yield* new BuildScriptError({
431 message: `Missing Linux icon at ${iconPath}`,
432 });
433 }
434 return;
435 }
436​
437 if (platform === "win") {
438 const iconPath = path.join(stageResourcesDir, "icon.ico");
439 if (!(yield* fs.exists(iconPath))) {
440 return yield* new BuildScriptError({
441 message: `Missing Windows icon at ${iconPath}`,
442 });
443 }
444 }
445});
446​
447const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
448 options: ResolvedBuildOptions,
449) {
450 const repoRoot = yield* RepoRoot;
451 const path = yield* Path.Path;
452 const fs = yield* FileSystem.FileSystem;
453​
454 const platformConfig = PLATFORM_CONFIG[options.platform];
455 if (!platformConfig) {
456 return yield* new BuildScriptError({
457 message: `Unsupported platform '${options.platform}'.`,
458 });
459 }
460​
461 const electronVersion = desktopPackageJson.dependencies.electron;
462​
463 const serverDependencies = serverPackageJson.dependencies;
464 if (!serverDependencies || Object.keys(serverDependencies).length === 0) {
465 return yield* new BuildScriptError({
466 message: "Could not resolve production dependencies from apps/server/package.json.",
467 });
468 }
469​
470 const resolvedServerDependencies = yield* Effect.try({
471 try: () =>
472 resolveCatalogDependencies(
473 serverDependencies,
474 rootPackageJson.workspaces.catalog,
475 "apps/server",
476 ),
477 catch: (cause) =>
478 new BuildScriptError({
479 message: "Could not resolve production dependencies from apps/server/package.json.",
480 cause,
481 }),
482 });
483 const resolvedDesktopRuntimeDependencies = yield* Effect.try({
484 try: () =>
485 resolveDesktopRuntimeDependencies(
486 desktopPackageJson.dependencies,
487 rootPackageJson.workspaces.catalog,
488 ),
489 catch: (cause) =>
490 new BuildScriptError({
491 message: "Could not resolve desktop runtime dependencies from apps/desktop/package.json.",
492 cause,
493 }),
494 });
495​
496 const appVersion = options.version ?? serverPackageJson.version;
497 const commitHash = resolveGitCommitHash(repoRoot);
498 const mkdir = options.keepStage ? fs.makeTempDirectory : fs.makeTempDirectoryScoped;
499 const stageRoot = yield* mkdir({
500 prefix: `t3code-desktop-${options.platform}-stage-`,
501 });
502​
503 const stageAppDir = path.join(stageRoot, "app");
504 const stageResourcesDir = path.join(stageAppDir, "apps/desktop/resources");
505 const distDirs = {
506 desktopDist: path.join(repoRoot, "apps/desktop/dist-electron"),
507 desktopResources: path.join(repoRoot, "apps/desktop/resources"),
508 serverDist: path.join(repoRoot, "apps/server/dist"),
509 };
510 const bundledClientEntry = path.join(distDirs.serverDist, "client/index.html");
511​
512 if (!options.skipBuild) {
513 yield* Effect.log("[desktop-artifact] Building desktop/server/web artifacts...");
514 yield* runCommand(
515 ChildProcess.make({
516 cwd: repoRoot,
517 ...commandOutputOptions(options.verbose),
518 })`bun run build:desktop`,
519 );
520 }
521​
522 for (const [label, dir] of Object.entries(distDirs)) {
523 if (!(yield* fs.exists(dir))) {
524 return yield* new BuildScriptError({
525 message: `Missing ${label} at ${dir}. Run 'bun run build:desktop' first.`,
526 });
527 }
528 }
529​
530 if (!(yield* fs.exists(bundledClientEntry))) {
531 return yield* new BuildScriptError({
532 message: `Missing bundled server client at ${bundledClientEntry}. Run 'bun run build:desktop' first.`,
533 });
534 }
535​
536 yield* validateBundledClientAssets(path.dirname(bundledClientEntry));
537​
538 yield* fs.makeDirectory(path.join(stageAppDir, "apps/desktop"), { recursive: true });
539 yield* fs.makeDirectory(path.join(stageAppDir, "apps/server"), { recursive: true });
540​
541 yield* Effect.log("[desktop-artifact] Staging release app...");
542 yield* fs.copy(distDirs.desktopDist, path.join(stageAppDir, "apps/desktop/dist-electron"));
543 yield* fs.copy(distDirs.desktopResources, stageResourcesDir);
544 yield* fs.copy(distDirs.serverDist, path.join(stageAppDir, "apps/server/dist"));
545​
546 yield* assertPlatformBuildResources(options.platform, stageResourcesDir, options.verbose);
547​
548 const stagePackageJson: StagePackageJson = {
549 name: "t3-code-desktop",
550 version: appVersion,
551 buildVersion: appVersion,
552 t3codeCommitHash: commitHash,
553 private: true,
554 description: "T3 Code desktop build",
555 author: "T3 Tools",
556 main: "apps/desktop/dist-electron/main.js",
557 build: yield* createBuildConfig(
558 options.platform,
559 options.target,
560 desktopPackageJson.productName ?? "T3 Code",
561 options.signed,
562 ),
563 dependencies: {
564 ...resolvedServerDependencies,
565 ...resolvedDesktopRuntimeDependencies,
566 },
567 devDependencies: {
568 electron: electronVersion,
569 },
570 };
571​
572 const stagePackageJsonString = yield* encodeJsonString(stagePackageJson);
573 yield* fs.writeFileString(path.join(stageAppDir, "package.json"), `${stagePackageJsonString}\n`);
574​
575 yield* Effect.log("[desktop-artifact] Installing staged production dependencies...");
576 yield* runCommand(
577 ChildProcess.make({
578 cwd: stageAppDir,
579 ...commandOutputOptions(options.verbose),
580 })`bun install --production`,
581 );
582​
583 const buildEnv: NodeJS.ProcessEnv = {
584 ...process.env,
585 };
586 for (const [key, value] of Object.entries(buildEnv)) {
587 if (value === "") {
588 delete buildEnv[key];
589 }
590 }
591 if (!options.signed) {
592 buildEnv.CSC_IDENTITY_AUTO_DISCOVERY = "false";
593 delete buildEnv.CSC_LINK;
594 delete buildEnv.CSC_KEY_PASSWORD;
595 delete buildEnv.APPLE_API_KEY;
596 delete buildEnv.APPLE_API_KEY_ID;
597 delete buildEnv.APPLE_API_ISSUER;
598 }
599​
600 yield* Effect.log(
601 `[desktop-artifact] Building ${options.platform}/${options.target} (arch=${options.arch}, version=${appVersion})...`,
602 );
603 yield* runCommand(
604 ChildProcess.make({
605 cwd: stageAppDir,
606 env: buildEnv,
607 ...commandOutputOptions(options.verbose),
608 })`bunx electron-builder ${platformConfig.cliFlag} --${options.arch} --publish never`,
609 );
610​
611 const stageDistDir = path.join(stageAppDir, "dist");
612 if (!(yield* fs.exists(stageDistDir))) {
613 return yield* new BuildScriptError({
614 message: `Build completed but dist directory was not found at ${stageDistDir}`,
615 });
616 }
617​
618 const stageEntries = yield* fs.readDirectory(stageDistDir);
619 yield* fs.makeDirectory(options.outputDir, { recursive: true });
620​
621 const copiedArtifacts: string[] = [];
622 for (const entry of stageEntries) {
623 const from = path.join(stageDistDir, entry);
624 const stat = yield* fs.stat(from).pipe(Effect.catch(() => Effect.succeed(null)));
625 if (!stat || stat.type !== "File") continue;
626​
627 const to = path.join(options.outputDir, entry);
628 yield* fs.copyFile(from, to);
629 copiedArtifacts.push(to);
630 }
631​
632 if (copiedArtifacts.length === 0) {
633 return yield* new BuildScriptError({
634 message: `Build completed but no files were produced in ${stageDistDir}`,
635 });
636 }
637​
638 yield* Effect.log("[desktop-artifact] Done. Artifacts:").pipe(
639 Effect.annotateLogs({ artifacts: copiedArtifacts }),
640 );
641});
642​
643const buildDesktopArtifactCli = Command.make("build-desktop-artifact", {
644 platform: Flag.choice("platform", BuildPlatform.literals).pipe(
645 Flag.withDescription("Build platform (env: T3CODE_DESKTOP_PLATFORM)."),
646 Flag.optional,
647 ),
648 target: Flag.string("target").pipe(
649 Flag.withDescription(
650 "Artifact target, for example dmg/AppImage/nsis (env: T3CODE_DESKTOP_TARGET).",
651 ),
652 Flag.optional,
653 ),
654 arch: Flag.choice("arch", BuildArch.literals).pipe(
655 Flag.withDescription("Build arch, for example arm64/x64/universal (env: T3CODE_DESKTOP_ARCH)."),
656 Flag.optional,
657 ),
658 buildVersion: Flag.string("build-version").pipe(
659 Flag.withDescription("Artifact version metadata (env: T3CODE_DESKTOP_VERSION)."),
660 Flag.optional,
661 ),
662 outputDir: Flag.string("output-dir").pipe(
663 Flag.withDescription("Output directory for artifacts (env: T3CODE_DESKTOP_OUTPUT_DIR)."),
664 Flag.optional,
665 ),
666 skipBuild: Flag.boolean("skip-build").pipe(
667 Flag.withDescription(
668 "Skip `bun run build:desktop` and use existing dist artifacts (env: T3CODE_DESKTOP_SKIP_BUILD).",
669 ),
670 Flag.optional,
671 ),
672 keepStage: Flag.boolean("keep-stage").pipe(
673 Flag.withDescription("Keep temporary staging files (env: T3CODE_DESKTOP_KEEP_STAGE)."),
674 Flag.optional,
675 ),
676 signed: Flag.boolean("signed").pipe(
677 Flag.withDescription(
678 "Enable signing/notarization discovery; Windows uses Azure Trusted Signing (env: T3CODE_DESKTOP_SIGNED).",
679 ),
680 Flag.optional,
681 ),
682 verbose: Flag.boolean("verbose").pipe(
683 Flag.withDescription("Stream subprocess stdout (env: T3CODE_DESKTOP_VERBOSE)."),
684 Flag.optional,
685 ),
686}).pipe(
687 Command.withDescription("Build a desktop artifact for T3 Code."),
688 Command.withHandler((input) => Effect.flatMap(resolveBuildOptions(input), buildDesktopArtifact)),
689);
690​
691const cliRuntimeLayer = Layer.mergeAll(Logger.layer([Logger.consolePretty()]), NodeServices.layer);
692​
693Command.run(buildDesktopArtifactCli, { version: "0.0.0" }).pipe(
694 Effect.scoped,
695 Effect.provide(cliRuntimeLayer),
696 NodeRuntime.runMain,
697);