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

build-cli-archive.ts

574 lines22.3 KB

1#!/usr/bin/env node
2/**
3 * The archive is the unit every runtime installer downloads, so nothing in it
4 * may require Node, npm, or a compiler on the machine that unpacks it.
5 */
6import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
7import * as NodeServices from "@effect/platform-node/NodeServices";
8import * as Config from "effect/Config";
9import * as Effect from "effect/Effect";
10import * as FileSystem from "effect/FileSystem";
11import * as Layer from "effect/Layer";
12import * as Logger from "effect/Logger";
13import * as Option from "effect/Option";
14import * as Path from "effect/Path";
15import * as PlatformError from "effect/PlatformError";
16import * as Schema from "effect/Schema";
17import { Command, Flag } from "effect/cli";
18import { ChildProcess, ChildProcessSpawner } from "effect/process";
19​
20import * as HostProcess from "@t3tools/shared/HostProcess";
21import { fromYaml } from "@t3tools/shared/schemaYaml";
22import { resolveSpawnCommand } from "@t3tools/shared/shell";
23import rootPackageJson from "../package.json" with { type: "json" };
24import serverPackageJson from "../apps/server/package.json" with { type: "json" };
25​
26import {
27 createStagePatchedDependencies,
28 createStageWorkspaceConfig,
29 resolveFffNativeDependencies,
30 STAGE_INSTALL_ARGS,
31} from "./build-desktop-artifact.ts";
32import { selectCliRuntimeExternalDependencies } from "./lib/cli-external-packages.ts";
33import { signWithJsign } from "./lib/windows-jsign.ts";
34import { windowsSystemTar } from "./lib/windows-tar.ts";
35import { resolveCatalogDependencies } from "./lib/resolve-catalog.ts";
36​
37const BuildPlatform = Schema.Literals(["mac", "linux", "win"]);
38const BuildArch = Schema.Literals(["arm64", "x64"]);
39type BuildPlatform = typeof BuildPlatform.Type;
40type BuildArch = typeof BuildArch.Type;
41​
42const WorkspaceConfig = Schema.Struct({
43 catalog: Schema.optional(Schema.Record(Schema.String, Schema.String)),
44 overrides: Schema.optional(Schema.Record(Schema.String, Schema.String)),
45 patchedDependencies: Schema.optional(Schema.Record(Schema.String, Schema.String)),
46 allowBuilds: Schema.optional(Schema.Record(Schema.String, Schema.Boolean)),
47});
48const decodeWorkspaceConfig = Schema.decodeEffect(fromYaml(WorkspaceConfig));
49const encodeJsonString = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
50const StageWorkspaceConfig = Schema.Struct({
51 supportedArchitectures: Schema.Struct({
52 os: Schema.Array(Schema.String),
53 cpu: Schema.Array(Schema.String),
54 libc: Schema.optional(Schema.Array(Schema.String)),
55 }),
56 allowBuilds: Schema.optional(Schema.Record(Schema.String, Schema.Boolean)),
57 patchedDependencies: Schema.optional(Schema.Record(Schema.String, Schema.String)),
58 overrides: Schema.optional(Schema.Record(Schema.String, Schema.String)),
59 nodeLinker: Schema.optional(Schema.Literals(["hoisted"])),
60});
61const encodeStageWorkspaceConfig = Schema.encodeEffect(fromYaml(StageWorkspaceConfig));
62​
63const RepoRoot = Effect.service(Path.Path).pipe(
64 Effect.flatMap((path) => path.fromFileUrl(new URL("..", import.meta.url))),
65);
66​
67export class CliArchiveCommandFailedError extends Schema.TaggedError<CliArchiveCommandFailedError>()(
68 "CliArchiveCommandFailedError",
69 { command: Schema.String, exitCode: Schema.Int },
70) {
71 override get message(): string {
72 return `${this.command} exited with code ${this.exitCode}.`;
73 }
75​
76export class CliArchiveInputMissingError extends Schema.TaggedError<CliArchiveInputMissingError>()(
77 "CliArchiveInputMissingError",
78 { inputPath: Schema.String, hint: Schema.String },
79) {
80 override get message(): string {
81 return `Missing ${this.inputPath}. ${this.hint}`;
82 }
84​
85export function cliArchivePlatformKey(platform: BuildPlatform, arch: BuildArch): string {
86 const nodePlatform = platform === "mac" ? "darwin" : platform === "win" ? "win32" : "linux";
87 return `${nodePlatform}-${arch}`;
89​
90export function cliArchiveStem(version: string, platform: BuildPlatform, arch: BuildArch): string {
91 return `t3-${version}-${cliArchivePlatformKey(platform, arch)}`;
93​
94export function cliArchiveFileName(version: string, platform: BuildPlatform, arch: BuildArch) {
95 // gzip rather than xz: GNU tar needs an external xz binary for -J, which
96 // minimal hosts lack, while every tar (and Node's zlib) handles gzip alone.
97 return `${cliArchiveStem(version, platform, arch)}.${platform === "win" ? "zip" : "tar.gz"}`;
99​
100const runCommand = Effect.fn("runCommand")(function* (
101 command: ChildProcess.Command,
102 label: string,
103) {
104 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
105 const child = yield* spawner.spawn(
106 ChildProcess.isStandardCommand(command)
107 ? ChildProcess.make(command.command, command.args, {
108 ...command.options,
109 stdout: "inherit",
110 stderr: "inherit",
111 })
112 : command,
113 );
114 const exitCode = Number(yield* child.exitCode);
115 if (exitCode !== 0) {
116 return yield* new CliArchiveCommandFailedError({ command: label, exitCode });
117 }
118});
119​
120const requireInput = Effect.fn("requireInput")(function* (inputPath: string, hint: string) {
121 const fs = yield* FileSystem.FileSystem;
122 if (!(yield* fs.exists(inputPath))) {
123 return yield* new CliArchiveInputMissingError({ inputPath, hint });
124 }
125});
126​
127/**
128 * The tree is archived and unpacked on machines without pnpm, so the store
129 * layout cannot be relied on to survive the trip.
130 */
131const stageRuntimeExternals = Effect.fn("stageRuntimeExternals")(function* (input: {
132 readonly repoRoot: string;
133 readonly stageDir: string;
134 readonly platform: BuildPlatform;
135 readonly arch: BuildArch;
136 readonly version: string;
137}) {
138 const fs = yield* FileSystem.FileSystem;
139 const path = yield* Path.Path;
140 const workspace = yield* decodeWorkspaceConfig(
141 yield* fs.readFileString(path.join(input.repoRoot, "pnpm-workspace.yaml")),
142 );
143 const catalog = workspace.catalog ?? {};
144 const serverDependencies = resolveCatalogDependencies(
145 serverPackageJson.dependencies,
146 catalog,
147 "apps/server",
148 );
149 const fffNodeVersion = serverDependencies["@ff-labs/fff-node"];
150 if (fffNodeVersion === undefined) {
151 return yield* new CliArchiveInputMissingError({
152 inputPath: "apps/server/package.json#dependencies['@ff-labs/fff-node']",
153 hint: "The archive stages fff's platform binary from this version.",
154 });
155 }
156 const dependencies = {
157 ...selectCliRuntimeExternalDependencies(serverDependencies),
158 ...resolveFffNativeDependencies(input.platform, input.arch, fffNodeVersion),
159 };
160 const patchedDependencies = createStagePatchedDependencies(
161 workspace.patchedDependencies ?? {},
162 dependencies,
163 );
164​
165 yield* fs.writeFileString(
166 path.join(input.stageDir, "package.json"),
167 `${yield* encodeJsonString({
168 name: "t3-runtime",
169 version: input.version,
170 private: true,
171 packageManager: rootPackageJson.packageManager,
172 dependencies,
173 })}\n`,
174 );
175 yield* fs.writeFileString(
176 path.join(input.stageDir, "pnpm-workspace.yaml"),
177 yield* encodeStageWorkspaceConfig({
178 ...createStageWorkspaceConfig({
179 platform: input.platform,
180 arch: input.arch,
181 ...(workspace.allowBuilds ? { allowBuilds: workspace.allowBuilds } : {}),
182 patchedDependencies,
183 overrides: resolveCatalogDependencies(workspace.overrides ?? {}, catalog, "apps/server"),
184 }),
185 nodeLinker: "hoisted",
186 }),
187 );
188 if (Object.keys(patchedDependencies).length > 0) {
189 yield* fs.copy(path.join(input.repoRoot, "patches"), path.join(input.stageDir, "patches"));
190 }
191​
192 const install = yield* resolveSpawnCommand("vp", [...STAGE_INSTALL_ARGS]);
193 yield* runCommand(
194 ChildProcess.make(install.command, install.args, {
195 cwd: input.stageDir,
196 shell: install.shell,
197 stdout: "inherit",
198 stderr: "inherit",
199 }),
200 "vp install --prod (cli archive runtime externals)",
201 );
202​
203 const platformKey = cliArchivePlatformKey(input.platform, input.arch);
204 const prebuildsDir = path.join(input.stageDir, "node_modules/node-pty/prebuilds");
205 const foreignPrebuilds = (yield* fs
206 .readDirectory(prebuildsDir)
207 .pipe(Effect.orElseSucceed((): ReadonlyArray<string> => []))).filter(
208 (entry) => entry !== platformKey,
209 );
210 for (const entry of [
211 "package.json",
212 "pnpm-workspace.yaml",
213 "pnpm-lock.yaml",
214 "patches",
215 "node_modules/.pnpm",
216 "node_modules/.modules.yaml",
217 "node_modules/.pnpm-workspace-state-v1.json",
218 "node_modules/.bin",
219 ...foreignPrebuilds.map((entry) => `node_modules/node-pty/prebuilds/${entry}`),
220 ]) {
221 yield* fs.remove(path.join(input.stageDir, entry), { recursive: true, force: true });
222 }
223 // A hoisted install still leaves nested `node_modules/.bin` shim directories
224 // inside packages that declare bins (msgpackr-extract's). They are symlinks
225 // nothing runs, and the npm registry refuses a tarball that contains any
226 // symlink, so strip every `.bin` directory below node_modules.
227 yield* removeNestedBinDirectories(fs, path, path.join(input.stageDir, "node_modules"));
228});
229​
230const removeNestedBinDirectories = Effect.fn("build-cli-archive.removeNestedBinDirectories")(
231 function* (
232 fs: FileSystem.FileSystem,
233 path: Path.Path,
234 root: string,
235 ): Effect.fn.Return<void, PlatformError.PlatformError> {
236 const entries = yield* fs.readDirectory(root).pipe(Effect.orElseSucceed(() => []));
237 for (const entry of entries) {
238 const child = path.join(root, entry);
239 if (entry === ".bin") {
240 yield* fs.remove(child, { recursive: true, force: true });
241 continue;
242 }
243 const info = yield* fs.stat(child).pipe(Effect.option);
244 if (Option.isSome(info) && info.value.type === "Directory") {
245 yield* removeNestedBinDirectories(fs, path, child);
246 }
247 }
248 },
249);
250​
251const stageWebClient = Effect.fn("stageWebClient")(function* (source: string, target: string) {
252 const fs = yield* FileSystem.FileSystem;
253 const path = yield* Path.Path;
254 yield* fs.copy(source, target);
255 const maps = (yield* fs.readDirectory(target, { recursive: true })).filter((entry) =>
256 entry.endsWith(".map"),
257 );
258 for (const entry of maps) {
259 yield* fs.remove(path.join(target, entry), { force: true });
260 }
261});
262​
263const MacSigningConfig = Config.all({
264 identity: Config.String("T3CODE_CLI_MAC_SIGN_IDENTITY").pipe(Config.option),
265 appleApiKey: Config.String("APPLE_API_KEY").pipe(Config.option),
266 appleApiKeyId: Config.String("APPLE_API_KEY_ID").pipe(Config.option),
267 appleApiIssuer: Config.String("APPLE_API_ISSUER").pipe(Config.option),
268});
269​
270/**
271 * Apple Silicon refuses to run unsigned Mach-O binaries at all, so the
272 * executable is always signed: ad hoc when no identity is configured, or with
273 * the Developer ID plus notarization when it is. The hardened runtime that
274 * notarization requires only loads signed libraries, so every native addon in
275 * the archive is signed with the same identity.
276 */
277const signMacArchiveContents = Effect.fn("signMacArchiveContents")(function* (input: {
278 readonly repoRoot: string;
279 readonly contentDir: string;
280 readonly executablePath: string;
281}) {
282 const fs = yield* FileSystem.FileSystem;
283 const path = yield* Path.Path;
284 const signing = yield* MacSigningConfig;
285 const identity = Option.getOrUndefined(signing.identity)?.trim() || "-";
286​
287 const entitlements = path.join(input.repoRoot, "apps/server/resources/cli-entitlements.plist");
288 const libraries = (yield* fs.readDirectory(input.contentDir, { recursive: true }))
289 .filter(
290 (entry) =>
291 entry.endsWith(".node") ||
292 entry.endsWith(".dylib") ||
293 entry.endsWith("spawn-helper") ||
294 entry.endsWith("t3-resource-monitor"),
295 )
296 .map((entry) => path.join(input.contentDir, entry));
297​
298 for (const target of [...libraries, input.executablePath]) {
299 yield* runCommand(
300 ChildProcess.make("codesign", [
301 "--force",
302 "--sign",
303 identity,
304 ...(identity === "-" ? [] : ["--options", "runtime", "--timestamp"]),
305 ...(target === input.executablePath ? ["--entitlements", entitlements] : []),
306 target,
307 ]),
308 `codesign ${path.relative(input.contentDir, target)}`,
309 );
310 }
311 if (identity === "-") {
312 yield* Effect.log("[cli-archive] Signed ad hoc (no T3CODE_CLI_MAC_SIGN_IDENTITY).");
313 return;
314 }
315​
316 const apiKey = Option.getOrUndefined(signing.appleApiKey);
317 const apiKeyId = Option.getOrUndefined(signing.appleApiKeyId);
318 const apiIssuer = Option.getOrUndefined(signing.appleApiIssuer);
319 if (!apiKey || !apiKeyId || !apiIssuer) {
320 yield* Effect.logWarning(
321 "[cli-archive] Developer ID signed but not notarized (missing APPLE_API_KEY*).",
322 );
323 return;
324 }
325 // notarytool only accepts archives, and a bare executable cannot be stapled,
326 // so notarize a zip of the binary and rely on the online ticket lookup.
327 const notarizeZip = path.join(path.dirname(input.executablePath), ".notarize-t3.zip");
328 yield* runCommand(
329 ChildProcess.make("ditto", ["-c", "-k", "--keepParent", input.executablePath, notarizeZip]),
330 "ditto (notarization zip)",
331 );
332 yield* runCommand(
333 ChildProcess.make("xcrun", [
334 "notarytool",
335 "submit",
336 notarizeZip,
337 "--key",
338 apiKey,
339 "--key-id",
340 apiKeyId,
341 "--issuer",
342 apiIssuer,
343 "--wait",
344 ]),
345 "notarytool submit",
346 ).pipe(Effect.ensuring(fs.remove(notarizeZip, { force: true }).pipe(Effect.ignore)));
347 yield* Effect.log("[cli-archive] Notarized t3.");
348});
349​
350const WindowsSigningConfig = Config.all({
351 endpoint: Config.String("AZURE_TRUSTED_SIGNING_ENDPOINT").pipe(Config.option),
352 accountName: Config.String("AZURE_TRUSTED_SIGNING_ACCOUNT_NAME").pipe(Config.option),
353 certificateProfileName: Config.String("AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME").pipe(
354 Config.option,
355 ),
356});
357​
358/**
359 * Node's --build-sea injects the blob into a copy of node.exe by rebuilding its
360 * resource section but, unlike its Mach-O path, leaves node's original
361 * Authenticode data-directory entry in the PE header. The file grows, so the
362 * entry now points into the middle of the new section at bytes that are not a
363 * certificate table.
364 */
365const stripStaleAuthenticodeEntry = Effect.fn("stripStaleAuthenticodeEntry")(function* (
366 executablePath: string,
367) {
368 const fs = yield* FileSystem.FileSystem;
369 const bytes = yield* fs.readFile(executablePath);
370 const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
371 const peOffset = view.getUint32(0x3c, true);
372 if (view.getUint32(peOffset, true) !== 0x00004550) {
373 return yield* new CliArchiveInputMissingError({
374 inputPath: executablePath,
375 hint: "Expected a PE executable to strip the stale signature entry from.",
376 });
377 }
378 const optionalHeader = peOffset + 24;
379 const magic = view.getUint16(optionalHeader, true);
380 // Data directories start at +112 (PE32+) or +96 (PE32); the certificate
381 // table is directory index 4, eight bytes (file offset, size).
382 const securityEntry = optionalHeader + (magic === 0x20b ? 112 : 96) + 4 * 8;
383 const offset = view.getUint32(securityEntry, true);
384 const size = view.getUint32(securityEntry + 4, true);
385 if (offset === 0 && size === 0) return;
386 if (offset + size === bytes.byteLength) {
387 // A certificate table that still ends at EOF is intact; leave it for
388 // signtool to replace rather than second-guessing it here.
389 return;
390 }
391 view.setUint32(securityEntry, 0, true);
392 view.setUint32(securityEntry + 4, 0, true);
393 yield* fs.writeFile(executablePath, bytes);
394 yield* Effect.log(
395 `[cli-archive] Cleared the stale Authenticode entry (offset ${String(offset)}, size ${String(size)}) left by --build-sea.`,
396 );
397});
398​
399const signWindowsExecutable = Effect.fn("signWindowsExecutable")(function* (
400 executablePath: string,
401) {
402 const signing = yield* WindowsSigningConfig;
403 const endpoint = Option.getOrUndefined(signing.endpoint);
404 const accountName = Option.getOrUndefined(signing.accountName);
405 const profile = Option.getOrUndefined(signing.certificateProfileName);
406 if (!endpoint || !accountName || !profile) {
407 yield* Effect.log("[cli-archive] Windows signing disabled (missing Azure Trusted Signing).");
408 return;
409 }
410 yield* stripStaleAuthenticodeEntry(executablePath);
411 if ((yield* HostProcess.Platform) !== "win32") {
412 yield* signWithJsign(executablePath);
413 yield* Effect.log("[cli-archive] Signed t3.exe (Azure Trusted Signing via jsign).");
414 return;
415 }
416 const quote = (value: string) => `'${value.replaceAll("'", "''")}'`;
417 const script = [
418 "$ErrorActionPreference = 'Stop';",
419 "Invoke-TrustedSigning",
420 `-Endpoint ${quote(endpoint)}`,
421 `-CodeSigningAccountName ${quote(accountName)}`,
422 `-CertificateProfileName ${quote(profile)}`,
423 "-FileDigest 'SHA256'",
424 "-TimestampRfc3161 'http://timestamp.acs.microsoft.com'",
425 "-TimestampDigest 'SHA256'",
426 `-Files ${quote(executablePath)}`,
427 ].join(" ");
428 yield* runCommand(
429 ChildProcess.make("pwsh", ["-NoProfile", "-NonInteractive", "-Command", script]),
430 "Invoke-TrustedSigning t3.exe",
431 );
432 yield* Effect.log("[cli-archive] Signed t3.exe (Azure Trusted Signing).");
433});
434​
435const buildCliArchive = Effect.fn("buildCliArchive")(function* (input: {
436 readonly platform: BuildPlatform;
437 readonly arch: BuildArch;
438 readonly version: string;
439 readonly outputDir: string;
440 readonly resourceMonitorDir: Option.Option<string>;
441}) {
442 const fs = yield* FileSystem.FileSystem;
443 const path = yield* Path.Path;
444 const repoRoot = yield* RepoRoot;
445 const serverDir = path.join(repoRoot, "apps/server");
446 const executableName = input.platform === "win" ? "t3.exe" : "t3";
447 // tsdown suffixes cross-built executables with their target (t3-darwin-x64);
448 // a host build is plain t3. Prefer the exact target when both exist.
449 const targetKey = `${input.platform === "mac" ? "darwin" : input.platform}-${input.arch}`;
450 const targetExecutable = path.join(
451 serverDir,
452 "dist-exe",
453 `t3-${targetKey}${input.platform === "win" ? ".exe" : ""}`,
454 );
455 // The unsuffixed host build is only a valid stand-in when it was built for
456 // this platform and architecture; otherwise a missing target must fail.
457 const hostPlatform = yield* HostProcess.Platform;
458 const hostKey = `${hostPlatform === "win32" ? "win" : hostPlatform}-${yield* HostProcess.Architecture}`;
459 const builtExecutable = (yield* fs.exists(targetExecutable))
460 ? targetExecutable
461 : targetKey === hostKey
462 ? path.join(serverDir, "dist-exe", executableName)
463 : targetExecutable;
464 const webClient = path.join(serverDir, "dist/client");
465 const resourceMonitorDir = Option.getOrElse(input.resourceMonitorDir, () =>
466 path.join(serverDir, "dist/resource-monitor"),
467 );
468​
469 yield* requireInput(
470 builtExecutable,
471 `Run \`node apps/server/scripts/cli.ts build-exe --target ${targetKey}\` first.`,
472 );
473 yield* requireInput(path.join(webClient, "index.html"), "Run `vp run --filter t3 build` first.");
474 yield* requireInput(
475 resourceMonitorDir,
476 "Build the resource monitor or pass --resource-monitor-dir.",
477 );
478​
479 const stem = cliArchiveStem(input.version, input.platform, input.arch);
480 const stageRoot = yield* fs.makeTempDirectoryScoped({ prefix: "t3-cli-archive-" });
481 const contentDir = path.join(stageRoot, stem);
482 yield* fs.makeDirectory(contentDir, { recursive: true });
483​
484 yield* Effect.log(`[cli-archive] Staging ${stem}...`);
485 yield* fs.copyFile(builtExecutable, path.join(contentDir, executableName));
486 yield* stageWebClient(webClient, path.join(contentDir, "client"));
487 yield* fs.copy(resourceMonitorDir, path.join(contentDir, "resource-monitor"));
488 yield* stageRuntimeExternals({
489 repoRoot,
490 stageDir: contentDir,
491 platform: input.platform,
492 arch: input.arch,
493 version: input.version,
494 });
495​
496 const executablePath = path.join(contentDir, executableName);
497 if (input.platform === "mac") {
498 yield* signMacArchiveContents({ repoRoot, contentDir, executablePath });
499 } else if (input.platform === "win") {
500 yield* signWindowsExecutable(executablePath);
501 }
502 if (input.platform !== "win") {
503 yield* fs.chmod(executablePath, 0o755);
504 }
505​
506 yield* fs.makeDirectory(input.outputDir, { recursive: true });
507 const archivePath = path.join(
508 input.outputDir,
509 cliArchiveFileName(input.version, input.platform, input.arch),
510 );
511 yield* fs.remove(archivePath, { force: true });
512 if (input.platform === "win" && hostPlatform !== "win32") {
513 yield* runCommand(
514 ChildProcess.make("zip", ["-q", "-r", "-X", path.resolve(archivePath), stem], {
515 cwd: stageRoot,
516 }),
517 "zip",
518 );
519 } else if (input.platform === "win") {
520 // Windows ships bsdtar, which writes zip natively. Name it by path: under
521 // the Git Bash shell CI uses, a bare `tar` is GNU tar, which neither
522 // writes zip nor accepts a drive-letter path.
523 yield* runCommand(
524 ChildProcess.make(windowsSystemTar(), ["-a", "-c", "-f", archivePath, "-C", stageRoot, stem]),
525 "tar (zip)",
526 );
527 } else {
528 // On Linux, pnpm hard-links identical files out of its store and node-gyp
529 // hard-links build outputs, and GNU tar records those as link entries.
530 // The npm registry rejects a tarball containing any, and the npm platform
531 // packages are re-packed from this archive's contents, so store every
532 // file as a file. macOS's bsdtar has no such flag; pnpm clones there.
533 yield* runCommand(
534 ChildProcess.make("tar", [
535 ...(input.platform === "linux" ? ["--hard-dereference"] : []),
536 "-czf",
537 archivePath,
538 "-C",
539 stageRoot,
540 stem,
541 ]),
542 "tar (gzip)",
543 );
544 }
545 const stat = yield* fs.stat(archivePath);
546 yield* Effect.log(`[cli-archive] Wrote ${archivePath} (${String(stat.size)} bytes).`);
547 return archivePath;
548});
549​
550const command = Command.make(
551 "build-cli-archive",
552 {
553 platform: Flag.Literals("platform", BuildPlatform.literals),
554 arch: Flag.Literals("arch", BuildArch.literals),
555 version: Flag.String("version").pipe(
556 Flag.withDescription("Release version for the archive name."),
557 ),
558 outputDir: Flag.String("output-dir").pipe(Flag.withDefault("release-cli")),
559 resourceMonitorDir: Flag.String("resource-monitor-dir").pipe(
560 Flag.withDescription(
561 "Directory laid out like dist/resource-monitor (defaults to apps/server/dist/resource-monitor).",
562 ),
563 Flag.optional,
564 ),
565 },
566 (input) => buildCliArchive(input).pipe(Effect.scoped),
567).pipe(Command.withDescription("Package the t3 single-executable into a per-platform archive."));
568​
569if (import.meta.main) {
570 Command.run(command, { version: "0.0.0" }).pipe(
571 Effect.provide(Layer.mergeAll(Logger.layer([Logger.consolePretty()]), NodeServices.layer)),
572 NodeRuntime.runMain,
573 );