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.
Files changed (320) hide show
  1. package/README.md +16 -0
  2. package/dist/index.d.ts +30 -0
  3. package/dist/index.js +283 -0
  4. package/dist/threenative.d.ts +6 -0
  5. package/dist/threenative.js +757 -0
  6. package/package.json +44 -0
  7. package/templates/action-rpg/.mcp.json +16 -0
  8. package/templates/action-rpg/AGENTS.md +40 -0
  9. package/templates/action-rpg/CLAUDE.md +42 -0
  10. package/templates/action-rpg/index.html +13 -0
  11. package/templates/action-rpg/kit.json +7 -0
  12. package/templates/action-rpg/package.json +47 -0
  13. package/templates/action-rpg/playtests/combat.playtest.json +61 -0
  14. package/templates/action-rpg/playtests/fail.playtest.json +21 -0
  15. package/templates/action-rpg/playtests/inventory.playtest.json +111 -0
  16. package/templates/action-rpg/playtests/progress.playtest.json +99 -0
  17. package/templates/action-rpg/playtests/survives.playtest.json +32 -0
  18. package/templates/action-rpg/playtests/win.playtest.json +30 -0
  19. package/templates/action-rpg/public/favicon.svg +5 -0
  20. package/templates/action-rpg/src/abilities/Ability.ts +45 -0
  21. package/templates/action-rpg/src/entities/Enemy.ts +143 -0
  22. package/templates/action-rpg/src/entities/Player.ts +83 -0
  23. package/templates/action-rpg/src/game.ts +40 -0
  24. package/templates/action-rpg/src/items/Inventory.ts +163 -0
  25. package/templates/action-rpg/src/loot/drops.ts +40 -0
  26. package/templates/action-rpg/src/main.ts +15 -0
  27. package/templates/action-rpg/src/physics.ts +40 -0
  28. package/templates/action-rpg/src/playtest-events.ts +15 -0
  29. package/templates/action-rpg/src/progress.ts +35 -0
  30. package/templates/action-rpg/src/render/camera.ts +26 -0
  31. package/templates/action-rpg/src/render/lighting.ts +30 -0
  32. package/templates/action-rpg/src/render/loading.ts +90 -0
  33. package/templates/action-rpg/src/render/materials.ts +40 -0
  34. package/templates/action-rpg/src/render/palette.ts +9 -0
  35. package/templates/action-rpg/src/render/postprocessing.ts +18 -0
  36. package/templates/action-rpg/src/render/shapes.ts +110 -0
  37. package/templates/action-rpg/src/render/sky.ts +18 -0
  38. package/templates/action-rpg/src/render/types.ts +3 -0
  39. package/templates/action-rpg/src/scenes/Boot.ts +12 -0
  40. package/templates/action-rpg/src/scenes/Play.ts +449 -0
  41. package/templates/action-rpg/src/state.ts +40 -0
  42. package/templates/action-rpg/src/stats/StatBlock.ts +57 -0
  43. package/templates/action-rpg/src/style.css +32 -0
  44. package/templates/action-rpg/src/ui/AbilityBar.tsx +28 -0
  45. package/templates/action-rpg/src/ui/App.tsx +21 -0
  46. package/templates/action-rpg/src/ui/CharacterPanel.tsx +31 -0
  47. package/templates/action-rpg/src/ui/Hud.tsx +29 -0
  48. package/templates/action-rpg/src/ui/InventoryPanel.tsx +37 -0
  49. package/templates/action-rpg/tailwind.config.ts +7 -0
  50. package/templates/action-rpg/threenative.config.ts +29 -0
  51. package/templates/action-rpg/tsconfig.json +17 -0
  52. package/templates/action-rpg/vite.config.ts +8 -0
  53. package/templates/defense/.mcp.json +16 -0
  54. package/templates/defense/AGENTS.md +53 -0
  55. package/templates/defense/CLAUDE.md +55 -0
  56. package/templates/defense/README.md +9 -0
  57. package/templates/defense/index.html +13 -0
  58. package/templates/defense/kit.json +7 -0
  59. package/templates/defense/package.json +46 -0
  60. package/templates/defense/playtests/leak.playtest.json +18 -0
  61. package/templates/defense/playtests/placement.playtest.json +40 -0
  62. package/templates/defense/playtests/scan.playtest.json +20 -0
  63. package/templates/defense/playtests/survive.playtest.json +26 -0
  64. package/templates/defense/playtests/survives.playtest.json +36 -0
  65. package/templates/defense/public/favicon.svg +5 -0
  66. package/templates/defense/src/attackers/Attacker.ts +104 -0
  67. package/templates/defense/src/board/Route.ts +80 -0
  68. package/templates/defense/src/economy.ts +36 -0
  69. package/templates/defense/src/entities/Player.ts +44 -0
  70. package/templates/defense/src/game.ts +30 -0
  71. package/templates/defense/src/main.ts +15 -0
  72. package/templates/defense/src/physics.ts +43 -0
  73. package/templates/defense/src/placement/Buildable.ts +49 -0
  74. package/templates/defense/src/playtest-events.ts +15 -0
  75. package/templates/defense/src/render/camera.ts +10 -0
  76. package/templates/defense/src/render/lighting.ts +32 -0
  77. package/templates/defense/src/render/loading.ts +89 -0
  78. package/templates/defense/src/render/materials.ts +13 -0
  79. package/templates/defense/src/render/palette.ts +21 -0
  80. package/templates/defense/src/render/postprocessing.ts +14 -0
  81. package/templates/defense/src/render/shapes.ts +89 -0
  82. package/templates/defense/src/render/sky.ts +45 -0
  83. package/templates/defense/src/scenes/Boot.ts +12 -0
  84. package/templates/defense/src/scenes/Defense.ts +165 -0
  85. package/templates/defense/src/state.ts +50 -0
  86. package/templates/defense/src/style.css +32 -0
  87. package/templates/defense/src/towers/Tower.ts +96 -0
  88. package/templates/defense/src/towers/targeting.ts +53 -0
  89. package/templates/defense/src/ui/App.tsx +17 -0
  90. package/templates/defense/src/ui/Hud.tsx +61 -0
  91. package/templates/defense/src/ui/Menu.tsx +7 -0
  92. package/templates/defense/src/waves.ts +40 -0
  93. package/templates/defense/tailwind.config.ts +1 -0
  94. package/templates/defense/threenative.config.ts +29 -0
  95. package/templates/defense/tsconfig.json +17 -0
  96. package/templates/defense/vite.config.ts +5 -0
  97. package/templates/minimal/.mcp.json +16 -0
  98. package/templates/minimal/AGENTS.md +400 -0
  99. package/templates/minimal/CLAUDE.md +402 -0
  100. package/templates/minimal/assets/.gitkeep +0 -0
  101. package/templates/minimal/index.html +14 -0
  102. package/templates/minimal/kit.json +7 -0
  103. package/templates/minimal/package.json +40 -0
  104. package/templates/minimal/playtests/play.playtest.json +32 -0
  105. package/templates/minimal/playtests/survives.playtest.json +32 -0
  106. package/templates/minimal/public/.gitkeep +0 -0
  107. package/templates/minimal/public/favicon.svg +4 -0
  108. package/templates/minimal/public/icon.png +0 -0
  109. package/templates/minimal/src/entities/Player.ts +66 -0
  110. package/templates/minimal/src/game.ts +28 -0
  111. package/templates/minimal/src/main.ts +17 -0
  112. package/templates/minimal/src/render/camera.ts +11 -0
  113. package/templates/minimal/src/render/hud.ts +53 -0
  114. package/templates/minimal/src/render/lighting.ts +46 -0
  115. package/templates/minimal/src/render/loading.ts +113 -0
  116. package/templates/minimal/src/render/materials.ts +16 -0
  117. package/templates/minimal/src/render/palette.ts +9 -0
  118. package/templates/minimal/src/render/postprocessing.ts +20 -0
  119. package/templates/minimal/src/render/sky.ts +41 -0
  120. package/templates/minimal/src/scenes/Boot.ts +5 -0
  121. package/templates/minimal/src/scenes/Play.ts +65 -0
  122. package/templates/minimal/src/state.ts +1 -0
  123. package/templates/minimal/src/style.css +41 -0
  124. package/templates/minimal/threenative.config.ts +32 -0
  125. package/templates/minimal/tsconfig.json +16 -0
  126. package/templates/minimal/vite.config.ts +3 -0
  127. package/templates/platformer/.mcp.json +16 -0
  128. package/templates/platformer/AGENTS.md +199 -0
  129. package/templates/platformer/CLAUDE.md +201 -0
  130. package/templates/platformer/assets/.gitkeep +0 -0
  131. package/templates/platformer/index.html +13 -0
  132. package/templates/platformer/kit.json +7 -0
  133. package/templates/platformer/package.json +50 -0
  134. package/templates/platformer/playtests/avoidance.playtest.json +23 -0
  135. package/templates/platformer/playtests/buffer.playtest.json +17 -0
  136. package/templates/platformer/playtests/chase.playtest.json +21 -0
  137. package/templates/platformer/playtests/collect.playtest.json +56 -0
  138. package/templates/platformer/playtests/collision-layers.playtest.json +36 -0
  139. package/templates/platformer/playtests/coyote.playtest.json +21 -0
  140. package/templates/platformer/playtests/damage.playtest.json +31 -0
  141. package/templates/platformer/playtests/dash.playtest.json +21 -0
  142. package/templates/platformer/playtests/jump.playtest.json +21 -0
  143. package/templates/platformer/playtests/oneway.playtest.json +17 -0
  144. package/templates/platformer/playtests/patrol.playtest.json +13 -0
  145. package/templates/platformer/playtests/performance.playtest.json +21 -0
  146. package/templates/platformer/playtests/physics.playtest.json +14 -0
  147. package/templates/platformer/playtests/respawn.playtest.json +31 -0
  148. package/templates/platformer/playtests/stomp-rise.playtest.json +41 -0
  149. package/templates/platformer/playtests/stomp.playtest.json +34 -0
  150. package/templates/platformer/playtests/survives.playtest.json +32 -0
  151. package/templates/platformer/playtests/terminal-loop-fail.playtest.json +29 -0
  152. package/templates/platformer/playtests/terminal-loop-win.playtest.json +52 -0
  153. package/templates/platformer/public/.gitkeep +0 -0
  154. package/templates/platformer/public/favicon.svg +4 -0
  155. package/templates/platformer/public/icon.png +0 -0
  156. package/templates/platformer/src/entities/Character.ts +218 -0
  157. package/templates/platformer/src/entities/Chaser.ts +118 -0
  158. package/templates/platformer/src/entities/Patrol.ts +88 -0
  159. package/templates/platformer/src/entities/Pickup.ts +72 -0
  160. package/templates/platformer/src/game.ts +27 -0
  161. package/templates/platformer/src/level/Checkpoints.ts +66 -0
  162. package/templates/platformer/src/level/Platform.ts +34 -0
  163. package/templates/platformer/src/main.ts +14 -0
  164. package/templates/platformer/src/playtest-events.ts +15 -0
  165. package/templates/platformer/src/render/camera.ts +8 -0
  166. package/templates/platformer/src/render/lighting.ts +38 -0
  167. package/templates/platformer/src/render/loading.ts +113 -0
  168. package/templates/platformer/src/render/materials.ts +11 -0
  169. package/templates/platformer/src/render/palette.ts +54 -0
  170. package/templates/platformer/src/render/postprocessing.ts +18 -0
  171. package/templates/platformer/src/render/rig.ts +60 -0
  172. package/templates/platformer/src/render/sky.ts +47 -0
  173. package/templates/platformer/src/render/terrain.ts +31 -0
  174. package/templates/platformer/src/render/touch-controls.ts +157 -0
  175. package/templates/platformer/src/render/touch-layout.ts +63 -0
  176. package/templates/platformer/src/scenes/Boot.ts +12 -0
  177. package/templates/platformer/src/scenes/Level.ts +176 -0
  178. package/templates/platformer/src/state.ts +23 -0
  179. package/templates/platformer/src/style.css +31 -0
  180. package/templates/platformer/src/ui/App.tsx +17 -0
  181. package/templates/platformer/src/ui/Hud.tsx +41 -0
  182. package/templates/platformer/src/ui/Menu.tsx +7 -0
  183. package/templates/platformer/tailwind.config.ts +2 -0
  184. package/templates/platformer/threenative.config.ts +32 -0
  185. package/templates/platformer/tsconfig.json +17 -0
  186. package/templates/platformer/vite.config.ts +5 -0
  187. package/templates/racing/.mcp.json +16 -0
  188. package/templates/racing/AGENTS.md +48 -0
  189. package/templates/racing/CLAUDE.md +50 -0
  190. package/templates/racing/index.html +13 -0
  191. package/templates/racing/kit.json +7 -0
  192. package/templates/racing/package.json +46 -0
  193. package/templates/racing/playtests/boost.playtest.json +45 -0
  194. package/templates/racing/playtests/outcome.playtest.json +78 -0
  195. package/templates/racing/playtests/ranking.playtest.json +37 -0
  196. package/templates/racing/playtests/rescue.playtest.json +28 -0
  197. package/templates/racing/playtests/reverse.playtest.json +37 -0
  198. package/templates/racing/playtests/shortcut.playtest.json +44 -0
  199. package/templates/racing/playtests/survives.playtest.json +32 -0
  200. package/templates/racing/public/favicon.svg +6 -0
  201. package/templates/racing/src/entities/RacingCar.ts +114 -0
  202. package/templates/racing/src/entities/Rival.ts +46 -0
  203. package/templates/racing/src/game.ts +29 -0
  204. package/templates/racing/src/kart/boost.ts +38 -0
  205. package/templates/racing/src/main.ts +15 -0
  206. package/templates/racing/src/playtest-events.ts +15 -0
  207. package/templates/racing/src/render/camera.ts +28 -0
  208. package/templates/racing/src/render/lighting.ts +32 -0
  209. package/templates/racing/src/render/loading.ts +58 -0
  210. package/templates/racing/src/render/materials.ts +15 -0
  211. package/templates/racing/src/render/palette.ts +30 -0
  212. package/templates/racing/src/render/postprocessing.ts +14 -0
  213. package/templates/racing/src/render/shapes.ts +37 -0
  214. package/templates/racing/src/render/sky.ts +45 -0
  215. package/templates/racing/src/scenes/Boot.ts +12 -0
  216. package/templates/racing/src/scenes/Race.ts +180 -0
  217. package/templates/racing/src/state.ts +35 -0
  218. package/templates/racing/src/style.css +32 -0
  219. package/templates/racing/src/track/Checkline.ts +19 -0
  220. package/templates/racing/src/track/Lap.ts +104 -0
  221. package/templates/racing/src/track/Ranking.ts +35 -0
  222. package/templates/racing/src/track/Track.ts +229 -0
  223. package/templates/racing/src/track/TrackSector.ts +77 -0
  224. package/templates/racing/src/track/rescue.ts +21 -0
  225. package/templates/racing/src/ui/App.tsx +17 -0
  226. package/templates/racing/src/ui/Hud.tsx +71 -0
  227. package/templates/racing/src/ui/Menu.tsx +7 -0
  228. package/templates/racing/tailwind.config.ts +2 -0
  229. package/templates/racing/threenative.config.ts +29 -0
  230. package/templates/racing/tsconfig.json +17 -0
  231. package/templates/racing/vite.config.ts +5 -0
  232. package/templates/shooter/.mcp.json +16 -0
  233. package/templates/shooter/AGENTS.md +69 -0
  234. package/templates/shooter/CLAUDE.md +71 -0
  235. package/templates/shooter/index.html +13 -0
  236. package/templates/shooter/kit.json +7 -0
  237. package/templates/shooter/package.json +46 -0
  238. package/templates/shooter/playtests/fail.playtest.json +30 -0
  239. package/templates/shooter/playtests/shooter.playtest.json +89 -0
  240. package/templates/shooter/playtests/survives.playtest.json +32 -0
  241. package/templates/shooter/public/favicon.svg +4 -0
  242. package/templates/shooter/src/combat/damage.ts +41 -0
  243. package/templates/shooter/src/entities/Pickup.ts +70 -0
  244. package/templates/shooter/src/entities/Player.ts +93 -0
  245. package/templates/shooter/src/entities/Target.ts +103 -0
  246. package/templates/shooter/src/game.ts +36 -0
  247. package/templates/shooter/src/level/SpawnPoints.ts +28 -0
  248. package/templates/shooter/src/main.ts +26 -0
  249. package/templates/shooter/src/physics.ts +49 -0
  250. package/templates/shooter/src/playtest-events.ts +15 -0
  251. package/templates/shooter/src/render/camera.ts +29 -0
  252. package/templates/shooter/src/render/lighting.ts +38 -0
  253. package/templates/shooter/src/render/loading.ts +86 -0
  254. package/templates/shooter/src/render/materials.ts +38 -0
  255. package/templates/shooter/src/render/palette.ts +9 -0
  256. package/templates/shooter/src/render/postprocessing.ts +19 -0
  257. package/templates/shooter/src/render/shapes.ts +194 -0
  258. package/templates/shooter/src/render/sky.ts +37 -0
  259. package/templates/shooter/src/render/types.ts +3 -0
  260. package/templates/shooter/src/render/ui.css +212 -0
  261. package/templates/shooter/src/render/ui.ts +59 -0
  262. package/templates/shooter/src/scenes/Boot.ts +12 -0
  263. package/templates/shooter/src/scenes/Play.ts +428 -0
  264. package/templates/shooter/src/state.ts +29 -0
  265. package/templates/shooter/src/ui/App.tsx +25 -0
  266. package/templates/shooter/src/ui/Hud.tsx +49 -0
  267. package/templates/shooter/src/ui/Menu.tsx +26 -0
  268. package/templates/shooter/src/waves.ts +50 -0
  269. package/templates/shooter/src/weapons/Hitscan.ts +43 -0
  270. package/templates/shooter/src/weapons/Projectile.ts +76 -0
  271. package/templates/shooter/tailwind.config.ts +5 -0
  272. package/templates/shooter/threenative.config.ts +29 -0
  273. package/templates/shooter/tsconfig.json +17 -0
  274. package/templates/shooter/vite.config.ts +8 -0
  275. package/templates/starter/.mcp.json +16 -0
  276. package/templates/starter/AGENTS.md +450 -0
  277. package/templates/starter/CLAUDE.md +452 -0
  278. package/templates/starter/assets/.gitkeep +0 -0
  279. package/templates/starter/index.html +13 -0
  280. package/templates/starter/kit.json +7 -0
  281. package/templates/starter/package.json +49 -0
  282. package/templates/starter/playtests/buffer.playtest.json +29 -0
  283. package/templates/starter/playtests/coyote.playtest.json +35 -0
  284. package/templates/starter/playtests/forward.playtest.json +15 -0
  285. package/templates/starter/playtests/hot-reload.playtest.json +28 -0
  286. package/templates/starter/playtests/look.playtest.json +43 -0
  287. package/templates/starter/playtests/monitoring.playtest.json +41 -0
  288. package/templates/starter/playtests/pause.playtest.json +33 -0
  289. package/templates/starter/playtests/play.playtest.json +16 -0
  290. package/templates/starter/playtests/respawn.playtest.json +28 -0
  291. package/templates/starter/playtests/restart.playtest.json +36 -0
  292. package/templates/starter/playtests/seed.playtest.json +18 -0
  293. package/templates/starter/playtests/survives.playtest.json +32 -0
  294. package/templates/starter/public/.gitkeep +0 -0
  295. package/templates/starter/public/favicon.svg +4 -0
  296. package/templates/starter/public/icon.png +0 -0
  297. package/templates/starter/public/native-proof.glb +0 -0
  298. package/templates/starter/public/native-proof.png +0 -0
  299. package/templates/starter/public/pickup.ogg +0 -0
  300. package/templates/starter/src/entities/Crate.ts +34 -0
  301. package/templates/starter/src/entities/Player.ts +80 -0
  302. package/templates/starter/src/game.ts +30 -0
  303. package/templates/starter/src/main.ts +15 -0
  304. package/templates/starter/src/render/camera.ts +57 -0
  305. package/templates/starter/src/render/lighting.ts +55 -0
  306. package/templates/starter/src/render/materials.ts +12 -0
  307. package/templates/starter/src/render/palette.ts +9 -0
  308. package/templates/starter/src/render/postprocessing.ts +18 -0
  309. package/templates/starter/src/render/shapes.ts +147 -0
  310. package/templates/starter/src/render/sky.ts +56 -0
  311. package/templates/starter/src/scenes/Play.ts +161 -0
  312. package/templates/starter/src/state.ts +10 -0
  313. package/templates/starter/src/style.css +45 -0
  314. package/templates/starter/src/ui/App.tsx +19 -0
  315. package/templates/starter/src/ui/Hud.tsx +37 -0
  316. package/templates/starter/src/ui/Menu.tsx +43 -0
  317. package/templates/starter/tailwind.config.ts +2 -0
  318. package/templates/starter/threenative.config.ts +31 -0
  319. package/templates/starter/tsconfig.json +17 -0
  320. package/templates/starter/vite.config.ts +8 -0
