vibedgames 0.5.0 → 0.6.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 (74) hide show
  1. package/LICENSE +21 -0
  2. package/dist/commands/completions.d.ts +1 -1
  3. package/dist/commands/completions.js +21 -20
  4. package/dist/commands/credits.d.ts +5 -5
  5. package/dist/commands/credits.js +43 -33
  6. package/dist/commands/deploy.d.ts +10 -10
  7. package/dist/commands/deploy.js +155 -139
  8. package/dist/commands/factory.d.ts +1 -1
  9. package/dist/commands/factory.js +18 -15
  10. package/dist/commands/fork.d.ts +14 -14
  11. package/dist/commands/fork.js +51 -46
  12. package/dist/commands/generate.js +318 -264
  13. package/dist/commands/init.d.ts +8 -8
  14. package/dist/commands/init.js +31 -24
  15. package/dist/commands/login.js +12 -12
  16. package/dist/commands/logout.js +2 -2
  17. package/dist/commands/new.d.ts +16 -16
  18. package/dist/commands/new.js +153 -142
  19. package/dist/commands/playtest-run.d.ts +62 -0
  20. package/dist/commands/playtest-run.js +258 -0
  21. package/dist/commands/playtest.d.ts +41 -6
  22. package/dist/commands/playtest.js +114 -101
  23. package/dist/commands/update.d.ts +7 -7
  24. package/dist/commands/update.js +20 -17
  25. package/dist/commands/whoami.d.ts +5 -5
  26. package/dist/commands/whoami.js +8 -7
  27. package/dist/index.js +21 -11
  28. package/dist/lib/api.d.ts +4 -4
  29. package/dist/lib/api.js +6 -12
  30. package/dist/lib/archive.d.ts +4 -4
  31. package/dist/lib/archive.js +121 -104
  32. package/dist/lib/codex.d.ts +45 -15
  33. package/dist/lib/codex.js +175 -106
  34. package/dist/lib/config-file.d.ts +6 -6
  35. package/dist/lib/config-file.js +28 -26
  36. package/dist/lib/config.d.ts +8 -8
  37. package/dist/lib/config.js +31 -33
  38. package/dist/lib/manifest.d.ts +3 -3
  39. package/dist/lib/manifest.js +42 -38
  40. package/dist/lib/media-args.d.ts +7 -7
  41. package/dist/lib/media-args.js +113 -95
  42. package/dist/lib/media-download.d.ts +9 -9
  43. package/dist/lib/media-download.js +148 -134
  44. package/dist/lib/media-poll.d.ts +8 -8
  45. package/dist/lib/media-poll.js +32 -27
  46. package/dist/lib/media-upload.d.ts +2 -2
  47. package/dist/lib/media-upload.js +27 -27
  48. package/dist/lib/output.d.ts +27 -12
  49. package/dist/lib/output.js +26 -26
  50. package/dist/lib/package-manager.d.ts +3 -3
  51. package/dist/lib/package-manager.js +27 -22
  52. package/dist/lib/playtest/agent.d.ts +188 -0
  53. package/dist/lib/playtest/agent.js +610 -0
  54. package/dist/lib/playtest/browser.d.ts +109 -0
  55. package/dist/lib/playtest/browser.js +219 -0
  56. package/dist/lib/playtest/controls.d.ts +47 -0
  57. package/dist/lib/playtest/controls.js +218 -0
  58. package/dist/lib/playtest/errors.d.ts +9 -0
  59. package/dist/lib/playtest/errors.js +12 -0
  60. package/dist/lib/playtest/keys.d.ts +41 -0
  61. package/dist/lib/playtest/keys.js +157 -0
  62. package/dist/lib/playtest/run.d.ts +193 -0
  63. package/dist/lib/playtest/run.js +408 -0
  64. package/dist/lib/run.d.ts +4 -4
  65. package/dist/lib/run.js +7 -4
  66. package/dist/lib/strict-args.d.ts +4 -4
  67. package/dist/lib/strict-args.js +28 -18
  68. package/dist/lib/types.d.ts +5 -5
  69. package/dist/lib/types.js +9 -12
  70. package/dist/lib/update.d.ts +4 -4
  71. package/dist/lib/update.js +41 -32
  72. package/dist/lib/upload.d.ts +4 -4
  73. package/dist/lib/upload.js +14 -9
  74. package/package.json +16 -16
