@air-jam/devtools 0.0.0-stage → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +112 -2
- package/dist/chunk-2O67AXCU.js +470 -0
- package/dist/chunk-2O67AXCU.js.map +1 -0
- package/dist/chunk-AO3ZDXF6.js +142 -0
- package/dist/chunk-AO3ZDXF6.js.map +1 -0
- package/dist/chunk-ART5TEYT.js +472 -0
- package/dist/chunk-ART5TEYT.js.map +1 -0
- package/dist/chunk-ASC2CK2R.js +77 -0
- package/dist/chunk-ASC2CK2R.js.map +1 -0
- package/dist/chunk-E3UZZGAV.js +50 -0
- package/dist/chunk-E3UZZGAV.js.map +1 -0
- package/dist/chunk-EJTE7UKX.js +64 -0
- package/dist/chunk-EJTE7UKX.js.map +1 -0
- package/dist/chunk-ESFKNN75.js +110 -0
- package/dist/chunk-ESFKNN75.js.map +1 -0
- package/dist/chunk-EU7A6PXW.js +1339 -0
- package/dist/chunk-EU7A6PXW.js.map +1 -0
- package/dist/chunk-FN7E6EA7.js +549 -0
- package/dist/chunk-FN7E6EA7.js.map +1 -0
- package/dist/chunk-GDFAWHGA.js +190 -0
- package/dist/chunk-GDFAWHGA.js.map +1 -0
- package/dist/chunk-HZUGBH4Y.js +347 -0
- package/dist/chunk-HZUGBH4Y.js.map +1 -0
- package/dist/chunk-ITKAOEGX.js +93 -0
- package/dist/chunk-ITKAOEGX.js.map +1 -0
- package/dist/chunk-JBCUTWRI.js +897 -0
- package/dist/chunk-JBCUTWRI.js.map +1 -0
- package/dist/chunk-JSI5S4WP.js +1174 -0
- package/dist/chunk-JSI5S4WP.js.map +1 -0
- package/dist/chunk-L4D675BG.js +97 -0
- package/dist/chunk-L4D675BG.js.map +1 -0
- package/dist/chunk-M6CJ7GQC.js +133 -0
- package/dist/chunk-M6CJ7GQC.js.map +1 -0
- package/dist/chunk-MEIMOSZC.js +749 -0
- package/dist/chunk-MEIMOSZC.js.map +1 -0
- package/dist/chunk-O3XG3FNL.js +1014 -0
- package/dist/chunk-O3XG3FNL.js.map +1 -0
- package/dist/chunk-OM6SCJ7H.js +18 -0
- package/dist/chunk-OM6SCJ7H.js.map +1 -0
- package/dist/chunk-PKD4WVX5.js +63 -0
- package/dist/chunk-PKD4WVX5.js.map +1 -0
- package/dist/chunk-PMBLXGFM.js +3384 -0
- package/dist/chunk-PMBLXGFM.js.map +1 -0
- package/dist/chunk-PMNE5GIN.js +279 -0
- package/dist/chunk-PMNE5GIN.js.map +1 -0
- package/dist/chunk-QAWI64VR.js +148 -0
- package/dist/chunk-QAWI64VR.js.map +1 -0
- package/dist/chunk-QGADSPHZ.js +449 -0
- package/dist/chunk-QGADSPHZ.js.map +1 -0
- package/dist/chunk-SPYN66UV.js +338 -0
- package/dist/chunk-SPYN66UV.js.map +1 -0
- package/dist/context.d.ts +19 -0
- package/dist/context.js +10 -0
- package/dist/context.js.map +1 -0
- package/dist/controller.d.ts +67 -0
- package/dist/controller.js +40 -0
- package/dist/controller.js.map +1 -0
- package/dist/dependencies.d.ts +44 -0
- package/dist/dependencies.js +10 -0
- package/dist/dependencies.js.map +1 -0
- package/dist/dev.d.ts +21 -0
- package/dist/dev.js +19 -0
- package/dist/dev.js.map +1 -0
- package/dist/game-builds.d.ts +200 -0
- package/dist/game-builds.js +16 -0
- package/dist/game-builds.js.map +1 -0
- package/dist/game-run-watch-CEd_SpAT.d.ts +84 -0
- package/dist/game-runs.d.ts +1452 -0
- package/dist/game-runs.js +76 -0
- package/dist/game-runs.js.map +1 -0
- package/dist/game-session-broker-CUvORfMd.d.ts +439 -0
- package/dist/game-session-broker.d.ts +4 -0
- package/dist/game-session-broker.js +40 -0
- package/dist/game-session-broker.js.map +1 -0
- package/dist/game-session.d.ts +3934 -0
- package/dist/game-session.js +195 -0
- package/dist/game-session.js.map +1 -0
- package/dist/game-settings.d.ts +16 -0
- package/dist/game-settings.js +237 -0
- package/dist/game-settings.js.map +1 -0
- package/dist/games.d.ts +28 -0
- package/dist/games.js +16 -0
- package/dist/games.js.map +1 -0
- package/dist/harness/visual.d.ts +204 -0
- package/dist/harness/visual.js +46 -0
- package/dist/harness/visual.js.map +1 -0
- package/dist/logs.d.ts +15 -0
- package/dist/logs.js +57 -0
- package/dist/logs.js.map +1 -0
- package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
- package/dist/mcp-config.d.ts +63 -0
- package/dist/mcp-config.js +191 -0
- package/dist/mcp-config.js.map +1 -0
- package/dist/platform-auth.d.ts +9 -0
- package/dist/platform-auth.js +45 -0
- package/dist/platform-auth.js.map +1 -0
- package/dist/platform-game-analytics.d.ts +51 -0
- package/dist/platform-game-analytics.js +49 -0
- package/dist/platform-game-analytics.js.map +1 -0
- package/dist/platform-game-app-id.d.ts +46 -0
- package/dist/platform-game-app-id.js +93 -0
- package/dist/platform-game-app-id.js.map +1 -0
- package/dist/platform-game-media.d.ts +347 -0
- package/dist/platform-game-media.js +168 -0
- package/dist/platform-game-media.js.map +1 -0
- package/dist/platform-games.d.ts +87 -0
- package/dist/platform-games.js +183 -0
- package/dist/platform-games.js.map +1 -0
- package/dist/quality.d.ts +16 -0
- package/dist/quality.js +62 -0
- package/dist/quality.js.map +1 -0
- package/dist/release.d.ts +1304 -0
- package/dist/release.js +34 -0
- package/dist/release.js.map +1 -0
- package/dist/rooms-check.d.ts +90 -0
- package/dist/rooms-check.js +717 -0
- package/dist/rooms-check.js.map +1 -0
- package/dist/source-tree-contract.d.ts +16 -0
- package/dist/source-tree-contract.js +13 -0
- package/dist/source-tree-contract.js.map +1 -0
- package/dist/testing.d.ts +464 -0
- package/dist/testing.js +27 -0
- package/dist/testing.js.map +1 -0
- package/dist/tooling/describe-game.d.ts +2 -0
- package/dist/tooling/describe-game.js +54 -0
- package/dist/tooling/describe-game.js.map +1 -0
- package/dist/tooling/game-session-broker.d.ts +2 -0
- package/dist/tooling/game-session-broker.js +28 -0
- package/dist/tooling/game-session-broker.js.map +1 -0
- package/dist/tooling/hold-runtime-host.d.ts +2 -0
- package/dist/tooling/hold-runtime-host.js +931 -0
- package/dist/tooling/hold-runtime-host.js.map +1 -0
- package/dist/tooling/list-visual-scenarios.d.ts +2 -0
- package/dist/tooling/list-visual-scenarios.js +25 -0
- package/dist/tooling/list-visual-scenarios.js.map +1 -0
- package/dist/tooling/managed-dev-supervisor.d.ts +2 -0
- package/dist/tooling/managed-dev-supervisor.js +51 -0
- package/dist/tooling/managed-dev-supervisor.js.map +1 -0
- package/dist/tooling/process-scope-bootstrap.mjs +24 -0
- package/dist/tooling/process-scope-guard.d.ts +2 -0
- package/dist/tooling/process-scope-guard.js +388 -0
- package/dist/tooling/process-scope-guard.js.map +1 -0
- package/dist/tooling/process-scope-windows.ps1 +148 -0
- package/dist/tooling/rooms-check-device.d.ts +2 -0
- package/dist/tooling/rooms-check-device.js +498 -0
- package/dist/tooling/rooms-check-device.js.map +1 -0
- package/dist/tooling/run-headless-room.d.ts +2 -0
- package/dist/tooling/run-headless-room.js +287 -0
- package/dist/tooling/run-headless-room.js.map +1 -0
- package/dist/tooling/run-test-profile.d.ts +2 -0
- package/dist/tooling/run-test-profile.js +181 -0
- package/dist/tooling/run-test-profile.js.map +1 -0
- package/dist/tooling/run-visual-capture.d.ts +2 -0
- package/dist/tooling/run-visual-capture.js +203 -0
- package/dist/tooling/run-visual-capture.js.map +1 -0
- package/dist/tooling/seal-game-build.d.ts +2 -0
- package/dist/tooling/seal-game-build.js +120 -0
- package/dist/tooling/seal-game-build.js.map +1 -0
- package/dist/types-CdYrgrG_.d.ts +1036 -0
- package/dist/types-DyRD-ym1.d.ts +141 -0
- package/dist/visual.d.ts +21 -0
- package/dist/visual.js +219 -0
- package/dist/visual.js.map +1 -0
- package/package.json +150 -3
- package/src/bounded-response.ts +28 -0
- package/src/built-game-runtime.ts +152 -0
- package/src/commands.ts +40 -0
- package/src/context.ts +218 -0
- package/src/controller-protocol.ts +22 -0
- package/src/controller.ts +1526 -0
- package/src/current-room-host.ts +166 -0
- package/src/decision-provider.ts +102 -0
- package/src/dependencies.ts +176 -0
- package/src/dependency-install-contract.ts +12 -0
- package/src/dev.ts +995 -0
- package/src/fs-utils.ts +93 -0
- package/src/game-action-observation.ts +106 -0
- package/src/game-build-protocol.ts +72 -0
- package/src/game-build.ts +483 -0
- package/src/game-run-owner.ts +2358 -0
- package/src/game-run-protocol.ts +448 -0
- package/src/game-run-record.ts +92 -0
- package/src/game-run-replay.ts +95 -0
- package/src/game-run-watch.ts +155 -0
- package/src/game-session-broker.ts +793 -0
- package/src/game-session-operations.ts +61 -0
- package/src/game-session-protocol.ts +180 -0
- package/src/game-session-runtime.ts +861 -0
- package/src/game-session.ts +206 -0
- package/src/game-settings.ts +295 -0
- package/src/games.ts +262 -0
- package/src/harness/visual/browser.ts +100 -0
- package/src/harness/visual/controller-observation.ts +181 -0
- package/src/harness/visual/prefab-contract.ts +29 -0
- package/src/harness/visual/prefab-runner.ts +178 -0
- package/src/harness/visual/runner.ts +549 -0
- package/src/harness/visual/runtime-controller-observations.ts +151 -0
- package/src/harness/visual/scenario-contract.ts +8 -0
- package/src/harness/visual/scenario-helpers.ts +67 -0
- package/src/harness/visual/screencast.ts +155 -0
- package/src/harness/visual/session.ts +400 -0
- package/src/harness/visual/types.ts +184 -0
- package/src/harness/visual.ts +7 -0
- package/src/headless-room-protocol.ts +112 -0
- package/src/headless-room.ts +222 -0
- package/src/helper-channel.ts +229 -0
- package/src/helper-scripts.ts +69 -0
- package/src/installed-dependencies.ts +74 -0
- package/src/logs.ts +67 -0
- package/src/managed-process-scope.ts +481 -0
- package/src/mcp-config.ts +262 -0
- package/src/node-process-environment.ts +10 -0
- package/src/platform-auth.ts +594 -0
- package/src/platform-game-analytics.ts +50 -0
- package/src/platform-game-app-id.ts +99 -0
- package/src/platform-game-media.ts +209 -0
- package/src/platform-games.ts +217 -0
- package/src/policy-artifact-contract.ts +52 -0
- package/src/policy-artifacts.ts +134 -0
- package/src/process-scope-admission.ts +50 -0
- package/src/process-scope-protocol.ts +66 -0
- package/src/process-scope.ts +327 -0
- package/src/quality.ts +82 -0
- package/src/release.ts +1683 -0
- package/src/rooms-check-fleet.ts +194 -0
- package/src/rooms-check-link.ts +138 -0
- package/src/rooms-check-protocol.ts +244 -0
- package/src/rooms-check.ts +797 -0
- package/src/runtime-owner-protocol.ts +218 -0
- package/src/source-tree-contract.ts +70 -0
- package/src/source-tree.ts +84 -0
- package/src/test-profile-process.ts +153 -0
- package/src/test-profile-protocol.ts +116 -0
- package/src/testing.ts +430 -0
- package/src/tooling/declaration-hook.ts +52 -0
- package/src/tooling/describe-game.ts +49 -0
- package/src/tooling/game-session-broker.ts +7 -0
- package/src/tooling/hold-runtime-host.ts +441 -0
- package/src/tooling/list-visual-scenarios.ts +21 -0
- package/src/tooling/load-game.ts +79 -0
- package/src/tooling/managed-dev-supervisor.ts +71 -0
- package/src/tooling/process-scope-bootstrap.mjs +24 -0
- package/src/tooling/process-scope-guard.ts +213 -0
- package/src/tooling/process-scope-windows.ps1 +148 -0
- package/src/tooling/rooms-check-device.ts +493 -0
- package/src/tooling/run-headless-room.ts +326 -0
- package/src/tooling/run-test-profile.ts +190 -0
- package/src/tooling/run-visual-capture.ts +231 -0
- package/src/tooling/runtime-owner-actions.ts +65 -0
- package/src/tooling/seal-game-build.ts +118 -0
- package/src/tooling/visual-pack.ts +11 -0
- package/src/types.ts +928 -0
- package/src/visual.ts +296 -0
- package/src/windows-process-scopes.ts +189 -0
- package/src/workspace-contract.ts +32 -0
package/src/release.ts
ADDED
|
@@ -0,0 +1,1683 @@
|
|
|
1
|
+
import {
|
|
2
|
+
platformMachineArchiveReleaseResultSchema,
|
|
3
|
+
platformMachineCreateReleaseDraftResultSchema,
|
|
4
|
+
platformMachineFinalizeReleaseUploadResultSchema,
|
|
5
|
+
platformMachineGetReleaseResultSchema,
|
|
6
|
+
platformMachineListOwnedGamesResultSchema,
|
|
7
|
+
platformMachineListReleasesResultSchema,
|
|
8
|
+
platformMachinePublishReleaseResultSchema,
|
|
9
|
+
platformMachineRequestReleaseGenerationExportResultSchema,
|
|
10
|
+
platformMachineRequestReleaseUploadTargetResultSchema,
|
|
11
|
+
} from "@air-jam/sdk/platform-machine";
|
|
12
|
+
import {
|
|
13
|
+
HOSTED_RELEASE_CONTROLLER_PATH,
|
|
14
|
+
HOSTED_RELEASE_ENTRY_PATH,
|
|
15
|
+
HOSTED_RELEASE_HOST_PATH,
|
|
16
|
+
HOSTED_RELEASE_MANIFEST_PATH,
|
|
17
|
+
createHostedReleaseArtifactManifest,
|
|
18
|
+
hostedReleaseArtifactManifestSchema,
|
|
19
|
+
type HostedReleaseArtifactManifest,
|
|
20
|
+
} from "@air-jam/sdk/release";
|
|
21
|
+
import { createHash } from "node:crypto";
|
|
22
|
+
import { createWriteStream } from "node:fs";
|
|
23
|
+
import {
|
|
24
|
+
copyFile,
|
|
25
|
+
mkdir,
|
|
26
|
+
mkdtemp,
|
|
27
|
+
open,
|
|
28
|
+
readFile,
|
|
29
|
+
readdir,
|
|
30
|
+
rm,
|
|
31
|
+
stat,
|
|
32
|
+
writeFile,
|
|
33
|
+
} from "node:fs/promises";
|
|
34
|
+
import os from "node:os";
|
|
35
|
+
import path from "node:path";
|
|
36
|
+
import * as yauzl from "yauzl";
|
|
37
|
+
import yazl from "yazl";
|
|
38
|
+
import { runCommandResult } from "./commands.js";
|
|
39
|
+
import { detectProjectContext } from "./context.js";
|
|
40
|
+
import {
|
|
41
|
+
pathExists,
|
|
42
|
+
readPackageJson,
|
|
43
|
+
resolveCanonicalPath,
|
|
44
|
+
} from "./fs-utils.js";
|
|
45
|
+
import { AIRJAM_CONFIG_PATH, inspectGame } from "./games.js";
|
|
46
|
+
import {
|
|
47
|
+
requestPlatformMachineApi,
|
|
48
|
+
resolvePlatformMachineAuth,
|
|
49
|
+
} from "./platform-auth.js";
|
|
50
|
+
import type {
|
|
51
|
+
AirJamLocalReleaseDoctor,
|
|
52
|
+
AirJamLocalReleaseIssue,
|
|
53
|
+
AirJamLocalReleaseValidation,
|
|
54
|
+
AirJamPackageManager,
|
|
55
|
+
ArchivePlatformReleaseOptions,
|
|
56
|
+
BundleLocalReleaseOptions,
|
|
57
|
+
BundleLocalReleaseResult,
|
|
58
|
+
CommandResult,
|
|
59
|
+
ExportPlatformReleaseGenerationOptions,
|
|
60
|
+
ExportPlatformReleaseGenerationResult,
|
|
61
|
+
FinalizePlatformReleaseGenerationOptions,
|
|
62
|
+
InspectLocalReleaseOptions,
|
|
63
|
+
InspectPlatformReleaseOptions,
|
|
64
|
+
ListPlatformReleaseTargetsOptions,
|
|
65
|
+
ListPlatformReleasesOptions,
|
|
66
|
+
PublishPlatformReleaseOptions,
|
|
67
|
+
SubmitPlatformReleaseOptions,
|
|
68
|
+
SubmitPlatformReleaseResult,
|
|
69
|
+
UploadPlatformReleaseGenerationOptions,
|
|
70
|
+
ValidateLocalReleaseOptions,
|
|
71
|
+
} from "./types.js";
|
|
72
|
+
|
|
73
|
+
export type {
|
|
74
|
+
AirJamLocalReleaseDoctor,
|
|
75
|
+
AirJamLocalReleaseIssue,
|
|
76
|
+
AirJamLocalReleaseValidation,
|
|
77
|
+
ArchivePlatformReleaseOptions,
|
|
78
|
+
BundleLocalReleaseOptions,
|
|
79
|
+
BundleLocalReleaseResult,
|
|
80
|
+
ExportPlatformReleaseGenerationOptions,
|
|
81
|
+
ExportPlatformReleaseGenerationResult,
|
|
82
|
+
FinalizePlatformReleaseGenerationOptions,
|
|
83
|
+
InspectLocalReleaseOptions,
|
|
84
|
+
InspectPlatformReleaseOptions,
|
|
85
|
+
ListPlatformReleaseTargetsOptions,
|
|
86
|
+
ListPlatformReleasesOptions,
|
|
87
|
+
PublishPlatformReleaseOptions,
|
|
88
|
+
SubmitPlatformReleaseOptions,
|
|
89
|
+
SubmitPlatformReleaseResult,
|
|
90
|
+
UploadPlatformReleaseGenerationOptions,
|
|
91
|
+
ValidateLocalReleaseOptions,
|
|
92
|
+
} from "./types.js";
|
|
93
|
+
|
|
94
|
+
const IGNORED_ARCHIVE_PATHS = ["__MACOSX/", ".DS_Store"] as const;
|
|
95
|
+
const VENDORED_FONT_ASSET_DIR = "assets/airjam-vendored/fonts";
|
|
96
|
+
const REMOTE_FONT_STYLESHEET_HOSTS = new Set(["fonts.googleapis.com"]);
|
|
97
|
+
const REMOTE_FONT_ASSET_HOSTS = new Set(["fonts.gstatic.com"]);
|
|
98
|
+
const REMOTE_CSS_IMPORT_PATTERN =
|
|
99
|
+
/@import\s*(?:url\(\s*)?(?<quote>["']?)(?<url>https?:\/\/[^"')\s]+)\k<quote>\s*\)?\s*;/g;
|
|
100
|
+
const REMOTE_CSS_URL_PATTERN =
|
|
101
|
+
/url\(\s*(?<quote>["']?)(?<url>https?:\/\/[^"')\s]+)\k<quote>\s*\)/g;
|
|
102
|
+
const FONT_ASSET_EXTENSION_PATTERN = /\.(woff2?|ttf|otf|eot)(?:[?#].*)?$/i;
|
|
103
|
+
const CSS_EXTENSION_PATTERN = /\.css(?:[?#].*)?$/i;
|
|
104
|
+
const FONT_FETCH_USER_AGENT =
|
|
105
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36";
|
|
106
|
+
const DEFAULT_RELEASE_PROCESSING_TIMEOUT_MS = 10 * 60 * 1000;
|
|
107
|
+
const RELEASE_PROCESSING_POLL_INTERVAL_MS = 2_000;
|
|
108
|
+
|
|
109
|
+
const wait = async (durationMs: number) =>
|
|
110
|
+
new Promise((resolve) => setTimeout(resolve, durationMs));
|
|
111
|
+
|
|
112
|
+
const sanitizePathSegment = (value: string): string =>
|
|
113
|
+
value.trim().replace(/[^a-zA-Z0-9._-]+/g, "-");
|
|
114
|
+
|
|
115
|
+
const parsePackageManagerField = (
|
|
116
|
+
value: string | undefined,
|
|
117
|
+
): AirJamPackageManager => {
|
|
118
|
+
const normalized = value?.trim().toLowerCase() ?? "";
|
|
119
|
+
if (normalized.startsWith("pnpm@")) {
|
|
120
|
+
return "pnpm";
|
|
121
|
+
}
|
|
122
|
+
if (normalized.startsWith("npm@")) {
|
|
123
|
+
return "npm";
|
|
124
|
+
}
|
|
125
|
+
if (normalized.startsWith("yarn@")) {
|
|
126
|
+
return "yarn";
|
|
127
|
+
}
|
|
128
|
+
if (normalized.startsWith("bun@")) {
|
|
129
|
+
return "bun";
|
|
130
|
+
}
|
|
131
|
+
return "unknown";
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const resolvePackageManager = async (
|
|
135
|
+
targetDir: string,
|
|
136
|
+
): Promise<AirJamPackageManager> => {
|
|
137
|
+
const packageJson = await readPackageJson(targetDir);
|
|
138
|
+
const packageManagerFromField = parsePackageManagerField(
|
|
139
|
+
packageJson?.value.packageManager,
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
if (packageManagerFromField !== "unknown") {
|
|
143
|
+
return packageManagerFromField;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const context = await detectProjectContext({ cwd: targetDir });
|
|
147
|
+
return context.packageManager;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const getDefaultReleaseBundlePath = ({
|
|
151
|
+
projectDir,
|
|
152
|
+
packageName,
|
|
153
|
+
packageVersion,
|
|
154
|
+
}: {
|
|
155
|
+
projectDir: string;
|
|
156
|
+
packageName?: string | null;
|
|
157
|
+
packageVersion?: string | null;
|
|
158
|
+
}): string => {
|
|
159
|
+
const normalizedReleaseLabel = sanitizePathSegment(packageVersion || "dev");
|
|
160
|
+
const normalizedPackageName = sanitizePathSegment(
|
|
161
|
+
packageName || "airjam-game",
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
return path.join(
|
|
165
|
+
projectDir,
|
|
166
|
+
".airjam",
|
|
167
|
+
"releases",
|
|
168
|
+
normalizedReleaseLabel,
|
|
169
|
+
`${normalizedPackageName}-hosted-release.zip`,
|
|
170
|
+
);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const getLocalAirJamConfigPath = async (
|
|
174
|
+
projectDir: string,
|
|
175
|
+
): Promise<string | null> => {
|
|
176
|
+
const configPath = path.join(projectDir, AIRJAM_CONFIG_PATH);
|
|
177
|
+
return (await pathExists(configPath)) ? configPath : null;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const collectDirectoryFiles = async (sourceDir: string): Promise<string[]> => {
|
|
181
|
+
const entries = await readdir(sourceDir);
|
|
182
|
+
const files: string[] = [];
|
|
183
|
+
|
|
184
|
+
for (const entry of entries) {
|
|
185
|
+
const absolutePath = path.join(sourceDir, entry);
|
|
186
|
+
const entryStats = await stat(absolutePath);
|
|
187
|
+
|
|
188
|
+
if (entryStats.isDirectory()) {
|
|
189
|
+
files.push(...(await collectDirectoryFiles(absolutePath)));
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
files.push(absolutePath);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return files;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const hashContent = (value: string): string =>
|
|
200
|
+
createHash("sha256").update(value).digest("hex").slice(0, 16);
|
|
201
|
+
|
|
202
|
+
const ensurePosixRelativePath = (fromDir: string, toPath: string): string =>
|
|
203
|
+
path.relative(fromDir, toPath).replace(/\\/g, "/");
|
|
204
|
+
|
|
205
|
+
const ensureExplicitRelativeUrl = (value: string): string => {
|
|
206
|
+
if (!value || value.startsWith("./") || value.startsWith("../")) {
|
|
207
|
+
return value;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return `./${value}`;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const isRemoteFontStylesheetUrl = (value: string): boolean => {
|
|
214
|
+
try {
|
|
215
|
+
const url = new URL(value);
|
|
216
|
+
return (
|
|
217
|
+
REMOTE_FONT_STYLESHEET_HOSTS.has(url.hostname) ||
|
|
218
|
+
CSS_EXTENSION_PATTERN.test(url.pathname)
|
|
219
|
+
);
|
|
220
|
+
} catch {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const isRemoteFontAssetUrl = (value: string): boolean => {
|
|
226
|
+
try {
|
|
227
|
+
const url = new URL(value);
|
|
228
|
+
return (
|
|
229
|
+
REMOTE_FONT_ASSET_HOSTS.has(url.hostname) ||
|
|
230
|
+
FONT_ASSET_EXTENSION_PATTERN.test(url.pathname)
|
|
231
|
+
);
|
|
232
|
+
} catch {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const inferFileExtensionFromContentType = (
|
|
238
|
+
contentType: string | null,
|
|
239
|
+
): string | null => {
|
|
240
|
+
if (!contentType) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const normalized = contentType.toLowerCase();
|
|
245
|
+
if (normalized.includes("text/css")) {
|
|
246
|
+
return ".css";
|
|
247
|
+
}
|
|
248
|
+
if (normalized.includes("font/woff2")) {
|
|
249
|
+
return ".woff2";
|
|
250
|
+
}
|
|
251
|
+
if (normalized.includes("font/woff")) {
|
|
252
|
+
return ".woff";
|
|
253
|
+
}
|
|
254
|
+
if (normalized.includes("font/ttf")) {
|
|
255
|
+
return ".ttf";
|
|
256
|
+
}
|
|
257
|
+
if (normalized.includes("font/otf")) {
|
|
258
|
+
return ".otf";
|
|
259
|
+
}
|
|
260
|
+
if (normalized.includes("application/vnd.ms-fontobject")) {
|
|
261
|
+
return ".eot";
|
|
262
|
+
}
|
|
263
|
+
if (normalized.includes("application/octet-stream")) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return null;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const inferFileExtensionFromUrl = (value: string): string | null => {
|
|
271
|
+
try {
|
|
272
|
+
const { pathname } = new URL(value);
|
|
273
|
+
const matched = pathname.match(/\.(woff2?|ttf|otf|eot|css)$/i);
|
|
274
|
+
return matched ? matched[0]!.toLowerCase() : null;
|
|
275
|
+
} catch {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const fetchRemoteAsset = async (value: string) => {
|
|
281
|
+
const response = await fetch(value, {
|
|
282
|
+
headers: {
|
|
283
|
+
"user-agent": FONT_FETCH_USER_AGENT,
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
if (!response.ok) {
|
|
288
|
+
throw new Error(
|
|
289
|
+
`Failed to fetch remote font asset ${value} (${response.status}).`,
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
294
|
+
return {
|
|
295
|
+
buffer,
|
|
296
|
+
contentType: response.headers.get("content-type"),
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
type VendoredFontState = {
|
|
301
|
+
cssByUrl: Map<string, string>;
|
|
302
|
+
assetByUrl: Map<string, string>;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
const rewriteCssAsync = async ({
|
|
306
|
+
css,
|
|
307
|
+
replacePattern,
|
|
308
|
+
replacer,
|
|
309
|
+
}: {
|
|
310
|
+
css: string;
|
|
311
|
+
replacePattern: RegExp;
|
|
312
|
+
replacer: (match: RegExpExecArray) => Promise<string>;
|
|
313
|
+
}): Promise<string> => {
|
|
314
|
+
const pieces: string[] = [];
|
|
315
|
+
let lastIndex = 0;
|
|
316
|
+
let match: RegExpExecArray | null;
|
|
317
|
+
const pattern = new RegExp(replacePattern.source, replacePattern.flags);
|
|
318
|
+
|
|
319
|
+
while ((match = pattern.exec(css)) !== null) {
|
|
320
|
+
const matchedText = match[0];
|
|
321
|
+
const index = match.index;
|
|
322
|
+
pieces.push(css.slice(lastIndex, index));
|
|
323
|
+
pieces.push(await replacer(match));
|
|
324
|
+
lastIndex = index + matchedText.length;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
pieces.push(css.slice(lastIndex));
|
|
328
|
+
return pieces.join("");
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const vendorRemoteFontAsset = async ({
|
|
332
|
+
assetUrl,
|
|
333
|
+
bundleRoot,
|
|
334
|
+
state,
|
|
335
|
+
}: {
|
|
336
|
+
assetUrl: string;
|
|
337
|
+
bundleRoot: string;
|
|
338
|
+
state: VendoredFontState;
|
|
339
|
+
}): Promise<string> => {
|
|
340
|
+
const cached = state.assetByUrl.get(assetUrl);
|
|
341
|
+
if (cached) {
|
|
342
|
+
return cached;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const { buffer, contentType } = await fetchRemoteAsset(assetUrl);
|
|
346
|
+
const extension =
|
|
347
|
+
inferFileExtensionFromContentType(contentType) ||
|
|
348
|
+
inferFileExtensionFromUrl(assetUrl) ||
|
|
349
|
+
".bin";
|
|
350
|
+
const fileName = `${hashContent(assetUrl)}${extension}`;
|
|
351
|
+
const relativePath = path.posix.join(VENDORED_FONT_ASSET_DIR, fileName);
|
|
352
|
+
const absolutePath = path.join(bundleRoot, relativePath);
|
|
353
|
+
await mkdir(path.dirname(absolutePath), { recursive: true });
|
|
354
|
+
await writeFile(absolutePath, buffer);
|
|
355
|
+
state.assetByUrl.set(assetUrl, relativePath);
|
|
356
|
+
return relativePath;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const vendorRemoteFontStylesheet = async ({
|
|
360
|
+
stylesheetUrl,
|
|
361
|
+
bundleRoot,
|
|
362
|
+
state,
|
|
363
|
+
}: {
|
|
364
|
+
stylesheetUrl: string;
|
|
365
|
+
bundleRoot: string;
|
|
366
|
+
state: VendoredFontState;
|
|
367
|
+
}): Promise<string> => {
|
|
368
|
+
const cached = state.cssByUrl.get(stylesheetUrl);
|
|
369
|
+
if (cached) {
|
|
370
|
+
return cached;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const { buffer, contentType } = await fetchRemoteAsset(stylesheetUrl);
|
|
374
|
+
if (contentType && !contentType.toLowerCase().includes("text/css")) {
|
|
375
|
+
throw new Error(
|
|
376
|
+
`Expected remote stylesheet ${stylesheetUrl} to return CSS but received ${contentType}.`,
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const stylesheetText = buffer.toString("utf8");
|
|
381
|
+
const rewrittenCss = await rewriteCssAsync({
|
|
382
|
+
css: stylesheetText,
|
|
383
|
+
replacePattern: REMOTE_CSS_URL_PATTERN,
|
|
384
|
+
replacer: async (match) => {
|
|
385
|
+
const remoteUrl = match.groups?.url?.trim();
|
|
386
|
+
if (!remoteUrl) {
|
|
387
|
+
return match[0];
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const absoluteUrl = new URL(remoteUrl, stylesheetUrl).toString();
|
|
391
|
+
const assetPath = await vendorRemoteFontAsset({
|
|
392
|
+
assetUrl: absoluteUrl,
|
|
393
|
+
bundleRoot,
|
|
394
|
+
state,
|
|
395
|
+
});
|
|
396
|
+
return `url("./${path.posix.basename(assetPath)}")`;
|
|
397
|
+
},
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
const relativePath = path.posix.join(
|
|
401
|
+
VENDORED_FONT_ASSET_DIR,
|
|
402
|
+
`${hashContent(stylesheetUrl)}.css`,
|
|
403
|
+
);
|
|
404
|
+
const absolutePath = path.join(bundleRoot, relativePath);
|
|
405
|
+
await mkdir(path.dirname(absolutePath), { recursive: true });
|
|
406
|
+
await writeFile(absolutePath, rewrittenCss, "utf8");
|
|
407
|
+
state.cssByUrl.set(stylesheetUrl, relativePath);
|
|
408
|
+
return relativePath;
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const vendorCssFontDependencies = async ({
|
|
412
|
+
bundleRoot,
|
|
413
|
+
}: {
|
|
414
|
+
bundleRoot: string;
|
|
415
|
+
}): Promise<void> => {
|
|
416
|
+
const files = await collectDirectoryFiles(bundleRoot);
|
|
417
|
+
const cssFiles = files.filter((filePath) => filePath.endsWith(".css"));
|
|
418
|
+
const state: VendoredFontState = {
|
|
419
|
+
cssByUrl: new Map(),
|
|
420
|
+
assetByUrl: new Map(),
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
for (const cssFilePath of cssFiles) {
|
|
424
|
+
const originalCss = await readFile(cssFilePath, "utf8");
|
|
425
|
+
const cssDir = path.dirname(cssFilePath);
|
|
426
|
+
|
|
427
|
+
let rewrittenCss = await rewriteCssAsync({
|
|
428
|
+
css: originalCss,
|
|
429
|
+
replacePattern: REMOTE_CSS_IMPORT_PATTERN,
|
|
430
|
+
replacer: async (match) => {
|
|
431
|
+
const remoteUrl = match.groups?.url?.trim();
|
|
432
|
+
if (!remoteUrl || !isRemoteFontStylesheetUrl(remoteUrl)) {
|
|
433
|
+
return match[0];
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const vendoredStylesheet = await vendorRemoteFontStylesheet({
|
|
437
|
+
stylesheetUrl: remoteUrl,
|
|
438
|
+
bundleRoot,
|
|
439
|
+
state,
|
|
440
|
+
});
|
|
441
|
+
const relativeImport = ensureExplicitRelativeUrl(
|
|
442
|
+
ensurePosixRelativePath(
|
|
443
|
+
cssDir,
|
|
444
|
+
path.join(bundleRoot, vendoredStylesheet),
|
|
445
|
+
),
|
|
446
|
+
);
|
|
447
|
+
return `@import url("${relativeImport}");`;
|
|
448
|
+
},
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
rewrittenCss = await rewriteCssAsync({
|
|
452
|
+
css: rewrittenCss,
|
|
453
|
+
replacePattern: REMOTE_CSS_URL_PATTERN,
|
|
454
|
+
replacer: async (match) => {
|
|
455
|
+
const remoteUrl = match.groups?.url?.trim();
|
|
456
|
+
if (!remoteUrl || !isRemoteFontAssetUrl(remoteUrl)) {
|
|
457
|
+
return match[0];
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
const vendoredAsset = await vendorRemoteFontAsset({
|
|
461
|
+
assetUrl: remoteUrl,
|
|
462
|
+
bundleRoot,
|
|
463
|
+
state,
|
|
464
|
+
});
|
|
465
|
+
const relativeAssetPath = ensureExplicitRelativeUrl(
|
|
466
|
+
ensurePosixRelativePath(cssDir, path.join(bundleRoot, vendoredAsset)),
|
|
467
|
+
);
|
|
468
|
+
return `url("${relativeAssetPath}")`;
|
|
469
|
+
},
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
if (rewrittenCss !== originalCss) {
|
|
473
|
+
await writeFile(cssFilePath, rewrittenCss, "utf8");
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
const materializeBundleSourceTree = async ({
|
|
479
|
+
sourceDir,
|
|
480
|
+
}: {
|
|
481
|
+
sourceDir: string;
|
|
482
|
+
}): Promise<string> => {
|
|
483
|
+
const tempRoot = await mkdtemp(
|
|
484
|
+
path.join(os.tmpdir(), "airjam-hosted-release-bundle-"),
|
|
485
|
+
);
|
|
486
|
+
const bundleRoot = path.join(tempRoot, "dist");
|
|
487
|
+
const files = await collectDirectoryFiles(sourceDir);
|
|
488
|
+
|
|
489
|
+
for (const sourcePath of files) {
|
|
490
|
+
const relativePath = path.relative(sourceDir, sourcePath);
|
|
491
|
+
const targetPath = path.join(bundleRoot, relativePath);
|
|
492
|
+
await mkdir(path.dirname(targetPath), { recursive: true });
|
|
493
|
+
await copyFile(sourcePath, targetPath);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
await vendorCssFontDependencies({ bundleRoot });
|
|
497
|
+
return bundleRoot;
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
const isIgnoredArchiveEntry = (archivePath: string): boolean =>
|
|
501
|
+
IGNORED_ARCHIVE_PATHS.some(
|
|
502
|
+
(ignoredPath) =>
|
|
503
|
+
archivePath === ignoredPath ||
|
|
504
|
+
archivePath.startsWith(ignoredPath) ||
|
|
505
|
+
archivePath.endsWith(`/${ignoredPath}`),
|
|
506
|
+
);
|
|
507
|
+
|
|
508
|
+
const hasPathTraversal = (value: string): boolean => {
|
|
509
|
+
const segments = value.split("/");
|
|
510
|
+
return segments.some(
|
|
511
|
+
(segment) => segment.length === 0 || segment === "." || segment === "..",
|
|
512
|
+
);
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
const normalizeArchiveEntryPath = (
|
|
516
|
+
rawPath: string,
|
|
517
|
+
): { archivePath: string; isDirectory: boolean } => {
|
|
518
|
+
const canonicalPath = rawPath.replaceAll("\\", "/").trim();
|
|
519
|
+
if (!canonicalPath || canonicalPath.includes("\0")) {
|
|
520
|
+
throw new Error("Release archive contains an invalid empty entry path.");
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
const isDirectory = canonicalPath.endsWith("/");
|
|
524
|
+
const normalizedPath = path.posix.normalize(
|
|
525
|
+
isDirectory ? canonicalPath.slice(0, -1) : canonicalPath,
|
|
526
|
+
);
|
|
527
|
+
|
|
528
|
+
if (
|
|
529
|
+
!normalizedPath ||
|
|
530
|
+
normalizedPath === "." ||
|
|
531
|
+
path.posix.isAbsolute(normalizedPath) ||
|
|
532
|
+
normalizedPath.startsWith("../") ||
|
|
533
|
+
normalizedPath === ".." ||
|
|
534
|
+
hasPathTraversal(normalizedPath)
|
|
535
|
+
) {
|
|
536
|
+
throw new Error(
|
|
537
|
+
`Release archive entry escapes the allowed root: ${rawPath}`,
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
return {
|
|
542
|
+
archivePath: normalizedPath,
|
|
543
|
+
isDirectory,
|
|
544
|
+
};
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
const getUnixMode = (entry: yauzl.Entry): number | null => {
|
|
548
|
+
const mode = entry.externalFileAttributes >>> 16;
|
|
549
|
+
return mode === 0 ? null : mode;
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
const isZipSymlink = (entry: yauzl.Entry): boolean => {
|
|
553
|
+
const unixMode = getUnixMode(entry);
|
|
554
|
+
if (unixMode === null) {
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return (unixMode & 0o170000) === 0o120000;
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
const buildArgsByPackageManager = {
|
|
562
|
+
npm: ["run", "build"],
|
|
563
|
+
pnpm: ["build"],
|
|
564
|
+
yarn: ["build"],
|
|
565
|
+
bun: ["run", "build"],
|
|
566
|
+
} satisfies Record<Exclude<AirJamPackageManager, "unknown">, readonly string[]>;
|
|
567
|
+
|
|
568
|
+
const resolveBuildCommand = (
|
|
569
|
+
packageManager: AirJamPackageManager,
|
|
570
|
+
): { command: string; args: string[] } | null => {
|
|
571
|
+
return packageManager === "unknown"
|
|
572
|
+
? null
|
|
573
|
+
: {
|
|
574
|
+
command: packageManager,
|
|
575
|
+
args: [...buildArgsByPackageManager[packageManager]],
|
|
576
|
+
};
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
const runBuild = async ({
|
|
580
|
+
projectDir,
|
|
581
|
+
packageManager,
|
|
582
|
+
}: {
|
|
583
|
+
projectDir: string;
|
|
584
|
+
packageManager: AirJamPackageManager;
|
|
585
|
+
}): Promise<CommandResult> => {
|
|
586
|
+
const buildCommand = resolveBuildCommand(packageManager);
|
|
587
|
+
if (!buildCommand) {
|
|
588
|
+
return {
|
|
589
|
+
command: "unknown",
|
|
590
|
+
args: [],
|
|
591
|
+
cwd: projectDir,
|
|
592
|
+
exitCode: null,
|
|
593
|
+
signal: null,
|
|
594
|
+
stdout: "",
|
|
595
|
+
stderr: "Unknown package manager. Cannot run build script.",
|
|
596
|
+
durationMs: 0,
|
|
597
|
+
ok: false,
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
return runCommandResult({
|
|
602
|
+
command: buildCommand.command,
|
|
603
|
+
args: buildCommand.args,
|
|
604
|
+
cwd: projectDir,
|
|
605
|
+
});
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
const createIssue = (
|
|
609
|
+
code: string,
|
|
610
|
+
severity: AirJamLocalReleaseIssue["severity"],
|
|
611
|
+
message: string,
|
|
612
|
+
issuePath: string | null = null,
|
|
613
|
+
): AirJamLocalReleaseIssue => ({
|
|
614
|
+
code,
|
|
615
|
+
severity,
|
|
616
|
+
message,
|
|
617
|
+
path: issuePath,
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
const openZipFile = async (archiveBuffer: Buffer): Promise<yauzl.ZipFile> =>
|
|
621
|
+
new Promise((resolve, reject) => {
|
|
622
|
+
yauzl.fromBuffer(
|
|
623
|
+
archiveBuffer,
|
|
624
|
+
{
|
|
625
|
+
lazyEntries: true,
|
|
626
|
+
validateEntrySizes: true,
|
|
627
|
+
strictFileNames: false,
|
|
628
|
+
},
|
|
629
|
+
(error, zipFile) => {
|
|
630
|
+
if (error) {
|
|
631
|
+
reject(error);
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
if (!zipFile) {
|
|
636
|
+
reject(new Error("Could not open release archive."));
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
resolve(zipFile);
|
|
641
|
+
},
|
|
642
|
+
);
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
const openZipEntryReadStream = async (
|
|
646
|
+
zipFile: yauzl.ZipFile,
|
|
647
|
+
entry: yauzl.Entry,
|
|
648
|
+
): Promise<NodeJS.ReadableStream> =>
|
|
649
|
+
new Promise((resolve, reject) => {
|
|
650
|
+
zipFile.openReadStream(entry, (error, stream) => {
|
|
651
|
+
if (error) {
|
|
652
|
+
reject(error);
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (!stream) {
|
|
657
|
+
reject(new Error(`Could not open zip entry stream: ${entry.fileName}`));
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
resolve(stream);
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
const readStreamBuffer = async (
|
|
666
|
+
stream: NodeJS.ReadableStream,
|
|
667
|
+
): Promise<Buffer> =>
|
|
668
|
+
new Promise((resolve, reject) => {
|
|
669
|
+
const chunks: Buffer[] = [];
|
|
670
|
+
|
|
671
|
+
stream.on("data", (chunk) => {
|
|
672
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
673
|
+
});
|
|
674
|
+
stream.on("end", () => resolve(Buffer.concat(chunks)));
|
|
675
|
+
stream.on("error", reject);
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
const resolveArchiveRoot = (
|
|
679
|
+
archivePaths: readonly string[],
|
|
680
|
+
): {
|
|
681
|
+
entryPath: typeof HOSTED_RELEASE_ENTRY_PATH;
|
|
682
|
+
wrapperDirectory: string | null;
|
|
683
|
+
} => {
|
|
684
|
+
if (archivePaths.includes(HOSTED_RELEASE_ENTRY_PATH)) {
|
|
685
|
+
return {
|
|
686
|
+
entryPath: HOSTED_RELEASE_ENTRY_PATH,
|
|
687
|
+
wrapperDirectory: null,
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
const topLevelSegments = new Set(
|
|
692
|
+
archivePaths.map((archivePath) => archivePath.split("/")[0]),
|
|
693
|
+
);
|
|
694
|
+
|
|
695
|
+
if (topLevelSegments.size !== 1) {
|
|
696
|
+
throw new Error(
|
|
697
|
+
"Release archive must contain a root index.html or a single top-level wrapper directory.",
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
const [wrapperDirectory] = [...topLevelSegments];
|
|
702
|
+
if (
|
|
703
|
+
!archivePaths.includes(`${wrapperDirectory}/${HOSTED_RELEASE_ENTRY_PATH}`)
|
|
704
|
+
) {
|
|
705
|
+
throw new Error(
|
|
706
|
+
"Release archive wrapper directory must contain index.html at its root.",
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
return {
|
|
711
|
+
entryPath: HOSTED_RELEASE_ENTRY_PATH,
|
|
712
|
+
wrapperDirectory,
|
|
713
|
+
};
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
const inspectProjectRelease = async ({
|
|
717
|
+
projectDir,
|
|
718
|
+
distDir,
|
|
719
|
+
packageManager,
|
|
720
|
+
}: {
|
|
721
|
+
projectDir: string;
|
|
722
|
+
distDir: string;
|
|
723
|
+
packageManager: AirJamPackageManager;
|
|
724
|
+
}): Promise<AirJamLocalReleaseDoctor> => {
|
|
725
|
+
const packageJson = await readPackageJson(projectDir);
|
|
726
|
+
const configPath = await getLocalAirJamConfigPath(projectDir);
|
|
727
|
+
const game = configPath ? await inspectGame({ cwd: projectDir }) : null;
|
|
728
|
+
const controllerPath = game?.declaration.controllerPath ?? null;
|
|
729
|
+
const distExists = await pathExists(distDir);
|
|
730
|
+
const distEntryExists = distExists
|
|
731
|
+
? await pathExists(path.join(distDir, HOSTED_RELEASE_ENTRY_PATH))
|
|
732
|
+
: false;
|
|
733
|
+
const issues: AirJamLocalReleaseIssue[] = [];
|
|
734
|
+
|
|
735
|
+
if (!configPath) {
|
|
736
|
+
issues.push(
|
|
737
|
+
createIssue(
|
|
738
|
+
"missing-config",
|
|
739
|
+
"error",
|
|
740
|
+
"Hosted releases require src/airjam.config.ts so tooling can inspect the game contract.",
|
|
741
|
+
),
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
if (!packageJson?.value.scripts?.build) {
|
|
746
|
+
issues.push(
|
|
747
|
+
createIssue(
|
|
748
|
+
"missing-build-script",
|
|
749
|
+
"error",
|
|
750
|
+
'Hosted releases require a "build" script in package.json.',
|
|
751
|
+
packageJson?.path ?? null,
|
|
752
|
+
),
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
if (controllerPath && controllerPath !== HOSTED_RELEASE_CONTROLLER_PATH) {
|
|
757
|
+
issues.push(
|
|
758
|
+
createIssue(
|
|
759
|
+
"invalid-controller-path",
|
|
760
|
+
"error",
|
|
761
|
+
`Hosted Air Jam bundles require controllerPath to be ${HOSTED_RELEASE_CONTROLLER_PATH}. This project is configured for ${controllerPath}.`,
|
|
762
|
+
configPath,
|
|
763
|
+
),
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
if (distExists && !distEntryExists) {
|
|
768
|
+
issues.push(
|
|
769
|
+
createIssue(
|
|
770
|
+
"invalid-dist-entry",
|
|
771
|
+
"warning",
|
|
772
|
+
`Current build output is missing ${HOSTED_RELEASE_ENTRY_PATH} at ${distDir}. Run the build before validating or bundling.`,
|
|
773
|
+
distDir,
|
|
774
|
+
),
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
return {
|
|
779
|
+
projectDir,
|
|
780
|
+
packageJsonPath: packageJson?.path ?? null,
|
|
781
|
+
packageName: packageJson?.value.name ?? null,
|
|
782
|
+
packageVersion: packageJson?.value.version ?? null,
|
|
783
|
+
packageManager,
|
|
784
|
+
configPath,
|
|
785
|
+
buildScript: packageJson?.value.scripts?.build ?? null,
|
|
786
|
+
gameSlug: game?.id ?? null,
|
|
787
|
+
controllerPath,
|
|
788
|
+
distDir,
|
|
789
|
+
distExists,
|
|
790
|
+
distEntryExists,
|
|
791
|
+
recommendedBundlePath: getDefaultReleaseBundlePath({
|
|
792
|
+
projectDir,
|
|
793
|
+
packageName: packageJson?.value.name ?? null,
|
|
794
|
+
packageVersion: packageJson?.value.version ?? null,
|
|
795
|
+
}),
|
|
796
|
+
canBundle: !issues.some((issue) => issue.severity === "error"),
|
|
797
|
+
issues,
|
|
798
|
+
hostedContract: {
|
|
799
|
+
entryPath: HOSTED_RELEASE_ENTRY_PATH,
|
|
800
|
+
manifestPath: HOSTED_RELEASE_MANIFEST_PATH,
|
|
801
|
+
hostPath: HOSTED_RELEASE_HOST_PATH,
|
|
802
|
+
controllerPath: HOSTED_RELEASE_CONTROLLER_PATH,
|
|
803
|
+
},
|
|
804
|
+
};
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
const validateProjectBuildOutput = async ({
|
|
808
|
+
projectDir,
|
|
809
|
+
distDir,
|
|
810
|
+
packageManager,
|
|
811
|
+
skipBuild,
|
|
812
|
+
}: {
|
|
813
|
+
projectDir: string;
|
|
814
|
+
distDir: string;
|
|
815
|
+
packageManager: AirJamPackageManager;
|
|
816
|
+
skipBuild: boolean;
|
|
817
|
+
}): Promise<{
|
|
818
|
+
buildResult: CommandResult | null;
|
|
819
|
+
validation: AirJamLocalReleaseValidation;
|
|
820
|
+
}> => {
|
|
821
|
+
const doctor = await inspectProjectRelease({
|
|
822
|
+
projectDir,
|
|
823
|
+
distDir,
|
|
824
|
+
packageManager,
|
|
825
|
+
});
|
|
826
|
+
const issues = [...doctor.issues];
|
|
827
|
+
let buildResult: CommandResult | null = null;
|
|
828
|
+
|
|
829
|
+
if (!skipBuild && doctor.buildScript) {
|
|
830
|
+
buildResult = await runBuild({ projectDir, packageManager });
|
|
831
|
+
if (!buildResult.ok) {
|
|
832
|
+
issues.push(
|
|
833
|
+
createIssue(
|
|
834
|
+
"build-failed",
|
|
835
|
+
"error",
|
|
836
|
+
`Build failed for hosted release validation.\n${buildResult.stderr || buildResult.stdout || "Unknown build failure."}`,
|
|
837
|
+
doctor.packageJsonPath,
|
|
838
|
+
),
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
const distExists = await pathExists(distDir);
|
|
844
|
+
const distEntryExists = distExists
|
|
845
|
+
? await pathExists(path.join(distDir, HOSTED_RELEASE_ENTRY_PATH))
|
|
846
|
+
: false;
|
|
847
|
+
|
|
848
|
+
if (!distExists) {
|
|
849
|
+
issues.push(
|
|
850
|
+
createIssue(
|
|
851
|
+
"missing-dist",
|
|
852
|
+
"error",
|
|
853
|
+
`Build output directory not found at ${distDir}. Run the build first or pass --dist-dir.`,
|
|
854
|
+
distDir,
|
|
855
|
+
),
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
if (distExists && !distEntryExists) {
|
|
860
|
+
issues.push(
|
|
861
|
+
createIssue(
|
|
862
|
+
"missing-dist-entry",
|
|
863
|
+
"error",
|
|
864
|
+
`Hosted bundle build output must contain ${HOSTED_RELEASE_ENTRY_PATH} at ${distDir}.`,
|
|
865
|
+
distDir,
|
|
866
|
+
),
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
let fileCount = 0;
|
|
871
|
+
let extractedSizeBytes = 0;
|
|
872
|
+
|
|
873
|
+
if (distExists) {
|
|
874
|
+
const files = await collectDirectoryFiles(distDir);
|
|
875
|
+
fileCount = files.length + 1;
|
|
876
|
+
|
|
877
|
+
for (const filePath of files) {
|
|
878
|
+
const fileStats = await stat(filePath);
|
|
879
|
+
extractedSizeBytes += fileStats.size;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
extractedSizeBytes += Buffer.byteLength(
|
|
883
|
+
`${JSON.stringify(createHostedReleaseArtifactManifest(), null, 2)}\n`,
|
|
884
|
+
"utf8",
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
return {
|
|
889
|
+
buildResult,
|
|
890
|
+
validation: {
|
|
891
|
+
source: {
|
|
892
|
+
kind: "project",
|
|
893
|
+
projectDir,
|
|
894
|
+
distDir,
|
|
895
|
+
bundlePath: null,
|
|
896
|
+
},
|
|
897
|
+
ok: !issues.some((issue) => issue.severity === "error"),
|
|
898
|
+
issues,
|
|
899
|
+
manifest: createHostedReleaseArtifactManifest(),
|
|
900
|
+
entryPath: distEntryExists ? HOSTED_RELEASE_ENTRY_PATH : null,
|
|
901
|
+
wrapperDirectory: null,
|
|
902
|
+
fileCount,
|
|
903
|
+
extractedSizeBytes,
|
|
904
|
+
},
|
|
905
|
+
};
|
|
906
|
+
};
|
|
907
|
+
|
|
908
|
+
const validateBundleArchive = async (
|
|
909
|
+
bundlePath: string,
|
|
910
|
+
): Promise<AirJamLocalReleaseValidation> => {
|
|
911
|
+
const issues: AirJamLocalReleaseIssue[] = [];
|
|
912
|
+
|
|
913
|
+
if (!(await pathExists(bundlePath))) {
|
|
914
|
+
return {
|
|
915
|
+
source: {
|
|
916
|
+
kind: "bundle",
|
|
917
|
+
projectDir: null,
|
|
918
|
+
distDir: null,
|
|
919
|
+
bundlePath,
|
|
920
|
+
},
|
|
921
|
+
ok: false,
|
|
922
|
+
issues: [
|
|
923
|
+
createIssue(
|
|
924
|
+
"missing-bundle",
|
|
925
|
+
"error",
|
|
926
|
+
`Hosted release bundle not found at ${bundlePath}.`,
|
|
927
|
+
bundlePath,
|
|
928
|
+
),
|
|
929
|
+
],
|
|
930
|
+
manifest: null,
|
|
931
|
+
entryPath: null,
|
|
932
|
+
wrapperDirectory: null,
|
|
933
|
+
fileCount: 0,
|
|
934
|
+
extractedSizeBytes: 0,
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
const archiveBuffer = await readFile(bundlePath);
|
|
939
|
+
const zipFile = await openZipFile(archiveBuffer);
|
|
940
|
+
const archivePaths: string[] = [];
|
|
941
|
+
const manifestCandidates = new Map<string, Buffer>();
|
|
942
|
+
let fileCount = 0;
|
|
943
|
+
let extractedSizeBytes = 0;
|
|
944
|
+
|
|
945
|
+
await new Promise<void>((resolve, reject) => {
|
|
946
|
+
zipFile.readEntry();
|
|
947
|
+
|
|
948
|
+
zipFile.on("entry", (entry) => {
|
|
949
|
+
try {
|
|
950
|
+
if (isZipSymlink(entry)) {
|
|
951
|
+
reject(
|
|
952
|
+
new Error(
|
|
953
|
+
`Release archive cannot contain symbolic links: ${entry.fileName}`,
|
|
954
|
+
),
|
|
955
|
+
);
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
const normalized = normalizeArchiveEntryPath(entry.fileName);
|
|
960
|
+
if (isIgnoredArchiveEntry(normalized.archivePath)) {
|
|
961
|
+
zipFile.readEntry();
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
if (normalized.isDirectory) {
|
|
966
|
+
zipFile.readEntry();
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
archivePaths.push(normalized.archivePath);
|
|
971
|
+
fileCount += 1;
|
|
972
|
+
extractedSizeBytes += entry.uncompressedSize;
|
|
973
|
+
|
|
974
|
+
if (
|
|
975
|
+
normalized.archivePath.endsWith(`/${HOSTED_RELEASE_MANIFEST_PATH}`) ||
|
|
976
|
+
normalized.archivePath === HOSTED_RELEASE_MANIFEST_PATH
|
|
977
|
+
) {
|
|
978
|
+
void openZipEntryReadStream(zipFile, entry)
|
|
979
|
+
.then(readStreamBuffer)
|
|
980
|
+
.then((buffer) => {
|
|
981
|
+
manifestCandidates.set(normalized.archivePath, buffer);
|
|
982
|
+
zipFile.readEntry();
|
|
983
|
+
})
|
|
984
|
+
.catch(reject);
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
zipFile.readEntry();
|
|
989
|
+
} catch (error) {
|
|
990
|
+
reject(error);
|
|
991
|
+
}
|
|
992
|
+
});
|
|
993
|
+
|
|
994
|
+
zipFile.once("end", resolve);
|
|
995
|
+
zipFile.once("error", reject);
|
|
996
|
+
}).finally(() => {
|
|
997
|
+
zipFile.close();
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
try {
|
|
1001
|
+
const root = resolveArchiveRoot(
|
|
1002
|
+
archivePaths.filter((archivePath) => !archivePath.endsWith("/")),
|
|
1003
|
+
);
|
|
1004
|
+
const manifestPath = root.wrapperDirectory
|
|
1005
|
+
? `${root.wrapperDirectory}/${HOSTED_RELEASE_MANIFEST_PATH}`
|
|
1006
|
+
: HOSTED_RELEASE_MANIFEST_PATH;
|
|
1007
|
+
const manifestBuffer = manifestCandidates.get(manifestPath);
|
|
1008
|
+
|
|
1009
|
+
if (!manifestBuffer) {
|
|
1010
|
+
issues.push(
|
|
1011
|
+
createIssue(
|
|
1012
|
+
"missing-manifest",
|
|
1013
|
+
"error",
|
|
1014
|
+
`Release archive must include ${HOSTED_RELEASE_MANIFEST_PATH} for Air Jam hosted releases.`,
|
|
1015
|
+
bundlePath,
|
|
1016
|
+
),
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
let manifest: HostedReleaseArtifactManifest | null = null;
|
|
1021
|
+
if (manifestBuffer) {
|
|
1022
|
+
try {
|
|
1023
|
+
manifest = hostedReleaseArtifactManifestSchema.parse(
|
|
1024
|
+
JSON.parse(manifestBuffer.toString("utf8")) as unknown,
|
|
1025
|
+
);
|
|
1026
|
+
} catch {
|
|
1027
|
+
issues.push(
|
|
1028
|
+
createIssue(
|
|
1029
|
+
"invalid-manifest",
|
|
1030
|
+
"error",
|
|
1031
|
+
`Hosted release manifest must match the Air Jam hosted artifact contract at ${HOSTED_RELEASE_MANIFEST_PATH}.`,
|
|
1032
|
+
bundlePath,
|
|
1033
|
+
),
|
|
1034
|
+
);
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
return {
|
|
1039
|
+
source: {
|
|
1040
|
+
kind: "bundle",
|
|
1041
|
+
projectDir: null,
|
|
1042
|
+
distDir: null,
|
|
1043
|
+
bundlePath,
|
|
1044
|
+
},
|
|
1045
|
+
ok: !issues.some((issue) => issue.severity === "error"),
|
|
1046
|
+
issues,
|
|
1047
|
+
manifest,
|
|
1048
|
+
entryPath: root.entryPath,
|
|
1049
|
+
wrapperDirectory: root.wrapperDirectory,
|
|
1050
|
+
fileCount,
|
|
1051
|
+
extractedSizeBytes,
|
|
1052
|
+
};
|
|
1053
|
+
} catch (error) {
|
|
1054
|
+
issues.push(
|
|
1055
|
+
createIssue(
|
|
1056
|
+
"invalid-bundle-layout",
|
|
1057
|
+
"error",
|
|
1058
|
+
error instanceof Error
|
|
1059
|
+
? error.message
|
|
1060
|
+
: "Invalid hosted release archive.",
|
|
1061
|
+
bundlePath,
|
|
1062
|
+
),
|
|
1063
|
+
);
|
|
1064
|
+
|
|
1065
|
+
return {
|
|
1066
|
+
source: {
|
|
1067
|
+
kind: "bundle",
|
|
1068
|
+
projectDir: null,
|
|
1069
|
+
distDir: null,
|
|
1070
|
+
bundlePath,
|
|
1071
|
+
},
|
|
1072
|
+
ok: false,
|
|
1073
|
+
issues,
|
|
1074
|
+
manifest: null,
|
|
1075
|
+
entryPath: null,
|
|
1076
|
+
wrapperDirectory: null,
|
|
1077
|
+
fileCount,
|
|
1078
|
+
extractedSizeBytes,
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
|
|
1083
|
+
const writeHostedReleaseBundle = async ({
|
|
1084
|
+
sourceDir,
|
|
1085
|
+
outputFile,
|
|
1086
|
+
}: {
|
|
1087
|
+
sourceDir: string;
|
|
1088
|
+
outputFile: string;
|
|
1089
|
+
}): Promise<void> => {
|
|
1090
|
+
const bundleSourceDir = await materializeBundleSourceTree({ sourceDir });
|
|
1091
|
+
|
|
1092
|
+
try {
|
|
1093
|
+
const files = await collectDirectoryFiles(bundleSourceDir);
|
|
1094
|
+
const zipFile = new yazl.ZipFile();
|
|
1095
|
+
await mkdir(path.dirname(outputFile), { recursive: true });
|
|
1096
|
+
const output = createWriteStream(outputFile);
|
|
1097
|
+
|
|
1098
|
+
const closePromise = new Promise<void>((resolve, reject) => {
|
|
1099
|
+
output.on("close", resolve);
|
|
1100
|
+
output.on("error", reject);
|
|
1101
|
+
zipFile.outputStream.on("error", reject);
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1104
|
+
zipFile.outputStream.pipe(output);
|
|
1105
|
+
|
|
1106
|
+
for (const filePath of files) {
|
|
1107
|
+
const relativePath = path
|
|
1108
|
+
.relative(bundleSourceDir, filePath)
|
|
1109
|
+
.replace(/\\/g, "/");
|
|
1110
|
+
if (!relativePath || relativePath === HOSTED_RELEASE_MANIFEST_PATH) {
|
|
1111
|
+
continue;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
zipFile.addFile(filePath, relativePath);
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
zipFile.addBuffer(
|
|
1118
|
+
Buffer.from(
|
|
1119
|
+
`${JSON.stringify(createHostedReleaseArtifactManifest(), null, 2)}\n`,
|
|
1120
|
+
"utf8",
|
|
1121
|
+
),
|
|
1122
|
+
HOSTED_RELEASE_MANIFEST_PATH,
|
|
1123
|
+
);
|
|
1124
|
+
zipFile.end();
|
|
1125
|
+
|
|
1126
|
+
await closePromise;
|
|
1127
|
+
} finally {
|
|
1128
|
+
await rm(path.dirname(bundleSourceDir), { recursive: true, force: true });
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
|
|
1132
|
+
export const inspectLocalRelease = async ({
|
|
1133
|
+
cwd = process.cwd(),
|
|
1134
|
+
distDir,
|
|
1135
|
+
}: InspectLocalReleaseOptions = {}): Promise<AirJamLocalReleaseDoctor> => {
|
|
1136
|
+
const projectDir = await resolveCanonicalPath(cwd);
|
|
1137
|
+
const resolvedDistDir = path.resolve(projectDir, distDir || "dist");
|
|
1138
|
+
const context = await detectProjectContext({ cwd: projectDir });
|
|
1139
|
+
const packageManager = await resolvePackageManager(projectDir);
|
|
1140
|
+
|
|
1141
|
+
if (context.mode === "monorepo" && context.rootDir === projectDir) {
|
|
1142
|
+
return {
|
|
1143
|
+
projectDir,
|
|
1144
|
+
packageJsonPath: context.packageJsonPath,
|
|
1145
|
+
packageName: context.packageJson?.name ?? null,
|
|
1146
|
+
packageVersion: context.packageJson?.version ?? null,
|
|
1147
|
+
packageManager,
|
|
1148
|
+
configPath: null,
|
|
1149
|
+
buildScript: null,
|
|
1150
|
+
gameSlug: null,
|
|
1151
|
+
controllerPath: null,
|
|
1152
|
+
distDir: resolvedDistDir,
|
|
1153
|
+
distExists: await pathExists(resolvedDistDir),
|
|
1154
|
+
distEntryExists: await pathExists(
|
|
1155
|
+
path.join(resolvedDistDir, HOSTED_RELEASE_ENTRY_PATH),
|
|
1156
|
+
),
|
|
1157
|
+
recommendedBundlePath: getDefaultReleaseBundlePath({
|
|
1158
|
+
projectDir,
|
|
1159
|
+
packageName: context.packageJson?.name ?? null,
|
|
1160
|
+
packageVersion: context.packageJson?.version ?? null,
|
|
1161
|
+
}),
|
|
1162
|
+
canBundle: false,
|
|
1163
|
+
issues: [
|
|
1164
|
+
createIssue(
|
|
1165
|
+
"unsupported-monorepo-project",
|
|
1166
|
+
"error",
|
|
1167
|
+
"Local hosted release bundling currently supports standalone Air Jam game projects only. Use a generated project directory for doctor/validate/bundle/submit, or use remote release list/inspect/publish tools from the monorepo.",
|
|
1168
|
+
context.packageJsonPath,
|
|
1169
|
+
),
|
|
1170
|
+
],
|
|
1171
|
+
hostedContract: {
|
|
1172
|
+
entryPath: HOSTED_RELEASE_ENTRY_PATH,
|
|
1173
|
+
manifestPath: HOSTED_RELEASE_MANIFEST_PATH,
|
|
1174
|
+
hostPath: HOSTED_RELEASE_HOST_PATH,
|
|
1175
|
+
controllerPath: HOSTED_RELEASE_CONTROLLER_PATH,
|
|
1176
|
+
},
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
return inspectProjectRelease({
|
|
1181
|
+
projectDir,
|
|
1182
|
+
distDir: resolvedDistDir,
|
|
1183
|
+
packageManager,
|
|
1184
|
+
});
|
|
1185
|
+
};
|
|
1186
|
+
|
|
1187
|
+
export const validateLocalRelease = async ({
|
|
1188
|
+
cwd = process.cwd(),
|
|
1189
|
+
distDir,
|
|
1190
|
+
bundlePath,
|
|
1191
|
+
skipBuild = false,
|
|
1192
|
+
}: ValidateLocalReleaseOptions = {}): Promise<AirJamLocalReleaseValidation> => {
|
|
1193
|
+
const projectDir = await resolveCanonicalPath(cwd);
|
|
1194
|
+
if (bundlePath) {
|
|
1195
|
+
return validateBundleArchive(path.resolve(projectDir, bundlePath));
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
const resolvedDistDir = path.resolve(projectDir, distDir || "dist");
|
|
1199
|
+
const packageManager = await resolvePackageManager(projectDir);
|
|
1200
|
+
const { validation } = await validateProjectBuildOutput({
|
|
1201
|
+
projectDir,
|
|
1202
|
+
distDir: resolvedDistDir,
|
|
1203
|
+
packageManager,
|
|
1204
|
+
skipBuild,
|
|
1205
|
+
});
|
|
1206
|
+
|
|
1207
|
+
return validation;
|
|
1208
|
+
};
|
|
1209
|
+
|
|
1210
|
+
export const bundleLocalRelease = async ({
|
|
1211
|
+
cwd = process.cwd(),
|
|
1212
|
+
distDir,
|
|
1213
|
+
out,
|
|
1214
|
+
skipBuild = false,
|
|
1215
|
+
}: BundleLocalReleaseOptions = {}): Promise<BundleLocalReleaseResult> => {
|
|
1216
|
+
const projectDir = await resolveCanonicalPath(cwd);
|
|
1217
|
+
const resolvedDistDir = path.resolve(projectDir, distDir || "dist");
|
|
1218
|
+
const doctor = await inspectLocalRelease({
|
|
1219
|
+
cwd: projectDir,
|
|
1220
|
+
distDir: resolvedDistDir,
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
if (!doctor.canBundle) {
|
|
1224
|
+
const summary = doctor.issues
|
|
1225
|
+
.filter((issue) => issue.severity === "error")
|
|
1226
|
+
.map((issue) => `- ${issue.message}`)
|
|
1227
|
+
.join("\n");
|
|
1228
|
+
throw new Error(`Hosted release bundle cannot be created:\n${summary}`);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
const { buildResult, validation: projectValidation } =
|
|
1232
|
+
await validateProjectBuildOutput({
|
|
1233
|
+
projectDir,
|
|
1234
|
+
distDir: resolvedDistDir,
|
|
1235
|
+
packageManager: doctor.packageManager,
|
|
1236
|
+
skipBuild,
|
|
1237
|
+
});
|
|
1238
|
+
|
|
1239
|
+
if (!projectValidation.ok) {
|
|
1240
|
+
const summary = projectValidation.issues
|
|
1241
|
+
.filter((issue) => issue.severity === "error")
|
|
1242
|
+
.map((issue) => `- ${issue.message}`)
|
|
1243
|
+
.join("\n");
|
|
1244
|
+
throw new Error(`Hosted release bundle validation failed:\n${summary}`);
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
const outputFile = out
|
|
1248
|
+
? path.resolve(projectDir, out)
|
|
1249
|
+
: doctor.recommendedBundlePath;
|
|
1250
|
+
|
|
1251
|
+
await writeHostedReleaseBundle({
|
|
1252
|
+
sourceDir: resolvedDistDir,
|
|
1253
|
+
outputFile,
|
|
1254
|
+
});
|
|
1255
|
+
|
|
1256
|
+
const bundleValidation = await validateBundleArchive(outputFile);
|
|
1257
|
+
if (!bundleValidation.ok) {
|
|
1258
|
+
const summary = bundleValidation.issues
|
|
1259
|
+
.filter((issue) => issue.severity === "error")
|
|
1260
|
+
.map((issue) => `- ${issue.message}`)
|
|
1261
|
+
.join("\n");
|
|
1262
|
+
throw new Error(`Hosted release bundle validation failed:\n${summary}`);
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
return {
|
|
1266
|
+
projectDir,
|
|
1267
|
+
distDir: resolvedDistDir,
|
|
1268
|
+
outputFile,
|
|
1269
|
+
built: !skipBuild,
|
|
1270
|
+
buildResult,
|
|
1271
|
+
validation: bundleValidation,
|
|
1272
|
+
};
|
|
1273
|
+
};
|
|
1274
|
+
|
|
1275
|
+
const uploadReleaseBundle = async ({
|
|
1276
|
+
bundlePath,
|
|
1277
|
+
upload,
|
|
1278
|
+
}: {
|
|
1279
|
+
bundlePath: string;
|
|
1280
|
+
upload: {
|
|
1281
|
+
method: "PUT";
|
|
1282
|
+
url: string;
|
|
1283
|
+
headers: Record<string, string>;
|
|
1284
|
+
};
|
|
1285
|
+
}) => {
|
|
1286
|
+
const archive = await readFile(bundlePath);
|
|
1287
|
+
const response = await fetch(upload.url, {
|
|
1288
|
+
method: upload.method,
|
|
1289
|
+
headers: upload.headers,
|
|
1290
|
+
body: archive,
|
|
1291
|
+
});
|
|
1292
|
+
|
|
1293
|
+
if (!response.ok) {
|
|
1294
|
+
throw new Error(
|
|
1295
|
+
`Release generation upload failed with status ${response.status}.`,
|
|
1296
|
+
);
|
|
1297
|
+
}
|
|
1298
|
+
};
|
|
1299
|
+
|
|
1300
|
+
export const listPlatformReleaseTargets = async ({
|
|
1301
|
+
platformUrl,
|
|
1302
|
+
token,
|
|
1303
|
+
}: ListPlatformReleaseTargetsOptions = {}) => {
|
|
1304
|
+
const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
|
|
1305
|
+
|
|
1306
|
+
return requestPlatformMachineApi({
|
|
1307
|
+
baseUrl: resolved.baseUrl,
|
|
1308
|
+
pathname: "/api/cli/games",
|
|
1309
|
+
token: resolved.token,
|
|
1310
|
+
schema: platformMachineListOwnedGamesResultSchema,
|
|
1311
|
+
});
|
|
1312
|
+
};
|
|
1313
|
+
|
|
1314
|
+
export const listPlatformReleases = async ({
|
|
1315
|
+
platformUrl,
|
|
1316
|
+
token,
|
|
1317
|
+
slugOrId,
|
|
1318
|
+
}: ListPlatformReleasesOptions) => {
|
|
1319
|
+
const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
|
|
1320
|
+
|
|
1321
|
+
return requestPlatformMachineApi({
|
|
1322
|
+
baseUrl: resolved.baseUrl,
|
|
1323
|
+
pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}/releases`,
|
|
1324
|
+
token: resolved.token,
|
|
1325
|
+
schema: platformMachineListReleasesResultSchema,
|
|
1326
|
+
});
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
export const inspectPlatformRelease = async ({
|
|
1330
|
+
platformUrl,
|
|
1331
|
+
token,
|
|
1332
|
+
releaseId,
|
|
1333
|
+
}: InspectPlatformReleaseOptions) => {
|
|
1334
|
+
const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
|
|
1335
|
+
|
|
1336
|
+
return requestPlatformMachineApi({
|
|
1337
|
+
baseUrl: resolved.baseUrl,
|
|
1338
|
+
pathname: `/api/cli/releases/${encodeURIComponent(releaseId)}`,
|
|
1339
|
+
token: resolved.token,
|
|
1340
|
+
schema: platformMachineGetReleaseResultSchema,
|
|
1341
|
+
});
|
|
1342
|
+
};
|
|
1343
|
+
|
|
1344
|
+
export const publishPlatformRelease = async ({
|
|
1345
|
+
platformUrl,
|
|
1346
|
+
token,
|
|
1347
|
+
releaseId,
|
|
1348
|
+
}: PublishPlatformReleaseOptions) => {
|
|
1349
|
+
const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
|
|
1350
|
+
|
|
1351
|
+
return requestPlatformMachineApi({
|
|
1352
|
+
baseUrl: resolved.baseUrl,
|
|
1353
|
+
pathname: `/api/cli/releases/${encodeURIComponent(releaseId)}/publish`,
|
|
1354
|
+
method: "POST",
|
|
1355
|
+
token: resolved.token,
|
|
1356
|
+
schema: platformMachinePublishReleaseResultSchema,
|
|
1357
|
+
});
|
|
1358
|
+
};
|
|
1359
|
+
|
|
1360
|
+
export const archivePlatformRelease = async ({
|
|
1361
|
+
platformUrl,
|
|
1362
|
+
token,
|
|
1363
|
+
releaseId,
|
|
1364
|
+
}: ArchivePlatformReleaseOptions) => {
|
|
1365
|
+
const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
|
|
1366
|
+
|
|
1367
|
+
return requestPlatformMachineApi({
|
|
1368
|
+
baseUrl: resolved.baseUrl,
|
|
1369
|
+
pathname: `/api/cli/releases/${encodeURIComponent(releaseId)}/archive`,
|
|
1370
|
+
method: "POST",
|
|
1371
|
+
token: resolved.token,
|
|
1372
|
+
schema: platformMachineArchiveReleaseResultSchema,
|
|
1373
|
+
});
|
|
1374
|
+
};
|
|
1375
|
+
|
|
1376
|
+
export const uploadPlatformReleaseGeneration = async ({
|
|
1377
|
+
platformUrl,
|
|
1378
|
+
token,
|
|
1379
|
+
releaseId,
|
|
1380
|
+
cwd = process.cwd(),
|
|
1381
|
+
bundlePath,
|
|
1382
|
+
}: UploadPlatformReleaseGenerationOptions) => {
|
|
1383
|
+
const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
|
|
1384
|
+
const effectiveBundlePath = path.resolve(cwd, bundlePath);
|
|
1385
|
+
const archive = await stat(effectiveBundlePath);
|
|
1386
|
+
if (!archive.isFile()) {
|
|
1387
|
+
throw new Error(`Release bundle is not a file: ${effectiveBundlePath}`);
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
const uploadTarget = await requestPlatformMachineApi({
|
|
1391
|
+
baseUrl: resolved.baseUrl,
|
|
1392
|
+
pathname: `/api/cli/releases/${encodeURIComponent(releaseId)}/upload-target`,
|
|
1393
|
+
method: "POST",
|
|
1394
|
+
token: resolved.token,
|
|
1395
|
+
body: {
|
|
1396
|
+
originalFilename: path.basename(effectiveBundlePath),
|
|
1397
|
+
sizeBytes: archive.size,
|
|
1398
|
+
},
|
|
1399
|
+
schema: platformMachineRequestReleaseUploadTargetResultSchema,
|
|
1400
|
+
});
|
|
1401
|
+
|
|
1402
|
+
await uploadReleaseBundle({
|
|
1403
|
+
bundlePath: effectiveBundlePath,
|
|
1404
|
+
upload: uploadTarget.upload,
|
|
1405
|
+
});
|
|
1406
|
+
|
|
1407
|
+
return { ...uploadTarget, bundlePath: effectiveBundlePath };
|
|
1408
|
+
};
|
|
1409
|
+
|
|
1410
|
+
export const finalizePlatformReleaseGeneration = async ({
|
|
1411
|
+
platformUrl,
|
|
1412
|
+
token,
|
|
1413
|
+
releaseId,
|
|
1414
|
+
generationId,
|
|
1415
|
+
}: FinalizePlatformReleaseGenerationOptions) => {
|
|
1416
|
+
const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
|
|
1417
|
+
|
|
1418
|
+
return requestPlatformMachineApi({
|
|
1419
|
+
baseUrl: resolved.baseUrl,
|
|
1420
|
+
pathname: `/api/cli/releases/${encodeURIComponent(releaseId)}/generations/${encodeURIComponent(generationId)}/finalize`,
|
|
1421
|
+
method: "POST",
|
|
1422
|
+
token: resolved.token,
|
|
1423
|
+
schema: platformMachineFinalizeReleaseUploadResultSchema,
|
|
1424
|
+
});
|
|
1425
|
+
};
|
|
1426
|
+
|
|
1427
|
+
export const exportPlatformReleaseGeneration = async ({
|
|
1428
|
+
platformUrl,
|
|
1429
|
+
token,
|
|
1430
|
+
releaseId,
|
|
1431
|
+
generationId,
|
|
1432
|
+
cwd = process.cwd(),
|
|
1433
|
+
out,
|
|
1434
|
+
}: ExportPlatformReleaseGenerationOptions): Promise<ExportPlatformReleaseGenerationResult> => {
|
|
1435
|
+
const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
|
|
1436
|
+
const target = await requestPlatformMachineApi({
|
|
1437
|
+
baseUrl: resolved.baseUrl,
|
|
1438
|
+
pathname: `/api/cli/releases/${encodeURIComponent(releaseId)}/generations/${encodeURIComponent(generationId)}/export`,
|
|
1439
|
+
method: "POST",
|
|
1440
|
+
token: resolved.token,
|
|
1441
|
+
schema: platformMachineRequestReleaseGenerationExportResultSchema,
|
|
1442
|
+
});
|
|
1443
|
+
const expectedSize =
|
|
1444
|
+
target.generation.observedSizeBytes ?? target.generation.declaredSizeBytes;
|
|
1445
|
+
const outputFile = path.resolve(cwd, out ?? target.download.filename);
|
|
1446
|
+
await mkdir(path.dirname(outputFile), { recursive: true });
|
|
1447
|
+
const destination = await open(outputFile, "wx");
|
|
1448
|
+
let sizeBytes = 0;
|
|
1449
|
+
let completed = false;
|
|
1450
|
+
try {
|
|
1451
|
+
const response = await fetch(target.download.url, {
|
|
1452
|
+
method: target.download.method,
|
|
1453
|
+
});
|
|
1454
|
+
if (!response.ok) {
|
|
1455
|
+
throw new Error(
|
|
1456
|
+
`Release generation export failed with status ${response.status}.`,
|
|
1457
|
+
);
|
|
1458
|
+
}
|
|
1459
|
+
if (!response.body) {
|
|
1460
|
+
throw new Error("Release generation export returned no response body.");
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
const reader = response.body.getReader();
|
|
1464
|
+
let streamFinished = false;
|
|
1465
|
+
try {
|
|
1466
|
+
while (true) {
|
|
1467
|
+
const chunk = await reader.read();
|
|
1468
|
+
if (chunk.done) {
|
|
1469
|
+
streamFinished = true;
|
|
1470
|
+
break;
|
|
1471
|
+
}
|
|
1472
|
+
const bytes = Buffer.from(chunk.value);
|
|
1473
|
+
sizeBytes += bytes.length;
|
|
1474
|
+
if (sizeBytes > expectedSize) {
|
|
1475
|
+
throw new Error(
|
|
1476
|
+
`Release generation export size mismatch: expected ${expectedSize} bytes, received more than ${expectedSize} bytes.`,
|
|
1477
|
+
);
|
|
1478
|
+
}
|
|
1479
|
+
let offset = 0;
|
|
1480
|
+
while (offset < bytes.length) {
|
|
1481
|
+
const { bytesWritten } = await destination.write(
|
|
1482
|
+
bytes,
|
|
1483
|
+
offset,
|
|
1484
|
+
bytes.length - offset,
|
|
1485
|
+
);
|
|
1486
|
+
if (bytesWritten === 0) {
|
|
1487
|
+
throw new Error(
|
|
1488
|
+
"Release generation export could not make progress writing the archive.",
|
|
1489
|
+
);
|
|
1490
|
+
}
|
|
1491
|
+
offset += bytesWritten;
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
} finally {
|
|
1495
|
+
if (!streamFinished) {
|
|
1496
|
+
await reader.cancel().catch(() => undefined);
|
|
1497
|
+
}
|
|
1498
|
+
reader.releaseLock();
|
|
1499
|
+
}
|
|
1500
|
+
if (sizeBytes !== expectedSize) {
|
|
1501
|
+
throw new Error(
|
|
1502
|
+
`Release generation export size mismatch: expected ${expectedSize} bytes, received ${sizeBytes}.`,
|
|
1503
|
+
);
|
|
1504
|
+
}
|
|
1505
|
+
await destination.sync();
|
|
1506
|
+
completed = true;
|
|
1507
|
+
} finally {
|
|
1508
|
+
await destination.close();
|
|
1509
|
+
if (!completed) {
|
|
1510
|
+
await rm(outputFile, { force: true });
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
return {
|
|
1515
|
+
...target,
|
|
1516
|
+
outputFile,
|
|
1517
|
+
sizeBytes,
|
|
1518
|
+
};
|
|
1519
|
+
};
|
|
1520
|
+
|
|
1521
|
+
export const waitForPlatformReleaseGeneration = async ({
|
|
1522
|
+
platformUrl,
|
|
1523
|
+
token,
|
|
1524
|
+
releaseId,
|
|
1525
|
+
generationId,
|
|
1526
|
+
timeoutMs = DEFAULT_RELEASE_PROCESSING_TIMEOUT_MS,
|
|
1527
|
+
pollIntervalMs = RELEASE_PROCESSING_POLL_INTERVAL_MS,
|
|
1528
|
+
}: FinalizePlatformReleaseGenerationOptions & {
|
|
1529
|
+
timeoutMs?: number;
|
|
1530
|
+
pollIntervalMs?: number;
|
|
1531
|
+
}) => {
|
|
1532
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1) {
|
|
1533
|
+
throw new Error("Release processing timeout must be a positive integer.");
|
|
1534
|
+
}
|
|
1535
|
+
if (!Number.isSafeInteger(pollIntervalMs) || pollIntervalMs < 1) {
|
|
1536
|
+
throw new Error(
|
|
1537
|
+
"Release processing poll interval must be a positive integer.",
|
|
1538
|
+
);
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
const deadline = Date.now() + timeoutMs;
|
|
1542
|
+
while (true) {
|
|
1543
|
+
const inspected = await inspectPlatformRelease({
|
|
1544
|
+
platformUrl,
|
|
1545
|
+
token,
|
|
1546
|
+
releaseId,
|
|
1547
|
+
});
|
|
1548
|
+
const generation = inspected.release.generations.find(
|
|
1549
|
+
(candidate) => candidate.id === generationId,
|
|
1550
|
+
);
|
|
1551
|
+
if (!generation) {
|
|
1552
|
+
throw new Error(
|
|
1553
|
+
`Release ${releaseId} no longer contains generation ${generationId}.`,
|
|
1554
|
+
);
|
|
1555
|
+
}
|
|
1556
|
+
if (
|
|
1557
|
+
generation.status === "ready" &&
|
|
1558
|
+
(inspected.release.status === "ready" ||
|
|
1559
|
+
inspected.release.status === "live") &&
|
|
1560
|
+
inspected.release.promotedGenerationId === generationId
|
|
1561
|
+
) {
|
|
1562
|
+
return inspected.release;
|
|
1563
|
+
}
|
|
1564
|
+
if (
|
|
1565
|
+
generation.status === "failed" ||
|
|
1566
|
+
generation.status === "abandoned" ||
|
|
1567
|
+
inspected.release.status === "failed" ||
|
|
1568
|
+
inspected.release.status === "quarantined" ||
|
|
1569
|
+
inspected.release.status === "archived"
|
|
1570
|
+
) {
|
|
1571
|
+
const failedJob = inspected.release.jobs.find(
|
|
1572
|
+
(job) =>
|
|
1573
|
+
job.generationId === generationId &&
|
|
1574
|
+
(job.status === "failed" || job.status === "canceled"),
|
|
1575
|
+
);
|
|
1576
|
+
const errorSuffix = failedJob?.lastErrorCode
|
|
1577
|
+
? ` (${failedJob.lastErrorCode})`
|
|
1578
|
+
: "";
|
|
1579
|
+
throw new Error(
|
|
1580
|
+
`Release generation ${generationId} ended with release ${inspected.release.status} and generation ${generation.status}${errorSuffix}. Inspect release ${releaseId} for its checks and job history.`,
|
|
1581
|
+
);
|
|
1582
|
+
}
|
|
1583
|
+
if (Date.now() >= deadline) {
|
|
1584
|
+
throw new Error(
|
|
1585
|
+
`Timed out waiting for release generation ${generationId}. Processing remains durable; inspect release ${releaseId} to continue.`,
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
await wait(Math.min(pollIntervalMs, Math.max(1, deadline - Date.now())));
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
|
|
1592
|
+
export const submitPlatformRelease = async ({
|
|
1593
|
+
platformUrl,
|
|
1594
|
+
token,
|
|
1595
|
+
slugOrId,
|
|
1596
|
+
versionLabel,
|
|
1597
|
+
cwd = process.cwd(),
|
|
1598
|
+
distDir,
|
|
1599
|
+
bundlePath,
|
|
1600
|
+
skipBuild = false,
|
|
1601
|
+
waitForProcessing = false,
|
|
1602
|
+
processingTimeoutMs = DEFAULT_RELEASE_PROCESSING_TIMEOUT_MS,
|
|
1603
|
+
processingPollIntervalMs = RELEASE_PROCESSING_POLL_INTERVAL_MS,
|
|
1604
|
+
publish = false,
|
|
1605
|
+
}: SubmitPlatformReleaseOptions): Promise<SubmitPlatformReleaseResult> => {
|
|
1606
|
+
const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
|
|
1607
|
+
const effectiveBundlePath = bundlePath
|
|
1608
|
+
? path.resolve(cwd, bundlePath)
|
|
1609
|
+
: (
|
|
1610
|
+
await bundleLocalRelease({
|
|
1611
|
+
cwd,
|
|
1612
|
+
distDir,
|
|
1613
|
+
skipBuild,
|
|
1614
|
+
})
|
|
1615
|
+
).outputFile;
|
|
1616
|
+
|
|
1617
|
+
const createdDraft = await requestPlatformMachineApi({
|
|
1618
|
+
baseUrl: resolved.baseUrl,
|
|
1619
|
+
pathname: "/api/cli/releases",
|
|
1620
|
+
method: "POST",
|
|
1621
|
+
token: resolved.token,
|
|
1622
|
+
body: {
|
|
1623
|
+
slugOrId,
|
|
1624
|
+
...(versionLabel?.trim() ? { versionLabel: versionLabel.trim() } : {}),
|
|
1625
|
+
},
|
|
1626
|
+
schema: platformMachineCreateReleaseDraftResultSchema,
|
|
1627
|
+
});
|
|
1628
|
+
|
|
1629
|
+
const uploadTarget = await uploadPlatformReleaseGeneration({
|
|
1630
|
+
platformUrl: resolved.baseUrl,
|
|
1631
|
+
token: resolved.token,
|
|
1632
|
+
releaseId: createdDraft.release.id,
|
|
1633
|
+
bundlePath: effectiveBundlePath,
|
|
1634
|
+
});
|
|
1635
|
+
|
|
1636
|
+
const submitted = await finalizePlatformReleaseGeneration({
|
|
1637
|
+
platformUrl: resolved.baseUrl,
|
|
1638
|
+
token: resolved.token,
|
|
1639
|
+
releaseId: createdDraft.release.id,
|
|
1640
|
+
generationId: uploadTarget.generation.id,
|
|
1641
|
+
});
|
|
1642
|
+
|
|
1643
|
+
const shouldWaitForProcessing = waitForProcessing || publish;
|
|
1644
|
+
const processedRelease = shouldWaitForProcessing
|
|
1645
|
+
? await waitForPlatformReleaseGeneration({
|
|
1646
|
+
platformUrl: resolved.baseUrl,
|
|
1647
|
+
token: resolved.token,
|
|
1648
|
+
releaseId: createdDraft.release.id,
|
|
1649
|
+
generationId: uploadTarget.generation.id,
|
|
1650
|
+
timeoutMs: processingTimeoutMs,
|
|
1651
|
+
pollIntervalMs: processingPollIntervalMs,
|
|
1652
|
+
})
|
|
1653
|
+
: null;
|
|
1654
|
+
|
|
1655
|
+
let publishedRelease = null;
|
|
1656
|
+
if (publish) {
|
|
1657
|
+
if (processedRelease?.status !== "ready") {
|
|
1658
|
+
throw new Error(
|
|
1659
|
+
`Release ${createdDraft.release.id} is ${processedRelease?.status ?? submitted.release.status} and cannot be published.`,
|
|
1660
|
+
);
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
const published = await requestPlatformMachineApi({
|
|
1664
|
+
baseUrl: resolved.baseUrl,
|
|
1665
|
+
pathname: `/api/cli/releases/${encodeURIComponent(createdDraft.release.id)}/publish`,
|
|
1666
|
+
method: "POST",
|
|
1667
|
+
token: resolved.token,
|
|
1668
|
+
schema: platformMachinePublishReleaseResultSchema,
|
|
1669
|
+
});
|
|
1670
|
+
publishedRelease = published.release;
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
return {
|
|
1674
|
+
bundlePath: effectiveBundlePath,
|
|
1675
|
+
createdRelease: createdDraft.release,
|
|
1676
|
+
createdGeneration: uploadTarget.generation,
|
|
1677
|
+
submittedRelease: submitted.release,
|
|
1678
|
+
submittedGeneration: submitted.generation,
|
|
1679
|
+
processingJob: submitted.job,
|
|
1680
|
+
processedRelease,
|
|
1681
|
+
publishedRelease,
|
|
1682
|
+
};
|
|
1683
|
+
};
|