@vibe-engine/cli 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/LICENSE-MIT +22 -0
  3. package/README.md +10 -2
  4. package/dist/assets.d.ts +9 -0
  5. package/dist/assets.js +76 -0
  6. package/dist/bin.d.ts +2 -0
  7. package/dist/bin.js +7 -0
  8. package/dist/boundary.d.ts +12 -0
  9. package/dist/boundary.js +63 -0
  10. package/dist/create.d.ts +7 -0
  11. package/dist/create.js +56 -0
  12. package/dist/game-test.d.ts +60 -0
  13. package/dist/game-test.js +129 -0
  14. package/dist/index.d.ts +5 -0
  15. package/dist/index.js +5 -0
  16. package/dist/info.d.ts +41 -0
  17. package/dist/info.js +57 -0
  18. package/dist/main.d.ts +9 -0
  19. package/dist/main.js +106 -0
  20. package/dist/map.d.ts +21 -0
  21. package/dist/map.js +29 -0
  22. package/dist/project.d.ts +74 -0
  23. package/dist/project.js +273 -0
  24. package/dist/registry.d.ts +62 -0
  25. package/dist/registry.js +27 -0
  26. package/dist/run.d.ts +18 -0
  27. package/dist/run.js +132 -0
  28. package/dist/save-store.d.ts +2 -0
  29. package/dist/save-store.js +19 -0
  30. package/dist/serve.d.ts +6 -0
  31. package/dist/serve.js +63 -0
  32. package/dist/source.d.ts +7 -0
  33. package/dist/source.js +20 -0
  34. package/dist/test-run.d.ts +17 -0
  35. package/dist/test-run.js +94 -0
  36. package/dist/vite-plugin.d.ts +17 -0
  37. package/dist/vite-plugin.js +211 -0
  38. package/dist/web.d.ts +32 -0
  39. package/dist/web.js +195 -0
  40. package/package.json +52 -3
  41. package/templates/arena-3d/AGENTS.md +169 -0
  42. package/templates/arena-3d/CLAUDE.md +3 -0
  43. package/templates/arena-3d/README.md +13 -0
  44. package/templates/arena-3d/assets/audio/coin.wav +0 -0
  45. package/templates/arena-3d/assets/fonts/LICENSE-kenney-fonts.txt +23 -0
  46. package/templates/arena-3d/assets/fonts/kenney-future.ttf +0 -0
  47. package/templates/arena-3d/assets/models/LICENSE-kenney-blocky-characters.txt +28 -0
  48. package/templates/arena-3d/assets/models/character.glb +0 -0
  49. package/templates/arena-3d/assets/ui/LICENSE-kenney-ui-pack.txt +23 -0
  50. package/templates/arena-3d/assets/ui/panel.meta.json +1 -0
  51. package/templates/arena-3d/assets/ui/panel.png +0 -0
  52. package/templates/arena-3d/package.json +22 -0
  53. package/templates/arena-3d/src/components/game.component.ts +11 -0
  54. package/templates/arena-3d/src/components/player.component.ts +16 -0
  55. package/templates/arena-3d/src/controls.input.ts +7 -0
  56. package/templates/arena-3d/src/level/build.ts +40 -0
  57. package/templates/arena-3d/src/maps/arena.map.ts +50 -0
  58. package/templates/arena-3d/src/scenes/arena.scene.ts +10 -0
  59. package/templates/arena-3d/src/systems/player-controller.system.ts +46 -0
  60. package/templates/arena-3d/src/systems/rules.system.ts +58 -0
  61. package/templates/arena-3d/src/ui/hud.ui.ts +11 -0
  62. package/templates/arena-3d/tests/arena.test.ts +111 -0
  63. package/templates/arena-3d/vibe.config.ts +21 -0
  64. package/templates/platformer-2d/AGENTS.md +172 -0
  65. package/templates/platformer-2d/CLAUDE.md +3 -0
  66. package/templates/platformer-2d/README.md +17 -0
  67. package/templates/platformer-2d/assets/KENNEY-LICENSE.txt +30 -0
  68. package/templates/platformer-2d/assets/audio/coin.wav +0 -0
  69. package/templates/platformer-2d/assets/audio/enemy-defeat.wav +0 -0
  70. package/templates/platformer-2d/assets/audio/enemy-hit.wav +0 -0
  71. package/templates/platformer-2d/assets/audio/game-over.wav +0 -0
  72. package/templates/platformer-2d/assets/audio/hurt.wav +0 -0
  73. package/templates/platformer-2d/assets/audio/jump.wav +0 -0
  74. package/templates/platformer-2d/assets/audio/level-complete.wav +0 -0
  75. package/templates/platformer-2d/assets/audio/music-theme.wav +0 -0
  76. package/templates/platformer-2d/assets/audio/shoot.wav +0 -0
  77. package/templates/platformer-2d/assets/audio/stomp.wav +0 -0
  78. package/templates/platformer-2d/assets/fonts/LICENSE-kenney-fonts.txt +23 -0
  79. package/templates/platformer-2d/assets/fonts/kenney-pixel.ttf +0 -0
  80. package/templates/platformer-2d/assets/sprites/bullet.png +0 -0
  81. package/templates/platformer-2d/assets/sprites/characters.meta.json +9 -0
  82. package/templates/platformer-2d/assets/sprites/characters.png +0 -0
  83. package/templates/platformer-2d/assets/sprites/heart-empty.png +0 -0
  84. package/templates/platformer-2d/assets/sprites/heart.png +0 -0
  85. package/templates/platformer-2d/assets/sprites/pistol.png +0 -0
  86. package/templates/platformer-2d/assets/sprites/tiles.meta.json +7 -0
  87. package/templates/platformer-2d/assets/sprites/tiles.png +0 -0
  88. package/templates/platformer-2d/assets/ui/button-focus.meta.json +1 -0
  89. package/templates/platformer-2d/assets/ui/button-focus.png +0 -0
  90. package/templates/platformer-2d/assets/ui/button-hover.meta.json +1 -0
  91. package/templates/platformer-2d/assets/ui/button-hover.png +0 -0
  92. package/templates/platformer-2d/assets/ui/button-pressed.meta.json +1 -0
  93. package/templates/platformer-2d/assets/ui/button-pressed.png +0 -0
  94. package/templates/platformer-2d/assets/ui/button.meta.json +1 -0
  95. package/templates/platformer-2d/assets/ui/button.png +0 -0
  96. package/templates/platformer-2d/assets/ui/panel.meta.json +1 -0
  97. package/templates/platformer-2d/assets/ui/panel.png +0 -0
  98. package/templates/platformer-2d/package.json +22 -0
  99. package/templates/platformer-2d/src/components/enemy.component.ts +12 -0
  100. package/templates/platformer-2d/src/components/gun.component.ts +18 -0
  101. package/templates/platformer-2d/src/components/level.component.ts +10 -0
  102. package/templates/platformer-2d/src/components/pickup.component.ts +7 -0
  103. package/templates/platformer-2d/src/components/player.component.ts +25 -0
  104. package/templates/platformer-2d/src/components/shockwave.component.ts +7 -0
  105. package/templates/platformer-2d/src/controls.input.ts +10 -0
  106. package/templates/platformer-2d/src/events/gameplay.events.ts +11 -0
  107. package/templates/platformer-2d/src/level/build.ts +89 -0
  108. package/templates/platformer-2d/src/listeners/feedback.listener.ts +22 -0
  109. package/templates/platformer-2d/src/listeners/particles.listener.ts +21 -0
  110. package/templates/platformer-2d/src/listeners/progress.listener.ts +18 -0
  111. package/templates/platformer-2d/src/listeners/sound-effects.listener.ts +16 -0
  112. package/templates/platformer-2d/src/maps/legend.ts +9 -0
  113. package/templates/platformer-2d/src/maps/level-1.map.ts +22 -0
  114. package/templates/platformer-2d/src/maps/level-2.map.ts +22 -0
  115. package/templates/platformer-2d/src/saves/progress.save.ts +11 -0
  116. package/templates/platformer-2d/src/scenes/level-1.scene.ts +17 -0
  117. package/templates/platformer-2d/src/scenes/level-2.scene.ts +16 -0
  118. package/templates/platformer-2d/src/scenes/main-menu.scene.ts +36 -0
  119. package/templates/platformer-2d/src/systems/contacts.system.ts +74 -0
  120. package/templates/platformer-2d/src/systems/enemy-patrol.system.ts +28 -0
  121. package/templates/platformer-2d/src/systems/gameplay.ts +17 -0
  122. package/templates/platformer-2d/src/systems/gun.system.ts +65 -0
  123. package/templates/platformer-2d/src/systems/hud.system.ts +23 -0
  124. package/templates/platformer-2d/src/systems/pause.system.ts +22 -0
  125. package/templates/platformer-2d/src/systems/player-controller.system.ts +46 -0
  126. package/templates/platformer-2d/src/systems/player-damage.system.ts +61 -0
  127. package/templates/platformer-2d/src/systems/player-juice.system.ts +40 -0
  128. package/templates/platformer-2d/src/systems/shockwave.system.ts +15 -0
  129. package/templates/platformer-2d/src/ui/hud.ui.ts +16 -0
  130. package/templates/platformer-2d/src/ui/main-menu.ui.ts +7 -0
  131. package/templates/platformer-2d/src/ui/pause-menu.ui.ts +12 -0
  132. package/templates/platformer-2d/tests/gameplay.test.ts +492 -0
  133. package/templates/platformer-2d/tests/jump.test.ts +41 -0
  134. package/templates/platformer-2d/vibe.config.ts +32 -0
  135. package/templates/shooter-2d-pvp/AGENTS.md +181 -0
  136. package/templates/shooter-2d-pvp/CLAUDE.md +3 -0
  137. package/templates/shooter-2d-pvp/README.md +14 -0
  138. package/templates/shooter-2d-pvp/assets/KENNEY-LICENSE.txt +30 -0
  139. package/templates/shooter-2d-pvp/assets/audio/enemy-defeat.wav +0 -0
  140. package/templates/shooter-2d-pvp/assets/audio/enemy-hit.wav +0 -0
  141. package/templates/shooter-2d-pvp/assets/audio/game-over.wav +0 -0
  142. package/templates/shooter-2d-pvp/assets/audio/hurt.wav +0 -0
  143. package/templates/shooter-2d-pvp/assets/audio/jump.wav +0 -0
  144. package/templates/shooter-2d-pvp/assets/audio/shoot.wav +0 -0
  145. package/templates/shooter-2d-pvp/assets/fonts/LICENSE-kenney-fonts.txt +23 -0
  146. package/templates/shooter-2d-pvp/assets/fonts/kenney-pixel.ttf +0 -0
  147. package/templates/shooter-2d-pvp/assets/sprites/bullet.png +0 -0
  148. package/templates/shooter-2d-pvp/assets/sprites/characters.meta.json +84 -0
  149. package/templates/shooter-2d-pvp/assets/sprites/characters.png +0 -0
  150. package/templates/shooter-2d-pvp/assets/sprites/heart.png +0 -0
  151. package/templates/shooter-2d-pvp/assets/sprites/pistol.png +0 -0
  152. package/templates/shooter-2d-pvp/assets/sprites/tiles.meta.json +7 -0
  153. package/templates/shooter-2d-pvp/assets/sprites/tiles.png +0 -0
  154. package/templates/shooter-2d-pvp/assets/ui/button-focus.meta.json +1 -0
  155. package/templates/shooter-2d-pvp/assets/ui/button-focus.png +0 -0
  156. package/templates/shooter-2d-pvp/assets/ui/button-hover.meta.json +1 -0
  157. package/templates/shooter-2d-pvp/assets/ui/button-hover.png +0 -0
  158. package/templates/shooter-2d-pvp/assets/ui/button-pressed.meta.json +1 -0
  159. package/templates/shooter-2d-pvp/assets/ui/button-pressed.png +0 -0
  160. package/templates/shooter-2d-pvp/assets/ui/button.meta.json +1 -0
  161. package/templates/shooter-2d-pvp/assets/ui/button.png +0 -0
  162. package/templates/shooter-2d-pvp/assets/ui/panel.meta.json +1 -0
  163. package/templates/shooter-2d-pvp/assets/ui/panel.png +0 -0
  164. package/templates/shooter-2d-pvp/package.json +23 -0
  165. package/templates/shooter-2d-pvp/src/components/fighter.component.ts +33 -0
  166. package/templates/shooter-2d-pvp/src/components/gun.component.ts +49 -0
  167. package/templates/shooter-2d-pvp/src/controls.input.ts +14 -0
  168. package/templates/shooter-2d-pvp/src/events/combat.events.ts +13 -0
  169. package/templates/shooter-2d-pvp/src/level/build.ts +46 -0
  170. package/templates/shooter-2d-pvp/src/listeners/effects.listener.ts +51 -0
  171. package/templates/shooter-2d-pvp/src/listeners/players.listener.ts +32 -0
  172. package/templates/shooter-2d-pvp/src/maps/arena.map.ts +26 -0
  173. package/templates/shooter-2d-pvp/src/rooms/arena.room.ts +22 -0
  174. package/templates/shooter-2d-pvp/src/rules/damage.ts +41 -0
  175. package/templates/shooter-2d-pvp/src/saves/player.save.ts +9 -0
  176. package/templates/shooter-2d-pvp/src/scenes/arena.scene.ts +15 -0
  177. package/templates/shooter-2d-pvp/src/scenes/lobby.scene.ts +11 -0
  178. package/templates/shooter-2d-pvp/src/systems/combat.system.ts +85 -0
  179. package/templates/shooter-2d-pvp/src/systems/fighter-controller.system.ts +54 -0
  180. package/templates/shooter-2d-pvp/src/systems/gun.system.ts +123 -0
  181. package/templates/shooter-2d-pvp/src/systems/lobby.system.ts +52 -0
  182. package/templates/shooter-2d-pvp/src/systems/view.system.ts +35 -0
  183. package/templates/shooter-2d-pvp/src/ui/hud.ui.ts +10 -0
  184. package/templates/shooter-2d-pvp/src/ui/lobby.ui.ts +18 -0
  185. package/templates/shooter-2d-pvp/tests/pvp.test.ts +221 -0
  186. package/templates/shooter-2d-pvp/vibe.config.ts +39 -0
