| ... | ... | @@ -121,6 +121,36 @@ const collectStreamAsString = <E>(stream: Stream.Stream<Uint8Array, E>): Effect. |
| 121 | 121 | ), |
| 122 | 122 | ); |
| 123 | 123 | |
| 124 | const COMMAND_OUTPUT_TAIL_LENGTH = 20_000; |
| 125 | |
| 126 | function appendOutputTail(acc: string, chunk: string): string { |
| 127 | const next = acc + chunk; |
| 128 | return next.length > COMMAND_OUTPUT_TAIL_LENGTH ? next.slice(-COMMAND_OUTPUT_TAIL_LENGTH) : next; |
| 129 | } |
| 130 | |
| 131 | function formatOutputSection(label: string, output: string): string | undefined { |
| 132 | const trimmed = output.trim(); |
| 133 | if (!trimmed) return undefined; |
| 134 | return `${label} tail:\n${trimmed}`; |
| 135 | } |
| 136 | |
| 137 | const collectCommandStream = <E>( |
| 138 | stream: Stream.Stream<Uint8Array, E>, |
| 139 | output: NodeJS.WriteStream, |
| 140 | verbose: boolean, |
| 141 | ): Effect.Effect<string, E> => |
| 142 | stream.pipe( |
| 143 | Stream.decodeText(), |
| 144 | Stream.runFoldEffect( |
| 145 | () => "", |
| 146 | (acc, chunk) => |
| 147 | Effect.as( |
| 148 | verbose ? Effect.sync(() => output.write(chunk)) : Effect.void, |
| 149 | appendOutputTail(acc, chunk), |
| 150 | ), |
| 151 | ), |
| 152 | ); |
| 153 | |
| 124 | 154 | const spawnAndCollectOutput = Effect.fn("spawnAndCollectOutput")(function* ( |
| 125 | 155 | command: ChildProcess.Command, |
| 126 | 156 | ) { |
| ... | ... | @@ -353,20 +383,33 @@ export const resolveBuildOptions = Effect.fn("resolveBuildOptions")(function* ( |
| 353 | 383 | } satisfies ResolvedBuildOptions; |
| 354 | 384 | }); |
| 355 | 385 | |
| 356 | | const commandOutputOptions = (verbose: boolean) => |
| 357 | | ({ |
| 358 | | stdout: verbose ? "inherit" : "ignore", |
| 359 | | stderr: "inherit", |
| 360 | | }) as const; |
| 361 | | |
| 362 | | const runCommand = Effect.fn("runCommand")(function* (command: ChildProcess.Command) { |
| 386 | const runCommand = Effect.fn("runCommand")(function* ( |
| 387 | command: ChildProcess.Command, |
| 388 | options: { |
| 389 | readonly label?: string; |
| 390 | readonly verbose: boolean; |
| 391 | }, |
| 392 | ) { |
| 363 | 393 | const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; |
| 364 | 394 | const child = yield* commandSpawner.spawn(command); |
| 365 | | const exitCode = yield* child.exitCode; |
| 395 | const [stdout, stderr, exitCode] = yield* Effect.all( |
| 396 | [ |
| 397 | collectCommandStream(child.stdout, process.stdout, options.verbose), |
| 398 | collectCommandStream(child.stderr, process.stderr, options.verbose), |
| 399 | child.exitCode.pipe(Effect.map(Number)), |
| 400 | ], |
| 401 | { concurrency: "unbounded" }, |
| 402 | ); |
| 366 | 403 | |
| 367 | 404 | if (exitCode !== 0) { |
| 405 | const outputSections = [ |
| 406 | options.label ? `Command: ${options.label}` : undefined, |
| 407 | formatOutputSection("stdout", stdout), |
| 408 | formatOutputSection("stderr", stderr), |
| 409 | ].filter((section): section is string => section !== undefined); |
| 410 | const outputSuffix = outputSections.length > 0 ? `\n\n${outputSections.join("\n\n")}` : ""; |
| 368 | 411 | return yield* new BuildScriptError({ |
| 369 | | message: `Command exited with non-zero exit code (${exitCode})`, |
| 412 | message: `Command exited with non-zero exit code (${exitCode})${outputSuffix}`, |
| 370 | 413 | }); |
| 371 | 414 | } |
| 372 | 415 | }); |
| ... | ... | @@ -386,24 +429,25 @@ function generateMacIconSet( |
| 386 | 429 | const iconSizes = [16, 32, 128, 256, 512] as const; |
| 387 | 430 | for (const size of iconSizes) { |
| 388 | 431 | yield* runCommand( |
| 389 | | ChildProcess.make({ |
| 390 | | ...commandOutputOptions(verbose), |
| 391 | | })`sips -z ${size} ${size} ${sourcePng} --out ${path.join(iconsetDir, `icon_${size}x${size}.png`)}`, |
| 432 | ChildProcess.make( |
| 433 | {}, |
| 434 | )`sips -z ${size} ${size} ${sourcePng} --out ${path.join(iconsetDir, `icon_${size}x${size}.png`)}`, |
| 435 | { label: `sips icon ${size}x${size}`, verbose }, |
| 392 | 436 | ); |
| 393 | 437 | |
| 394 | 438 | const retinaSize = size * 2; |
| 395 | 439 | yield* runCommand( |
| 396 | | ChildProcess.make({ |
| 397 | | ...commandOutputOptions(verbose), |
| 398 | | })`sips -z ${retinaSize} ${retinaSize} ${sourcePng} --out ${path.join(iconsetDir, `icon_${size}x${size}@2x.png`)}`, |
| 440 | ChildProcess.make( |
| 441 | {}, |
| 442 | )`sips -z ${retinaSize} ${retinaSize} ${sourcePng} --out ${path.join(iconsetDir, `icon_${size}x${size}@2x.png`)}`, |
| 443 | { label: `sips icon ${size}x${size}@2x`, verbose }, |
| 399 | 444 | ); |
| 400 | 445 | } |
| 401 | 446 | |
| 402 | | yield* runCommand( |
| 403 | | ChildProcess.make({ |
| 404 | | ...commandOutputOptions(verbose), |
| 405 | | })`iconutil -c icns ${iconsetDir} -o ${targetIcns}`, |
| 406 | | ); |
| 447 | yield* runCommand(ChildProcess.make({})`iconutil -c icns ${iconsetDir} -o ${targetIcns}`, { |
| 448 | label: "iconutil icns", |
| 449 | verbose, |
| 450 | }); |
| 407 | 451 | }); |
| 408 | 452 | } |
| 409 | 453 | |
| ... | ... | @@ -424,11 +468,10 @@ function stageMacIcons(stageResourcesDir: string, sourcePng: string, verbose: bo |
| 424 | 468 | const iconPngPath = path.join(stageResourcesDir, "icon.png"); |
| 425 | 469 | const iconIcnsPath = path.join(stageResourcesDir, "icon.icns"); |
| 426 | 470 | |
| 427 | | yield* runCommand( |
| 428 | | ChildProcess.make({ |
| 429 | | ...commandOutputOptions(verbose), |
| 430 | | })`sips -z 512 512 ${sourcePng} --out ${iconPngPath}`, |
| 431 | | ); |
| 471 | yield* runCommand(ChildProcess.make({})`sips -z 512 512 ${sourcePng} --out ${iconPngPath}`, { |
| 472 | label: "sips mac icon", |
| 473 | verbose, |
| 474 | }); |
| 432 | 475 | |
| 433 | 476 | yield* generateMacIconSet(sourcePng, iconIcnsPath, tmpRoot, path, verbose); |
| 434 | 477 | }); |
| ... | ... | @@ -468,9 +511,8 @@ function stageLinuxIconSize( |
| 468 | 511 | ) { |
| 469 | 512 | const resize = (command: string) => |
| 470 | 513 | runCommand( |
| 471 | | ChildProcess.make(command, [sourcePng, "-resize", `${iconSize}x${iconSize}`, targetPng], { |
| 472 | | ...commandOutputOptions(verbose), |
| 473 | | }), |
| 514 | ChildProcess.make(command, [sourcePng, "-resize", `${iconSize}x${iconSize}`, targetPng]), |
| 515 | { label: `${command} linux icon ${iconSize}x${iconSize}`, verbose }, |
| 474 | 516 | ); |
| 475 | 517 | |
| 476 | 518 | return resize("magick").pipe( |
| ... | ... | @@ -778,10 +820,10 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* ( |
| 778 | 820 | yield* runCommand( |
| 779 | 821 | ChildProcess.make({ |
| 780 | 822 | cwd: repoRoot, |
| 781 | | ...commandOutputOptions(options.verbose), |
| 782 | 823 | // Windows needs shell mode to resolve .cmd shims (e.g. vp.cmd). |
| 783 | 824 | shell: process.platform === "win32", |
| 784 | 825 | })`vp run build:desktop`, |
| 826 | { label: "vp run build:desktop", verbose: options.verbose }, |
| 785 | 827 | ); |
| 786 | 828 | } |
| 787 | 829 | |
| ... | ... | @@ -858,10 +900,10 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* ( |
| 858 | 900 | yield* runCommand( |
| 859 | 901 | ChildProcess.make({ |
| 860 | 902 | cwd: stageAppDir, |
| 861 | | ...commandOutputOptions(options.verbose), |
| 862 | 903 | // Windows needs shell mode to resolve .cmd shims (e.g. vp.cmd). |
| 863 | 904 | shell: process.platform === "win32", |
| 864 | 905 | })`vp install --prod --no-optional`, |
| 906 | { label: "vp install --prod --no-optional", verbose: options.verbose }, |
| 865 | 907 | ); |
| 866 | 908 | |
| 867 | 909 | const buildEnv: NodeJS.ProcessEnv = { |
| ... | ... | @@ -890,6 +932,12 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* ( |
| 890 | 932 | buildEnv.npm_config_msvs_version = buildEnv.npm_config_msvs_version ?? "2022"; |
| 891 | 933 | buildEnv.GYP_MSVS_VERSION = buildEnv.GYP_MSVS_VERSION ?? "2022"; |
| 892 | 934 | } |
| 935 | if (options.verbose) { |
| 936 | buildEnv.DEBUG = |
| 937 | buildEnv.DEBUG === undefined || buildEnv.DEBUG === "" |
| 938 | ? "electron-builder,electron-builder:*" |
| 939 | : `${buildEnv.DEBUG},electron-builder,electron-builder:*`; |
| 940 | } |
| 893 | 941 | |
| 894 | 942 | yield* Effect.log( |
| 895 | 943 | `[desktop-artifact] Building ${options.platform}/${options.target} (arch=${options.arch}, version=${appVersion})...`, |
| ... | ... | @@ -898,10 +946,13 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* ( |
| 898 | 946 | ChildProcess.make({ |
| 899 | 947 | cwd: stageAppDir, |
| 900 | 948 | env: buildEnv, |
| 901 | | ...commandOutputOptions(options.verbose), |
| 902 | 949 | // Windows needs shell mode to resolve .cmd shims. |
| 903 | 950 | shell: process.platform === "win32", |
| 904 | 951 | })`vp dlx electron-builder ${platformConfig.cliFlag} --${options.arch} --publish never`, |
| 952 | { |
| 953 | label: `vp dlx electron-builder ${platformConfig.cliFlag} --${options.arch} --publish never`, |
| 954 | verbose: options.verbose, |
| 955 | }, |
| 905 | 956 | ); |
| 906 | 957 | |
| 907 | 958 | const stageDistDir = path.join(stageAppDir, "dist"); |