@@ -1,20 +1,20 @@
1
1
  export declare const initCommand: import("citty").CommandDef<{
2
2
  readonly agent: {
3
- readonly type: "string";
4
- readonly description: "Comma-separated target agents. Default installs for Claude Code, Cursor, and Codex (symlinked from a shared .agents/skills/ dir). Pass '*' for every supported agent.";
5
3
  readonly alias: "a";
6
4
  readonly default: "claude-code,cursor,codex";
5
+ readonly description: "Comma-separated target agents. Default installs for Claude Code, Cursor, and Codex (symlinked from a shared .agents/skills/ dir). Pass '*' for every supported agent.";
6
+ readonly type: "string";
7
7
  };
8
8
  readonly global: {
9
- readonly type: "boolean";
10
- readonly description: "Install to user directory instead of project";
11
- readonly default: false;
12
9
  readonly alias: "g";
10
+ readonly default: false;
11
+ readonly description: "Install to user directory instead of project";
12
+ readonly type: "boolean";
13
13
  };
14
14
  readonly yes: {
15
- readonly type: "boolean";
16
- readonly description: "Skip confirmation prompts";
17
- readonly default: true;
18
15
  readonly alias: "y";
16
+ readonly default: true;
17
+ readonly description: "Skip confirmation prompts";
18
+ readonly type: "boolean";
19
19
  };
20
20
  }>;
@@ -1,6 +1,5 @@
1
- import { fileURLToPath } from "node:url";
2
1
  import { defineCommand } from "citty";
3
- import consola from "consola";
2
+ import { consola } from "consola";
4
3
  import { detectPackageManager, globalInstallArgs, globalInstallCommand, PKG_NAME, } from "../lib/package-manager.js";
5
4
  import { isMissingCommand, run } from "../lib/run.js";
6
5
  import { assertKnownFlags } from "../lib/strict-args.js";
@@ -9,45 +8,50 @@ const DEFAULT_AGENTS = "claude-code,cursor,codex";
9
8
  const description = "Install/update vibedgames skills and the vg CLI";
10
9
  const skillsAddArgs = (agents, global, yes) => {
11
10
  const args = ["-y", "skills", "add", REPO];
12
- for (const agent of agents)
11
+ for (const agent of agents) {
13
12
  args.push("-a", agent);
14
- if (global)
13
+ }
14
+ if (global) {
15
15
  args.push("-g");
16
- if (yes)
16
+ }
17
+ if (yes) {
17
18
  args.push("-y");
19
+ }
18
20
  return args;
19
21
  };
20
22
  const skillsUpdateArgs = (global, yes) => {
21
23
  const args = ["-y", "skills", "update"];
22
- if (global)
24
+ if (global) {
23
25
  args.push("-g");
24
- if (yes)
26
+ }
27
+ if (yes) {
25
28
  args.push("-y");
29
+ }
26
30
  return args;
27
31
  };
28
32
  const initArgs = {
29
33
  agent: {
30
- type: "string",
31
- description: "Comma-separated target agents. Default installs for Claude Code, Cursor, and Codex (symlinked from a shared .agents/skills/ dir). Pass '*' for every supported agent.",
32
34
  alias: "a",
33
35
  default: DEFAULT_AGENTS,
36
+ description: "Comma-separated target agents. Default installs for Claude Code, Cursor, and Codex (symlinked from a shared .agents/skills/ dir). Pass '*' for every supported agent.",
37
+ type: "string",
34
38
  },
35
39
  global: {
36
- type: "boolean",
37
- description: "Install to user directory instead of project",
38
- default: false,
39
40
  alias: "g",
41
+ default: false,
42
+ description: "Install to user directory instead of project",
43
+ type: "boolean",
40
44
  },
41
45
  yes: {
42
- type: "boolean",
43
- description: "Skip confirmation prompts",
44
- default: true,
45
46
  alias: "y",
47
+ default: true,
48
+ description: "Skip confirmation prompts",
49
+ type: "boolean",
46
50
  },
47
51
  };
