create-threenative 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +10 -2
- package/agent-docs/asset-mcp-loop.md +33 -0
- package/agent-docs/ctx-surface.md +69 -0
- package/agent-docs/engine-capabilities.md +4 -0
- package/agent-docs/framework-blocks-you.md +60 -0
- package/agent-docs/look-at-it-and-budget-the-look.md +27 -0
- package/agent-docs/performance-default.md +42 -0
- package/agent-docs/pixel-budget.md +20 -0
- package/agent-docs/playtest-fail-closed.md +23 -0
- package/agent-docs/references/assertion-reference.md +652 -0
- package/agent-docs/references/capability-reference.md +3279 -0
- package/agent-docs/references/capture-the-frame.md +53 -0
- package/agent-docs/references/ctx-cookbook.md +51 -0
- package/agent-docs/references/debug-surface.md +63 -0
- package/agent-docs/references/finding-assets.md +147 -0
- package/agent-docs/references/gameplay-recipes.md +54 -0
- package/agent-docs/references/menu-screens.md +69 -0
- package/agent-docs/references/mobile-memory-budget.md +87 -0
- package/agent-docs/references/sculpt-from-a-reference.md +39 -0
- package/agent-docs/references/visual-baseline.md +133 -0
- package/agent-docs/references/webview-ui.md +113 -0
- package/agent-docs/sculpt-loop.md +16 -0
- package/agent-files/.agents/skills/threenative-builder/SKILL.md +7 -0
- package/agent-files/.agents/skills/threenative-verifier/SKILL.md +7 -0
- package/agent-files/.claude/agents/threenative-builder.md +7 -0
- package/agent-files/.claude/agents/threenative-verifier.md +7 -0
- package/agent-files/.threenative/agents/builder.md +32 -0
- package/agent-files/.threenative/agents/verifier.md +31 -0
- package/agent-files/AGENT-ROLES.md +26 -0
- package/capabilities.json +3542 -0
- package/dist/index.d.ts +191 -3
- package/dist/index.js +1707 -73
- package/dist/threenative.d.ts +9 -2
- package/dist/threenative.js +1825 -148
- package/package.json +30 -6
- package/template-assets/loading.ts +315 -0
- package/template-assets/patches/three@0.185.1.patch +287 -0
- package/templates/action-rpg/.codex/config.toml +15 -0
- package/templates/action-rpg/.mcp.json +6 -2
- package/templates/action-rpg/AGENTS.md +370 -6
- package/templates/action-rpg/CLAUDE.md +370 -6
- package/templates/action-rpg/index.html +0 -1
- package/templates/action-rpg/package.json +15 -11
- package/templates/action-rpg/playtests/combat.playtest.json +23 -9
- package/templates/action-rpg/playtests/fail.playtest.json +3 -3
- package/templates/action-rpg/playtests/inventory.playtest.json +16 -10
- package/templates/action-rpg/playtests/performance.playtest.json +22 -0
- package/templates/action-rpg/playtests/progress.playtest.json +18 -13
- package/templates/action-rpg/playtests/win.playtest.json +10 -4
- package/templates/action-rpg/public/icon.png +0 -0
- package/templates/action-rpg/src/entities/Enemy.ts +14 -4
- package/templates/action-rpg/src/game.ts +21 -0
- package/templates/action-rpg/src/render/lighting.ts +6 -1
- package/templates/action-rpg/src/render/loading.ts +267 -42
- package/templates/action-rpg/src/render/postprocessing.ts +68 -15
- package/templates/action-rpg/src/render/worldEnvironment.ts +583 -0
- package/templates/action-rpg/src/scenes/Play.ts +49 -19
- package/templates/action-rpg/src/state.ts +4 -0
- package/templates/action-rpg/src/style.css +45 -1
- package/templates/action-rpg/src/ui/AbilityBar.tsx +9 -7
- package/templates/action-rpg/src/ui/App.tsx +9 -8
- package/templates/action-rpg/src/ui/CharacterPanel.tsx +10 -8
- package/templates/action-rpg/src/ui/GameUi.tsx +24 -0
- package/templates/action-rpg/src/ui/Hud.tsx +10 -8
- package/templates/action-rpg/src/ui/InventoryPanel.tsx +9 -7
- package/templates/action-rpg/src/ui/main.tsx +14 -0
- package/templates/action-rpg/threenative.config.ts +21 -8
- package/templates/action-rpg/vite.config.ts +32 -2
- package/templates/defense/.codex/config.toml +15 -0
- package/templates/defense/.mcp.json +6 -2
- package/templates/defense/AGENTS.md +371 -8
- package/templates/defense/CLAUDE.md +371 -8
- package/templates/defense/README.md +2 -1
- package/templates/defense/index.html +0 -1
- package/templates/defense/package.json +16 -12
- package/templates/defense/playtests/leak.playtest.json +9 -4
- package/templates/defense/playtests/performance.playtest.json +22 -0
- package/templates/defense/playtests/placement.playtest.json +5 -5
- package/templates/defense/playtests/pointer-placement.playtest.json +89 -0
- package/templates/defense/playtests/scan.playtest.json +3 -3
- package/templates/defense/playtests/survive.playtest.json +11 -6
- package/templates/defense/public/icon.png +0 -0
- package/templates/defense/src/attackers/Attacker.ts +28 -12
- package/templates/defense/src/game.ts +24 -2
- package/templates/defense/src/render/lighting.ts +6 -1
- package/templates/defense/src/render/loading.ts +263 -37
- package/templates/defense/src/render/postprocessing.ts +70 -13
- package/templates/defense/src/render/shapes.ts +38 -0
- package/templates/defense/src/render/worldEnvironment.ts +583 -0
- package/templates/defense/src/scenes/Defense.ts +109 -50
- package/templates/defense/src/state.ts +6 -0
- package/templates/defense/src/style.css +45 -1
- package/templates/defense/src/ui/App.tsx +9 -4
- package/templates/defense/src/ui/GameUi.tsx +20 -0
- package/templates/defense/src/ui/Hud.tsx +6 -5
- package/templates/defense/src/ui/main.tsx +14 -0
- package/templates/defense/threenative.config.ts +21 -8
- package/templates/defense/vite.config.ts +34 -1
- package/templates/minimal/.codex/config.toml +15 -0
- package/templates/minimal/.mcp.json +6 -2
- package/templates/minimal/AGENTS.md +360 -255
- package/templates/minimal/CLAUDE.md +360 -255
- package/templates/minimal/index.html +0 -1
- package/templates/minimal/package.json +14 -11
- package/templates/minimal/playtests/atmosphere.playtest.json +32 -0
- package/templates/minimal/playtests/play.playtest.json +17 -5
- package/templates/minimal/public/icon.png +0 -0
- package/templates/minimal/src/game.ts +1 -0
- package/templates/minimal/src/render/camera.ts +1 -1
- package/templates/minimal/src/render/hud.ts +24 -8
- package/templates/minimal/src/render/lighting.ts +23 -2
- package/templates/minimal/src/render/loading.ts +23 -103
- package/templates/minimal/src/render/postprocessing.ts +92 -14
- package/templates/minimal/src/render/sky.ts +37 -32
- package/templates/minimal/src/render/worldEnvironment.ts +583 -0
- package/templates/minimal/src/scenes/Play.ts +91 -13
- package/templates/minimal/src/state.ts +8 -1
- package/templates/minimal/threenative.config.ts +15 -10
- package/templates/minimal/vite.config.ts +28 -1
- package/templates/platformer/.codex/config.toml +15 -0
- package/templates/platformer/.mcp.json +6 -2
- package/templates/platformer/AGENTS.md +385 -130
- package/templates/platformer/CLAUDE.md +385 -130
- package/templates/platformer/index.html +0 -1
- package/templates/platformer/package.json +17 -14
- package/templates/platformer/playtests/avoidance.playtest.json +6 -1
- package/templates/platformer/playtests/branding.playtest.json +29 -0
- package/templates/platformer/playtests/buffer.playtest.json +1 -1
- package/templates/platformer/playtests/collect.playtest.json +1 -1
- package/templates/platformer/playtests/collision-layers.playtest.json +2 -2
- package/templates/platformer/playtests/coyote.playtest.json +42 -8
- package/templates/platformer/playtests/damage.playtest.json +4 -1
- package/templates/platformer/playtests/dash.playtest.json +2 -2
- package/templates/platformer/playtests/jump.playtest.json +2 -3
- package/templates/platformer/playtests/native/touch-controls.playtest.json +33 -0
- package/templates/platformer/playtests/oneway.playtest.json +1 -1
- package/templates/platformer/playtests/performance.playtest.json +6 -5
- package/templates/platformer/playtests/respawn.playtest.json +2 -2
- package/templates/platformer/playtests/stomp-rise.playtest.json +17 -3
- package/templates/platformer/playtests/stomp.playtest.json +11 -3
- package/templates/platformer/playtests/terminal-loop-fail.playtest.json +13 -4
- package/templates/platformer/playtests/terminal-loop-win.playtest.json +3 -3
- package/templates/platformer/playtests/touch-controls-web.playtest.json +46 -0
- package/templates/platformer/public/icon.png +0 -0
- package/templates/platformer/src/entities/Character.ts +16 -10
- package/templates/platformer/src/entities/Patrol.ts +5 -0
- package/templates/platformer/src/game.ts +24 -1
- package/templates/platformer/src/render/lighting.ts +6 -1
- package/templates/platformer/src/render/loading.ts +270 -61
- package/templates/platformer/src/render/postprocessing.ts +68 -15
- package/templates/platformer/src/render/touch-controls.ts +54 -36
- package/templates/platformer/src/render/worldEnvironment.ts +583 -0
- package/templates/platformer/src/scenes/Level.ts +47 -22
- package/templates/platformer/src/state.ts +4 -0
- package/templates/platformer/src/style.css +45 -1
- package/templates/platformer/src/ui/App.tsx +9 -4
- package/templates/platformer/src/ui/GameUi.tsx +20 -0
- package/templates/platformer/src/ui/Hud.tsx +6 -5
- package/templates/platformer/src/ui/main.tsx +14 -0
- package/templates/platformer/threenative.config.ts +20 -10
- package/templates/platformer/vite.config.ts +34 -1
- package/templates/racing/.codex/config.toml +15 -0
- package/templates/racing/.mcp.json +6 -2
- package/templates/racing/AGENTS.md +370 -6
- package/templates/racing/CLAUDE.md +370 -6
- package/templates/racing/index.html +0 -1
- package/templates/racing/package.json +16 -12
- package/templates/racing/playtests/boost.playtest.json +5 -5
- package/templates/racing/playtests/outcome.playtest.json +14 -4
- package/templates/racing/playtests/performance.playtest.json +22 -0
- package/templates/racing/playtests/ranking.playtest.json +2 -2
- package/templates/racing/playtests/rescue.playtest.json +12 -6
- package/templates/racing/playtests/reverse.playtest.json +3 -3
- package/templates/racing/playtests/shortcut.playtest.json +3 -3
- package/templates/racing/public/icon.png +0 -0
- package/templates/racing/src/game.ts +24 -1
- package/templates/racing/src/render/camera.ts +10 -6
- package/templates/racing/src/render/lighting.ts +6 -1
- package/templates/racing/src/render/loading.ts +291 -34
- package/templates/racing/src/render/postprocessing.ts +70 -13
- package/templates/racing/src/render/worldEnvironment.ts +583 -0
- package/templates/racing/src/scenes/Race.ts +68 -36
- package/templates/racing/src/state.ts +4 -0
- package/templates/racing/src/style.css +45 -1
- package/templates/racing/src/track/Lap.ts +20 -9
- package/templates/racing/src/track/Ranking.ts +53 -14
- package/templates/racing/src/track/Track.ts +29 -16
- package/templates/racing/src/track/TrackSector.ts +14 -4
- package/templates/racing/src/ui/App.tsx +9 -4
- package/templates/racing/src/ui/GameUi.tsx +20 -0
- package/templates/racing/src/ui/Hud.tsx +6 -5
- package/templates/racing/src/ui/main.tsx +14 -0
- package/templates/racing/threenative.config.ts +21 -8
- package/templates/racing/vite.config.ts +34 -1
- package/templates/sailing/.codex/config.toml +15 -0
- package/templates/sailing/.mcp.json +20 -0
- package/templates/sailing/AGENTS.md +388 -0
- package/templates/sailing/CLAUDE.md +390 -0
- package/templates/sailing/README.md +25 -0
- package/templates/sailing/index.html +12 -0
- package/templates/sailing/kit.json +7 -0
- package/templates/sailing/native-playtests/survives.playtest.json +21 -0
- package/templates/sailing/package.json +52 -0
- package/templates/sailing/playtests/fail.playtest.json +24 -0
- package/templates/sailing/playtests/performance.playtest.json +21 -0
- package/templates/sailing/playtests/survives.playtest.json +38 -0
- package/templates/sailing/playtests/win.playtest.json +31 -0
- package/templates/sailing/public/favicon.svg +5 -0
- package/templates/sailing/public/icon.png +0 -0
- package/templates/sailing/src/entities/Ship.ts +96 -0
- package/templates/sailing/src/game.ts +40 -0
- package/templates/sailing/src/main.ts +15 -0
- package/templates/sailing/src/render/camera.ts +21 -0
- package/templates/sailing/src/render/lighting.ts +36 -0
- package/templates/sailing/src/render/loading.ts +315 -0
- package/templates/sailing/src/render/materials.ts +28 -0
- package/templates/sailing/src/render/palette.ts +24 -0
- package/templates/sailing/src/render/postprocessing.ts +33 -0
- package/templates/sailing/src/render/props.ts +52 -0
- package/templates/sailing/src/render/sky.ts +32 -0
- package/templates/sailing/src/render/water-material.ts +14 -0
- package/templates/sailing/src/render/water-shaders.ts +12 -0
- package/templates/sailing/src/render/wave-nodes.ts +10 -0
- package/templates/sailing/src/render/worldEnvironment.ts +590 -0
- package/templates/sailing/src/scenes/Boot.ts +12 -0
- package/templates/sailing/src/scenes/Sailing.ts +106 -0
- package/templates/sailing/src/state.ts +10 -0
- package/templates/sailing/src/style.css +61 -0
- package/templates/sailing/src/ui/App.tsx +15 -0
- package/templates/sailing/src/ui/GameUi.tsx +12 -0
- package/templates/sailing/src/ui/Hud.tsx +55 -0
- package/templates/sailing/src/ui/Menu.tsx +30 -0
- package/templates/sailing/src/ui/main.tsx +7 -0
- package/templates/sailing/tailwind.config.ts +2 -0
- package/templates/sailing/threenative.config.ts +34 -0
- package/templates/sailing/tsconfig.json +17 -0
- package/templates/sailing/vite.config.ts +34 -0
- package/templates/shooter/.codex/config.toml +15 -0
- package/templates/shooter/.mcp.json +6 -2
- package/templates/shooter/AGENTS.md +373 -7
- package/templates/shooter/CLAUDE.md +373 -7
- package/templates/shooter/index.html +0 -1
- package/templates/shooter/package.json +16 -11
- package/templates/shooter/playtests/fail.playtest.json +5 -4
- package/templates/shooter/playtests/input-control.playtest.json +131 -0
- package/templates/shooter/playtests/per-item.playtest.json +59 -0
- package/templates/shooter/playtests/performance.playtest.json +22 -0
- package/templates/shooter/playtests/shooter.playtest.json +22 -18
- package/templates/shooter/playtests/survives.playtest.json +1 -1
- package/templates/shooter/public/favicon.svg +1 -1
- package/templates/shooter/public/icon.png +0 -0
- package/templates/shooter/src/game.ts +24 -1
- package/templates/shooter/src/main.ts +3 -13
- package/templates/shooter/src/render/camera.ts +62 -12
- package/templates/shooter/src/render/lighting.ts +6 -1
- package/templates/shooter/src/render/loading.ts +262 -33
- package/templates/shooter/src/render/palette.ts +1 -1
- package/templates/shooter/src/render/postprocessing.ts +68 -16
- package/templates/shooter/src/render/shapes.ts +178 -0
- package/templates/shooter/src/render/ui.css +34 -1
- package/templates/shooter/src/render/worldEnvironment.ts +583 -0
- package/templates/shooter/src/scenes/Play.ts +246 -73
- package/templates/shooter/src/state.ts +13 -0
- package/templates/shooter/src/style.css +26 -0
- package/templates/shooter/src/ui/App.tsx +10 -12
- package/templates/shooter/src/ui/GameUi.tsx +20 -0
- package/templates/shooter/src/ui/Hud.tsx +8 -10
- package/templates/shooter/src/ui/Menu.tsx +24 -9
- package/templates/shooter/src/ui/main.tsx +15 -0
- package/templates/shooter/src/weapons/Projectile.ts +21 -10
- package/templates/shooter/threenative.config.ts +21 -8
- package/templates/shooter/vite.config.ts +32 -2
- package/templates/starter/.codex/config.toml +15 -0
- package/templates/starter/.mcp.json +6 -2
- package/templates/starter/AGENTS.md +429 -326
- package/templates/starter/CLAUDE.md +429 -326
- package/templates/starter/assets/pickup.wav +0 -0
- package/templates/starter/gitignore +4 -0
- package/templates/starter/index.html +0 -1
- package/templates/starter/native-playtests/react-hud.playtest.json +20 -0
- package/templates/starter/native-playtests/render-chain.playtest.json +12 -0
- package/templates/starter/package.json +16 -12
- package/templates/starter/playtests/assets.playtest.json +65 -0
- package/templates/starter/playtests/buffer.playtest.json +59 -9
- package/templates/starter/playtests/cloth.playtest.json +113 -0
- package/templates/starter/playtests/coyote.playtest.json +60 -8
- package/templates/starter/playtests/forward.playtest.json +29 -4
- package/templates/starter/playtests/gameover.playtest.json +66 -0
- package/templates/starter/playtests/goal.playtest.json +67 -0
- package/templates/starter/playtests/hot-reload.playtest.json +48 -8
- package/templates/starter/playtests/look.playtest.json +34 -6
- package/templates/starter/playtests/models-baseline.png +0 -0
- package/templates/starter/playtests/models.playtest.json +74 -0
- package/templates/starter/playtests/monitoring.playtest.json +38 -7
- package/templates/starter/playtests/odometer.playtest.json +54 -0
- package/templates/starter/playtests/pause.playtest.json +27 -4
- package/templates/starter/playtests/play.playtest.json +43 -7
- package/templates/starter/playtests/respawn.playtest.json +46 -6
- package/templates/starter/playtests/restart.playtest.json +65 -10
- package/templates/starter/playtests/seed.playtest.json +44 -8
- package/templates/starter/playtests/survives.playtest.json +27 -4
- package/templates/starter/playtests/textures-baseline.png +0 -0
- package/templates/starter/playtests/textures.playtest.json +74 -0
- package/templates/starter/playtests/zoom-pinch.playtest.json +86 -0
- package/templates/starter/playtests/zoom-wheel.playtest.json +59 -0
- package/templates/starter/public/icon.png +0 -0
- package/templates/starter/src/entities/Goal.ts +122 -0
- package/templates/starter/src/entities/Player.ts +40 -2
- package/templates/starter/src/game.ts +25 -0
- package/templates/starter/src/render/camera.ts +31 -5
- package/templates/starter/src/render/easing.ts +5 -0
- package/templates/starter/src/render/effects/gradualBackground.ts +48 -0
- package/templates/starter/src/render/effects/lensDistortion.ts +43 -0
- package/templates/starter/src/render/effects/sparkle.ts +49 -0
- package/templates/starter/src/render/lighting.ts +6 -1
- package/templates/starter/src/render/loading.ts +315 -0
- package/templates/starter/src/render/materials.ts +17 -1
- package/templates/starter/src/render/pennant.ts +54 -0
- package/templates/starter/src/render/postprocessing.ts +46 -15
- package/templates/starter/src/render/scenery.ts +83 -0
- package/templates/starter/src/render/shapes.ts +9 -21
- package/templates/starter/src/render/worldEnvironment.ts +583 -0
- package/templates/starter/src/scenes/Play.ts +146 -36
- package/templates/starter/src/state.ts +12 -0
- package/templates/starter/src/style.css +45 -1
- package/templates/starter/src/ui/App.tsx +9 -6
- package/templates/starter/src/ui/GameUi.tsx +20 -0
- package/templates/starter/src/ui/Hud.tsx +52 -29
- package/templates/starter/src/ui/Menu.tsx +25 -23
- package/templates/starter/src/ui/main.tsx +14 -0
- package/templates/starter/threenative.config.ts +27 -9
- package/templates/starter/tools/look.mjs +109 -0
- package/templates/starter/vite.config.ts +32 -2
- package/templates/minimal/assets/.gitkeep +0 -0
- package/templates/minimal/public/.gitkeep +0 -0
- package/templates/platformer/assets/.gitkeep +0 -0
- package/templates/platformer/public/.gitkeep +0 -0
- package/templates/starter/assets/.gitkeep +0 -0
- package/templates/starter/public/.gitkeep +0 -0
- package/templates/starter/public/pickup.ogg +0 -0
- /package/templates/starter/{public → assets}/native-proof.glb +0 -0
- /package/templates/starter/{public → assets}/native-proof.png +0 -0
package/dist/index.js
CHANGED
|
@@ -1,25 +1,1459 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
2
3
|
import { spawn } from 'child_process';
|
|
3
|
-
import { existsSync, realpathSync, readdirSync, readFileSync } from 'fs';
|
|
4
|
-
import { mkdir, cp,
|
|
5
|
-
import
|
|
6
|
-
import { fileURLToPath } from 'url';
|
|
4
|
+
import { existsSync, realpathSync, readdirSync, readFileSync, rmSync, mkdirSync, writeFileSync } from 'fs';
|
|
5
|
+
import { mkdir, cp, rename, readFile, readdir, writeFile, access, unlink, stat } from 'fs/promises';
|
|
6
|
+
import path5 from 'path';
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
8
|
+
import { LoadingManager, Box3, Vector3 } from 'three';
|
|
9
|
+
import { createHash } from 'crypto';
|
|
10
|
+
import { createRequire as createRequire$1 } from 'module';
|
|
11
|
+
import { parsePng } from '@threenative/assets';
|
|
7
12
|
|
|
13
|
+
createRequire(import.meta.url);
|
|
14
|
+
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([".glb", ".gltf"]);
|
|
15
|
+
var CENTIMETRE_HEURISTIC_THRESHOLD = 10;
|
|
16
|
+
var RESOURCE_MIME_TYPES = {
|
|
17
|
+
".avif": "image/avif",
|
|
18
|
+
".gif": "image/gif",
|
|
19
|
+
".jpeg": "image/jpeg",
|
|
20
|
+
".jpg": "image/jpeg",
|
|
21
|
+
".png": "image/png",
|
|
22
|
+
".webp": "image/webp"
|
|
23
|
+
};
|
|
24
|
+
function vector(value) {
|
|
25
|
+
return { x: value.x, y: value.y, z: value.z };
|
|
26
|
+
}
|
|
27
|
+
function emptyBounds() {
|
|
28
|
+
return {
|
|
29
|
+
center: { x: 0, y: 0, z: 0 },
|
|
30
|
+
size: { x: 0, y: 0, z: 0 }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function longestAxis(size) {
|
|
34
|
+
const axes = [
|
|
35
|
+
{ axis: "X", value: size.x },
|
|
36
|
+
{ axis: "Y", value: size.y },
|
|
37
|
+
{ axis: "Z", value: size.z }
|
|
38
|
+
];
|
|
39
|
+
const result = axes.reduce(
|
|
40
|
+
(largest, current) => current.value > largest.value ? current : largest
|
|
41
|
+
);
|
|
42
|
+
return result.value > 0 ? result : void 0;
|
|
43
|
+
}
|
|
44
|
+
function installNodeGltfGlobals() {
|
|
45
|
+
const globals = globalThis;
|
|
46
|
+
const nodeGlobals = globals;
|
|
47
|
+
const previousSelf = globals.self;
|
|
48
|
+
const previousCreateImageBitmap = globals.createImageBitmap;
|
|
49
|
+
const previousProgressEvent = nodeGlobals.ProgressEvent;
|
|
50
|
+
const nodeUrl = URL;
|
|
51
|
+
const previousCreateObjectUrl = nodeUrl.createObjectURL;
|
|
52
|
+
if (globals.self === void 0) globals.self = globalThis;
|
|
53
|
+
if (globals.createImageBitmap === void 0) {
|
|
54
|
+
globals.createImageBitmap = async () => ({ close() {
|
|
55
|
+
}, height: 1, width: 1 });
|
|
56
|
+
}
|
|
57
|
+
if (previousProgressEvent === void 0) {
|
|
58
|
+
nodeGlobals.ProgressEvent = class {
|
|
59
|
+
constructor(type, init) {
|
|
60
|
+
this.type = type;
|
|
61
|
+
this.init = init;
|
|
62
|
+
}
|
|
63
|
+
type;
|
|
64
|
+
init;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (nodeUrl.createObjectURL === void 0) {
|
|
68
|
+
nodeUrl.createObjectURL = () => "blob:threenative-inspect";
|
|
69
|
+
}
|
|
70
|
+
return () => {
|
|
71
|
+
if (previousSelf === void 0) globals.self = void 0;
|
|
72
|
+
else globals.self = previousSelf;
|
|
73
|
+
if (previousCreateImageBitmap === void 0) globals.createImageBitmap = void 0;
|
|
74
|
+
else globals.createImageBitmap = previousCreateImageBitmap;
|
|
75
|
+
nodeGlobals.ProgressEvent = previousProgressEvent;
|
|
76
|
+
if (previousCreateObjectUrl === void 0) nodeUrl.createObjectURL = void 0;
|
|
77
|
+
else nodeUrl.createObjectURL = previousCreateObjectUrl;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function localResourcePath(baseDirectory, uri) {
|
|
81
|
+
if (/^(?:blob|data):/i.test(uri) || /^(?:https?:)?\/\//i.test(uri)) return void 0;
|
|
82
|
+
let decoded;
|
|
83
|
+
try {
|
|
84
|
+
decoded = decodeURIComponent(uri);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw new Error(`Invalid glTF resource URI "${uri}": ${String(error)}`);
|
|
87
|
+
}
|
|
88
|
+
return path5.resolve(baseDirectory, decoded);
|
|
89
|
+
}
|
|
90
|
+
function resourceMimeType(resourcePath, declared) {
|
|
91
|
+
return declared ?? RESOURCE_MIME_TYPES[path5.extname(resourcePath).toLowerCase()] ?? "application/octet-stream";
|
|
92
|
+
}
|
|
93
|
+
function gltfResourceReferences(document) {
|
|
94
|
+
const references = [];
|
|
95
|
+
for (const section of ["buffers", "images"]) {
|
|
96
|
+
const entries = document[section];
|
|
97
|
+
if (!Array.isArray(entries)) continue;
|
|
98
|
+
for (const entry of entries) {
|
|
99
|
+
if (!isObject(entry) || typeof entry.uri !== "string") continue;
|
|
100
|
+
references.push({
|
|
101
|
+
...typeof entry.mimeType === "string" ? { declared: entry.mimeType } : {},
|
|
102
|
+
uri: entry.uri
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return references;
|
|
107
|
+
}
|
|
108
|
+
async function readLocalResources(baseDirectory, references) {
|
|
109
|
+
const resources = /* @__PURE__ */ new Map();
|
|
110
|
+
for (const reference of references) {
|
|
111
|
+
const resourcePath = localResourcePath(baseDirectory, reference.uri);
|
|
112
|
+
if (resourcePath === void 0 || resources.has(resourcePath)) continue;
|
|
113
|
+
const resource = await readFile(resourcePath);
|
|
114
|
+
const mimeType = resourceMimeType(resourcePath, reference.declared);
|
|
115
|
+
resources.set(resourcePath, `data:${mimeType};base64,${resource.toString("base64")}`);
|
|
116
|
+
}
|
|
117
|
+
return resources;
|
|
118
|
+
}
|
|
119
|
+
async function localResourceResolver(file, data) {
|
|
120
|
+
if (path5.extname(file).toLowerCase() !== ".gltf") return (url) => url;
|
|
121
|
+
const document = JSON.parse(data.toString("utf8"));
|
|
122
|
+
const references = gltfResourceReferences(document);
|
|
123
|
+
const baseDirectory = path5.dirname(path5.resolve(file));
|
|
124
|
+
const resources = await readLocalResources(baseDirectory, references);
|
|
125
|
+
return (url) => {
|
|
126
|
+
const resourcePath = localResourcePath(baseDirectory, url);
|
|
127
|
+
return resourcePath === void 0 ? url : resources.get(resourcePath) ?? url;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
async function parseGltf(file, data) {
|
|
131
|
+
const restoreGlobals = installNodeGltfGlobals();
|
|
132
|
+
try {
|
|
133
|
+
const { GLTFLoader } = await import('three/addons/loaders/GLTFLoader.js');
|
|
134
|
+
const manager = new LoadingManager();
|
|
135
|
+
manager.setURLModifier(await localResourceResolver(file, data));
|
|
136
|
+
const loader = new GLTFLoader(manager);
|
|
137
|
+
const extension = path5.extname(file).toLowerCase();
|
|
138
|
+
const payload = extension === ".gltf" ? data.toString("utf8") : data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
139
|
+
const parsed = await loader.parseAsync(
|
|
140
|
+
payload,
|
|
141
|
+
`${path5.dirname(path5.resolve(file))}${path5.sep}`
|
|
142
|
+
);
|
|
143
|
+
const json = parsed.parser.json;
|
|
144
|
+
return {
|
|
145
|
+
animations: parsed.animations,
|
|
146
|
+
resourceCounts: {
|
|
147
|
+
...Array.isArray(json.meshes) ? { meshes: json.meshes.length } : {},
|
|
148
|
+
...Array.isArray(json.materials) ? { materials: json.materials.length } : {},
|
|
149
|
+
...Array.isArray(json.textures) ? { textures: json.textures.length } : {}
|
|
150
|
+
},
|
|
151
|
+
scene: parsed.scene
|
|
152
|
+
};
|
|
153
|
+
} finally {
|
|
154
|
+
restoreGlobals();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function isObject(value) {
|
|
158
|
+
return typeof value === "object" && value !== null;
|
|
159
|
+
}
|
|
160
|
+
function countSceneResources(scene) {
|
|
161
|
+
const materials = /* @__PURE__ */ new Set();
|
|
162
|
+
const textures = /* @__PURE__ */ new Set();
|
|
163
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
164
|
+
const collectTextures = (value) => {
|
|
165
|
+
if (!isObject(value)) return;
|
|
166
|
+
if (value.isTexture === true) {
|
|
167
|
+
textures.add(value);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (visited.has(value)) return;
|
|
171
|
+
visited.add(value);
|
|
172
|
+
for (const child of Object.values(value)) collectTextures(child);
|
|
173
|
+
};
|
|
174
|
+
const bones = [];
|
|
175
|
+
let meshes = 0;
|
|
176
|
+
scene.traverse((object) => {
|
|
177
|
+
const candidate = object;
|
|
178
|
+
if (candidate.isBone === true) bones.push(candidate.name || "(unnamed)");
|
|
179
|
+
if (candidate.isMesh !== true) return;
|
|
180
|
+
meshes += 1;
|
|
181
|
+
const material = candidate.material;
|
|
182
|
+
for (const surface of Array.isArray(material) ? material : [material]) {
|
|
183
|
+
if (isObject(surface)) {
|
|
184
|
+
materials.add(surface);
|
|
185
|
+
collectTextures(surface);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
return { bones, materials: materials.size, meshes, textures: textures.size };
|
|
190
|
+
}
|
|
191
|
+
function inspectScene(file, scene, animations, resourceCounts) {
|
|
192
|
+
scene.updateWorldMatrix(true, true);
|
|
193
|
+
const box = new Box3().setFromObject(scene);
|
|
194
|
+
const bounds = box.isEmpty() ? emptyBounds() : { center: vector(box.getCenter(new Vector3())), size: vector(box.getSize(new Vector3())) };
|
|
195
|
+
const largest = longestAxis(bounds.size);
|
|
196
|
+
const resources = countSceneResources(scene);
|
|
197
|
+
return {
|
|
198
|
+
bounds,
|
|
199
|
+
bones: resources.bones,
|
|
200
|
+
clips: animations.map((clip) => clip.name || "(unnamed)"),
|
|
201
|
+
file: path5.basename(file),
|
|
202
|
+
forwardAxis: largest === void 0 ? { axis: "unknown", basis: "none", direction: "unknown" } : { axis: largest.axis, basis: "longest geometry axis", direction: "unknown" },
|
|
203
|
+
materials: resourceCounts.materials ?? resources.materials,
|
|
204
|
+
meshes: resourceCounts.meshes ?? resources.meshes,
|
|
205
|
+
path: path5.resolve(file),
|
|
206
|
+
textures: resourceCounts.textures ?? resources.textures,
|
|
207
|
+
units: {
|
|
208
|
+
label: largest !== void 0 && largest.value > CENTIMETRE_HEURISTIC_THRESHOLD ? "likely centimetres" : "likely metres",
|
|
209
|
+
longestAxis: largest?.value ?? 0
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function inspectionFailure(file, error) {
|
|
214
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
215
|
+
return new Error(`TN_ASSET_INSPECT_FAILED: ${file}: ${detail}`);
|
|
216
|
+
}
|
|
217
|
+
function parseInspectArgs(argv) {
|
|
218
|
+
const positional = argv.filter((argument) => !argument.startsWith("-"));
|
|
219
|
+
const unknown = argv.filter((argument) => argument.startsWith("-") && argument !== "--json");
|
|
220
|
+
if (unknown.length > 0 || positional.length !== 1) {
|
|
221
|
+
throw new Error("Usage: npx create-threenative inspect <file.glb> [--json]");
|
|
222
|
+
}
|
|
223
|
+
const file = positional[0];
|
|
224
|
+
if (file === void 0)
|
|
225
|
+
throw new Error("Usage: npx create-threenative inspect <file.glb> [--json]");
|
|
226
|
+
return { file, json: argv.includes("--json") };
|
|
227
|
+
}
|
|
228
|
+
async function inspectAsset(file) {
|
|
229
|
+
const extension = path5.extname(file).toLowerCase();
|
|
230
|
+
if (!SUPPORTED_EXTENSIONS.has(extension)) {
|
|
231
|
+
throw new Error(`TN_ASSET_INSPECT_UNSUPPORTED: ${file}: expected a .glb or .gltf file.`);
|
|
232
|
+
}
|
|
233
|
+
let data;
|
|
234
|
+
try {
|
|
235
|
+
data = await readFile(file);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
throw inspectionFailure(file, error);
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
const parsed = await parseGltf(file, data);
|
|
241
|
+
return inspectScene(file, parsed.scene, parsed.animations, parsed.resourceCounts);
|
|
242
|
+
} catch (error) {
|
|
243
|
+
throw inspectionFailure(file, error);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function formatVector(value, separator) {
|
|
247
|
+
return [value.x, value.y, value.z].map((component) => component.toFixed(3)).join(separator);
|
|
248
|
+
}
|
|
249
|
+
function listOrNone(values) {
|
|
250
|
+
return values.length === 0 ? "(none)" : values.join(", ");
|
|
251
|
+
}
|
|
252
|
+
function formatAssetInspection(result) {
|
|
253
|
+
const forward = result.forwardAxis.axis === "unknown" ? "unknown (glTF has no forward-axis metadata)" : `${result.forwardAxis.axis} (inferred from geometry; sign unknown)`;
|
|
254
|
+
const bones = result.bones.length === 0 ? "(none)" : `${result.bones.join(", ")} (${result.bones.length})`;
|
|
255
|
+
return `${[
|
|
256
|
+
result.file,
|
|
257
|
+
` bounds ${formatVector(result.bounds.size, " x ")} (centre ${formatVector(result.bounds.center, ", ")})`,
|
|
258
|
+
` units ${result.units.label} \u2014 longest axis ${result.units.longestAxis.toFixed(1)}`,
|
|
259
|
+
` forward ${forward}`,
|
|
260
|
+
` clips ${listOrNone(result.clips)}`,
|
|
261
|
+
` bones ${bones}`,
|
|
262
|
+
` meshes ${result.meshes} materials ${result.materials} textures ${result.textures}`
|
|
263
|
+
].join("\n")}
|
|
264
|
+
`;
|
|
265
|
+
}
|
|
266
|
+
function inspectHelp() {
|
|
267
|
+
return `${[
|
|
268
|
+
"Usage: npx create-threenative inspect <file.glb> [--json]",
|
|
269
|
+
"",
|
|
270
|
+
"Read a glTF asset and report its bounds, units heuristic, axis observation, clips, bones,",
|
|
271
|
+
"meshes, materials and textures. The command never modifies the asset.",
|
|
272
|
+
"",
|
|
273
|
+
"Options:",
|
|
274
|
+
" --json Print the same inspection as machine-readable JSON."
|
|
275
|
+
].join("\n")}
|
|
276
|
+
`;
|
|
277
|
+
}
|
|
278
|
+
async function inspectCommand(argv, write = (text) => process.stdout.write(text)) {
|
|
279
|
+
const options = parseInspectArgs(argv);
|
|
280
|
+
const result = await inspectAsset(options.file);
|
|
281
|
+
write(options.json ? `${JSON.stringify(result, null, 2)}
|
|
282
|
+
` : formatAssetInspection(result));
|
|
283
|
+
return result;
|
|
284
|
+
}
|
|
285
|
+
var MARKER_RELATIVE = path5.join("node_modules", ".vite", "threenative-engine-build.json");
|
|
286
|
+
function hashTree(hash, directory) {
|
|
287
|
+
const entries = readdirSync(directory, { withFileTypes: true }).sort(
|
|
288
|
+
(left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0
|
|
289
|
+
);
|
|
290
|
+
for (const entry of entries) {
|
|
291
|
+
const full = path5.join(directory, entry.name);
|
|
292
|
+
if (entry.isDirectory()) {
|
|
293
|
+
hashTree(hash, full);
|
|
294
|
+
} else if (entry.isFile()) {
|
|
295
|
+
hash.update(path5.relative(directory, full));
|
|
296
|
+
hash.update(readFileSync(full));
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function hashEngineDist(projectRoot) {
|
|
301
|
+
const scopeDir = path5.join(projectRoot, "node_modules", "@threenative");
|
|
302
|
+
let packages;
|
|
303
|
+
try {
|
|
304
|
+
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);
|
|
305
|
+
} catch {
|
|
306
|
+
return void 0;
|
|
307
|
+
}
|
|
308
|
+
const dists = [];
|
|
309
|
+
for (const name of packages) {
|
|
310
|
+
let packageDir = path5.join(scopeDir, name);
|
|
311
|
+
try {
|
|
312
|
+
packageDir = realpathSync(packageDir);
|
|
313
|
+
} catch {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
const dist = path5.join(packageDir, "dist");
|
|
317
|
+
if (existsSync(dist)) dists.push([name, dist]);
|
|
318
|
+
}
|
|
319
|
+
if (dists.length === 0) return void 0;
|
|
320
|
+
const hash = createHash("sha256");
|
|
321
|
+
for (const [name, dist] of dists) {
|
|
322
|
+
hash.update(name);
|
|
323
|
+
hashTree(hash, dist);
|
|
324
|
+
}
|
|
325
|
+
return hash.digest("hex");
|
|
326
|
+
}
|
|
327
|
+
function markerPath(projectRoot) {
|
|
328
|
+
return path5.join(projectRoot, MARKER_RELATIVE);
|
|
329
|
+
}
|
|
330
|
+
function readMarker(file) {
|
|
331
|
+
try {
|
|
332
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
333
|
+
} catch {
|
|
334
|
+
return void 0;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function processIsAlive(pid) {
|
|
338
|
+
if (pid === process.pid) return true;
|
|
339
|
+
try {
|
|
340
|
+
process.kill(pid, 0);
|
|
341
|
+
return true;
|
|
342
|
+
} catch (error) {
|
|
343
|
+
return error.code === "EPERM";
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function createEngineFreshnessPlugin() {
|
|
347
|
+
let recordedHash;
|
|
348
|
+
const rootOf = (config) => path5.resolve(config.root ?? process.cwd());
|
|
349
|
+
return {
|
|
350
|
+
name: "threenative-engine-freshness",
|
|
351
|
+
apply: "serve",
|
|
352
|
+
config(config) {
|
|
353
|
+
const root = rootOf(config);
|
|
354
|
+
recordedHash = hashEngineDist(root);
|
|
355
|
+
const marker = recordedHash === void 0 ? void 0 : readMarker(markerPath(root));
|
|
356
|
+
if (recordedHash === void 0 || marker === void 0 || marker.hash === recordedHash) {
|
|
357
|
+
return void 0;
|
|
358
|
+
}
|
|
359
|
+
if (processIsAlive(marker.pid)) {
|
|
360
|
+
const where = marker.port === void 0 ? `pid ${marker.pid}` : `pid ${marker.pid} on port ${marker.port}`;
|
|
361
|
+
const how = marker.port === void 0 ? "" : ` (lsof -ti tcp:${marker.port} | xargs -r kill)`;
|
|
362
|
+
console.warn(
|
|
363
|
+
`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.`
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
return { optimizeDeps: { force: true } };
|
|
367
|
+
},
|
|
368
|
+
configureServer(server) {
|
|
369
|
+
const root = rootOf(server.config);
|
|
370
|
+
const file = markerPath(root);
|
|
371
|
+
const writeBootMarker = (port) => {
|
|
372
|
+
const hash = recordedHash ?? hashEngineDist(root);
|
|
373
|
+
if (hash === void 0) return;
|
|
374
|
+
mkdirSync(path5.dirname(file), { recursive: true });
|
|
375
|
+
writeFileSync(
|
|
376
|
+
file,
|
|
377
|
+
JSON.stringify(
|
|
378
|
+
port === void 0 ? { hash, pid: process.pid } : { hash, pid: process.pid, port }
|
|
379
|
+
)
|
|
380
|
+
);
|
|
381
|
+
};
|
|
382
|
+
const httpServer = server.httpServer;
|
|
383
|
+
if (httpServer === void 0 || httpServer === null) {
|
|
384
|
+
writeBootMarker(void 0);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
httpServer.once("listening", () => {
|
|
388
|
+
const address = httpServer.address();
|
|
389
|
+
writeBootMarker(
|
|
390
|
+
typeof address === "object" && address !== null && address.port !== void 0 ? address.port : void 0
|
|
391
|
+
);
|
|
392
|
+
});
|
|
393
|
+
httpServer.once("close", () => {
|
|
394
|
+
const marker = readMarker(file);
|
|
395
|
+
if (marker?.pid === process.pid) rmSync(file, { force: true });
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
var ORIENTATIONS = ["landscape", "portrait", "sensor"];
|
|
401
|
+
var CONFIG_FILE = "threenative.config.ts";
|
|
402
|
+
var ConfigFailure = class extends Error {
|
|
403
|
+
code;
|
|
404
|
+
context;
|
|
405
|
+
detail;
|
|
406
|
+
constructor(code, detail, context) {
|
|
407
|
+
super(`${code}: ${context === void 0 ? detail : formatContext(context, detail)}`);
|
|
408
|
+
this.name = "ConfigFailure";
|
|
409
|
+
this.code = code;
|
|
410
|
+
this.context = context;
|
|
411
|
+
this.detail = detail;
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
function formatContext(context, detail) {
|
|
415
|
+
return `${context.layer} layer failed for ${context.sources.map((source) => `'${source}'`).join(", ")} from '${context.cwd}'. Searched: ${context.searched.join(", ")}. ${detail} Fix: ${context.fix}`;
|
|
416
|
+
}
|
|
417
|
+
function fail(code, message) {
|
|
418
|
+
throw new ConfigFailure(code, message);
|
|
419
|
+
}
|
|
420
|
+
function isRecord(value) {
|
|
421
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
422
|
+
}
|
|
423
|
+
function assertRecord(value, group) {
|
|
424
|
+
if (value === void 0) return {};
|
|
425
|
+
if (!isRecord(value)) fail("TN_CONFIG_GROUP_INVALID", `${group} must be an object.`);
|
|
426
|
+
return value;
|
|
427
|
+
}
|
|
428
|
+
function assertKeys(value, group, allowed) {
|
|
429
|
+
for (const key of Object.keys(value)) {
|
|
430
|
+
if (!allowed.includes(key)) fail("TN_CONFIG_UNKNOWN_KEY", `${group}.${key} is not recognised.`);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function nonEmptyString(value, code, label) {
|
|
434
|
+
if (typeof value !== "string" || value.trim().length === 0)
|
|
435
|
+
fail(code, `${label} must be non-empty.`);
|
|
436
|
+
return value;
|
|
437
|
+
}
|
|
438
|
+
function booleanValue(value, fallback, code, label) {
|
|
439
|
+
if (value === void 0) return fallback;
|
|
440
|
+
if (typeof value !== "boolean") fail(code, `${label} must be true or false.`);
|
|
441
|
+
return value;
|
|
442
|
+
}
|
|
443
|
+
function positiveInteger(value, fallback, code, label) {
|
|
444
|
+
if (value === void 0) return fallback;
|
|
445
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
446
|
+
fail(code, `${label} must be a positive integer.`);
|
|
447
|
+
}
|
|
448
|
+
return value;
|
|
449
|
+
}
|
|
450
|
+
function maxFpsValue(value) {
|
|
451
|
+
if (value === void 0) return 60;
|
|
452
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > 1e3) {
|
|
453
|
+
fail(
|
|
454
|
+
"TN_CONFIG_MAX_FPS_INVALID",
|
|
455
|
+
"display.maxFps must be a whole number between 0 (uncapped) and 1000."
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
return value;
|
|
459
|
+
}
|
|
460
|
+
function packageDisplayName(manifest) {
|
|
461
|
+
if (typeof manifest.name !== "string" || manifest.name.trim().length === 0) {
|
|
462
|
+
fail("TN_CONFIG_PACKAGE_NAME_MISSING", "package.json must declare a non-empty name.");
|
|
463
|
+
}
|
|
464
|
+
const name = manifest.name.replace(/^@[^/]+\//u, "");
|
|
465
|
+
if (name.length === 0) fail("TN_CONFIG_PACKAGE_NAME_MISSING", "package.json name is incomplete.");
|
|
466
|
+
return name;
|
|
467
|
+
}
|
|
468
|
+
function defaultAppId(name) {
|
|
469
|
+
let segment = name.toLowerCase().replace(/[^a-z0-9]/gu, "") || "game";
|
|
470
|
+
if (!/^[a-z]/u.test(segment)) segment = `game${segment}`;
|
|
471
|
+
return `com.threenative.${segment}`;
|
|
472
|
+
}
|
|
473
|
+
function projectRequire(cwd) {
|
|
474
|
+
return createRequire$1(path5.join(cwd, "package.json"));
|
|
475
|
+
}
|
|
476
|
+
function configLoaderSearch(cwd) {
|
|
477
|
+
return [
|
|
478
|
+
path5.join(cwd, "node_modules", "vite"),
|
|
479
|
+
path5.join(cwd, "node_modules", "esbuild"),
|
|
480
|
+
path5.resolve(path5.dirname(fileURLToPath(import.meta.url)), "..", "node_modules", "esbuild")
|
|
481
|
+
];
|
|
482
|
+
}
|
|
483
|
+
var CONFIG_BUILD_COMMAND = "pnpm exec threenative build --target web";
|
|
484
|
+
function configContext(cwd, layer, sources, searched, fix) {
|
|
485
|
+
return { cwd, fix, layer, searched, sources };
|
|
486
|
+
}
|
|
487
|
+
function packageContext(cwd) {
|
|
488
|
+
const packagePath = path5.join(cwd, "package.json");
|
|
489
|
+
return configContext(
|
|
490
|
+
cwd,
|
|
491
|
+
"package manifest",
|
|
492
|
+
[packagePath],
|
|
493
|
+
[packagePath],
|
|
494
|
+
`repair '${packagePath}' and rerun ${CONFIG_BUILD_COMMAND}`
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
function loadingContext(cwd, sourcePath, fix) {
|
|
498
|
+
return configContext(
|
|
499
|
+
cwd,
|
|
500
|
+
"config loading",
|
|
501
|
+
[sourcePath],
|
|
502
|
+
configLoaderSearch(cwd),
|
|
503
|
+
fix ?? `fix '${sourcePath}' and rerun ${CONFIG_BUILD_COMMAND}`
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
function validationContext(cwd, sources) {
|
|
507
|
+
return configContext(
|
|
508
|
+
cwd,
|
|
509
|
+
"config validation",
|
|
510
|
+
sources,
|
|
511
|
+
[path5.join(cwd, "package.json"), path5.join(cwd, CONFIG_FILE)],
|
|
512
|
+
`fix '${path5.join(cwd, CONFIG_FILE)}' and rerun ${CONFIG_BUILD_COMMAND}`
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
function configFailure(code, context, detail) {
|
|
516
|
+
throw new ConfigFailure(code, detail, context);
|
|
517
|
+
}
|
|
518
|
+
function contextualize(error, context, fallbackCode) {
|
|
519
|
+
if (error instanceof ConfigFailure && error.context !== void 0) return error;
|
|
520
|
+
if (error instanceof ConfigFailure) return new ConfigFailure(error.code, error.detail, context);
|
|
521
|
+
return new ConfigFailure(
|
|
522
|
+
fallbackCode,
|
|
523
|
+
error instanceof Error ? error.message : String(error),
|
|
524
|
+
context
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
async function withConfigContext(context, fallbackCode, action) {
|
|
528
|
+
try {
|
|
529
|
+
return await action();
|
|
530
|
+
} catch (error) {
|
|
531
|
+
throw contextualize(error, context, fallbackCode);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function resolveEsbuild(cwd) {
|
|
535
|
+
const require2 = projectRequire(cwd);
|
|
536
|
+
try {
|
|
537
|
+
return require2.resolve("esbuild");
|
|
538
|
+
} catch {
|
|
539
|
+
try {
|
|
540
|
+
const vite = require2.resolve("vite");
|
|
541
|
+
return createRequire$1(vite).resolve("esbuild");
|
|
542
|
+
} catch {
|
|
543
|
+
try {
|
|
544
|
+
return createRequire$1(import.meta.url).resolve("esbuild");
|
|
545
|
+
} catch {
|
|
546
|
+
return void 0;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
async function importConfig(cwd) {
|
|
552
|
+
const sourcePath = path5.join(cwd, CONFIG_FILE);
|
|
553
|
+
try {
|
|
554
|
+
await access(sourcePath);
|
|
555
|
+
} catch {
|
|
556
|
+
return void 0;
|
|
557
|
+
}
|
|
558
|
+
const esbuildPath = resolveEsbuild(cwd);
|
|
559
|
+
if (esbuildPath === void 0) {
|
|
560
|
+
configFailure(
|
|
561
|
+
"TN_CONFIG_TRANSPILER_MISSING",
|
|
562
|
+
loadingContext(
|
|
563
|
+
cwd,
|
|
564
|
+
sourcePath,
|
|
565
|
+
`run pnpm add -D esbuild in '${cwd}' and rerun ${CONFIG_BUILD_COMMAND}`
|
|
566
|
+
),
|
|
567
|
+
// Not "install Vite": Vite 8 dropped esbuild for rolldown, so a project on it satisfies the
|
|
568
|
+
// old advice and still lands here. The templates ship esbuild explicitly for this reason;
|
|
569
|
+
// projects scaffolded before that do not.
|
|
570
|
+
"threenative.config.ts needs project-resolved esbuild; install esbuild."
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
let esbuild;
|
|
574
|
+
try {
|
|
575
|
+
esbuild = projectRequire(cwd)(esbuildPath);
|
|
576
|
+
} catch (error) {
|
|
577
|
+
configFailure(
|
|
578
|
+
"TN_CONFIG_TRANSPILER_MISSING",
|
|
579
|
+
loadingContext(
|
|
580
|
+
cwd,
|
|
581
|
+
sourcePath,
|
|
582
|
+
`run pnpm install in '${cwd}' and rerun ${CONFIG_BUILD_COMMAND}`
|
|
583
|
+
),
|
|
584
|
+
error instanceof Error ? error.message : String(error)
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
const context = loadingContext(cwd, sourcePath);
|
|
588
|
+
let source;
|
|
589
|
+
try {
|
|
590
|
+
source = await readFile(sourcePath, "utf8");
|
|
591
|
+
} catch (error) {
|
|
592
|
+
configFailure(
|
|
593
|
+
"TN_CONFIG_LOAD_FAILED",
|
|
594
|
+
context,
|
|
595
|
+
error instanceof Error ? error.message : String(error)
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
let code;
|
|
599
|
+
try {
|
|
600
|
+
code = esbuild.transformSync(source, {
|
|
601
|
+
format: "esm",
|
|
602
|
+
loader: "ts",
|
|
603
|
+
platform: "node",
|
|
604
|
+
target: "node20"
|
|
605
|
+
}).code;
|
|
606
|
+
} catch (error) {
|
|
607
|
+
configFailure(
|
|
608
|
+
"TN_CONFIG_TRANSPILE_FAILED",
|
|
609
|
+
context,
|
|
610
|
+
error instanceof Error ? error.message : String(error)
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
const compiledPath = path5.join(cwd, `.threenative.config.${process.pid}.${Date.now()}.mjs`);
|
|
614
|
+
try {
|
|
615
|
+
await writeFile(compiledPath, code, "utf8");
|
|
616
|
+
} catch (error) {
|
|
617
|
+
configFailure(
|
|
618
|
+
"TN_CONFIG_LOAD_FAILED",
|
|
619
|
+
context,
|
|
620
|
+
error instanceof Error ? error.message : String(error)
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
try {
|
|
624
|
+
let module;
|
|
625
|
+
try {
|
|
626
|
+
module = await import(`${pathToFileURL(compiledPath).href}?cache=${Date.now()}`);
|
|
627
|
+
} catch (error) {
|
|
628
|
+
configFailure(
|
|
629
|
+
"TN_CONFIG_LOAD_FAILED",
|
|
630
|
+
context,
|
|
631
|
+
error instanceof Error ? error.message : String(error)
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
if (!isRecord(module.default)) {
|
|
635
|
+
configFailure(
|
|
636
|
+
"TN_CONFIG_DEFAULT_MISSING",
|
|
637
|
+
context,
|
|
638
|
+
"the config did not default-export an object."
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
return module.default;
|
|
642
|
+
} finally {
|
|
643
|
+
await unlink(compiledPath).catch(() => void 0);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
async function readManifest(cwd) {
|
|
647
|
+
let parsed;
|
|
648
|
+
try {
|
|
649
|
+
parsed = JSON.parse(await readFile(path5.join(cwd, "package.json"), "utf8"));
|
|
650
|
+
} catch (error) {
|
|
651
|
+
fail("TN_CONFIG_PACKAGE_INVALID", error instanceof Error ? error.message : String(error));
|
|
652
|
+
}
|
|
653
|
+
if (!isRecord(parsed)) fail("TN_CONFIG_PACKAGE_INVALID", "package.json must contain an object.");
|
|
654
|
+
return parsed;
|
|
655
|
+
}
|
|
656
|
+
function packageNativeEntry(manifest) {
|
|
657
|
+
if (manifest.threenative === void 0) return void 0;
|
|
658
|
+
if (!isRecord(manifest.threenative)) {
|
|
659
|
+
fail("TN_CONFIG_PACKAGE_INVALID", "package.json.threenative must be an object.");
|
|
660
|
+
}
|
|
661
|
+
assertKeys(manifest.threenative, "package.json.threenative", ["nativeEntry"]);
|
|
662
|
+
const value = manifest.threenative.nativeEntry;
|
|
663
|
+
if (value === void 0) return void 0;
|
|
664
|
+
return nonEmptyString(value, "TN_NATIVE_ENTRY_MISSING", "package.json.threenative.nativeEntry");
|
|
665
|
+
}
|
|
666
|
+
function validateNativeEntry(value, cwd) {
|
|
667
|
+
const entry = nonEmptyString(value, "TN_NATIVE_ENTRY_MISSING", "nativeEntry");
|
|
668
|
+
if (path5.isAbsolute(entry)) {
|
|
669
|
+
fail("TN_CONFIG_NATIVE_ENTRY_INVALID", "nativeEntry must be project-relative.");
|
|
670
|
+
}
|
|
671
|
+
const resolved = path5.resolve(cwd, entry);
|
|
672
|
+
const relative = path5.relative(cwd, resolved);
|
|
673
|
+
if (relative === ".." || relative.startsWith(`..${path5.sep}`) || path5.isAbsolute(relative)) {
|
|
674
|
+
fail("TN_CONFIG_NATIVE_ENTRY_INVALID", "nativeEntry must stay inside the project.");
|
|
675
|
+
}
|
|
676
|
+
return entry;
|
|
677
|
+
}
|
|
678
|
+
async function validateApp(raw, name, cwd) {
|
|
679
|
+
const app = assertRecord(raw, "app");
|
|
680
|
+
assertKeys(app, "app", ["id", "name", "version", "build", "icon", "icons"]);
|
|
681
|
+
const id = app.id === void 0 ? defaultAppId(name) : nonEmptyString(app.id, "TN_CONFIG_APP_ID_INVALID", "app.id");
|
|
682
|
+
if (!/^[a-z][a-z0-9]*(?:\.[a-z][a-z0-9]*)+$/u.test(id)) {
|
|
683
|
+
fail("TN_CONFIG_APP_ID_INVALID", "app.id must be a lower-case reverse-DNS identifier.");
|
|
684
|
+
}
|
|
685
|
+
const appName = app.name === void 0 ? name : nonEmptyString(app.name, "TN_CONFIG_APP_NAME_INVALID", "app.name");
|
|
686
|
+
const version = app.version === void 0 ? "0.1.13" : nonEmptyString(app.version, "TN_CONFIG_APP_VERSION_INVALID", "app.version");
|
|
687
|
+
if (!/^\d+\.\d+\.\d+$/u.test(version)) {
|
|
688
|
+
fail(
|
|
689
|
+
"TN_CONFIG_APP_VERSION_INVALID",
|
|
690
|
+
"app.version must contain three period-separated integer components."
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
const build = positiveInteger(app.build, 1, "TN_CONFIG_APP_BUILD_INVALID", "app.build");
|
|
694
|
+
const icon = app.icon === void 0 ? void 0 : await validateProjectAsset(app.icon, cwd, "app.icon", {
|
|
695
|
+
codePrefix: "TN_CONFIG_ICON",
|
|
696
|
+
formats: ["png"],
|
|
697
|
+
square: true
|
|
698
|
+
});
|
|
699
|
+
const icons = await validateIconVariants(app.icons, cwd);
|
|
700
|
+
if (icons?.android !== void 0 && icon === void 0 && icons.android.foreground === void 0) {
|
|
701
|
+
fail(
|
|
702
|
+
"TN_CONFIG_BRAND_ANDROID_FOREGROUND_MISSING",
|
|
703
|
+
"app.icons.android.foreground is required when app.icon is not declared."
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
return {
|
|
707
|
+
id,
|
|
708
|
+
name: appName,
|
|
709
|
+
version,
|
|
710
|
+
build,
|
|
711
|
+
...icon === void 0 ? {} : { icon },
|
|
712
|
+
...icons === void 0 ? {} : { icons }
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
async function validateProjectAsset(raw, cwd, label, options) {
|
|
716
|
+
const relative = nonEmptyString(raw, `${options.codePrefix}_INVALID`, label);
|
|
717
|
+
if (path5.isAbsolute(relative)) {
|
|
718
|
+
fail(`${options.codePrefix}_PATH_INVALID`, `${label} must be project-relative: ${relative}`);
|
|
719
|
+
}
|
|
720
|
+
const resolved = path5.resolve(cwd, relative);
|
|
721
|
+
const withinProject = path5.relative(cwd, resolved);
|
|
722
|
+
if (withinProject === ".." || withinProject.startsWith(`..${path5.sep}`) || path5.isAbsolute(withinProject)) {
|
|
723
|
+
fail(
|
|
724
|
+
`${options.codePrefix}_PATH_INVALID`,
|
|
725
|
+
`${label} must stay inside the project: ${relative}`
|
|
726
|
+
);
|
|
727
|
+
}
|
|
728
|
+
const extension = path5.extname(relative).slice(1).toLowerCase();
|
|
729
|
+
if (!options.formats.includes(extension)) {
|
|
730
|
+
fail(
|
|
731
|
+
options.codePrefix === "TN_CONFIG_ICON" ? `${options.codePrefix}_INVALID` : `${options.codePrefix}_FORMAT_INVALID`,
|
|
732
|
+
`${label} must use ${options.formats.map((format) => `.${format}`).join(" or ")}: ${relative}`
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
let info;
|
|
736
|
+
try {
|
|
737
|
+
info = await stat(resolved);
|
|
738
|
+
} catch {
|
|
739
|
+
fail(`${options.codePrefix}_MISSING`, `${label} does not exist: ${relative}`);
|
|
740
|
+
}
|
|
741
|
+
if (!info.isFile()) fail(`${options.codePrefix}_MISSING`, `${label} is not a file: ${relative}`);
|
|
742
|
+
let contents;
|
|
743
|
+
try {
|
|
744
|
+
contents = await readFile(resolved);
|
|
745
|
+
} catch (error) {
|
|
746
|
+
fail(
|
|
747
|
+
`${options.codePrefix}_INVALID`,
|
|
748
|
+
`${label} could not be read at ${relative}: ${error instanceof Error ? error.message : String(error)}`
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
if (extension === "svg") {
|
|
752
|
+
if (!/<svg(?:\s|>)/iu.test(contents.toString("utf8"))) {
|
|
753
|
+
fail(`${options.codePrefix}_INVALID`, `${label} is not a valid SVG file: ${relative}`);
|
|
754
|
+
}
|
|
755
|
+
return relative;
|
|
756
|
+
}
|
|
757
|
+
const png = parsePng(contents);
|
|
758
|
+
if (png === void 0) {
|
|
759
|
+
fail(`${options.codePrefix}_INVALID`, `${label} is not a valid PNG file: ${relative}`);
|
|
760
|
+
}
|
|
761
|
+
if (options.square === true && png.width !== png.height) {
|
|
762
|
+
fail(
|
|
763
|
+
`${options.codePrefix}_DIMENSIONS_INVALID`,
|
|
764
|
+
`${label} must be square (${png.width}x${png.height}): ${relative}`
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
if (options.requiresAlpha === true && !png.hasAlpha) {
|
|
768
|
+
fail(
|
|
769
|
+
`${options.codePrefix}_ALPHA_INVALID`,
|
|
770
|
+
`${label} must include an alpha channel: ${relative}`
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
return relative;
|
|
774
|
+
}
|
|
775
|
+
function validateBrandColor(raw, label) {
|
|
776
|
+
if (typeof raw !== "string" || !/^#[0-9a-f]{6}$/iu.test(raw)) {
|
|
777
|
+
fail("TN_CONFIG_BRAND_COLOR_INVALID", `${label} must be a #rrggbb colour.`);
|
|
778
|
+
}
|
|
779
|
+
return raw;
|
|
780
|
+
}
|
|
781
|
+
async function validateIconVariants(raw, cwd) {
|
|
782
|
+
if (raw === void 0) return void 0;
|
|
783
|
+
const icons = assertRecord(raw, "app.icons");
|
|
784
|
+
assertKeys(icons, "app.icons", ["android", "ios", "web"]);
|
|
785
|
+
const android = icons.android === void 0 ? void 0 : assertRecord(icons.android, "app.icons.android");
|
|
786
|
+
const ios = icons.ios === void 0 ? void 0 : assertRecord(icons.ios, "app.icons.ios");
|
|
787
|
+
const web = icons.web === void 0 ? void 0 : assertRecord(icons.web, "app.icons.web");
|
|
788
|
+
if (android !== void 0)
|
|
789
|
+
assertKeys(android, "app.icons.android", ["foreground", "background", "monochrome"]);
|
|
790
|
+
if (ios !== void 0) assertKeys(ios, "app.icons.ios", ["dark", "tinted"]);
|
|
791
|
+
if (web !== void 0)
|
|
792
|
+
assertKeys(web, "app.icons.web", ["favicon", "maskable", "monochrome", "appleTouch"]);
|
|
793
|
+
const androidResult = android === void 0 ? void 0 : {
|
|
794
|
+
...android.foreground === void 0 ? {} : {
|
|
795
|
+
foreground: await validateProjectAsset(
|
|
796
|
+
android.foreground,
|
|
797
|
+
cwd,
|
|
798
|
+
"app.icons.android.foreground",
|
|
799
|
+
{
|
|
800
|
+
codePrefix: "TN_CONFIG_BRAND_ANDROID_FOREGROUND",
|
|
801
|
+
formats: ["png"],
|
|
802
|
+
requiresAlpha: true,
|
|
803
|
+
square: true
|
|
804
|
+
}
|
|
805
|
+
)
|
|
806
|
+
},
|
|
807
|
+
...android.background === void 0 ? {} : {
|
|
808
|
+
background: validateBrandColor(android.background, "app.icons.android.background")
|
|
809
|
+
},
|
|
810
|
+
...android.monochrome === void 0 ? {} : {
|
|
811
|
+
monochrome: await validateProjectAsset(
|
|
812
|
+
android.monochrome,
|
|
813
|
+
cwd,
|
|
814
|
+
"app.icons.android.monochrome",
|
|
815
|
+
{
|
|
816
|
+
codePrefix: "TN_CONFIG_BRAND_ANDROID_MONOCHROME",
|
|
817
|
+
formats: ["png"],
|
|
818
|
+
requiresAlpha: true,
|
|
819
|
+
square: true
|
|
820
|
+
}
|
|
821
|
+
)
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
const iosResult = ios === void 0 ? void 0 : {
|
|
825
|
+
...ios.dark === void 0 ? {} : {
|
|
826
|
+
dark: await validateProjectAsset(ios.dark, cwd, "app.icons.ios.dark", {
|
|
827
|
+
codePrefix: "TN_CONFIG_BRAND_IOS_DARK",
|
|
828
|
+
formats: ["png"],
|
|
829
|
+
square: true
|
|
830
|
+
})
|
|
831
|
+
},
|
|
832
|
+
...ios.tinted === void 0 ? {} : {
|
|
833
|
+
tinted: await validateProjectAsset(ios.tinted, cwd, "app.icons.ios.tinted", {
|
|
834
|
+
codePrefix: "TN_CONFIG_BRAND_IOS_TINTED",
|
|
835
|
+
formats: ["png"],
|
|
836
|
+
square: true
|
|
837
|
+
})
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
const webResult = web === void 0 ? void 0 : {
|
|
841
|
+
...web.favicon === void 0 ? {} : {
|
|
842
|
+
favicon: await validateProjectAsset(web.favicon, cwd, "app.icons.web.favicon", {
|
|
843
|
+
codePrefix: "TN_CONFIG_BRAND_WEB_FAVICON",
|
|
844
|
+
formats: ["png", "svg"],
|
|
845
|
+
square: true
|
|
846
|
+
})
|
|
847
|
+
},
|
|
848
|
+
...web.maskable === void 0 ? {} : {
|
|
849
|
+
maskable: await validateProjectAsset(web.maskable, cwd, "app.icons.web.maskable", {
|
|
850
|
+
codePrefix: "TN_CONFIG_BRAND_WEB_MASKABLE",
|
|
851
|
+
formats: ["png"],
|
|
852
|
+
square: true
|
|
853
|
+
})
|
|
854
|
+
},
|
|
855
|
+
...web.monochrome === void 0 ? {} : {
|
|
856
|
+
monochrome: await validateProjectAsset(
|
|
857
|
+
web.monochrome,
|
|
858
|
+
cwd,
|
|
859
|
+
"app.icons.web.monochrome",
|
|
860
|
+
{
|
|
861
|
+
codePrefix: "TN_CONFIG_BRAND_WEB_MONOCHROME",
|
|
862
|
+
formats: ["png"],
|
|
863
|
+
square: true
|
|
864
|
+
}
|
|
865
|
+
)
|
|
866
|
+
},
|
|
867
|
+
...web.appleTouch === void 0 ? {} : {
|
|
868
|
+
appleTouch: await validateProjectAsset(
|
|
869
|
+
web.appleTouch,
|
|
870
|
+
cwd,
|
|
871
|
+
"app.icons.web.appleTouch",
|
|
872
|
+
{
|
|
873
|
+
codePrefix: "TN_CONFIG_BRAND_WEB_APPLE_TOUCH",
|
|
874
|
+
formats: ["png"],
|
|
875
|
+
square: true
|
|
876
|
+
}
|
|
877
|
+
)
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
return {
|
|
881
|
+
...androidResult === void 0 ? {} : { android: androidResult },
|
|
882
|
+
...iosResult === void 0 ? {} : { ios: iosResult },
|
|
883
|
+
...webResult === void 0 ? {} : { web: webResult }
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
function validateDisplay(raw) {
|
|
887
|
+
const display = assertRecord(raw, "display");
|
|
888
|
+
assertKeys(display, "display", ["orientation", "fullscreen", "keepScreenOn", "maxFps"]);
|
|
889
|
+
const orientation = display.orientation === void 0 ? "landscape" : display.orientation;
|
|
890
|
+
if (typeof orientation !== "string" || !ORIENTATIONS.includes(orientation)) {
|
|
891
|
+
fail(
|
|
892
|
+
"TN_NATIVE_ORIENTATION_INVALID",
|
|
893
|
+
"display.orientation must be landscape, portrait, or sensor."
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
return {
|
|
897
|
+
orientation,
|
|
898
|
+
fullscreen: booleanValue(
|
|
899
|
+
display.fullscreen,
|
|
900
|
+
true,
|
|
901
|
+
"TN_CONFIG_FULLSCREEN_INVALID",
|
|
902
|
+
"display.fullscreen"
|
|
903
|
+
),
|
|
904
|
+
keepScreenOn: booleanValue(
|
|
905
|
+
display.keepScreenOn,
|
|
906
|
+
false,
|
|
907
|
+
"TN_CONFIG_KEEP_SCREEN_ON_INVALID",
|
|
908
|
+
"display.keepScreenOn"
|
|
909
|
+
),
|
|
910
|
+
maxFps: maxFpsValue(display.maxFps)
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
function validateWindow(raw, appName) {
|
|
914
|
+
const window = assertRecord(raw, "window");
|
|
915
|
+
assertKeys(window, "window", ["title", "width", "height", "resizable"]);
|
|
916
|
+
return {
|
|
917
|
+
title: window.title === void 0 ? appName : nonEmptyString(window.title, "TN_CONFIG_WINDOW_TITLE_INVALID", "window.title"),
|
|
918
|
+
width: positiveInteger(window.width, 1280, "TN_CONFIG_WINDOW_WIDTH_INVALID", "window.width"),
|
|
919
|
+
height: positiveInteger(window.height, 720, "TN_CONFIG_WINDOW_HEIGHT_INVALID", "window.height"),
|
|
920
|
+
resizable: booleanValue(
|
|
921
|
+
window.resizable,
|
|
922
|
+
true,
|
|
923
|
+
"TN_CONFIG_WINDOW_RESIZABLE_INVALID",
|
|
924
|
+
"window.resizable"
|
|
925
|
+
)
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
async function validateBootSplash(raw, cwd) {
|
|
929
|
+
if (raw === void 0) return void 0;
|
|
930
|
+
const bootSplash = assertRecord(raw, "bootSplash");
|
|
931
|
+
assertKeys(bootSplash, "bootSplash", ["backgroundColor", "image"]);
|
|
932
|
+
const backgroundColor = bootSplash.backgroundColor === void 0 ? void 0 : validateBrandColor(bootSplash.backgroundColor, "bootSplash.backgroundColor");
|
|
933
|
+
const image = bootSplash.image === void 0 ? void 0 : await validateProjectAsset(bootSplash.image, cwd, "bootSplash.image", {
|
|
934
|
+
codePrefix: "TN_CONFIG_BRAND_SPLASH",
|
|
935
|
+
formats: ["png"]
|
|
936
|
+
});
|
|
937
|
+
return {
|
|
938
|
+
...backgroundColor === void 0 ? {} : { backgroundColor },
|
|
939
|
+
...image === void 0 ? {} : { image }
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
var UI_RENDERERS = ["native", "web"];
|
|
943
|
+
function validateUi(raw) {
|
|
944
|
+
const ui = assertRecord(raw, "ui");
|
|
945
|
+
assertKeys(ui, "ui", ["renderer"]);
|
|
946
|
+
const renderer = ui.renderer === void 0 ? "native" : ui.renderer;
|
|
947
|
+
if (typeof renderer !== "string" || !UI_RENDERERS.includes(renderer)) {
|
|
948
|
+
fail("TN_CONFIG_UI_RENDERER_INVALID", "ui.renderer must be web or native.");
|
|
949
|
+
}
|
|
950
|
+
return { renderer };
|
|
951
|
+
}
|
|
952
|
+
function validateRenderer(raw) {
|
|
953
|
+
const renderer = assertRecord(raw, "renderer");
|
|
954
|
+
assertKeys(renderer, "renderer", ["preferWebGPU", "resolutionScale", "antialias", "android"]);
|
|
955
|
+
const android = assertRecord(renderer.android, "renderer.android");
|
|
956
|
+
assertKeys(android, "renderer.android", ["resolutionScale", "antialias"]);
|
|
957
|
+
const resolutionScale = renderer.resolutionScale;
|
|
958
|
+
const androidResolutionScale = android.resolutionScale;
|
|
959
|
+
for (const [name, value] of [
|
|
960
|
+
["renderer.resolutionScale", resolutionScale],
|
|
961
|
+
["renderer.android.resolutionScale", androidResolutionScale]
|
|
962
|
+
]) {
|
|
963
|
+
if (value === void 0 || value === "auto") continue;
|
|
964
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0 || value > 1) {
|
|
965
|
+
fail(
|
|
966
|
+
"TN_CONFIG_RENDERER_RESOLUTION_SCALE_INVALID",
|
|
967
|
+
`${name} must be "auto" or a number within (0, 1].`
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
const antialias = booleanOrUndefined(renderer.antialias, "renderer.antialias");
|
|
972
|
+
const androidAntialias = booleanOrUndefined(android.antialias, "renderer.android.antialias");
|
|
973
|
+
const androidOverrides = {
|
|
974
|
+
...androidResolutionScale === void 0 ? {} : { resolutionScale: androidResolutionScale },
|
|
975
|
+
...androidAntialias === void 0 ? {} : { antialias: androidAntialias }
|
|
976
|
+
};
|
|
977
|
+
return {
|
|
978
|
+
preferWebGPU: booleanValue(
|
|
979
|
+
renderer.preferWebGPU,
|
|
980
|
+
true,
|
|
981
|
+
"TN_CONFIG_RENDERER_INVALID",
|
|
982
|
+
"renderer.preferWebGPU"
|
|
983
|
+
),
|
|
984
|
+
...antialias === void 0 ? {} : { antialias },
|
|
985
|
+
...resolutionScale === void 0 ? {} : { resolutionScale },
|
|
986
|
+
...Object.keys(androidOverrides).length === 0 ? {} : { android: androidOverrides }
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
function booleanOrUndefined(value, name) {
|
|
990
|
+
if (value === void 0) return void 0;
|
|
991
|
+
if (typeof value !== "boolean") fail("TN_CONFIG_RENDERER_INVALID", `${name} must be a boolean.`);
|
|
992
|
+
return value;
|
|
993
|
+
}
|
|
994
|
+
var ASSET_TARGET_KEYS = [
|
|
995
|
+
"maxMaterials",
|
|
996
|
+
"maxTriangles",
|
|
997
|
+
"maxTextureDimension"
|
|
998
|
+
];
|
|
999
|
+
function validateAssetTargets(raw) {
|
|
1000
|
+
const targets = assertRecord(raw, "assets.targets");
|
|
1001
|
+
assertKeys(targets, "assets.targets", ASSET_TARGET_KEYS);
|
|
1002
|
+
return {
|
|
1003
|
+
...targets.maxMaterials === void 0 ? {} : {
|
|
1004
|
+
maxMaterials: positiveInteger(
|
|
1005
|
+
targets.maxMaterials,
|
|
1006
|
+
1,
|
|
1007
|
+
"TN_CONFIG_ASSETS_INVALID",
|
|
1008
|
+
"assets.targets.maxMaterials"
|
|
1009
|
+
)
|
|
1010
|
+
},
|
|
1011
|
+
...targets.maxTriangles === void 0 ? {} : {
|
|
1012
|
+
maxTriangles: positiveInteger(
|
|
1013
|
+
targets.maxTriangles,
|
|
1014
|
+
1,
|
|
1015
|
+
"TN_CONFIG_ASSETS_INVALID",
|
|
1016
|
+
"assets.targets.maxTriangles"
|
|
1017
|
+
)
|
|
1018
|
+
},
|
|
1019
|
+
...targets.maxTextureDimension === void 0 ? {} : {
|
|
1020
|
+
maxTextureDimension: positiveInteger(
|
|
1021
|
+
targets.maxTextureDimension,
|
|
1022
|
+
1,
|
|
1023
|
+
"TN_CONFIG_ASSETS_INVALID",
|
|
1024
|
+
"assets.targets.maxTextureDimension"
|
|
1025
|
+
)
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
var ASSET_TEXTURE_KEYS = ["overrides", "quality"];
|
|
1030
|
+
var TEXTURE_OVERRIDE_KEYS = ["codec", "glob", "quality"];
|
|
1031
|
+
var TEXTURE_CODECS = ["etc1s", "none", "uastc"];
|
|
1032
|
+
function textureQuality(value, label) {
|
|
1033
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 1 || value > 255) {
|
|
1034
|
+
fail("TN_CONFIG_ASSETS_INVALID", `${label} must be an integer between 1 and 255.`);
|
|
1035
|
+
}
|
|
1036
|
+
return value;
|
|
1037
|
+
}
|
|
1038
|
+
function validateTextureOverrides(raw) {
|
|
1039
|
+
if (!Array.isArray(raw)) {
|
|
1040
|
+
fail("TN_CONFIG_ASSETS_INVALID", "assets.textures.overrides must be an array.");
|
|
1041
|
+
}
|
|
1042
|
+
return raw.map((item, index) => {
|
|
1043
|
+
if (!isRecord(item)) {
|
|
1044
|
+
fail(
|
|
1045
|
+
"TN_CONFIG_ASSETS_INVALID",
|
|
1046
|
+
`assets.textures.overrides[${String(index)}] must be an object.`
|
|
1047
|
+
);
|
|
1048
|
+
}
|
|
1049
|
+
assertKeys(item, `assets.textures.overrides[${String(index)}]`, TEXTURE_OVERRIDE_KEYS);
|
|
1050
|
+
const glob = nonEmptyString(
|
|
1051
|
+
item.glob,
|
|
1052
|
+
"TN_CONFIG_ASSETS_INVALID",
|
|
1053
|
+
`assets.textures.overrides[${String(index)}].glob`
|
|
1054
|
+
);
|
|
1055
|
+
if (typeof item.codec !== "string" || !TEXTURE_CODECS.includes(item.codec)) {
|
|
1056
|
+
fail(
|
|
1057
|
+
"TN_CONFIG_ASSETS_INVALID",
|
|
1058
|
+
`assets.textures.overrides[${String(index)}].codec must be one of ${TEXTURE_CODECS.join(", ")}; received '${String(item.codec)}'.`
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
return {
|
|
1062
|
+
codec: item.codec,
|
|
1063
|
+
glob,
|
|
1064
|
+
...item.quality === void 0 ? {} : {
|
|
1065
|
+
quality: textureQuality(
|
|
1066
|
+
item.quality,
|
|
1067
|
+
`assets.textures.overrides[${String(index)}].quality`
|
|
1068
|
+
)
|
|
1069
|
+
}
|
|
1070
|
+
};
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
function validateTextures(raw) {
|
|
1074
|
+
if (raw === "none") return "none";
|
|
1075
|
+
const textures = assertRecord(raw, "assets.textures");
|
|
1076
|
+
assertKeys(textures, "assets.textures", ASSET_TEXTURE_KEYS);
|
|
1077
|
+
return {
|
|
1078
|
+
...textures.quality === void 0 ? {} : { quality: textureQuality(textures.quality, "assets.textures.quality") },
|
|
1079
|
+
...textures.overrides === void 0 ? {} : { overrides: validateTextureOverrides(textures.overrides) }
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
var MODEL_PASS_KEYS = ["dedup", "meshopt", "prune", "quantize", "reorder"];
|
|
1083
|
+
var MODEL_QUANTIZE_KEYS = ["normalBits", "positionBits", "uvBits"];
|
|
1084
|
+
var MODEL_VIRTUAL_KEYS = [
|
|
1085
|
+
"groupSize",
|
|
1086
|
+
"maxTriangles",
|
|
1087
|
+
"minSourceTriangles",
|
|
1088
|
+
"minTriangles",
|
|
1089
|
+
"simplifyRatio"
|
|
1090
|
+
];
|
|
1091
|
+
function bitDepth(value, label) {
|
|
1092
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 1 || value > 16) {
|
|
1093
|
+
fail("TN_CONFIG_ASSETS_INVALID", `${label} must be an integer between 1 and 16 bits.`);
|
|
1094
|
+
}
|
|
1095
|
+
return value;
|
|
1096
|
+
}
|
|
1097
|
+
function validateModels(raw) {
|
|
1098
|
+
if (raw === "none") return "none";
|
|
1099
|
+
const models = assertRecord(raw, "assets.models");
|
|
1100
|
+
assertKeys(models, "assets.models", [
|
|
1101
|
+
"lightmap",
|
|
1102
|
+
"passes",
|
|
1103
|
+
"quantize",
|
|
1104
|
+
"simplify",
|
|
1105
|
+
"textures",
|
|
1106
|
+
"virtual"
|
|
1107
|
+
]);
|
|
1108
|
+
let lightmap;
|
|
1109
|
+
if (models.lightmap !== void 0) {
|
|
1110
|
+
const rawLightmap = assertRecord(models.lightmap, "assets.models.lightmap");
|
|
1111
|
+
assertKeys(rawLightmap, "assets.models.lightmap", ["atlasSize", "padding"]);
|
|
1112
|
+
if (rawLightmap.atlasSize === void 0 || rawLightmap.padding === void 0) {
|
|
1113
|
+
fail("TN_CONFIG_ASSETS_INVALID", "assets.models.lightmap requires atlasSize and padding.");
|
|
1114
|
+
}
|
|
1115
|
+
lightmap = {
|
|
1116
|
+
atlasSize: positiveInteger(
|
|
1117
|
+
rawLightmap.atlasSize,
|
|
1118
|
+
1,
|
|
1119
|
+
"TN_CONFIG_ASSETS_INVALID",
|
|
1120
|
+
"assets.models.lightmap.atlasSize"
|
|
1121
|
+
),
|
|
1122
|
+
padding: positiveInteger(
|
|
1123
|
+
rawLightmap.padding,
|
|
1124
|
+
1,
|
|
1125
|
+
"TN_CONFIG_ASSETS_INVALID",
|
|
1126
|
+
"assets.models.lightmap.padding"
|
|
1127
|
+
)
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
let passes;
|
|
1131
|
+
if (models.passes !== void 0) {
|
|
1132
|
+
const rawPasses = assertRecord(models.passes, "assets.models.passes");
|
|
1133
|
+
assertKeys(rawPasses, "assets.models.passes", MODEL_PASS_KEYS);
|
|
1134
|
+
passes = {};
|
|
1135
|
+
for (const key of MODEL_PASS_KEYS) {
|
|
1136
|
+
const value = rawPasses[key];
|
|
1137
|
+
if (value === void 0) continue;
|
|
1138
|
+
if (typeof value !== "boolean")
|
|
1139
|
+
fail("TN_CONFIG_ASSETS_INVALID", `assets.models.passes.${key} must be true or false.`);
|
|
1140
|
+
passes = { ...passes, [key]: value };
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
let quantize;
|
|
1144
|
+
if (models.quantize !== void 0) {
|
|
1145
|
+
const rawQuantize = assertRecord(models.quantize, "assets.models.quantize");
|
|
1146
|
+
assertKeys(rawQuantize, "assets.models.quantize", MODEL_QUANTIZE_KEYS);
|
|
1147
|
+
quantize = {};
|
|
1148
|
+
for (const key of MODEL_QUANTIZE_KEYS) {
|
|
1149
|
+
const value = rawQuantize[key];
|
|
1150
|
+
if (value === void 0) continue;
|
|
1151
|
+
quantize = {
|
|
1152
|
+
...quantize,
|
|
1153
|
+
[key]: bitDepth(value, `assets.models.quantize.${key}`)
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
const simplify = models.simplify;
|
|
1158
|
+
const textures = models.textures;
|
|
1159
|
+
let virtual;
|
|
1160
|
+
if (models.virtual === "none") {
|
|
1161
|
+
virtual = "none";
|
|
1162
|
+
} else if (models.virtual !== void 0) {
|
|
1163
|
+
const rawVirtual = assertRecord(models.virtual, "assets.models.virtual");
|
|
1164
|
+
assertKeys(rawVirtual, "assets.models.virtual", MODEL_VIRTUAL_KEYS);
|
|
1165
|
+
const bake = {};
|
|
1166
|
+
for (const key of MODEL_VIRTUAL_KEYS) {
|
|
1167
|
+
const value = rawVirtual[key];
|
|
1168
|
+
if (value === void 0) continue;
|
|
1169
|
+
if (key === "simplifyRatio") {
|
|
1170
|
+
if (typeof value !== "number" || !(value > 0) || !(value < 1))
|
|
1171
|
+
fail(
|
|
1172
|
+
"TN_CONFIG_ASSETS_INVALID",
|
|
1173
|
+
"assets.models.virtual.simplifyRatio must be a number between 0 and 1, exclusive."
|
|
1174
|
+
);
|
|
1175
|
+
bake.simplifyRatio = value;
|
|
1176
|
+
continue;
|
|
1177
|
+
}
|
|
1178
|
+
bake[key] = positiveInteger(
|
|
1179
|
+
value,
|
|
1180
|
+
1,
|
|
1181
|
+
"TN_CONFIG_ASSETS_INVALID",
|
|
1182
|
+
`assets.models.virtual.${key}`
|
|
1183
|
+
);
|
|
1184
|
+
}
|
|
1185
|
+
virtual = bake;
|
|
1186
|
+
}
|
|
1187
|
+
return {
|
|
1188
|
+
...lightmap === void 0 ? {} : { lightmap },
|
|
1189
|
+
...passes === void 0 || Object.keys(passes).length === 0 ? {} : { passes },
|
|
1190
|
+
...quantize === void 0 || Object.keys(quantize).length === 0 ? {} : { quantize },
|
|
1191
|
+
...simplify === void 0 ? {} : { simplify },
|
|
1192
|
+
...textures === void 0 ? {} : { textures },
|
|
1193
|
+
...virtual === void 0 ? {} : { virtual }
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
function validateAssets(raw) {
|
|
1197
|
+
const assets = assertRecord(raw, "assets");
|
|
1198
|
+
assertKeys(assets, "assets", ["models", "source", "output", "targets", "textures"]);
|
|
1199
|
+
const targets = assets.targets === void 0 ? void 0 : validateAssetTargets(assets.targets);
|
|
1200
|
+
const models = assets.models === void 0 ? void 0 : validateModels(assets.models);
|
|
1201
|
+
const textures = assets.textures === void 0 ? void 0 : validateTextures(assets.textures);
|
|
1202
|
+
return {
|
|
1203
|
+
...assets.source === void 0 ? {} : { source: nonEmptyString(assets.source, "TN_CONFIG_ASSETS_INVALID", "assets.source") },
|
|
1204
|
+
...assets.output === void 0 ? {} : { output: nonEmptyString(assets.output, "TN_CONFIG_ASSETS_INVALID", "assets.output") },
|
|
1205
|
+
...targets === void 0 ? {} : { targets },
|
|
1206
|
+
...models === void 0 ? {} : { models },
|
|
1207
|
+
...textures === void 0 ? {} : { textures }
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
async function loadConfigInternal(root) {
|
|
1211
|
+
const packagePath = path5.join(root, "package.json");
|
|
1212
|
+
const sourcePath = path5.join(root, CONFIG_FILE);
|
|
1213
|
+
const manifest = await withConfigContext(
|
|
1214
|
+
packageContext(root),
|
|
1215
|
+
"TN_CONFIG_PACKAGE_INVALID",
|
|
1216
|
+
() => readManifest(root)
|
|
1217
|
+
);
|
|
1218
|
+
const name = await withConfigContext(
|
|
1219
|
+
packageContext(root),
|
|
1220
|
+
"TN_CONFIG_PACKAGE_INVALID",
|
|
1221
|
+
() => packageDisplayName(manifest)
|
|
1222
|
+
);
|
|
1223
|
+
const packageEntry = await withConfigContext(
|
|
1224
|
+
packageContext(root),
|
|
1225
|
+
"TN_CONFIG_PACKAGE_INVALID",
|
|
1226
|
+
() => packageNativeEntry(manifest)
|
|
1227
|
+
);
|
|
1228
|
+
const raw = await importConfig(root);
|
|
1229
|
+
const sources = packageEntry === void 0 ? [sourcePath] : [sourcePath, packagePath];
|
|
1230
|
+
return withConfigContext(
|
|
1231
|
+
validationContext(root, sources),
|
|
1232
|
+
"TN_CONFIG_VALIDATION_FAILED",
|
|
1233
|
+
async () => {
|
|
1234
|
+
if (raw !== void 0) {
|
|
1235
|
+
assertKeys(raw, "config", [
|
|
1236
|
+
"app",
|
|
1237
|
+
"display",
|
|
1238
|
+
"bootSplash",
|
|
1239
|
+
"window",
|
|
1240
|
+
"nativeEntry",
|
|
1241
|
+
"renderer",
|
|
1242
|
+
"ui",
|
|
1243
|
+
"assets"
|
|
1244
|
+
]);
|
|
1245
|
+
}
|
|
1246
|
+
const configuredEntry = raw?.nativeEntry;
|
|
1247
|
+
if (configuredEntry !== void 0 && packageEntry !== void 0) {
|
|
1248
|
+
fail(
|
|
1249
|
+
"TN_CONFIG_CONFLICT",
|
|
1250
|
+
"nativeEntry is declared in both threenative.config.ts and package.json."
|
|
1251
|
+
);
|
|
1252
|
+
}
|
|
1253
|
+
const app = await validateApp(raw?.app, name, root);
|
|
1254
|
+
const bootSplash = await validateBootSplash(raw?.bootSplash, root);
|
|
1255
|
+
const assets = raw?.assets === void 0 ? void 0 : validateAssets(raw.assets);
|
|
1256
|
+
return {
|
|
1257
|
+
app,
|
|
1258
|
+
display: validateDisplay(raw?.display),
|
|
1259
|
+
window: validateWindow(raw?.window, app.name),
|
|
1260
|
+
nativeEntry: validateNativeEntry(configuredEntry ?? packageEntry ?? "src/game.ts", root),
|
|
1261
|
+
renderer: validateRenderer(raw?.renderer),
|
|
1262
|
+
ui: validateUi(raw?.ui),
|
|
1263
|
+
...bootSplash === void 0 ? {} : { bootSplash },
|
|
1264
|
+
...assets === void 0 ? {} : { assets }
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
1269
|
+
async function loadConfig(cwd) {
|
|
1270
|
+
const root = path5.resolve(cwd);
|
|
1271
|
+
return withConfigContext(
|
|
1272
|
+
validationContext(root, [path5.join(root, CONFIG_FILE), path5.join(root, "package.json")]),
|
|
1273
|
+
"TN_CONFIG_VALIDATION_FAILED",
|
|
1274
|
+
() => loadConfigInternal(root)
|
|
1275
|
+
);
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
// src/web-brand.ts
|
|
1279
|
+
function htmlAttribute(value) {
|
|
1280
|
+
return value.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<");
|
|
1281
|
+
}
|
|
1282
|
+
function publicUrl(root, value) {
|
|
1283
|
+
if (value === void 0) return void 0;
|
|
1284
|
+
const relative = path5.isAbsolute(value) ? path5.relative(root, value) : value;
|
|
1285
|
+
const normalized = relative.replaceAll(path5.sep, "/").replace(/^public\//u, "");
|
|
1286
|
+
return `/${normalized.replace(/^\//u, "")}`;
|
|
1287
|
+
}
|
|
1288
|
+
function manifestIcon(root, source, purpose) {
|
|
1289
|
+
const url = publicUrl(root, source);
|
|
1290
|
+
if (url === void 0) return void 0;
|
|
1291
|
+
const type = url.endsWith(".svg") ? "image/svg+xml" : "image/png";
|
|
1292
|
+
return { purpose, src: url, type };
|
|
1293
|
+
}
|
|
1294
|
+
function renderWebManifest(root, config) {
|
|
1295
|
+
const web = config.app.icons?.web;
|
|
1296
|
+
const fallback = web?.favicon ?? config.app.icon;
|
|
1297
|
+
const icons = [
|
|
1298
|
+
manifestIcon(root, fallback, "any"),
|
|
1299
|
+
manifestIcon(root, web?.maskable ?? config.app.icon, "maskable"),
|
|
1300
|
+
manifestIcon(root, web?.monochrome, "monochrome")
|
|
1301
|
+
].filter((icon) => icon !== void 0);
|
|
1302
|
+
const background = config.bootSplash?.backgroundColor ?? "#000000";
|
|
1303
|
+
const manifest = Object.fromEntries([
|
|
1304
|
+
["background_color", background],
|
|
1305
|
+
["display", "fullscreen"],
|
|
1306
|
+
["icons", icons],
|
|
1307
|
+
["name", config.app.name],
|
|
1308
|
+
["orientation", config.display.orientation],
|
|
1309
|
+
["short_name", config.app.name],
|
|
1310
|
+
["start_url", "."],
|
|
1311
|
+
["theme_color", background]
|
|
1312
|
+
]);
|
|
1313
|
+
return `${JSON.stringify(manifest, null, 2)}
|
|
1314
|
+
`;
|
|
1315
|
+
}
|
|
1316
|
+
function metadataLinks(root, config) {
|
|
1317
|
+
const web = config.app.icons?.web;
|
|
1318
|
+
const favicon = publicUrl(root, web?.favicon ?? config.app.icon);
|
|
1319
|
+
const appleTouch = publicUrl(root, web?.appleTouch ?? config.app.icon);
|
|
1320
|
+
const links = [
|
|
1321
|
+
favicon === void 0 ? void 0 : `<link rel="icon" href="${htmlAttribute(favicon)}" />`,
|
|
1322
|
+
appleTouch === void 0 ? void 0 : `<link rel="apple-touch-icon" href="${htmlAttribute(appleTouch)}" />`,
|
|
1323
|
+
'<link rel="manifest" href="/manifest.webmanifest" />'
|
|
1324
|
+
].filter((link) => link !== void 0);
|
|
1325
|
+
const background = config.bootSplash?.backgroundColor ?? "#000000";
|
|
1326
|
+
links.push(`<meta name="theme-color" content="${htmlAttribute(background)}" />`);
|
|
1327
|
+
return links.join("\n ");
|
|
1328
|
+
}
|
|
1329
|
+
function updateLaunchMarkup(root, config, html) {
|
|
1330
|
+
let output = html.replace(
|
|
1331
|
+
/(<title[^>]*>)[\s\S]*?(<\/title>)/iu,
|
|
1332
|
+
`$1${htmlAttribute(config.app.name)}$2`
|
|
1333
|
+
);
|
|
1334
|
+
output = output.replace(
|
|
1335
|
+
/(<[^>]*data-threenative-launch-name[^>]*>)[\s\S]*?(<\/[^>]+>)/iu,
|
|
1336
|
+
`$1${htmlAttribute(config.app.name)}$2`
|
|
1337
|
+
);
|
|
1338
|
+
const launchImage = publicUrl(root, config.bootSplash?.image);
|
|
1339
|
+
if (launchImage !== void 0) {
|
|
1340
|
+
output = output.replace(
|
|
1341
|
+
/<img([^>]*data-threenative-launch-image[^>]*)>/iu,
|
|
1342
|
+
(_match, attributes) => `<img${attributes.replace(/\s+hidden(?:="[^"]*")?/iu, "")} src="${htmlAttribute(launchImage)}">`
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1345
|
+
const links = metadataLinks(root, config);
|
|
1346
|
+
output = output.replace(/\s*<link\s+rel="icon"[^>]*>/giu, "");
|
|
1347
|
+
output = output.replace(/\s*<link\s+rel="apple-touch-icon"[^>]*>/giu, "");
|
|
1348
|
+
output = output.replace(/\s*<link\s+rel="manifest"[^>]*>/giu, "");
|
|
1349
|
+
output = output.replace(/(<\/head>)/iu, ` ${links}
|
|
1350
|
+
$1`);
|
|
1351
|
+
return output;
|
|
1352
|
+
}
|
|
1353
|
+
function createWebBrandPlugin() {
|
|
1354
|
+
let root = process.cwd();
|
|
1355
|
+
let config;
|
|
1356
|
+
return {
|
|
1357
|
+
name: "threenative-web-brand",
|
|
1358
|
+
async configResolved(resolved) {
|
|
1359
|
+
root = resolved.root;
|
|
1360
|
+
config = await loadConfig(root);
|
|
1361
|
+
},
|
|
1362
|
+
transformIndexHtml(html) {
|
|
1363
|
+
if (config === void 0) throw new Error("TN_WEB_BRAND_CONFIG_MISSING");
|
|
1364
|
+
return updateLaunchMarkup(root, config, html);
|
|
1365
|
+
},
|
|
1366
|
+
generateBundle() {
|
|
1367
|
+
if (config === void 0) throw new Error("TN_WEB_BRAND_CONFIG_MISSING");
|
|
1368
|
+
this.emitFile({
|
|
1369
|
+
fileName: "manifest.webmanifest",
|
|
1370
|
+
source: renderWebManifest(root, config),
|
|
1371
|
+
type: "asset"
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
// src/index.ts
|
|
1378
|
+
var PACKAGE_SOURCE_FLAGS = {
|
|
1379
|
+
"@threenative/core": "--core-package",
|
|
1380
|
+
"@threenative/assets": "--assets-package",
|
|
1381
|
+
"@threenative/physics": "--physics-package",
|
|
1382
|
+
"@threenative/playtest": "--playtest-package",
|
|
1383
|
+
"@threenative/runtime-native": "--runtime-native-package",
|
|
1384
|
+
"@threenative/ui": "--ui-package",
|
|
1385
|
+
"threenative-engine-mcp": "--engine-mcp-package",
|
|
1386
|
+
"create-threenative": "--cli-package"
|
|
1387
|
+
};
|
|
8
1388
|
var TEXT_FILE_EXTENSIONS = /* @__PURE__ */ new Set([".css", ".html", ".json", ".md", ".svg", ".ts", ".tsx"]);
|
|
9
1389
|
var TEMPLATE_NAME = /^[a-z][a-z0-9-]*$/u;
|
|
1390
|
+
var SHARED_AGENT_MARKER_LINE = /^<!--\s*(?:shared:\s*[^>]+|\/shared)\s*-->\r?\n?/gmu;
|
|
1391
|
+
var DEFAULT_TEMPLATE = "starter";
|
|
10
1392
|
function templateRoot() {
|
|
11
|
-
return
|
|
1393
|
+
return path5.resolve(path5.dirname(fileURLToPath(import.meta.url)), "../templates");
|
|
1394
|
+
}
|
|
1395
|
+
var LOADING_SOURCE_RELATIVE_PATH = path5.join("src", "render", "loading.ts");
|
|
1396
|
+
var LOADING_APPEARANCE_BLOCK_PATTERN = /\/\* BEGIN THREENATIVE LOADING APPEARANCE \*\/[\s\S]*?\/\* END THREENATIVE LOADING APPEARANCE \*\//gu;
|
|
1397
|
+
var FULL_LOADING_TEMPLATES = [
|
|
1398
|
+
"action-rpg",
|
|
1399
|
+
"defense",
|
|
1400
|
+
"platformer",
|
|
1401
|
+
"racing",
|
|
1402
|
+
"sailing",
|
|
1403
|
+
"shooter",
|
|
1404
|
+
"starter"
|
|
1405
|
+
];
|
|
1406
|
+
function canonicalLoadingPath(root = templateRoot()) {
|
|
1407
|
+
const local = path5.resolve(root, "..", "template-assets", "loading.ts");
|
|
1408
|
+
if (existsSync(local)) return local;
|
|
1409
|
+
return path5.resolve(templateRoot(), "..", "template-assets", "loading.ts");
|
|
1410
|
+
}
|
|
1411
|
+
function loadingAppearanceBlock(source, file) {
|
|
1412
|
+
const matches = source.match(LOADING_APPEARANCE_BLOCK_PATTERN) ?? [];
|
|
1413
|
+
if (matches.length !== 1) {
|
|
1414
|
+
throw new Error(
|
|
1415
|
+
`TN_LOADING_TEMPLATE_INVALID: ${file}: expected exactly one loading appearance block, found ${matches.length}.`
|
|
1416
|
+
);
|
|
1417
|
+
}
|
|
1418
|
+
return matches[0];
|
|
1419
|
+
}
|
|
1420
|
+
function stampLoadingSource(canonical, template) {
|
|
1421
|
+
const canonicalBlock = loadingAppearanceBlock(canonical, "canonical loading source");
|
|
1422
|
+
const templateBlock = loadingAppearanceBlock(template, "template loading source");
|
|
1423
|
+
return canonical.replace(canonicalBlock, templateBlock);
|
|
1424
|
+
}
|
|
1425
|
+
async function restampTemplateLoadingCopies(root = templateRoot()) {
|
|
1426
|
+
const canonical = await readFile(canonicalLoadingPath(root), "utf8");
|
|
1427
|
+
const stamped = [];
|
|
1428
|
+
for (const template of FULL_LOADING_TEMPLATES) {
|
|
1429
|
+
const file = path5.join(root, template, LOADING_SOURCE_RELATIVE_PATH);
|
|
1430
|
+
const source = await readFile(file, "utf8");
|
|
1431
|
+
await writeFile(file, stampLoadingSource(canonical, source));
|
|
1432
|
+
stamped.push(file);
|
|
1433
|
+
}
|
|
1434
|
+
return stamped;
|
|
1435
|
+
}
|
|
1436
|
+
async function stampTemplateLoading(target, template, root) {
|
|
1437
|
+
const sourcePath = path5.join(template, LOADING_SOURCE_RELATIVE_PATH);
|
|
1438
|
+
if (!existsSync(sourcePath)) return;
|
|
1439
|
+
const source = await readFile(sourcePath, "utf8");
|
|
1440
|
+
if (!source.includes("BEGIN THREENATIVE LOADING APPEARANCE")) return;
|
|
1441
|
+
const canonical = await readFile(canonicalLoadingPath(root), "utf8");
|
|
1442
|
+
await writeFile(
|
|
1443
|
+
path5.join(target, LOADING_SOURCE_RELATIVE_PATH),
|
|
1444
|
+
stampLoadingSource(canonical, source)
|
|
1445
|
+
);
|
|
12
1446
|
}
|
|
13
1447
|
function invalidManifest(file, reason) {
|
|
14
1448
|
throw new Error(`TN_KIT_MANIFEST_INVALID: ${file}: ${reason}`);
|
|
15
1449
|
}
|
|
16
|
-
function
|
|
1450
|
+
function nonEmptyString2(value, field, file) {
|
|
17
1451
|
if (typeof value !== "string" || value.trim().length === 0)
|
|
18
1452
|
return invalidManifest(file, `${field} must be a non-empty string`);
|
|
19
1453
|
return value;
|
|
20
1454
|
}
|
|
21
1455
|
function loadManifest(directory) {
|
|
22
|
-
const file =
|
|
1456
|
+
const file = path5.join(directory, "kit.json");
|
|
23
1457
|
let raw;
|
|
24
1458
|
try {
|
|
25
1459
|
raw = readFileSync(file, "utf8");
|
|
@@ -37,8 +1471,8 @@ function loadManifest(directory) {
|
|
|
37
1471
|
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
38
1472
|
return invalidManifest(file, "the root must be an object");
|
|
39
1473
|
const record = value;
|
|
40
|
-
const directoryName =
|
|
41
|
-
const name =
|
|
1474
|
+
const directoryName = path5.basename(directory);
|
|
1475
|
+
const name = nonEmptyString2(record.name, "name", file);
|
|
42
1476
|
if (!TEMPLATE_NAME.test(name))
|
|
43
1477
|
return invalidManifest(file, "name must match /^[a-z][a-z0-9-]*$/");
|
|
44
1478
|
if (name !== directoryName)
|
|
@@ -46,15 +1480,15 @@ function loadManifest(directory) {
|
|
|
46
1480
|
const kit = record.kit;
|
|
47
1481
|
if (typeof kit !== "boolean") return invalidManifest(file, "kit must be a boolean");
|
|
48
1482
|
return {
|
|
49
|
-
blurb:
|
|
50
|
-
genre:
|
|
1483
|
+
blurb: nonEmptyString2(record.blurb, "blurb", file),
|
|
1484
|
+
genre: nonEmptyString2(record.genre, "genre", file),
|
|
51
1485
|
kit,
|
|
52
1486
|
name,
|
|
53
|
-
title:
|
|
1487
|
+
title: nonEmptyString2(record.title, "title", file)
|
|
54
1488
|
};
|
|
55
1489
|
}
|
|
56
1490
|
function discoverKitManifests(root = templateRoot()) {
|
|
57
|
-
return readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => loadManifest(
|
|
1491
|
+
return readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => loadManifest(path5.join(root, entry.name))).sort((left, right) => left.name.localeCompare(right.name));
|
|
58
1492
|
}
|
|
59
1493
|
function discoverTemplateNames(root = templateRoot()) {
|
|
60
1494
|
return discoverKitManifests(root).map(({ name }) => name);
|
|
@@ -67,17 +1501,32 @@ function kitManifest(template, root = templateRoot()) {
|
|
|
67
1501
|
);
|
|
68
1502
|
return manifest;
|
|
69
1503
|
}
|
|
1504
|
+
function templateForGenre(genre, root = templateRoot()) {
|
|
1505
|
+
const normalized = genre.trim().toLowerCase();
|
|
1506
|
+
if (normalized.length === 0) throw new Error("Genre must not be empty.");
|
|
1507
|
+
return discoverKitManifests(root).find((manifest) => manifest.genre.toLowerCase() === normalized)?.name ?? "minimal";
|
|
1508
|
+
}
|
|
70
1509
|
function templateHelp(manifests) {
|
|
71
1510
|
const width = Math.max(...manifests.map(({ name }) => name.length), 0);
|
|
72
1511
|
return manifests.map(({ blurb, name, title }) => ` ${name.padEnd(width)} ${title}: ${blurb}`).join("\n");
|
|
73
1512
|
}
|
|
1513
|
+
function scaffoldCompletionMessage(manifests, defaultTemplate = DEFAULT_TEMPLATE) {
|
|
1514
|
+
const names = manifests.map(({ name }) => name === defaultTemplate ? `${name} (default)` : name).join(", ");
|
|
1515
|
+
return `Templates: ${names}. Choose with --template <name>.
|
|
1516
|
+
`;
|
|
1517
|
+
}
|
|
74
1518
|
function cliHelp() {
|
|
75
1519
|
const manifests = discoverKitManifests();
|
|
76
1520
|
return `${[
|
|
77
1521
|
"Usage: npx create-threenative <directory> [options]",
|
|
1522
|
+
" npx create-threenative inspect <file.glb> [--json]",
|
|
1523
|
+
"",
|
|
1524
|
+
"Commands:",
|
|
1525
|
+
" inspect <file> Report the facts in a glTF asset.",
|
|
78
1526
|
"",
|
|
79
1527
|
"Options:",
|
|
80
1528
|
" --template <name> Choose a template.",
|
|
1529
|
+
" --genre <name> Choose an exact genre kit; unknown genres use minimal.",
|
|
81
1530
|
" --no-install Copy the project without running pnpm install.",
|
|
82
1531
|
" --help Show this help.",
|
|
83
1532
|
"",
|
|
@@ -87,65 +1536,169 @@ function cliHelp() {
|
|
|
87
1536
|
`;
|
|
88
1537
|
}
|
|
89
1538
|
function packageName(target) {
|
|
90
|
-
const name =
|
|
1539
|
+
const name = path5.basename(target).toLowerCase().replace(/[^a-z0-9-_]+/g, "-");
|
|
91
1540
|
if (name.length === 0 || name === "-" || name === "_") {
|
|
92
1541
|
throw new Error(`Cannot derive a package name from '${target}'.`);
|
|
93
1542
|
}
|
|
94
1543
|
return name;
|
|
95
1544
|
}
|
|
96
1545
|
async function isEmpty(directory) {
|
|
97
|
-
const entries = await readdir(directory).catch(
|
|
1546
|
+
const entries = await readdir(directory).catch(
|
|
1547
|
+
(error) => error?.code === "ENOENT" ? [] : void 0
|
|
1548
|
+
);
|
|
1549
|
+
if (entries === void 0) return false;
|
|
98
1550
|
return entries.length === 0;
|
|
99
1551
|
}
|
|
1552
|
+
function substituteTemplateVariables(content, replacements) {
|
|
1553
|
+
let rendered = content;
|
|
1554
|
+
for (const [placeholder, value] of Object.entries(replacements)) {
|
|
1555
|
+
rendered = rendered.replaceAll(placeholder, value);
|
|
1556
|
+
}
|
|
1557
|
+
return rendered;
|
|
1558
|
+
}
|
|
100
1559
|
async function renderTemplate(directory, replacements) {
|
|
101
1560
|
const files = await readdir(directory, { withFileTypes: true });
|
|
102
1561
|
for (const entry of files) {
|
|
103
|
-
const source =
|
|
1562
|
+
const source = path5.join(directory, entry.name);
|
|
104
1563
|
if (entry.isDirectory()) {
|
|
105
1564
|
await renderTemplate(source, replacements);
|
|
106
1565
|
continue;
|
|
107
1566
|
}
|
|
108
|
-
if (!TEXT_FILE_EXTENSIONS.has(
|
|
1567
|
+
if (!TEXT_FILE_EXTENSIONS.has(path5.extname(entry.name))) continue;
|
|
109
1568
|
const content = await readFile(source, "utf8");
|
|
110
|
-
let rendered = content;
|
|
111
|
-
|
|
112
|
-
rendered = rendered.
|
|
1569
|
+
let rendered = substituteTemplateVariables(content, replacements);
|
|
1570
|
+
if (entry.name === "AGENTS.md" || entry.name === "CLAUDE.md") {
|
|
1571
|
+
rendered = rendered.replace(SHARED_AGENT_MARKER_LINE, "");
|
|
113
1572
|
}
|
|
114
1573
|
await writeFile(source, rendered);
|
|
115
1574
|
}
|
|
116
1575
|
}
|
|
1576
|
+
var REFERENCE_BUNDLE_DIRECTORY = "agent-docs";
|
|
1577
|
+
var REFERENCE_FILE_NAME = /^[a-z0-9][a-z0-9-]*\.md$/u;
|
|
1578
|
+
var AGENT_FILES_DIRECTORY = "agent-files";
|
|
1579
|
+
var REFERENCE_TOKEN_PATTERN = /`agent-docs\/([a-z0-9][a-z0-9./-]*\.md)`|\[[^\]]*\]\(agent-docs\/([^)#]+\.md)\)/gu;
|
|
1580
|
+
async function copyReferenceBundle(target, templateRootDirectory, replacements) {
|
|
1581
|
+
const bundle = path5.join(
|
|
1582
|
+
path5.dirname(templateRootDirectory),
|
|
1583
|
+
REFERENCE_BUNDLE_DIRECTORY,
|
|
1584
|
+
"references"
|
|
1585
|
+
);
|
|
1586
|
+
if (!existsSync(bundle)) return;
|
|
1587
|
+
const destination = path5.join(target, REFERENCE_BUNDLE_DIRECTORY);
|
|
1588
|
+
await mkdir(destination, { recursive: true });
|
|
1589
|
+
for (const entry of await readdir(bundle, { withFileTypes: true })) {
|
|
1590
|
+
if (!entry.isFile() || !REFERENCE_FILE_NAME.test(entry.name)) continue;
|
|
1591
|
+
const content = substituteTemplateVariables(
|
|
1592
|
+
await readFile(path5.join(bundle, entry.name), "utf8"),
|
|
1593
|
+
replacements
|
|
1594
|
+
);
|
|
1595
|
+
const destinationPath = path5.join(destination, entry.name);
|
|
1596
|
+
if (path5.relative(target, destinationPath).startsWith("..")) {
|
|
1597
|
+
throw new Error(`Reference page '${entry.name}' resolves outside '${target}'.`);
|
|
1598
|
+
}
|
|
1599
|
+
await writeFile(destinationPath, content);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
async function copyAgentFiles(target, templateRootDirectory) {
|
|
1603
|
+
const source = path5.join(path5.dirname(templateRootDirectory), AGENT_FILES_DIRECTORY);
|
|
1604
|
+
if (!existsSync(source)) {
|
|
1605
|
+
throw new Error(
|
|
1606
|
+
`TN_AGENT_FILES_MISSING: '${source}' is not in the package; every generated project needs the canonical agent roles.`
|
|
1607
|
+
);
|
|
1608
|
+
}
|
|
1609
|
+
await cp(source, target, { recursive: true });
|
|
1610
|
+
}
|
|
1611
|
+
async function assertReferenceBundle(target) {
|
|
1612
|
+
for (const file of ["AGENTS.md", "CLAUDE.md"]) {
|
|
1613
|
+
const filePath = path5.join(target, file);
|
|
1614
|
+
if (existsSync(filePath)) await assertReferenceTargets(target, file, filePath);
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
async function assertReferenceTargets(target, from, filePath) {
|
|
1618
|
+
const content = await readFile(filePath, "utf8");
|
|
1619
|
+
for (const match of content.matchAll(REFERENCE_TOKEN_PATTERN)) {
|
|
1620
|
+
const referenced = match[1] ?? match[2];
|
|
1621
|
+
if (referenced === void 0) continue;
|
|
1622
|
+
if (!REFERENCE_FILE_NAME.test(referenced) || referenced.includes("/")) {
|
|
1623
|
+
throw new Error(
|
|
1624
|
+
`RED observed: referenced recipe missing: '${from}' names '${referenced}', which is not a shipped reference page.`
|
|
1625
|
+
);
|
|
1626
|
+
}
|
|
1627
|
+
const resolved = path5.join(target, REFERENCE_BUNDLE_DIRECTORY, referenced);
|
|
1628
|
+
if (!existsSync(resolved)) {
|
|
1629
|
+
throw new Error(
|
|
1630
|
+
`RED observed: referenced recipe missing: '${from}' links 'agent-docs/${referenced}', which the scaffold did not copy.`
|
|
1631
|
+
);
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
117
1635
|
async function applyPackageSources(target, packageSources) {
|
|
118
1636
|
if (packageSources === void 0) return;
|
|
119
|
-
const packagePath =
|
|
1637
|
+
const packagePath = path5.join(target, "package.json");
|
|
120
1638
|
const packageJson = JSON.parse(await readFile(packagePath, "utf8"));
|
|
1639
|
+
const localSource = (source) => {
|
|
1640
|
+
const filePath = source.startsWith("file:") ? source.slice("file:".length) : source;
|
|
1641
|
+
return `file:${path5.resolve(filePath)}`;
|
|
1642
|
+
};
|
|
121
1643
|
for (const [name, source] of Object.entries(packageSources)) {
|
|
122
1644
|
if (source === void 0) continue;
|
|
1645
|
+
const resolvedSource = localSource(source);
|
|
1646
|
+
const isExistingDevDependency = packageJson.devDependencies?.[name] !== void 0;
|
|
123
1647
|
if (packageJson.optionalDependencies?.[name] !== void 0) {
|
|
124
|
-
packageJson.optionalDependencies[name] =
|
|
125
|
-
} else if (name === "@threenative/playtest" || name === "
|
|
1648
|
+
packageJson.optionalDependencies[name] = resolvedSource;
|
|
1649
|
+
} else if (isExistingDevDependency || name === "@threenative/playtest" || name === "create-threenative" || name === "threenative-engine-mcp") {
|
|
126
1650
|
packageJson.devDependencies ??= {};
|
|
127
|
-
packageJson.devDependencies[name] =
|
|
1651
|
+
packageJson.devDependencies[name] = resolvedSource;
|
|
128
1652
|
} else {
|
|
129
1653
|
packageJson.dependencies ??= {};
|
|
130
|
-
packageJson.dependencies[name] =
|
|
131
|
-
}
|
|
132
|
-
if (name === "create-threenative") {
|
|
133
|
-
packageJson.pnpm ??= {};
|
|
134
|
-
packageJson.pnpm.overrides ??= {};
|
|
135
|
-
packageJson.pnpm.overrides[name] = source.startsWith("file:") ? source : `file:${source}`;
|
|
1654
|
+
packageJson.dependencies[name] = resolvedSource;
|
|
136
1655
|
}
|
|
1656
|
+
packageJson.pnpm ??= {};
|
|
1657
|
+
packageJson.pnpm.overrides ??= {};
|
|
1658
|
+
packageJson.pnpm.overrides[name] = resolvedSource;
|
|
137
1659
|
}
|
|
138
1660
|
await writeFile(packagePath, `${JSON.stringify(packageJson, null, 2)}
|
|
139
1661
|
`);
|
|
140
1662
|
}
|
|
1663
|
+
async function copyCapabilityManifest(target, templateRootDirectory) {
|
|
1664
|
+
const source = path5.join(path5.dirname(templateRootDirectory), "capabilities.json");
|
|
1665
|
+
if (!existsSync(source)) {
|
|
1666
|
+
throw new Error(
|
|
1667
|
+
`TN_KIT_CAPABILITIES_MISSING: '${source}' is not in the package; the generated project needs the capability manifest for its agent tooling.`
|
|
1668
|
+
);
|
|
1669
|
+
}
|
|
1670
|
+
await cp(source, path5.join(target, "capabilities.json"));
|
|
1671
|
+
}
|
|
1672
|
+
var FRAMEWORK_PATCH_DIRECTORY = "patches";
|
|
1673
|
+
var THREE_PATCH_NAME = "three@0.185.1.patch";
|
|
1674
|
+
async function copyFrameworkPatches(target, templateRootDirectory) {
|
|
1675
|
+
const source = path5.join(
|
|
1676
|
+
path5.dirname(templateRootDirectory),
|
|
1677
|
+
"template-assets",
|
|
1678
|
+
FRAMEWORK_PATCH_DIRECTORY,
|
|
1679
|
+
THREE_PATCH_NAME
|
|
1680
|
+
);
|
|
1681
|
+
if (!existsSync(source)) {
|
|
1682
|
+
throw new Error(
|
|
1683
|
+
`TN_FRAMEWORK_PATCH_MISSING: '${source}' is not in the package; the generated project needs the Three.js velocity patch for batched temporal history.`
|
|
1684
|
+
);
|
|
1685
|
+
}
|
|
1686
|
+
const destination = path5.join(target, FRAMEWORK_PATCH_DIRECTORY, THREE_PATCH_NAME);
|
|
1687
|
+
await mkdir(path5.dirname(destination), { recursive: true });
|
|
1688
|
+
await cp(source, destination);
|
|
1689
|
+
}
|
|
141
1690
|
var NODE_MODULES_PREFIX = "./node_modules/";
|
|
142
|
-
var REQUIRED_MCP_SERVERS =
|
|
1691
|
+
var REQUIRED_MCP_SERVERS = {
|
|
1692
|
+
"threenative-assets": `${NODE_MODULES_PREFIX}@threenative/core/mcp/assets.mjs`,
|
|
1693
|
+
"threenative-sculpt": `${NODE_MODULES_PREFIX}@threenative/core/mcp/sculpt.mjs`,
|
|
1694
|
+
"threenative-engine": `${NODE_MODULES_PREFIX}@threenative/core/mcp/engine.mjs`
|
|
1695
|
+
};
|
|
143
1696
|
function mcpPackageName(entry) {
|
|
144
1697
|
const segments = entry.slice(NODE_MODULES_PREFIX.length).split("/");
|
|
145
1698
|
return entry.startsWith(`${NODE_MODULES_PREFIX}@`) ? segments.slice(0, 2).join("/") : segments[0] ?? "";
|
|
146
1699
|
}
|
|
147
1700
|
async function assertMcpConfig(target) {
|
|
148
|
-
const configPath =
|
|
1701
|
+
const configPath = path5.join(target, ".mcp.json");
|
|
149
1702
|
const raw = await readFile(configPath, "utf8").catch(() => {
|
|
150
1703
|
throw new Error(`Scaffold produced no .mcp.json at '${configPath}'.`);
|
|
151
1704
|
});
|
|
@@ -153,12 +1706,12 @@ async function assertMcpConfig(target) {
|
|
|
153
1706
|
if (mcpServers === void 0 || Object.keys(mcpServers).length === 0) {
|
|
154
1707
|
throw new Error(`'${configPath}' declares no mcpServers.`);
|
|
155
1708
|
}
|
|
156
|
-
for (const name of REQUIRED_MCP_SERVERS) {
|
|
1709
|
+
for (const name of Object.keys(REQUIRED_MCP_SERVERS)) {
|
|
157
1710
|
if (mcpServers[name] === void 0) {
|
|
158
1711
|
throw new Error(`'${configPath}' is missing required MCP server '${name}'.`);
|
|
159
1712
|
}
|
|
160
1713
|
}
|
|
161
|
-
const manifest = JSON.parse(await readFile(
|
|
1714
|
+
const manifest = JSON.parse(await readFile(path5.join(target, "package.json"), "utf8"));
|
|
162
1715
|
const declared = /* @__PURE__ */ new Set([
|
|
163
1716
|
...Object.keys(manifest.dependencies ?? {}),
|
|
164
1717
|
...Object.keys(manifest.devDependencies ?? {})
|
|
@@ -185,6 +1738,22 @@ async function assertMcpConfig(target) {
|
|
|
185
1738
|
}
|
|
186
1739
|
}
|
|
187
1740
|
}
|
|
1741
|
+
for (const [name, entry] of Object.entries(REQUIRED_MCP_SERVERS)) {
|
|
1742
|
+
if (mcpServers[name]?.args?.[0] !== entry) {
|
|
1743
|
+
throw new Error(
|
|
1744
|
+
`MCP server '${name}' must launch '${entry}', not '${mcpServers[name]?.args?.[0] ?? "nothing"}'.`
|
|
1745
|
+
);
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
const codexPath = path5.join(target, ".codex", "config.toml");
|
|
1749
|
+
const codex = await readFile(codexPath, "utf8").catch(() => {
|
|
1750
|
+
throw new Error(`Scaffold produced no Codex MCP config at '${codexPath}'.`);
|
|
1751
|
+
});
|
|
1752
|
+
for (const [name, entry] of Object.entries(REQUIRED_MCP_SERVERS)) {
|
|
1753
|
+
if (!codex.includes(`[mcp_servers.${name}]`) || !codex.includes(`args = ["${entry}"]`)) {
|
|
1754
|
+
throw new Error(`'${codexPath}' does not wire required MCP server '${name}' to '${entry}'.`);
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
188
1757
|
}
|
|
189
1758
|
async function runInstall(target) {
|
|
190
1759
|
await new Promise((resolve, reject) => {
|
|
@@ -196,68 +1765,135 @@ async function runInstall(target) {
|
|
|
196
1765
|
});
|
|
197
1766
|
});
|
|
198
1767
|
}
|
|
199
|
-
async function createProject(options, cwd = process.cwd()) {
|
|
200
|
-
const manifests = discoverKitManifests();
|
|
201
|
-
const template = options.template ??
|
|
202
|
-
if (!manifests.some(({ name }) => name === template)) kitManifest(template);
|
|
203
|
-
const target =
|
|
1768
|
+
async function createProject(options, cwd = process.cwd(), root = templateRoot()) {
|
|
1769
|
+
const manifests = discoverKitManifests(root);
|
|
1770
|
+
const template = options.template ?? DEFAULT_TEMPLATE;
|
|
1771
|
+
if (!manifests.some(({ name }) => name === template)) kitManifest(template, root);
|
|
1772
|
+
const target = path5.resolve(cwd, options.target);
|
|
204
1773
|
const targetExists = await isEmpty(target).catch(() => false);
|
|
205
1774
|
if (!targetExists) {
|
|
206
1775
|
throw new Error(`Target '${target}' already exists and is not empty.`);
|
|
207
1776
|
}
|
|
208
1777
|
await mkdir(target, { recursive: true });
|
|
209
|
-
const source =
|
|
1778
|
+
const source = path5.join(root, template);
|
|
210
1779
|
await cp(source, target, { recursive: true, errorOnExist: true });
|
|
1780
|
+
if (existsSync(path5.join(target, "gitignore"))) {
|
|
1781
|
+
await rename(path5.join(target, "gitignore"), path5.join(target, ".gitignore"));
|
|
1782
|
+
}
|
|
211
1783
|
const projectName = packageName(target);
|
|
212
1784
|
const compactProjectId = projectName.toLowerCase().replace(/[^a-z0-9]+/gu, "") || "game";
|
|
213
1785
|
const projectId = /^[a-z]/u.test(compactProjectId) ? compactProjectId : `game${compactProjectId}`;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
);
|
|
1786
|
+
const replacements = Object.fromEntries([
|
|
1787
|
+
["__PROJECT_NAME__", projectName],
|
|
1788
|
+
["__PROJECT_ID__", projectId]
|
|
1789
|
+
]);
|
|
1790
|
+
await stampTemplateLoading(target, source, root);
|
|
1791
|
+
await copyAgentFiles(target, root);
|
|
1792
|
+
await renderTemplate(target, replacements);
|
|
1793
|
+
await copyReferenceBundle(target, root, replacements);
|
|
1794
|
+
await copyCapabilityManifest(target, root);
|
|
1795
|
+
await copyFrameworkPatches(target, root);
|
|
221
1796
|
await applyPackageSources(target, options.packageSources);
|
|
222
1797
|
await assertMcpConfig(target);
|
|
1798
|
+
await assertReferenceBundle(target);
|
|
223
1799
|
const installed = options.install ?? true;
|
|
224
1800
|
if (installed) await runInstall(target);
|
|
225
1801
|
return { installed, target, template };
|
|
226
1802
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
1803
|
+
var PACKAGE_SOURCE_FLAG = /^--([a-z0-9-]+)-package$/u;
|
|
1804
|
+
var SCOPED_PACKAGE_FLAG_PREFIX = "threenative-";
|
|
1805
|
+
function packageNameFromFlag(flag) {
|
|
1806
|
+
const match = flag.match(PACKAGE_SOURCE_FLAG);
|
|
1807
|
+
if (match === null) return void 0;
|
|
1808
|
+
const suffix = match[1];
|
|
1809
|
+
if (suffix === void 0) return void 0;
|
|
1810
|
+
if (suffix.startsWith(SCOPED_PACKAGE_FLAG_PREFIX)) {
|
|
1811
|
+
const scopedSuffix = suffix.slice(SCOPED_PACKAGE_FLAG_PREFIX.length);
|
|
1812
|
+
return scopedSuffix.length === 0 ? void 0 : `@threenative/${scopedSuffix}`;
|
|
1813
|
+
}
|
|
1814
|
+
if (suffix === "runtime") return void 0;
|
|
1815
|
+
if (suffix === "cli") return "create-threenative";
|
|
1816
|
+
if (suffix === "engine-mcp") return "threenative-engine-mcp";
|
|
1817
|
+
return `@threenative/${suffix}`;
|
|
230
1818
|
}
|
|
1819
|
+
var BOOLEAN_FLAGS = /* @__PURE__ */ new Set(["--no-install", "--help", "-h"]);
|
|
1820
|
+
var VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
1821
|
+
"--template",
|
|
1822
|
+
"--genre",
|
|
1823
|
+
"--runtime-package",
|
|
1824
|
+
...Object.values(PACKAGE_SOURCE_FLAGS)
|
|
1825
|
+
]);
|
|
1826
|
+
var SCAFFOLD_USAGE = "Usage: pnpm create threenative my-game";
|
|
231
1827
|
function parseArgs(argv) {
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
1828
|
+
const values = /* @__PURE__ */ new Map();
|
|
1829
|
+
const booleans = /* @__PURE__ */ new Set();
|
|
1830
|
+
const targets = [];
|
|
1831
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
1832
|
+
const token = argv[index] ?? "";
|
|
1833
|
+
if (!token.startsWith("-")) {
|
|
1834
|
+
targets.push(token);
|
|
1835
|
+
continue;
|
|
1836
|
+
}
|
|
1837
|
+
const equals = token.indexOf("=");
|
|
1838
|
+
const name = equals === -1 ? token : token.slice(0, equals);
|
|
1839
|
+
const inlineValue = equals === -1 ? void 0 : token.slice(equals + 1);
|
|
1840
|
+
if (BOOLEAN_FLAGS.has(name)) {
|
|
1841
|
+
if (inlineValue !== void 0)
|
|
1842
|
+
throw new Error(`Option '${name}' takes no value. ${SCAFFOLD_USAGE}`);
|
|
1843
|
+
booleans.add(name);
|
|
1844
|
+
continue;
|
|
1845
|
+
}
|
|
1846
|
+
if (!VALUE_FLAGS.has(name) && !PACKAGE_SOURCE_FLAG.test(name))
|
|
1847
|
+
throw new Error(`Unknown option '${name}'. ${SCAFFOLD_USAGE}`);
|
|
1848
|
+
const next = argv[index + 1];
|
|
1849
|
+
const value = inlineValue ?? next;
|
|
1850
|
+
if (value === void 0 || value.length === 0 || value.startsWith("-"))
|
|
1851
|
+
throw new Error(`Option '${name}' requires a value. ${SCAFFOLD_USAGE}`);
|
|
1852
|
+
values.set(name, value);
|
|
1853
|
+
if (inlineValue === void 0) index += 1;
|
|
1854
|
+
}
|
|
1855
|
+
const target = targets[0];
|
|
1856
|
+
if (target === void 0) throw new Error(`Missing target directory. ${SCAFFOLD_USAGE}`);
|
|
1857
|
+
if (targets.length > 1)
|
|
1858
|
+
throw new Error(`Unexpected extra argument '${targets.at(1)}'. ${SCAFFOLD_USAGE}`);
|
|
1859
|
+
const template = values.get("--template");
|
|
238
1860
|
if (template !== void 0) kitManifest(template);
|
|
1861
|
+
const genre = values.get("--genre");
|
|
1862
|
+
if (template !== void 0 && genre !== void 0)
|
|
1863
|
+
throw new Error(`Options '--template' and '--genre' cannot be combined. ${SCAFFOLD_USAGE}`);
|
|
1864
|
+
const resolvedTemplate = genre === void 0 ? template : templateForGenre(genre);
|
|
239
1865
|
const packageSources = {};
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
["@threenative/playtest", "--playtest-package"],
|
|
244
|
-
["@threenative/runtime-native", "--runtime-native-package"],
|
|
245
|
-
["@threenative/studio", "--studio-package"],
|
|
246
|
-
["@threenative/ui", "--ui-package"],
|
|
247
|
-
["create-threenative", "--cli-package"]
|
|
248
|
-
]) {
|
|
249
|
-
const source = readFlag(argv, flag);
|
|
1866
|
+
const knownPackageFlags = new Set(Object.values(PACKAGE_SOURCE_FLAGS));
|
|
1867
|
+
for (const [name, flag] of Object.entries(PACKAGE_SOURCE_FLAGS)) {
|
|
1868
|
+
const source = values.get(flag);
|
|
250
1869
|
if (source !== void 0) packageSources[name] = source;
|
|
251
1870
|
}
|
|
1871
|
+
for (const [flag, source] of values) {
|
|
1872
|
+
if (knownPackageFlags.has(flag)) continue;
|
|
1873
|
+
const name = packageNameFromFlag(flag);
|
|
1874
|
+
if (name !== void 0) packageSources[name] = source;
|
|
1875
|
+
}
|
|
1876
|
+
const shortRuntimeSource = values.get("--runtime-package");
|
|
1877
|
+
if (shortRuntimeSource !== void 0) {
|
|
1878
|
+
packageSources["@threenative/runtime-native"] = shortRuntimeSource;
|
|
1879
|
+
}
|
|
252
1880
|
return {
|
|
253
|
-
install: !
|
|
1881
|
+
install: !booleans.has("--no-install"),
|
|
254
1882
|
target,
|
|
255
1883
|
...Object.keys(packageSources).length === 0 ? {} : { packageSources },
|
|
256
|
-
...
|
|
1884
|
+
...resolvedTemplate === void 0 ? {} : { template: resolvedTemplate }
|
|
257
1885
|
};
|
|
258
1886
|
}
|
|
259
1887
|
async function main() {
|
|
260
1888
|
const argv = process.argv.slice(2);
|
|
1889
|
+
if (argv[0] === "inspect") {
|
|
1890
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
1891
|
+
process.stdout.write(inspectHelp());
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1894
|
+
await inspectCommand(argv.slice(1));
|
|
1895
|
+
return;
|
|
1896
|
+
}
|
|
261
1897
|
if (argv.includes("--help") || argv.includes("-h")) {
|
|
262
1898
|
process.stdout.write(cliHelp());
|
|
263
1899
|
return;
|
|
@@ -265,15 +1901,13 @@ async function main() {
|
|
|
265
1901
|
const result = await createProject(parseArgs(argv));
|
|
266
1902
|
process.stdout.write(`Created ${result.template} project at ${result.target}
|
|
267
1903
|
`);
|
|
268
|
-
process.stdout.write(
|
|
269
|
-
"Templates: minimal (smallest), starter (default), platformer. Choose with --template <name>.\n"
|
|
270
|
-
);
|
|
1904
|
+
process.stdout.write(scaffoldCompletionMessage(discoverKitManifests()));
|
|
271
1905
|
if (!result.installed)
|
|
272
1906
|
process.stdout.write("Skipped install (--no-install). Run pnpm install, then pnpm dev.\n");
|
|
273
1907
|
else process.stdout.write("Next: cd into the project and run pnpm dev.\n");
|
|
274
1908
|
}
|
|
275
1909
|
var entryPath = process.argv[1];
|
|
276
|
-
if (entryPath !== void 0 && existsSync(entryPath) && realpathSync(
|
|
1910
|
+
if (entryPath !== void 0 && existsSync(entryPath) && realpathSync(path5.resolve(entryPath)) === realpathSync(fileURLToPath(import.meta.url))) {
|
|
277
1911
|
main().catch((error) => {
|
|
278
1912
|
process.stderr.write(`${error instanceof Error ? error.message : String(error)}
|
|
279
1913
|
`);
|
|
@@ -281,4 +1915,4 @@ if (entryPath !== void 0 && existsSync(entryPath) && realpathSync(path.resolve(e
|
|
|
281
1915
|
});
|
|
282
1916
|
}
|
|
283
1917
|
|
|
284
|
-
export { cliHelp, createProject, discoverKitManifests, discoverTemplateNames, kitManifest, parseArgs, templateRoot };
|
|
1918
|
+
export { FULL_LOADING_TEMPLATES, canonicalLoadingPath, cliHelp, createEngineFreshnessPlugin, createProject, createWebBrandPlugin, discoverKitManifests, discoverTemplateNames, hashEngineDist, kitManifest, parseArgs, renderWebManifest, restampTemplateLoadingCopies, scaffoldCompletionMessage, stampLoadingSource, templateForGenre, templateRoot };
|