create-threenative 0.2.0
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/README.md +16 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +283 -0
- package/dist/threenative.d.ts +6 -0
- package/dist/threenative.js +757 -0
- package/package.json +44 -0
- package/templates/action-rpg/.mcp.json +16 -0
- package/templates/action-rpg/AGENTS.md +40 -0
- package/templates/action-rpg/CLAUDE.md +42 -0
- package/templates/action-rpg/index.html +13 -0
- package/templates/action-rpg/kit.json +7 -0
- package/templates/action-rpg/package.json +47 -0
- package/templates/action-rpg/playtests/combat.playtest.json +61 -0
- package/templates/action-rpg/playtests/fail.playtest.json +21 -0
- package/templates/action-rpg/playtests/inventory.playtest.json +111 -0
- package/templates/action-rpg/playtests/progress.playtest.json +99 -0
- package/templates/action-rpg/playtests/survives.playtest.json +32 -0
- package/templates/action-rpg/playtests/win.playtest.json +30 -0
- package/templates/action-rpg/public/favicon.svg +5 -0
- package/templates/action-rpg/src/abilities/Ability.ts +45 -0
- package/templates/action-rpg/src/entities/Enemy.ts +143 -0
- package/templates/action-rpg/src/entities/Player.ts +83 -0
- package/templates/action-rpg/src/game.ts +40 -0
- package/templates/action-rpg/src/items/Inventory.ts +163 -0
- package/templates/action-rpg/src/loot/drops.ts +40 -0
- package/templates/action-rpg/src/main.ts +15 -0
- package/templates/action-rpg/src/physics.ts +40 -0
- package/templates/action-rpg/src/playtest-events.ts +15 -0
- package/templates/action-rpg/src/progress.ts +35 -0
- package/templates/action-rpg/src/render/camera.ts +26 -0
- package/templates/action-rpg/src/render/lighting.ts +30 -0
- package/templates/action-rpg/src/render/loading.ts +90 -0
- package/templates/action-rpg/src/render/materials.ts +40 -0
- package/templates/action-rpg/src/render/palette.ts +9 -0
- package/templates/action-rpg/src/render/postprocessing.ts +18 -0
- package/templates/action-rpg/src/render/shapes.ts +110 -0
- package/templates/action-rpg/src/render/sky.ts +18 -0
- package/templates/action-rpg/src/render/types.ts +3 -0
- package/templates/action-rpg/src/scenes/Boot.ts +12 -0
- package/templates/action-rpg/src/scenes/Play.ts +449 -0
- package/templates/action-rpg/src/state.ts +40 -0
- package/templates/action-rpg/src/stats/StatBlock.ts +57 -0
- package/templates/action-rpg/src/style.css +32 -0
- package/templates/action-rpg/src/ui/AbilityBar.tsx +28 -0
- package/templates/action-rpg/src/ui/App.tsx +21 -0
- package/templates/action-rpg/src/ui/CharacterPanel.tsx +31 -0
- package/templates/action-rpg/src/ui/Hud.tsx +29 -0
- package/templates/action-rpg/src/ui/InventoryPanel.tsx +37 -0
- package/templates/action-rpg/tailwind.config.ts +7 -0
- package/templates/action-rpg/threenative.config.ts +29 -0
- package/templates/action-rpg/tsconfig.json +17 -0
- package/templates/action-rpg/vite.config.ts +8 -0
- package/templates/defense/.mcp.json +16 -0
- package/templates/defense/AGENTS.md +53 -0
- package/templates/defense/CLAUDE.md +55 -0
- package/templates/defense/README.md +9 -0
- package/templates/defense/index.html +13 -0
- package/templates/defense/kit.json +7 -0
- package/templates/defense/package.json +46 -0
- package/templates/defense/playtests/leak.playtest.json +18 -0
- package/templates/defense/playtests/placement.playtest.json +40 -0
- package/templates/defense/playtests/scan.playtest.json +20 -0
- package/templates/defense/playtests/survive.playtest.json +26 -0
- package/templates/defense/playtests/survives.playtest.json +36 -0
- package/templates/defense/public/favicon.svg +5 -0
- package/templates/defense/src/attackers/Attacker.ts +104 -0
- package/templates/defense/src/board/Route.ts +80 -0
- package/templates/defense/src/economy.ts +36 -0
- package/templates/defense/src/entities/Player.ts +44 -0
- package/templates/defense/src/game.ts +30 -0
- package/templates/defense/src/main.ts +15 -0
- package/templates/defense/src/physics.ts +43 -0
- package/templates/defense/src/placement/Buildable.ts +49 -0
- package/templates/defense/src/playtest-events.ts +15 -0
- package/templates/defense/src/render/camera.ts +10 -0
- package/templates/defense/src/render/lighting.ts +32 -0
- package/templates/defense/src/render/loading.ts +89 -0
- package/templates/defense/src/render/materials.ts +13 -0
- package/templates/defense/src/render/palette.ts +21 -0
- package/templates/defense/src/render/postprocessing.ts +14 -0
- package/templates/defense/src/render/shapes.ts +89 -0
- package/templates/defense/src/render/sky.ts +45 -0
- package/templates/defense/src/scenes/Boot.ts +12 -0
- package/templates/defense/src/scenes/Defense.ts +165 -0
- package/templates/defense/src/state.ts +50 -0
- package/templates/defense/src/style.css +32 -0
- package/templates/defense/src/towers/Tower.ts +96 -0
- package/templates/defense/src/towers/targeting.ts +53 -0
- package/templates/defense/src/ui/App.tsx +17 -0
- package/templates/defense/src/ui/Hud.tsx +61 -0
- package/templates/defense/src/ui/Menu.tsx +7 -0
- package/templates/defense/src/waves.ts +40 -0
- package/templates/defense/tailwind.config.ts +1 -0
- package/templates/defense/threenative.config.ts +29 -0
- package/templates/defense/tsconfig.json +17 -0
- package/templates/defense/vite.config.ts +5 -0
- package/templates/minimal/.mcp.json +16 -0
- package/templates/minimal/AGENTS.md +400 -0
- package/templates/minimal/CLAUDE.md +402 -0
- package/templates/minimal/assets/.gitkeep +0 -0
- package/templates/minimal/index.html +14 -0
- package/templates/minimal/kit.json +7 -0
- package/templates/minimal/package.json +40 -0
- package/templates/minimal/playtests/play.playtest.json +32 -0
- package/templates/minimal/playtests/survives.playtest.json +32 -0
- package/templates/minimal/public/.gitkeep +0 -0
- package/templates/minimal/public/favicon.svg +4 -0
- package/templates/minimal/public/icon.png +0 -0
- package/templates/minimal/src/entities/Player.ts +66 -0
- package/templates/minimal/src/game.ts +28 -0
- package/templates/minimal/src/main.ts +17 -0
- package/templates/minimal/src/render/camera.ts +11 -0
- package/templates/minimal/src/render/hud.ts +53 -0
- package/templates/minimal/src/render/lighting.ts +46 -0
- package/templates/minimal/src/render/loading.ts +113 -0
- package/templates/minimal/src/render/materials.ts +16 -0
- package/templates/minimal/src/render/palette.ts +9 -0
- package/templates/minimal/src/render/postprocessing.ts +20 -0
- package/templates/minimal/src/render/sky.ts +41 -0
- package/templates/minimal/src/scenes/Boot.ts +5 -0
- package/templates/minimal/src/scenes/Play.ts +65 -0
- package/templates/minimal/src/state.ts +1 -0
- package/templates/minimal/src/style.css +41 -0
- package/templates/minimal/threenative.config.ts +32 -0
- package/templates/minimal/tsconfig.json +16 -0
- package/templates/minimal/vite.config.ts +3 -0
- package/templates/platformer/.mcp.json +16 -0
- package/templates/platformer/AGENTS.md +199 -0
- package/templates/platformer/CLAUDE.md +201 -0
- package/templates/platformer/assets/.gitkeep +0 -0
- package/templates/platformer/index.html +13 -0
- package/templates/platformer/kit.json +7 -0
- package/templates/platformer/package.json +50 -0
- package/templates/platformer/playtests/avoidance.playtest.json +23 -0
- package/templates/platformer/playtests/buffer.playtest.json +17 -0
- package/templates/platformer/playtests/chase.playtest.json +21 -0
- package/templates/platformer/playtests/collect.playtest.json +56 -0
- package/templates/platformer/playtests/collision-layers.playtest.json +36 -0
- package/templates/platformer/playtests/coyote.playtest.json +21 -0
- package/templates/platformer/playtests/damage.playtest.json +31 -0
- package/templates/platformer/playtests/dash.playtest.json +21 -0
- package/templates/platformer/playtests/jump.playtest.json +21 -0
- package/templates/platformer/playtests/oneway.playtest.json +17 -0
- package/templates/platformer/playtests/patrol.playtest.json +13 -0
- package/templates/platformer/playtests/performance.playtest.json +21 -0
- package/templates/platformer/playtests/physics.playtest.json +14 -0
- package/templates/platformer/playtests/respawn.playtest.json +31 -0
- package/templates/platformer/playtests/stomp-rise.playtest.json +41 -0
- package/templates/platformer/playtests/stomp.playtest.json +34 -0
- package/templates/platformer/playtests/survives.playtest.json +32 -0
- package/templates/platformer/playtests/terminal-loop-fail.playtest.json +29 -0
- package/templates/platformer/playtests/terminal-loop-win.playtest.json +52 -0
- package/templates/platformer/public/.gitkeep +0 -0
- package/templates/platformer/public/favicon.svg +4 -0
- package/templates/platformer/public/icon.png +0 -0
- package/templates/platformer/src/entities/Character.ts +218 -0
- package/templates/platformer/src/entities/Chaser.ts +118 -0
- package/templates/platformer/src/entities/Patrol.ts +88 -0
- package/templates/platformer/src/entities/Pickup.ts +72 -0
- package/templates/platformer/src/game.ts +27 -0
- package/templates/platformer/src/level/Checkpoints.ts +66 -0
- package/templates/platformer/src/level/Platform.ts +34 -0
- package/templates/platformer/src/main.ts +14 -0
- package/templates/platformer/src/playtest-events.ts +15 -0
- package/templates/platformer/src/render/camera.ts +8 -0
- package/templates/platformer/src/render/lighting.ts +38 -0
- package/templates/platformer/src/render/loading.ts +113 -0
- package/templates/platformer/src/render/materials.ts +11 -0
- package/templates/platformer/src/render/palette.ts +54 -0
- package/templates/platformer/src/render/postprocessing.ts +18 -0
- package/templates/platformer/src/render/rig.ts +60 -0
- package/templates/platformer/src/render/sky.ts +47 -0
- package/templates/platformer/src/render/terrain.ts +31 -0
- package/templates/platformer/src/render/touch-controls.ts +157 -0
- package/templates/platformer/src/render/touch-layout.ts +63 -0
- package/templates/platformer/src/scenes/Boot.ts +12 -0
- package/templates/platformer/src/scenes/Level.ts +176 -0
- package/templates/platformer/src/state.ts +23 -0
- package/templates/platformer/src/style.css +31 -0
- package/templates/platformer/src/ui/App.tsx +17 -0
- package/templates/platformer/src/ui/Hud.tsx +41 -0
- package/templates/platformer/src/ui/Menu.tsx +7 -0
- package/templates/platformer/tailwind.config.ts +2 -0
- package/templates/platformer/threenative.config.ts +32 -0
- package/templates/platformer/tsconfig.json +17 -0
- package/templates/platformer/vite.config.ts +5 -0
- package/templates/racing/.mcp.json +16 -0
- package/templates/racing/AGENTS.md +48 -0
- package/templates/racing/CLAUDE.md +50 -0
- package/templates/racing/index.html +13 -0
- package/templates/racing/kit.json +7 -0
- package/templates/racing/package.json +46 -0
- package/templates/racing/playtests/boost.playtest.json +45 -0
- package/templates/racing/playtests/outcome.playtest.json +78 -0
- package/templates/racing/playtests/ranking.playtest.json +37 -0
- package/templates/racing/playtests/rescue.playtest.json +28 -0
- package/templates/racing/playtests/reverse.playtest.json +37 -0
- package/templates/racing/playtests/shortcut.playtest.json +44 -0
- package/templates/racing/playtests/survives.playtest.json +32 -0
- package/templates/racing/public/favicon.svg +6 -0
- package/templates/racing/src/entities/RacingCar.ts +114 -0
- package/templates/racing/src/entities/Rival.ts +46 -0
- package/templates/racing/src/game.ts +29 -0
- package/templates/racing/src/kart/boost.ts +38 -0
- package/templates/racing/src/main.ts +15 -0
- package/templates/racing/src/playtest-events.ts +15 -0
- package/templates/racing/src/render/camera.ts +28 -0
- package/templates/racing/src/render/lighting.ts +32 -0
- package/templates/racing/src/render/loading.ts +58 -0
- package/templates/racing/src/render/materials.ts +15 -0
- package/templates/racing/src/render/palette.ts +30 -0
- package/templates/racing/src/render/postprocessing.ts +14 -0
- package/templates/racing/src/render/shapes.ts +37 -0
- package/templates/racing/src/render/sky.ts +45 -0
- package/templates/racing/src/scenes/Boot.ts +12 -0
- package/templates/racing/src/scenes/Race.ts +180 -0
- package/templates/racing/src/state.ts +35 -0
- package/templates/racing/src/style.css +32 -0
- package/templates/racing/src/track/Checkline.ts +19 -0
- package/templates/racing/src/track/Lap.ts +104 -0
- package/templates/racing/src/track/Ranking.ts +35 -0
- package/templates/racing/src/track/Track.ts +229 -0
- package/templates/racing/src/track/TrackSector.ts +77 -0
- package/templates/racing/src/track/rescue.ts +21 -0
- package/templates/racing/src/ui/App.tsx +17 -0
- package/templates/racing/src/ui/Hud.tsx +71 -0
- package/templates/racing/src/ui/Menu.tsx +7 -0
- package/templates/racing/tailwind.config.ts +2 -0
- package/templates/racing/threenative.config.ts +29 -0
- package/templates/racing/tsconfig.json +17 -0
- package/templates/racing/vite.config.ts +5 -0
- package/templates/shooter/.mcp.json +16 -0
- package/templates/shooter/AGENTS.md +69 -0
- package/templates/shooter/CLAUDE.md +71 -0
- package/templates/shooter/index.html +13 -0
- package/templates/shooter/kit.json +7 -0
- package/templates/shooter/package.json +46 -0
- package/templates/shooter/playtests/fail.playtest.json +30 -0
- package/templates/shooter/playtests/shooter.playtest.json +89 -0
- package/templates/shooter/playtests/survives.playtest.json +32 -0
- package/templates/shooter/public/favicon.svg +4 -0
- package/templates/shooter/src/combat/damage.ts +41 -0
- package/templates/shooter/src/entities/Pickup.ts +70 -0
- package/templates/shooter/src/entities/Player.ts +93 -0
- package/templates/shooter/src/entities/Target.ts +103 -0
- package/templates/shooter/src/game.ts +36 -0
- package/templates/shooter/src/level/SpawnPoints.ts +28 -0
- package/templates/shooter/src/main.ts +26 -0
- package/templates/shooter/src/physics.ts +49 -0
- package/templates/shooter/src/playtest-events.ts +15 -0
- package/templates/shooter/src/render/camera.ts +29 -0
- package/templates/shooter/src/render/lighting.ts +38 -0
- package/templates/shooter/src/render/loading.ts +86 -0
- package/templates/shooter/src/render/materials.ts +38 -0
- package/templates/shooter/src/render/palette.ts +9 -0
- package/templates/shooter/src/render/postprocessing.ts +19 -0
- package/templates/shooter/src/render/shapes.ts +194 -0
- package/templates/shooter/src/render/sky.ts +37 -0
- package/templates/shooter/src/render/types.ts +3 -0
- package/templates/shooter/src/render/ui.css +212 -0
- package/templates/shooter/src/render/ui.ts +59 -0
- package/templates/shooter/src/scenes/Boot.ts +12 -0
- package/templates/shooter/src/scenes/Play.ts +428 -0
- package/templates/shooter/src/state.ts +29 -0
- package/templates/shooter/src/ui/App.tsx +25 -0
- package/templates/shooter/src/ui/Hud.tsx +49 -0
- package/templates/shooter/src/ui/Menu.tsx +26 -0
- package/templates/shooter/src/waves.ts +50 -0
- package/templates/shooter/src/weapons/Hitscan.ts +43 -0
- package/templates/shooter/src/weapons/Projectile.ts +76 -0
- package/templates/shooter/tailwind.config.ts +5 -0
- package/templates/shooter/threenative.config.ts +29 -0
- package/templates/shooter/tsconfig.json +17 -0
- package/templates/shooter/vite.config.ts +8 -0
- package/templates/starter/.mcp.json +16 -0
- package/templates/starter/AGENTS.md +450 -0
- package/templates/starter/CLAUDE.md +452 -0
- package/templates/starter/assets/.gitkeep +0 -0
- package/templates/starter/index.html +13 -0
- package/templates/starter/kit.json +7 -0
- package/templates/starter/package.json +49 -0
- package/templates/starter/playtests/buffer.playtest.json +29 -0
- package/templates/starter/playtests/coyote.playtest.json +35 -0
- package/templates/starter/playtests/forward.playtest.json +15 -0
- package/templates/starter/playtests/hot-reload.playtest.json +28 -0
- package/templates/starter/playtests/look.playtest.json +43 -0
- package/templates/starter/playtests/monitoring.playtest.json +41 -0
- package/templates/starter/playtests/pause.playtest.json +33 -0
- package/templates/starter/playtests/play.playtest.json +16 -0
- package/templates/starter/playtests/respawn.playtest.json +28 -0
- package/templates/starter/playtests/restart.playtest.json +36 -0
- package/templates/starter/playtests/seed.playtest.json +18 -0
- package/templates/starter/playtests/survives.playtest.json +32 -0
- package/templates/starter/public/.gitkeep +0 -0
- package/templates/starter/public/favicon.svg +4 -0
- package/templates/starter/public/icon.png +0 -0
- package/templates/starter/public/native-proof.glb +0 -0
- package/templates/starter/public/native-proof.png +0 -0
- package/templates/starter/public/pickup.ogg +0 -0
- package/templates/starter/src/entities/Crate.ts +34 -0
- package/templates/starter/src/entities/Player.ts +80 -0
- package/templates/starter/src/game.ts +30 -0
- package/templates/starter/src/main.ts +15 -0
- package/templates/starter/src/render/camera.ts +57 -0
- package/templates/starter/src/render/lighting.ts +55 -0
- package/templates/starter/src/render/materials.ts +12 -0
- package/templates/starter/src/render/palette.ts +9 -0
- package/templates/starter/src/render/postprocessing.ts +18 -0
- package/templates/starter/src/render/shapes.ts +147 -0
- package/templates/starter/src/render/sky.ts +56 -0
- package/templates/starter/src/scenes/Play.ts +161 -0
- package/templates/starter/src/state.ts +10 -0
- package/templates/starter/src/style.css +45 -0
- package/templates/starter/src/ui/App.tsx +19 -0
- package/templates/starter/src/ui/Hud.tsx +37 -0
- package/templates/starter/src/ui/Menu.tsx +43 -0
- package/templates/starter/tailwind.config.ts +2 -0
- package/templates/starter/threenative.config.ts +31 -0
- package/templates/starter/tsconfig.json +17 -0
- package/templates/starter/vite.config.ts +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# create-threenative
|
|
2
|
+
|
|
3
|
+
Scaffold a ThreeNative game:
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm create threenative my-game
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The default template is `starter`. Choose `minimal` for the smallest project or `platformer`
|
|
10
|
+
for a worked platform game:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
pnpm create threenative my-game --template minimal
|
|
14
|
+
pnpm create threenative my-game --template starter
|
|
15
|
+
pnpm create threenative my-game --template platformer
|
|
16
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
type ScaffoldTemplate = string;
|
|
3
|
+
interface IKitManifest {
|
|
4
|
+
readonly blurb: string;
|
|
5
|
+
readonly genre: string;
|
|
6
|
+
readonly kit: boolean;
|
|
7
|
+
readonly name: ScaffoldTemplate;
|
|
8
|
+
readonly title: string;
|
|
9
|
+
}
|
|
10
|
+
interface IScaffoldOptions {
|
|
11
|
+
install?: boolean;
|
|
12
|
+
packageSources?: Partial<Record<"@threenative/core" | "@threenative/physics" | "@threenative/playtest" | "@threenative/runtime-native" | "@threenative/studio" | "@threenative/ui" | "create-threenative", string>>;
|
|
13
|
+
target: string;
|
|
14
|
+
template?: ScaffoldTemplate;
|
|
15
|
+
}
|
|
16
|
+
interface IScaffoldResult {
|
|
17
|
+
installed: boolean;
|
|
18
|
+
target: string;
|
|
19
|
+
template: ScaffoldTemplate;
|
|
20
|
+
}
|
|
21
|
+
declare function templateRoot(): string;
|
|
22
|
+
/** Reads every template directory on each call so a new kit is live without a TypeScript edit. */
|
|
23
|
+
declare function discoverKitManifests(root?: string): readonly IKitManifest[];
|
|
24
|
+
declare function discoverTemplateNames(root?: string): readonly ScaffoldTemplate[];
|
|
25
|
+
declare function kitManifest(template: ScaffoldTemplate, root?: string): IKitManifest;
|
|
26
|
+
declare function cliHelp(): string;
|
|
27
|
+
declare function createProject(options: IScaffoldOptions, cwd?: string): Promise<IScaffoldResult>;
|
|
28
|
+
declare function parseArgs(argv: readonly string[]): IScaffoldOptions;
|
|
29
|
+
|
|
30
|
+
export { type IKitManifest, type IScaffoldOptions, type IScaffoldResult, type ScaffoldTemplate, cliHelp, createProject, discoverKitManifests, discoverTemplateNames, kitManifest, parseArgs, templateRoot };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import { readdirSync, readFileSync } from 'fs';
|
|
4
|
+
import { mkdir, cp, readdir, readFile, writeFile } from 'fs/promises';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
|
|
8
|
+
var TEXT_FILE_EXTENSIONS = /* @__PURE__ */ new Set([".css", ".html", ".json", ".md", ".svg", ".ts", ".tsx"]);
|
|
9
|
+
var TEMPLATE_NAME = /^[a-z][a-z0-9-]*$/u;
|
|
10
|
+
function templateRoot() {
|
|
11
|
+
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../templates");
|
|
12
|
+
}
|
|
13
|
+
function invalidManifest(file, reason) {
|
|
14
|
+
throw new Error(`TN_KIT_MANIFEST_INVALID: ${file}: ${reason}`);
|
|
15
|
+
}
|
|
16
|
+
function nonEmptyString(value, field, file) {
|
|
17
|
+
if (typeof value !== "string" || value.trim().length === 0)
|
|
18
|
+
return invalidManifest(file, `${field} must be a non-empty string`);
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function loadManifest(directory) {
|
|
22
|
+
const file = path.join(directory, "kit.json");
|
|
23
|
+
let raw;
|
|
24
|
+
try {
|
|
25
|
+
raw = readFileSync(file, "utf8");
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error.code === "ENOENT")
|
|
28
|
+
throw new Error(`TN_KIT_MANIFEST_MISSING: ${file}`);
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
let value;
|
|
32
|
+
try {
|
|
33
|
+
value = JSON.parse(raw);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return invalidManifest(file, `JSON could not be parsed: ${String(error)}`);
|
|
36
|
+
}
|
|
37
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
38
|
+
return invalidManifest(file, "the root must be an object");
|
|
39
|
+
const record = value;
|
|
40
|
+
const directoryName = path.basename(directory);
|
|
41
|
+
const name = nonEmptyString(record.name, "name", file);
|
|
42
|
+
if (!TEMPLATE_NAME.test(name))
|
|
43
|
+
return invalidManifest(file, "name must match /^[a-z][a-z0-9-]*$/");
|
|
44
|
+
if (name !== directoryName)
|
|
45
|
+
return invalidManifest(file, `name '${name}' must match directory '${directoryName}'`);
|
|
46
|
+
const kit = record.kit;
|
|
47
|
+
if (typeof kit !== "boolean") return invalidManifest(file, "kit must be a boolean");
|
|
48
|
+
return {
|
|
49
|
+
blurb: nonEmptyString(record.blurb, "blurb", file),
|
|
50
|
+
genre: nonEmptyString(record.genre, "genre", file),
|
|
51
|
+
kit,
|
|
52
|
+
name,
|
|
53
|
+
title: nonEmptyString(record.title, "title", file)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function discoverKitManifests(root = templateRoot()) {
|
|
57
|
+
return readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => loadManifest(path.join(root, entry.name))).sort((left, right) => left.name.localeCompare(right.name));
|
|
58
|
+
}
|
|
59
|
+
function discoverTemplateNames(root = templateRoot()) {
|
|
60
|
+
return discoverKitManifests(root).map(({ name }) => name);
|
|
61
|
+
}
|
|
62
|
+
function kitManifest(template, root = templateRoot()) {
|
|
63
|
+
const manifest = discoverKitManifests(root).find(({ name }) => name === template);
|
|
64
|
+
if (manifest === void 0)
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Unknown template '${template}'. Available templates: ${discoverTemplateNames(root).join(", ")}.`
|
|
67
|
+
);
|
|
68
|
+
return manifest;
|
|
69
|
+
}
|
|
70
|
+
function templateHelp(manifests) {
|
|
71
|
+
const width = Math.max(...manifests.map(({ name }) => name.length), 0);
|
|
72
|
+
return manifests.map(({ blurb, name, title }) => ` ${name.padEnd(width)} ${title}: ${blurb}`).join("\n");
|
|
73
|
+
}
|
|
74
|
+
function cliHelp() {
|
|
75
|
+
const manifests = discoverKitManifests();
|
|
76
|
+
return `${[
|
|
77
|
+
"Usage: npx create-threenative <directory> [options]",
|
|
78
|
+
"",
|
|
79
|
+
"Options:",
|
|
80
|
+
" --template <name> Choose a template.",
|
|
81
|
+
" --no-install Copy the project without running pnpm install.",
|
|
82
|
+
" --help Show this help.",
|
|
83
|
+
"",
|
|
84
|
+
"Templates:",
|
|
85
|
+
templateHelp(manifests)
|
|
86
|
+
].join("\n")}
|
|
87
|
+
`;
|
|
88
|
+
}
|
|
89
|
+
function packageName(target) {
|
|
90
|
+
const name = path.basename(target).toLowerCase().replace(/[^a-z0-9-_]+/g, "-");
|
|
91
|
+
if (name.length === 0 || name === "-" || name === "_") {
|
|
92
|
+
throw new Error(`Cannot derive a package name from '${target}'.`);
|
|
93
|
+
}
|
|
94
|
+
return name;
|
|
95
|
+
}
|
|
96
|
+
async function isEmpty(directory) {
|
|
97
|
+
const entries = await readdir(directory).catch(() => []);
|
|
98
|
+
return entries.length === 0;
|
|
99
|
+
}
|
|
100
|
+
async function renderTemplate(directory, replacements) {
|
|
101
|
+
const files = await readdir(directory, { withFileTypes: true });
|
|
102
|
+
for (const entry of files) {
|
|
103
|
+
const source = path.join(directory, entry.name);
|
|
104
|
+
if (entry.isDirectory()) {
|
|
105
|
+
await renderTemplate(source, replacements);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (!TEXT_FILE_EXTENSIONS.has(path.extname(entry.name))) continue;
|
|
109
|
+
const content = await readFile(source, "utf8");
|
|
110
|
+
let rendered = content;
|
|
111
|
+
for (const [placeholder, value] of Object.entries(replacements)) {
|
|
112
|
+
rendered = rendered.replaceAll(placeholder, value);
|
|
113
|
+
}
|
|
114
|
+
await writeFile(source, rendered);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function applyPackageSources(target, packageSources) {
|
|
118
|
+
if (packageSources === void 0) return;
|
|
119
|
+
const packagePath = path.join(target, "package.json");
|
|
120
|
+
const packageJson = JSON.parse(await readFile(packagePath, "utf8"));
|
|
121
|
+
for (const [name, source] of Object.entries(packageSources)) {
|
|
122
|
+
if (source === void 0) continue;
|
|
123
|
+
if (packageJson.optionalDependencies?.[name] !== void 0) {
|
|
124
|
+
packageJson.optionalDependencies[name] = source.startsWith("file:") ? source : `file:${source}`;
|
|
125
|
+
} else if (name === "@threenative/playtest" || name === "@threenative/studio" || name === "create-threenative") {
|
|
126
|
+
packageJson.devDependencies ??= {};
|
|
127
|
+
packageJson.devDependencies[name] = source.startsWith("file:") ? source : `file:${source}`;
|
|
128
|
+
} else {
|
|
129
|
+
packageJson.dependencies ??= {};
|
|
130
|
+
packageJson.dependencies[name] = source.startsWith("file:") ? source : `file:${source}`;
|
|
131
|
+
}
|
|
132
|
+
if (name === "create-threenative") {
|
|
133
|
+
packageJson.pnpm ??= {};
|
|
134
|
+
packageJson.pnpm.overrides ??= {};
|
|
135
|
+
packageJson.pnpm.overrides[name] = source.startsWith("file:") ? source : `file:${source}`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
await writeFile(packagePath, `${JSON.stringify(packageJson, null, 2)}
|
|
139
|
+
`);
|
|
140
|
+
}
|
|
141
|
+
var NODE_MODULES_PREFIX = "./node_modules/";
|
|
142
|
+
var REQUIRED_MCP_SERVERS = ["threenative-assets", "threenative-sculpt"];
|
|
143
|
+
function mcpPackageName(entry) {
|
|
144
|
+
const segments = entry.slice(NODE_MODULES_PREFIX.length).split("/");
|
|
145
|
+
return entry.startsWith(`${NODE_MODULES_PREFIX}@`) ? segments.slice(0, 2).join("/") : segments[0] ?? "";
|
|
146
|
+
}
|
|
147
|
+
async function assertMcpConfig(target) {
|
|
148
|
+
const configPath = path.join(target, ".mcp.json");
|
|
149
|
+
const raw = await readFile(configPath, "utf8").catch(() => {
|
|
150
|
+
throw new Error(`Scaffold produced no .mcp.json at '${configPath}'.`);
|
|
151
|
+
});
|
|
152
|
+
const { mcpServers } = JSON.parse(raw);
|
|
153
|
+
if (mcpServers === void 0 || Object.keys(mcpServers).length === 0) {
|
|
154
|
+
throw new Error(`'${configPath}' declares no mcpServers.`);
|
|
155
|
+
}
|
|
156
|
+
for (const name of REQUIRED_MCP_SERVERS) {
|
|
157
|
+
if (mcpServers[name] === void 0) {
|
|
158
|
+
throw new Error(`'${configPath}' is missing required MCP server '${name}'.`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const manifest = JSON.parse(await readFile(path.join(target, "package.json"), "utf8"));
|
|
162
|
+
const declared = /* @__PURE__ */ new Set([
|
|
163
|
+
...Object.keys(manifest.dependencies ?? {}),
|
|
164
|
+
...Object.keys(manifest.devDependencies ?? {})
|
|
165
|
+
]);
|
|
166
|
+
for (const [name, server] of Object.entries(mcpServers)) {
|
|
167
|
+
const entry = server.args?.[0];
|
|
168
|
+
if (entry === void 0 || !entry.startsWith(NODE_MODULES_PREFIX)) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
`MCP server '${name}' must launch from '${NODE_MODULES_PREFIX}', not '${entry ?? "nothing"}'.`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
const dependency = mcpPackageName(entry);
|
|
174
|
+
if (!declared.has(dependency)) {
|
|
175
|
+
throw new Error(
|
|
176
|
+
`MCP server '${name}' launches '${dependency}', which this project does not depend on.`
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
for (const [key, value] of Object.entries(server.env ?? {})) {
|
|
180
|
+
if (!key.endsWith("_DOWNLOAD_DIR")) continue;
|
|
181
|
+
if (!value.startsWith("./") || value.includes("..")) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`MCP server '${name}' sets ${key}='${value}'; it must be a './' path inside the project.`
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async function runInstall(target) {
|
|
190
|
+
await new Promise((resolve, reject) => {
|
|
191
|
+
const child = spawn("pnpm", ["install"], { cwd: target, stdio: "inherit" });
|
|
192
|
+
child.once("error", reject);
|
|
193
|
+
child.once("exit", (code) => {
|
|
194
|
+
if (code === 0) resolve();
|
|
195
|
+
else reject(new Error(`pnpm install exited with code ${code ?? "unknown"}.`));
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
async function createProject(options, cwd = process.cwd()) {
|
|
200
|
+
const manifests = discoverKitManifests();
|
|
201
|
+
const template = options.template ?? "starter";
|
|
202
|
+
if (!manifests.some(({ name }) => name === template)) kitManifest(template);
|
|
203
|
+
const target = path.resolve(cwd, options.target);
|
|
204
|
+
const targetExists = await isEmpty(target).catch(() => false);
|
|
205
|
+
if (!targetExists) {
|
|
206
|
+
throw new Error(`Target '${target}' already exists and is not empty.`);
|
|
207
|
+
}
|
|
208
|
+
await mkdir(target, { recursive: true });
|
|
209
|
+
const source = path.join(templateRoot(), template);
|
|
210
|
+
await cp(source, target, { recursive: true, errorOnExist: true });
|
|
211
|
+
const projectName = packageName(target);
|
|
212
|
+
const compactProjectId = projectName.toLowerCase().replace(/[^a-z0-9]+/gu, "") || "game";
|
|
213
|
+
const projectId = /^[a-z]/u.test(compactProjectId) ? compactProjectId : `game${compactProjectId}`;
|
|
214
|
+
await renderTemplate(
|
|
215
|
+
target,
|
|
216
|
+
Object.fromEntries([
|
|
217
|
+
["__PROJECT_NAME__", projectName],
|
|
218
|
+
["__PROJECT_ID__", projectId]
|
|
219
|
+
])
|
|
220
|
+
);
|
|
221
|
+
await applyPackageSources(target, options.packageSources);
|
|
222
|
+
await assertMcpConfig(target);
|
|
223
|
+
const installed = options.install ?? true;
|
|
224
|
+
if (installed) await runInstall(target);
|
|
225
|
+
return { installed, target, template };
|
|
226
|
+
}
|
|
227
|
+
function readFlag(argv, name) {
|
|
228
|
+
const index = argv.indexOf(name);
|
|
229
|
+
return index === -1 ? void 0 : argv[index + 1];
|
|
230
|
+
}
|
|
231
|
+
function parseArgs(argv) {
|
|
232
|
+
const target = argv.find(
|
|
233
|
+
(value, index) => !value.startsWith("-") && (index === 0 || !argv[index - 1]?.startsWith("--"))
|
|
234
|
+
);
|
|
235
|
+
if (target === void 0)
|
|
236
|
+
throw new Error("Missing target directory. Usage: pnpm create threenative my-game");
|
|
237
|
+
const template = readFlag(argv, "--template");
|
|
238
|
+
if (template !== void 0) kitManifest(template);
|
|
239
|
+
const packageSources = {};
|
|
240
|
+
for (const [name, flag] of [
|
|
241
|
+
["@threenative/core", "--core-package"],
|
|
242
|
+
["@threenative/physics", "--physics-package"],
|
|
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);
|
|
250
|
+
if (source !== void 0) packageSources[name] = source;
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
install: !argv.includes("--no-install"),
|
|
254
|
+
target,
|
|
255
|
+
...Object.keys(packageSources).length === 0 ? {} : { packageSources },
|
|
256
|
+
...template === void 0 ? {} : { template }
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
async function main() {
|
|
260
|
+
const argv = process.argv.slice(2);
|
|
261
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
262
|
+
process.stdout.write(cliHelp());
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const result = await createProject(parseArgs(argv));
|
|
266
|
+
process.stdout.write(`Created ${result.template} project at ${result.target}
|
|
267
|
+
`);
|
|
268
|
+
process.stdout.write(
|
|
269
|
+
"Templates: minimal (smallest), starter (default), platformer. Choose with --template <name>.\n"
|
|
270
|
+
);
|
|
271
|
+
if (!result.installed)
|
|
272
|
+
process.stdout.write("Skipped install (--no-install). Run pnpm install, then pnpm dev.\n");
|
|
273
|
+
else process.stdout.write("Next: cd into the project and run pnpm dev.\n");
|
|
274
|
+
}
|
|
275
|
+
if (process.argv[1] !== void 0 && path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url))) {
|
|
276
|
+
main().catch((error) => {
|
|
277
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}
|
|
278
|
+
`);
|
|
279
|
+
process.exitCode = 1;
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export { cliHelp, createProject, discoverKitManifests, discoverTemplateNames, kitManifest, parseArgs, templateRoot };
|