@air-jam/cli 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 +273 -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/auth-profile.d.ts +5 -0
- package/dist/auth-profile.js +7 -0
- package/dist/auth-profile.js.map +1 -0
- package/dist/auth-sessions.d.ts +5 -0
- package/dist/auth-sessions.js +7 -0
- package/dist/auth-sessions.js.map +1 -0
- package/dist/chunk-7D4AYBAV.js +64 -0
- package/dist/chunk-7D4AYBAV.js.map +1 -0
- package/dist/chunk-J5MAU4QZ.js +102 -0
- package/dist/chunk-J5MAU4QZ.js.map +1 -0
- package/dist/chunk-LH7UO57C.js +23 -0
- package/dist/chunk-LH7UO57C.js.map +1 -0
- package/dist/chunk-N7AI7HZK.js +529 -0
- package/dist/chunk-N7AI7HZK.js.map +1 -0
- package/dist/chunk-PKTLVQXZ.js +82 -0
- package/dist/chunk-PKTLVQXZ.js.map +1 -0
- package/dist/chunk-SQE4NPZP.js +31 -0
- package/dist/chunk-SQE4NPZP.js.map +1 -0
- package/dist/chunk-U6V3HEBB.js +939 -0
- package/dist/chunk-U6V3HEBB.js.map +1 -0
- package/dist/chunk-VEHNFPEO.js +224 -0
- package/dist/chunk-VEHNFPEO.js.map +1 -0
- package/dist/development.d.ts +102 -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/game-analytics.d.ts +5 -0
- package/dist/game-analytics.js +7 -0
- package/dist/game-analytics.js.map +1 -0
- package/dist/game-app-id.d.ts +5 -0
- package/dist/game-app-id.js +7 -0
- package/dist/game-app-id.js.map +1 -0
- package/dist/game-media.d.ts +5 -0
- package/dist/game-media.js +7 -0
- package/dist/game-media.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2468 -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 +82 -3
- package/runtime/local-network.d.mts +6 -0
- package/runtime/local-network.mjs +9 -0
- package/runtime/public-assets.mjs +62 -0
- package/runtime/source-fence.mjs +182 -0
- package/runtime/vite-config.d.mts +43 -0
- package/runtime/vite-config.mjs +134 -0
- package/runtime/vite-dev.mjs +18 -0
- package/runtime/vite-https.d.mts +11 -0
- package/runtime/vite-https.mjs +40 -0
- package/template-assets/bootstrap/.claude/launch.json +12 -0
- package/template-assets/bootstrap/AGENTS.md +290 -0
- package/template-assets/bootstrap/CLAUDE.md +55 -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 +100 -0
- package/template-assets/bootstrap/skills/canvas-2d-gameplay/SKILL.md +47 -0
- package/template-assets/bootstrap/skills/controller-ui/SKILL.md +71 -0
- package/template-assets/bootstrap/skills/debug-and-test/SKILL.md +72 -0
- package/template-assets/bootstrap/skills/game-architecture/SKILL.md +102 -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 +58 -0
- package/template-assets/bootstrap/skills/r3f-3d-scene/SKILL.md +61 -0
- package/template-assets/documentation/for-agents/controller-ui/page.mdx +99 -0
- package/template-assets/documentation/for-agents/page.mdx +120 -0
- package/template-assets/documentation/for-agents/project-structure/page.mdx +170 -0
- package/template-assets/documentation/for-agents/state-and-rendering/page.mdx +77 -0
- package/template-assets/documentation/for-agents/supported-agents/page.mdx +18 -0
- package/template-assets/documentation/getting-started/debugging/page.mdx +164 -0
- package/template-assets/documentation/getting-started/dev-logs/page.mdx +169 -0
- package/template-assets/documentation/getting-started/game-ideas/page.mdx +114 -0
- package/template-assets/documentation/getting-started/introduction/page.mdx +200 -0
- package/template-assets/documentation/getting-started/migrating-legacy-games/page.mdx +673 -0
- package/template-assets/documentation/getting-started/quick-start/page.mdx +310 -0
- package/template-assets/documentation/how-it-works/architecture/page.mdx +230 -0
- package/template-assets/documentation/how-it-works/host-system/page.mdx +270 -0
- package/template-assets/documentation/manifest.json +500 -0
- package/template-assets/documentation/sdk/assets-and-theme/page.mdx +185 -0
- package/template-assets/documentation/sdk/hooks/page.mdx +435 -0
- package/template-assets/documentation/sdk/input-system/page.mdx +240 -0
- package/template-assets/documentation/sdk/networked-state/page.mdx +295 -0
- package/template-assets/documentation/sdk/settings/page.mdx +155 -0
- package/template-assets/documentation/sdk/ui-components/page.mdx +268 -0
- package/template-assets/managed/.airjam/ai-pack.json +209 -0
- package/template-assets/managed/docs/airjam/agent-gold-path.md +115 -0
- package/template-assets/managed/docs/airjam/agent-mcp.md +179 -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 +104 -0
- package/template-assets/managed/docs/airjam/development-loop.md +51 -0
- package/template-assets/managed/docs/airjam/docs-index.md +64 -0
- package/template-assets/managed/docs/airjam/generated/architecture.md +223 -0
- package/template-assets/managed/docs/airjam/generated/assets-and-theme.md +188 -0
- package/template-assets/managed/docs/airjam/generated/controller-ui.md +102 -0
- package/template-assets/managed/docs/airjam/generated/debugging-and-logs.md +165 -0
- package/template-assets/managed/docs/airjam/generated/for-agents.md +123 -0
- package/template-assets/managed/docs/airjam/generated/game-ideas.md +107 -0
- package/template-assets/managed/docs/airjam/generated/host-system.md +261 -0
- package/template-assets/managed/docs/airjam/generated/input-system.md +241 -0
- package/template-assets/managed/docs/airjam/generated/introduction.md +195 -0
- package/template-assets/managed/docs/airjam/generated/migrating-legacy-games.md +674 -0
- package/template-assets/managed/docs/airjam/generated/networked-state.md +298 -0
- package/template-assets/managed/docs/airjam/generated/project-structure.md +171 -0
- package/template-assets/managed/docs/airjam/generated/quick-start.md +311 -0
- package/template-assets/managed/docs/airjam/generated/sdk-hooks.md +430 -0
- package/template-assets/managed/docs/airjam/generated/settings.md +158 -0
- package/template-assets/managed/docs/airjam/generated/state-and-rendering.md +80 -0
- package/template-assets/managed/docs/airjam/generated/supported-agents.md +21 -0
- package/template-assets/managed/docs/airjam/generated/ui-components.md +265 -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 +212 -0
- package/template-assets/managed/docs/airjam/preview-controllers.md +129 -0
- package/template-assets/managed/docs/airjam/r3f-3d-scene.md +163 -0
- package/template-assets/managed/docs/airjam/state-lanes-cookbook.md +101 -0
- package/template-assets/managed/docs/airjam/visual-system.md +103 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
3
|
+
import sirv from "sirv";
|
|
4
|
+
|
|
5
|
+
function contains(directory, file) {
|
|
6
|
+
const path = relative(directory, file);
|
|
7
|
+
return path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function publicAssetFallback(server) {
|
|
11
|
+
const { publicDir, base } = server.config;
|
|
12
|
+
if (!publicDir) return (_request, _response, next) => next();
|
|
13
|
+
const serve = sirv(publicDir, {
|
|
14
|
+
dev: true,
|
|
15
|
+
etag: true,
|
|
16
|
+
extensions: [],
|
|
17
|
+
setHeaders(response, path) {
|
|
18
|
+
if (/\.(?:[tj]sx?|[cm][tj]s)$/.test(path))
|
|
19
|
+
response.setHeader("Content-Type", "text/javascript");
|
|
20
|
+
for (const [name, value] of Object.entries(
|
|
21
|
+
server.config.server.headers ?? {},
|
|
22
|
+
))
|
|
23
|
+
response.setHeader(name, value);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
return (request, response, next) => {
|
|
27
|
+
if (!["GET", "HEAD"].includes(request.method)) return next();
|
|
28
|
+
// Vite's HTML fallback rewrites url before configureServer's post hook.
|
|
29
|
+
const original = request.originalUrl;
|
|
30
|
+
if (!original?.startsWith(base)) return next();
|
|
31
|
+
const url = `/${original.slice(base.length)}`;
|
|
32
|
+
const [encodedPath, query] = url.split("?");
|
|
33
|
+
const parameters = new URLSearchParams(query);
|
|
34
|
+
if (["import", "raw", "url"].some((name) => parameters.has(name)))
|
|
35
|
+
return next();
|
|
36
|
+
let path;
|
|
37
|
+
try {
|
|
38
|
+
path = decodeURI(encodedPath);
|
|
39
|
+
} catch {
|
|
40
|
+
return next();
|
|
41
|
+
}
|
|
42
|
+
if (path.includes("\0")) return next();
|
|
43
|
+
const file = resolve(publicDir, `.${path}`);
|
|
44
|
+
if (!contains(publicDir, file)) return next();
|
|
45
|
+
try {
|
|
46
|
+
if (
|
|
47
|
+
!contains(realpathSync(publicDir), realpathSync(file)) ||
|
|
48
|
+
!statSync(file).isFile()
|
|
49
|
+
)
|
|
50
|
+
return next();
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (["ENOENT", "ENOTDIR"].includes(error.code)) return next();
|
|
53
|
+
return next(error);
|
|
54
|
+
}
|
|
55
|
+
const previous = request.url;
|
|
56
|
+
request.url = url;
|
|
57
|
+
serve(request, response, (error) => {
|
|
58
|
+
request.url = previous;
|
|
59
|
+
next(error);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { publicAssetFallback } from "./public-assets.mjs";
|
|
6
|
+
|
|
7
|
+
function read(path) {
|
|
8
|
+
try {
|
|
9
|
+
return readFileSync(path);
|
|
10
|
+
} catch (error) {
|
|
11
|
+
if (error.code === "ENOENT") return null;
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Replay final watcher events for Vite's caches, but batch their browser delivery.
|
|
17
|
+
export function sourceFencePlugin() {
|
|
18
|
+
const replay = new AsyncLocalStorage();
|
|
19
|
+
return {
|
|
20
|
+
name: "airjam-source-fence",
|
|
21
|
+
apply: "serve",
|
|
22
|
+
hotUpdate: {
|
|
23
|
+
order: "post",
|
|
24
|
+
handler() {
|
|
25
|
+
// Public-file registration and module bookkeeping precede this hook.
|
|
26
|
+
replay.getStore()?.resolve();
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
configureServer(server) {
|
|
30
|
+
const marker = resolve(
|
|
31
|
+
server.config.root,
|
|
32
|
+
".airjam/devtools/source-change.json",
|
|
33
|
+
);
|
|
34
|
+
const watcher = server.watcher;
|
|
35
|
+
const emit = watcher.emit;
|
|
36
|
+
const expected = new Map();
|
|
37
|
+
const queued = new Map();
|
|
38
|
+
const waiting = new Set();
|
|
39
|
+
const restore = [];
|
|
40
|
+
let seen;
|
|
41
|
+
let held = false;
|
|
42
|
+
let settling = false;
|
|
43
|
+
for (const channel of new Set([
|
|
44
|
+
server.ws,
|
|
45
|
+
...Object.values(server.environments).map(
|
|
46
|
+
(environment) => environment.hot,
|
|
47
|
+
),
|
|
48
|
+
])) {
|
|
49
|
+
const send = channel.send;
|
|
50
|
+
channel.send = function (message, ...argumentsList) {
|
|
51
|
+
const context = replay.getStore();
|
|
52
|
+
if (context) {
|
|
53
|
+
if (message.type === "error")
|
|
54
|
+
context.reject(new Error(message.err.message));
|
|
55
|
+
if (
|
|
56
|
+
["update", "full-reload", "prune", "error"].includes(message.type)
|
|
57
|
+
)
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
return send.call(this, message, ...argumentsList);
|
|
61
|
+
};
|
|
62
|
+
restore.push(() => {
|
|
63
|
+
channel.send = send;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function dispatch(event, argumentsList) {
|
|
67
|
+
return new Promise((resolvePromise, reject) => {
|
|
68
|
+
replay.run({ resolve: resolvePromise, reject }, () =>
|
|
69
|
+
emit.call(watcher, event, ...argumentsList),
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async function settle(state) {
|
|
74
|
+
const events = new Map(queued);
|
|
75
|
+
queued.clear();
|
|
76
|
+
for (const file of state.files ?? []) {
|
|
77
|
+
const path = resolve(server.config.root, file.path);
|
|
78
|
+
expected.set(path, file.hash);
|
|
79
|
+
// Explicit final events also cover OS notifications arriving after release.
|
|
80
|
+
events.set(path, [file.event, [path]]);
|
|
81
|
+
}
|
|
82
|
+
if (state.phase !== "applying" && !state.committed) return;
|
|
83
|
+
if (server.config.server.hmr === false) {
|
|
84
|
+
await server.restart();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const configFiles = new Set([
|
|
88
|
+
server.config.configFile,
|
|
89
|
+
...server.config.configFileDependencies,
|
|
90
|
+
...(server.config.envDir === false
|
|
91
|
+
? []
|
|
92
|
+
: [
|
|
93
|
+
".env",
|
|
94
|
+
".env.local",
|
|
95
|
+
`.env.${server.config.mode}`,
|
|
96
|
+
`.env.${server.config.mode}.local`,
|
|
97
|
+
].map((name) => resolve(server.config.envDir, name))),
|
|
98
|
+
]);
|
|
99
|
+
let changedConfig;
|
|
100
|
+
const pending = [];
|
|
101
|
+
for (const [path, [event, argumentsList]] of events) {
|
|
102
|
+
if (configFiles.has(path)) changedConfig = path;
|
|
103
|
+
else pending.push(dispatch(event, argumentsList));
|
|
104
|
+
}
|
|
105
|
+
await Promise.all(pending);
|
|
106
|
+
if (changedConfig) {
|
|
107
|
+
// Let Vite reload its own config once, including plugin and env caches.
|
|
108
|
+
emit.call(watcher, "change", changedConfig);
|
|
109
|
+
} else {
|
|
110
|
+
for (const environment of Object.values(server.environments))
|
|
111
|
+
environment.moduleGraph.invalidateAll();
|
|
112
|
+
server.ws.send({ type: "full-reload", path: "*" });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function reconcile() {
|
|
116
|
+
const bytes = read(marker);
|
|
117
|
+
const state = bytes && JSON.parse(bytes.toString());
|
|
118
|
+
held = state?.phase === "applying" && state.expiresAt > Date.now();
|
|
119
|
+
if (held || settling) return;
|
|
120
|
+
if (state && state.id !== seen) {
|
|
121
|
+
seen = state.id;
|
|
122
|
+
settling = true;
|
|
123
|
+
return settle(state)
|
|
124
|
+
.catch((error) => {
|
|
125
|
+
server.ws.send({
|
|
126
|
+
type: "error",
|
|
127
|
+
err: { message: error.message, stack: error.stack },
|
|
128
|
+
});
|
|
129
|
+
})
|
|
130
|
+
.finally(() => {
|
|
131
|
+
settling = false;
|
|
132
|
+
reconcile();
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
for (const next of waiting) next();
|
|
136
|
+
waiting.clear();
|
|
137
|
+
}
|
|
138
|
+
// A settled marker from before this server started needs no reload.
|
|
139
|
+
const initial = read(marker);
|
|
140
|
+
if (initial) {
|
|
141
|
+
const state = JSON.parse(initial.toString());
|
|
142
|
+
if (state.phase === "settled") seen = state.id;
|
|
143
|
+
}
|
|
144
|
+
watcher.emit = function (event, ...argumentsList) {
|
|
145
|
+
if (["change", "add", "unlink"].includes(event)) {
|
|
146
|
+
reconcile();
|
|
147
|
+
const path = resolve(argumentsList[0]);
|
|
148
|
+
if (expected.has(path)) {
|
|
149
|
+
const content = read(path);
|
|
150
|
+
const hash =
|
|
151
|
+
content === null
|
|
152
|
+
? null
|
|
153
|
+
: createHash("sha256").update(content).digest("hex");
|
|
154
|
+
if (hash === expected.get(path)) return false;
|
|
155
|
+
expected.delete(path);
|
|
156
|
+
}
|
|
157
|
+
if (held) {
|
|
158
|
+
queued.set(path, [event, argumentsList]);
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return emit.call(this, event, ...argumentsList);
|
|
163
|
+
};
|
|
164
|
+
server.middlewares.use((_request, _response, next) => {
|
|
165
|
+
reconcile();
|
|
166
|
+
if (held || settling) waiting.add(next);
|
|
167
|
+
else next();
|
|
168
|
+
});
|
|
169
|
+
const timer = setInterval(reconcile, 25);
|
|
170
|
+
timer.unref();
|
|
171
|
+
const cleanup = () => {
|
|
172
|
+
clearInterval(timer);
|
|
173
|
+
watcher.emit = emit;
|
|
174
|
+
for (const reset of restore) reset();
|
|
175
|
+
for (const next of waiting) next();
|
|
176
|
+
waiting.clear();
|
|
177
|
+
};
|
|
178
|
+
server.httpServer?.once("close", cleanup);
|
|
179
|
+
return () => server.middlewares.use(publicAssetFallback(server));
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
getAirJamDevProxyOptions,
|
|
3
|
+
getAirJamHttpsServerOptions,
|
|
4
|
+
} from "./vite-https.mjs";
|
|
5
|
+
|
|
6
|
+
export type AirJamViteProfile = "default" | "three";
|
|
7
|
+
|
|
8
|
+
export interface CreateAirJamViteConfigOptions {
|
|
9
|
+
env?: NodeJS.ProcessEnv;
|
|
10
|
+
port?: number;
|
|
11
|
+
profile?: AirJamViteProfile;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export declare const AIR_JAM_IFRAME_HEADERS: {
|
|
15
|
+
"Content-Security-Policy": string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type AirJamViteServerConfig = {
|
|
19
|
+
host: string | true;
|
|
20
|
+
allowedHosts: true;
|
|
21
|
+
https: ReturnType<typeof getAirJamHttpsServerOptions>;
|
|
22
|
+
port: number;
|
|
23
|
+
strictPort: true;
|
|
24
|
+
headers: typeof AIR_JAM_IFRAME_HEADERS;
|
|
25
|
+
cors: true;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export declare function createAirJamViteConfig(
|
|
29
|
+
options?: CreateAirJamViteConfigOptions,
|
|
30
|
+
): {
|
|
31
|
+
base: string;
|
|
32
|
+
build: {
|
|
33
|
+
chunkSizeWarningLimit: number;
|
|
34
|
+
rollupOptions?: {
|
|
35
|
+
output: { manualChunks: (id: string) => string | undefined };
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
server: AirJamViteServerConfig & {
|
|
39
|
+
watch: { ignored: string[] };
|
|
40
|
+
proxy: ReturnType<typeof getAirJamDevProxyOptions>;
|
|
41
|
+
};
|
|
42
|
+
preview: AirJamViteServerConfig;
|
|
43
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAirJamDevProxyOptions,
|
|
3
|
+
getAirJamHttpsServerOptions,
|
|
4
|
+
} from "./vite-https.mjs";
|
|
5
|
+
|
|
6
|
+
export const AIR_JAM_IFRAME_HEADERS = {
|
|
7
|
+
// Air Jam games must be embeddable inside the local Arcade shell.
|
|
8
|
+
"Content-Security-Policy": "frame-ancestors *;",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const AIR_JAM_VITE_PROFILES = new Set(["default", "three"]);
|
|
12
|
+
const DEFAULT_CHUNK_WARNING_LIMIT_KB = 1000;
|
|
13
|
+
const THREE_PROFILE_CHUNK_WARNING_LIMIT_KB = 2500;
|
|
14
|
+
|
|
15
|
+
const resolveThreeProfileManualChunk = (id) => {
|
|
16
|
+
if (id.includes("/zod/") || id.includes("/packages/sdk/src/")) {
|
|
17
|
+
// Keep SDK runtime dependencies with the SDK chunk so schema evaluation
|
|
18
|
+
// cannot race a separate vendor chunk during embedded production startup.
|
|
19
|
+
return "airjam-sdk";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!id.includes("node_modules")) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (
|
|
27
|
+
id.includes("@dimforge/rapier3d-compat") ||
|
|
28
|
+
id.includes("@react-three/rapier")
|
|
29
|
+
) {
|
|
30
|
+
return "rapier-runtime";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (
|
|
34
|
+
id.includes("@react-three/drei") ||
|
|
35
|
+
id.includes("three-stdlib") ||
|
|
36
|
+
id.includes("@use-gesture") ||
|
|
37
|
+
id.includes("@react-spring")
|
|
38
|
+
) {
|
|
39
|
+
return "drei-runtime";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (id.includes("@react-three/fiber")) {
|
|
43
|
+
return "fiber-runtime";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (id.includes("/three/")) {
|
|
47
|
+
return "three-core";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (
|
|
51
|
+
id.includes("/react/") ||
|
|
52
|
+
id.includes("/react-dom/") ||
|
|
53
|
+
id.includes("react-router-dom")
|
|
54
|
+
) {
|
|
55
|
+
// Keep the core React/app runtime in one chunk for the three profile.
|
|
56
|
+
// Splitting React away from state/router/runtime helpers created a
|
|
57
|
+
// circular startup edge in built embeds.
|
|
58
|
+
return "app-runtime";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (
|
|
62
|
+
id.includes("/zustand/") ||
|
|
63
|
+
id.includes("/howler/") ||
|
|
64
|
+
id.includes("/qrcode/")
|
|
65
|
+
) {
|
|
66
|
+
return "app-runtime";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return undefined;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const resolveBuildConfig = (profile) => {
|
|
73
|
+
if (profile === "three") {
|
|
74
|
+
return {
|
|
75
|
+
chunkSizeWarningLimit: THREE_PROFILE_CHUNK_WARNING_LIMIT_KB,
|
|
76
|
+
rollupOptions: {
|
|
77
|
+
output: {
|
|
78
|
+
manualChunks: resolveThreeProfileManualChunk,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
chunkSizeWarningLimit: DEFAULT_CHUNK_WARNING_LIMIT_KB,
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const createSharedDevServerConfig = ({ env, port }) => ({
|
|
90
|
+
host: env.AIR_JAM_BIND_HOST?.trim() || true,
|
|
91
|
+
allowedHosts: true,
|
|
92
|
+
https: getAirJamHttpsServerOptions(env),
|
|
93
|
+
port,
|
|
94
|
+
strictPort: true,
|
|
95
|
+
headers: AIR_JAM_IFRAME_HEADERS,
|
|
96
|
+
cors: true,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const AIR_JAM_GENERATED_STATE_GLOB = "**/.airjam/**";
|
|
100
|
+
|
|
101
|
+
export const createAirJamViteConfig = ({
|
|
102
|
+
env = process.env,
|
|
103
|
+
port = Number(env.VITE_PORT || 5173),
|
|
104
|
+
profile = "default",
|
|
105
|
+
} = {}) => {
|
|
106
|
+
if (!AIR_JAM_VITE_PROFILES.has(profile)) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
`Unsupported Air Jam Vite profile "${profile}". Use "default" or "three".`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const build = resolveBuildConfig(profile);
|
|
113
|
+
const base = env.AIR_JAM_BUILD_BASE || "/";
|
|
114
|
+
if (!/^\/(?:[a-zA-Z0-9_-]+\/)*$/.test(base)) {
|
|
115
|
+
throw new Error("AIR_JAM_BUILD_BASE must be an absolute directory path.");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
base,
|
|
120
|
+
build,
|
|
121
|
+
server: {
|
|
122
|
+
...createSharedDevServerConfig({ env, port }),
|
|
123
|
+
watch: {
|
|
124
|
+
// Runtime logs, managed-process state, screenshots, and other generated
|
|
125
|
+
// Air Jam artifacts live here. Watching them creates a feedback loop:
|
|
126
|
+
// browser activity writes a log entry, Vite reloads the browser, and
|
|
127
|
+
// the reload writes another entry.
|
|
128
|
+
ignored: [AIR_JAM_GENERATED_STATE_GLOB],
|
|
129
|
+
},
|
|
130
|
+
proxy: getAirJamDevProxyOptions(env),
|
|
131
|
+
},
|
|
132
|
+
preview: createSharedDevServerConfig({ env, port }),
|
|
133
|
+
};
|
|
134
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { sourceFencePlugin } from "./source-fence.mjs";
|
|
5
|
+
|
|
6
|
+
// Resolve the game's Vite, keeping it an app dependency rather than a CLI copy.
|
|
7
|
+
const require = createRequire(resolve("package.json"));
|
|
8
|
+
const { createServer } = await import(
|
|
9
|
+
pathToFileURL(require.resolve("vite")).href
|
|
10
|
+
);
|
|
11
|
+
const host = process.env.AIR_JAM_BIND_HOST?.trim();
|
|
12
|
+
const server = await createServer({
|
|
13
|
+
plugins: [sourceFencePlugin()],
|
|
14
|
+
...(host ? { server: { host } } : {}),
|
|
15
|
+
});
|
|
16
|
+
await server.listen();
|
|
17
|
+
server.printUrls();
|
|
18
|
+
server.bindCLIShortcuts({ print: true });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const DEFAULT_AIR_JAM_DEV_BACKEND_URL: string;
|
|
2
|
+
|
|
3
|
+
export function getAirJamHttpsServerOptions(
|
|
4
|
+
env?: NodeJS.ProcessEnv,
|
|
5
|
+
): { cert: Buffer; key: Buffer } | undefined;
|
|
6
|
+
|
|
7
|
+
export function getAirJamDevBackendUrl(env?: NodeJS.ProcessEnv): string;
|
|
8
|
+
|
|
9
|
+
export function getAirJamDevProxyOptions(
|
|
10
|
+
env?: NodeJS.ProcessEnv,
|
|
11
|
+
): Record<string, { target: string; ws?: boolean; changeOrigin: boolean }>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { resolveLocalBackendOrigin } from "./local-network.mjs";
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_AIR_JAM_DEV_BACKEND_URL = resolveLocalBackendOrigin();
|
|
5
|
+
|
|
6
|
+
export const getAirJamHttpsServerOptions = (env = process.env) => {
|
|
7
|
+
const certFile = env.AIR_JAM_DEV_CERT_FILE;
|
|
8
|
+
const keyFile = env.AIR_JAM_DEV_KEY_FILE;
|
|
9
|
+
if (!certFile || !keyFile) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (!fs.existsSync(certFile) || !fs.existsSync(keyFile)) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
cert: fs.readFileSync(certFile),
|
|
19
|
+
key: fs.readFileSync(keyFile),
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getAirJamDevBackendUrl = (env = process.env) =>
|
|
24
|
+
env.AIR_JAM_DEV_PROXY_BACKEND_URL?.trim() || resolveLocalBackendOrigin(env);
|
|
25
|
+
|
|
26
|
+
export const getAirJamDevProxyOptions = (env = process.env) => {
|
|
27
|
+
const target = getAirJamDevBackendUrl(env);
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
"/v1": {
|
|
31
|
+
target,
|
|
32
|
+
ws: true,
|
|
33
|
+
changeOrigin: true,
|
|
34
|
+
},
|
|
35
|
+
"/__airjam": {
|
|
36
|
+
target,
|
|
37
|
+
changeOrigin: true,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
};
|