vibedgames 0.4.1 → 0.5.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.
- package/README.md +1 -1
- package/dist/commands/completions.d.ts +1 -1
- package/dist/commands/completions.js +21 -20
- package/dist/commands/credits.d.ts +5 -5
- package/dist/commands/credits.js +45 -47
- package/dist/commands/deploy.d.ts +10 -10
- package/dist/commands/deploy.js +157 -137
- package/dist/commands/factory.d.ts +1 -1
- package/dist/commands/factory.js +18 -15
- package/dist/commands/fork.d.ts +14 -14
- package/dist/commands/fork.js +53 -45
- package/dist/commands/generate.js +343 -286
- package/dist/commands/init.d.ts +8 -8
- package/dist/commands/init.js +31 -24
- package/dist/commands/login.js +14 -14
- package/dist/commands/logout.js +2 -2
- package/dist/commands/new.d.ts +16 -16
- package/dist/commands/new.js +191 -165
- package/dist/commands/playtest.d.ts +5 -5
- package/dist/commands/playtest.js +103 -97
- package/dist/commands/update.d.ts +7 -7
- package/dist/commands/update.js +22 -17
- package/dist/commands/whoami.d.ts +5 -5
- package/dist/commands/whoami.js +11 -10
- package/dist/index.js +12 -10
- package/dist/lib/api.d.ts +16 -4
- package/dist/lib/api.js +20 -32
- package/dist/lib/archive.d.ts +4 -4
- package/dist/lib/archive.js +123 -102
- package/dist/lib/codex.d.ts +46 -15
- package/dist/lib/codex.js +178 -108
- package/dist/lib/config-file.d.ts +6 -6
- package/dist/lib/config-file.js +33 -30
- package/dist/lib/config.d.ts +8 -8
- package/dist/lib/config.js +38 -30
- package/dist/lib/manifest.d.ts +3 -3
- package/dist/lib/manifest.js +44 -40
- package/dist/lib/media-args.d.ts +8 -6
- package/dist/lib/media-args.js +113 -94
- package/dist/lib/media-download.d.ts +9 -8
- package/dist/lib/media-download.js +158 -144
- package/dist/lib/media-poll.d.ts +8 -7
- package/dist/lib/media-poll.js +38 -32
- package/dist/lib/media-upload.d.ts +1 -1
- package/dist/lib/media-upload.js +30 -29
- package/dist/lib/output.d.ts +34 -11
- package/dist/lib/output.js +28 -20
- package/dist/lib/package-manager.d.ts +3 -3
- package/dist/lib/package-manager.js +27 -22
- package/dist/lib/run.d.ts +4 -4
- package/dist/lib/run.js +7 -4
- package/dist/lib/strict-args.d.ts +4 -4
- package/dist/lib/strict-args.js +29 -19
- package/dist/lib/types.d.ts +16 -2
- package/dist/lib/types.js +10 -4
- package/dist/lib/update.d.ts +4 -4
- package/dist/lib/update.js +47 -35
- package/dist/lib/upload.d.ts +4 -4
- package/dist/lib/upload.js +14 -9
- package/package.json +7 -8
package/dist/commands/new.js
CHANGED
|
@@ -1,135 +1,255 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import
|
|
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";
|
|
8
|
-
|
|
8
|
+
import { isJsonObject, isJsonString } from "../lib/types.js";
|
|
9
|
+
const ENGINES = new Map([
|
|
9
10
|
// phaserjs/template-vite-ts is the official Phaser 4 + Vite + TypeScript
|
|
10
11
|
// starter (despite the description still saying "Phaser 3" — package.json
|
|
11
12
|
// pins phaser@^4). Pulled fresh on each `vg new`.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
[
|
|
14
|
+
"phaser",
|
|
15
|
+
{
|
|
16
|
+
label: "Phaser 4 + Vite + TypeScript (official)",
|
|
17
|
+
postNotes: [
|
|
18
|
+
"The phaser template ships a `log.js` telemetry shim and uses `vite/config.*.mjs` for build configs — both are upstream, not vibedgames.",
|
|
19
|
+
],
|
|
20
|
+
repo: "phaserjs/template-vite-ts",
|
|
21
|
+
skill: "phaser",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
20
24
|
// No officially-blessed Three.js starter exists. Using the most-starred
|
|
21
25
|
// community Vite+TS starter that's been kept current.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
[
|
|
27
|
+
"threejs",
|
|
28
|
+
{
|
|
29
|
+
label: "Three.js + Vite + TypeScript (community)",
|
|
30
|
+
postNotes: [
|
|
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.",
|
|
32
|
+
],
|
|
33
|
+
repo: "pachoclo/vite-threejs-ts-template",
|
|
34
|
+
skill: "threejs",
|
|
35
|
+
},
|
|
36
|
+
],
|
|
30
37
|
// React Three Fiber. Same author as the threejs preset — Vite + TS +
|
|
31
38
|
// React 18 + R3F 8 + drei, with leva and r3f-perf wired up for debug.
|
|
32
39
|
// The pmndrs org doesn't ship an official R3F starter (its templates
|
|
33
40
|
// are all Next.js-based), and the highest-starred R3F template on
|
|
34
41
|
// GitHub is still on CRA + React 17, so this is the cleanest current
|
|
35
42
|
// option for an agent.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
[
|
|
44
|
+
"react-r3f",
|
|
45
|
+
{
|
|
46
|
+
label: "React + React Three Fiber + Vite + TypeScript (community)",
|
|
47
|
+
repo: "pachoclo/vite-r3f-ts-template",
|
|
48
|
+
skill: "threejs",
|
|
49
|
+
},
|
|
50
|
+
],
|
|
41
51
|
// Engine-agnostic fallback for "I'll wire it up myself" / non-canvas
|
|
42
52
|
// games. Stays inline so we don't get blocked on a network fetch when
|
|
43
53
|
// the user explicitly asked for a minimal start.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
[
|
|
55
|
+
"none",
|
|
56
|
+
{
|
|
57
|
+
inline: true,
|
|
58
|
+
label: "minimal Vite + TypeScript canvas",
|
|
59
|
+
skill: "deploy",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
]);
|
|
50
63
|
const NONE_FILES = [
|
|
51
64
|
{
|
|
52
|
-
path: "package.json",
|
|
53
65
|
content: (slug) => `${JSON.stringify({
|
|
66
|
+
devDependencies: { typescript: "^5.6.0", vite: "^7.0.0" },
|
|
54
67
|
name: slug,
|
|
55
|
-
version: "0.0.0",
|
|
56
68
|
private: true,
|
|
57
|
-
type: "module",
|
|
58
69
|
scripts: {
|
|
59
|
-
dev: "vite",
|
|
60
70
|
build: "vite build",
|
|
71
|
+
dev: "vite",
|
|
61
72
|
preview: "vite preview",
|
|
62
73
|
},
|
|
63
|
-
|
|
74
|
+
type: "module",
|
|
75
|
+
version: "0.0.0",
|
|
64
76
|
}, null, 2)}\n`,
|
|
77
|
+
path: "package.json",
|
|
65
78
|
},
|
|
66
79
|
{
|
|
67
|
-
path: "tsconfig.json",
|
|
68
80
|
content: () => `${JSON.stringify({
|
|
69
81
|
compilerOptions: {
|
|
70
|
-
|
|
82
|
+
esModuleInterop: true,
|
|
83
|
+
isolatedModules: true,
|
|
71
84
|
lib: ["ES2022", "DOM", "DOM.Iterable"],
|
|
72
85
|
module: "Preserve",
|
|
73
86
|
moduleResolution: "Bundler",
|
|
74
|
-
|
|
87
|
+
noEmit: true,
|
|
75
88
|
noUncheckedIndexedAccess: true,
|
|
76
|
-
isolatedModules: true,
|
|
77
|
-
esModuleInterop: true,
|
|
78
89
|
skipLibCheck: true,
|
|
79
|
-
|
|
90
|
+
strict: true,
|
|
91
|
+
target: "ES2022",
|
|
80
92
|
types: ["vite/client"],
|
|
81
93
|
},
|
|
82
94
|
include: ["src", "vite.config.ts"],
|
|
83
95
|
}, null, 2)}\n`,
|
|
96
|
+
path: "tsconfig.json",
|
|
84
97
|
},
|
|
85
98
|
{
|
|
86
|
-
path: "vite.config.ts",
|
|
87
99
|
content: () => `import { defineConfig } from "vite";\n\nexport default defineConfig({\n base: "./",\n server: { port: 5173 },\n});\n`,
|
|
100
|
+
path: "vite.config.ts",
|
|
88
101
|
},
|
|
89
102
|
{
|
|
90
|
-
path: "index.html",
|
|
91
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",
|
|
92
105
|
},
|
|
93
106
|
{
|
|
94
|
-
path: "src/main.ts",
|
|
95
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",
|
|
96
109
|
},
|
|
97
|
-
{
|
|
110
|
+
{ content: () => `node_modules\ndist\n.DS_Store\n`, path: ".gitignore" },
|
|
98
111
|
];
|
|
99
112
|
// Derived so `--help` and the error message can't drift from the presets again.
|
|
100
|
-
const ENGINE_IDS =
|
|
113
|
+
const ENGINE_IDS = [...ENGINES.keys()];
|
|
101
114
|
const newArgs = {
|
|
102
|
-
slug: {
|
|
103
|
-
type: "positional",
|
|
104
|
-
description: "Lowercase, hyphenated slug — used as the directory name and deploy subdomain.",
|
|
105
|
-
required: true,
|
|
106
|
-
},
|
|
107
115
|
engine: {
|
|
108
|
-
type: "string",
|
|
109
|
-
description: `Engine preset: ${ENGINE_IDS.join(", ")} (default: phaser).`,
|
|
110
116
|
default: "phaser",
|
|
111
|
-
|
|
112
|
-
template: {
|
|
117
|
+
description: `Engine preset: ${ENGINE_IDS.join(", ")} (default: phaser).`,
|
|
113
118
|
type: "string",
|
|
114
|
-
description: "Override the engine preset and fetch from an arbitrary degit spec (e.g. owner/repo, owner/repo#branch). Skips the engine preset entirely.",
|
|
115
|
-
},
|
|
116
|
-
here: {
|
|
117
|
-
type: "boolean",
|
|
118
|
-
description: "Write into the current directory instead of creating <slug>/.",
|
|
119
|
-
default: false,
|
|
120
119
|
},
|
|
121
120
|
force: {
|
|
122
|
-
|
|
121
|
+
default: false,
|
|
123
122
|
description: "Overwrite an existing target directory.",
|
|
123
|
+
type: "boolean",
|
|
124
|
+
},
|
|
125
|
+
here: {
|
|
124
126
|
default: false,
|
|
127
|
+
description: "Write into the current directory instead of creating <slug>/.",
|
|
128
|
+
type: "boolean",
|
|
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",
|
|
125
138
|
},
|
|
126
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}`);
|
|
246
|
+
};
|
|
127
247
|
export const newCommand = defineCommand({
|
|
248
|
+
args: newArgs,
|
|
128
249
|
meta: {
|
|
129
|
-
name: "new",
|
|
130
250
|
description: "Scaffold a new browser game. Pulls an engine template (phaser, threejs, react-r3f) or generates a minimal canvas starter.",
|
|
251
|
+
name: "new",
|
|
131
252
|
},
|
|
132
|
-
args: newArgs,
|
|
133
253
|
run: async ({ args, rawArgs }) => {
|
|
134
254
|
assertKnownFlags(rawArgs, newArgs);
|
|
135
255
|
const slug = args.slug.trim().toLowerCase();
|
|
@@ -139,16 +259,16 @@ export const newCommand = defineCommand({
|
|
|
139
259
|
}
|
|
140
260
|
const preset = args.template
|
|
141
261
|
? {
|
|
142
|
-
repo: args.template,
|
|
143
262
|
label: `custom: ${args.template}`,
|
|
263
|
+
repo: args.template,
|
|
144
264
|
skill: "deploy",
|
|
145
265
|
}
|
|
146
|
-
: ENGINES
|
|
266
|
+
: ENGINES.get(args.engine);
|
|
147
267
|
if (!preset) {
|
|
148
268
|
consola.error(`Unknown engine: ${args.engine}. Use one of: ${ENGINE_IDS.join(", ")}.`);
|
|
149
269
|
process.exit(1);
|
|
150
270
|
}
|
|
151
|
-
const target = args.here ? process.cwd() : resolve(process.cwd(), slug);
|
|
271
|
+
const target = args.here ? process.cwd() : path.resolve(process.cwd(), slug);
|
|
152
272
|
if (!args.here) {
|
|
153
273
|
if (existsSync(target) && !args.force) {
|
|
154
274
|
consola.error(`Directory ${target} already exists. Pass --force to overwrite, or pick a different slug.`);
|
|
@@ -164,8 +284,8 @@ export const newCommand = defineCommand({
|
|
|
164
284
|
try {
|
|
165
285
|
await fetchTemplate(preset.repo, target, args.force);
|
|
166
286
|
}
|
|
167
|
-
catch (
|
|
168
|
-
consola.error(`Failed to fetch template ${preset.repo}: ${
|
|
287
|
+
catch (error) {
|
|
288
|
+
consola.error(`Failed to fetch template ${preset.repo}: ${error instanceof Error ? error.message : String(error)}\n ` +
|
|
169
289
|
`Check your network connection, or pass --engine none to scaffold a minimal starter offline.`);
|
|
170
290
|
process.exit(1);
|
|
171
291
|
}
|
|
@@ -182,8 +302,9 @@ export const newCommand = defineCommand({
|
|
|
182
302
|
writeReadme(target, slug, preset);
|
|
183
303
|
consola.success(`Scaffolded ${slug} in ${target}`);
|
|
184
304
|
if ("postNotes" in preset && preset.postNotes) {
|
|
185
|
-
for (const n of preset.postNotes)
|
|
305
|
+
for (const n of preset.postNotes) {
|
|
186
306
|
consola.info(n);
|
|
307
|
+
}
|
|
187
308
|
}
|
|
188
309
|
consola.log("");
|
|
189
310
|
consola.info("Next steps:");
|
|
@@ -195,98 +316,3 @@ export const newCommand = defineCommand({
|
|
|
195
316
|
consola.log(`Skill to load for engine work: ${preset.skill} (Claude Code: triggered automatically by package.json deps)`);
|
|
196
317
|
},
|
|
197
318
|
});
|
|
198
|
-
async function fetchTemplate(repo, target, force) {
|
|
199
|
-
const emitter = tiged(repo, { force, verbose: false, mode: "tar" });
|
|
200
|
-
await emitter.clone(target);
|
|
201
|
-
}
|
|
202
|
-
/** Remove template-repo artifacts that never apply to a scaffolded game:
|
|
203
|
-
* the template's own lockfile (wrong for whatever package manager the user
|
|
204
|
-
* runs) and its CI workflows (reference the template repo, fail elsewhere). */
|
|
205
|
-
function cleanTemplateArtifacts(target) {
|
|
206
|
-
for (const f of ["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lockb", "bun.lock"]) {
|
|
207
|
-
const p = resolve(target, f);
|
|
208
|
-
if (existsSync(p))
|
|
209
|
-
rmSync(p);
|
|
210
|
-
}
|
|
211
|
-
const gh = resolve(target, ".github");
|
|
212
|
-
if (existsSync(gh))
|
|
213
|
-
rmSync(gh, { recursive: true });
|
|
214
|
-
}
|
|
215
|
-
/** Some templates (threejs) ship no vite config at all, which means no
|
|
216
|
-
* relative `base` — write a minimal one so built asset URLs are relative
|
|
217
|
-
* and the bundle works wherever it's hosted. Never touches templates that
|
|
218
|
-
* bring their own config (phaser uses a vite/ config dir wired into its
|
|
219
|
-
* npm scripts). */
|
|
220
|
-
function ensureViteConfig(target) {
|
|
221
|
-
const hasConfig = ["vite.config.ts", "vite.config.js", "vite.config.mjs"].some((f) => existsSync(resolve(target, f))) || existsSync(resolve(target, "vite"));
|
|
222
|
-
if (hasConfig)
|
|
223
|
-
return;
|
|
224
|
-
writeFileSync(resolve(target, "vite.config.ts"), `import { defineConfig } from "vite";\n\nexport default defineConfig({\n base: "./",\n});\n`);
|
|
225
|
-
}
|
|
226
|
-
/** Agents lean on \`npm run typecheck\` to verify changes without a full
|
|
227
|
-
* build — add it when the template doesn't define one. */
|
|
228
|
-
function ensureTypecheckScript(target) {
|
|
229
|
-
const pkgPath = resolve(target, "package.json");
|
|
230
|
-
if (!existsSync(pkgPath))
|
|
231
|
-
return;
|
|
232
|
-
try {
|
|
233
|
-
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
234
|
-
const scripts = typeof pkg.scripts === "object" && pkg.scripts !== null
|
|
235
|
-
? pkg.scripts
|
|
236
|
-
: {};
|
|
237
|
-
if (typeof scripts.typecheck === "string")
|
|
238
|
-
return;
|
|
239
|
-
scripts.typecheck = "tsc --noEmit";
|
|
240
|
-
pkg.scripts = scripts;
|
|
241
|
-
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
242
|
-
}
|
|
243
|
-
catch {
|
|
244
|
-
// malformed package.json — rewritePackageName will warn about it
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
function writeInlineTemplate(target, slug, force) {
|
|
248
|
-
for (const file of NONE_FILES) {
|
|
249
|
-
const path = resolve(target, file.path);
|
|
250
|
-
if (existsSync(path) && !force)
|
|
251
|
-
continue;
|
|
252
|
-
mkdirSync(path.slice(0, path.lastIndexOf("/")), { recursive: true });
|
|
253
|
-
writeFileSync(path, file.content(slug));
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
function rewritePackageName(target, slug) {
|
|
257
|
-
const pkgPath = resolve(target, "package.json");
|
|
258
|
-
if (!existsSync(pkgPath))
|
|
259
|
-
return;
|
|
260
|
-
try {
|
|
261
|
-
const raw = readFileSync(pkgPath, "utf8");
|
|
262
|
-
const pkg = JSON.parse(raw);
|
|
263
|
-
pkg.name = slug;
|
|
264
|
-
delete pkg.repository;
|
|
265
|
-
delete pkg.bugs;
|
|
266
|
-
delete pkg.homepage;
|
|
267
|
-
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
268
|
-
}
|
|
269
|
-
catch (err) {
|
|
270
|
-
consola.warn(`Could not rewrite package.json name to ${slug}: ${err instanceof Error ? err.message : String(err)}`);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
function writeVibedgamesJson(target, slug) {
|
|
274
|
-
writeFileSync(resolve(target, "vibedgames.json"), `${JSON.stringify({ slug, name: slug.replace(/-/g, " ") }, null, 2)}\n`);
|
|
275
|
-
}
|
|
276
|
-
function writeReadme(target, slug, preset) {
|
|
277
|
-
const readmePath = resolve(target, "README.md");
|
|
278
|
-
// Keep the template's README if present (it usually has engine docs).
|
|
279
|
-
// Append a vibedgames-specific footer so devs see the deploy flow.
|
|
280
|
-
const footer = `\n\n---\n\n## Vibedgames\n\n` +
|
|
281
|
-
`This project was scaffolded with \`vg new ${slug}\` (${preset.label}).\n\n` +
|
|
282
|
-
`\`\`\`sh\nnpm install\nnpm run dev # local preview\nnpm run build\nvg deploy ./dist # ships to ${slug}.vibedgames.com\n\`\`\`\n\n` +
|
|
283
|
-
`For engine-specific work, the \`${preset.skill}\` skill loads automatically in Claude Code.\n`;
|
|
284
|
-
if (existsSync(readmePath)) {
|
|
285
|
-
const existing = readFileSync(readmePath, "utf8");
|
|
286
|
-
if (existing.includes("## Vibedgames"))
|
|
287
|
-
return;
|
|
288
|
-
writeFileSync(readmePath, existing.replace(/\s*$/, "") + footer);
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
writeFileSync(readmePath, `# ${slug}${footer}`);
|
|
292
|
-
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* staging rather than silently hitting production the way a hardcoded apex
|
|
5
5
|
* would. Mirrors the derivation the deploy router does server-side.
|
|
6
6
|
*/
|
|
7
|
-
declare
|
|
7
|
+
declare const resolveGameUrl: (slug: string | null) => string;
|
|
8
8
|
/**
|
|
9
9
|
* The tokens in `args` that aren't flags or flag values — agent-browser's verb
|
|
10
10
|
* and its positional arguments, in order.
|
|
@@ -21,8 +21,8 @@ declare function resolveGameUrl(slug: string | null): string;
|
|
|
21
21
|
* a grammar that moves every release. This catches the shapes people actually
|
|
22
22
|
* type; anything past it reaches agent-browser as before.
|
|
23
23
|
*/
|
|
24
|
-
export declare
|
|
25
|
-
export declare
|
|
24
|
+
export declare const bareTokens: (args: string[]) => string[];
|
|
25
|
+
export declare const expandGameFlag: (args: string[], resolveUrl?: typeof resolveGameUrl) => string[];
|
|
26
26
|
/**
|
|
27
27
|
* agent-browser's session defaults to the literal name `default`, which is
|
|
28
28
|
* shared by every caller on the machine. Two `vg playtest` runs — two projects
|
|
@@ -34,8 +34,8 @@ export declare function expandGameFlag(args: string[], resolveUrl?: typeof resol
|
|
|
34
34
|
* environment, or is asking about sessions themselves (`session list` must see
|
|
35
35
|
* every session, not just this project's).
|
|
36
36
|
*/
|
|
37
|
-
export declare
|
|
37
|
+
export declare const withScopedSession: (args: string[], sessionId: () => string) => string[];
|
|
38
38
|
/** Resolve (installing on first use) and exec agent-browser. Never returns. */
|
|
39
|
-
export declare
|
|
39
|
+
export declare const runPlaytest: (rawArgs: string[]) => never;
|
|
40
40
|
export declare const playtestCommand: import("citty").CommandDef<import("citty").ArgsDef>;
|
|
41
41
|
export {};
|