@@ -0,0 +1,129 @@
1
+ /**
2
+ * `gameTest`: teste de gameplay headless sobre `node:test` (#36).
3
+ *
4
+ * `game` abre o projeto do arquivo de teste (sobe até achar `vibe.config.ts`),
5
+ * nada avança sem `step`/`hold`/`until`, e uma falha sai com tick, cena, seed,
6
+ * os últimos inputs e eventos — o suficiente para saber o que mudou.
7
+ */
8
+ import { test } from 'node:test';
9
+ import { existsSync } from 'node:fs';
10
+ import { dirname, join } from 'node:path';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { getCallSites } from 'node:util';
13
+ import { CONFIG_FILE, openScene } from './project.js';
14
+ /** Como `test` do `node:test`, com `game` pronto. `root` sobrescreve a pasta do projeto. */
15
+ export function gameTest(name, fn, opts = {}) {
16
+ const root = opts.root ?? projectRootOf(callerFile());
17
+ test(name, { ...(opts.timeout !== undefined && { timeout: opts.timeout }), ...(opts.skip && { skip: true }), ...(opts.only && { only: true }) }, async (t) => {
18
+ const game = createGame(root);
19
+ try {
20
+ await fn({ game, t });
21
+ }
22
+ catch (err) {
23
+ throw withContext(err, game);
24
+ }
25
+ });
26
+ }
27
+ export function createGame(root) {
28
+ let world = null;
29
+ let scene = '';
30
+ let seed = 1;
31
+ const log = [];
32
+ const w = () => {
33
+ if (!world)
34
+ throw new Error('game.start() first: the game is not open');
35
+ return world;
36
+ };
37
+ const step = (frames = 1) => {
38
+ const wd = w();
39
+ for (let i = 0; i < frames; i++) {
40
+ const from = wd.frame;
41
+ wd.step(1);
42
+ for (const e of wd.observe({ entityIds: [], sinceFrame: from }).events)
43
+ log.push({ frame: e.frame, name: e.name, payload: e.payload });
44
+ }
45
+ };
46
+ const until = (pred, { maxFrames }) => {
47
+ const start = w().frame;
48
+ for (let i = 0; i < maxFrames; i++) {
49
+ if (pred())
50
+ return;
51
+ step(1);
52
+ }
53
+ if (!pred())
54
+ throw new Error(`until: condition still false after ${maxFrames} ticks (from tick ${start} to ${w().frame})`);
55
+ };
56
+ return {
57
+ async start(opts = {}) {
58
+ seed = opts.seed ?? 1;
59
+ world = await openScene(root, { seed, ...(opts.scene !== undefined && { scene: opts.scene }), ...(opts.saves && { saves: opts.saves }) });
60
+ scene = world.sceneControl.id ?? '';
61
+ log.length = 0;
62
+ return world;
63
+ },
64
+ get world() {
65
+ return w();
66
+ },
67
+ get frame() {
68
+ return w().frame;
69
+ },
70
+ step,
71
+ until,
72
+ entity: (id) => w().entity(id),
73
+ events: (event) => {
74
+ const name = typeof event === 'string' ? event : event.id;
75
+ return log.filter((e) => e.name === name);
76
+ },
77
+ input: {
78
+ set: (action, value, player) => w().input.set(action, value, player),
79
+ press: (action, player) => w().input.press(action, player),
80
+ hold(action, value, opts, player) {
81
+ w().input.set(action, value, player);
82
+ if ('frames' in opts)
83
+ step(opts.frames);
84
+ else
85
+ until(opts.until, { maxFrames: opts.maxFrames });
86
+ w().input.set(action, typeof value === 'boolean' ? false : Array.isArray(value) ? [0, 0] : 0, player);
87
+ },
88
+ },
89
+ context() {
90
+ if (!world)
91
+ return 'game not started';
92
+ const inputs = world.input.recorded().slice(-5).map((c) => `${c.action}=${JSON.stringify(c.value)}@${c.frame}`).join(', ') || 'none';
93
+ const events = log.slice(-5).map((e) => `${e.name}@${e.frame}`).join(', ') || 'none';
94
+ return `at tick ${world.frame} (scene ${scene || world.sceneControl.id}, seed ${seed})\n last inputs: ${inputs}\n last events: ${events}`;
95
+ },
96
+ };
97
+ }
98
+ function withContext(err, game) {
99
+ if (!(err instanceof Error))
100
+ return err;
101
+ const extra = `\n ${game.context()}`;
102
+ const before = err.message;
103
+ try {
104
+ err.message = before + extra;
105
+ if (err.stack)
106
+ err.stack = err.stack.replace(before, err.message);
107
+ }
108
+ catch {
109
+ return new Error(before + extra, { cause: err });
110
+ }
111
+ return err;
112
+ }
113
+ function callerFile() {
114
+ const self = fileURLToPath(import.meta.url);
115
+ for (const site of getCallSites()) {
116
+ const file = site.scriptName.startsWith('file:') ? fileURLToPath(site.scriptName) : site.scriptName;
117
+ if (file && file !== self && !file.startsWith('node:'))
118
+ return file;
119
+ }
120
+ return process.cwd();
121
+ }
122
+ function projectRootOf(file) {
123
+ for (let dir = dirname(file);; dir = dirname(dir)) {
124
+ if (existsSync(join(dir, CONFIG_FILE)))
125
+ return dir;
126
+ if (dirname(dir) === dir)
127
+ return process.cwd();
128
+ }
129
+ }
@@ -0,0 +1,5 @@
1
+ export { main, COMMANDS, type MainIO } from './main.ts';
2
+ export { CliError, SCHEMA, defineCommand, type CommandSpec, type FlagSpec } from './registry.ts';
3
+ export { fileSaveStore } from './save-store.ts';
4
+ export { loadProject, createWorld, openScene, scanAssets, type Project, type AssetEntry } from './project.ts';
5
+ export { vibePlugin } from './vite-plugin.ts';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { main, COMMANDS } from './main.js';
2
+ export { CliError, SCHEMA, defineCommand } from './registry.js';
3
+ export { fileSaveStore } from './save-store.js';
4
+ export { loadProject, createWorld, openScene, scanAssets } from './project.js';
5
+ export { vibePlugin } from './vite-plugin.js';
package/dist/info.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ interface FieldInfo {
2
+ kind: string;
3
+ default: unknown;
4
+ doc?: string;
5
+ }
6
+ export interface InfoOutput {
7
+ name: string | null;
8
+ dimension: '2d' | '3d';
9
+ tickRate: number;
10
+ startScene: string | null;
11
+ input: {
12
+ file: string;
13
+ actions: Record<string, string>;
14
+ } | null;
15
+ scenes: Array<{
16
+ id: string;
17
+ file: string;
18
+ systems: string[];
19
+ listeners: string[];
20
+ next: string | null;
21
+ }>;
22
+ components: Array<{
23
+ id: string;
24
+ file: string;
25
+ fields: Record<string, FieldInfo>;
26
+ }>;
27
+ events: Array<{
28
+ id: string;
29
+ file: string;
30
+ }>;
31
+ saves: Array<{
32
+ id: string;
33
+ file: string;
34
+ }>;
35
+ resources: Array<{
36
+ id: string;
37
+ file: string;
38
+ }>;
39
+ }
40
+ export declare const info: import("./registry.ts").CommandSpec<InfoOutput>;
41
+ export {};
package/dist/info.js ADDED
@@ -0,0 +1,57 @@
1
+ import { CliError, defineCommand } from './registry.js';
2
+ import { PROJECT_ERRORS, loadProject } from './project.js';
3
+ export const info = defineCommand({
4
+ name: 'info',
5
+ summary: 'Show what the project defines: scenes, components (with schemas), events, saves, resources, input',
6
+ flags: {
7
+ component: { type: 'string', doc: 'show only this component' },
8
+ },
9
+ output: {
10
+ 'name, dimension, tickRate, startScene': 'from vibe.config.ts',
11
+ input: 'input file and action → type',
12
+ scenes: 'id (file name), file, systems, listeners, next',
13
+ components: 'id, file, fields: name → { kind, default, doc }',
14
+ 'events, saves, resources': 'id and file',
15
+ },
16
+ errors: {
17
+ ...PROJECT_ERRORS,
18
+ 'component-not-found': 'no discovered component has the id passed to --component',
19
+ },
20
+ async run({ flags, io }) {
21
+ const p = await loadProject(io.cwd);
22
+ let components = p.components;
23
+ if (flags.component !== undefined) {
24
+ components = components.filter((c) => c.id === flags.component);
25
+ if (components.length === 0)
26
+ throw new CliError('component-not-found', `component '${flags.component}' was not found`, { expected: 'a component id defined in a *.component.ts', detail: { components: p.components.map((c) => c.id) } });
27
+ }
28
+ const ids = (list) => list.map(({ id, file }) => ({ id, file }));
29
+ return {
30
+ name: p.config.name ?? null,
31
+ dimension: p.config.dimension,
32
+ tickRate: p.config.tickRate ?? 60,
33
+ startScene: p.config.startScene ?? null,
34
+ input: p.input && { file: p.input.file, actions: Object.fromEntries(Object.entries(p.input.def.actions).map(([n, a]) => [n, a.type])) },
35
+ scenes: p.scenes.map((s) => ({ id: s.id, file: s.file, systems: s.def.systems.map((x) => x.id), listeners: s.def.listeners.map((x) => x.id), next: s.def.next })),
36
+ components: components.map((c) => ({ id: c.id, file: c.file, fields: Object.fromEntries(Object.entries(c.def.fields).map(([n, f]) => [n, describeField(f)])) })),
37
+ events: ids(p.events),
38
+ saves: ids(p.saves),
39
+ resources: ids(p.resources),
40
+ };
41
+ },
42
+ human(o) {
43
+ const fields = (c) => Object.entries(c.fields).map(([n, f]) => `${n}: ${f.kind}`).join(', ');
44
+ return [
45
+ `${o.name ?? '(unnamed)'} · ${o.dimension} · ${o.tickRate} ticks/s · start ${o.startScene ?? '-'}`,
46
+ `input: ${o.input ? `${o.input.file} (${Object.entries(o.input.actions).map(([n, t]) => `${n}:${t}`).join(', ')})` : '-'}`,
47
+ `scenes:`, ...o.scenes.map((s) => ` ${s.id.padEnd(14)} ${s.file} systems: ${s.systems.join(', ') || '-'}`),
48
+ `components:`, ...o.components.map((c) => ` ${c.id.padEnd(14)} ${c.file} { ${fields(c)} }`),
49
+ `events: ${o.events.map((e) => e.id).join(', ') || '-'}`,
50
+ `saves: ${o.saves.map((e) => e.id).join(', ') || '-'}`,
51
+ `resources: ${o.resources.map((e) => e.id).join(', ') || '-'}`,
52
+ ].join('\n');
53
+ },
54
+ });
55
+ function describeField(f) {
56
+ return { kind: f.kind, default: f.create(), ...(f.options.doc ? { doc: f.options.doc } : {}) };
57
+ }
package/dist/main.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { type CommandSpec } from './registry.ts';
2
+ export declare const COMMANDS: CommandSpec<any>[];
3
+ export interface MainIO {
4
+ cwd: string;
5
+ stdout(text: string): void;
6
+ stderr(text: string): void;
7
+ }
8
+ /** Roda a CLI e devolve o exit code: 0 ok, 1 erro do comando, 2 uso errado. */
9
+ export declare function main(argv: string[], io: MainIO): Promise<number>;
package/dist/main.js ADDED
@@ -0,0 +1,106 @@
1
+ /** Entrada da CLI: parse de flags pelo registro, saída humana ou `--json`. */
2
+ import { parseArgs } from 'node:util';
3
+ import { CliError, GLOBAL_ERRORS, SCHEMA, defineCommand } from './registry.js';
4
+ import { run } from './run.js';
5
+ import { info } from './info.js';
6
+ import { assets, check } from './assets.js';
7
+ import { map } from './map.js';
8
+ import { build, dev } from './web.js';
9
+ import { create } from './create.js';
10
+ import { serve } from './serve.js';
11
+ import { testCmd } from './test-run.js';
12
+ const describe = (c) => ({
13
+ name: c.name,
14
+ summary: c.summary,
15
+ positionals: c.positionals ?? [],
16
+ flags: { ...c.flags, json: { type: 'boolean', default: false, doc: 'print versioned JSON (vibe.cli/1)' } },
17
+ output: c.output,
18
+ errors: { ...GLOBAL_ERRORS, ...c.errors },
19
+ });
20
+ const help = defineCommand({
21
+ name: 'help',
22
+ summary: 'List commands with their flags, output fields and error codes',
23
+ positionals: [{ name: 'command', doc: 'show a single command' }],
24
+ flags: { tree: { type: 'boolean', default: false, doc: 'every command with its full schema (with --json)' } },
25
+ output: { commands: 'commands with name, summary, positionals, flags, output and errors' },
26
+ errors: {},
27
+ async run({ positionals }) {
28
+ const name = positionals[0];
29
+ if (name === undefined)
30
+ return { commands: COMMANDS.map(describe) };
31
+ const cmd = COMMANDS.find((c) => c.name === name);
32
+ if (!cmd)
33
+ throw unknownCommand(name);
34
+ return { commands: [describe(cmd)] };
35
+ },
36
+ human({ commands }) {
37
+ if (commands.length > 1)
38
+ return ['vibe <command> [flags] (add --json for machine output)', '', ...commands.map((c) => ` ${c.name.padEnd(8)} ${c.summary}`), '', 'vibe help <command> shows flags and error codes.'].join('\n');
39
+ const c = commands[0];
40
+ const flags = Object.entries(c.flags).map(([n, f]) => ` --${n} <${f.type}>${f.default !== undefined ? ` (default ${f.default})` : ''}\n ${f.doc}`);
41
+ const errors = Object.entries(c.errors).map(([code, when]) => ` ${code.padEnd(18)} ${when}`);
42
+ return [`vibe ${c.name} — ${c.summary}`, '', 'flags:', ...flags, '', 'errors:', ...errors].join('\n');
43
+ },
44
+ });
45
+ export const COMMANDS = [create, run, testCmd, dev, serve, build, info, assets, check, map, help];
46
+ function unknownCommand(name) {
47
+ return new CliError('unknown-command', `unknown command '${name}'`, { expected: COMMANDS.map((c) => c.name).join(' | '), hint: 'vibe help --tree --json lists every command' });
48
+ }
49
+ /** Roda a CLI e devolve o exit code: 0 ok, 1 erro do comando, 2 uso errado. */
50
+ export async function main(argv, io) {
51
+ const json = argv.includes('--json');
52
+ try {
53
+ let [name = 'help', ...rest] = argv;
54
+ if (name.startsWith('-'))
55
+ [name, rest] = ['help', argv];
56
+ const cmd = COMMANDS.find((c) => c.name === name);
57
+ if (!cmd)
58
+ throw unknownCommand(name);
59
+ if (rest.includes('--help') || rest.includes('-h'))
60
+ return main(['help', cmd.name, ...(json ? ['--json'] : [])], io);
61
+ const { flags, positionals } = parse(cmd, rest);
62
+ const out = await cmd.run({ flags, positionals, io: { cwd: io.cwd } });
63
+ io.stdout(json ? JSON.stringify({ schema: SCHEMA, command: cmd.name, ...out }) : cmd.human(out));
64
+ return 0;
65
+ }
66
+ catch (err) {
67
+ const e = err instanceof CliError ? err : new CliError('internal', err?.message ?? String(err), { hint: 'this is a CLI bug; please report it with the command you ran' });
68
+ if (json)
69
+ io.stdout(JSON.stringify(e));
70
+ else
71
+ io.stderr(`error ${e.code}: ${e.message}${e.fields.source ? `\n at ${e.fields.source}` : ''}${e.fields.hint ? `\n hint: ${e.fields.hint}` : ''}`);
72
+ return e.code === 'usage' || e.code === 'unknown-command' ? 2 : 1;
73
+ }
74
+ }
75
+ function parse(cmd, args) {
76
+ const options = { json: { type: 'boolean' } };
77
+ for (const [n, f] of Object.entries(cmd.flags))
78
+ options[n] = { type: f.type === 'boolean' ? 'boolean' : 'string' };
79
+ let parsed;
80
+ try {
81
+ parsed = parseArgs({ args, options, allowPositionals: true, strict: true, allowNegative: true });
82
+ }
83
+ catch (err) {
84
+ throw new CliError('usage', err.message, { expected: Object.keys(options).map((n) => `--${n}`).join(' '), hint: `vibe help ${cmd.name}` });
85
+ }
86
+ const max = cmd.positionals?.length ?? 0;
87
+ if (parsed.positionals.length > max)
88
+ throw new CliError('usage', `unexpected argument '${parsed.positionals[max]}'`, { hint: `vibe help ${cmd.name}` });
89
+ const flags = {};
90
+ for (const [n, f] of Object.entries(cmd.flags)) {
91
+ const raw = parsed.values[n];
92
+ if (raw === undefined) {
93
+ flags[n] = f.default;
94
+ continue;
95
+ }
96
+ if (f.type !== 'number') {
97
+ flags[n] = raw;
98
+ continue;
99
+ }
100
+ const num = Number(raw);
101
+ if (raw === '' || !Number.isFinite(num))
102
+ throw new CliError('usage', `--${n} expects a number, got '${raw}'`, { expected: 'number', hint: `vibe help ${cmd.name}` });
103
+ flags[n] = num;
104
+ }
105
+ return { flags, positionals: parsed.positionals };
106
+ }
package/dist/map.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ type MapOutput = {
2
+ action: 'show';
3
+ id: string;
4
+ file: string;
5
+ width: number;
6
+ height: number;
7
+ depth: number;
8
+ legend: Record<string, string>;
9
+ text: string;
10
+ } | {
11
+ action: 'check';
12
+ maps: Array<{
13
+ id: string;
14
+ file: string;
15
+ width: number;
16
+ height: number;
17
+ depth: number;
18
+ }>;
19
+ };
20
+ export declare const map: import("./registry.ts").CommandSpec<MapOutput>;
21
+ export {};
package/dist/map.js ADDED
@@ -0,0 +1,29 @@
1
+ /** `vibe map show <id>` e `vibe map check`: mapas em texto (`*.map.ts`, #111). */
2
+ import { CliError, defineCommand } from './registry.js';
3
+ import { PROJECT_ERRORS, loadProject } from './project.js';
4
+ export const map = defineCommand({
5
+ name: 'map',
6
+ summary: 'Text maps (*.map.ts): show one with a coordinate ruler, or check that all of them load and pass their rules',
7
+ positionals: [{ name: 'action', doc: 'show | check', required: true }, { name: 'id', doc: 'map id (for show)' }],
8
+ flags: {},
9
+ output: { 'show: id, file, width, height, depth, legend, text': 'the map with column ruler and row numbers', 'check: maps': 'every map found (id, file, size)' },
10
+ errors: { ...PROJECT_ERRORS, 'map-not-found': 'no *.map.ts defines that id' },
11
+ async run({ positionals, io }) {
12
+ const [action, id] = positionals;
13
+ if (action !== 'show' && action !== 'check')
14
+ throw new CliError('usage', `vibe map ${action ?? ''}: expected 'show <id>' or 'check'`, { expected: 'show | check', hint: 'vibe map show level-1' });
15
+ const project = await loadProject(io.cwd); // carregar = validar: defineMap checa as regras e aponta linha/coluna
16
+ if (action === 'check')
17
+ return { action, maps: project.maps.map((m) => ({ id: m.id, file: m.file, width: m.def.width, height: m.def.height, depth: m.def.depth })) };
18
+ const found = project.maps.find((m) => m.id === id);
19
+ if (!found)
20
+ throw new CliError('map-not-found', `map '${id ?? ''}' was not found`, { expected: 'an id from a *.map.ts', detail: { maps: project.maps.map((m) => m.id) } });
21
+ const m = found.def;
22
+ return { action, id: m.id, file: found.file, width: m.width, height: m.height, depth: m.depth, legend: { ...m.legend }, text: m.toString() };
23
+ },
24
+ human(o) {
25
+ if (o.action === 'show')
26
+ return `${o.id} · ${o.width}×${o.height}${o.depth > 1 ? `×${o.depth}` : ''} · ${o.file}\n${o.text}`;
27
+ return o.maps.length ? `ok · ${o.maps.length} maps\n${o.maps.map((m) => ` ${m.id.padEnd(14)} ${m.width}×${m.height}${m.depth > 1 ? `×${m.depth}` : ''} ${m.file}`).join('\n')}` : 'no maps (add src/<id>.map.ts with export default defineMap(...))';
28
+ },
29
+ });
@@ -0,0 +1,74 @@
1
+ import { World, type AssetKind, type ComponentDef, type InputDef, type SceneDef, type VibeConfig, type SaveStore, type GridMap, type ShaderDef } from '@vibe-engine/core';
2
+ export declare const CONFIG_FILE = "vibe.config.ts";
3
+ interface Found<T> {
4
+ id: string;
5
+ file: string;
6
+ def: T;
7
+ }
8
+ export interface AssetEntry {
9
+ id: string;
10
+ kind: AssetKind;
11
+ file: string;
12
+ bytes: number;
13
+ /** sha256 do conteúdo, 12 primeiros hex (o build usa para o nome com hash). */
14
+ hash: string;
15
+ /** Imagens: dimensões lidas do arquivo. */
16
+ width?: number;
17
+ height?: number;
18
+ /** Folha de sprites (`.meta.json` ao lado): quantos frames e quais animações. */
19
+ frames?: number;
20
+ animations?: string[];
21
+ /** Skin 9-slice de UI (`slice` no `.meta.json`). */
22
+ slice?: number | [number, number, number, number];
23
+ }
24
+ export interface Project {
25
+ root: string;
26
+ config: VibeConfig;
27
+ input: {
28
+ file: string;
29
+ def: InputDef;
30
+ } | null;
31
+ scenes: Found<SceneDef>[];
32
+ components: Found<ComponentDef<any>>[];
33
+ events: Found<{
34
+ id: string;
35
+ }>[];
36
+ saves: Found<{
37
+ id: string;
38
+ }>[];
39
+ resources: Found<{
40
+ id: string;
41
+ }>[];
42
+ maps: Found<GridMap>[];
43
+ /** Tipos de sala do multiplayer (`*.room.ts`, `defineRoom`). */
44
+ rooms: Found<{
45
+ id: string;
46
+ scene: string;
47
+ maxPlayers: number;
48
+ }>[];
49
+ /** Shaders do projeto (`*.shader.ts`, `defineShader`). Os presets da engine ficam em `SHADER_PRESETS`. */
50
+ shaders: Found<ShaderDef>[];
51
+ assets: AssetEntry[];
52
+ }
53
+ export declare const PROJECT_ERRORS: Record<string, string>;
54
+ export declare function loadProject(root: string): Promise<Project>;
55
+ /** Versão do jogo para a rede: hash do config e de `src/` (cliente e servidor do mesmo código batem; código diferente é recusado). */
56
+ export declare function projectVersion(root: string): string;
57
+ /** Monta o World do projeto: tickRate, input, cenas e o adapter de física da dimensão. */
58
+ export declare function createWorld(project: Project, seed: number, opts?: {
59
+ saves?: SaveStore;
60
+ }): Promise<World>;
61
+ /** Arquivos `.ts` em ordem alfabética (ordem de import determinística). */
62
+ export declare function walk(dir: string): string[];
63
+ /**
64
+ * Para testes do jogo: carrega o projeto, monta o World e abre a cena
65
+ * (padrão: `startScene`), igual ao `vibe run`.
66
+ */
67
+ export declare function openScene(root: string, opts?: {
68
+ scene?: string;
69
+ seed?: number;
70
+ saves?: SaveStore;
71
+ }): Promise<World>;
72
+ /** Catálogo de `assets/`: id = caminho sem extensão, formato conferido pela assinatura do arquivo. */
73
+ export declare function scanAssets(root: string): AssetEntry[];
74
+ export {};