create-threenative 0.2.17 → 0.2.18
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/agent-docs/kit-mcp.md +1 -1
- package/agent-docs/kit-router.md +1 -1
- package/agent-docs/references/assertion-reference.md +54 -110
- package/agent-docs/references/capability-reference.md +580 -22
- package/agent-docs/references/conventions.md +28 -0
- package/agent-docs/references/performance-basics.md +8 -4
- package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +7 -4
- package/agent-files/.claude/hooks/discovery-gate.mjs +2 -2
- package/dist/index.d.ts +97 -6
- package/dist/index.js +769 -277
- package/dist/threenative.js +96 -17
- package/dist/web-engine-ccd-ik-solver.js +127 -0
- package/dist/web-engine-gltf-loader.js +52 -14
- package/dist/web-engine-post-effects.js +5 -10
- package/dist/web-engine-runtime.js +3648 -546
- package/package.json +8 -7
- package/template-assets/clearwater/README.md +1 -1
- package/template-assets/patches/manifest.json +18 -0
- package/template-assets/terrain/alpine/assets.json +12 -0
- package/template-assets/terrain/alpine/bake.mjs +6 -0
- package/template-assets/terrain/alpine/credits.json +164 -0
- package/template-assets/terrain/alpine/heightmap.r16 +0 -0
- package/template-assets/terrain/alpine/recipe.json +119 -0
- package/template-assets/terrain/alpine/surface.json +53 -0
- package/template-assets/terrain/coastal/assets.json +11 -0
- package/template-assets/terrain/coastal/bake.mjs +6 -0
- package/template-assets/terrain/coastal/credits.json +117 -0
- package/template-assets/terrain/coastal/heightmap.r16 +0 -0
- package/template-assets/terrain/coastal/recipe.json +113 -0
- package/template-assets/terrain/coastal/surface.json +41 -0
- package/template-assets/terrain/desert/assets.json +12 -0
- package/template-assets/terrain/desert/bake.mjs +6 -0
- package/template-assets/terrain/desert/credits.json +164 -0
- package/template-assets/terrain/desert/heightmap.r16 +0 -0
- package/template-assets/terrain/desert/recipe.json +108 -0
- package/template-assets/terrain/desert/surface.json +54 -0
- package/template-assets/terrain/forest/assets.json +65 -0
- package/template-assets/terrain/forest/bake.mjs +8 -0
- package/template-assets/terrain/forest/credits.json +225 -0
- package/template-assets/terrain/forest/heightmap.r16 +0 -0
- package/template-assets/terrain/forest/recipe.json +350 -0
- package/template-assets/terrain/forest/surface.json +79 -0
- package/template-assets/terrain/tundra/assets.json +12 -0
- package/template-assets/terrain/tundra/bake.mjs +6 -0
- package/template-assets/terrain/tundra/credits.json +164 -0
- package/template-assets/terrain/tundra/heightmap.r16 +0 -0
- package/template-assets/terrain/tundra/recipe.json +277 -0
- package/template-assets/terrain/tundra/surface.json +54 -0
- package/templates/action-rpg/AGENTS.md +8 -4
- package/templates/action-rpg/CLAUDE.md +8 -4
- package/templates/action-rpg/package.json +7 -7
- package/templates/action-rpg/src/game.ts +1 -1
- package/templates/action-rpg/src/render/atmosphere.ts +6 -0
- package/templates/action-rpg/src/render/backlightControls.ts +10 -0
- package/templates/action-rpg/src/render/backlightMaterial.ts +4 -4
- package/templates/action-rpg/src/render/clouds.ts +13 -0
- package/templates/action-rpg/src/render/materialLighting.ts +5 -5
- package/templates/action-rpg/src/render/quality.ts +7 -32
- package/templates/action-rpg/src/scenes/Play.ts +4 -1
- package/templates/action-rpg/src/style.css +4 -0
- package/templates/action-rpg/vite.config.ts +2 -0
- package/templates/adventure/AGENTS.md +7 -2
- package/templates/adventure/CLAUDE.md +7 -2
- package/templates/adventure/kit.json +5 -1
- package/templates/adventure/package.json +7 -7
- package/templates/adventure/src/game.ts +1 -1
- package/templates/adventure/src/style.css +4 -0
- package/templates/adventure/tsconfig.json +1 -1
- package/templates/adventure/vite.config.ts +2 -0
- package/templates/collectathon/AGENTS.md +7 -2
- package/templates/collectathon/CLAUDE.md +7 -2
- package/templates/collectathon/package.json +7 -7
- package/templates/collectathon/src/game.ts +1 -1
- package/templates/collectathon/src/level/Course.ts +55 -9
- package/templates/collectathon/src/level/terrain.ts +27 -6
- package/templates/collectathon/src/main.ts +1 -0
- package/templates/collectathon/src/render/foliage.ts +359 -98
- package/templates/collectathon/src/render/sky.ts +76 -12
- package/templates/collectathon/src/render/water.ts +32 -10
- package/templates/collectathon/src/scenes/Play.ts +18 -5
- package/templates/collectathon/src/style.css +4 -0
- package/templates/collectathon/tsconfig.json +1 -1
- package/templates/collectathon/vite.config.ts +2 -0
- package/templates/kart/AGENTS.md +7 -2
- package/templates/kart/CLAUDE.md +7 -2
- package/templates/kart/package.json +6 -6
- package/templates/kart/src/game.ts +1 -1
- package/templates/kart/src/main.ts +1 -0
- package/templates/kart/src/style.css +4 -0
- package/templates/kart/tsconfig.json +1 -1
- package/templates/kart/vite.config.ts +2 -0
- package/templates/minimal/AGENTS.md +8 -3
- package/templates/minimal/CLAUDE.md +8 -3
- package/templates/minimal/package.json +6 -6
- package/templates/minimal/playtests/stands-still.playtest.json +30 -0
- package/templates/minimal/src/game.ts +1 -1
- package/templates/minimal/src/render/atmosphere.ts +6 -0
- package/templates/minimal/src/render/backlightControls.ts +10 -0
- package/templates/minimal/src/render/backlightMaterial.ts +4 -4
- package/templates/minimal/src/render/camera.ts +13 -2
- package/templates/minimal/src/render/clouds.ts +13 -0
- package/templates/minimal/src/render/lighting.ts +4 -2
- package/templates/minimal/src/render/materialLighting.ts +5 -5
- package/templates/minimal/src/render/materials.ts +10 -0
- package/templates/minimal/src/render/quality.ts +7 -32
- package/templates/minimal/src/scenes/Play.ts +4 -1
- package/templates/minimal/vite.config.ts +7 -1
- package/templates/platformer/AGENTS.md +9 -4
- package/templates/platformer/CLAUDE.md +9 -4
- package/templates/platformer/index.html +1 -1
- package/templates/platformer/main.html +12 -0
- package/templates/platformer/package.json +7 -7
- package/templates/platformer/playtests/gamepad-idle.playtest.json +21 -0
- package/templates/platformer/playtests/gamepad.playtest.json +30 -0
- package/templates/platformer/src/entities/Fox.ts +21 -6
- package/templates/platformer/src/game.ts +1 -1
- package/templates/platformer/src/main.ts +1 -0
- package/templates/platformer/src/render/backlightControls.ts +10 -0
- package/templates/platformer/src/render/backlightMaterial.ts +4 -4
- package/templates/platformer/src/render/materialLighting.ts +5 -5
- package/templates/platformer/src/render/quality.ts +7 -32
- package/templates/platformer/src/scenes/Play.ts +2 -1
- package/templates/platformer/src/style.css +4 -0
- package/templates/platformer/src/worker-page.ts +29 -0
- package/templates/platformer/src/worker.ts +5 -0
- package/templates/platformer/tsconfig.json +1 -1
- package/templates/platformer/vite.config.ts +4 -0
- package/templates/puzzle/AGENTS.md +7 -2
- package/templates/puzzle/CLAUDE.md +7 -2
- package/templates/puzzle/package.json +7 -7
- package/templates/puzzle/src/game.ts +1 -1
- package/templates/puzzle/src/render/backlightControls.ts +10 -0
- package/templates/puzzle/src/render/backlightMaterial.ts +4 -4
- package/templates/puzzle/src/render/materialLighting.ts +5 -5
- package/templates/puzzle/src/render/quality.ts +7 -32
- package/templates/puzzle/src/scenes/Play.ts +1 -1
- package/templates/puzzle/src/style.css +4 -0
- package/templates/puzzle/tsconfig.json +1 -1
- package/templates/puzzle/vite.config.ts +2 -0
- package/templates/racing/AGENTS.md +7 -2
- package/templates/racing/CLAUDE.md +7 -2
- package/templates/racing/package.json +7 -7
- package/templates/racing/src/game.ts +1 -1
- package/templates/racing/src/render/atmosphere.ts +6 -0
- package/templates/racing/src/render/backlightControls.ts +10 -0
- package/templates/racing/src/render/backlightMaterial.ts +4 -4
- package/templates/racing/src/render/clouds.ts +13 -0
- package/templates/racing/src/render/materialLighting.ts +5 -5
- package/templates/racing/src/render/quality.ts +7 -32
- package/templates/racing/src/scenes/Race.ts +4 -1
- package/templates/racing/src/style.css +4 -0
- package/templates/racing/tsconfig.json +1 -1
- package/templates/racing/vite.config.ts +2 -0
- package/templates/rain/AGENTS.md +6 -2
- package/templates/rain/CLAUDE.md +6 -2
- package/templates/rain/package.json +6 -6
- package/templates/rain/src/game.ts +1 -1
- package/templates/rain/vite.config.ts +6 -0
- package/templates/rts/AGENTS.md +6 -2
- package/templates/rts/CLAUDE.md +6 -2
- package/templates/rts/package.json +6 -6
- package/templates/rts/src/game.ts +1 -1
- package/templates/rts/src/render/backlightControls.ts +10 -0
- package/templates/rts/src/render/backlightMaterial.ts +4 -4
- package/templates/rts/src/render/materialLighting.ts +5 -5
- package/templates/rts/src/render/quality.ts +7 -31
- package/templates/rts/src/scenes/Play.ts +1 -1
- package/templates/rts/src/style.css +4 -0
- package/templates/rts/vite.config.ts +2 -0
- package/templates/runner/AGENTS.md +7 -2
- package/templates/runner/CLAUDE.md +7 -2
- package/templates/runner/package.json +7 -7
- package/templates/runner/src/game.ts +1 -1
- package/templates/runner/src/render/atmosphere.ts +6 -0
- package/templates/runner/src/render/backlightControls.ts +10 -0
- package/templates/runner/src/render/backlightMaterial.ts +4 -4
- package/templates/runner/src/render/clouds.ts +13 -0
- package/templates/runner/src/render/materialLighting.ts +5 -5
- package/templates/runner/src/render/quality.ts +7 -32
- package/templates/runner/src/scenes/Run.ts +4 -1
- package/templates/runner/src/style.css +4 -0
- package/templates/runner/tsconfig.json +1 -1
- package/templates/runner/vite.config.ts +2 -0
- package/templates/sailing/AGENTS.md +7 -2
- package/templates/sailing/CLAUDE.md +7 -2
- package/templates/sailing/package.json +7 -7
- package/templates/sailing/src/game.ts +1 -1
- package/templates/sailing/src/render/backlightControls.ts +10 -0
- package/templates/sailing/src/render/backlightMaterial.ts +4 -4
- package/templates/sailing/src/render/environmentSetup.ts +1 -1
- package/templates/sailing/src/render/materialLighting.ts +5 -5
- package/templates/sailing/src/render/quality.ts +7 -32
- package/templates/sailing/src/style.css +5 -0
- package/templates/sailing/vite.config.ts +6 -0
- package/templates/shooter/AGENTS.md +6 -2
- package/templates/shooter/CLAUDE.md +6 -2
- package/templates/shooter/package.json +7 -7
- package/templates/shooter/src/game.ts +3 -2
- package/templates/shooter/src/render/atmosphere.ts +6 -0
- package/templates/shooter/src/render/backlightControls.ts +10 -0
- package/templates/shooter/src/render/backlightMaterial.ts +4 -4
- package/templates/shooter/src/render/clouds.ts +13 -0
- package/templates/shooter/src/render/materialLighting.ts +5 -5
- package/templates/shooter/src/render/quality.ts +7 -32
- package/templates/shooter/src/scenes/Play.ts +4 -1
- package/templates/shooter/src/style.css +4 -0
- package/templates/shooter/vite.config.ts +2 -0
- package/templates/snow/AGENTS.md +7 -2
- package/templates/snow/CLAUDE.md +7 -2
- package/templates/snow/package.json +7 -7
- package/templates/snow/src/game.ts +1 -1
- package/templates/snow/src/render/backlightControls.ts +10 -0
- package/templates/snow/src/render/backlightMaterial.ts +4 -4
- package/templates/snow/src/render/materialLighting.ts +5 -5
- package/templates/snow/src/render/quality.ts +7 -32
- package/templates/snow/src/style.css +5 -0
- package/templates/snow/vite.config.ts +6 -0
- package/templates/starter/AGENTS.md +8 -3
- package/templates/starter/CLAUDE.md +8 -3
- package/templates/starter/package.json +7 -7
- package/templates/starter/src/entities/Crate.ts +5 -2
- package/templates/starter/src/game.ts +4 -3
- package/templates/starter/src/render/adaptiveQuality.ts +17 -0
- package/templates/starter/src/render/atmosphere.ts +6 -0
- package/templates/starter/src/render/backlightControls.ts +10 -0
- package/templates/starter/src/render/backlightMaterial.ts +4 -4
- package/templates/starter/src/render/clouds.ts +13 -0
- package/templates/starter/src/render/contactShadow.ts +1 -1
- package/templates/starter/src/render/materialLighting.ts +5 -5
- package/templates/starter/src/render/postprocessing.ts +11 -10
- package/templates/starter/src/render/quality.ts +14 -1
- package/templates/starter/src/scenes/Play.ts +12 -3
- package/templates/starter/src/state.ts +2 -0
- package/templates/starter/src/style.css +4 -0
- package/templates/starter/src/ui/Menu.tsx +5 -1
- package/templates/starter/vite.config.ts +2 -0
- package/templates/tower-defense/AGENTS.md +7 -2
- package/templates/tower-defense/CLAUDE.md +7 -2
- package/templates/tower-defense/package.json +7 -7
- package/templates/tower-defense/src/game.ts +1 -1
- package/templates/tower-defense/src/render/backlightControls.ts +10 -0
- package/templates/tower-defense/src/render/backlightMaterial.ts +4 -4
- package/templates/tower-defense/src/render/materialLighting.ts +5 -5
- package/templates/tower-defense/src/render/quality.ts +7 -32
- package/templates/tower-defense/src/scenes/Battle.ts +1 -1
- package/templates/tower-defense/src/style.css +4 -0
- package/templates/tower-defense/tsconfig.json +1 -1
- package/templates/tower-defense/vite.config.ts +2 -0
- package/templates/action-rpg/src/render/environmentContribution.ts +0 -188
- package/templates/action-rpg/src/render/environmentRadiance.ts +0 -36
- package/templates/action-rpg/src/render/environmentSampleCache.ts +0 -43
- package/templates/action-rpg/src/render/environmentSampling.ts +0 -193
- package/templates/action-rpg/src/render/environmentSnapshot.ts +0 -53
- package/templates/minimal/src/render/environmentContribution.ts +0 -188
- package/templates/minimal/src/render/environmentRadiance.ts +0 -36
- package/templates/minimal/src/render/environmentSampleCache.ts +0 -43
- package/templates/minimal/src/render/environmentSampling.ts +0 -193
- package/templates/minimal/src/render/environmentSnapshot.ts +0 -53
- package/templates/platformer/src/render/environmentContribution.ts +0 -188
- package/templates/platformer/src/render/environmentRadiance.ts +0 -36
- package/templates/platformer/src/render/environmentSampleCache.ts +0 -43
- package/templates/platformer/src/render/environmentSampling.ts +0 -193
- package/templates/platformer/src/render/environmentSnapshot.ts +0 -53
- package/templates/puzzle/src/render/environmentContribution.ts +0 -188
- package/templates/puzzle/src/render/environmentRadiance.ts +0 -36
- package/templates/puzzle/src/render/environmentSampleCache.ts +0 -43
- package/templates/puzzle/src/render/environmentSampling.ts +0 -193
- package/templates/puzzle/src/render/environmentSnapshot.ts +0 -53
- package/templates/racing/src/render/environmentContribution.ts +0 -188
- package/templates/racing/src/render/environmentRadiance.ts +0 -36
- package/templates/racing/src/render/environmentSampleCache.ts +0 -43
- package/templates/racing/src/render/environmentSampling.ts +0 -193
- package/templates/racing/src/render/environmentSnapshot.ts +0 -53
- package/templates/rts/src/render/environmentContribution.ts +0 -188
- package/templates/rts/src/render/environmentRadiance.ts +0 -36
- package/templates/rts/src/render/environmentSampleCache.ts +0 -43
- package/templates/rts/src/render/environmentSampling.ts +0 -193
- package/templates/rts/src/render/environmentSnapshot.ts +0 -53
- package/templates/runner/src/render/environmentContribution.ts +0 -188
- package/templates/runner/src/render/environmentRadiance.ts +0 -36
- package/templates/runner/src/render/environmentSampleCache.ts +0 -43
- package/templates/runner/src/render/environmentSampling.ts +0 -193
- package/templates/runner/src/render/environmentSnapshot.ts +0 -53
- package/templates/sailing/src/render/environmentContribution.ts +0 -188
- package/templates/sailing/src/render/environmentRadiance.ts +0 -36
- package/templates/sailing/src/render/environmentSampleCache.ts +0 -43
- package/templates/sailing/src/render/environmentSampling.ts +0 -193
- package/templates/sailing/src/render/environmentSnapshot.ts +0 -53
- package/templates/shooter/src/render/environmentContribution.ts +0 -188
- package/templates/shooter/src/render/environmentRadiance.ts +0 -36
- package/templates/shooter/src/render/environmentSampleCache.ts +0 -43
- package/templates/shooter/src/render/environmentSampling.ts +0 -193
- package/templates/shooter/src/render/environmentSnapshot.ts +0 -53
- package/templates/snow/src/render/environmentContribution.ts +0 -188
- package/templates/snow/src/render/environmentRadiance.ts +0 -36
- package/templates/snow/src/render/environmentSampleCache.ts +0 -43
- package/templates/snow/src/render/environmentSampling.ts +0 -193
- package/templates/snow/src/render/environmentSnapshot.ts +0 -53
- package/templates/starter/src/render/environmentContribution.ts +0 -188
- package/templates/starter/src/render/environmentRadiance.ts +0 -36
- package/templates/starter/src/render/environmentSampleCache.ts +0 -43
- package/templates/starter/src/render/environmentSampling.ts +0 -193
- package/templates/starter/src/render/environmentSnapshot.ts +0 -53
- package/templates/starter/src/render/rendererGate.ts +0 -36
- package/templates/tower-defense/src/render/environmentContribution.ts +0 -188
- package/templates/tower-defense/src/render/environmentRadiance.ts +0 -36
- package/templates/tower-defense/src/render/environmentSampleCache.ts +0 -43
- package/templates/tower-defense/src/render/environmentSampling.ts +0 -193
- package/templates/tower-defense/src/render/environmentSnapshot.ts +0 -53
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { execFileSync, spawn } from 'child_process';
|
|
4
|
+
import { createHash } from 'crypto';
|
|
4
5
|
import { existsSync, realpathSync, readdirSync, readFileSync, mkdirSync, writeFileSync, rmSync } from 'fs';
|
|
5
|
-
import { mkdir, cp, rm, rename, readFile, readdir, writeFile, symlink, access, unlink, stat } from 'fs/promises';
|
|
6
|
-
import
|
|
6
|
+
import { mkdir, cp, rm, rename, readFile, readdir, writeFile, mkdtemp, lstat, symlink, access, unlink, stat } from 'fs/promises';
|
|
7
|
+
import { tmpdir } from 'os';
|
|
8
|
+
import path8 from 'path';
|
|
7
9
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
8
10
|
import { LoadingManager, Box3, Vector3 } from 'three';
|
|
9
|
-
import { createHash } from 'crypto';
|
|
10
11
|
import { createRequire as createRequire$1 } from 'module';
|
|
11
12
|
import { parsePng, parseAudioConfig } from '@threenative/assets';
|
|
12
13
|
|
|
@@ -86,10 +87,10 @@ function localResourcePath(baseDirectory, uri) {
|
|
|
86
87
|
} catch (error) {
|
|
87
88
|
throw new Error(`Invalid glTF resource URI "${uri}": ${String(error)}`);
|
|
88
89
|
}
|
|
89
|
-
return
|
|
90
|
+
return path8.resolve(baseDirectory, decoded);
|
|
90
91
|
}
|
|
91
92
|
function resourceMimeType(resourcePath, declared) {
|
|
92
|
-
return declared ?? RESOURCE_MIME_TYPES[
|
|
93
|
+
return declared ?? RESOURCE_MIME_TYPES[path8.extname(resourcePath).toLowerCase()] ?? "application/octet-stream";
|
|
93
94
|
}
|
|
94
95
|
function gltfResourceReferences(document) {
|
|
95
96
|
const references = [];
|
|
@@ -118,10 +119,10 @@ async function readLocalResources(baseDirectory, references) {
|
|
|
118
119
|
return resources;
|
|
119
120
|
}
|
|
120
121
|
async function localResourceResolver(file, data) {
|
|
121
|
-
if (
|
|
122
|
+
if (path8.extname(file).toLowerCase() !== ".gltf") return (url) => url;
|
|
122
123
|
const document = JSON.parse(data.toString("utf8"));
|
|
123
124
|
const references = gltfResourceReferences(document);
|
|
124
|
-
const baseDirectory =
|
|
125
|
+
const baseDirectory = path8.dirname(path8.resolve(file));
|
|
125
126
|
const resources = await readLocalResources(baseDirectory, references);
|
|
126
127
|
return (url) => {
|
|
127
128
|
const resourcePath = localResourcePath(baseDirectory, url);
|
|
@@ -135,11 +136,11 @@ async function parseGltfAsset(file, data) {
|
|
|
135
136
|
const manager = new LoadingManager();
|
|
136
137
|
manager.setURLModifier(await localResourceResolver(file, data));
|
|
137
138
|
const loader = new GLTFLoader(manager);
|
|
138
|
-
const extension =
|
|
139
|
+
const extension = path8.extname(file).toLowerCase();
|
|
139
140
|
const payload = extension === ".gltf" ? data.toString("utf8") : data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
140
141
|
const parsed = await loader.parseAsync(
|
|
141
142
|
payload,
|
|
142
|
-
`${
|
|
143
|
+
`${path8.dirname(path8.resolve(file))}${path8.sep}`
|
|
143
144
|
);
|
|
144
145
|
const json = parsed.parser.json;
|
|
145
146
|
return {
|
|
@@ -199,11 +200,11 @@ function inspectScene(file, scene, animations, resourceCounts) {
|
|
|
199
200
|
bounds,
|
|
200
201
|
bones: resources.bones,
|
|
201
202
|
clips: animations.map((clip) => clip.name || "(unnamed)"),
|
|
202
|
-
file:
|
|
203
|
+
file: path8.basename(file),
|
|
203
204
|
forwardAxis: largest === void 0 ? { axis: "unknown", basis: "none", direction: "unknown" } : { axis: largest.axis, basis: "longest geometry axis", direction: "unknown" },
|
|
204
205
|
materials: resourceCounts.materials ?? resources.materials,
|
|
205
206
|
meshes: resourceCounts.meshes ?? resources.meshes,
|
|
206
|
-
path:
|
|
207
|
+
path: path8.resolve(file),
|
|
207
208
|
textures: resourceCounts.textures ?? resources.textures,
|
|
208
209
|
units: {
|
|
209
210
|
label: unitsLabel(largest?.value ?? 0),
|
|
@@ -232,7 +233,7 @@ function parseInspectArgs(argv) {
|
|
|
232
233
|
return { file, json: argv.includes("--json") };
|
|
233
234
|
}
|
|
234
235
|
async function inspectAsset(file) {
|
|
235
|
-
const extension =
|
|
236
|
+
const extension = path8.extname(file).toLowerCase();
|
|
236
237
|
if (!SUPPORTED_EXTENSIONS.has(extension)) {
|
|
237
238
|
throw new Error(`TN_ASSET_INSPECT_UNSUPPORTED: ${file}: expected a .glb or .gltf file.`);
|
|
238
239
|
}
|
|
@@ -426,6 +427,9 @@ var CODEX_MCP_SERVERS = Object.freeze(
|
|
|
426
427
|
([name, server]) => Object.freeze({ body: codexServerBlock(name, server), name })
|
|
427
428
|
)
|
|
428
429
|
);
|
|
430
|
+
|
|
431
|
+
// ../core/src/version.ts
|
|
432
|
+
var CORE_VERSION = "0.3.13";
|
|
429
433
|
var MCP_HOSTS = Object.freeze([
|
|
430
434
|
Object.freeze({
|
|
431
435
|
id: "claude-code",
|
|
@@ -454,7 +458,7 @@ var MCP_HOSTS = Object.freeze([
|
|
|
454
458
|
Object.freeze({ id: "zed", label: "Zed", file: ".zed/settings.json", format: "zed" })
|
|
455
459
|
]);
|
|
456
460
|
function ensureJsonMcpConfig(target, file, format, seed = void 0) {
|
|
457
|
-
const configPath =
|
|
461
|
+
const configPath = path8.join(target, file);
|
|
458
462
|
let existing;
|
|
459
463
|
if (existsSync(configPath)) {
|
|
460
464
|
try {
|
|
@@ -472,14 +476,14 @@ function ensureJsonMcpConfig(target, file, format, seed = void 0) {
|
|
|
472
476
|
const { changed, config, conflicts } = merged;
|
|
473
477
|
if (!changed) return conflicts.length > 0 ? "conflict" : "unchanged";
|
|
474
478
|
const written = existing === void 0 ? { ...seed, ...config } : config;
|
|
475
|
-
mkdirSync(
|
|
479
|
+
mkdirSync(path8.dirname(configPath), { recursive: true });
|
|
476
480
|
writeFileSync(configPath, `${JSON.stringify(written, null, 2)}
|
|
477
481
|
`);
|
|
478
482
|
return conflicts.length > 0 ? "conflict" : existing === void 0 ? "created" : "updated";
|
|
479
483
|
}
|
|
480
484
|
function ensureCodexMcpConfig(target) {
|
|
481
|
-
const directory =
|
|
482
|
-
const configPath =
|
|
485
|
+
const directory = path8.join(target, ".codex");
|
|
486
|
+
const configPath = path8.join(directory, "config.toml");
|
|
483
487
|
const existing = existsSync(configPath) ? readFileSync(configPath, "utf8") : "";
|
|
484
488
|
const missing = CODEX_MCP_SERVERS.filter(
|
|
485
489
|
({ name }) => !existing.includes(`[mcp_servers.${name}]`)
|
|
@@ -510,6 +514,8 @@ function ensureHostMcpConfigs(target) {
|
|
|
510
514
|
}
|
|
511
515
|
|
|
512
516
|
// src/mcp-servers.ts
|
|
517
|
+
var CORE_PACKAGE_NAME = "@threenative/core";
|
|
518
|
+
var CORE_PACKAGE_VERSION = CORE_VERSION;
|
|
513
519
|
function serverEntryPath(server) {
|
|
514
520
|
const entry = server.args[0];
|
|
515
521
|
if (entry === void 0) {
|
|
@@ -517,132 +523,6 @@ function serverEntryPath(server) {
|
|
|
517
523
|
}
|
|
518
524
|
return entry;
|
|
519
525
|
}
|
|
520
|
-
var DECODER_LOADER_ID = /[/\\]examples[/\\]jsm[/\\]loaders[/\\](?:KTX2Loader|DRACOLoader)\.js$/u;
|
|
521
|
-
var DECODER_LIB_ASSET_URL = /new URL\(\s*(['"])\.\.\/libs\/([^'"]+)\1\s*,\s*import\.meta\.url\s*\)(?:\.toString\s*\(\s*\)|\.href\s*)?/gu;
|
|
522
|
-
function rewriteDecoderAssetUrls(code) {
|
|
523
|
-
return code.replace(DECODER_LIB_ASSET_URL, '"../libs/$2"');
|
|
524
|
-
}
|
|
525
|
-
var MARKER_RELATIVE = path7.join("node_modules", ".vite", "threenative-engine-build.json");
|
|
526
|
-
function hashTree(hash, directory) {
|
|
527
|
-
const entries = readdirSync(directory, { withFileTypes: true }).sort(
|
|
528
|
-
(left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0
|
|
529
|
-
);
|
|
530
|
-
for (const entry of entries) {
|
|
531
|
-
const full = path7.join(directory, entry.name);
|
|
532
|
-
if (entry.isDirectory()) {
|
|
533
|
-
hashTree(hash, full);
|
|
534
|
-
} else if (entry.isFile()) {
|
|
535
|
-
hash.update(path7.relative(directory, full));
|
|
536
|
-
hash.update(readFileSync(full));
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
function hashEngineDist(projectRoot) {
|
|
541
|
-
const scopeDir = path7.join(projectRoot, "node_modules", "@threenative");
|
|
542
|
-
let packages;
|
|
543
|
-
try {
|
|
544
|
-
packages = readdirSync(scopeDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) => entry.name).sort((left, right) => left < right ? -1 : left > right ? 1 : 0);
|
|
545
|
-
} catch {
|
|
546
|
-
return void 0;
|
|
547
|
-
}
|
|
548
|
-
const dists = [];
|
|
549
|
-
for (const name of packages) {
|
|
550
|
-
let packageDir = path7.join(scopeDir, name);
|
|
551
|
-
try {
|
|
552
|
-
packageDir = realpathSync(packageDir);
|
|
553
|
-
} catch {
|
|
554
|
-
continue;
|
|
555
|
-
}
|
|
556
|
-
const dist = path7.join(packageDir, "dist");
|
|
557
|
-
if (existsSync(dist)) dists.push([name, dist]);
|
|
558
|
-
}
|
|
559
|
-
if (dists.length === 0) return void 0;
|
|
560
|
-
const hash = createHash("sha256");
|
|
561
|
-
for (const [name, dist] of dists) {
|
|
562
|
-
hash.update(name);
|
|
563
|
-
hashTree(hash, dist);
|
|
564
|
-
}
|
|
565
|
-
return hash.digest("hex");
|
|
566
|
-
}
|
|
567
|
-
function markerPath(projectRoot) {
|
|
568
|
-
return path7.join(projectRoot, MARKER_RELATIVE);
|
|
569
|
-
}
|
|
570
|
-
function readMarker(file) {
|
|
571
|
-
try {
|
|
572
|
-
return JSON.parse(readFileSync(file, "utf8"));
|
|
573
|
-
} catch {
|
|
574
|
-
return void 0;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
function processIsAlive(pid) {
|
|
578
|
-
if (pid === process.pid) return true;
|
|
579
|
-
try {
|
|
580
|
-
process.kill(pid, 0);
|
|
581
|
-
return true;
|
|
582
|
-
} catch (error) {
|
|
583
|
-
return error.code === "EPERM";
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
function createEngineFreshnessPlugin() {
|
|
587
|
-
let recordedHash;
|
|
588
|
-
const rootOf = (config) => path7.resolve(config.root ?? process.cwd());
|
|
589
|
-
return {
|
|
590
|
-
name: "threenative-engine-freshness",
|
|
591
|
-
config(config, env) {
|
|
592
|
-
const resolve = { dedupe: ["three", "react", "react-dom"] };
|
|
593
|
-
if (env.command !== "serve") return { resolve };
|
|
594
|
-
const root = rootOf(config);
|
|
595
|
-
recordedHash = hashEngineDist(root);
|
|
596
|
-
const marker = recordedHash === void 0 ? void 0 : readMarker(markerPath(root));
|
|
597
|
-
if (recordedHash === void 0 || marker === void 0 || marker.hash === recordedHash) {
|
|
598
|
-
return { resolve };
|
|
599
|
-
}
|
|
600
|
-
if (processIsAlive(marker.pid)) {
|
|
601
|
-
const where = marker.port === void 0 ? `pid ${marker.pid}` : `pid ${marker.pid} on port ${marker.port}`;
|
|
602
|
-
const how = marker.port === void 0 ? "" : ` (lsof -ti tcp:${marker.port} | xargs -r kill)`;
|
|
603
|
-
console.warn(
|
|
604
|
-
`threenative: a dev server is still running at ${where}, serving engine build ${marker.hash.slice(0, 8)}; the installed build is ${recordedHash.slice(0, 8)}. Kill it before playing${how} \u2014 its tab renders yesterday's engine.`
|
|
605
|
-
);
|
|
606
|
-
}
|
|
607
|
-
return { resolve, optimizeDeps: { force: true } };
|
|
608
|
-
},
|
|
609
|
-
transform(code, id) {
|
|
610
|
-
if (!DECODER_LOADER_ID.test(id)) return null;
|
|
611
|
-
const rewritten = rewriteDecoderAssetUrls(code);
|
|
612
|
-
return rewritten === code ? null : { code: rewritten, map: null };
|
|
613
|
-
},
|
|
614
|
-
configureServer(server) {
|
|
615
|
-
const root = rootOf(server.config);
|
|
616
|
-
const file = markerPath(root);
|
|
617
|
-
const writeBootMarker = (port) => {
|
|
618
|
-
const hash = recordedHash ?? hashEngineDist(root);
|
|
619
|
-
if (hash === void 0) return;
|
|
620
|
-
mkdirSync(path7.dirname(file), { recursive: true });
|
|
621
|
-
writeFileSync(
|
|
622
|
-
file,
|
|
623
|
-
JSON.stringify(
|
|
624
|
-
port === void 0 ? { hash, pid: process.pid } : { hash, pid: process.pid, port }
|
|
625
|
-
)
|
|
626
|
-
);
|
|
627
|
-
};
|
|
628
|
-
const httpServer = server.httpServer;
|
|
629
|
-
if (httpServer === void 0 || httpServer === null) {
|
|
630
|
-
writeBootMarker(void 0);
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
httpServer.once("listening", () => {
|
|
634
|
-
const address = httpServer.address();
|
|
635
|
-
writeBootMarker(
|
|
636
|
-
typeof address === "object" && address !== null && address.port !== void 0 ? address.port : void 0
|
|
637
|
-
);
|
|
638
|
-
});
|
|
639
|
-
httpServer.once("close", () => {
|
|
640
|
-
const marker = readMarker(file);
|
|
641
|
-
if (marker?.pid === process.pid) rmSync(file, { force: true });
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
526
|
var ORIENTATIONS = ["landscape", "portrait", "sensor"];
|
|
647
527
|
var CONFIG_FILE = "threenative.config.ts";
|
|
648
528
|
var ConfigFailure = class extends Error {
|
|
@@ -693,6 +573,13 @@ function positiveInteger(value, fallback, code, label) {
|
|
|
693
573
|
}
|
|
694
574
|
return value;
|
|
695
575
|
}
|
|
576
|
+
function priorityValue(value) {
|
|
577
|
+
if (value === void 0) return "game";
|
|
578
|
+
if (value !== "game" && value !== "normal") {
|
|
579
|
+
fail("TN_CONFIG_PRIORITY_INVALID", 'display.priority must be "game" or "normal".');
|
|
580
|
+
}
|
|
581
|
+
return value;
|
|
582
|
+
}
|
|
696
583
|
function maxFpsValue(value) {
|
|
697
584
|
if (value === void 0) return 60;
|
|
698
585
|
if (!Number.isSafeInteger(value) || value < 0 || value > 1e3) {
|
|
@@ -717,13 +604,13 @@ function defaultAppId(name) {
|
|
|
717
604
|
return `com.threenative.${segment}`;
|
|
718
605
|
}
|
|
719
606
|
function projectRequire(cwd) {
|
|
720
|
-
return createRequire$1(
|
|
607
|
+
return createRequire$1(path8.join(cwd, "package.json"));
|
|
721
608
|
}
|
|
722
609
|
function configLoaderSearch(cwd) {
|
|
723
610
|
return [
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
611
|
+
path8.join(cwd, "node_modules", "vite"),
|
|
612
|
+
path8.join(cwd, "node_modules", "esbuild"),
|
|
613
|
+
path8.resolve(path8.dirname(fileURLToPath(import.meta.url)), "..", "node_modules", "esbuild")
|
|
727
614
|
];
|
|
728
615
|
}
|
|
729
616
|
var CONFIG_BUILD_COMMAND = "pnpm exec threenative build --target web";
|
|
@@ -731,7 +618,7 @@ function configContext(cwd, layer, sources, searched, fix) {
|
|
|
731
618
|
return { cwd, fix, layer, searched, sources };
|
|
732
619
|
}
|
|
733
620
|
function packageContext(cwd) {
|
|
734
|
-
const packagePath =
|
|
621
|
+
const packagePath = path8.join(cwd, "package.json");
|
|
735
622
|
return configContext(
|
|
736
623
|
cwd,
|
|
737
624
|
"package manifest",
|
|
@@ -754,8 +641,8 @@ function validationContext(cwd, sources) {
|
|
|
754
641
|
cwd,
|
|
755
642
|
"config validation",
|
|
756
643
|
sources,
|
|
757
|
-
[
|
|
758
|
-
`fix '${
|
|
644
|
+
[path8.join(cwd, "package.json"), path8.join(cwd, CONFIG_FILE)],
|
|
645
|
+
`fix '${path8.join(cwd, CONFIG_FILE)}' and rerun ${CONFIG_BUILD_COMMAND}`
|
|
759
646
|
);
|
|
760
647
|
}
|
|
761
648
|
function configFailure(code, context, detail) {
|
|
@@ -794,8 +681,12 @@ function resolveEsbuild(cwd) {
|
|
|
794
681
|
}
|
|
795
682
|
}
|
|
796
683
|
}
|
|
684
|
+
var configLoadSequence = 0;
|
|
685
|
+
function configTempName(cwd, pid, now, sequence) {
|
|
686
|
+
return path8.join(cwd, `.threenative.config.${pid}.${now}.${sequence}.mjs`);
|
|
687
|
+
}
|
|
797
688
|
async function importConfig(cwd) {
|
|
798
|
-
const sourcePath =
|
|
689
|
+
const sourcePath = path8.join(cwd, CONFIG_FILE);
|
|
799
690
|
try {
|
|
800
691
|
await access(sourcePath);
|
|
801
692
|
} catch {
|
|
@@ -856,7 +747,8 @@ async function importConfig(cwd) {
|
|
|
856
747
|
error instanceof Error ? error.message : String(error)
|
|
857
748
|
);
|
|
858
749
|
}
|
|
859
|
-
|
|
750
|
+
configLoadSequence += 1;
|
|
751
|
+
const compiledPath = configTempName(cwd, process.pid, Date.now(), configLoadSequence);
|
|
860
752
|
try {
|
|
861
753
|
await writeFile(compiledPath, code, "utf8");
|
|
862
754
|
} catch (error) {
|
|
@@ -892,7 +784,7 @@ async function importConfig(cwd) {
|
|
|
892
784
|
async function readManifest(cwd) {
|
|
893
785
|
let parsed;
|
|
894
786
|
try {
|
|
895
|
-
parsed = JSON.parse(await readFile(
|
|
787
|
+
parsed = JSON.parse(await readFile(path8.join(cwd, "package.json"), "utf8"));
|
|
896
788
|
} catch (error) {
|
|
897
789
|
fail("TN_CONFIG_PACKAGE_INVALID", error instanceof Error ? error.message : String(error));
|
|
898
790
|
}
|
|
@@ -911,12 +803,12 @@ function packageNativeEntry(manifest) {
|
|
|
911
803
|
}
|
|
912
804
|
function validateNativeEntry(value, cwd) {
|
|
913
805
|
const entry = nonEmptyString(value, "TN_NATIVE_ENTRY_MISSING", "nativeEntry");
|
|
914
|
-
if (
|
|
806
|
+
if (path8.isAbsolute(entry)) {
|
|
915
807
|
fail("TN_CONFIG_NATIVE_ENTRY_INVALID", "nativeEntry must be project-relative.");
|
|
916
808
|
}
|
|
917
|
-
const resolved =
|
|
918
|
-
const relative =
|
|
919
|
-
if (relative === ".." || relative.startsWith(`..${
|
|
809
|
+
const resolved = path8.resolve(cwd, entry);
|
|
810
|
+
const relative = path8.relative(cwd, resolved);
|
|
811
|
+
if (relative === ".." || relative.startsWith(`..${path8.sep}`) || path8.isAbsolute(relative)) {
|
|
920
812
|
fail("TN_CONFIG_NATIVE_ENTRY_INVALID", "nativeEntry must stay inside the project.");
|
|
921
813
|
}
|
|
922
814
|
return entry;
|
|
@@ -960,18 +852,18 @@ async function validateApp(raw, name, cwd) {
|
|
|
960
852
|
}
|
|
961
853
|
async function validateProjectAsset(raw, cwd, label, options) {
|
|
962
854
|
const relative = nonEmptyString(raw, `${options.codePrefix}_INVALID`, label);
|
|
963
|
-
if (
|
|
855
|
+
if (path8.isAbsolute(relative)) {
|
|
964
856
|
fail(`${options.codePrefix}_PATH_INVALID`, `${label} must be project-relative: ${relative}`);
|
|
965
857
|
}
|
|
966
|
-
const resolved =
|
|
967
|
-
const withinProject =
|
|
968
|
-
if (withinProject === ".." || withinProject.startsWith(`..${
|
|
858
|
+
const resolved = path8.resolve(cwd, relative);
|
|
859
|
+
const withinProject = path8.relative(cwd, resolved);
|
|
860
|
+
if (withinProject === ".." || withinProject.startsWith(`..${path8.sep}`) || path8.isAbsolute(withinProject)) {
|
|
969
861
|
fail(
|
|
970
862
|
`${options.codePrefix}_PATH_INVALID`,
|
|
971
863
|
`${label} must stay inside the project: ${relative}`
|
|
972
864
|
);
|
|
973
865
|
}
|
|
974
|
-
const extension =
|
|
866
|
+
const extension = path8.extname(relative).slice(1).toLowerCase();
|
|
975
867
|
if (!options.formats.includes(extension)) {
|
|
976
868
|
fail(
|
|
977
869
|
options.codePrefix === "TN_CONFIG_ICON" ? `${options.codePrefix}_INVALID` : `${options.codePrefix}_FORMAT_INVALID`,
|
|
@@ -1131,7 +1023,13 @@ async function validateIconVariants(raw, cwd) {
|
|
|
1131
1023
|
}
|
|
1132
1024
|
function validateDisplay(raw) {
|
|
1133
1025
|
const display = assertRecord(raw, "display");
|
|
1134
|
-
assertKeys(display, "display", [
|
|
1026
|
+
assertKeys(display, "display", [
|
|
1027
|
+
"orientation",
|
|
1028
|
+
"fullscreen",
|
|
1029
|
+
"keepScreenOn",
|
|
1030
|
+
"priority",
|
|
1031
|
+
"maxFps"
|
|
1032
|
+
]);
|
|
1135
1033
|
const orientation = display.orientation === void 0 ? "landscape" : display.orientation;
|
|
1136
1034
|
if (typeof orientation !== "string" || !ORIENTATIONS.includes(orientation)) {
|
|
1137
1035
|
fail(
|
|
@@ -1153,6 +1051,7 @@ function validateDisplay(raw) {
|
|
|
1153
1051
|
"TN_CONFIG_KEEP_SCREEN_ON_INVALID",
|
|
1154
1052
|
"display.keepScreenOn"
|
|
1155
1053
|
),
|
|
1054
|
+
priority: priorityValue(display.priority),
|
|
1156
1055
|
maxFps: maxFpsValue(display.maxFps)
|
|
1157
1056
|
};
|
|
1158
1057
|
}
|
|
@@ -1973,8 +1872,8 @@ function assertProfileCapReachable(assets, overlay, name) {
|
|
|
1973
1872
|
}
|
|
1974
1873
|
}
|
|
1975
1874
|
async function loadConfigInternal(root, selection) {
|
|
1976
|
-
const packagePath =
|
|
1977
|
-
const sourcePath =
|
|
1875
|
+
const packagePath = path8.join(root, "package.json");
|
|
1876
|
+
const sourcePath = path8.join(root, CONFIG_FILE);
|
|
1978
1877
|
const manifest = await withConfigContext(
|
|
1979
1878
|
packageContext(root),
|
|
1980
1879
|
"TN_CONFIG_PACKAGE_INVALID",
|
|
@@ -2049,15 +1948,15 @@ async function loadConfigInternal(root, selection) {
|
|
|
2049
1948
|
);
|
|
2050
1949
|
}
|
|
2051
1950
|
async function loadConfig(cwd, selection) {
|
|
2052
|
-
const root =
|
|
1951
|
+
const root = path8.resolve(cwd);
|
|
2053
1952
|
return withConfigContext(
|
|
2054
|
-
validationContext(root, [
|
|
1953
|
+
validationContext(root, [path8.join(root, CONFIG_FILE), path8.join(root, "package.json")]),
|
|
2055
1954
|
"TN_CONFIG_VALIDATION_FAILED",
|
|
2056
1955
|
() => loadConfigInternal(root, selection)
|
|
2057
1956
|
);
|
|
2058
1957
|
}
|
|
2059
|
-
function webRuntimeDecoders(
|
|
2060
|
-
return
|
|
1958
|
+
function webRuntimeDecoders(_config) {
|
|
1959
|
+
return { ktx2: true, meshopt: true };
|
|
2061
1960
|
}
|
|
2062
1961
|
var WEB_ENGINE_ID = "\0threenative:web-engine";
|
|
2063
1962
|
var UPSTREAM = ["three", "three/webgpu", "three/tsl"];
|
|
@@ -2095,9 +1994,14 @@ var ENGINE_MATH_MODULES = /* @__PURE__ */ new Set([
|
|
|
2095
1994
|
"three/src/math/Sphere.js",
|
|
2096
1995
|
"three/src/math/Vector2.js",
|
|
2097
1996
|
"three/src/math/Vector3.js",
|
|
2098
|
-
"three/src/math/Vector4.js"
|
|
1997
|
+
"three/src/math/Vector4.js",
|
|
1998
|
+
// three's loader base classes (browser-loaders.ts): fetch and request tracking, no drawing.
|
|
1999
|
+
"three/src/loaders/Cache.js",
|
|
2000
|
+
"three/src/loaders/FileLoader.js",
|
|
2001
|
+
"three/src/loaders/Loader.js",
|
|
2002
|
+
"three/src/loaders/LoadingManager.js"
|
|
2099
2003
|
]);
|
|
2100
|
-
var ENGINE_MATH_IMPORTER = /[\\/](?:browser-math\.ts|web-engine-runtime\.js)(?:\?.*)?$/u;
|
|
2004
|
+
var ENGINE_MATH_IMPORTER = /[\\/](?:browser-math\.ts|browser-loaders\.ts|web-engine-runtime\.js)(?:\?.*)?$/u;
|
|
2101
2005
|
function browserModule(built, source) {
|
|
2102
2006
|
const bundled = fileURLToPath(new URL(`./${built}`, import.meta.url));
|
|
2103
2007
|
if (existsSync(bundled)) return bundled;
|
|
@@ -2117,9 +2021,9 @@ function wasmModule(root, explicit) {
|
|
|
2117
2021
|
}
|
|
2118
2022
|
let entry;
|
|
2119
2023
|
try {
|
|
2120
|
-
const require2 = createRequire$1(
|
|
2121
|
-
entry =
|
|
2122
|
-
|
|
2024
|
+
const require2 = createRequire$1(path8.join(root, "package.json"));
|
|
2025
|
+
entry = path8.join(
|
|
2026
|
+
path8.dirname(require2.resolve("@threenative/runtime-native/package.json")),
|
|
2123
2027
|
WASM_ENGINE_ENTRY
|
|
2124
2028
|
);
|
|
2125
2029
|
} catch {
|
|
@@ -2133,15 +2037,69 @@ function wasmModule(root, explicit) {
|
|
|
2133
2037
|
);
|
|
2134
2038
|
return entry;
|
|
2135
2039
|
}
|
|
2040
|
+
function esmEntry(resolved) {
|
|
2041
|
+
if (!resolved.endsWith(".cjs")) return resolved;
|
|
2042
|
+
for (let dir = path8.dirname(resolved); dir !== path8.dirname(dir); dir = path8.dirname(dir)) {
|
|
2043
|
+
const manifest = path8.join(dir, "package.json");
|
|
2044
|
+
if (!existsSync(manifest)) continue;
|
|
2045
|
+
const root = JSON.parse(readFileSync(manifest, "utf8")).exports?.["."];
|
|
2046
|
+
const sameEntry = typeof root?.require === "string" && path8.join(dir, root.require) === resolved;
|
|
2047
|
+
return sameEntry && typeof root?.import === "string" ? path8.join(dir, root.import) : resolved;
|
|
2048
|
+
}
|
|
2049
|
+
return resolved;
|
|
2050
|
+
}
|
|
2136
2051
|
async function upstreamNames(root) {
|
|
2137
|
-
const require2 = createRequire$1(
|
|
2052
|
+
const require2 = createRequire$1(path8.join(root, "package.json"));
|
|
2138
2053
|
const modules = await Promise.all(
|
|
2139
|
-
UPSTREAM.map(
|
|
2054
|
+
UPSTREAM.map(
|
|
2055
|
+
(id) => import(pathToFileURL(esmEntry(require2.resolve(id))).href)
|
|
2056
|
+
)
|
|
2140
2057
|
);
|
|
2141
2058
|
return [...new Set(modules.flatMap((module) => Object.keys(module)))].filter((name) => name !== "default" && name !== "module.exports").sort();
|
|
2142
2059
|
}
|
|
2060
|
+
var REFUSAL = /^(TN_[A-Z0-9_]+): (\S+) is not available on the Wasm engine\.$/u;
|
|
2061
|
+
async function upstreamRefusals(root, wasm) {
|
|
2062
|
+
const entry = wasmModule(root, wasm);
|
|
2063
|
+
const binary = readFileSync(entry.replace(/\.mjs$/u, ".wasm"));
|
|
2064
|
+
const create = (await import(pathToFileURL(entry).href)).default;
|
|
2065
|
+
const { bindWebEngine } = await import(pathToFileURL(runtimeModule()).href);
|
|
2066
|
+
const names = await upstreamNames(root);
|
|
2067
|
+
const bound = await bindWebEngine(
|
|
2068
|
+
(options) => create({
|
|
2069
|
+
...options,
|
|
2070
|
+
print: () => {
|
|
2071
|
+
},
|
|
2072
|
+
printErr: () => {
|
|
2073
|
+
},
|
|
2074
|
+
// The web build fetches its .wasm by URL; Node has no page to fetch from.
|
|
2075
|
+
instantiateWasm(imports, receive) {
|
|
2076
|
+
void WebAssembly.instantiate(binary, imports).then(
|
|
2077
|
+
(result) => receive(result.instance, result.module)
|
|
2078
|
+
);
|
|
2079
|
+
return {};
|
|
2080
|
+
}
|
|
2081
|
+
}),
|
|
2082
|
+
names
|
|
2083
|
+
);
|
|
2084
|
+
return refusalsOf(bound, names);
|
|
2085
|
+
}
|
|
2086
|
+
function refusalsOf(bound, names) {
|
|
2087
|
+
const refusals = /* @__PURE__ */ new Map();
|
|
2088
|
+
for (const name of names) {
|
|
2089
|
+
const value = bound[name];
|
|
2090
|
+
if (typeof value !== "function") continue;
|
|
2091
|
+
try {
|
|
2092
|
+
Reflect.ownKeys(value);
|
|
2093
|
+
} catch (error) {
|
|
2094
|
+
const match = REFUSAL.exec(error instanceof Error ? error.message : "");
|
|
2095
|
+
if (match?.[2] === name && match[1] !== void 0) refusals.set(name, match[1]);
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
return refusals;
|
|
2099
|
+
}
|
|
2143
2100
|
function createWebEnginePlugin(options = {}) {
|
|
2144
2101
|
let root = options.root;
|
|
2102
|
+
let strict = options.strict ?? true;
|
|
2145
2103
|
const native = options.engine === "threenative";
|
|
2146
2104
|
const projectRoot = () => {
|
|
2147
2105
|
if (root === void 0)
|
|
@@ -2153,6 +2111,7 @@ function createWebEnginePlugin(options = {}) {
|
|
|
2153
2111
|
enforce: "pre",
|
|
2154
2112
|
configResolved(config) {
|
|
2155
2113
|
root ??= config.root;
|
|
2114
|
+
strict = options.strict ?? config.command !== "build";
|
|
2156
2115
|
},
|
|
2157
2116
|
resolveId(specifier, importer = "") {
|
|
2158
2117
|
if (!native) return null;
|
|
@@ -2172,6 +2131,8 @@ function createWebEnginePlugin(options = {}) {
|
|
|
2172
2131
|
);
|
|
2173
2132
|
if (source === "three/addons/geometries/DecalGeometry.js")
|
|
2174
2133
|
return browserModule("web-engine-decal-geometry.js", "addons/decal-geometry.ts");
|
|
2134
|
+
if (source === "three/addons/animation/CCDIKSolver.js")
|
|
2135
|
+
return browserModule("web-engine-ccd-ik-solver.js", "addons/ccd-ik-solver.ts");
|
|
2175
2136
|
if (source === "three/addons/loaders/HDRLoader.js")
|
|
2176
2137
|
return browserModule("web-engine-hdr-loader.js", "addons/hdr-loader.ts");
|
|
2177
2138
|
if (source === "three/addons/loaders/GLTFLoader.js")
|
|
@@ -2201,27 +2162,268 @@ function createWebEnginePlugin(options = {}) {
|
|
|
2201
2162
|
"__tnLoadGltf"
|
|
2202
2163
|
];
|
|
2203
2164
|
const single = wasmModule(projectRoot(), options.wasm);
|
|
2204
|
-
const threads =
|
|
2165
|
+
const threads = path8.join(path8.dirname(single), path8.basename(WASM_THREADS_ENTRY));
|
|
2205
2166
|
if (!existsSync(threads))
|
|
2206
2167
|
throw new Error(
|
|
2207
2168
|
`TN_WASM_THREADS_MISSING: engine "threenative" needs the threaded Wasm engine at ${threads}; reinstall @threenative/runtime-native, or in a ThreeNative checkout run \`pnpm wasm:build\` (presets wasm and wasm-threads). ${OPT_OUT}`
|
|
2208
2169
|
);
|
|
2209
|
-
|
|
2170
|
+
const off = (detail) => `${THREADS_OFF}: ${detail} Serve the game over https or localhost (the build's service worker adds Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp), or send both headers; on itch.io enable "SharedArrayBuffer support".`;
|
|
2171
|
+
const head = [
|
|
2210
2172
|
`import { bindWebEngine } from ${JSON.stringify(runtimeModule())};`,
|
|
2173
|
+
"if (globalThis.crossOriginIsolated !== true) await globalThis.__tnIsolation;"
|
|
2174
|
+
];
|
|
2175
|
+
const threadsReport = "${globalThis.__tnWebThreads}";
|
|
2176
|
+
const lines = strict ? [
|
|
2211
2177
|
"if (globalThis.crossOriginIsolated !== true)",
|
|
2212
|
-
` throw new Error(
|
|
2178
|
+
` throw new Error(${JSON.stringify(off("this page is not cross-origin isolated, so the engine cannot start its worker threads."))});`,
|
|
2213
2179
|
`const createModule = (await import(${JSON.stringify(threads)})).default;`,
|
|
2214
2180
|
`const engine = await bindWebEngine(createModule, ${JSON.stringify(names)});`,
|
|
2215
2181
|
'if (!String(globalThis.__tnWebThreads).startsWith("on"))',
|
|
2216
|
-
` throw new Error(\`${THREADS_OFF}: the engine's job pool started no worker thread (
|
|
2217
|
-
|
|
2218
|
-
""
|
|
2219
|
-
|
|
2182
|
+
` throw new Error(\`${THREADS_OFF}: the engine's job pool started no worker thread (${threadsReport}).\`);`
|
|
2183
|
+
] : [
|
|
2184
|
+
"const createModule = (",
|
|
2185
|
+
" globalThis.crossOriginIsolated === true",
|
|
2186
|
+
` ? await import(${JSON.stringify(threads)})`,
|
|
2187
|
+
` : await import(${JSON.stringify(single)})`,
|
|
2188
|
+
").default;",
|
|
2189
|
+
`const engine = await bindWebEngine(createModule, ${JSON.stringify(names)});`,
|
|
2190
|
+
'if (!String(globalThis.__tnWebThreads).startsWith("on"))',
|
|
2191
|
+
` console.warn(\`${off(`the engine runs without worker threads (${threadsReport}), so frames cost more.`).replaceAll("`", "\\`")}\`);`
|
|
2192
|
+
];
|
|
2193
|
+
return [...head, ...lines, `export const { ${names.join(", ")} } = engine;`, ""].join("\n");
|
|
2220
2194
|
}
|
|
2221
2195
|
};
|
|
2222
2196
|
}
|
|
2223
2197
|
|
|
2224
|
-
// src/
|
|
2198
|
+
// src/engine-catalog.ts
|
|
2199
|
+
var CHECKED_SOURCES = /* @__PURE__ */ new Set(["three", "three/webgpu", "three/tsl"]);
|
|
2200
|
+
var IMPORTS_THREE = /from\s*["']three(?:\/webgpu|\/tsl)?["']/u;
|
|
2201
|
+
var SOURCE_FILE = /\.[cm]?[jt]sx?$/u;
|
|
2202
|
+
var OVERRIDE = 'createEngineCatalogPlugin({ mode: "warn" }) in vite.config.ts reports instead of failing; engine: "threejs" in threenative.config.ts binds every name.';
|
|
2203
|
+
function namedList(ts, statement) {
|
|
2204
|
+
const declaration = ts.isImportDeclaration(statement) && statement.importClause?.isTypeOnly !== true ? { bindings: statement.importClause?.namedBindings, specifier: statement.moduleSpecifier } : ts.isExportDeclaration(statement) && !statement.isTypeOnly ? { bindings: statement.exportClause, specifier: statement.moduleSpecifier } : void 0;
|
|
2205
|
+
const bindings = declaration?.bindings;
|
|
2206
|
+
const specifier = declaration?.specifier;
|
|
2207
|
+
if (bindings === void 0 || specifier === void 0 || !ts.isStringLiteral(specifier))
|
|
2208
|
+
return void 0;
|
|
2209
|
+
if (!CHECKED_SOURCES.has(specifier.text)) return void 0;
|
|
2210
|
+
return ts.isNamedImports(bindings) || ts.isNamedExports(bindings) ? { elements: bindings.elements, source: specifier.text } : void 0;
|
|
2211
|
+
}
|
|
2212
|
+
async function refusedImports(code, file, refusals) {
|
|
2213
|
+
const ts = (await import('typescript')).default;
|
|
2214
|
+
const sourceFile = ts.createSourceFile(file, code, ts.ScriptTarget.Latest, true);
|
|
2215
|
+
const found = [];
|
|
2216
|
+
for (const statement of sourceFile.statements) {
|
|
2217
|
+
const list = namedList(ts, statement);
|
|
2218
|
+
for (const element of list?.elements ?? []) {
|
|
2219
|
+
const name = (element.propertyName ?? element.name).text;
|
|
2220
|
+
const refusal = refusals.get(name);
|
|
2221
|
+
if (element.isTypeOnly || refusal === void 0 || list === void 0) continue;
|
|
2222
|
+
const position = sourceFile.getLineAndCharacterOfPosition(element.getStart(sourceFile));
|
|
2223
|
+
found.push({
|
|
2224
|
+
code: refusal,
|
|
2225
|
+
column: position.character,
|
|
2226
|
+
line: position.line + 1,
|
|
2227
|
+
name,
|
|
2228
|
+
source: list.source
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
return found;
|
|
2233
|
+
}
|
|
2234
|
+
function createEngineCatalogPlugin(options = {}) {
|
|
2235
|
+
const mode = options.mode ?? "error";
|
|
2236
|
+
let root = process.cwd();
|
|
2237
|
+
let active = false;
|
|
2238
|
+
let bootWarned = false;
|
|
2239
|
+
let refusals;
|
|
2240
|
+
async function transform(code, id) {
|
|
2241
|
+
const file = id.split("?")[0] ?? id;
|
|
2242
|
+
const where = path8.relative(root, file);
|
|
2243
|
+
if (!active || id.startsWith("\0") || where.startsWith("..") || path8.isAbsolute(where))
|
|
2244
|
+
return null;
|
|
2245
|
+
if (where.split(path8.sep).includes("node_modules")) return null;
|
|
2246
|
+
if (!SOURCE_FILE.test(file) || !IMPORTS_THREE.test(code)) return null;
|
|
2247
|
+
refusals ??= upstreamRefusals(root).catch(
|
|
2248
|
+
(error) => new Error(
|
|
2249
|
+
`TN_ENGINE_CATALOG: the installed Wasm engine did not boot under this create-threenative, so the page cannot bind it either (${error instanceof Error ? error.message : String(error)}). Install one release of both: pnpm up --latest create-threenative @threenative/*`
|
|
2250
|
+
)
|
|
2251
|
+
);
|
|
2252
|
+
const known = await refusals;
|
|
2253
|
+
if (known instanceof Error) {
|
|
2254
|
+
if (mode === "error") return this.error({ message: known.message, id: file });
|
|
2255
|
+
if (!bootWarned) this.warn(known.message);
|
|
2256
|
+
bootWarned = true;
|
|
2257
|
+
return null;
|
|
2258
|
+
}
|
|
2259
|
+
const found = await refusedImports(code, file, known);
|
|
2260
|
+
const first = found[0];
|
|
2261
|
+
if (first === void 0) return null;
|
|
2262
|
+
const message = [
|
|
2263
|
+
...found.map(
|
|
2264
|
+
(refused) => `${refused.code}: ${refused.name} from "${refused.source}" is not available on the Wasm engine (${where}:${refused.line}:${refused.column + 1}).`
|
|
2265
|
+
),
|
|
2266
|
+
OVERRIDE
|
|
2267
|
+
].join("\n");
|
|
2268
|
+
if (mode === "warn") {
|
|
2269
|
+
this.warn(message);
|
|
2270
|
+
return null;
|
|
2271
|
+
}
|
|
2272
|
+
return this.error({
|
|
2273
|
+
message,
|
|
2274
|
+
id: file,
|
|
2275
|
+
loc: { file, line: first.line, column: first.column }
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
return {
|
|
2279
|
+
name: "threenative-engine-catalog",
|
|
2280
|
+
enforce: "pre",
|
|
2281
|
+
// A game booted in a worker (the kits' default page) bundles through `worker.plugins` only.
|
|
2282
|
+
config: () => ({
|
|
2283
|
+
worker: {
|
|
2284
|
+
plugins: () => [{ name: "threenative-engine-catalog-worker", enforce: "pre", transform }]
|
|
2285
|
+
}
|
|
2286
|
+
}),
|
|
2287
|
+
async configResolved(config) {
|
|
2288
|
+
root = config.root;
|
|
2289
|
+
const { engine } = await loadConfig(root);
|
|
2290
|
+
const off = engine !== "threenative" ? `engine ${engine}` : process.env.THREENATIVE_NATIVE_BUNDLE !== void 0 ? "native host bundle" : void 0;
|
|
2291
|
+
active = off === void 0;
|
|
2292
|
+
if (off !== void 0) console.info(`TN_ENGINE_CATALOG: off (${off})`);
|
|
2293
|
+
else if (mode === "warn")
|
|
2294
|
+
console.info(
|
|
2295
|
+
'TN_ENGINE_CATALOG: warn (mode "warn": a refused import is reported, and the page throws at its first use)'
|
|
2296
|
+
);
|
|
2297
|
+
},
|
|
2298
|
+
transform
|
|
2299
|
+
};
|
|
2300
|
+
}
|
|
2301
|
+
var DECODER_LOADER_ID = /[/\\]examples[/\\]jsm[/\\]loaders[/\\](?:KTX2Loader|DRACOLoader)\.js$/u;
|
|
2302
|
+
var DECODER_LIB_ASSET_URL = /new URL\(\s*(['"])\.\.\/libs\/([^'"]+)\1\s*,\s*import\.meta\.url\s*\)(?:\.toString\s*\(\s*\)|\.href\s*)?/gu;
|
|
2303
|
+
function rewriteDecoderAssetUrls(code) {
|
|
2304
|
+
return code.replace(DECODER_LIB_ASSET_URL, '"../libs/$2"');
|
|
2305
|
+
}
|
|
2306
|
+
var MARKER_RELATIVE = path8.join("node_modules", ".vite", "threenative-engine-build.json");
|
|
2307
|
+
function hashTree(hash, directory) {
|
|
2308
|
+
const entries = readdirSync(directory, { withFileTypes: true }).sort(
|
|
2309
|
+
(left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0
|
|
2310
|
+
);
|
|
2311
|
+
for (const entry of entries) {
|
|
2312
|
+
const full = path8.join(directory, entry.name);
|
|
2313
|
+
if (entry.isDirectory()) {
|
|
2314
|
+
hashTree(hash, full);
|
|
2315
|
+
} else if (entry.isFile()) {
|
|
2316
|
+
hash.update(path8.relative(directory, full));
|
|
2317
|
+
hash.update(readFileSync(full));
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
function hashEngineDist(projectRoot) {
|
|
2322
|
+
const scopeDir = path8.join(projectRoot, "node_modules", "@threenative");
|
|
2323
|
+
let packages;
|
|
2324
|
+
try {
|
|
2325
|
+
packages = readdirSync(scopeDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).map((entry) => entry.name).sort((left, right) => left < right ? -1 : left > right ? 1 : 0);
|
|
2326
|
+
} catch {
|
|
2327
|
+
return void 0;
|
|
2328
|
+
}
|
|
2329
|
+
const dists = [];
|
|
2330
|
+
for (const name of packages) {
|
|
2331
|
+
let packageDir = path8.join(scopeDir, name);
|
|
2332
|
+
try {
|
|
2333
|
+
packageDir = realpathSync(packageDir);
|
|
2334
|
+
} catch {
|
|
2335
|
+
continue;
|
|
2336
|
+
}
|
|
2337
|
+
const dist = path8.join(packageDir, "dist");
|
|
2338
|
+
if (existsSync(dist)) dists.push([name, dist]);
|
|
2339
|
+
}
|
|
2340
|
+
if (dists.length === 0) return void 0;
|
|
2341
|
+
const hash = createHash("sha256");
|
|
2342
|
+
for (const [name, dist] of dists) {
|
|
2343
|
+
hash.update(name);
|
|
2344
|
+
hashTree(hash, dist);
|
|
2345
|
+
}
|
|
2346
|
+
return hash.digest("hex");
|
|
2347
|
+
}
|
|
2348
|
+
function markerPath(projectRoot) {
|
|
2349
|
+
return path8.join(projectRoot, MARKER_RELATIVE);
|
|
2350
|
+
}
|
|
2351
|
+
function readMarker(file) {
|
|
2352
|
+
try {
|
|
2353
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
2354
|
+
} catch {
|
|
2355
|
+
return void 0;
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
function processIsAlive(pid) {
|
|
2359
|
+
if (pid === process.pid) return true;
|
|
2360
|
+
try {
|
|
2361
|
+
process.kill(pid, 0);
|
|
2362
|
+
return true;
|
|
2363
|
+
} catch (error) {
|
|
2364
|
+
return error.code === "EPERM";
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
function createEngineFreshnessPlugin() {
|
|
2368
|
+
let recordedHash;
|
|
2369
|
+
const rootOf = (config) => path8.resolve(config.root ?? process.cwd());
|
|
2370
|
+
return {
|
|
2371
|
+
name: "threenative-engine-freshness",
|
|
2372
|
+
config(config, env) {
|
|
2373
|
+
const resolve = { dedupe: ["three", "react", "react-dom"] };
|
|
2374
|
+
if (env.command !== "serve") return { resolve };
|
|
2375
|
+
const root = rootOf(config);
|
|
2376
|
+
recordedHash = hashEngineDist(root);
|
|
2377
|
+
const marker = recordedHash === void 0 ? void 0 : readMarker(markerPath(root));
|
|
2378
|
+
if (recordedHash === void 0 || marker === void 0 || marker.hash === recordedHash) {
|
|
2379
|
+
return { resolve };
|
|
2380
|
+
}
|
|
2381
|
+
if (processIsAlive(marker.pid)) {
|
|
2382
|
+
const where = marker.port === void 0 ? `pid ${marker.pid}` : `pid ${marker.pid} on port ${marker.port}`;
|
|
2383
|
+
const how = marker.port === void 0 ? "" : ` (lsof -ti tcp:${marker.port} | xargs -r kill)`;
|
|
2384
|
+
console.warn(
|
|
2385
|
+
`threenative: a dev server is still running at ${where}, serving engine build ${marker.hash.slice(0, 8)}; the installed build is ${recordedHash.slice(0, 8)}. Kill it before playing${how} \u2014 its tab renders yesterday's engine.`
|
|
2386
|
+
);
|
|
2387
|
+
}
|
|
2388
|
+
return { resolve, optimizeDeps: { force: true } };
|
|
2389
|
+
},
|
|
2390
|
+
transform(code, id) {
|
|
2391
|
+
if (!DECODER_LOADER_ID.test(id)) return null;
|
|
2392
|
+
const rewritten = rewriteDecoderAssetUrls(code);
|
|
2393
|
+
return rewritten === code ? null : { code: rewritten, map: null };
|
|
2394
|
+
},
|
|
2395
|
+
configureServer(server) {
|
|
2396
|
+
const root = rootOf(server.config);
|
|
2397
|
+
const file = markerPath(root);
|
|
2398
|
+
const writeBootMarker = (port) => {
|
|
2399
|
+
const hash = recordedHash ?? hashEngineDist(root);
|
|
2400
|
+
if (hash === void 0) return;
|
|
2401
|
+
mkdirSync(path8.dirname(file), { recursive: true });
|
|
2402
|
+
writeFileSync(
|
|
2403
|
+
file,
|
|
2404
|
+
JSON.stringify(
|
|
2405
|
+
port === void 0 ? { hash, pid: process.pid } : { hash, pid: process.pid, port }
|
|
2406
|
+
)
|
|
2407
|
+
);
|
|
2408
|
+
};
|
|
2409
|
+
const httpServer = server.httpServer;
|
|
2410
|
+
if (httpServer === void 0 || httpServer === null) {
|
|
2411
|
+
writeBootMarker(void 0);
|
|
2412
|
+
return;
|
|
2413
|
+
}
|
|
2414
|
+
httpServer.once("listening", () => {
|
|
2415
|
+
const address = httpServer.address();
|
|
2416
|
+
writeBootMarker(
|
|
2417
|
+
typeof address === "object" && address !== null && address.port !== void 0 ? address.port : void 0
|
|
2418
|
+
);
|
|
2419
|
+
});
|
|
2420
|
+
httpServer.once("close", () => {
|
|
2421
|
+
const marker = readMarker(file);
|
|
2422
|
+
if (marker?.pid === process.pid) rmSync(file, { force: true });
|
|
2423
|
+
});
|
|
2424
|
+
}
|
|
2425
|
+
};
|
|
2426
|
+
}
|
|
2225
2427
|
var ISOLATION_HEADERS = {
|
|
2226
2428
|
"Cross-Origin-Embedder-Policy": "require-corp",
|
|
2227
2429
|
"Cross-Origin-Opener-Policy": "same-origin"
|
|
@@ -2234,15 +2436,105 @@ var isolationMiddleware = (req, res, next) => {
|
|
|
2234
2436
|
function renderIsolationHeaders() {
|
|
2235
2437
|
return `/*
|
|
2236
2438
|
${Object.entries(ISOLATION_HEADERS).map(([key, value]) => ` ${key}: ${value}
|
|
2237
|
-
`).join("")}
|
|
2439
|
+
`).join("")}/assets/*
|
|
2440
|
+
Cache-Control: public, max-age=31536000, immutable
|
|
2441
|
+
`;
|
|
2442
|
+
}
|
|
2443
|
+
var ISOLATION_WORKER_FILE = "tn-isolation-sw.js";
|
|
2444
|
+
function renderIsolationWorker() {
|
|
2445
|
+
return `self.addEventListener("install", () => self.skipWaiting());
|
|
2446
|
+
self.addEventListener("activate", (event) => event.waitUntil(self.clients.claim()));
|
|
2447
|
+
self.addEventListener("fetch", (event) => {
|
|
2448
|
+
const request = event.request;
|
|
2449
|
+
if (request.cache === "only-if-cached" && request.mode !== "same-origin") return;
|
|
2450
|
+
event.respondWith(
|
|
2451
|
+
fetch(request).then((response) => {
|
|
2452
|
+
if (response.status === 0) return response;
|
|
2453
|
+
const headers = new Headers(response.headers);
|
|
2454
|
+
${Object.entries({ ...ISOLATION_HEADERS, "Cross-Origin-Resource-Policy": "cross-origin" }).map(
|
|
2455
|
+
([key, value]) => ` headers.set("${key}", "${value}");
|
|
2456
|
+
`
|
|
2457
|
+
).join(
|
|
2458
|
+
""
|
|
2459
|
+
)} return new Response(response.body, { headers, status: response.status, statusText: response.statusText });
|
|
2460
|
+
}),
|
|
2461
|
+
);
|
|
2462
|
+
});
|
|
2463
|
+
`;
|
|
2464
|
+
}
|
|
2465
|
+
var ISOLATION_BOOT = `<script>(() => {
|
|
2466
|
+
const key = "tnIsolationReload";
|
|
2467
|
+
const store = (use) => { try { return use(sessionStorage); } catch { return null; } };
|
|
2468
|
+
if (globalThis.crossOriginIsolated) return void store((s) => s.removeItem(key));
|
|
2469
|
+
if (!isSecureContext || !("serviceWorker" in navigator) || /[?&]tnIsolation=0(?:&|$)/.test(location.search)) return;
|
|
2470
|
+
globalThis.__tnIsolation = navigator.serviceWorker.register("${ISOLATION_WORKER_FILE}")
|
|
2471
|
+
.then(() => navigator.serviceWorker.ready)
|
|
2472
|
+
.then(() => {
|
|
2473
|
+
if (store((s) => s.getItem(key)) !== null) return void store((s) => s.removeItem(key));
|
|
2474
|
+
if (store((s) => (s.setItem(key, "1"), true)) !== true) return;
|
|
2475
|
+
location.reload();
|
|
2476
|
+
return new Promise(() => {});
|
|
2477
|
+
}, () => {});
|
|
2478
|
+
})();</script>`;
|
|
2479
|
+
function withBuildId(html) {
|
|
2480
|
+
const entry = /<script\b[^>]*\btype="module"[^>]*\bsrc="([^"]*\/assets\/[^"]+\.js)"/iu.exec(
|
|
2481
|
+
html
|
|
2482
|
+
)?.[1];
|
|
2483
|
+
if (entry === void 0) return html;
|
|
2484
|
+
return html.replace(
|
|
2485
|
+
/<script/iu,
|
|
2486
|
+
`<script>globalThis.__TN_BUILD_ID__ = ${JSON.stringify(entry).replaceAll("<", "\\u003c")};</script>
|
|
2487
|
+
<script`
|
|
2488
|
+
);
|
|
2489
|
+
}
|
|
2490
|
+
function withEnginePreload(html, bundle, threaded) {
|
|
2491
|
+
if (bundle === void 0) return html;
|
|
2492
|
+
const files = Object.values(bundle);
|
|
2493
|
+
const entry = /<script\b[^>]*\btype="module"[^>]*\bsrc="([^"]*)"/iu.exec(html)?.[1];
|
|
2494
|
+
const entryFile = files.find((file) => entry?.endsWith(file.fileName) === true);
|
|
2495
|
+
if (entry === void 0 || entryFile === void 0) return html;
|
|
2496
|
+
const base = entry.slice(0, entry.length - entryFile.fileName.length);
|
|
2497
|
+
const href = (test) => {
|
|
2498
|
+
const found = files.find(test);
|
|
2499
|
+
return found === void 0 ? void 0 : base + found.fileName;
|
|
2500
|
+
};
|
|
2501
|
+
const threads = href((file) => /tn-native-engine-web-threads-[^/]*\.wasm$/u.test(file.fileName));
|
|
2502
|
+
const plain = href(
|
|
2503
|
+
(file) => /tn-native-engine-web-(?!threads-)[^/]*\.wasm$/u.test(file.fileName)
|
|
2504
|
+
);
|
|
2505
|
+
const wasm = threaded ? threads : plain;
|
|
2506
|
+
if (wasm === void 0) return html;
|
|
2507
|
+
const rapier = href(
|
|
2508
|
+
(file) => file.type === "chunk" && file.moduleIds?.some((id) => id.includes("/@dimforge/rapier3d")) === true
|
|
2509
|
+
);
|
|
2510
|
+
const quote = (value) => JSON.stringify(value ?? null).replaceAll("<", "\\u003c");
|
|
2511
|
+
const script = `<script>(() => {
|
|
2512
|
+
const link = (rel, href, as) => {
|
|
2513
|
+
const tag = Object.assign(document.createElement("link"), { rel, href, crossOrigin: "anonymous" });
|
|
2514
|
+
if (as !== undefined) tag.as = as;
|
|
2515
|
+
return document.head.appendChild(tag);
|
|
2516
|
+
};
|
|
2517
|
+
if (${threaded} && !globalThis.crossOriginIsolated) return;
|
|
2518
|
+
const href = ${quote(wasm)};
|
|
2519
|
+
const store = (use) => { try { return use(localStorage); } catch { return null; } };
|
|
2520
|
+
if (store((s) => s.getItem("tnEngineWasm")) === href) return;
|
|
2521
|
+
const wasm = link("preload", href, "fetch");
|
|
2522
|
+
const rapier = ${quote(rapier)};
|
|
2523
|
+
wasm.onload = wasm.onerror = () => {
|
|
2524
|
+
store((s) => s.setItem("tnEngineWasm", href));
|
|
2525
|
+
if (rapier !== null) link("modulepreload", rapier);
|
|
2526
|
+
};
|
|
2527
|
+
})();</script>`;
|
|
2528
|
+
return html.replace(/<script/iu, `${script}
|
|
2529
|
+
<script`);
|
|
2238
2530
|
}
|
|
2239
2531
|
function htmlAttribute(value) {
|
|
2240
2532
|
return value.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<");
|
|
2241
2533
|
}
|
|
2242
2534
|
function publicUrl(root, value) {
|
|
2243
2535
|
if (value === void 0) return void 0;
|
|
2244
|
-
const relative =
|
|
2245
|
-
const normalized = relative.replaceAll(
|
|
2536
|
+
const relative = path8.isAbsolute(value) ? path8.relative(root, value) : value;
|
|
2537
|
+
const normalized = relative.replaceAll(path8.sep, "/").replace(/^public\//u, "");
|
|
2246
2538
|
return `/${normalized.replace(/^\//u, "")}`;
|
|
2247
2539
|
}
|
|
2248
2540
|
function manifestIcon(root, source, purpose) {
|
|
@@ -2315,11 +2607,17 @@ function createWebBrandPlugin() {
|
|
|
2315
2607
|
let root = process.cwd();
|
|
2316
2608
|
let config;
|
|
2317
2609
|
let engine;
|
|
2610
|
+
let threaded = false;
|
|
2611
|
+
const load = async (id) => {
|
|
2612
|
+
const code = await engine?.load(id) ?? null;
|
|
2613
|
+
if (id === WEB_ENGINE_ID && code !== null) threaded = true;
|
|
2614
|
+
return code;
|
|
2615
|
+
};
|
|
2318
2616
|
return {
|
|
2319
2617
|
name: "threenative-web-brand",
|
|
2320
2618
|
enforce: "pre",
|
|
2321
2619
|
async config(vite) {
|
|
2322
|
-
const loaded = await loadConfig(
|
|
2620
|
+
const loaded = await loadConfig(path8.resolve(vite.root ?? process.cwd()));
|
|
2323
2621
|
if (loaded.engine === "threenative" && process.env.THREENATIVE_NATIVE_BUNDLE === void 0)
|
|
2324
2622
|
return {
|
|
2325
2623
|
optimizeDeps: { exclude: ["three", "three/webgpu", "three/tsl", "three-mesh-bvh"] },
|
|
@@ -2332,7 +2630,7 @@ function createWebBrandPlugin() {
|
|
|
2332
2630
|
name: "threenative-web-engine-worker",
|
|
2333
2631
|
enforce: "pre",
|
|
2334
2632
|
resolveId: (source, importer) => engine?.resolveId(source, importer) ?? null,
|
|
2335
|
-
load
|
|
2633
|
+
load
|
|
2336
2634
|
}
|
|
2337
2635
|
]
|
|
2338
2636
|
}
|
|
@@ -2342,18 +2640,23 @@ function createWebBrandPlugin() {
|
|
|
2342
2640
|
resolveId(source, importer) {
|
|
2343
2641
|
return engine?.resolveId(source, importer) ?? null;
|
|
2344
2642
|
},
|
|
2345
|
-
|
|
2346
|
-
return engine?.load(id) ?? null;
|
|
2347
|
-
},
|
|
2643
|
+
load,
|
|
2348
2644
|
async configResolved(resolved) {
|
|
2349
2645
|
root = resolved.root;
|
|
2350
2646
|
config = await loadConfig(root);
|
|
2351
2647
|
if (config.engine === "threenative" && process.env.THREENATIVE_NATIVE_BUNDLE === void 0)
|
|
2352
|
-
engine = createWebEnginePlugin({
|
|
2648
|
+
engine = createWebEnginePlugin({
|
|
2649
|
+
root,
|
|
2650
|
+
engine: config.engine,
|
|
2651
|
+
strict: resolved.command !== "build"
|
|
2652
|
+
});
|
|
2353
2653
|
},
|
|
2354
|
-
transformIndexHtml(html) {
|
|
2654
|
+
transformIndexHtml(html, context) {
|
|
2355
2655
|
if (config === void 0) throw new Error("TN_WEB_BRAND_CONFIG_MISSING");
|
|
2356
|
-
|
|
2656
|
+
const output = withBuildId(updateLaunchMarkup(root, config, html));
|
|
2657
|
+
const isolated = threaded ? output.replace(/<script/iu, `${ISOLATION_BOOT}
|
|
2658
|
+
<script`) : output;
|
|
2659
|
+
return withEnginePreload(isolated, context?.bundle, threaded);
|
|
2357
2660
|
},
|
|
2358
2661
|
// Every page links the manifest, and only a build emits it: in dev Vite would answer the link
|
|
2359
2662
|
// with index.html, which the browser reports as a manifest syntax error on each load.
|
|
@@ -2378,6 +2681,12 @@ function createWebBrandPlugin() {
|
|
|
2378
2681
|
});
|
|
2379
2682
|
if (config.engine === "threenative")
|
|
2380
2683
|
this.emitFile({ fileName: "_headers", source: renderIsolationHeaders(), type: "asset" });
|
|
2684
|
+
if (threaded)
|
|
2685
|
+
this.emitFile({
|
|
2686
|
+
fileName: ISOLATION_WORKER_FILE,
|
|
2687
|
+
source: renderIsolationWorker(),
|
|
2688
|
+
type: "asset"
|
|
2689
|
+
});
|
|
2381
2690
|
}
|
|
2382
2691
|
};
|
|
2383
2692
|
}
|
|
@@ -2404,22 +2713,22 @@ var SHARED_AGENT_MARKER_LINE = /^<!--\s*(?:shared:\s*[^>]+|\/shared)\s*-->\r?\n?
|
|
|
2404
2713
|
var DEFAULT_TEMPLATE = "starter";
|
|
2405
2714
|
var SUPPORTED_PACKAGE_MANAGER = "pnpm@10.25.0";
|
|
2406
2715
|
function templateRoot() {
|
|
2407
|
-
return
|
|
2716
|
+
return path8.resolve(path8.dirname(fileURLToPath(import.meta.url)), "../templates");
|
|
2408
2717
|
}
|
|
2409
|
-
var LOADING_SOURCE_RELATIVE_PATH =
|
|
2718
|
+
var LOADING_SOURCE_RELATIVE_PATH = path8.join("src", "render", "loading.ts");
|
|
2410
2719
|
var LOADING_APPEARANCE_MARKER = "BEGIN THREENATIVE LOADING APPEARANCE";
|
|
2411
2720
|
var TEMPLATE_ICON_NAME = "icon.png";
|
|
2412
2721
|
var LOADING_APPEARANCE_BLOCK_PATTERN = /\/\* BEGIN THREENATIVE LOADING APPEARANCE \*\/[\s\S]*?\/\* END THREENATIVE LOADING APPEARANCE \*\//gu;
|
|
2413
2722
|
function discoverStampedTemplates(root = templateRoot()) {
|
|
2414
2723
|
return readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name).sort((left, right) => left.localeCompare(right)).filter((template) => {
|
|
2415
|
-
const file =
|
|
2724
|
+
const file = path8.join(root, template, LOADING_SOURCE_RELATIVE_PATH);
|
|
2416
2725
|
return existsSync(file) && readFileSync(file, "utf8").includes(LOADING_APPEARANCE_MARKER);
|
|
2417
2726
|
});
|
|
2418
2727
|
}
|
|
2419
2728
|
function canonicalLoadingPath(root = templateRoot()) {
|
|
2420
|
-
const local =
|
|
2729
|
+
const local = path8.resolve(root, "..", "template-assets", "loading.ts");
|
|
2421
2730
|
if (existsSync(local)) return local;
|
|
2422
|
-
return
|
|
2731
|
+
return path8.resolve(templateRoot(), "..", "template-assets", "loading.ts");
|
|
2423
2732
|
}
|
|
2424
2733
|
function loadingAppearanceBlock(source, file) {
|
|
2425
2734
|
const matches = source.match(LOADING_APPEARANCE_BLOCK_PATTERN) ?? [];
|
|
@@ -2436,25 +2745,36 @@ function stampLoadingSource(canonical, template) {
|
|
|
2436
2745
|
return canonical.replace(canonicalBlock, templateBlock);
|
|
2437
2746
|
}
|
|
2438
2747
|
var SHARED_RENDER_SOURCES = [
|
|
2748
|
+
// The backlight shader: mechanism every kit repeats, but its constants decide how a surface
|
|
2749
|
+
// looks, so it lives in `src/render/` (rule 3) and is stamped from one source rather than moved
|
|
2750
|
+
// into the engine.
|
|
2751
|
+
"src/render/backlightControls.ts",
|
|
2752
|
+
"src/render/backlightMaterial.ts",
|
|
2753
|
+
"src/render/atmosphere.ts",
|
|
2754
|
+
"src/render/gpuSky.ts",
|
|
2755
|
+
"src/render/kitExposure.ts",
|
|
2756
|
+
"src/render/temporalDetailStage.ts"
|
|
2757
|
+
];
|
|
2758
|
+
var ADDED_RENDER_SOURCES = [
|
|
2439
2759
|
"src/render/kitExposure.ts",
|
|
2440
2760
|
"src/render/temporalDetailStage.ts"
|
|
2441
2761
|
];
|
|
2442
2762
|
function canonicalRenderSourcePath(relativePath, root = templateRoot()) {
|
|
2443
|
-
const name =
|
|
2444
|
-
const local =
|
|
2763
|
+
const name = path8.basename(relativePath);
|
|
2764
|
+
const local = path8.resolve(root, "..", "template-assets", name);
|
|
2445
2765
|
if (existsSync(local)) return local;
|
|
2446
|
-
const starter =
|
|
2766
|
+
const starter = path8.resolve(root, "starter", relativePath);
|
|
2447
2767
|
if (existsSync(starter)) return starter;
|
|
2448
|
-
const shared =
|
|
2768
|
+
const shared = path8.resolve(templateRoot(), "..", "template-assets", name);
|
|
2449
2769
|
if (existsSync(shared)) return shared;
|
|
2450
|
-
return
|
|
2770
|
+
return path8.resolve(templateRoot(), "starter", relativePath);
|
|
2451
2771
|
}
|
|
2452
2772
|
async function restampSharedRenderCopies(root = templateRoot()) {
|
|
2453
2773
|
const stamped = [];
|
|
2454
2774
|
for (const relativePath of SHARED_RENDER_SOURCES) {
|
|
2455
2775
|
const canonical = await readFile(canonicalRenderSourcePath(relativePath, root), "utf8");
|
|
2456
2776
|
for (const template of readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name).sort((left, right) => left.localeCompare(right))) {
|
|
2457
|
-
const file =
|
|
2777
|
+
const file = path8.join(root, template, relativePath);
|
|
2458
2778
|
if (!existsSync(file)) continue;
|
|
2459
2779
|
await writeFile(file, canonical);
|
|
2460
2780
|
stamped.push(file);
|
|
@@ -2466,7 +2786,7 @@ async function restampTemplateLoadingCopies(root = templateRoot()) {
|
|
|
2466
2786
|
const canonical = await readFile(canonicalLoadingPath(root), "utf8");
|
|
2467
2787
|
const stamped = [];
|
|
2468
2788
|
for (const template of discoverStampedTemplates(root)) {
|
|
2469
|
-
const file =
|
|
2789
|
+
const file = path8.join(root, template, LOADING_SOURCE_RELATIVE_PATH);
|
|
2470
2790
|
const source = await readFile(file, "utf8");
|
|
2471
2791
|
await writeFile(file, stampLoadingSource(canonical, source));
|
|
2472
2792
|
stamped.push(file);
|
|
@@ -2474,19 +2794,19 @@ async function restampTemplateLoadingCopies(root = templateRoot()) {
|
|
|
2474
2794
|
return stamped;
|
|
2475
2795
|
}
|
|
2476
2796
|
async function stampTemplateLoading(target, template, root) {
|
|
2477
|
-
const sourcePath =
|
|
2797
|
+
const sourcePath = path8.join(template, LOADING_SOURCE_RELATIVE_PATH);
|
|
2478
2798
|
if (!existsSync(sourcePath)) return;
|
|
2479
2799
|
const source = await readFile(sourcePath, "utf8");
|
|
2480
2800
|
if (!source.includes("BEGIN THREENATIVE LOADING APPEARANCE")) return;
|
|
2481
2801
|
const canonical = await readFile(canonicalLoadingPath(root), "utf8");
|
|
2482
2802
|
await writeFile(
|
|
2483
|
-
|
|
2803
|
+
path8.join(target, LOADING_SOURCE_RELATIVE_PATH),
|
|
2484
2804
|
stampLoadingSource(canonical, source)
|
|
2485
2805
|
);
|
|
2486
2806
|
}
|
|
2487
2807
|
async function copyTemplateIcon(target, templateRootDirectory) {
|
|
2488
|
-
const source =
|
|
2489
|
-
|
|
2808
|
+
const source = path8.join(
|
|
2809
|
+
path8.dirname(templateRootDirectory),
|
|
2490
2810
|
"template-assets",
|
|
2491
2811
|
TEMPLATE_ICON_NAME
|
|
2492
2812
|
);
|
|
@@ -2495,18 +2815,18 @@ async function copyTemplateIcon(target, templateRootDirectory) {
|
|
|
2495
2815
|
`TN_TEMPLATE_ICON_MISSING: '${source}' is not in the package; every generated project needs the native icon asset.`
|
|
2496
2816
|
);
|
|
2497
2817
|
}
|
|
2498
|
-
const destination =
|
|
2499
|
-
await mkdir(
|
|
2818
|
+
const destination = path8.join(target, "public", TEMPLATE_ICON_NAME);
|
|
2819
|
+
await mkdir(path8.dirname(destination), { recursive: true });
|
|
2500
2820
|
await cp(source, destination, { errorOnExist: true, force: false });
|
|
2501
2821
|
}
|
|
2502
2822
|
async function copySharedAssets(target, templateRootDirectory) {
|
|
2503
|
-
const shared =
|
|
2823
|
+
const shared = path8.join(path8.dirname(templateRootDirectory), "template-assets", "assets");
|
|
2504
2824
|
if (!existsSync(shared)) return;
|
|
2505
|
-
const source =
|
|
2825
|
+
const source = path8.join(target, "src");
|
|
2506
2826
|
const texts = [];
|
|
2507
2827
|
const walk = async (directory) => {
|
|
2508
2828
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
2509
|
-
const file =
|
|
2829
|
+
const file = path8.join(directory, entry.name);
|
|
2510
2830
|
if (entry.isDirectory()) await walk(file);
|
|
2511
2831
|
else if (/\.(?:ts|tsx)$/u.test(entry.name)) texts.push(await readFile(file, "utf8"));
|
|
2512
2832
|
}
|
|
@@ -2524,13 +2844,13 @@ async function copySharedAssets(target, templateRootDirectory) {
|
|
|
2524
2844
|
};
|
|
2525
2845
|
for (const name of names) {
|
|
2526
2846
|
if (!copied(name)) continue;
|
|
2527
|
-
const destination =
|
|
2528
|
-
await mkdir(
|
|
2529
|
-
await cp(
|
|
2847
|
+
const destination = path8.join(target, "assets", name);
|
|
2848
|
+
await mkdir(path8.dirname(destination), { recursive: true });
|
|
2849
|
+
await cp(path8.join(shared, name), destination, { errorOnExist: true, force: false });
|
|
2530
2850
|
}
|
|
2531
2851
|
}
|
|
2532
2852
|
async function copyQualityConfig(target, templateRootDirectory) {
|
|
2533
|
-
const shared =
|
|
2853
|
+
const shared = path8.join(path8.dirname(templateRootDirectory), "template-assets", "quality");
|
|
2534
2854
|
if (!existsSync(shared)) throw new Error(`TN_QUALITY_CONFIG_MISSING: ${shared}`);
|
|
2535
2855
|
await cp(shared, target, { errorOnExist: true, recursive: true });
|
|
2536
2856
|
}
|
|
@@ -2543,7 +2863,7 @@ function nonEmptyString2(value, field, file) {
|
|
|
2543
2863
|
return value;
|
|
2544
2864
|
}
|
|
2545
2865
|
function loadManifest(directory) {
|
|
2546
|
-
const file =
|
|
2866
|
+
const file = path8.join(directory, "kit.json");
|
|
2547
2867
|
let raw;
|
|
2548
2868
|
try {
|
|
2549
2869
|
raw = readFileSync(file, "utf8");
|
|
@@ -2561,7 +2881,7 @@ function loadManifest(directory) {
|
|
|
2561
2881
|
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
2562
2882
|
return invalidManifest(file, "the root must be an object");
|
|
2563
2883
|
const record = value;
|
|
2564
|
-
const directoryName =
|
|
2884
|
+
const directoryName = path8.basename(directory);
|
|
2565
2885
|
const name = nonEmptyString2(record.name, "name", file);
|
|
2566
2886
|
if (!TEMPLATE_NAME.test(name))
|
|
2567
2887
|
return invalidManifest(file, "name must match /^[a-z][a-z0-9-]*$/");
|
|
@@ -2581,7 +2901,7 @@ function loadManifest(directory) {
|
|
|
2581
2901
|
};
|
|
2582
2902
|
}
|
|
2583
2903
|
function discoverKitManifests(root = templateRoot()) {
|
|
2584
|
-
return readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => loadManifest(
|
|
2904
|
+
return readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => loadManifest(path8.join(root, entry.name))).sort((left, right) => left.name.localeCompare(right.name));
|
|
2585
2905
|
}
|
|
2586
2906
|
function discoverTemplateNames(root = templateRoot()) {
|
|
2587
2907
|
return discoverKitManifests(root).map(({ name }) => name);
|
|
@@ -2627,7 +2947,7 @@ function scaffoldNextSteps(target, installed, servers = []) {
|
|
|
2627
2947
|
function projectMcpServers(target) {
|
|
2628
2948
|
try {
|
|
2629
2949
|
return Object.keys(
|
|
2630
|
-
JSON.parse(readFileSync(
|
|
2950
|
+
JSON.parse(readFileSync(path8.join(target, ".mcp.json"), "utf8")).mcpServers ?? {}
|
|
2631
2951
|
);
|
|
2632
2952
|
} catch {
|
|
2633
2953
|
return [];
|
|
@@ -2706,12 +3026,21 @@ function cliHelp() {
|
|
|
2706
3026
|
`;
|
|
2707
3027
|
}
|
|
2708
3028
|
function packageName(target) {
|
|
2709
|
-
const name =
|
|
3029
|
+
const name = path8.basename(target).toLowerCase().replace(/[^a-z0-9-_]+/g, "-");
|
|
2710
3030
|
if (name.length === 0 || name === "-" || name === "_") {
|
|
2711
3031
|
throw new Error(`Cannot derive a package name from '${target}'.`);
|
|
2712
3032
|
}
|
|
2713
3033
|
return name;
|
|
2714
3034
|
}
|
|
3035
|
+
function templateReplacements(target) {
|
|
3036
|
+
const projectName = packageName(target);
|
|
3037
|
+
const compactProjectId = projectName.toLowerCase().replace(/[^a-z0-9]+/gu, "") || "game";
|
|
3038
|
+
const projectId = /^[a-z]/u.test(compactProjectId) ? compactProjectId : `game${compactProjectId}`;
|
|
3039
|
+
return Object.fromEntries([
|
|
3040
|
+
["__PROJECT_NAME__", projectName],
|
|
3041
|
+
["__PROJECT_ID__", projectId]
|
|
3042
|
+
]);
|
|
3043
|
+
}
|
|
2715
3044
|
async function isEmpty(directory) {
|
|
2716
3045
|
const entries = await readdir(directory).catch(
|
|
2717
3046
|
(error) => error?.code === "ENOENT" ? [] : void 0
|
|
@@ -2729,12 +3058,12 @@ function substituteTemplateVariables(content, replacements) {
|
|
|
2729
3058
|
async function renderTemplate(directory, replacements) {
|
|
2730
3059
|
const files = await readdir(directory, { withFileTypes: true });
|
|
2731
3060
|
for (const entry of files) {
|
|
2732
|
-
const source =
|
|
3061
|
+
const source = path8.join(directory, entry.name);
|
|
2733
3062
|
if (entry.isDirectory()) {
|
|
2734
3063
|
await renderTemplate(source, replacements);
|
|
2735
3064
|
continue;
|
|
2736
3065
|
}
|
|
2737
|
-
if (!TEXT_FILE_EXTENSIONS.has(
|
|
3066
|
+
if (!TEXT_FILE_EXTENSIONS.has(path8.extname(entry.name))) continue;
|
|
2738
3067
|
const content = await readFile(source, "utf8");
|
|
2739
3068
|
let rendered = substituteTemplateVariables(content, replacements);
|
|
2740
3069
|
if (entry.name === "AGENTS.md" || entry.name === "CLAUDE.md") {
|
|
@@ -2766,27 +3095,28 @@ var REFERENCE_TOKEN_PATTERN = new RegExp(
|
|
|
2766
3095
|
"gu"
|
|
2767
3096
|
);
|
|
2768
3097
|
async function linkClaudeSkills(target) {
|
|
2769
|
-
const stored =
|
|
3098
|
+
const stored = path8.join(target, ".agents", "skills");
|
|
2770
3099
|
if (!existsSync(stored)) return;
|
|
2771
|
-
const hostSkills =
|
|
2772
|
-
const subagents =
|
|
3100
|
+
const hostSkills = path8.join(target, ".claude", "skills");
|
|
3101
|
+
const subagents = path8.join(target, ".claude", "agents");
|
|
2773
3102
|
await mkdir(hostSkills, { recursive: true });
|
|
2774
3103
|
for (const entry of await readdir(stored, { withFileTypes: true })) {
|
|
2775
3104
|
if (!entry.isDirectory()) continue;
|
|
2776
|
-
if (existsSync(
|
|
2777
|
-
const link =
|
|
2778
|
-
|
|
3105
|
+
if (existsSync(path8.join(subagents, `${entry.name}.md`))) continue;
|
|
3106
|
+
const link = path8.join(hostSkills, entry.name);
|
|
3107
|
+
if (await lstat(link).catch(() => void 0)) continue;
|
|
3108
|
+
const relative = path8.relative(hostSkills, path8.join(stored, entry.name));
|
|
2779
3109
|
try {
|
|
2780
3110
|
await symlink(relative, link, "dir");
|
|
2781
3111
|
} catch (error) {
|
|
2782
3112
|
const code = error.code;
|
|
2783
3113
|
if (code !== "EPERM" && code !== "EACCES") throw error;
|
|
2784
|
-
await cp(
|
|
3114
|
+
await cp(path8.join(stored, entry.name), link, { recursive: true });
|
|
2785
3115
|
}
|
|
2786
3116
|
}
|
|
2787
3117
|
}
|
|
2788
3118
|
async function copyAgentFiles(target, templateRootDirectory) {
|
|
2789
|
-
const source =
|
|
3119
|
+
const source = path8.join(path8.dirname(templateRootDirectory), AGENT_FILES_DIRECTORY);
|
|
2790
3120
|
if (!existsSync(source)) {
|
|
2791
3121
|
throw new Error(
|
|
2792
3122
|
`TN_AGENT_FILES_MISSING: '${source}' is not in the package; every generated project needs the canonical agent roles.`
|
|
@@ -2796,7 +3126,7 @@ async function copyAgentFiles(target, templateRootDirectory) {
|
|
|
2796
3126
|
await linkClaudeSkills(target);
|
|
2797
3127
|
}
|
|
2798
3128
|
async function installAuthoringGitignore(target) {
|
|
2799
|
-
const file =
|
|
3129
|
+
const file = path8.join(target, ".gitignore");
|
|
2800
3130
|
const existing = existsSync(file) ? await readFile(file, "utf8") : "";
|
|
2801
3131
|
const present = new Set(existing.split(/\r?\n/u));
|
|
2802
3132
|
const missing = AUTHORING_GITIGNORE_RULES.filter((entry) => !present.has(entry));
|
|
@@ -2810,8 +3140,8 @@ async function installAuthoringGitignore(target) {
|
|
|
2810
3140
|
);
|
|
2811
3141
|
}
|
|
2812
3142
|
async function assertReferenceBundle(target, templateRootDirectory) {
|
|
2813
|
-
const bundleDirectory =
|
|
2814
|
-
|
|
3143
|
+
const bundleDirectory = path8.join(
|
|
3144
|
+
path8.dirname(templateRootDirectory),
|
|
2815
3145
|
"agent-docs",
|
|
2816
3146
|
"references"
|
|
2817
3147
|
);
|
|
@@ -2823,7 +3153,7 @@ async function assertReferenceBundle(target, templateRootDirectory) {
|
|
|
2823
3153
|
".agents/skills/threenative-assets/SKILL.md",
|
|
2824
3154
|
".claude/skills/threenative-assets/SKILL.md"
|
|
2825
3155
|
]) {
|
|
2826
|
-
const filePath =
|
|
3156
|
+
const filePath = path8.join(target, file);
|
|
2827
3157
|
if (existsSync(filePath)) await assertReferenceTargets(file, filePath, bundleDirectory);
|
|
2828
3158
|
}
|
|
2829
3159
|
}
|
|
@@ -2837,7 +3167,7 @@ async function assertReferenceTargets(from, filePath, bundleDirectory) {
|
|
|
2837
3167
|
`RED observed: referenced recipe missing: '${from}' names '${referenced}', which is not a shipped reference page.`
|
|
2838
3168
|
);
|
|
2839
3169
|
}
|
|
2840
|
-
if (!existsSync(
|
|
3170
|
+
if (!existsSync(path8.join(bundleDirectory, referenced))) {
|
|
2841
3171
|
throw new Error(
|
|
2842
3172
|
`RED observed: referenced recipe missing: '${from}' links '${REFERENCE_BUNDLE_PREFIX}${referenced}', which the package does not ship.`
|
|
2843
3173
|
);
|
|
@@ -2845,7 +3175,7 @@ async function assertReferenceTargets(from, filePath, bundleDirectory) {
|
|
|
2845
3175
|
}
|
|
2846
3176
|
}
|
|
2847
3177
|
async function applyPackageSources(target, packageSources) {
|
|
2848
|
-
const packagePath =
|
|
3178
|
+
const packagePath = path8.join(target, "package.json");
|
|
2849
3179
|
const packageJson = JSON.parse(await readFile(packagePath, "utf8"));
|
|
2850
3180
|
packageJson.packageManager = SUPPORTED_PACKAGE_MANAGER;
|
|
2851
3181
|
if (packageSources === void 0) {
|
|
@@ -2855,7 +3185,7 @@ async function applyPackageSources(target, packageSources) {
|
|
|
2855
3185
|
}
|
|
2856
3186
|
const localSource = (source) => {
|
|
2857
3187
|
const filePath = source.startsWith("file:") ? source.slice("file:".length) : source;
|
|
2858
|
-
return `file:${
|
|
3188
|
+
return `file:${path8.resolve(filePath)}`;
|
|
2859
3189
|
};
|
|
2860
3190
|
for (const [name, source] of Object.entries(packageSources)) {
|
|
2861
3191
|
if (source === void 0) continue;
|
|
@@ -2878,25 +3208,34 @@ async function applyPackageSources(target, packageSources) {
|
|
|
2878
3208
|
`);
|
|
2879
3209
|
}
|
|
2880
3210
|
var FRAMEWORK_PATCH_DIRECTORY = "patches";
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
3211
|
+
async function frameworkPatches(packageRoot) {
|
|
3212
|
+
const manifest = JSON.parse(
|
|
3213
|
+
await readFile(
|
|
3214
|
+
path8.join(packageRoot, "template-assets", FRAMEWORK_PATCH_DIRECTORY, "manifest.json"),
|
|
3215
|
+
"utf8"
|
|
3216
|
+
)
|
|
3217
|
+
);
|
|
3218
|
+
if (manifest.version !== 1 || !Array.isArray(manifest.patches)) {
|
|
3219
|
+
throw new Error("TN_FRAMEWORK_PATCH_MANIFEST: expected version 1 with a patches array.");
|
|
3220
|
+
}
|
|
3221
|
+
return manifest.patches;
|
|
3222
|
+
}
|
|
2886
3223
|
async function copyFrameworkPatches(target, templateRootDirectory) {
|
|
2887
|
-
const manifest = JSON.parse(await readFile(
|
|
2888
|
-
const packageRoot =
|
|
3224
|
+
const manifest = JSON.parse(await readFile(path8.join(target, "package.json"), "utf8"));
|
|
3225
|
+
const packageRoot = path8.dirname(templateRoot());
|
|
3226
|
+
const supported = await frameworkPatches(packageRoot);
|
|
3227
|
+
const repositoryRoot = path8.resolve(packageRoot, "..", "..");
|
|
2889
3228
|
for (const relative of Object.values(manifest.pnpm?.patchedDependencies ?? {})) {
|
|
2890
|
-
const name =
|
|
2891
|
-
const
|
|
2892
|
-
if (
|
|
3229
|
+
const name = path8.basename(relative);
|
|
3230
|
+
const patch = supported.find((candidate) => candidate.name === name);
|
|
3231
|
+
if (patch === void 0 || relative !== `${FRAMEWORK_PATCH_DIRECTORY}/${name}`) {
|
|
2893
3232
|
throw new Error(`TN_FRAMEWORK_PATCH_MISSING: unsupported template patch '${relative}'.`);
|
|
2894
3233
|
}
|
|
2895
|
-
const candidates = [.../* @__PURE__ */ new Set([
|
|
2896
|
-
(root) =>
|
|
3234
|
+
const candidates = [.../* @__PURE__ */ new Set([path8.dirname(templateRootDirectory), packageRoot])].map(
|
|
3235
|
+
(root) => path8.join(root, "template-assets", FRAMEWORK_PATCH_DIRECTORY, name)
|
|
2897
3236
|
);
|
|
2898
|
-
const canonical =
|
|
2899
|
-
if (existsSync(
|
|
3237
|
+
const canonical = path8.resolve(repositoryRoot, patch.source);
|
|
3238
|
+
if (existsSync(path8.join(packageRoot, "src", "index.ts"))) candidates.unshift(canonical);
|
|
2900
3239
|
else candidates.push(canonical);
|
|
2901
3240
|
const source = candidates.find((candidate) => existsSync(candidate));
|
|
2902
3241
|
if (source === void 0) {
|
|
@@ -2904,8 +3243,8 @@ async function copyFrameworkPatches(target, templateRootDirectory) {
|
|
|
2904
3243
|
`TN_FRAMEWORK_PATCH_MISSING: dependency patch '${name}' is absent from the CLI package.`
|
|
2905
3244
|
);
|
|
2906
3245
|
}
|
|
2907
|
-
const destination =
|
|
2908
|
-
await mkdir(
|
|
3246
|
+
const destination = path8.join(target, relative);
|
|
3247
|
+
await mkdir(path8.dirname(destination), { recursive: true });
|
|
2909
3248
|
await cp(source, destination);
|
|
2910
3249
|
}
|
|
2911
3250
|
}
|
|
@@ -2924,8 +3263,18 @@ function writeHostMcpConfigs(target) {
|
|
|
2924
3263
|
}
|
|
2925
3264
|
}
|
|
2926
3265
|
}
|
|
3266
|
+
function assertMcpShims(target) {
|
|
3267
|
+
if (!existsSync(path8.join(target, "node_modules"))) return;
|
|
3268
|
+
for (const [name, entry] of Object.entries(REQUIRED_MCP_SERVERS)) {
|
|
3269
|
+
if (existsSync(path8.resolve(target, entry))) continue;
|
|
3270
|
+
throw new Error(
|
|
3271
|
+
`MCP server '${name}' launches '${entry}', which this project does not have. Run 'pnpm install', or install one release of both: ${ENGINE_PAIR_UPGRADE}`
|
|
3272
|
+
);
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
2927
3275
|
async function assertMcpConfig(target) {
|
|
2928
|
-
|
|
3276
|
+
assertMcpShims(target);
|
|
3277
|
+
const configPath = path8.join(target, ".mcp.json");
|
|
2929
3278
|
const raw = await readFile(configPath, "utf8").catch(() => {
|
|
2930
3279
|
throw new Error(`Scaffold produced no .mcp.json at '${configPath}'.`);
|
|
2931
3280
|
});
|
|
@@ -2938,7 +3287,7 @@ async function assertMcpConfig(target) {
|
|
|
2938
3287
|
throw new Error(`'${configPath}' is missing required MCP server '${name}'.`);
|
|
2939
3288
|
}
|
|
2940
3289
|
}
|
|
2941
|
-
const manifest = JSON.parse(await readFile(
|
|
3290
|
+
const manifest = JSON.parse(await readFile(path8.join(target, "package.json"), "utf8"));
|
|
2942
3291
|
const declared = /* @__PURE__ */ new Set([
|
|
2943
3292
|
...Object.keys(manifest.dependencies ?? {}),
|
|
2944
3293
|
...Object.keys(manifest.devDependencies ?? {})
|
|
@@ -2972,7 +3321,7 @@ async function assertMcpConfig(target) {
|
|
|
2972
3321
|
);
|
|
2973
3322
|
}
|
|
2974
3323
|
}
|
|
2975
|
-
const codexPath =
|
|
3324
|
+
const codexPath = path8.join(target, ".codex", "config.toml");
|
|
2976
3325
|
const codex = await readFile(codexPath, "utf8").catch(() => {
|
|
2977
3326
|
throw new Error(`Scaffold produced no Codex MCP config at '${codexPath}'.`);
|
|
2978
3327
|
});
|
|
@@ -2982,6 +3331,149 @@ async function assertMcpConfig(target) {
|
|
|
2982
3331
|
}
|
|
2983
3332
|
}
|
|
2984
3333
|
}
|
|
3334
|
+
var AUTHORING_STAMP = path8.join(".threenative", "agent-files.json");
|
|
3335
|
+
var KIT_TITLE = /\bthe ([a-z][a-z0-9-]*) kit\b/u;
|
|
3336
|
+
var sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
3337
|
+
async function fileHash(file) {
|
|
3338
|
+
return readFile(file).then(sha256, () => void 0);
|
|
3339
|
+
}
|
|
3340
|
+
async function hashFiles(directory, relative = "") {
|
|
3341
|
+
const hashes = {};
|
|
3342
|
+
for (const entry of await readdir(path8.join(directory, relative), { withFileTypes: true })) {
|
|
3343
|
+
const next = path8.posix.join(relative, entry.name);
|
|
3344
|
+
if (entry.isDirectory()) Object.assign(hashes, await hashFiles(directory, next));
|
|
3345
|
+
else if (entry.isFile()) hashes[next] = sha256(await readFile(path8.join(directory, next)));
|
|
3346
|
+
}
|
|
3347
|
+
return hashes;
|
|
3348
|
+
}
|
|
3349
|
+
async function renderedAuthoringLayer(target, kit, root, directory) {
|
|
3350
|
+
const into = directory ?? await mkdtemp(path8.join(tmpdir(), "threenative-authoring-"));
|
|
3351
|
+
try {
|
|
3352
|
+
for (const file of ["AGENTS.md", "CLAUDE.md"])
|
|
3353
|
+
await cp(path8.join(root, kit, file), path8.join(into, file));
|
|
3354
|
+
await copyAgentFiles(into, root);
|
|
3355
|
+
await renderTemplate(into, templateReplacements(target));
|
|
3356
|
+
return await hashFiles(into);
|
|
3357
|
+
} finally {
|
|
3358
|
+
if (directory === void 0) await rm(into, { force: true, recursive: true });
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
function packageVersion(root) {
|
|
3362
|
+
const manifest = JSON.parse(
|
|
3363
|
+
readFileSync(path8.join(path8.dirname(root), "package.json"), "utf8")
|
|
3364
|
+
);
|
|
3365
|
+
if (typeof manifest.version !== "string")
|
|
3366
|
+
throw new Error("TN_AUTHORING_LAYER_VERSION: create-threenative has no version.");
|
|
3367
|
+
return manifest.version;
|
|
3368
|
+
}
|
|
3369
|
+
async function writeAuthoringStamp(target, kit, files, root) {
|
|
3370
|
+
const stamp = { createThreenative: packageVersion(root), kit, files };
|
|
3371
|
+
await mkdir(path8.join(target, path8.dirname(AUTHORING_STAMP)), { recursive: true });
|
|
3372
|
+
await writeFile(path8.join(target, AUTHORING_STAMP), `${JSON.stringify(stamp, null, 2)}
|
|
3373
|
+
`);
|
|
3374
|
+
}
|
|
3375
|
+
async function readJsonRecord(file) {
|
|
3376
|
+
const text = await readFile(file, "utf8").catch(() => void 0);
|
|
3377
|
+
if (text === void 0) return void 0;
|
|
3378
|
+
const value = JSON.parse(text);
|
|
3379
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
3380
|
+
throw new Error(`TN_AUTHORING_LAYER_STAMP: '${file}' is not a JSON object.`);
|
|
3381
|
+
return value;
|
|
3382
|
+
}
|
|
3383
|
+
async function gameKit(game, stamp, root) {
|
|
3384
|
+
const kits = discoverTemplateNames(root);
|
|
3385
|
+
const kitJson = (await readJsonRecord(path8.join(game, "kit.json")))?.name;
|
|
3386
|
+
const title = (await readFile(path8.join(game, "AGENTS.md"), "utf8").catch(() => "")).split("\n", 1)[0]?.trim();
|
|
3387
|
+
const titleKit = title === void 0 ? void 0 : KIT_TITLE.exec(title)?.[1] ?? title.split(" ").at(-1);
|
|
3388
|
+
return [stamp?.kit, kitJson, titleKit].find(
|
|
3389
|
+
(name) => typeof name === "string" && kits.includes(name)
|
|
3390
|
+
);
|
|
3391
|
+
}
|
|
3392
|
+
async function authoringContext(game, root) {
|
|
3393
|
+
const stamp = await readJsonRecord(path8.join(game, AUTHORING_STAMP));
|
|
3394
|
+
return { kit: await gameKit(game, stamp, root), stamp };
|
|
3395
|
+
}
|
|
3396
|
+
var NO_KIT = 'no stamp, kit.json or kit router title names a kit; write {"kit": "<kit>"} to .threenative/agent-files.json';
|
|
3397
|
+
var ENGINE_PAIR_UPGRADE = "pnpm up --latest create-threenative @threenative/*";
|
|
3398
|
+
async function installedCoreVersion(game) {
|
|
3399
|
+
const manifest = await readFile(
|
|
3400
|
+
path8.join(game, "node_modules", CORE_PACKAGE_NAME, "package.json"),
|
|
3401
|
+
"utf8"
|
|
3402
|
+
).catch(() => void 0);
|
|
3403
|
+
if (manifest === void 0) return void 0;
|
|
3404
|
+
try {
|
|
3405
|
+
const version = JSON.parse(manifest).version;
|
|
3406
|
+
return typeof version === "string" ? version : void 0;
|
|
3407
|
+
} catch {
|
|
3408
|
+
return void 0;
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
async function assertEnginePair(game) {
|
|
3412
|
+
const installed = await installedCoreVersion(game);
|
|
3413
|
+
if (installed === CORE_PACKAGE_VERSION) return;
|
|
3414
|
+
const got = installed === void 0 ? "no installed core" : `${CORE_PACKAGE_NAME}@${installed}`;
|
|
3415
|
+
throw new Error(
|
|
3416
|
+
`TN_AUTHORING_LAYER_PAIR: this create-threenative pairs with ${CORE_PACKAGE_NAME}@${CORE_PACKAGE_VERSION}, and this game installs ${got}. Run '${ENGINE_PAIR_UPGRADE}' first, then 'pnpm exec threenative doctor --fix'.`
|
|
3417
|
+
);
|
|
3418
|
+
}
|
|
3419
|
+
async function authoringLayerStatus(game, root = templateRoot()) {
|
|
3420
|
+
const installed = packageVersion(root);
|
|
3421
|
+
const { kit, stamp } = await authoringContext(game, root);
|
|
3422
|
+
const stamped = stamp?.createThreenative;
|
|
3423
|
+
const versions = { installed, ...stamped === void 0 ? {} : { stamped } };
|
|
3424
|
+
if (kit === void 0) return { ...versions, problem: NO_KIT, stale: [] };
|
|
3425
|
+
const expected = await renderedAuthoringLayer(game, kit, root);
|
|
3426
|
+
const stale = [];
|
|
3427
|
+
for (const [file, hash] of Object.entries(expected))
|
|
3428
|
+
if (await fileHash(path8.join(game, file)) !== hash) stale.push(file);
|
|
3429
|
+
for (const file of Object.keys(stamp?.files ?? {}))
|
|
3430
|
+
if (!(file in expected) && existsSync(path8.join(game, file))) stale.push(file);
|
|
3431
|
+
return { ...versions, kit, stale: stale.sort() };
|
|
3432
|
+
}
|
|
3433
|
+
async function fixAuthoringLayer(game, options, root = templateRoot()) {
|
|
3434
|
+
await assertEnginePair(game);
|
|
3435
|
+
assertMcpShims(game);
|
|
3436
|
+
const { kit, stamp } = await authoringContext(game, root);
|
|
3437
|
+
if (kit === void 0) throw new Error(`TN_AUTHORING_LAYER_KIT: ${NO_KIT}.`);
|
|
3438
|
+
const stamped = stamp?.files ?? {};
|
|
3439
|
+
const rendered = await mkdtemp(path8.join(tmpdir(), "threenative-authoring-"));
|
|
3440
|
+
const result = { deleted: [], kept: [], written: [] };
|
|
3441
|
+
try {
|
|
3442
|
+
const expected = await renderedAuthoringLayer(game, kit, root, rendered);
|
|
3443
|
+
for (const [file, hash] of Object.entries(expected).sort(
|
|
3444
|
+
([left], [right]) => left < right ? -1 : 1
|
|
3445
|
+
)) {
|
|
3446
|
+
const current = await fileHash(path8.join(game, file));
|
|
3447
|
+
if (current === hash) continue;
|
|
3448
|
+
if (current !== void 0 && current !== stamped[file] && !options.force) {
|
|
3449
|
+
result.kept.push(file);
|
|
3450
|
+
continue;
|
|
3451
|
+
}
|
|
3452
|
+
await mkdir(path8.dirname(path8.join(game, file)), { recursive: true });
|
|
3453
|
+
await cp(path8.join(rendered, file), path8.join(game, file));
|
|
3454
|
+
result.written.push(file);
|
|
3455
|
+
}
|
|
3456
|
+
for (const file of Object.keys(stamped).sort()) {
|
|
3457
|
+
if (file in expected) continue;
|
|
3458
|
+
const current = await fileHash(path8.join(game, file));
|
|
3459
|
+
if (current === void 0) continue;
|
|
3460
|
+
if (current !== stamped[file] && !options.force) result.kept.push(file);
|
|
3461
|
+
else {
|
|
3462
|
+
await rm(path8.join(game, file));
|
|
3463
|
+
result.deleted.push(file);
|
|
3464
|
+
}
|
|
3465
|
+
}
|
|
3466
|
+
await linkClaudeSkills(game);
|
|
3467
|
+
writeHostMcpConfigs(game);
|
|
3468
|
+
await assertMcpConfig(game);
|
|
3469
|
+
await installAuthoringGitignore(game);
|
|
3470
|
+
await assertReferenceBundle(game, root);
|
|
3471
|
+
await writeAuthoringStamp(game, kit, expected, root);
|
|
3472
|
+
} finally {
|
|
3473
|
+
await rm(rendered, { force: true, recursive: true });
|
|
3474
|
+
}
|
|
3475
|
+
return result;
|
|
3476
|
+
}
|
|
2985
3477
|
async function runInstall(target) {
|
|
2986
3478
|
await new Promise((resolve, reject) => {
|
|
2987
3479
|
const child = spawn("pnpm", ["install"], { cwd: target, stdio: "inherit" });
|
|
@@ -2998,14 +3490,14 @@ async function discardScaffold(target, existedBefore) {
|
|
|
2998
3490
|
return;
|
|
2999
3491
|
}
|
|
3000
3492
|
for (const entry of await readdir(target)) {
|
|
3001
|
-
await rm(
|
|
3493
|
+
await rm(path8.join(target, entry), { force: true, recursive: true });
|
|
3002
3494
|
}
|
|
3003
3495
|
}
|
|
3004
3496
|
async function createProject(options, cwd = process.cwd(), root = templateRoot()) {
|
|
3005
3497
|
const manifests = discoverKitManifests(root);
|
|
3006
3498
|
const template = options.template ?? DEFAULT_TEMPLATE;
|
|
3007
3499
|
if (!manifests.some(({ name }) => name === template)) kitManifest(template, root);
|
|
3008
|
-
const target =
|
|
3500
|
+
const target = path8.resolve(cwd, options.target);
|
|
3009
3501
|
const targetExists = await isEmpty(target).catch(() => false);
|
|
3010
3502
|
if (!targetExists) {
|
|
3011
3503
|
throw new Error(`Target '${target}' already exists and is not empty.`);
|
|
@@ -3014,26 +3506,20 @@ async function createProject(options, cwd = process.cwd(), root = templateRoot()
|
|
|
3014
3506
|
await mkdir(target, { recursive: true });
|
|
3015
3507
|
const installed = options.install ?? true;
|
|
3016
3508
|
try {
|
|
3017
|
-
const source =
|
|
3509
|
+
const source = path8.join(root, template);
|
|
3018
3510
|
await cp(source, target, { recursive: true, errorOnExist: true });
|
|
3019
|
-
await rm(
|
|
3511
|
+
await rm(path8.join(target, "kit.json"), { force: true });
|
|
3020
3512
|
if (["starter", "collectathon", "adventure", "kart"].includes(template))
|
|
3021
|
-
for (const relative of
|
|
3022
|
-
await cp(canonicalRenderSourcePath(relative, root),
|
|
3513
|
+
for (const relative of ADDED_RENDER_SOURCES)
|
|
3514
|
+
await cp(canonicalRenderSourcePath(relative, root), path8.join(target, relative));
|
|
3023
3515
|
await copyTemplateIcon(target, root);
|
|
3024
3516
|
await copySharedAssets(target, root);
|
|
3025
3517
|
await copyQualityConfig(target, root);
|
|
3026
|
-
if (existsSync(
|
|
3027
|
-
await rename(
|
|
3518
|
+
if (existsSync(path8.join(target, "gitignore"))) {
|
|
3519
|
+
await rename(path8.join(target, "gitignore"), path8.join(target, ".gitignore"));
|
|
3028
3520
|
}
|
|
3029
3521
|
await installAuthoringGitignore(target);
|
|
3030
|
-
const
|
|
3031
|
-
const compactProjectId = projectName.toLowerCase().replace(/[^a-z0-9]+/gu, "") || "game";
|
|
3032
|
-
const projectId = /^[a-z]/u.test(compactProjectId) ? compactProjectId : `game${compactProjectId}`;
|
|
3033
|
-
const replacements = Object.fromEntries([
|
|
3034
|
-
["__PROJECT_NAME__", projectName],
|
|
3035
|
-
["__PROJECT_ID__", projectId]
|
|
3036
|
-
]);
|
|
3522
|
+
const replacements = templateReplacements(target);
|
|
3037
3523
|
await stampTemplateLoading(target, source, root);
|
|
3038
3524
|
await copyAgentFiles(target, root);
|
|
3039
3525
|
await renderTemplate(target, replacements);
|
|
@@ -3042,6 +3528,12 @@ async function createProject(options, cwd = process.cwd(), root = templateRoot()
|
|
|
3042
3528
|
writeHostMcpConfigs(target);
|
|
3043
3529
|
await assertMcpConfig(target);
|
|
3044
3530
|
await assertReferenceBundle(target, root);
|
|
3531
|
+
await writeAuthoringStamp(
|
|
3532
|
+
target,
|
|
3533
|
+
template,
|
|
3534
|
+
await renderedAuthoringLayer(target, template, root),
|
|
3535
|
+
root
|
|
3536
|
+
);
|
|
3045
3537
|
if (installed) await runInstall(target);
|
|
3046
3538
|
} catch (error) {
|
|
3047
3539
|
await discardScaffold(target, existedBefore);
|
|
@@ -3160,7 +3652,7 @@ async function main() {
|
|
|
3160
3652
|
);
|
|
3161
3653
|
}
|
|
3162
3654
|
var entryPath = process.argv[1];
|
|
3163
|
-
if (entryPath !== void 0 && existsSync(entryPath) && realpathSync(
|
|
3655
|
+
if (entryPath !== void 0 && existsSync(entryPath) && realpathSync(path8.resolve(entryPath)) === realpathSync(fileURLToPath(import.meta.url))) {
|
|
3164
3656
|
main().catch((error) => {
|
|
3165
3657
|
process.stderr.write(`${error instanceof Error ? error.message : String(error)}
|
|
3166
3658
|
`);
|
|
@@ -3168,4 +3660,4 @@ if (entryPath !== void 0 && existsSync(entryPath) && realpathSync(path7.resolve(
|
|
|
3168
3660
|
});
|
|
3169
3661
|
}
|
|
3170
3662
|
|
|
3171
|
-
export { SHARED_RENDER_SOURCES, canonicalLoadingPath, canonicalRenderSourcePath, cliHelp, createEngineFreshnessPlugin, createProject, createWebBrandPlugin, discoverKitManifests, discoverStampedTemplates, discoverTemplateNames, hashEngineDist, kitManifest, packageNameFromFlag, parseArgs, projectMcpServers, referenceDigest, renderWebManifest, restampSharedRenderCopies, restampTemplateLoadingCopies, scaffoldCompletionMessage, scaffoldNextSteps, stampLoadingSource, templateForGenre, templateRoot, webRuntimeDecoders };
|
|
3663
|
+
export { ADDED_RENDER_SOURCES, SHARED_RENDER_SOURCES, authoringLayerStatus, canonicalLoadingPath, canonicalRenderSourcePath, cliHelp, createEngineCatalogPlugin, createEngineFreshnessPlugin, createProject, createWebBrandPlugin, discoverKitManifests, discoverStampedTemplates, discoverTemplateNames, fixAuthoringLayer, hashEngineDist, kitManifest, packageNameFromFlag, parseArgs, projectMcpServers, referenceDigest, renderWebManifest, restampSharedRenderCopies, restampTemplateLoadingCopies, scaffoldCompletionMessage, scaffoldNextSteps, stampLoadingSource, templateForGenre, templateRoot, webRuntimeDecoders };
|