1
#!/usr/bin/env node
2
3
import { spawnSync } from "node:child_process";
4
+import { existsSync } from "node:fs";
5
+import { join } from "node:path";
6
7
import rootPackageJson from "../package.json" with { type: "json" };
8
import desktopPackageJson from "../apps/desktop/package.json" with { type: "json" };
9
import serverPackageJson from "../apps/server/package.json" with { type: "json" };
10
11
+import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";
12
import { resolveCatalogDependencies } from "./lib/resolve-catalog.ts";
13
14
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
23
const RepoRoot = Effect.service(Path.Path).pipe(
24
Effect.flatMap((path) => path.fromFileUrl(new URL("..", import.meta.url))),
25
);
23
-const IconSource = Effect.zipWith(RepoRoot, Effect.service(Path.Path), (repoRoot, path) =>
24
- path.join(repoRoot, "assets/macos-icon-1024.png"),
26
+const ProductionMacIconSource = Effect.zipWith(RepoRoot, Effect.service(Path.Path), (repoRoot, path) =>
27
+ path.join(repoRoot, BRAND_ASSET_PATHS.productionMacIconPng),
28
+);
29
+const ProductionLinuxIconSource = Effect.zipWith(
30
+ RepoRoot,
31
+ Effect.service(Path.Path),
32
+ (repoRoot, path) => path.join(repoRoot, BRAND_ASSET_PATHS.productionLinuxIconPng),
33
+);
34
+const ProductionWindowsIconSource = Effect.zipWith(
35
+ RepoRoot,
36
+ Effect.service(Path.Path),
37
+ (repoRoot, path) => path.join(repoRoot, BRAND_ASSET_PATHS.productionWindowsIconIco),
38
);
39
const encodeJsonString = Schema.encodeEffect(Schema.UnknownFromJsonString);
40
117
return hash.toLowerCase();
118
}
119
120
+function resolvePythonForNodeGyp(): string | undefined {
121
+ const configured = process.env.npm_config_python ?? process.env.PYTHON;
122
+ if (configured && existsSync(configured)) {
123
+ return configured;
124
+ }
125
+
126
+ if (process.platform === "win32") {
127
+ const localAppData = process.env.LOCALAPPDATA;
128
+ if (localAppData) {
129
+ for (const version of ["Python313", "Python312", "Python311", "Python310"]) {
130
+ const candidate = join(localAppData, "Programs", "Python", version, "python.exe");
131
+ if (existsSync(candidate)) {
132
+ return candidate;
133
+ }
134
+ }
135
+ }
136
+ }
137
+
138
+ const probe = spawnSync("python", ["-c", "import sys;print(sys.executable)"], {
139
+ encoding: "utf8",
140
+ });
141
+ if (probe.status !== 0) {
142
+ return undefined;
143
+ }
144
+
145
+ const executable = probe.stdout.trim();
146
+ if (!executable || !existsSync(executable)) {
147
+ return undefined;
148
+ }
149
+
150
+ return executable;
151
+}
152
+
153
interface ResolvedBuildOptions {
154
readonly platform: typeof BuildPlatform.Type;
155
readonly target: string;
307
return Effect.gen(function* () {
308
const fs = yield* FileSystem.FileSystem;
309
const path = yield* Path.Path;
264
- const iconSource = yield* IconSource;
310
+ const iconSource = yield* ProductionMacIconSource;
311
if (!(yield* fs.exists(iconSource))) {
312
return yield* new BuildScriptError({
313
message: `Production icon source is missing at ${iconSource}`,
331
});
332
}
333
334
+function stageLinuxIcons(stageResourcesDir: string) {
335
+ return Effect.gen(function* () {
336
+ const fs = yield* FileSystem.FileSystem;
337
+ const path = yield* Path.Path;
338
+ const iconSource = yield* ProductionLinuxIconSource;
339
+ if (!(yield* fs.exists(iconSource))) {
340
+ return yield* new BuildScriptError({
341
+ message: `Production icon source is missing at ${iconSource}`,
342
+ });
343
+ }
344
+
345
+ const iconPath = path.join(stageResourcesDir, "icon.png");
346
+ yield* fs.copyFile(iconSource, iconPath);
347
+ });
348
+}
349
+
350
+function stageWindowsIcons(stageResourcesDir: string) {
351
+ return Effect.gen(function* () {
352
+ const fs = yield* FileSystem.FileSystem;
353
+ const path = yield* Path.Path;
354
+ const iconSource = yield* ProductionWindowsIconSource;
355
+ if (!(yield* fs.exists(iconSource))) {
356
+ return yield* new BuildScriptError({
357
+ message: `Production Windows icon source is missing at ${iconSource}`,
358
+ });
359
+ }
360
+
361
+ const iconPath = path.join(stageResourcesDir, "icon.ico");
362
+ yield* fs.copyFile(iconSource, iconPath);
363
+ });
364
+}
365
+
366
function validateBundledClientAssets(clientDir: string) {
367
return Effect.gen(function* () {
368
const fs = yield* FileSystem.FileSystem;
494
stageResourcesDir: string,
495
verbose: boolean,
496
) {
419
- const fs = yield* FileSystem.FileSystem;
420
- const path = yield* Path.Path;
421
-
497
if (platform === "mac") {
498
yield* stageMacIcons(stageResourcesDir, verbose);
499
return;
500
}
501
502
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
- }
503
+ yield* stageLinuxIcons(stageResourcesDir);
504
return;
505
}
506
507
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
- }
508
+ yield* stageWindowsIcons(stageResourcesDir);
509
}
510
});
511
662
delete buildEnv.APPLE_API_ISSUER;
663
}
664
665
+ if (process.platform === "win32") {
666
+ const python = resolvePythonForNodeGyp();
667
+ if (python) {
668
+ buildEnv.PYTHON = python;
669
+ buildEnv.npm_config_python = python;
670
+ }
671
+ buildEnv.npm_config_msvs_version = buildEnv.npm_config_msvs_version ?? "2022";
672
+ buildEnv.GYP_MSVS_VERSION = buildEnv.GYP_MSVS_VERSION ?? "2022";
673
+ }
674
+
675
yield* Effect.log(
676
`[desktop-artifact] Building ${options.platform}/${options.target} (arch=${options.arch}, version=${appVersion})...`,
677
);