@air-jam/cli 0.0.0-stage → 0.9.3
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 +145 -2
- package/bin/airjam.mjs +66 -0
- package/dist/ai-pack.d.ts +44 -0
- package/dist/ai-pack.js +15 -0
- package/dist/ai-pack.js.map +1 -0
- package/dist/chunk-A4V2N4LX.js +938 -0
- package/dist/chunk-A4V2N4LX.js.map +1 -0
- package/dist/chunk-J5MAU4QZ.js +102 -0
- package/dist/chunk-J5MAU4QZ.js.map +1 -0
- package/dist/chunk-N7AI7HZK.js +529 -0
- package/dist/chunk-N7AI7HZK.js.map +1 -0
- package/dist/development.d.ts +98 -0
- package/dist/development.js +33 -0
- package/dist/development.js.map +1 -0
- package/dist/documentation.d.ts +27 -0
- package/dist/documentation.js +7 -0
- package/dist/documentation.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2184 -0
- package/dist/index.js.map +1 -0
- package/dist/scaffold.d.ts +6 -0
- package/dist/scaffold.js +20 -0
- package/dist/scaffold.js.map +1 -0
- package/package.json +78 -3
- package/runtime/local-network.d.mts +8 -0
- package/runtime/local-network.mjs +9 -0
- package/runtime/vite-config.d.mts +42 -0
- package/runtime/vite-config.mjs +130 -0
- package/runtime/vite-https.d.mts +11 -0
- package/runtime/vite-https.mjs +41 -0
- package/template-assets/bootstrap/.claude/launch.json +12 -0
- package/template-assets/bootstrap/AGENTS.md +248 -0
- package/template-assets/bootstrap/CLAUDE.md +63 -0
- package/template-assets/bootstrap/_gitignore +6 -0
- package/template-assets/bootstrap/skills/airjam-docs-workflow/SKILL.md +49 -0
- package/template-assets/bootstrap/skills/airjam-mcp/SKILL.md +56 -0
- package/template-assets/bootstrap/skills/canvas-2d-gameplay/SKILL.md +47 -0
- package/template-assets/bootstrap/skills/controller-ui/SKILL.md +69 -0
- package/template-assets/bootstrap/skills/debug-and-test/SKILL.md +72 -0
- package/template-assets/bootstrap/skills/game-architecture/SKILL.md +58 -0
- package/template-assets/bootstrap/skills/game-state-and-rendering/SKILL.md +44 -0
- package/template-assets/bootstrap/skills/host-surface/SKILL.md +52 -0
- package/template-assets/bootstrap/skills/index.md +36 -0
- package/template-assets/bootstrap/skills/prefab-authoring/SKILL.md +48 -0
- package/template-assets/bootstrap/skills/r3f-3d-scene/SKILL.md +51 -0
- package/template-assets/documentation/for-agents/controller-ui/page.mdx +60 -0
- package/template-assets/documentation/for-agents/page.mdx +98 -0
- package/template-assets/documentation/for-agents/project-structure/page.mdx +172 -0
- package/template-assets/documentation/for-agents/state-and-rendering/page.mdx +79 -0
- package/template-assets/documentation/getting-started/debugging/page.mdx +165 -0
- package/template-assets/documentation/getting-started/dev-logs/page.mdx +171 -0
- package/template-assets/documentation/getting-started/game-ideas/page.mdx +116 -0
- package/template-assets/documentation/getting-started/introduction/page.mdx +183 -0
- package/template-assets/documentation/getting-started/migrating-legacy-games/page.mdx +427 -0
- package/template-assets/documentation/getting-started/quick-start/page.mdx +333 -0
- package/template-assets/documentation/how-it-works/architecture/page.mdx +189 -0
- package/template-assets/documentation/how-it-works/host-system/page.mdx +267 -0
- package/template-assets/documentation/manifest.json +430 -0
- package/template-assets/documentation/sdk/hooks/page.mdx +500 -0
- package/template-assets/documentation/sdk/input-system/page.mdx +270 -0
- package/template-assets/documentation/sdk/networked-state/page.mdx +213 -0
- package/template-assets/documentation/sdk/ui-components/page.mdx +227 -0
- package/template-assets/managed/.airjam/ai-pack.json +191 -0
- package/template-assets/managed/docs/airjam/agent-gold-path.md +67 -0
- package/template-assets/managed/docs/airjam/agent-mcp.md +135 -0
- package/template-assets/managed/docs/airjam/canvas-2d-gameplay.md +82 -0
- package/template-assets/managed/docs/airjam/composition-shell-contract.md +87 -0
- package/template-assets/managed/docs/airjam/debug-and-testing.md +86 -0
- package/template-assets/managed/docs/airjam/development-loop.md +51 -0
- package/template-assets/managed/docs/airjam/docs-index.md +58 -0
- package/template-assets/managed/docs/airjam/generated/architecture.md +178 -0
- package/template-assets/managed/docs/airjam/generated/controller-ui.md +61 -0
- package/template-assets/managed/docs/airjam/generated/debugging-and-logs.md +164 -0
- package/template-assets/managed/docs/airjam/generated/for-agents.md +99 -0
- package/template-assets/managed/docs/airjam/generated/game-ideas.md +107 -0
- package/template-assets/managed/docs/airjam/generated/host-system.md +251 -0
- package/template-assets/managed/docs/airjam/generated/input-system.md +260 -0
- package/template-assets/managed/docs/airjam/generated/introduction.md +175 -0
- package/template-assets/managed/docs/airjam/generated/migrating-legacy-games.md +426 -0
- package/template-assets/managed/docs/airjam/generated/networked-state.md +214 -0
- package/template-assets/managed/docs/airjam/generated/project-structure.md +171 -0
- package/template-assets/managed/docs/airjam/generated/quick-start.md +334 -0
- package/template-assets/managed/docs/airjam/generated/sdk-hooks.md +490 -0
- package/template-assets/managed/docs/airjam/generated/state-and-rendering.md +80 -0
- package/template-assets/managed/docs/airjam/generated/ui-components.md +222 -0
- package/template-assets/managed/docs/airjam/generated/unified-dev-logs.md +170 -0
- package/template-assets/managed/docs/airjam/iconography.md +55 -0
- package/template-assets/managed/docs/airjam/prefab-authoring.md +112 -0
- package/template-assets/managed/docs/airjam/preview-controllers.md +126 -0
- package/template-assets/managed/docs/airjam/r3f-3d-scene.md +97 -0
- package/template-assets/managed/docs/airjam/state-lanes-cookbook.md +106 -0
- package/template-assets/managed/docs/airjam/visual-system.md +103 -0
|
@@ -0,0 +1,938 @@
|
|
|
1
|
+
// runtime/dev-utils.mjs
|
|
2
|
+
import crossSpawn from "cross-spawn";
|
|
3
|
+
import { execFileSync } from "child_process";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import net from "net";
|
|
6
|
+
import os from "os";
|
|
7
|
+
var isPortOpen = (port) => new Promise((resolve) => {
|
|
8
|
+
const socket = net.createConnection({ port, host: "127.0.0.1" });
|
|
9
|
+
const done = (value) => {
|
|
10
|
+
socket.removeAllListeners();
|
|
11
|
+
socket.destroy();
|
|
12
|
+
resolve(value);
|
|
13
|
+
};
|
|
14
|
+
socket.setTimeout(400);
|
|
15
|
+
socket.on("connect", () => done(true));
|
|
16
|
+
socket.on("timeout", () => done(false));
|
|
17
|
+
socket.on("error", () => done(false));
|
|
18
|
+
});
|
|
19
|
+
var waitForPort = (port, timeoutMs) => new Promise((resolve, reject) => {
|
|
20
|
+
const start = Date.now();
|
|
21
|
+
const tryConnect = () => {
|
|
22
|
+
const socket = net.createConnection({ port, host: "127.0.0.1" });
|
|
23
|
+
socket.on("connect", () => {
|
|
24
|
+
socket.end();
|
|
25
|
+
resolve(true);
|
|
26
|
+
});
|
|
27
|
+
socket.on("error", () => {
|
|
28
|
+
socket.destroy();
|
|
29
|
+
if (Date.now() - start > timeoutMs) {
|
|
30
|
+
reject(new Error(`Timed out waiting for localhost:${port}`));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
setTimeout(tryConnect, 300);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
tryConnect();
|
|
37
|
+
});
|
|
38
|
+
var loadEnvFile = (filePath, env = process.env) => {
|
|
39
|
+
if (!fs.existsSync(filePath)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
43
|
+
for (const rawLine of content.split("\n")) {
|
|
44
|
+
const line = rawLine.trim();
|
|
45
|
+
if (!line || line.startsWith("#")) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const eq = line.indexOf("=");
|
|
49
|
+
if (eq <= 0) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const key = line.slice(0, eq).trim();
|
|
53
|
+
const value = line.slice(eq + 1).trim();
|
|
54
|
+
if (!env[key]) {
|
|
55
|
+
env[key] = value;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var isPrivateIpv4 = (ip) => ip.startsWith("10.") || ip.startsWith("192.168.") || /^172\.(1[6-9]|2[0-9]|3[01])\./.test(ip);
|
|
60
|
+
var isVirtualInterface = (name) => /^(lo|docker|br-|veth|vbox|vmnet|utun|gif|stf|awdl|llw)/i.test(name);
|
|
61
|
+
var scoreIp = (ip) => {
|
|
62
|
+
if (ip.startsWith("192.168.")) {
|
|
63
|
+
const parts = ip.split(".");
|
|
64
|
+
const third = Number(parts[2] ?? "0");
|
|
65
|
+
return third < 64 ? 300 - third : 200 - third;
|
|
66
|
+
}
|
|
67
|
+
if (ip.startsWith("10.")) {
|
|
68
|
+
return 150;
|
|
69
|
+
}
|
|
70
|
+
if (/^172\.(1[6-9]|2[0-9]|3[01])\./.test(ip)) {
|
|
71
|
+
return 100;
|
|
72
|
+
}
|
|
73
|
+
return 0;
|
|
74
|
+
};
|
|
75
|
+
var detectLocalIpv4 = () => {
|
|
76
|
+
const networks = os.networkInterfaces();
|
|
77
|
+
const candidates = [];
|
|
78
|
+
for (const [name, entries] of Object.entries(networks)) {
|
|
79
|
+
if (!entries || isVirtualInterface(name)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
for (const entry of entries) {
|
|
83
|
+
if (!entry || entry.internal || entry.family !== "IPv4") {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const ip = entry.address;
|
|
87
|
+
if (!isPrivateIpv4(ip) || ip.startsWith("169.254.")) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
candidates.push({ ip, score: scoreIp(ip) });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
candidates.sort((a, b) => b.score - a.score);
|
|
94
|
+
return candidates[0]?.ip ?? null;
|
|
95
|
+
};
|
|
96
|
+
var getFlagValue = (argv, flag) => {
|
|
97
|
+
const inlineArg = argv.find((arg) => arg.startsWith(`${flag}=`));
|
|
98
|
+
if (inlineArg) {
|
|
99
|
+
return inlineArg.slice(flag.length + 1);
|
|
100
|
+
}
|
|
101
|
+
const index = argv.indexOf(flag);
|
|
102
|
+
return index === -1 ? null : argv[index + 1] ?? null;
|
|
103
|
+
};
|
|
104
|
+
var hasFlag = (argv, flag) => argv.includes(flag);
|
|
105
|
+
var upsertEnv = (filePath, key, value) => {
|
|
106
|
+
let content = "";
|
|
107
|
+
if (fs.existsSync(filePath)) {
|
|
108
|
+
content = fs.readFileSync(filePath, "utf8");
|
|
109
|
+
}
|
|
110
|
+
const nextLine = `${key}=${value}`;
|
|
111
|
+
const pattern = new RegExp(`^${key}=.*$`, "m");
|
|
112
|
+
if (pattern.test(content)) {
|
|
113
|
+
content = content.replace(pattern, nextLine);
|
|
114
|
+
} else {
|
|
115
|
+
content += `${content.endsWith("\n") || content.length === 0 ? "" : "\n"}${nextLine}
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
fs.writeFileSync(filePath, content, "utf8");
|
|
119
|
+
};
|
|
120
|
+
var commandExists = (command, args = ["--version"]) => {
|
|
121
|
+
try {
|
|
122
|
+
execFileSync(command, args, {
|
|
123
|
+
encoding: "utf8",
|
|
124
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
125
|
+
});
|
|
126
|
+
return true;
|
|
127
|
+
} catch {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
var logChunk = (prefix, data) => {
|
|
132
|
+
const text = data.toString();
|
|
133
|
+
for (const line of text.split("\n")) {
|
|
134
|
+
if (!line.trim()) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
console.log(`[${prefix}] ${line}`);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var createProcessGroup = () => {
|
|
141
|
+
const children = [];
|
|
142
|
+
let isShuttingDown = false;
|
|
143
|
+
const shutdown = (code = 0) => {
|
|
144
|
+
if (isShuttingDown) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
isShuttingDown = true;
|
|
148
|
+
for (const child of children) {
|
|
149
|
+
if (!child.killed) {
|
|
150
|
+
child.kill("SIGTERM");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
setTimeout(() => process.exit(code), 100);
|
|
154
|
+
};
|
|
155
|
+
const run2 = (name, command, args, options = {}) => {
|
|
156
|
+
const { fatal = true, ...spawnOptions } = options;
|
|
157
|
+
const child = crossSpawn(command, args, {
|
|
158
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
159
|
+
...spawnOptions
|
|
160
|
+
});
|
|
161
|
+
child.stdout.on("data", (data) => logChunk(name, data));
|
|
162
|
+
child.stderr.on("data", (data) => logChunk(name, data));
|
|
163
|
+
child.on("error", (error) => {
|
|
164
|
+
console.error(`[${name}] failed to start: ${error.message}`);
|
|
165
|
+
shutdown(1);
|
|
166
|
+
});
|
|
167
|
+
child.on("exit", (code, signal) => {
|
|
168
|
+
if (!fatal) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (code === 0 || signal === "SIGTERM") {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
console.error(`[${name}] exited with code ${code ?? "null"}`);
|
|
175
|
+
shutdown(code ?? 1);
|
|
176
|
+
});
|
|
177
|
+
children.push(child);
|
|
178
|
+
return child;
|
|
179
|
+
};
|
|
180
|
+
const registerSignalHandlers = () => {
|
|
181
|
+
process.on("SIGINT", () => shutdown(0));
|
|
182
|
+
process.on("SIGTERM", () => shutdown(0));
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
run: run2,
|
|
186
|
+
shutdown,
|
|
187
|
+
registerSignalHandlers
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// runtime/runtime-topology.mjs
|
|
192
|
+
import {
|
|
193
|
+
resolveProjectRuntimeTopology,
|
|
194
|
+
resolveRuntimeTopology,
|
|
195
|
+
serializeRuntimeTopology
|
|
196
|
+
} from "@air-jam/sdk/runtime-topology";
|
|
197
|
+
|
|
198
|
+
// runtime/vite-https.mjs
|
|
199
|
+
import fs2 from "fs";
|
|
200
|
+
|
|
201
|
+
// runtime/local-network.mjs
|
|
202
|
+
var DEFAULT_AIR_JAM_SERVER_PORT = 4e3;
|
|
203
|
+
var resolveLocalBackendOrigin = (env = {}) => {
|
|
204
|
+
const explicitOrigin = env.VITE_AIR_JAM_SERVER_URL?.trim();
|
|
205
|
+
return explicitOrigin || `http://127.0.0.1:${env.AIR_JAM_SERVER_PORT ?? DEFAULT_AIR_JAM_SERVER_PORT}`;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// runtime/vite-https.mjs
|
|
209
|
+
var DEFAULT_AIR_JAM_DEV_BACKEND_URL = resolveLocalBackendOrigin();
|
|
210
|
+
|
|
211
|
+
// runtime/runtime-topology.mjs
|
|
212
|
+
var normalizeAssetBasePath = (runtimeUrl) => {
|
|
213
|
+
const parsed = new URL(runtimeUrl);
|
|
214
|
+
if (parsed.pathname.startsWith("/airjam-local-builds/")) {
|
|
215
|
+
const [, localBuilds, gameId] = parsed.pathname.split("/");
|
|
216
|
+
return `/${localBuilds}/${gameId}`;
|
|
217
|
+
}
|
|
218
|
+
return "/";
|
|
219
|
+
};
|
|
220
|
+
var buildStandaloneGameTopology = ({
|
|
221
|
+
surfaceRole,
|
|
222
|
+
publicHost,
|
|
223
|
+
secureTransport = false,
|
|
224
|
+
backendOrigin = DEFAULT_AIR_JAM_DEV_BACKEND_URL
|
|
225
|
+
}) => resolveProjectRuntimeTopology({
|
|
226
|
+
runtimeMode: secureTransport ? "standalone-secure" : "standalone-dev",
|
|
227
|
+
surfaceRole,
|
|
228
|
+
appOrigin: publicHost,
|
|
229
|
+
backendOrigin,
|
|
230
|
+
publicHost,
|
|
231
|
+
secureTransport
|
|
232
|
+
});
|
|
233
|
+
var buildPlatformShellTopology = ({
|
|
234
|
+
runtimeMode,
|
|
235
|
+
surfaceRole,
|
|
236
|
+
appOrigin,
|
|
237
|
+
publicHost,
|
|
238
|
+
backendOrigin = DEFAULT_AIR_JAM_DEV_BACKEND_URL,
|
|
239
|
+
secureTransport = false
|
|
240
|
+
}) => resolveRuntimeTopology({
|
|
241
|
+
runtimeMode,
|
|
242
|
+
surfaceRole,
|
|
243
|
+
appOrigin,
|
|
244
|
+
backendOrigin,
|
|
245
|
+
publicHost,
|
|
246
|
+
proxyStrategy: "platform-proxy",
|
|
247
|
+
secureTransport
|
|
248
|
+
});
|
|
249
|
+
var buildEmbeddedGameTopology = ({
|
|
250
|
+
runtimeMode,
|
|
251
|
+
surfaceRole,
|
|
252
|
+
runtimeUrl,
|
|
253
|
+
publicHost,
|
|
254
|
+
embedParentOrigin,
|
|
255
|
+
backendOrigin = DEFAULT_AIR_JAM_DEV_BACKEND_URL,
|
|
256
|
+
secureTransport = false
|
|
257
|
+
}) => resolveRuntimeTopology({
|
|
258
|
+
runtimeMode,
|
|
259
|
+
surfaceRole,
|
|
260
|
+
appOrigin: new URL(runtimeUrl).origin,
|
|
261
|
+
backendOrigin,
|
|
262
|
+
publicHost,
|
|
263
|
+
assetBasePath: normalizeAssetBasePath(runtimeUrl),
|
|
264
|
+
secureTransport,
|
|
265
|
+
embedded: true,
|
|
266
|
+
embedParentOrigin,
|
|
267
|
+
proxyStrategy: "none"
|
|
268
|
+
});
|
|
269
|
+
var serializeResolvedTopology = (topology) => serializeRuntimeTopology(topology);
|
|
270
|
+
|
|
271
|
+
// ../env/index.mjs
|
|
272
|
+
var ANSI = {
|
|
273
|
+
reset: "\x1B[0m",
|
|
274
|
+
bold: "\x1B[1m",
|
|
275
|
+
red: "\x1B[31m",
|
|
276
|
+
yellow: "\x1B[33m",
|
|
277
|
+
cyan: "\x1B[36m",
|
|
278
|
+
dim: "\x1B[2m"
|
|
279
|
+
};
|
|
280
|
+
var DEFAULT_FOOTER_HINT = "Set the required environment variables and retry.";
|
|
281
|
+
var resolveColorEnabled = (forced) => {
|
|
282
|
+
if (typeof forced === "boolean") {
|
|
283
|
+
return forced;
|
|
284
|
+
}
|
|
285
|
+
if (typeof process === "undefined") {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
if (typeof process.env?.NO_COLOR !== "undefined") {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
return Boolean(process.stderr?.isTTY);
|
|
292
|
+
};
|
|
293
|
+
var paint = (enabled, tone, value) => {
|
|
294
|
+
if (!enabled) {
|
|
295
|
+
return value;
|
|
296
|
+
}
|
|
297
|
+
return `${ANSI[tone]}${value}${ANSI.reset}`;
|
|
298
|
+
};
|
|
299
|
+
var toEnvKey = (path2) => {
|
|
300
|
+
if (!Array.isArray(path2) || path2.length === 0) {
|
|
301
|
+
return "<root>";
|
|
302
|
+
}
|
|
303
|
+
const firstStringSegment = path2.find(
|
|
304
|
+
(segment) => typeof segment === "string"
|
|
305
|
+
);
|
|
306
|
+
return typeof firstStringSegment === "string" ? firstStringSegment : "<root>";
|
|
307
|
+
};
|
|
308
|
+
var describeExpectedRule = (issue) => {
|
|
309
|
+
switch (issue.code) {
|
|
310
|
+
case "invalid_type":
|
|
311
|
+
return `type ${String(issue.expected)}`;
|
|
312
|
+
case "invalid_value":
|
|
313
|
+
return issue.values && issue.values.length > 0 ? `one of: ${issue.values.join(", ")}` : "a valid value";
|
|
314
|
+
case "too_small":
|
|
315
|
+
return issue.minimum != null ? `at least ${issue.minimum}${issue.inclusive === false ? " (exclusive)" : ""}` : "a larger value";
|
|
316
|
+
case "too_big":
|
|
317
|
+
return issue.maximum != null ? `at most ${issue.maximum}${issue.inclusive === false ? " (exclusive)" : ""}` : "a smaller value";
|
|
318
|
+
case "invalid_format":
|
|
319
|
+
return issue.format ? `format ${issue.format}` : "a valid format";
|
|
320
|
+
default:
|
|
321
|
+
return "a valid value";
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
var toReceivedValue = (env, envKey) => {
|
|
325
|
+
if (!env || envKey === "<root>") {
|
|
326
|
+
return void 0;
|
|
327
|
+
}
|
|
328
|
+
const value = env[envKey];
|
|
329
|
+
if (typeof value === "undefined") {
|
|
330
|
+
return void 0;
|
|
331
|
+
}
|
|
332
|
+
return String(value);
|
|
333
|
+
};
|
|
334
|
+
var normalizeIssues = ({ zodIssues, env, keyHints }) => zodIssues.map((issue) => {
|
|
335
|
+
const envKey = toEnvKey(issue.path);
|
|
336
|
+
return {
|
|
337
|
+
envKey,
|
|
338
|
+
expected: describeExpectedRule(issue),
|
|
339
|
+
received: toReceivedValue(env, envKey),
|
|
340
|
+
message: issue.message,
|
|
341
|
+
fix: keyHints?.[envKey] ?? (envKey === "<root>" ? "Adjust the environment values so the schema constraints pass." : `Set ${envKey} to a valid value.`)
|
|
342
|
+
};
|
|
343
|
+
}).sort((a, b) => {
|
|
344
|
+
if (a.envKey === b.envKey) {
|
|
345
|
+
return a.message.localeCompare(b.message);
|
|
346
|
+
}
|
|
347
|
+
return a.envKey.localeCompare(b.envKey);
|
|
348
|
+
});
|
|
349
|
+
var EnvValidationError = class extends Error {
|
|
350
|
+
constructor({ boundary, issues, docsHint }) {
|
|
351
|
+
const count = issues.length;
|
|
352
|
+
super(
|
|
353
|
+
`${boundary}: invalid environment configuration (${count} issue${count === 1 ? "" : "s"})`
|
|
354
|
+
);
|
|
355
|
+
this.name = "EnvValidationError";
|
|
356
|
+
this.boundary = boundary;
|
|
357
|
+
this.issues = issues;
|
|
358
|
+
this.docsHint = docsHint;
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
var isEnvValidationError = (error) => error instanceof EnvValidationError;
|
|
362
|
+
var validateEnv = ({
|
|
363
|
+
boundary,
|
|
364
|
+
schema,
|
|
365
|
+
env = process.env,
|
|
366
|
+
docsHint,
|
|
367
|
+
keyHints
|
|
368
|
+
}) => {
|
|
369
|
+
const result = schema.safeParse(env);
|
|
370
|
+
if (result.success) {
|
|
371
|
+
return result.data;
|
|
372
|
+
}
|
|
373
|
+
throw new EnvValidationError({
|
|
374
|
+
boundary,
|
|
375
|
+
docsHint,
|
|
376
|
+
issues: normalizeIssues({
|
|
377
|
+
zodIssues: result.error.issues,
|
|
378
|
+
env,
|
|
379
|
+
keyHints
|
|
380
|
+
})
|
|
381
|
+
});
|
|
382
|
+
};
|
|
383
|
+
var formatEnvValidationError = (error, { color, includeReceived = true, docsHint } = {}) => {
|
|
384
|
+
if (!isEnvValidationError(error)) {
|
|
385
|
+
return String(error);
|
|
386
|
+
}
|
|
387
|
+
const colorEnabled = resolveColorEnabled(color);
|
|
388
|
+
const heading = `\u2716 ${error.boundary}: invalid environment configuration`;
|
|
389
|
+
const lines = [
|
|
390
|
+
paint(colorEnabled, "red", paint(colorEnabled, "bold", heading))
|
|
391
|
+
];
|
|
392
|
+
for (const [index, issue] of error.issues.entries()) {
|
|
393
|
+
lines.push(
|
|
394
|
+
`${paint(colorEnabled, "yellow", `${index + 1}. ${issue.envKey}`)} ${paint(colorEnabled, "dim", `(${issue.message})`)}`
|
|
395
|
+
);
|
|
396
|
+
lines.push(` expected: ${issue.expected}`);
|
|
397
|
+
if (includeReceived) {
|
|
398
|
+
lines.push(
|
|
399
|
+
` received: ${typeof issue.received === "string" && issue.received.length > 0 ? `"${issue.received}"` : "<missing>"}`
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
lines.push(` fix: ${issue.fix}`);
|
|
403
|
+
}
|
|
404
|
+
lines.push("");
|
|
405
|
+
lines.push(
|
|
406
|
+
paint(
|
|
407
|
+
colorEnabled,
|
|
408
|
+
"cyan",
|
|
409
|
+
`Next: ${docsHint ?? error.docsHint ?? DEFAULT_FOOTER_HINT}`
|
|
410
|
+
)
|
|
411
|
+
);
|
|
412
|
+
return lines.join("\n");
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
// runtime/secure-dev.mjs
|
|
416
|
+
import { execFileSync as execFileSync2 } from "child_process";
|
|
417
|
+
import fs3 from "fs";
|
|
418
|
+
import path from "path";
|
|
419
|
+
|
|
420
|
+
// runtime/runtime-env.mjs
|
|
421
|
+
import { z } from "zod";
|
|
422
|
+
var trimToUndefined = (value) => {
|
|
423
|
+
if (typeof value !== "string") {
|
|
424
|
+
return void 0;
|
|
425
|
+
}
|
|
426
|
+
const normalized = value.trim();
|
|
427
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
428
|
+
};
|
|
429
|
+
var optionalEnvValue = z.string().optional().transform((value) => trimToUndefined(value));
|
|
430
|
+
var optionalEnumFromEnv = (envKey, values) => optionalEnvValue.transform((value, context) => {
|
|
431
|
+
if (!value) {
|
|
432
|
+
return void 0;
|
|
433
|
+
}
|
|
434
|
+
if (!values.includes(value)) {
|
|
435
|
+
context.addIssue({
|
|
436
|
+
code: "custom",
|
|
437
|
+
message: `${envKey} must be one of: ${values.join(", ")}.`
|
|
438
|
+
});
|
|
439
|
+
return z.NEVER;
|
|
440
|
+
}
|
|
441
|
+
return value;
|
|
442
|
+
});
|
|
443
|
+
var positiveIntegerFromEnv = (envKey, fallback) => optionalEnvValue.transform((value, context) => {
|
|
444
|
+
if (!value) {
|
|
445
|
+
return fallback;
|
|
446
|
+
}
|
|
447
|
+
const parsed = Number.parseInt(value, 10);
|
|
448
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
449
|
+
context.addIssue({
|
|
450
|
+
code: "custom",
|
|
451
|
+
message: `${envKey} must be a positive integer.`
|
|
452
|
+
});
|
|
453
|
+
return z.NEVER;
|
|
454
|
+
}
|
|
455
|
+
return parsed;
|
|
456
|
+
});
|
|
457
|
+
var createAirJamRuntimeEnvSchema = z.object({
|
|
458
|
+
VITE_PORT: positiveIntegerFromEnv("VITE_PORT", 5173),
|
|
459
|
+
AIR_JAM_SERVER_PORT: positiveIntegerFromEnv(
|
|
460
|
+
"AIR_JAM_SERVER_PORT",
|
|
461
|
+
DEFAULT_AIR_JAM_SERVER_PORT
|
|
462
|
+
),
|
|
463
|
+
AIR_JAM_SECURE_MODE: optionalEnumFromEnv("AIR_JAM_SECURE_MODE", [
|
|
464
|
+
"local",
|
|
465
|
+
"tunnel"
|
|
466
|
+
]),
|
|
467
|
+
AIR_JAM_MKCERT_TRUST_STORES: optionalEnvValue,
|
|
468
|
+
AIR_JAM_SECURE_PUBLIC_HOST: optionalEnvValue,
|
|
469
|
+
CLOUDFLARE_TUNNEL_NAME: optionalEnvValue,
|
|
470
|
+
AIR_JAM_SECURE_ROOT: optionalEnvValue,
|
|
471
|
+
VITE_AIR_JAM_SERVER_URL: optionalEnvValue,
|
|
472
|
+
VITE_AIR_JAM_PUBLIC_HOST: optionalEnvValue,
|
|
473
|
+
NEXT_PUBLIC_APP_URL: optionalEnvValue,
|
|
474
|
+
HOME: optionalEnvValue
|
|
475
|
+
});
|
|
476
|
+
var loadCreateAirJamRuntimeEnv = ({
|
|
477
|
+
env = process.env,
|
|
478
|
+
boundary = "create-airjam.runtime"
|
|
479
|
+
} = {}) => validateEnv({
|
|
480
|
+
boundary,
|
|
481
|
+
schema: createAirJamRuntimeEnvSchema,
|
|
482
|
+
env,
|
|
483
|
+
docsHint: "Fix runtime env values in .env / .env.local before running create-airjam runtime commands.",
|
|
484
|
+
keyHints: {
|
|
485
|
+
VITE_PORT: "Set a positive integer Vite port (for example: VITE_PORT=5173).",
|
|
486
|
+
AIR_JAM_SERVER_PORT: "Set a positive integer local server port (for example: AIR_JAM_SERVER_PORT=4000).",
|
|
487
|
+
AIR_JAM_SECURE_MODE: "Use AIR_JAM_SECURE_MODE=local or AIR_JAM_SECURE_MODE=tunnel."
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
// runtime/secure-dev.mjs
|
|
492
|
+
var SECURE_MODE_LOCAL = "local";
|
|
493
|
+
var SECURE_MODE_TUNNEL = "tunnel";
|
|
494
|
+
var DEFAULT_GAME_PORT = 5173;
|
|
495
|
+
var DEFAULT_PLATFORM_PORT = 3e3;
|
|
496
|
+
var SECURE_DEV_VERSION = 1;
|
|
497
|
+
var SECURE_MODE_VALUES = /* @__PURE__ */ new Set([SECURE_MODE_LOCAL, SECURE_MODE_TUNNEL]);
|
|
498
|
+
var resolveRequestedSecureMode = ({
|
|
499
|
+
argv = [],
|
|
500
|
+
env = process.env,
|
|
501
|
+
defaultMode = SECURE_MODE_LOCAL
|
|
502
|
+
} = {}) => {
|
|
503
|
+
const flagValue = getFlagValue(argv, "--secure-mode");
|
|
504
|
+
const envValue = env.AIR_JAM_SECURE_MODE;
|
|
505
|
+
const rawValue = (flagValue ?? envValue ?? defaultMode).trim().toLowerCase();
|
|
506
|
+
if (!SECURE_MODE_VALUES.has(rawValue)) {
|
|
507
|
+
throw new Error(
|
|
508
|
+
`Unsupported secure mode "${rawValue}". Use "local" or "tunnel".`
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
return rawValue;
|
|
512
|
+
};
|
|
513
|
+
var parseSecureInitArgs = (argv = [], env = process.env) => ({
|
|
514
|
+
mode: resolveRequestedSecureMode({ argv, env }),
|
|
515
|
+
hostname: getFlagValue(argv, "--hostname")?.trim() ?? "",
|
|
516
|
+
tunnel: getFlagValue(argv, "--tunnel")?.trim() ?? ""
|
|
517
|
+
});
|
|
518
|
+
var parseGameDevArgs = (argv = [], env = process.env) => {
|
|
519
|
+
const runtimeEnv = typeof env.VITE_PORT === "number" ? env : loadCreateAirJamRuntimeEnv({
|
|
520
|
+
env,
|
|
521
|
+
boundary: "create-airjam.dev"
|
|
522
|
+
});
|
|
523
|
+
return {
|
|
524
|
+
secure: hasFlag(argv, "--secure"),
|
|
525
|
+
secureMode: resolveRequestedSecureMode({ argv, env: runtimeEnv }),
|
|
526
|
+
previewManaged: hasFlag(argv, "--preview-managed"),
|
|
527
|
+
webOnly: hasFlag(argv, "--web-only"),
|
|
528
|
+
serverOnly: hasFlag(argv, "--server-only"),
|
|
529
|
+
allowExistingGame: hasFlag(argv, "--allow-existing-game"),
|
|
530
|
+
port: runtimeEnv.VITE_PORT ?? DEFAULT_GAME_PORT
|
|
531
|
+
};
|
|
532
|
+
};
|
|
533
|
+
var getSecurePaths = (cwd) => {
|
|
534
|
+
const rootDir = cwd;
|
|
535
|
+
const airJamDir = path.join(rootDir, ".airjam");
|
|
536
|
+
const certDir = path.join(airJamDir, "certs");
|
|
537
|
+
return {
|
|
538
|
+
rootDir,
|
|
539
|
+
airJamDir,
|
|
540
|
+
certDir,
|
|
541
|
+
secureDevStateFile: path.join(airJamDir, "secure-dev.json"),
|
|
542
|
+
certFile: path.join(certDir, "local-dev.pem"),
|
|
543
|
+
keyFile: path.join(certDir, "local-dev-key.pem"),
|
|
544
|
+
cloudflaredDir: path.join(rootDir, ".cloudflared"),
|
|
545
|
+
cloudflaredConfigFile: path.join(rootDir, ".cloudflared", "config.yml")
|
|
546
|
+
};
|
|
547
|
+
};
|
|
548
|
+
var run = (command, args, options = {}) => execFileSync2(command, args, {
|
|
549
|
+
encoding: "utf8",
|
|
550
|
+
stdio: options.silent ? ["ignore", "pipe", "pipe"] : "inherit",
|
|
551
|
+
cwd: options.cwd,
|
|
552
|
+
env: options.env ?? process.env
|
|
553
|
+
});
|
|
554
|
+
var buildLocalCertificateHosts = (lanIp) => {
|
|
555
|
+
const hosts = ["localhost", "127.0.0.1", "::1"];
|
|
556
|
+
if (lanIp) {
|
|
557
|
+
hosts.push(lanIp);
|
|
558
|
+
}
|
|
559
|
+
return hosts;
|
|
560
|
+
};
|
|
561
|
+
var resolveSecurePublicHost = ({ mode, port, lanIp, tunnelHost }) => {
|
|
562
|
+
if (mode === SECURE_MODE_TUNNEL) {
|
|
563
|
+
return tunnelHost;
|
|
564
|
+
}
|
|
565
|
+
const host = lanIp ?? "localhost";
|
|
566
|
+
return `https://${host}:${port}`;
|
|
567
|
+
};
|
|
568
|
+
var resolveSecureLoopbackHost = (port) => `https://127.0.0.1:${port}`;
|
|
569
|
+
var resolveSecurePlatformHost = ({
|
|
570
|
+
mode,
|
|
571
|
+
lanIp,
|
|
572
|
+
tunnelHost,
|
|
573
|
+
port = DEFAULT_PLATFORM_PORT
|
|
574
|
+
}) => {
|
|
575
|
+
if (mode === SECURE_MODE_TUNNEL) {
|
|
576
|
+
return tunnelHost;
|
|
577
|
+
}
|
|
578
|
+
const host = lanIp ?? "localhost";
|
|
579
|
+
return `https://${host}:${port}`;
|
|
580
|
+
};
|
|
581
|
+
var readSecureDevState = (filePath) => {
|
|
582
|
+
if (!fs3.existsSync(filePath)) {
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
585
|
+
return JSON.parse(fs3.readFileSync(filePath, "utf8"));
|
|
586
|
+
};
|
|
587
|
+
var writeSecureDevState = (filePath, state) => {
|
|
588
|
+
fs3.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
589
|
+
fs3.writeFileSync(filePath, JSON.stringify(state, null, 2), "utf8");
|
|
590
|
+
};
|
|
591
|
+
var ensureMkcertInstalled = () => {
|
|
592
|
+
if (!commandExists("mkcert", ["-help"])) {
|
|
593
|
+
throw new Error(
|
|
594
|
+
[
|
|
595
|
+
"mkcert is required for local secure dev.",
|
|
596
|
+
"Install it once, then rerun `airjam secure:init`.",
|
|
597
|
+
"macOS: brew install mkcert",
|
|
598
|
+
"Windows: winget install FiloSottile.mkcert or choco install mkcert",
|
|
599
|
+
"Linux: install mkcert from your package manager or https://github.com/FiloSottile/mkcert"
|
|
600
|
+
].join("\n")
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
var ensureCloudflaredInstalled = () => {
|
|
605
|
+
if (!commandExists("cloudflared")) {
|
|
606
|
+
throw new Error(
|
|
607
|
+
[
|
|
608
|
+
"cloudflared is required for tunnel secure mode.",
|
|
609
|
+
"Install it once, then rerun `airjam secure:init --mode=tunnel ...`."
|
|
610
|
+
].join("\n")
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
var ensureCloudflareLogin = (env = process.env) => {
|
|
615
|
+
const certPath = path.join(env.HOME || "", ".cloudflared", "cert.pem");
|
|
616
|
+
if (!fs3.existsSync(certPath)) {
|
|
617
|
+
throw new Error(
|
|
618
|
+
"Cloudflare login not found. Run: cloudflared tunnel login"
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
var ensureLocalCertificate = ({
|
|
623
|
+
cwd,
|
|
624
|
+
certFile,
|
|
625
|
+
keyFile,
|
|
626
|
+
lanIp,
|
|
627
|
+
env,
|
|
628
|
+
runtimeEnv
|
|
629
|
+
}) => {
|
|
630
|
+
ensureMkcertInstalled();
|
|
631
|
+
fs3.mkdirSync(path.dirname(certFile), { recursive: true });
|
|
632
|
+
const trustStores = runtimeEnv.AIR_JAM_MKCERT_TRUST_STORES || "system,nss";
|
|
633
|
+
const mkcertEnv = {
|
|
634
|
+
...env,
|
|
635
|
+
TRUST_STORES: trustStores
|
|
636
|
+
};
|
|
637
|
+
run("mkcert", ["-install"], {
|
|
638
|
+
cwd,
|
|
639
|
+
env: mkcertEnv
|
|
640
|
+
});
|
|
641
|
+
run(
|
|
642
|
+
"mkcert",
|
|
643
|
+
[
|
|
644
|
+
"-cert-file",
|
|
645
|
+
certFile,
|
|
646
|
+
"-key-file",
|
|
647
|
+
keyFile,
|
|
648
|
+
...buildLocalCertificateHosts(lanIp)
|
|
649
|
+
],
|
|
650
|
+
{ cwd, env: mkcertEnv }
|
|
651
|
+
);
|
|
652
|
+
};
|
|
653
|
+
var configureCloudflareTunnel = ({
|
|
654
|
+
cwd,
|
|
655
|
+
cloudflaredConfigFile,
|
|
656
|
+
hostname,
|
|
657
|
+
tunnel,
|
|
658
|
+
gamePort,
|
|
659
|
+
env
|
|
660
|
+
}) => {
|
|
661
|
+
ensureCloudflaredInstalled();
|
|
662
|
+
ensureCloudflareLogin(env);
|
|
663
|
+
let tunnelExists = false;
|
|
664
|
+
try {
|
|
665
|
+
run("cloudflared", ["tunnel", "info", tunnel], { cwd, silent: true });
|
|
666
|
+
tunnelExists = true;
|
|
667
|
+
} catch {
|
|
668
|
+
tunnelExists = false;
|
|
669
|
+
}
|
|
670
|
+
if (!tunnelExists) {
|
|
671
|
+
console.log(`Creating tunnel ${tunnel}...`);
|
|
672
|
+
run("cloudflared", ["tunnel", "create", tunnel], { cwd });
|
|
673
|
+
} else {
|
|
674
|
+
console.log(`Tunnel ${tunnel} already exists, reusing it.`);
|
|
675
|
+
}
|
|
676
|
+
console.log(`Routing DNS ${hostname} -> ${tunnel}...`);
|
|
677
|
+
run("cloudflared", ["tunnel", "route", "dns", tunnel, hostname], { cwd });
|
|
678
|
+
const tunnelInfoRaw = run("cloudflared", ["tunnel", "info", tunnel], {
|
|
679
|
+
cwd,
|
|
680
|
+
silent: true
|
|
681
|
+
});
|
|
682
|
+
const idMatch = tunnelInfoRaw.match(/[0-9a-f-]{36}/i);
|
|
683
|
+
if (!idMatch) {
|
|
684
|
+
throw new Error(
|
|
685
|
+
"Could not resolve tunnel UUID from `cloudflared tunnel info`."
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
const tunnelId = idMatch[0];
|
|
689
|
+
const credentialsFile = path.join(
|
|
690
|
+
env.HOME || "",
|
|
691
|
+
".cloudflared",
|
|
692
|
+
`${tunnelId}.json`
|
|
693
|
+
);
|
|
694
|
+
fs3.mkdirSync(path.dirname(cloudflaredConfigFile), { recursive: true });
|
|
695
|
+
fs3.writeFileSync(
|
|
696
|
+
cloudflaredConfigFile,
|
|
697
|
+
[
|
|
698
|
+
`tunnel: ${tunnel}`,
|
|
699
|
+
`credentials-file: ${credentialsFile}`,
|
|
700
|
+
"",
|
|
701
|
+
"ingress:",
|
|
702
|
+
` - hostname: ${hostname}`,
|
|
703
|
+
` service: https://127.0.0.1:${gamePort}`,
|
|
704
|
+
" originRequest:",
|
|
705
|
+
" noTLSVerify: true",
|
|
706
|
+
" - service: http_status:404",
|
|
707
|
+
""
|
|
708
|
+
].join("\n"),
|
|
709
|
+
"utf8"
|
|
710
|
+
);
|
|
711
|
+
};
|
|
712
|
+
var initializeSecureDev = ({
|
|
713
|
+
cwd,
|
|
714
|
+
envFilePath,
|
|
715
|
+
mode,
|
|
716
|
+
hostname,
|
|
717
|
+
tunnel,
|
|
718
|
+
env = process.env,
|
|
719
|
+
runtimeEnv = loadCreateAirJamRuntimeEnv({
|
|
720
|
+
env,
|
|
721
|
+
boundary: "create-airjam.secure-init"
|
|
722
|
+
}),
|
|
723
|
+
gamePort = DEFAULT_GAME_PORT,
|
|
724
|
+
nextStepMessage = "pnpm run dev -- --secure"
|
|
725
|
+
} = {}) => {
|
|
726
|
+
const paths = getSecurePaths(cwd);
|
|
727
|
+
const lanIp = detectLocalIpv4();
|
|
728
|
+
const tunnelHost = hostname ? `https://${hostname}` : null;
|
|
729
|
+
ensureLocalCertificate({
|
|
730
|
+
cwd,
|
|
731
|
+
certFile: paths.certFile,
|
|
732
|
+
keyFile: paths.keyFile,
|
|
733
|
+
lanIp,
|
|
734
|
+
env,
|
|
735
|
+
runtimeEnv
|
|
736
|
+
});
|
|
737
|
+
if (mode === SECURE_MODE_TUNNEL) {
|
|
738
|
+
if (!hostname || !tunnel) {
|
|
739
|
+
throw new Error(
|
|
740
|
+
"Tunnel mode requires both --hostname <dev.example.com> and --tunnel <tunnel-name>."
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
configureCloudflareTunnel({
|
|
744
|
+
cwd,
|
|
745
|
+
cloudflaredConfigFile: paths.cloudflaredConfigFile,
|
|
746
|
+
hostname,
|
|
747
|
+
tunnel,
|
|
748
|
+
gamePort,
|
|
749
|
+
env
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
const nextState = {
|
|
753
|
+
version: SECURE_DEV_VERSION,
|
|
754
|
+
mode,
|
|
755
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
756
|
+
lanIp,
|
|
757
|
+
certFile: paths.certFile,
|
|
758
|
+
keyFile: paths.keyFile,
|
|
759
|
+
hosts: buildLocalCertificateHosts(lanIp),
|
|
760
|
+
publicHost: resolveSecurePublicHost({
|
|
761
|
+
mode,
|
|
762
|
+
port: gamePort,
|
|
763
|
+
lanIp,
|
|
764
|
+
tunnelHost
|
|
765
|
+
}),
|
|
766
|
+
tunnelHost,
|
|
767
|
+
tunnelName: tunnel || null
|
|
768
|
+
};
|
|
769
|
+
writeSecureDevState(paths.secureDevStateFile, nextState);
|
|
770
|
+
upsertEnv(envFilePath, "AIR_JAM_SECURE_MODE", mode);
|
|
771
|
+
if (mode === SECURE_MODE_TUNNEL) {
|
|
772
|
+
upsertEnv(envFilePath, "AIR_JAM_SECURE_PUBLIC_HOST", nextState.publicHost);
|
|
773
|
+
upsertEnv(envFilePath, "CLOUDFLARE_TUNNEL_NAME", tunnel);
|
|
774
|
+
}
|
|
775
|
+
console.log("\nSecure dev setup complete.");
|
|
776
|
+
console.log(`Mode: ${mode}`);
|
|
777
|
+
console.log(`Public host: ${nextState.publicHost}`);
|
|
778
|
+
console.log(`Certificate: ${paths.certFile}`);
|
|
779
|
+
if (!lanIp) {
|
|
780
|
+
console.log(
|
|
781
|
+
"No LAN IPv4 address was detected. Secure dev will work on localhost, but phone-on-LAN testing is not configured."
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
if (mode === SECURE_MODE_TUNNEL) {
|
|
785
|
+
console.log(`Tunnel: ${tunnel}`);
|
|
786
|
+
}
|
|
787
|
+
console.log(`Next: ${nextStepMessage}`);
|
|
788
|
+
return nextState;
|
|
789
|
+
};
|
|
790
|
+
var loadSecureDevState = ({
|
|
791
|
+
cwd,
|
|
792
|
+
mode,
|
|
793
|
+
env = process.env,
|
|
794
|
+
gamePort = DEFAULT_GAME_PORT
|
|
795
|
+
} = {}) => {
|
|
796
|
+
const runtimeEnv = loadCreateAirJamRuntimeEnv({
|
|
797
|
+
env,
|
|
798
|
+
boundary: "create-airjam.secure-state"
|
|
799
|
+
});
|
|
800
|
+
const paths = getSecurePaths(cwd);
|
|
801
|
+
const state = readSecureDevState(paths.secureDevStateFile);
|
|
802
|
+
if (!state) {
|
|
803
|
+
throw new Error(
|
|
804
|
+
"Missing .airjam/secure-dev.json. Run `airjam secure:init` first."
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
if (!fs3.existsSync(state.certFile ?? "") || !fs3.existsSync(state.keyFile ?? "")) {
|
|
808
|
+
throw new Error(
|
|
809
|
+
"Missing local HTTPS certificate files. Run `pnpm secure:init` again."
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
if (mode === SECURE_MODE_LOCAL) {
|
|
813
|
+
const currentLanIp = detectLocalIpv4();
|
|
814
|
+
if ((state.lanIp ?? null) !== (currentLanIp ?? null)) {
|
|
815
|
+
throw new Error(
|
|
816
|
+
"Your LAN IPv4 address changed since secure setup was created. Run `airjam secure:init` again."
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
const publicHost = resolveSecurePublicHost({
|
|
821
|
+
mode,
|
|
822
|
+
port: gamePort,
|
|
823
|
+
lanIp: state.lanIp ?? null,
|
|
824
|
+
tunnelHost: runtimeEnv.AIR_JAM_SECURE_PUBLIC_HOST || state.tunnelHost || null
|
|
825
|
+
});
|
|
826
|
+
const tunnelName = runtimeEnv.CLOUDFLARE_TUNNEL_NAME || state.tunnelName || null;
|
|
827
|
+
if (mode === SECURE_MODE_TUNNEL && !tunnelName) {
|
|
828
|
+
throw new Error(
|
|
829
|
+
"Missing CLOUDFLARE_TUNNEL_NAME for tunnel secure mode. Run `airjam secure:init --mode=tunnel ...` again."
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
return {
|
|
833
|
+
...state,
|
|
834
|
+
mode,
|
|
835
|
+
publicHost,
|
|
836
|
+
tunnelName,
|
|
837
|
+
certFile: state.certFile,
|
|
838
|
+
keyFile: state.keyFile,
|
|
839
|
+
loopbackHost: resolveSecureLoopbackHost(gamePort),
|
|
840
|
+
platformHost: resolveSecurePlatformHost({
|
|
841
|
+
mode,
|
|
842
|
+
lanIp: state.lanIp ?? null,
|
|
843
|
+
tunnelHost: runtimeEnv.AIR_JAM_SECURE_PUBLIC_HOST || state.tunnelHost || null,
|
|
844
|
+
port: DEFAULT_PLATFORM_PORT
|
|
845
|
+
})
|
|
846
|
+
};
|
|
847
|
+
};
|
|
848
|
+
var buildSecureGameEnv = ({
|
|
849
|
+
secureState,
|
|
850
|
+
webOnly,
|
|
851
|
+
env = process.env,
|
|
852
|
+
backendOrigin
|
|
853
|
+
} = {}) => {
|
|
854
|
+
return {
|
|
855
|
+
VITE_AIR_JAM_RUNTIME_TOPOLOGY: serializeResolvedTopology(
|
|
856
|
+
buildStandaloneGameTopology({
|
|
857
|
+
surfaceRole: "host",
|
|
858
|
+
publicHost: secureState.publicHost,
|
|
859
|
+
backendOrigin,
|
|
860
|
+
secureTransport: true
|
|
861
|
+
})
|
|
862
|
+
),
|
|
863
|
+
AIR_JAM_SECURE_MODE: secureState.mode,
|
|
864
|
+
AIR_JAM_SECURE_PUBLIC_HOST: secureState.publicHost,
|
|
865
|
+
AIR_JAM_DEV_CERT_FILE: secureState.certFile,
|
|
866
|
+
AIR_JAM_DEV_KEY_FILE: secureState.keyFile,
|
|
867
|
+
AIR_JAM_DEV_PROXY_BACKEND_URL: backendOrigin,
|
|
868
|
+
VITE_AIR_JAM_PUBLIC_HOST: secureState.publicHost,
|
|
869
|
+
...webOnly && env.VITE_AIR_JAM_SERVER_URL ? { VITE_AIR_JAM_SERVER_URL: env.VITE_AIR_JAM_SERVER_URL } : {}
|
|
870
|
+
};
|
|
871
|
+
};
|
|
872
|
+
var runSecureInitCli = async ({
|
|
873
|
+
cwd = process.cwd(),
|
|
874
|
+
argv = process.argv.slice(2),
|
|
875
|
+
env = process.env,
|
|
876
|
+
nextStepMessage = "pnpm run dev -- --secure"
|
|
877
|
+
} = {}) => {
|
|
878
|
+
if (hasFlag(argv, "--help") || hasFlag(argv, "-h")) {
|
|
879
|
+
console.log(
|
|
880
|
+
"Usage: airjam secure:init [--mode=local|tunnel] [--hostname <dev.example.com>] [--tunnel <tunnel-name>]"
|
|
881
|
+
);
|
|
882
|
+
console.log("");
|
|
883
|
+
console.log("Modes:");
|
|
884
|
+
console.log(
|
|
885
|
+
" local Generate trusted local HTTPS certs with mkcert (default)"
|
|
886
|
+
);
|
|
887
|
+
console.log(
|
|
888
|
+
" tunnel Generate local HTTPS certs and configure the optional Cloudflare tunnel fallback"
|
|
889
|
+
);
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
loadEnvFile(path.join(cwd, ".env"), env);
|
|
893
|
+
loadEnvFile(path.join(cwd, ".env.local"), env);
|
|
894
|
+
const runtimeEnv = loadCreateAirJamRuntimeEnv({
|
|
895
|
+
env,
|
|
896
|
+
boundary: "create-airjam.secure-init"
|
|
897
|
+
});
|
|
898
|
+
const args = parseSecureInitArgs(argv, runtimeEnv);
|
|
899
|
+
initializeSecureDev({
|
|
900
|
+
cwd,
|
|
901
|
+
envFilePath: path.join(cwd, ".env.local"),
|
|
902
|
+
mode: args.mode,
|
|
903
|
+
hostname: args.hostname,
|
|
904
|
+
tunnel: args.tunnel,
|
|
905
|
+
env,
|
|
906
|
+
runtimeEnv,
|
|
907
|
+
gamePort: runtimeEnv.VITE_PORT ?? DEFAULT_GAME_PORT,
|
|
908
|
+
nextStepMessage
|
|
909
|
+
});
|
|
910
|
+
};
|
|
911
|
+
|
|
912
|
+
export {
|
|
913
|
+
isPortOpen,
|
|
914
|
+
waitForPort,
|
|
915
|
+
loadEnvFile,
|
|
916
|
+
detectLocalIpv4,
|
|
917
|
+
getFlagValue,
|
|
918
|
+
hasFlag,
|
|
919
|
+
createProcessGroup,
|
|
920
|
+
resolveLocalBackendOrigin,
|
|
921
|
+
buildStandaloneGameTopology,
|
|
922
|
+
buildPlatformShellTopology,
|
|
923
|
+
buildEmbeddedGameTopology,
|
|
924
|
+
serializeResolvedTopology,
|
|
925
|
+
isEnvValidationError,
|
|
926
|
+
formatEnvValidationError,
|
|
927
|
+
loadCreateAirJamRuntimeEnv,
|
|
928
|
+
SECURE_MODE_LOCAL,
|
|
929
|
+
SECURE_MODE_TUNNEL,
|
|
930
|
+
DEFAULT_GAME_PORT,
|
|
931
|
+
DEFAULT_PLATFORM_PORT,
|
|
932
|
+
resolveRequestedSecureMode,
|
|
933
|
+
parseGameDevArgs,
|
|
934
|
+
loadSecureDevState,
|
|
935
|
+
buildSecureGameEnv,
|
|
936
|
+
runSecureInitCli
|
|
937
|
+
};
|
|
938
|
+
//# sourceMappingURL=chunk-A4V2N4LX.js.map
|