@@ -0,0 +1,757 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from 'child_process';
3
+ import { stat, mkdir, writeFile, readFile, access, unlink } from 'fs/promises';
4
+ import { createRequire } from 'module';
5
+ import path from 'path';
6
+ import { pathToFileURL, fileURLToPath } from 'url';
7
+
8
+ var ORIENTATIONS = ["landscape", "portrait", "sensor"];
9
+ var CONFIG_FILE = "threenative.config.ts";
10
+ var ConfigFailure = class extends Error {
11
+ code;
12
+ context;
13
+ detail;
14
+ constructor(code, detail, context) {
15
+ super(`${code}: ${context === void 0 ? detail : formatContext(context, detail)}`);
16
+ this.name = "ConfigFailure";
17
+ this.code = code;
18
+ this.context = context;
19
+ this.detail = detail;
20
+ }
21
+ };
22
+ function formatContext(context, detail) {
23
+ return `${context.layer} layer failed for ${context.sources.map((source) => `'${source}'`).join(", ")} from '${context.cwd}'. Searched: ${context.searched.join(", ")}. ${detail} Fix: ${context.fix}`;
24
+ }
25
+ function fail(code, message) {
26
+ throw new ConfigFailure(code, message);
27
+ }
28
+ function isRecord(value) {
29
+ return typeof value === "object" && value !== null && !Array.isArray(value);
30
+ }
31
+ function assertRecord(value, group) {
32
+ if (value === void 0) return {};
33
+ if (!isRecord(value)) fail("TN_CONFIG_GROUP_INVALID", `${group} must be an object.`);
34
+ return value;
35
+ }
36
+ function assertKeys(value, group, allowed) {
37
+ for (const key of Object.keys(value)) {
38
+ if (!allowed.includes(key)) fail("TN_CONFIG_UNKNOWN_KEY", `${group}.${key} is not recognised.`);
39
+ }
40
+ }
41
+ function nonEmptyString(value, code, label) {
42
+ if (typeof value !== "string" || value.trim().length === 0)
43
+ fail(code, `${label} must be non-empty.`);
44
+ return value;
45
+ }
46
+ function booleanValue(value, fallback, code, label) {
47
+ if (value === void 0) return fallback;
48
+ if (typeof value !== "boolean") fail(code, `${label} must be true or false.`);
49
+ return value;
50
+ }
51
+ function positiveInteger(value, fallback, code, label) {
52
+ if (value === void 0) return fallback;
53
+ if (!Number.isSafeInteger(value) || value <= 0) {
54
+ fail(code, `${label} must be a positive integer.`);
55
+ }
56
+ return value;
57
+ }
58
+ function packageDisplayName(manifest) {
59
+ if (typeof manifest.name !== "string" || manifest.name.trim().length === 0) {
60
+ fail("TN_CONFIG_PACKAGE_NAME_MISSING", "package.json must declare a non-empty name.");
61
+ }
62
+ const name = manifest.name.replace(/^@[^/]+\//u, "");
63
+ if (name.length === 0) fail("TN_CONFIG_PACKAGE_NAME_MISSING", "package.json name is incomplete.");
64
+ return name;
65
+ }
66
+ function defaultAppId(name) {
67
+ let segment = name.toLowerCase().replace(/[^a-z0-9]/gu, "") || "game";
68
+ if (!/^[a-z]/u.test(segment)) segment = `game${segment}`;
69
+ return `com.threenative.${segment}`;
70
+ }
71
+ var PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
72
+ function crc32(value) {
73
+ let crc = 4294967295;
74
+ for (const byte of value) {
75
+ crc ^= byte;
76
+ for (let bit = 0; bit < 8; bit += 1) {
77
+ crc = crc >>> 1 ^ (crc & 1 ? 3988292384 : 0);
78
+ }
79
+ }
80
+ return (crc ^ 4294967295) >>> 0;
81
+ }
82
+ function isPng(value) {
83
+ if (value.length < PNG_SIGNATURE.length || !value.subarray(0, 8).equals(PNG_SIGNATURE)) {
84
+ return false;
85
+ }
86
+ let offset = PNG_SIGNATURE.length;
87
+ let hasHeader = false;
88
+ let hasData = false;
89
+ while (offset + 12 <= value.length) {
90
+ const length = value.readUInt32BE(offset);
91
+ const chunkEnd = offset + 12 + length;
92
+ if (chunkEnd > value.length) return false;
93
+ const type = value.toString("ascii", offset + 4, offset + 8);
94
+ const chunk = value.subarray(offset + 4, offset + 8 + length);
95
+ if (crc32(chunk) !== value.readUInt32BE(offset + 8 + length)) return false;
96
+ if (type === "IHDR") {
97
+ if (hasHeader || length !== 13) return false;
98
+ if (value.readUInt32BE(offset + 8) === 0 || value.readUInt32BE(offset + 12) === 0) {
99
+ return false;
100
+ }
101
+ hasHeader = true;
102
+ } else if (type === "IDAT") {
103
+ hasData = true;
104
+ } else if (type === "IEND") {
105
+ return length === 0 && hasHeader && hasData && chunkEnd === value.length;
106
+ }
107
+ offset = chunkEnd;
108
+ }
109
+ return false;
110
+ }
111
+ function projectRequire(cwd) {
112
+ return createRequire(path.join(cwd, "package.json"));
113
+ }
114
+ function configLoaderSearch(cwd) {
115
+ return [
116
+ path.join(cwd, "node_modules", "vite"),
117
+ path.join(cwd, "node_modules", "esbuild"),
118
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "node_modules", "esbuild")
119
+ ];
120
+ }
121
+ var CONFIG_BUILD_COMMAND = "pnpm exec threenative build --target web";
122
+ function configContext(cwd, layer, sources, searched, fix) {
123
+ return { cwd, fix, layer, searched, sources };
124
+ }
125
+ function packageContext(cwd) {
126
+ const packagePath = path.join(cwd, "package.json");
127
+ return configContext(
128
+ cwd,
129
+ "package manifest",
130
+ [packagePath],
131
+ [packagePath],
132
+ `repair '${packagePath}' and rerun ${CONFIG_BUILD_COMMAND}`
133
+ );
134
+ }
135
+ function loadingContext(cwd, sourcePath, fix) {
136
+ return configContext(
137
+ cwd,
138
+ "config loading",
139
+ [sourcePath],
140
+ configLoaderSearch(cwd),
141
+ fix ?? `fix '${sourcePath}' and rerun ${CONFIG_BUILD_COMMAND}`
142
+ );
143
+ }
144
+ function validationContext(cwd, sources) {
145
+ return configContext(
146
+ cwd,
147
+ "config validation",
148
+ sources,
149
+ [path.join(cwd, "package.json"), path.join(cwd, CONFIG_FILE)],
150
+ `fix '${path.join(cwd, CONFIG_FILE)}' and rerun ${CONFIG_BUILD_COMMAND}`
151
+ );
152
+ }
153
+ function configFailure(code, context, detail) {
154
+ throw new ConfigFailure(code, detail, context);
155
+ }
156
+ function contextualize(error, context, fallbackCode) {
157
+ if (error instanceof ConfigFailure && error.context !== void 0) return error;
158
+ if (error instanceof ConfigFailure) return new ConfigFailure(error.code, error.detail, context);
159
+ return new ConfigFailure(
160
+ fallbackCode,
161
+ error instanceof Error ? error.message : String(error),
162
+ context
163
+ );
164
+ }
165
+ async function withConfigContext(context, fallbackCode, action) {
166
+ try {
167
+ return await action();
168
+ } catch (error) {
169
+ throw contextualize(error, context, fallbackCode);
170
+ }
171
+ }
172
+ function resolveEsbuild(cwd) {
173
+ const require2 = projectRequire(cwd);
174
+ try {
175
+ return require2.resolve("esbuild");
176
+ } catch {
177
+ try {
178
+ const vite = require2.resolve("vite");
179
+ return createRequire(vite).resolve("esbuild");
180
+ } catch {
181
+ try {
182
+ return createRequire(import.meta.url).resolve("esbuild");
183
+ } catch {
184
+ return void 0;
185
+ }
186
+ }
187
+ }
188
+ }
189
+ async function importConfig(cwd) {
190
+ const sourcePath = path.join(cwd, CONFIG_FILE);
191
+ try {
192
+ await access(sourcePath);
193
+ } catch {
194
+ return void 0;
195
+ }
196
+ const esbuildPath = resolveEsbuild(cwd);
197
+ if (esbuildPath === void 0) {
198
+ configFailure(
199
+ "TN_CONFIG_TRANSPILER_MISSING",
200
+ loadingContext(
201
+ cwd,
202
+ sourcePath,
203
+ `run pnpm add -D vite in '${cwd}' and rerun ${CONFIG_BUILD_COMMAND}`
204
+ ),
205
+ "threenative.config.ts needs project-resolved esbuild; install Vite or esbuild."
206
+ );
207
+ }
208
+ let esbuild;
209
+ try {
210
+ esbuild = projectRequire(cwd)(esbuildPath);
211
+ } catch (error) {
212
+ configFailure(
213
+ "TN_CONFIG_TRANSPILER_MISSING",
214
+ loadingContext(
215
+ cwd,
216
+ sourcePath,
217
+ `run pnpm install in '${cwd}' and rerun ${CONFIG_BUILD_COMMAND}`
218
+ ),
219
+ error instanceof Error ? error.message : String(error)
220
+ );
221
+ }
222
+ const context = loadingContext(cwd, sourcePath);
223
+ let source;
224
+ try {
225
+ source = await readFile(sourcePath, "utf8");
226
+ } catch (error) {
227
+ configFailure(
228
+ "TN_CONFIG_LOAD_FAILED",
229
+ context,
230
+ error instanceof Error ? error.message : String(error)
231
+ );
232
+ }
233
+ let code;
234
+ try {
235
+ code = esbuild.transformSync(source, {
236
+ format: "esm",
237
+ loader: "ts",
238
+ platform: "node",
239
+ target: "node20"
240
+ }).code;
241
+ } catch (error) {
242
+ configFailure(
243
+ "TN_CONFIG_TRANSPILE_FAILED",
244
+ context,
245
+ error instanceof Error ? error.message : String(error)
246
+ );
247
+ }
248
+ const compiledPath = path.join(cwd, `.threenative.config.${process.pid}.${Date.now()}.mjs`);
249
+ try {
250
+ await writeFile(compiledPath, code, "utf8");
251
+ } catch (error) {
252
+ configFailure(
253
+ "TN_CONFIG_LOAD_FAILED",
254
+ context,
255
+ error instanceof Error ? error.message : String(error)
256
+ );
257
+ }
258
+ try {
259
+ let module;
260
+ try {
261
+ module = await import(`${pathToFileURL(compiledPath).href}?cache=${Date.now()}`);
262
+ } catch (error) {
263
+ configFailure(
264
+ "TN_CONFIG_LOAD_FAILED",
265
+ context,
266
+ error instanceof Error ? error.message : String(error)
267
+ );
268
+ }
269
+ if (!isRecord(module.default)) {
270
+ configFailure(
271
+ "TN_CONFIG_DEFAULT_MISSING",
272
+ context,
273
+ "the config did not default-export an object."
274
+ );
275
+ }
276
+ return module.default;
277
+ } finally {
278
+ await unlink(compiledPath).catch(() => void 0);
279
+ }
280
+ }
281
+ async function readManifest(cwd) {
282
+ let parsed;
283
+ try {
284
+ parsed = JSON.parse(await readFile(path.join(cwd, "package.json"), "utf8"));
285
+ } catch (error) {
286
+ fail("TN_CONFIG_PACKAGE_INVALID", error instanceof Error ? error.message : String(error));
287
+ }
288
+ if (!isRecord(parsed)) fail("TN_CONFIG_PACKAGE_INVALID", "package.json must contain an object.");
289
+ return parsed;
290
+ }
291
+ function packageNativeEntry(manifest) {
292
+ if (manifest.threenative === void 0) return void 0;
293
+ if (!isRecord(manifest.threenative)) {
294
+ fail("TN_CONFIG_PACKAGE_INVALID", "package.json.threenative must be an object.");
295
+ }
296
+ assertKeys(manifest.threenative, "package.json.threenative", ["nativeEntry"]);
297
+ const value = manifest.threenative.nativeEntry;
298
+ if (value === void 0) return void 0;
299
+ return nonEmptyString(value, "TN_NATIVE_ENTRY_MISSING", "package.json.threenative.nativeEntry");
300
+ }
301
+ function validateNativeEntry(value, cwd) {
302
+ const entry = nonEmptyString(value, "TN_NATIVE_ENTRY_MISSING", "nativeEntry");
303
+ if (path.isAbsolute(entry)) {
304
+ fail("TN_CONFIG_NATIVE_ENTRY_INVALID", "nativeEntry must be project-relative.");
305
+ }
306
+ const resolved = path.resolve(cwd, entry);
307
+ const relative = path.relative(cwd, resolved);
308
+ if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
309
+ fail("TN_CONFIG_NATIVE_ENTRY_INVALID", "nativeEntry must stay inside the project.");
310
+ }
311
+ return entry;
312
+ }
313
+ async function validateApp(raw, name, cwd) {
314
+ const app = assertRecord(raw, "app");
315
+ assertKeys(app, "app", ["id", "name", "version", "build", "icon"]);
316
+ const id = app.id === void 0 ? defaultAppId(name) : nonEmptyString(app.id, "TN_CONFIG_APP_ID_INVALID", "app.id");
317
+ if (!/^[a-z][a-z0-9]*(?:\.[a-z][a-z0-9]*)+$/u.test(id)) {
318
+ fail("TN_CONFIG_APP_ID_INVALID", "app.id must be a lower-case reverse-DNS identifier.");
319
+ }
320
+ const appName = app.name === void 0 ? name : nonEmptyString(app.name, "TN_CONFIG_APP_NAME_INVALID", "app.name");
321
+ const version = app.version === void 0 ? "0.1.13" : nonEmptyString(app.version, "TN_CONFIG_APP_VERSION_INVALID", "app.version");
322
+ if (!/^\d+\.\d+\.\d+$/u.test(version)) {
323
+ fail(
324
+ "TN_CONFIG_APP_VERSION_INVALID",
325
+ "app.version must contain three period-separated integer components."
326
+ );
327
+ }
328
+ const build2 = positiveInteger(app.build, 1, "TN_CONFIG_APP_BUILD_INVALID", "app.build");
329
+ if (app.icon === void 0) return { id, name: appName, version, build: build2 };
330
+ const icon = nonEmptyString(app.icon, "TN_CONFIG_ICON_INVALID", "app.icon");
331
+ if (path.extname(icon).toLowerCase() !== ".png") {
332
+ fail("TN_CONFIG_ICON_INVALID", "app.icon must point to a PNG file.");
333
+ }
334
+ const iconPath = path.resolve(cwd, icon);
335
+ try {
336
+ const info = await stat(iconPath);
337
+ if (!info.isFile()) fail("TN_CONFIG_ICON_MISSING", `app.icon does not name a file: ${icon}`);
338
+ } catch (error) {
339
+ if (error instanceof ConfigFailure) throw error;
340
+ fail("TN_CONFIG_ICON_MISSING", `app.icon does not exist: ${icon}`);
341
+ }
342
+ let contents;
343
+ try {
344
+ contents = await readFile(iconPath);
345
+ } catch (error) {
346
+ fail("TN_CONFIG_ICON_INVALID", error instanceof Error ? error.message : String(error));
347
+ }
348
+ if (!isPng(contents)) {
349
+ fail("TN_CONFIG_ICON_INVALID", `app.icon is not a valid PNG file: ${icon}`);
350
+ }
351
+ return { id, name: appName, version, build: build2, icon };
352
+ }
353
+ function validateDisplay(raw) {
354
+ const display = assertRecord(raw, "display");
355
+ assertKeys(display, "display", ["orientation", "fullscreen", "keepScreenOn"]);
356
+ const orientation = display.orientation === void 0 ? "landscape" : display.orientation;
357
+ if (typeof orientation !== "string" || !ORIENTATIONS.includes(orientation)) {
358
+ fail(
359
+ "TN_NATIVE_ORIENTATION_INVALID",
360
+ "display.orientation must be landscape, portrait, or sensor."
361
+ );
362
+ }
363
+ return {
364
+ orientation,
365
+ fullscreen: booleanValue(
366
+ display.fullscreen,
367
+ true,
368
+ "TN_CONFIG_FULLSCREEN_INVALID",
369
+ "display.fullscreen"
370
+ ),
371
+ keepScreenOn: booleanValue(
372
+ display.keepScreenOn,
373
+ false,
374
+ "TN_CONFIG_KEEP_SCREEN_ON_INVALID",
375
+ "display.keepScreenOn"
376
+ )
377
+ };
378
+ }
379
+ function validateWindow(raw, appName) {
380
+ const window = assertRecord(raw, "window");
381
+ assertKeys(window, "window", ["title", "width", "height", "resizable"]);
382
+ return {
383
+ title: window.title === void 0 ? appName : nonEmptyString(window.title, "TN_CONFIG_WINDOW_TITLE_INVALID", "window.title"),
384
+ width: positiveInteger(window.width, 1280, "TN_CONFIG_WINDOW_WIDTH_INVALID", "window.width"),
385
+ height: positiveInteger(window.height, 720, "TN_CONFIG_WINDOW_HEIGHT_INVALID", "window.height"),
386
+ resizable: booleanValue(
387
+ window.resizable,
388
+ true,
389
+ "TN_CONFIG_WINDOW_RESIZABLE_INVALID",
390
+ "window.resizable"
391
+ )
392
+ };
393
+ }
394
+ function validateLoading(raw) {
395
+ const loading = assertRecord(raw, "loading");
396
+ assertKeys(loading, "loading", [
397
+ "image",
398
+ "backdropColor",
399
+ "trackColor",
400
+ "progressColor",
401
+ "showProgressBar"
402
+ ]);
403
+ const color = (value, fallback, label) => {
404
+ if (value === void 0) return fallback;
405
+ if (typeof value !== "string" || !/^#[0-9a-f]{6}$/iu.test(value)) {
406
+ fail("TN_CONFIG_LOADING_COLOR_INVALID", `${label} must be a #rrggbb colour.`);
407
+ }
408
+ return value;
409
+ };
410
+ const image = loading.image === void 0 ? void 0 : nonEmptyString(loading.image, "TN_CONFIG_LOADING_IMAGE_INVALID", "loading.image");
411
+ if (image !== void 0 && path.isAbsolute(image)) {
412
+ fail("TN_CONFIG_LOADING_IMAGE_INVALID", "loading.image must be project-relative.");
413
+ }
414
+ return {
415
+ ...image === void 0 ? {} : { image },
416
+ backdropColor: color(loading.backdropColor, "#0d1b2a", "loading.backdropColor"),
417
+ trackColor: color(loading.trackColor, "#274060", "loading.trackColor"),
418
+ progressColor: color(loading.progressColor, "#8fd694", "loading.progressColor"),
419
+ showProgressBar: booleanValue(
420
+ loading.showProgressBar,
421
+ true,
422
+ "TN_CONFIG_LOADING_BAR_INVALID",
423
+ "loading.showProgressBar"
424
+ )
425
+ };
426
+ }
427
+ function validateRenderer(raw) {
428
+ const renderer = assertRecord(raw, "renderer");
429
+ assertKeys(renderer, "renderer", ["preferWebGPU"]);
430
+ return {
431
+ preferWebGPU: booleanValue(
432
+ renderer.preferWebGPU,
433
+ true,
434
+ "TN_CONFIG_RENDERER_INVALID",
435
+ "renderer.preferWebGPU"
436
+ )
437
+ };
438
+ }
439
+ async function loadConfigInternal(root) {
440
+ const packagePath = path.join(root, "package.json");
441
+ const sourcePath = path.join(root, CONFIG_FILE);
442
+ const manifest = await withConfigContext(
443
+ packageContext(root),
444
+ "TN_CONFIG_PACKAGE_INVALID",
445
+ () => readManifest(root)
446
+ );
447
+ const name = await withConfigContext(
448
+ packageContext(root),
449
+ "TN_CONFIG_PACKAGE_INVALID",
450
+ () => packageDisplayName(manifest)
451
+ );
452
+ const packageEntry = await withConfigContext(
453
+ packageContext(root),
454
+ "TN_CONFIG_PACKAGE_INVALID",
455
+ () => packageNativeEntry(manifest)
456
+ );
457
+ const raw = await importConfig(root);
458
+ const sources = packageEntry === void 0 ? [sourcePath] : [sourcePath, packagePath];
459
+ return withConfigContext(
460
+ validationContext(root, sources),
461
+ "TN_CONFIG_VALIDATION_FAILED",
462
+ async () => {
463
+ if (raw !== void 0) {
464
+ assertKeys(raw, "config", [
465
+ "app",
466
+ "display",
467
+ "loading",
468
+ "window",
469
+ "nativeEntry",
470
+ "renderer"
471
+ ]);
472
+ }
473
+ const configuredEntry = raw?.nativeEntry;
474
+ if (configuredEntry !== void 0 && packageEntry !== void 0) {
475
+ fail(
476
+ "TN_CONFIG_CONFLICT",
477
+ "nativeEntry is declared in both threenative.config.ts and package.json."
478
+ );
479
+ }
480
+ const app = await validateApp(raw?.app, name, root);
481
+ return {
482
+ app,
483
+ display: validateDisplay(raw?.display),
484
+ loading: validateLoading(raw?.loading),
485
+ window: validateWindow(raw?.window, app.name),
486
+ nativeEntry: validateNativeEntry(configuredEntry ?? packageEntry ?? "src/game.ts", root),
487
+ renderer: validateRenderer(raw?.renderer)
488
+ };
489
+ }
490
+ );
491
+ }
492
+ async function loadConfig(cwd) {
493
+ const root = path.resolve(cwd);
494
+ return withConfigContext(
495
+ validationContext(root, [path.join(root, CONFIG_FILE), path.join(root, "package.json")]),
496
+ "TN_CONFIG_VALIDATION_FAILED",
497
+ () => loadConfigInternal(root)
498
+ );
499
+ }
500
+
501
+ // src/build.ts
502
+ var TARGETS = ["web", "desktop", "android", "ios"];
503
+ function projectRequire2(cwd) {
504
+ return createRequire(path.join(cwd, "package.json"));
505
+ }
506
+ function packageRoot(cwd, packageName) {
507
+ try {
508
+ return path.dirname(projectRequire2(cwd).resolve(`${packageName}/package.json`));
509
+ } catch {
510
+ throw new Error(
511
+ `Cannot build a native target because '${packageName}' is not installed in ${cwd}.`
512
+ );
513
+ }
514
+ }
515
+ function executable(cwd, name) {
516
+ const suffix = process.platform === "win32" ? ".cmd" : "";
517
+ return path.join(cwd, "node_modules", ".bin", `${name}${suffix}`);
518
+ }
519
+ async function run(command, args, cwd) {
520
+ await new Promise((resolve, reject) => {
521
+ const child = spawn(command, [...args], { cwd, stdio: "inherit" });
522
+ child.once("error", reject);
523
+ child.once("exit", (code) => {
524
+ if (code === 0) resolve();
525
+ else reject(new Error(`${path.basename(command)} exited with code ${code ?? "unknown"}.`));
526
+ });
527
+ });
528
+ }
529
+ async function projectName(cwd) {
530
+ const manifest = JSON.parse(await readFile(path.join(cwd, "package.json"), "utf8"));
531
+ const name = manifest.name?.replace(/^@[^/]+\//u, "").replace(/[^a-zA-Z0-9._-]/gu, "-");
532
+ if (name === void 0 || name.length === 0) throw new Error("package.json must name the game.");
533
+ return name;
534
+ }
535
+ async function assertNativeBundleCompatible(bundle, target) {
536
+ const source = await readFile(bundle, "utf8");
537
+ const webOnlyUi = [
538
+ ["React DOM", /\breact-dom(?:\/client)?\b|\bcreateRoot\s*\(/u],
539
+ ["document.getElementById", /\bdocument\.getElementById\s*\(/u]
540
+ ].filter(([, pattern]) => pattern.test(source));
541
+ if (webOnlyUi.length > 0) {
542
+ throw new Error(
543
+ `TN_NATIVE_WEB_ONLY_UI: ${target} bundle contains ${webOnlyUi.map(([label]) => label).join(", ")}. Keep the portable game in src/game.ts and move DOM or React mounting to src/main.ts; native UI is owned by PRD-051.`
544
+ );
545
+ }
546
+ if (target === "desktop") return;
547
+ const wasm = [
548
+ ["WebAssembly", /\bWebAssembly\b/u],
549
+ ["Rapier WASM", /rapier_wasm|RAPIER_VERSION|rawrapier/u],
550
+ ["Recast WASM", /recast-navigation\.wasm|recastnavigationwasm/u]
551
+ ].filter(([, pattern]) => pattern.test(source));
552
+ if (wasm.length === 0) return;
553
+ throw new Error(
554
+ `TN_NATIVE_WASM_ON_MOBILE: ${target} bundle contains ${wasm.map(([label]) => label).join(", ")}. Move web-only WASM imports out of src/game.ts or provide a threenative-native conditional backend; mobile navigation is owned by PRD-052.`
555
+ );
556
+ }
557
+ async function buildWeb(cwd, viteArgs = []) {
558
+ await loadConfig(cwd);
559
+ await run(executable(cwd, "vite"), ["build", ...viteArgs], cwd);
560
+ }
561
+ async function nativeEntry(cwd, config) {
562
+ const relative = (config ?? await loadConfig(cwd)).nativeEntry;
563
+ const entry = path.resolve(cwd, relative);
564
+ try {
565
+ if (!(await stat(entry)).isFile()) throw new Error("not a file");
566
+ } catch {
567
+ throw new Error(`TN_NATIVE_ENTRY_MISSING: ${relative} does not exist.`);
568
+ }
569
+ return entry;
570
+ }
571
+ async function writePackagingConfig(cwd, config) {
572
+ const directory = path.join(cwd, ".threenative", "build");
573
+ await mkdir(directory, { recursive: true });
574
+ const artifact = {
575
+ ...config,
576
+ app: {
577
+ ...config.app,
578
+ ...config.app.icon === void 0 ? {} : { icon: path.resolve(cwd, config.app.icon) }
579
+ }
580
+ };
581
+ const output = path.join(directory, "config.json");
582
+ await writeFile(output, `${JSON.stringify(artifact, null, 2)}
583
+ `);
584
+ return output;
585
+ }
586
+ async function bundleNative(cwd, runtimeRoot, entry, target) {
587
+ const output = path.join(cwd, ".threenative", "build", "game.js");
588
+ await run(
589
+ process.execPath,
590
+ [
591
+ path.join(runtimeRoot, "scripts", "bundle.mjs"),
592
+ "--project",
593
+ cwd,
594
+ "--entry",
595
+ entry,
596
+ "--target",
597
+ target,
598
+ "--output",
599
+ output
600
+ ],
601
+ cwd
602
+ );
603
+ return output;
604
+ }
605
+ function installedRuntime(runtimeRoot) {
606
+ if (process.env.THREENATIVE_RUNTIME_BINARY)
607
+ return path.resolve(process.env.THREENATIVE_RUNTIME_BINARY);
608
+ const key = `${process.platform}-${process.arch}`;
609
+ const filename = process.platform === "win32" ? "threenative-runtime.exe" : "threenative-runtime";
610
+ return path.join(runtimeRoot, "prebuilt", key, filename);
611
+ }
612
+ async function buildNative(target, cwd) {
613
+ const config = await loadConfig(cwd);
614
+ const entry = await nativeEntry(cwd, config);
615
+ const orientation = config.display.orientation;
616
+ const configPath = await writePackagingConfig(cwd, config);
617
+ const runtimeRoot = packageRoot(cwd, "@threenative/runtime-native");
618
+ const bundle = await bundleNative(cwd, runtimeRoot, entry, target);
619
+ await assertNativeBundleCompatible(bundle, target);
620
+ const assets = path.join(cwd, "public");
621
+ if (target === "ios") {
622
+ const output2 = path.join(cwd, "dist-native", `${await projectName(cwd)}.app`);
623
+ await run(
624
+ process.execPath,
625
+ [
626
+ path.join(runtimeRoot, "scripts", "package-ios.mjs"),
627
+ "--bundle",
628
+ bundle,
629
+ "--assets",
630
+ assets,
631
+ "--orientation",
632
+ orientation,
633
+ "--config",
634
+ configPath,
635
+ "--output",
636
+ output2
637
+ ],
638
+ runtimeRoot
639
+ );
640
+ return;
641
+ }
642
+ if (target === "android") {
643
+ const output2 = path.join(cwd, "dist-native", `${await projectName(cwd)}.apk`);
644
+ await run(
645
+ process.execPath,
646
+ [
647
+ path.join(runtimeRoot, "scripts", "package-android.mjs"),
648
+ "--bundle",
649
+ bundle,
650
+ "--assets",
651
+ assets,
652
+ "--orientation",
653
+ orientation,
654
+ "--config",
655
+ configPath,
656
+ "--output",
657
+ output2
658
+ ],
659
+ runtimeRoot
660
+ );
661
+ return;
662
+ }
663
+ const output = path.join(cwd, "dist-native", await projectName(cwd));
664
+ await run(
665
+ process.execPath,
666
+ [
667
+ path.join(runtimeRoot, "scripts", "package-desktop.mjs"),
668
+ "--bundle",
669
+ bundle,
670
+ "--assets",
671
+ assets,
672
+ "--config",
673
+ configPath,
674
+ "--runtime",
675
+ installedRuntime(runtimeRoot),
676
+ "--output",
677
+ output
678
+ ],
679
+ cwd
680
+ );
681
+ }
682
+ async function build(options) {
683
+ const cwd = path.resolve(options.cwd ?? process.cwd());
684
+ if (options.target === "web") await buildWeb(cwd, options.viteArgs);
685
+ else {
686
+ if ((options.viteArgs?.length ?? 0) > 0) {
687
+ throw new Error(
688
+ `${options.target} build does not accept ${options.viteArgs?.join(" ")}. iOS output is simulator-only; device signing remains OPEN.`
689
+ );
690
+ }
691
+ await buildNative(options.target, cwd);
692
+ }
693
+ }
694
+ function buildHelp() {
695
+ return `${[
696
+ "Usage: threenative build [--target web|desktop|android|ios]",
697
+ "",
698
+ "Options:",
699
+ " --target <target> Choose web, desktop, android, or ios (default: web).",
700
+ " --help Show this help."
701
+ ].join("\n")}
702
+ `;
703
+ }
704
+ function parseBuildArgs(argv) {
705
+ if (argv[0] !== "build") {
706
+ throw new Error("Usage: threenative build [--target web|desktop|android|ios]");
707
+ }
708
+ const targetIndex = argv.indexOf("--target");
709
+ const value = targetIndex === -1 ? "web" : argv[targetIndex + 1];
710
+ if (!TARGETS.includes(value)) {
711
+ throw new Error(`Unknown build target '${value ?? ""}'. Choose ${TARGETS.join(", ")}.`);
712
+ }
713
+ const consumed = /* @__PURE__ */ new Set([0]);
714
+ if (targetIndex !== -1) {
715
+ consumed.add(targetIndex);
716
+ consumed.add(targetIndex + 1);
717
+ }
718
+ return {
719
+ target: value,
720
+ viteArgs: argv.filter((_, index) => !consumed.has(index))
721
+ };
722
+ }
723
+
724
+ // src/threenative.ts
725
+ function cliHelp(command) {
726
+ if (command === "build") return buildHelp();
727
+ return `${[
728
+ "Usage: threenative build [options]",
729
+ "",
730
+ "Commands:",
731
+ " build Build web or native output.",
732
+ "",
733
+ "Run 'threenative build --help' for command-specific help."
734
+ ].join("\n")}
735
+ `;
736
+ }
737
+ function helpFor(argv) {
738
+ const command = argv[0];
739
+ if (command === void 0 || command.startsWith("-")) return cliHelp();
740
+ if (command === "build") return cliHelp("build");
741
+ throw new Error(`Unknown threenative command '${command}'.
742
+ ${cliHelp()}`);
743
+ }
744
+ async function main(argv = process.argv.slice(2)) {
745
+ if (argv.includes("--help") || argv.includes("-h")) {
746
+ process.stdout.write(helpFor(argv));
747
+ return;
748
+ }
749
+ await build(parseBuildArgs(argv));
750
+ }
751
+ main().catch((error) => {
752
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}
753
+ `);
754
+ process.exitCode = 1;
755
+ });
756
+
757
+ export { cliHelp, main };