| ... | @@ -121,6 +121,36 @@ const collectStreamAsString = <E>(stream: Stream.Stream<Uint8Array, E>): Effect. | ... | @@ -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 | const spawnAndCollectOutput = Effect.fn("spawnAndCollectOutput")(function* ( | 154 | const spawnAndCollectOutput = Effect.fn("spawnAndCollectOutput")(function* ( |
| 125 | command: ChildProcess.Command, | 155 | command: ChildProcess.Command, |
| 126 | ) { | 156 | ) { |
| ... | @@ -353,20 +383,33 @@ export const resolveBuildOptions = Effect.fn("resolveBuildOptions")(function* ( | ... | @@ -353,20 +383,33 @@ export const resolveBuildOptions = Effect.fn("resolveBuildOptions")(function* ( |
| 353 | } satisfies ResolvedBuildOptions; | 383 | } satisfies ResolvedBuildOptions; |
| 354 | }); | 384 | }); |
| 355 | | 385 | |
| 356 | const commandOutputOptions = (verbose: boolean) => | 386 | const runCommand = Effect.fn("runCommand")(function* ( |
| 357 | ({ | 387 | command: ChildProcess.Command, |
| 358 | stdout: verbose ? "inherit" : "ignore", | 388 | options: { |
| 359 | stderr: "inherit", | 389 | readonly label?: string; |
| 360 | }) as const; | 390 | readonly verbose: boolean; |
| 361 | | 391 | }, |
| 362 | const runCommand = Effect.fn("runCommand")(function* (command: ChildProcess.Command) { | 392 | ) { |
| 363 | const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; | 393 | const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; |
| 364 | const child = yield* commandSpawner.spawn(command); | 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 | if (exitCode !== 0) { | 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 | return yield* new BuildScriptError({ | 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,24 +429,25 @@ function generateMacIconSet( |
| 386 | const iconSizes = [16, 32, 128, 256, 512] as const; | 429 | const iconSizes = [16, 32, 128, 256, 512] as const; |
| 387 | for (const size of iconSizes) { | 430 | for (const size of iconSizes) { |
| 388 | yield* runCommand( | 431 | yield* runCommand( |
| 389 | ChildProcess.make({ | 432 | ChildProcess.make( |
| 390 | ...commandOutputOptions(verbose), | 433 | {}, |
| 391 | })`sips -z ${size} ${size} ${sourcePng} --out ${path.join(iconsetDir, `icon_${size}x${size}.png`)}`, | 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 | const retinaSize = size * 2; | 438 | const retinaSize = size * 2; |
| 395 | yield* runCommand( | 439 | yield* runCommand( |
| 396 | ChildProcess.make({ | 440 | ChildProcess.make( |
| 397 | ...commandOutputOptions(verbose), | 441 | {}, |
| 398 | })`sips -z ${retinaSize} ${retinaSize} ${sourcePng} --out ${path.join(iconsetDir, `icon_${size}x${size}@2x.png`)}`, | 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( | 447 | yield* runCommand(ChildProcess.make({})`iconutil -c icns ${iconsetDir} -o ${targetIcns}`, { |
| 403 | ChildProcess.make({ | 448 | label: "iconutil icns", |
| 404 | ...commandOutputOptions(verbose), | 449 | verbose, |
| 405 | })`iconutil -c icns ${iconsetDir} -o ${targetIcns}`, | 450 | }); |
| 406 | ); | | |
| 407 | }); | 451 | }); |
| 408 | } | 452 | } |
| 409 | | 453 | |
| ... | @@ -424,11 +468,10 @@ function stageMacIcons(stageResourcesDir: string, sourcePng: string, verbose: bo | ... | @@ -424,11 +468,10 @@ function stageMacIcons(stageResourcesDir: string, sourcePng: string, verbose: bo |
| 424 | const iconPngPath = path.join(stageResourcesDir, "icon.png"); | 468 | const iconPngPath = path.join(stageResourcesDir, "icon.png"); |
| 425 | const iconIcnsPath = path.join(stageResourcesDir, "icon.icns"); | 469 | const iconIcnsPath = path.join(stageResourcesDir, "icon.icns"); |
| 426 | | 470 | |
| 427 | yield* runCommand( | 471 | yield* runCommand(ChildProcess.make({})`sips -z 512 512 ${sourcePng} --out ${iconPngPath}`, { |
| 428 | ChildProcess.make({ | 472 | label: "sips mac icon", |
| 429 | ...commandOutputOptions(verbose), | 473 | verbose, |
| 430 | })`sips -z 512 512 ${sourcePng} --out ${iconPngPath}`, | 474 | }); |
| 431 | ); | | |
| 432 | | 475 | |
| 433 | yield* generateMacIconSet(sourcePng, iconIcnsPath, tmpRoot, path, verbose); | 476 | yield* generateMacIconSet(sourcePng, iconIcnsPath, tmpRoot, path, verbose); |
| 434 | }); | 477 | }); |
| ... | @@ -468,9 +511,8 @@ function stageLinuxIconSize( | ... | @@ -468,9 +511,8 @@ function stageLinuxIconSize( |
| 468 | ) { | 511 | ) { |
| 469 | const resize = (command: string) => | 512 | const resize = (command: string) => |
| 470 | runCommand( | 513 | runCommand( |
| 471 | ChildProcess.make(command, [sourcePng, "-resize", `${iconSize}x${iconSize}`, targetPng], { | 514 | ChildProcess.make(command, [sourcePng, "-resize", `${iconSize}x${iconSize}`, targetPng]), |
| 472 | ...commandOutputOptions(verbose), | 515 | { label: `${command} linux icon ${iconSize}x${iconSize}`, verbose }, |
| 473 | }), | | |
| 474 | ); | 516 | ); |
| 475 | | 517 | |
| 476 | return resize("magick").pipe( | 518 | return resize("magick").pipe( |
| ... | @@ -778,10 +820,10 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* ( | ... | @@ -778,10 +820,10 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* ( |
| 778 | yield* runCommand( | 820 | yield* runCommand( |
| 779 | ChildProcess.make({ | 821 | ChildProcess.make({ |
| 780 | cwd: repoRoot, | 822 | cwd: repoRoot, |
| 781 | ...commandOutputOptions(options.verbose), | | |
| 782 | // Windows needs shell mode to resolve .cmd shims (e.g. vp.cmd). | 823 | // Windows needs shell mode to resolve .cmd shims (e.g. vp.cmd). |
| 783 | shell: process.platform === "win32", | 824 | shell: process.platform === "win32", |
| 784 | })`vp run build:desktop`, | 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,10 +900,10 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* ( |
| 858 | yield* runCommand( | 900 | yield* runCommand( |
| 859 | ChildProcess.make({ | 901 | ChildProcess.make({ |
| 860 | cwd: stageAppDir, | 902 | cwd: stageAppDir, |
| 861 | ...commandOutputOptions(options.verbose), | | |
| 862 | // Windows needs shell mode to resolve .cmd shims (e.g. vp.cmd). | 903 | // Windows needs shell mode to resolve .cmd shims (e.g. vp.cmd). |
| 863 | shell: process.platform === "win32", | 904 | shell: process.platform === "win32", |
| 864 | })`vp install --prod --no-optional`, | 905 | })`vp install --prod --no-optional`, |
| | 906 | { label: "vp install --prod --no-optional", verbose: options.verbose }, |
| 865 | ); | 907 | ); |
| 866 | | 908 | |
| 867 | const buildEnv: NodeJS.ProcessEnv = { | 909 | const buildEnv: NodeJS.ProcessEnv = { |
| ... | @@ -890,6 +932,12 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* ( | ... | @@ -890,6 +932,12 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* ( |
| 890 | buildEnv.npm_config_msvs_version = buildEnv.npm_config_msvs_version ?? "2022"; | 932 | buildEnv.npm_config_msvs_version = buildEnv.npm_config_msvs_version ?? "2022"; |
| 891 | buildEnv.GYP_MSVS_VERSION = buildEnv.GYP_MSVS_VERSION ?? "2022"; | 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 | yield* Effect.log( | 942 | yield* Effect.log( |
| 895 | `[desktop-artifact] Building ${options.platform}/${options.target} (arch=${options.arch}, version=${appVersion})...`, | 943 | `[desktop-artifact] Building ${options.platform}/${options.target} (arch=${options.arch}, version=${appVersion})...`, |
| ... | @@ -898,10 +946,13 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* ( | ... | @@ -898,10 +946,13 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* ( |
| 898 | ChildProcess.make({ | 946 | ChildProcess.make({ |
| 899 | cwd: stageAppDir, | 947 | cwd: stageAppDir, |
| 900 | env: buildEnv, | 948 | env: buildEnv, |
| 901 | ...commandOutputOptions(options.verbose), | | |
| 902 | // Windows needs shell mode to resolve .cmd shims. | 949 | // Windows needs shell mode to resolve .cmd shims. |
| 903 | shell: process.platform === "win32", | 950 | shell: process.platform === "win32", |
| 904 | })`vp dlx electron-builder ${platformConfig.cliFlag} --${options.arch} --publish never`, | 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 | const stageDistDir = path.join(stageAppDir, "dist"); | 958 | const stageDistDir = path.join(stageAppDir, "dist"); |