48
52
  export const initCommand = defineCommand({
49
- meta: { name: "init", description },
50
53
  args: initArgs,
54
+ meta: { description, name: "init" },
51
55
  run: async ({ args, rawArgs }) => {
52
56
  assertKnownFlags(rawArgs, initArgs);
53
57
  const agents = args.agent
@@ -57,7 +61,7 @@ export const initCommand = defineCommand({
57
61
  // Whatever installed this CLI is what should upgrade it. Installing with a
58
62
  // different manager writes a second copy into a prefix the shell may not
59
63
  // even be looking at, so `vg --version` would not move.
60
- const manager = detectPackageManager(fileURLToPath(import.meta.url));
64
+ const manager = detectPackageManager(import.meta.filename);
61
65
  consola.start("Installing/updating vibedgames skills and the vg CLI (this takes a few minutes — `skills` fetches the repo once per skill)...");
62
66
  const [add, cli] = await Promise.all([
63
67
  run("npx", skillsAddArgs(agents, args.global, args.yes), { stream: true }),
@@ -69,25 +73,28 @@ export const initCommand = defineCommand({
69
73
  "the vg CLI is running from a standalone build — install Node, or add " +
70
74
  `the skills yourself with: npx skills add ${REPO}`);
71
75
  }
72
- if (add.output.trim())
76
+ if (add.output.trim()) {
73
77
  consola.error(add.output.trim());
78
+ }
74
79
  throw new Error(`skills add exited with code ${add.code}`);
75
80
  }
76
81
  consola.success(`Installed vibedgames skills for ${agents.join(", ")}`);
77
82
  const update = await run("npx", skillsUpdateArgs(args.global, args.yes), {
78
83
  stream: true,
79
84
  });
80
- if (update.code !== 0) {
81
- if (update.output.trim())
82
- consola.warn(update.output.trim());
83
- consola.warn(`'skills update' exited with code ${update.code}. Skills were just installed via 'add', so they should already be current.`);
85
+ if (update.code === 0) {
86
+ consola.success("Refreshed installed skills to latest");
84
87
  }
85
88
  else {
86
- consola.success("Refreshed installed skills to latest");
89
+ if (update.output.trim()) {
90
+ consola.warn(update.output.trim());
91
+ }
92
+ consola.warn(`'skills update' exited with code ${update.code}. Skills were just installed via 'add', so they should already be current.`);
87
93
  }
88
94
  if (cli.code !== 0) {
89
- if (cli.output.trim() && !isMissingCommand(cli))
95
+ if (cli.output.trim() && !isMissingCommand(cli)) {
90
96
  consola.warn(cli.output.trim());
97
+ }
91
98
  consola.warn(isMissingCommand(cli)
92
99
  ? `Couldn't find ${manager} to update the vg CLI. Update manually: ${globalInstallCommand(manager)}`
93
100
  : `Couldn't install the vg CLI globally (${manager} exit ${cli.code}). Install manually: ${globalInstallCommand(manager)}`);
@@ -1,21 +1,21 @@
1
1
  import { exec } from "node:child_process";
2
+ import { setTimeout as sleep } from "node:timers/promises";
2
3
  import { defineCommand } from "citty";
3
- import consola from "consola";
4
+ import { consola } from "consola";
4
5
  import { createPublicClient } from "../lib/api.js";
5
6
  import { getBaseUrl, saveConfig } from "../lib/config.js";
6
- const POLL_INTERVAL_MS = 2_000;
7
- const MAX_POLLS = 150; // 5 min at 2s intervals
8
- function openBrowser(url) {
9
- const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
7
+ const POLL_INTERVAL_MS = 2000;
8
+ // 5 min at 2s intervals
9
+ const MAX_POLLS = 150;
10
+ const openBrowser = (url) => {
11
+ const openers = { darwin: "open", win32: "start" };
12
+ const cmd = openers[process.platform] ?? "xdg-open";
10
13
  exec(`${cmd} "${url}"`);
11
- }
12
- function sleep(ms) {
13
- return new Promise((resolve) => setTimeout(resolve, ms));
14
- }
14
+ };
15
15
  export const loginCommand = defineCommand({
16
16
  meta: {
17
- name: "login",
18
17
  description: "Authenticate with vibedgames",
18
+ name: "login",
19
19
  },
20
20
  run: async () => {
21
21
  const baseUrl = getBaseUrl();
@@ -26,11 +26,11 @@ export const loginCommand = defineCommand({
26
26
  const authUrl = `${baseUrl}/auth/cli?code=${code}`;
27
27
  openBrowser(authUrl);
28
28
  consola.start("Waiting for confirmation...");
29
- for (let i = 0; i < MAX_POLLS; i++) {
29
+ for (let i = 0; i < MAX_POLLS; i += 1) {
30
30
  await sleep(POLL_INTERVAL_MS);
31
31
  const result = await client.auth.cliPoll({ code });
32
32
  if (result.status === "confirmed") {
33
- saveConfig({ token: result.token, baseUrl });
33
+ saveConfig({ baseUrl, token: result.token });
34
34
  consola.success("Logged in successfully");
35
35
  return;
36
36
  }
@@ -1,10 +1,10 @@
1
1
  import { defineCommand } from "citty";
2
- import consola from "consola";
2
+ import { consola } from "consola";
3
3
  import { clearConfig } from "../lib/config.js";
4
4
  export const logoutCommand = defineCommand({
5
5
  meta: {
6
- name: "logout",
7
6
  description: "Log out of vibedgames",
7
+ name: "logout",
8
8
  },
9
9
  run: () => {
10
10
  clearConfig();
@@ -1,26 +1,26 @@
1
1
  export declare const newCommand: import("citty").CommandDef<{
2
- readonly slug: {
3
- readonly type: "positional";
4
- readonly description: "Lowercase, hyphenated slug — used as the directory name and deploy subdomain.";
5
- readonly required: true;
6
- };
7
2
  readonly engine: {
8
- readonly type: "string";
9
- readonly description: `Engine preset: ${string} (default: phaser).`;
10
3
  readonly default: "phaser";
11
- };
12
- readonly template: {
4
+ readonly description: `Engine preset: ${string} (default: phaser).`;
13
5
  readonly type: "string";
14
- readonly description: "Override the engine preset and fetch from an arbitrary degit spec (e.g. owner/repo, owner/repo#branch). Skips the engine preset entirely.";
15
- };
16
- readonly here: {
17
- readonly type: "boolean";
18
- readonly description: "Write into the current directory instead of creating <slug>/.";
19
- readonly default: false;
20
6
  };
21
7
  readonly force: {
22
- readonly type: "boolean";
8
+ readonly default: false;
23
9
  readonly description: "Overwrite an existing target directory.";
10
+ readonly type: "boolean";
11
+ };
12
+ readonly here: {
24
13
  readonly default: false;
14
+ readonly description: "Write into the current directory instead of creating <slug>/.";
15
+ readonly type: "boolean";
16
+ };
17
+ readonly slug: {
18
+ readonly description: "Lowercase, hyphenated slug — used as the directory name and deploy subdomain.";
19
+ readonly required: true;
20
+ readonly type: "positional";
21
+ };
22
+ readonly template: {
23
+ readonly description: "Override the engine preset and fetch from an arbitrary degit spec (e.g. owner/repo, owner/repo#branch). Skips the engine preset entirely.";
24
+ readonly type: "string";
25
25
  };
26
26
  }>;
@@ -1,7 +1,7 @@
1
1
  import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
- import { resolve } from "node:path";
2
+ import path from "node:path";
3
3
  import { defineCommand } from "citty";
4
- import consola from "consola";
4
+ import { consola } from "consola";
5
5
  import tiged from "tiged";
6
6
  import { SLUG_RE } from "../lib/config-file.js";
7
7
  import { assertKnownFlags } from "../lib/strict-args.js";
@@ -13,12 +13,12 @@ const ENGINES = new Map([
13
13
  [
14
14
  "phaser",
15
15
  {
16
- repo: "phaserjs/template-vite-ts",
17
16
  label: "Phaser 4 + Vite + TypeScript (official)",
18
- skill: "phaser",
19
17
  postNotes: [
20
18
  "The phaser template ships a `log.js` telemetry shim and uses `vite/config.*.mjs` for build configs — both are upstream, not vibedgames.",
21
19
  ],
20
+ repo: "phaserjs/template-vite-ts",
21
+ skill: "phaser",
22
22
  },
23
23
  ],
24
24
  // No officially-blessed Three.js starter exists. Using the most-starred
@@ -26,12 +26,12 @@ const ENGINES = new Map([
26
26
  [
27
27
  "threejs",
28
28
  {
29
- repo: "pachoclo/vite-threejs-ts-template",
30
29
  label: "Three.js + Vite + TypeScript (community)",
31
- skill: "threejs",
32
30
  postNotes: [
33
31
  "The demo scene (src/scene.ts) wires lil-gui, stats.js and Drag/OrbitControls as a showcase — replace it with your game and drop the debug deps for production.",
34
32
  ],
33
+ repo: "pachoclo/vite-threejs-ts-template",
34
+ skill: "threejs",
35
35
  },
36
36
  ],
37
37
  // React Three Fiber. Same author as the threejs preset — Vite + TS +
@@ -43,8 +43,8 @@ const ENGINES = new Map([
43
43
  [
44
44
  "react-r3f",
45
45
  {
46
- repo: "pachoclo/vite-r3f-ts-template",
47
46
  label: "React + React Three Fiber + Vite + TypeScript (community)",
47
+ repo: "pachoclo/vite-r3f-ts-template",
48
48
  skill: "threejs",
49
49
  },
50
50
  ],
@@ -62,87 +62,194 @@ const ENGINES = new Map([
62
62
  ]);
63
63
  const NONE_FILES = [
64
64
  {
65
- path: "package.json",
66
65
  content: (slug) => `${JSON.stringify({
66
+ devDependencies: { typescript: "^5.6.0", vite: "^7.0.0" },
67
67
  name: slug,
68
- version: "0.0.0",
69
68
  private: true,
70
- type: "module",
71
69
  scripts: {
72
- dev: "vite",
73
70
  build: "vite build",
71
+ dev: "vite",
74
72
  preview: "vite preview",
75
73
  },
76
- devDependencies: { typescript: "^5.6.0", vite: "^7.0.0" },
74
+ type: "module",
75
+ version: "0.0.0",
77
76
  }, null, 2)}\n`,
77
+ path: "package.json",
78
78
  },
79
79
  {
80
- path: "tsconfig.json",
81
80
  content: () => `${JSON.stringify({
82
81
  compilerOptions: {
83
- target: "ES2022",
82
+ esModuleInterop: true,
83
+ isolatedModules: true,
84
84
  lib: ["ES2022", "DOM", "DOM.Iterable"],
85
85
  module: "Preserve",
86
86
  moduleResolution: "Bundler",
87
- strict: true,
87
+ noEmit: true,
88
88
  noUncheckedIndexedAccess: true,
89
- isolatedModules: true,
90
- esModuleInterop: true,
91
89
  skipLibCheck: true,
92
- noEmit: true,
90
+ strict: true,
91
+ target: "ES2022",
93
92
  types: ["vite/client"],
94
93
  },
95
94
  include: ["src", "vite.config.ts"],
96
95
  }, null, 2)}\n`,
96
+ path: "tsconfig.json",
97
97
  },
98
98
  {
99
- path: "vite.config.ts",
100
99
  content: () => `import { defineConfig } from "vite";\n\nexport default defineConfig({\n base: "./",\n server: { port: 5173 },\n});\n`,
100
+ path: "vite.config.ts",
101
101
  },
102
102
  {
103
- path: "index.html",
104
103
  content: (slug) => `<!doctype html>\n<html lang="en">\n <head>\n <meta charset="UTF-8" />\n <title>${slug}</title>\n <style>html,body{margin:0;background:#0f1020;color:#fff;font-family:system-ui,sans-serif;}#game{display:flex;align-items:center;justify-content:center;height:100vh;}</style>\n </head>\n <body>\n <div id="game"></div>\n <script type="module" src="/src/main.ts"></script>\n </body>\n</html>\n`,
104
+ path: "index.html",
105
105
  },
106
106
  {
107
- path: "src/main.ts",
108
107
  content: (slug) => `const canvas = document.createElement("canvas");\ncanvas.width = 800;\ncanvas.height = 600;\ndocument.getElementById("game")!.appendChild(canvas);\nconst ctx = canvas.getContext("2d")!;\n\nctx.fillStyle = "#fff";\nctx.textAlign = "center";\nctx.font = "28px system-ui";\nctx.fillText("${slug}", canvas.width / 2, canvas.height / 2 - 8);\nctx.font = "14px system-ui";\nctx.fillStyle = "#aaa";\nctx.fillText("Edit src/main.ts to start building.", canvas.width / 2, canvas.height / 2 + 22);\n`,
108
+ path: "src/main.ts",
109
109
  },
110
- { path: ".gitignore", content: () => `node_modules\ndist\n.DS_Store\n` },
110
+ { content: () => `node_modules\ndist\n.DS_Store\n`, path: ".gitignore" },
111
111
  ];
112
112
  // Derived so `--help` and the error message can't drift from the presets again.
113
113
  const ENGINE_IDS = [...ENGINES.keys()];
114
114
  const newArgs = {
115
- slug: {
116
- type: "positional",
117
- description: "Lowercase, hyphenated slug — used as the directory name and deploy subdomain.",
118
- required: true,
119
- },
120
115
  engine: {
121
- type: "string",
122
- description: `Engine preset: ${ENGINE_IDS.join(", ")} (default: phaser).`,
123
116
  default: "phaser",
124
- },
125
- template: {
117
+ description: `Engine preset: ${ENGINE_IDS.join(", ")} (default: phaser).`,
126
118
  type: "string",
127
- description: "Override the engine preset and fetch from an arbitrary degit spec (e.g. owner/repo, owner/repo#branch). Skips the engine preset entirely.",
128
- },
129
- here: {
130
- type: "boolean",
131
- description: "Write into the current directory instead of creating <slug>/.",
132
- default: false,
133
119
  },
134
120
  force: {
135
- type: "boolean",
121
+ default: false,
136
122
  description: "Overwrite an existing target directory.",
123
+ type: "boolean",
124
+ },
125
+ here: {
137
126
  default: false,
127
+ description: "Write into the current directory instead of creating <slug>/.",
128
+ type: "boolean",
138
129
  },
130
+ slug: {
131
+ description: "Lowercase, hyphenated slug — used as the directory name and deploy subdomain.",
132
+ required: true,
133
+ type: "positional",
134
+ },
135
+ template: {
136
+ description: "Override the engine preset and fetch from an arbitrary degit spec (e.g. owner/repo, owner/repo#branch). Skips the engine preset entirely.",
137
+ type: "string",
138
+ },
139
+ };
140
+ const fetchTemplate = async (repo, target, force) => {
141
+ const emitter = tiged(repo, { force, mode: "tar", verbose: false });
142
+ await emitter.clone(target);
143
+ };
144
+ /** Remove template-repo artifacts that never apply to a scaffolded game:
145
+ * the template's own lockfile (wrong for whatever package manager the user
146
+ * runs) and its CI workflows (reference the template repo, fail elsewhere). */
147
+ const cleanTemplateArtifacts = (target) => {
148
+ for (const f of ["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lockb", "bun.lock"]) {
149
+ const p = path.resolve(target, f);
150
+ if (existsSync(p)) {
151
+ rmSync(p);
152
+ }
153
+ }
154
+ const gh = path.resolve(target, ".github");
155
+ if (existsSync(gh)) {
156
+ rmSync(gh, { recursive: true });
157
+ }
158
+ };
159
+ /** Some templates (threejs) ship no vite config at all, which means no
160
+ * relative `base` — write a minimal one so built asset URLs are relative
161
+ * and the bundle works wherever it's hosted. Never touches templates that
162
+ * bring their own config (phaser uses a vite/ config dir wired into its
163
+ * npm scripts). */
164
+ const ensureViteConfig = (target) => {
165
+ const hasConfig = ["vite.config.ts", "vite.config.js", "vite.config.mjs"].some((f) => existsSync(path.resolve(target, f))) || existsSync(path.resolve(target, "vite"));
166
+ if (hasConfig) {
167
+ return;
168
+ }
169
+ writeFileSync(path.resolve(target, "vite.config.ts"), `import { defineConfig } from "vite";\n\nexport default defineConfig({\n base: "./",\n});\n`);
170
+ };
171
+ /** Agents lean on \`npm run typecheck\` to verify changes without a full
172
+ * build — add it when the template doesn't define one. */
173
+ const ensureTypecheckScript = (target) => {
174
+ const pkgPath = path.resolve(target, "package.json");
175
+ if (!existsSync(pkgPath)) {
176
+ return;
177
+ }
178
+ try {
179
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
180
+ if (!isJsonObject(pkg)) {
181
+ return;
182
+ }
183
+ const scripts = isJsonObject(pkg.scripts) ? pkg.scripts : {};
184
+ if (isJsonString(scripts.typecheck)) {
185
+ return;
186
+ }
187
+ scripts.typecheck = "tsc --noEmit";
188
+ pkg.scripts = scripts;
189
+ writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
190
+ }
191
+ catch {
192
+ // malformed package.json — rewritePackageName will warn about it
193
+ }
194
+ };
195
+ const writeInlineTemplate = (target, slug, force) => {
196
+ for (const file of NONE_FILES) {
197
+ const dest = path.resolve(target, file.path);
198
+ if (existsSync(dest) && !force) {
199
+ continue;
200
+ }
201
+ mkdirSync(dest.slice(0, dest.lastIndexOf("/")), { recursive: true });
202
+ writeFileSync(dest, file.content(slug));
203
+ }
204
+ };
205
+ const rewritePackageName = (target, slug) => {
206
+ const pkgPath = path.resolve(target, "package.json");
207
+ if (!existsSync(pkgPath)) {
208
+ return;
209
+ }
210
+ try {
211
+ const raw = readFileSync(pkgPath, "utf-8");
212
+ const pkg = JSON.parse(raw);
213
+ if (!isJsonObject(pkg)) {
214
+ throw new Error("package.json is not a JSON object");
215
+ }
216
+ pkg.name = slug;
217
+ delete pkg.repository;
218
+ delete pkg.bugs;
219
+ delete pkg.homepage;
220
+ writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
221
+ }
222
+ catch (error) {
223
+ consola.warn(`Could not rewrite package.json name to ${slug}: ${error instanceof Error ? error.message : String(error)}`);
224
+ }
225
+ };
226
+ const writeVibedgamesJson = (target, slug) => {
227
+ writeFileSync(path.resolve(target, "vibedgames.json"), `${JSON.stringify({ name: slug.replaceAll("-", " "), slug }, null, 2)}\n`);
228
+ };
229
+ const writeReadme = (target, slug, preset) => {
230
+ const readmePath = path.resolve(target, "README.md");
231
+ // Keep the template's README if present (it usually has engine docs).
232
+ // Append a vibedgames-specific footer so devs see the deploy flow.
233
+ const footer = `\n\n---\n\n## Vibedgames\n\n` +
234
+ `This project was scaffolded with \`vg new ${slug}\` (${preset.label}).\n\n` +
235
+ `\`\`\`sh\nnpm install\nnpm run dev # local preview\nnpm run build\nvg deploy ./dist # ships to ${slug}.vibedgames.com\n\`\`\`\n\n` +
236
+ `For engine-specific work, the \`${preset.skill}\` skill loads automatically in Claude Code.\n`;
237
+ if (existsSync(readmePath)) {
238
+ const existing = readFileSync(readmePath, "utf-8");
239
+ if (existing.includes("## Vibedgames")) {
240
+ return;
241
+ }
242
+ writeFileSync(readmePath, existing.replace(/\s*$/u, "") + footer);
243
+ return;
244
+ }
245
+ writeFileSync(readmePath, `# ${slug}${footer}`);
139
246
  };
140
247
  export const newCommand = defineCommand({
248
+ args: newArgs,
141
249
  meta: {
142
- name: "new",
143
250
  description: "Scaffold a new browser game. Pulls an engine template (phaser, threejs, react-r3f) or generates a minimal canvas starter.",
251
+ name: "new",
144
252
  },
145
- args: newArgs,
146
253
  run: async ({ args, rawArgs }) => {
147
254
  assertKnownFlags(rawArgs, newArgs);
148
255
  const slug = args.slug.trim().toLowerCase();
@@ -152,8 +259,8 @@ export const newCommand = defineCommand({
152
259
  }
153
260
  const preset = args.template
154
261
  ? {
155
- repo: args.template,
156
262
  label: `custom: ${args.template}`,
263
+ repo: args.template,
157
264
  skill: "deploy",
158
265
  }
159
266
  : ENGINES.get(args.engine);
@@ -161,7 +268,7 @@ export const newCommand = defineCommand({
161
268
  consola.error(`Unknown engine: ${args.engine}. Use one of: ${ENGINE_IDS.join(", ")}.`);
162
269
  process.exit(1);
163
270
  }
164
- const target = args.here ? process.cwd() : resolve(process.cwd(), slug);
271
+ const target = args.here ? process.cwd() : path.resolve(process.cwd(), slug);
165
272
  if (!args.here) {
166
273
  if (existsSync(target) && !args.force) {
167
274
  consola.error(`Directory ${target} already exists. Pass --force to overwrite, or pick a different slug.`);
@@ -177,8 +284,8 @@ export const newCommand = defineCommand({
177
284
  try {
178
285
  await fetchTemplate(preset.repo, target, args.force);
179
286
  }
180
- catch (err) {
181
- consola.error(`Failed to fetch template ${preset.repo}: ${err instanceof Error ? err.message : String(err)}\n ` +
287
+ catch (error) {
288
+ consola.error(`Failed to fetch template ${preset.repo}: ${error instanceof Error ? error.message : String(error)}\n ` +
182
289
  `Check your network connection, or pass --engine none to scaffold a minimal starter offline.`);
183
290
  process.exit(1);
184
291
  }
@@ -195,8 +302,9 @@ export const newCommand = defineCommand({
195
302
  writeReadme(target, slug, preset);
196
303
  consola.success(`Scaffolded ${slug} in ${target}`);
197
304
  if ("postNotes" in preset && preset.postNotes) {
198
- for (const n of preset.postNotes)
305
+ for (const n of preset.postNotes) {
199
306
  consola.info(n);
307
+ }
200
308
  }
201
309
  consola.log("");
202
310
  consola.info("Next steps:");
@@ -208,100 +316,3 @@ export const newCommand = defineCommand({
208
316
  consola.log(`Skill to load for engine work: ${preset.skill} (Claude Code: triggered automatically by package.json deps)`);
209
317
  },
210
318
  });
211
- async function fetchTemplate(repo, target, force) {
212
- const emitter = tiged(repo, { force, verbose: false, mode: "tar" });
213
- await emitter.clone(target);
214
- }
215
- /** Remove template-repo artifacts that never apply to a scaffolded game:
216
- * the template's own lockfile (wrong for whatever package manager the user
217
- * runs) and its CI workflows (reference the template repo, fail elsewhere). */
218
- function cleanTemplateArtifacts(target) {
219
- for (const f of ["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lockb", "bun.lock"]) {
220
- const p = resolve(target, f);
221
- if (existsSync(p))
222
- rmSync(p);
223
- }
224
- const gh = resolve(target, ".github");
225
- if (existsSync(gh))
226
- rmSync(gh, { recursive: true });
227
- }
228
- /** Some templates (threejs) ship no vite config at all, which means no
229
- * relative `base` — write a minimal one so built asset URLs are relative
230
- * and the bundle works wherever it's hosted. Never touches templates that
231
- * bring their own config (phaser uses a vite/ config dir wired into its
232
- * npm scripts). */
233
- function ensureViteConfig(target) {
234
- const hasConfig = ["vite.config.ts", "vite.config.js", "vite.config.mjs"].some((f) => existsSync(resolve(target, f))) || existsSync(resolve(target, "vite"));
235
- if (hasConfig)
236
- return;
237
- writeFileSync(resolve(target, "vite.config.ts"), `import { defineConfig } from "vite";\n\nexport default defineConfig({\n base: "./",\n});\n`);
238
- }
239
- /** Agents lean on \`npm run typecheck\` to verify changes without a full
240
- * build — add it when the template doesn't define one. */
241
- function ensureTypecheckScript(target) {
242
- const pkgPath = resolve(target, "package.json");
243
- if (!existsSync(pkgPath))
244
- return;
245
- try {
246
- const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
247
- if (!isJsonObject(pkg))
248
- return;
249
- const scripts = isJsonObject(pkg.scripts) ? pkg.scripts : {};
250
- if (isJsonString(scripts.typecheck))
251
- return;
252
- scripts.typecheck = "tsc --noEmit";
253
- pkg.scripts = scripts;
254
- writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
255
- }
256
- catch {
257
- // malformed package.json — rewritePackageName will warn about it
258
- }
259
- }
260
- function writeInlineTemplate(target, slug, force) {
261
- for (const file of NONE_FILES) {
262
- const path = resolve(target, file.path);
263
- if (existsSync(path) && !force)
264
- continue;
265
- mkdirSync(path.slice(0, path.lastIndexOf("/")), { recursive: true });
266
- writeFileSync(path, file.content(slug));
267
- }
268
- }
269
- function rewritePackageName(target, slug) {
270
- const pkgPath = resolve(target, "package.json");
271
- if (!existsSync(pkgPath))
272
- return;
273
- try {
274
- const raw = readFileSync(pkgPath, "utf8");
275
- const pkg = JSON.parse(raw);
276
- if (!isJsonObject(pkg))
277
- throw new Error("package.json is not a JSON object");
278
- pkg.name = slug;
279
- delete pkg.repository;
280
- delete pkg.bugs;
281
- delete pkg.homepage;
282
- writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
283
- }
284
- catch (err) {
285
- consola.warn(`Could not rewrite package.json name to ${slug}: ${err instanceof Error ? err.message : String(err)}`);
286
- }
287
- }
288
- function writeVibedgamesJson(target, slug) {
289
- writeFileSync(resolve(target, "vibedgames.json"), `${JSON.stringify({ slug, name: slug.replace(/-/g, " ") }, null, 2)}\n`);
290
- }
291
- function writeReadme(target, slug, preset) {
292
- const readmePath = resolve(target, "README.md");
293
- // Keep the template's README if present (it usually has engine docs).
294
- // Append a vibedgames-specific footer so devs see the deploy flow.
295
- const footer = `\n\n---\n\n## Vibedgames\n\n` +
296
- `This project was scaffolded with \`vg new ${slug}\` (${preset.label}).\n\n` +
297
- `\`\`\`sh\nnpm install\nnpm run dev # local preview\nnpm run build\nvg deploy ./dist # ships to ${slug}.vibedgames.com\n\`\`\`\n\n` +
298
- `For engine-specific work, the \`${preset.skill}\` skill loads automatically in Claude Code.\n`;
299
- if (existsSync(readmePath)) {
300
- const existing = readFileSync(readmePath, "utf8");
301
- if (existing.includes("## Vibedgames"))
302
- return;
303
- writeFileSync(readmePath, existing.replace(/\s*$/, "") + footer);
304
- return;
305
- }
306
- writeFileSync(readmePath, `# ${slug}${footer}`);
307
- }