vibedgames 0.6.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -9
- package/dist/THIRD_PARTY_NOTICES.txt +383 -0
- package/dist/chunk-2GL2WJZX.js +172 -0
- package/dist/chunk-2QBYTIMH.js +511 -0
- package/dist/chunk-34AHIMX7.js +466 -0
- package/dist/chunk-6FZPPUQH.js +107 -0
- package/dist/chunk-BVVYDSFJ.js +99 -0
- package/dist/chunk-CAKBGDCY.js +47 -0
- package/dist/chunk-CBKOPVU6.js +1780 -0
- package/dist/chunk-CU7UY5YJ.js +1108 -0
- package/dist/chunk-CZPKN32Z.js +257 -0
- package/dist/chunk-DHEXGWJY.js +111 -0
- package/dist/chunk-FL6IFBUF.js +22 -0
- package/dist/chunk-FLUXEHMU.js +1360 -0
- package/dist/chunk-FNYBZNW2.js +165 -0
- package/dist/chunk-G5FRIFA3.js +22 -0
- package/dist/chunk-HCMTSR7E.js +69 -0
- package/dist/chunk-HKA5LBYW.js +159 -0
- package/dist/chunk-I6O4HIDY.js +1063 -0
- package/dist/chunk-J6PKNPI2.js +26 -0
- package/dist/chunk-JT2AU24K.js +759 -0
- package/dist/chunk-MBXCVCC4.js +478 -0
- package/dist/chunk-MJQSHP3Y.js +415 -0
- package/dist/chunk-MYFLYNPO.js +68 -0
- package/dist/chunk-PEUP4MZR.js +59 -0
- package/dist/chunk-PHEDW6C7.js +32 -0
- package/dist/chunk-PQDBCZRT.js +2017 -0
- package/dist/chunk-QGEITHUP.js +395 -0
- package/dist/chunk-QIVCBUYD.js +273 -0
- package/dist/chunk-RYFO3ZPO.js +71 -0
- package/dist/chunk-RZ4DIJQW.js +68 -0
- package/dist/chunk-SAANBZ25.js +118 -0
- package/dist/chunk-VFFOT7KD.js +2980 -0
- package/dist/chunk-Y552BNFZ.js +41 -0
- package/dist/chunk-Z4Z24FWO.js +39 -0
- package/dist/chunk-ZI6PKVXG.js +64 -0
- package/dist/chunk-ZYCSYJWX.js +87 -0
- package/dist/index.js +67 -60
- package/package.json +13 -16
- package/templates/none/_gitignore +3 -0
- package/templates/none/index.html +29 -0
- package/templates/none/package.json +16 -0
- package/templates/none/src/main.ts +16 -0
- package/templates/none/tsconfig.json +18 -0
- package/templates/none/vite.config.ts +8 -0
- package/templates/phaser/_gitignore +3 -0
- package/templates/phaser/index.html +24 -0
- package/templates/phaser/package.json +19 -0
- package/templates/phaser/src/main.ts +16 -0
- package/templates/phaser/src/scenes/game-scene.ts +65 -0
- package/templates/phaser/tsconfig.json +18 -0
- package/templates/phaser/vite.config.ts +8 -0
- package/templates/react-r3f/_gitignore +3 -0
- package/templates/react-r3f/index.html +24 -0
- package/templates/react-r3f/package.json +27 -0
- package/templates/react-r3f/src/app.tsx +33 -0
- package/templates/react-r3f/src/main.tsx +15 -0
- package/templates/react-r3f/tsconfig.json +19 -0
- package/templates/react-r3f/vite.config.ts +10 -0
- package/templates/threejs/_gitignore +3 -0
- package/templates/threejs/index.html +36 -0
- package/templates/threejs/package.json +20 -0
- package/templates/threejs/src/main.ts +44 -0
- package/templates/threejs/tsconfig.json +18 -0
- package/templates/threejs/vite.config.ts +8 -0
- package/dist/commands/completions.d.ts +0 -7
- package/dist/commands/completions.js +0 -145
- package/dist/commands/credits.d.ts +0 -10
- package/dist/commands/credits.js +0 -136
- package/dist/commands/deploy.d.ts +0 -26
- package/dist/commands/deploy.js +0 -257
- package/dist/commands/factory.d.ts +0 -3
- package/dist/commands/factory.js +0 -73
- package/dist/commands/fork.d.ts +0 -29
- package/dist/commands/fork.js +0 -124
- package/dist/commands/generate.d.ts +0 -1
- package/dist/commands/generate.js +0 -565
- package/dist/commands/init.d.ts +0 -20
- package/dist/commands/init.js +0 -105
- package/dist/commands/login.d.ts +0 -1
- package/dist/commands/login.js +0 -45
- package/dist/commands/logout.d.ts +0 -1
- package/dist/commands/logout.js +0 -13
- package/dist/commands/new.d.ts +0 -26
- package/dist/commands/new.js +0 -318
- package/dist/commands/playtest-run.d.ts +0 -66
- package/dist/commands/playtest-run.js +0 -268
- package/dist/commands/playtest.d.ts +0 -76
- package/dist/commands/playtest.js +0 -372
- package/dist/commands/update.d.ts +0 -13
- package/dist/commands/update.js +0 -82
- package/dist/commands/whoami.d.ts +0 -10
- package/dist/commands/whoami.js +0 -44
- package/dist/index.d.ts +0 -2
- package/dist/lib/api.d.ts +0 -18
- package/dist/lib/api.js +0 -27
- package/dist/lib/archive.d.ts +0 -17
- package/dist/lib/archive.js +0 -228
- package/dist/lib/codex.d.ts +0 -117
- package/dist/lib/codex.js +0 -426
- package/dist/lib/config-file.d.ts +0 -16
- package/dist/lib/config-file.js +0 -54
- package/dist/lib/config.d.ts +0 -11
- package/dist/lib/config.js +0 -54
- package/dist/lib/manifest.d.ts +0 -10
- package/dist/lib/manifest.js +0 -91
- package/dist/lib/media-args.d.ts +0 -30
- package/dist/lib/media-args.js +0 -219
- package/dist/lib/media-download.d.ts +0 -37
- package/dist/lib/media-download.js +0 -268
- package/dist/lib/media-poll.d.ts +0 -18
- package/dist/lib/media-poll.js +0 -86
- package/dist/lib/media-upload.d.ts +0 -12
- package/dist/lib/media-upload.js +0 -52
- package/dist/lib/output.d.ts +0 -68
- package/dist/lib/output.js +0 -102
- package/dist/lib/package-manager.d.ts +0 -25
- package/dist/lib/package-manager.js +0 -77
- package/dist/lib/playtest/agent.d.ts +0 -192
- package/dist/lib/playtest/agent.js +0 -652
- package/dist/lib/playtest/browser.d.ts +0 -109
- package/dist/lib/playtest/browser.js +0 -219
- package/dist/lib/playtest/controls.d.ts +0 -47
- package/dist/lib/playtest/controls.js +0 -218
- package/dist/lib/playtest/errors.d.ts +0 -9
- package/dist/lib/playtest/errors.js +0 -12
- package/dist/lib/playtest/keys.d.ts +0 -41
- package/dist/lib/playtest/keys.js +0 -157
- package/dist/lib/playtest/run.d.ts +0 -195
- package/dist/lib/playtest/run.js +0 -409
- package/dist/lib/run.d.ts +0 -19
- package/dist/lib/run.js +0 -23
- package/dist/lib/strict-args.d.ts +0 -27
- package/dist/lib/strict-args.js +0 -78
- package/dist/lib/types.d.ts +0 -16
- package/dist/lib/types.js +0 -10
- package/dist/lib/update.d.ts +0 -10
- package/dist/lib/update.js +0 -110
- package/dist/lib/upload.d.ts +0 -16
- package/dist/lib/upload.js +0 -41
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "node:module";
|
|
2
|
+
import { dirname as __pathDirname } from "node:path";
|
|
3
|
+
import { fileURLToPath as __fileURLToPath } from "node:url";
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __pathDirname(__filename);
|
|
7
|
+
import {
|
|
8
|
+
So
|
|
9
|
+
} from "./chunk-VFFOT7KD.js";
|
|
10
|
+
import {
|
|
11
|
+
SLUG_RE
|
|
12
|
+
} from "./chunk-ZI6PKVXG.js";
|
|
13
|
+
import {
|
|
14
|
+
PACKAGE_ROOT
|
|
15
|
+
} from "./chunk-Z4Z24FWO.js";
|
|
16
|
+
import "./chunk-PEUP4MZR.js";
|
|
17
|
+
import {
|
|
18
|
+
assertKnownFlags
|
|
19
|
+
} from "./chunk-RZ4DIJQW.js";
|
|
20
|
+
import {
|
|
21
|
+
consola
|
|
22
|
+
} from "./chunk-CU7UY5YJ.js";
|
|
23
|
+
import {
|
|
24
|
+
isJsonObject,
|
|
25
|
+
isJsonString
|
|
26
|
+
} from "./chunk-J6PKNPI2.js";
|
|
27
|
+
import {
|
|
28
|
+
defineCommand
|
|
29
|
+
} from "./chunk-MBXCVCC4.js";
|
|
30
|
+
import "./chunk-CAKBGDCY.js";
|
|
31
|
+
|
|
32
|
+
// src/commands/new.ts
|
|
33
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
34
|
+
import path2 from "node:path";
|
|
35
|
+
|
|
36
|
+
// src/lib/template-source.ts
|
|
37
|
+
import { once } from "node:events";
|
|
38
|
+
import { readdirSync } from "node:fs";
|
|
39
|
+
var REPO_PREFIXES = ["github:", "https://github.com/", "http://github.com/", "git@github.com:"];
|
|
40
|
+
var OTHER_HOSTS = /^(?:gitlab|bitbucket|sourcehut|codeberg):|^(?:https?:\/\/|git@)(?!github\.com[/:])/u;
|
|
41
|
+
var OWNER = /^[A-Za-z\d](?:[A-Za-z\d-]*[A-Za-z\d])?$/u;
|
|
42
|
+
var NAME = /^[\w.-]+$/u;
|
|
43
|
+
var SPEC_FORMS = "owner/repo, owner/repo/sub/dir or owner/repo#ref";
|
|
44
|
+
var parseTemplateSpec = (spec) => {
|
|
45
|
+
const trimmed = spec.trim();
|
|
46
|
+
const hashAt = trimmed.indexOf("#");
|
|
47
|
+
const location = hashAt === -1 ? trimmed : trimmed.slice(0, hashAt);
|
|
48
|
+
const ref = hashAt === -1 ? "HEAD" : trimmed.slice(hashAt + 1);
|
|
49
|
+
if (OTHER_HOSTS.test(location)) {
|
|
50
|
+
throw new Error(`Only GitHub templates are supported: ${SPEC_FORMS}.`);
|
|
51
|
+
}
|
|
52
|
+
const prefix = REPO_PREFIXES.find((candidate) => location.startsWith(candidate)) ?? "";
|
|
53
|
+
const [owner = "", repoSegment = "", ...subdir] = location.slice(prefix.length).replace(/\/+$/u, "").split("/");
|
|
54
|
+
const repo = repoSegment.replace(/\.git$/u, "");
|
|
55
|
+
if (!OWNER.test(owner) || !NAME.test(repo) || subdir.some((part) => !NAME.test(part) || part === "." || part === "..") || !ref || /\s/u.test(ref)) {
|
|
56
|
+
throw new Error(`"${spec}" is not a GitHub template spec. Use ${SPEC_FORMS}.`);
|
|
57
|
+
}
|
|
58
|
+
return { owner, ref, repo, subdir: subdir.join("/") };
|
|
59
|
+
};
|
|
60
|
+
var templateTarballUrl = ({ owner, repo, ref }) => `https://codeload.github.com/${owner}/${repo}/tar.gz/${ref.split("/").map(encodeURIComponent).join("/")}`;
|
|
61
|
+
var fetchTemplate = async (template, target, force, fetchImpl = fetch) => {
|
|
62
|
+
if (!force && readdirSync(target).length > 0) {
|
|
63
|
+
throw new Error(`${target} is not empty. Pass --force to scaffold into it anyway.`);
|
|
64
|
+
}
|
|
65
|
+
const url = templateTarballUrl(template);
|
|
66
|
+
const res = await fetchImpl(url, { signal: AbortSignal.timeout(12e4) });
|
|
67
|
+
if (res.status === 404) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`GitHub has no ${template.owner}/${template.repo} at ${template.ref} (or the repo is private).`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
if (!res.ok) {
|
|
73
|
+
throw new Error(`Couldn't download ${url}: HTTP ${res.status}.`);
|
|
74
|
+
}
|
|
75
|
+
const tarball = Buffer.from(await res.arrayBuffer());
|
|
76
|
+
const prefix = template.subdir ? template.subdir.split("/") : [];
|
|
77
|
+
let unpacked = 0;
|
|
78
|
+
const unpack = So({
|
|
79
|
+
cwd: target,
|
|
80
|
+
filter: (entryPath) => {
|
|
81
|
+
const parts = entryPath.split("/").slice(1);
|
|
82
|
+
const inside = parts.length > prefix.length && prefix.every((part, index) => parts[index] === part);
|
|
83
|
+
if (inside) {
|
|
84
|
+
unpacked += 1;
|
|
85
|
+
}
|
|
86
|
+
return inside;
|
|
87
|
+
},
|
|
88
|
+
strip: 1 + prefix.length
|
|
89
|
+
});
|
|
90
|
+
const closed = once(unpack, "close");
|
|
91
|
+
unpack.end(tarball);
|
|
92
|
+
await closed;
|
|
93
|
+
if (unpacked === 0) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
template.subdir ? `${template.owner}/${template.repo} has no directory ${template.subdir} at ${template.ref}.` : `${template.owner}/${template.repo} at ${template.ref} has no files.`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/lib/templates.ts
|
|
101
|
+
import {
|
|
102
|
+
copyFileSync,
|
|
103
|
+
existsSync,
|
|
104
|
+
mkdirSync,
|
|
105
|
+
readdirSync as readdirSync2,
|
|
106
|
+
readFileSync,
|
|
107
|
+
writeFileSync
|
|
108
|
+
} from "node:fs";
|
|
109
|
+
import path from "node:path";
|
|
110
|
+
var TEMPLATES_DIR = path.join(PACKAGE_ROOT, "templates");
|
|
111
|
+
var SLUG_TOKEN = "__VG_SLUG__";
|
|
112
|
+
var TEXT_EXTENSIONS = /* @__PURE__ */ new Set([".css", ".html", ".json", ".md", ".ts", ".tsx"]);
|
|
113
|
+
var SKIPPED_ENTRIES = /* @__PURE__ */ new Set([".turbo", "dist", "node_modules"]);
|
|
114
|
+
var GITIGNORE_STAND_IN = "_gitignore";
|
|
115
|
+
var copyTemplate = (template, target, slug, force, templatesDir = TEMPLATES_DIR) => {
|
|
116
|
+
const root = path.join(templatesDir, template);
|
|
117
|
+
if (!existsSync(root)) {
|
|
118
|
+
throw new Error(`No bundled template named "${template}" in ${templatesDir}.`);
|
|
119
|
+
}
|
|
120
|
+
const kept = [];
|
|
121
|
+
const walk = (from, relative) => {
|
|
122
|
+
for (const entry of readdirSync2(from, { withFileTypes: true })) {
|
|
123
|
+
if (SKIPPED_ENTRIES.has(entry.name)) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const source = path.join(from, entry.name);
|
|
127
|
+
const name = entry.name === GITIGNORE_STAND_IN ? ".gitignore" : entry.name;
|
|
128
|
+
const relativePath = path.join(relative, name);
|
|
129
|
+
if (entry.isDirectory()) {
|
|
130
|
+
walk(source, relativePath);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const destination = path.join(target, relativePath);
|
|
134
|
+
if (existsSync(destination) && !force) {
|
|
135
|
+
kept.push(relativePath);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
mkdirSync(path.dirname(destination), { recursive: true });
|
|
139
|
+
if (TEXT_EXTENSIONS.has(path.extname(name))) {
|
|
140
|
+
writeFileSync(destination, readFileSync(source, "utf-8").replaceAll(SLUG_TOKEN, slug));
|
|
141
|
+
} else {
|
|
142
|
+
copyFileSync(source, destination);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
walk(root, "");
|
|
147
|
+
return kept;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// src/commands/new.ts
|
|
151
|
+
var ENGINES = /* @__PURE__ */ new Map([
|
|
152
|
+
[
|
|
153
|
+
"phaser",
|
|
154
|
+
{ kind: "bundled", label: "Phaser 4 + Vite + TypeScript", skill: "phaser", template: "phaser" }
|
|
155
|
+
],
|
|
156
|
+
[
|
|
157
|
+
"threejs",
|
|
158
|
+
{
|
|
159
|
+
kind: "bundled",
|
|
160
|
+
label: "Three.js + Vite + TypeScript",
|
|
161
|
+
skill: "threejs",
|
|
162
|
+
template: "threejs"
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
[
|
|
166
|
+
"react-r3f",
|
|
167
|
+
{
|
|
168
|
+
kind: "bundled",
|
|
169
|
+
label: "React Three Fiber + drei + Vite + TypeScript",
|
|
170
|
+
skill: "threejs",
|
|
171
|
+
template: "react-r3f"
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
[
|
|
175
|
+
"none",
|
|
176
|
+
{
|
|
177
|
+
kind: "bundled",
|
|
178
|
+
label: "minimal Vite + TypeScript canvas",
|
|
179
|
+
skill: "deploy",
|
|
180
|
+
template: "none"
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
]);
|
|
184
|
+
var ENGINE_IDS = [...ENGINES.keys()];
|
|
185
|
+
var newArgs = {
|
|
186
|
+
engine: {
|
|
187
|
+
default: "phaser",
|
|
188
|
+
description: `Engine preset: ${ENGINE_IDS.join(", ")} (default: phaser).`,
|
|
189
|
+
type: "string"
|
|
190
|
+
},
|
|
191
|
+
force: {
|
|
192
|
+
default: false,
|
|
193
|
+
description: "Overwrite an existing target directory.",
|
|
194
|
+
type: "boolean"
|
|
195
|
+
},
|
|
196
|
+
here: {
|
|
197
|
+
default: false,
|
|
198
|
+
description: "Write into the current directory instead of creating <slug>/.",
|
|
199
|
+
type: "boolean"
|
|
200
|
+
},
|
|
201
|
+
slug: {
|
|
202
|
+
description: "Lowercase, hyphenated slug \u2014 used as the directory name and deploy subdomain.",
|
|
203
|
+
required: true,
|
|
204
|
+
type: "positional"
|
|
205
|
+
},
|
|
206
|
+
template: {
|
|
207
|
+
description: "Fetch a third-party template from GitHub instead of a bundled preset: owner/repo, owner/repo/sub/dir, either with #branch, #tag or #commit. Needs network; not maintained by vibedgames.",
|
|
208
|
+
type: "string"
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var cleanTemplateArtifacts = (target) => {
|
|
212
|
+
for (const f of ["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lockb", "bun.lock"]) {
|
|
213
|
+
const p = path2.resolve(target, f);
|
|
214
|
+
if (existsSync2(p)) {
|
|
215
|
+
rmSync(p);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const gh = path2.resolve(target, ".github");
|
|
219
|
+
if (existsSync2(gh)) {
|
|
220
|
+
rmSync(gh, { recursive: true });
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
var ensureViteConfig = (target) => {
|
|
224
|
+
const hasConfig = ["vite.config.ts", "vite.config.js", "vite.config.mjs"].some(
|
|
225
|
+
(f) => existsSync2(path2.resolve(target, f))
|
|
226
|
+
) || existsSync2(path2.resolve(target, "vite"));
|
|
227
|
+
if (hasConfig) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
writeFileSync2(
|
|
231
|
+
path2.resolve(target, "vite.config.ts"),
|
|
232
|
+
`import { defineConfig } from "vite";
|
|
233
|
+
|
|
234
|
+
export default defineConfig({
|
|
235
|
+
base: "./",
|
|
236
|
+
});
|
|
237
|
+
`
|
|
238
|
+
);
|
|
239
|
+
};
|
|
240
|
+
var ensureTypecheckScript = (target) => {
|
|
241
|
+
const pkgPath = path2.resolve(target, "package.json");
|
|
242
|
+
if (!existsSync2(pkgPath)) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
const pkg = JSON.parse(readFileSync2(pkgPath, "utf-8"));
|
|
247
|
+
if (!isJsonObject(pkg)) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const scripts = isJsonObject(pkg.scripts) ? pkg.scripts : {};
|
|
251
|
+
if (isJsonString(scripts.typecheck)) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
scripts.typecheck = "tsc --noEmit";
|
|
255
|
+
pkg.scripts = scripts;
|
|
256
|
+
writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
257
|
+
`);
|
|
258
|
+
} catch {
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
var rewritePackageName = (target, slug) => {
|
|
262
|
+
const pkgPath = path2.resolve(target, "package.json");
|
|
263
|
+
if (!existsSync2(pkgPath)) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
const raw = readFileSync2(pkgPath, "utf-8");
|
|
268
|
+
const pkg = JSON.parse(raw);
|
|
269
|
+
if (!isJsonObject(pkg)) {
|
|
270
|
+
throw new Error("package.json is not a JSON object");
|
|
271
|
+
}
|
|
272
|
+
pkg.name = slug;
|
|
273
|
+
delete pkg.repository;
|
|
274
|
+
delete pkg.bugs;
|
|
275
|
+
delete pkg.homepage;
|
|
276
|
+
writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
277
|
+
`);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
consola.warn(
|
|
280
|
+
`Could not rewrite package.json name to ${slug}: ${error instanceof Error ? error.message : String(error)}`
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
var writeVibedgamesJson = (target, slug) => {
|
|
285
|
+
writeFileSync2(
|
|
286
|
+
path2.resolve(target, "vibedgames.json"),
|
|
287
|
+
`${JSON.stringify({ name: slug.replaceAll("-", " "), slug }, null, 2)}
|
|
288
|
+
`
|
|
289
|
+
);
|
|
290
|
+
};
|
|
291
|
+
var writeReadme = (target, slug, preset) => {
|
|
292
|
+
const readmePath = path2.resolve(target, "README.md");
|
|
293
|
+
const footer = `
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## Vibedgames
|
|
298
|
+
|
|
299
|
+
This project was scaffolded with \`vg new ${slug}\` (${preset.label}).
|
|
300
|
+
|
|
301
|
+
\`\`\`sh
|
|
302
|
+
npm install
|
|
303
|
+
npm run dev # local preview
|
|
304
|
+
npm run build
|
|
305
|
+
vg deploy ./dist # ships to ${slug}.vibedgames.com
|
|
306
|
+
\`\`\`
|
|
307
|
+
|
|
308
|
+
For engine-specific work, the \`${preset.skill}\` skill loads automatically in Claude Code.
|
|
309
|
+
`;
|
|
310
|
+
if (existsSync2(readmePath)) {
|
|
311
|
+
const existing = readFileSync2(readmePath, "utf-8");
|
|
312
|
+
if (existing.includes("## Vibedgames")) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
writeFileSync2(readmePath, existing.replace(/\s*$/u, "") + footer);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
writeFileSync2(readmePath, `# ${slug}${footer}`);
|
|
319
|
+
};
|
|
320
|
+
var newCommand = defineCommand({
|
|
321
|
+
args: newArgs,
|
|
322
|
+
meta: {
|
|
323
|
+
description: "Scaffold a new browser game from a template bundled with the CLI (phaser, threejs, react-r3f, none). Works offline.",
|
|
324
|
+
name: "new"
|
|
325
|
+
},
|
|
326
|
+
run: async ({ args, rawArgs }) => {
|
|
327
|
+
assertKnownFlags(rawArgs, newArgs);
|
|
328
|
+
const slug = args.slug.trim().toLowerCase();
|
|
329
|
+
if (!SLUG_RE.test(slug)) {
|
|
330
|
+
consola.error(
|
|
331
|
+
`Invalid slug: ${args.slug}
|
|
332
|
+
Use lowercase letters, digits, and hyphens (e.g. "asteroid-belt").`
|
|
333
|
+
);
|
|
334
|
+
process.exit(1);
|
|
335
|
+
}
|
|
336
|
+
let template;
|
|
337
|
+
try {
|
|
338
|
+
template = args.template ? parseTemplateSpec(args.template) : void 0;
|
|
339
|
+
} catch (error) {
|
|
340
|
+
consola.error(error instanceof Error ? error.message : String(error));
|
|
341
|
+
process.exit(1);
|
|
342
|
+
}
|
|
343
|
+
const preset = template ? { kind: "remote", label: `custom: ${args.template}`, skill: "deploy", template } : ENGINES.get(args.engine);
|
|
344
|
+
if (!preset) {
|
|
345
|
+
consola.error(`Unknown engine: ${args.engine}. Use one of: ${ENGINE_IDS.join(", ")}.`);
|
|
346
|
+
process.exit(1);
|
|
347
|
+
}
|
|
348
|
+
const target = args.here ? process.cwd() : path2.resolve(process.cwd(), slug);
|
|
349
|
+
if (!args.here) {
|
|
350
|
+
if (existsSync2(target) && !args.force) {
|
|
351
|
+
consola.error(
|
|
352
|
+
`Directory ${target} already exists. Pass --force to overwrite, or pick a different slug.`
|
|
353
|
+
);
|
|
354
|
+
process.exit(1);
|
|
355
|
+
}
|
|
356
|
+
mkdirSync2(target, { recursive: true });
|
|
357
|
+
}
|
|
358
|
+
consola.start(`Scaffolding ${slug} with ${preset.label}`);
|
|
359
|
+
if (preset.kind === "bundled") {
|
|
360
|
+
for (const file of copyTemplate(preset.template, target, slug, args.force)) {
|
|
361
|
+
consola.warn(`Kept the existing ${file} (pass --force to overwrite it).`);
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
try {
|
|
365
|
+
await fetchTemplate(preset.template, target, args.force);
|
|
366
|
+
} catch (error) {
|
|
367
|
+
consola.error(
|
|
368
|
+
`Failed to fetch template ${args.template}: ${error instanceof Error ? error.message : String(error)}
|
|
369
|
+
Check your network connection, or drop --template to use a bundled engine preset.`
|
|
370
|
+
);
|
|
371
|
+
process.exit(1);
|
|
372
|
+
}
|
|
373
|
+
cleanTemplateArtifacts(target);
|
|
374
|
+
ensureViteConfig(target);
|
|
375
|
+
ensureTypecheckScript(target);
|
|
376
|
+
}
|
|
377
|
+
rewritePackageName(target, slug);
|
|
378
|
+
writeVibedgamesJson(target, slug);
|
|
379
|
+
writeReadme(target, slug, preset);
|
|
380
|
+
consola.success(`Scaffolded ${slug} in ${target}`);
|
|
381
|
+
consola.log("");
|
|
382
|
+
consola.info("Next steps:");
|
|
383
|
+
consola.log(` cd ${args.here ? "." : slug}`);
|
|
384
|
+
consola.log(" npm install");
|
|
385
|
+
consola.log(" npm run dev");
|
|
386
|
+
consola.log(" # then: npm run build && vg deploy ./dist");
|
|
387
|
+
consola.log("");
|
|
388
|
+
consola.log(
|
|
389
|
+
`Skill to load for engine work: ${preset.skill} (Claude Code: triggered automatically by package.json deps)`
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
export {
|
|
394
|
+
newCommand
|
|
395
|
+
};
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "node:module";
|
|
2
|
+
import { dirname as __pathDirname } from "node:path";
|
|
3
|
+
import { fileURLToPath as __fileURLToPath } from "node:url";
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __pathDirname(__filename);
|
|
7
|
+
import {
|
|
8
|
+
authErrorCode,
|
|
9
|
+
createClient
|
|
10
|
+
} from "./chunk-PQDBCZRT.js";
|
|
11
|
+
import "./chunk-Z4Z24FWO.js";
|
|
12
|
+
import "./chunk-PEUP4MZR.js";
|
|
13
|
+
import {
|
|
14
|
+
outputArgs,
|
|
15
|
+
writeStructured
|
|
16
|
+
} from "./chunk-ZYCSYJWX.js";
|
|
17
|
+
import {
|
|
18
|
+
assertKnownFlags
|
|
19
|
+
} from "./chunk-RZ4DIJQW.js";
|
|
20
|
+
import {
|
|
21
|
+
getToken
|
|
22
|
+
} from "./chunk-RYFO3ZPO.js";
|
|
23
|
+
import {
|
|
24
|
+
consola
|
|
25
|
+
} from "./chunk-CU7UY5YJ.js";
|
|
26
|
+
import "./chunk-J6PKNPI2.js";
|
|
27
|
+
import {
|
|
28
|
+
defineCommand
|
|
29
|
+
} from "./chunk-MBXCVCC4.js";
|
|
30
|
+
import "./chunk-CAKBGDCY.js";
|
|
31
|
+
|
|
32
|
+
// src/commands/credits.ts
|
|
33
|
+
var creditsArgs = { ...outputArgs };
|
|
34
|
+
var MICRO_PER_USD = 1e6;
|
|
35
|
+
var SUB_CENT_MICRO = MICRO_PER_USD / 100;
|
|
36
|
+
var MAX_ENTRIES_SHOWN = 15;
|
|
37
|
+
var MIN_PURCHASE_USD = 5;
|
|
38
|
+
var MAX_PURCHASE_USD = 500;
|
|
39
|
+
var formatUsd = (micro) => {
|
|
40
|
+
const abs = Math.abs(micro);
|
|
41
|
+
const decimals = abs > 0 && abs < SUB_CENT_MICRO ? 4 : 2;
|
|
42
|
+
const base = `$${(abs / MICRO_PER_USD).toFixed(decimals)}`;
|
|
43
|
+
return micro < 0 ? `-${base}` : base;
|
|
44
|
+
};
|
|
45
|
+
var formatSignedUsd = (micro) => micro < 0 ? formatUsd(micro) : `+${formatUsd(micro)}`;
|
|
46
|
+
var kindLabel = (kind, deltaMicro) => {
|
|
47
|
+
switch (kind) {
|
|
48
|
+
case "signup_grant": {
|
|
49
|
+
return "Welcome credits";
|
|
50
|
+
}
|
|
51
|
+
case "admin_grant": {
|
|
52
|
+
return deltaMicro < 0 ? "Adjustment" : "Credit grant";
|
|
53
|
+
}
|
|
54
|
+
case "code_redeem": {
|
|
55
|
+
return "Code redeemed";
|
|
56
|
+
}
|
|
57
|
+
case "purchase": {
|
|
58
|
+
return "Credit purchase";
|
|
59
|
+
}
|
|
60
|
+
case "generation_hold": {
|
|
61
|
+
return "Generation";
|
|
62
|
+
}
|
|
63
|
+
case "generation_settle": {
|
|
64
|
+
return "Usage adjustment";
|
|
65
|
+
}
|
|
66
|
+
case "generation_release": {
|
|
67
|
+
return "Refund \u2014 failed generation";
|
|
68
|
+
}
|
|
69
|
+
default: {
|
|
70
|
+
return kind;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var formatWhen = (date, now) => {
|
|
75
|
+
const minutes = Math.floor((now.getTime() - date.getTime()) / 6e4);
|
|
76
|
+
if (minutes < 1) {
|
|
77
|
+
return "just now";
|
|
78
|
+
}
|
|
79
|
+
if (minutes < 60) {
|
|
80
|
+
return `${minutes}m ago`;
|
|
81
|
+
}
|
|
82
|
+
const hours = Math.floor(minutes / 60);
|
|
83
|
+
if (hours < 24) {
|
|
84
|
+
return `${hours}h ago`;
|
|
85
|
+
}
|
|
86
|
+
const days = Math.floor(hours / 24);
|
|
87
|
+
if (days < 7) {
|
|
88
|
+
return `${days}d ago`;
|
|
89
|
+
}
|
|
90
|
+
const opts = { day: "numeric", month: "short" };
|
|
91
|
+
if (date.getFullYear() !== now.getFullYear()) {
|
|
92
|
+
opts.year = "numeric";
|
|
93
|
+
}
|
|
94
|
+
return date.toLocaleDateString("en-US", opts);
|
|
95
|
+
};
|
|
96
|
+
var requireLogin = () => {
|
|
97
|
+
if (!getToken()) {
|
|
98
|
+
consola.warn("Not logged in. Run `vg login` to authenticate.");
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var balanceCommand = defineCommand({
|
|
103
|
+
args: creditsArgs,
|
|
104
|
+
meta: {
|
|
105
|
+
description: "Show your credit balance and recent usage (the default).",
|
|
106
|
+
name: "balance"
|
|
107
|
+
},
|
|
108
|
+
run: async ({ args, rawArgs }) => {
|
|
109
|
+
assertKnownFlags(rawArgs, creditsArgs);
|
|
110
|
+
requireLogin();
|
|
111
|
+
const client = createClient();
|
|
112
|
+
try {
|
|
113
|
+
const { balanceMicro, entries, purchasesEnabled } = await client.credits.me();
|
|
114
|
+
const payload = {
|
|
115
|
+
balance_micro: balanceMicro,
|
|
116
|
+
balance_usd: balanceMicro / MICRO_PER_USD,
|
|
117
|
+
entries: entries.map((e) => ({
|
|
118
|
+
created_at: e.createdAt.toISOString(),
|
|
119
|
+
delta_micro: e.deltaMicro,
|
|
120
|
+
endpoint_id: e.endpointId,
|
|
121
|
+
id: e.id,
|
|
122
|
+
kind: e.kind,
|
|
123
|
+
note: e.note,
|
|
124
|
+
request_id: e.requestId
|
|
125
|
+
})),
|
|
126
|
+
// Whether `vg credits buy` can take a card payment; false means codes only.
|
|
127
|
+
purchases_enabled: purchasesEnabled
|
|
128
|
+
};
|
|
129
|
+
if (writeStructured(payload, args)) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
consola.log(`Balance: ${formatUsd(balanceMicro)}`);
|
|
133
|
+
if (entries.length === 0) {
|
|
134
|
+
consola.log("No activity yet.");
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const now = /* @__PURE__ */ new Date();
|
|
138
|
+
const rows = entries.slice(0, MAX_ENTRIES_SHOWN).map((e) => ({
|
|
139
|
+
amount: formatSignedUsd(e.deltaMicro),
|
|
140
|
+
endpoint: e.endpointId ?? "",
|
|
141
|
+
label: kindLabel(e.kind, e.deltaMicro),
|
|
142
|
+
when: formatWhen(e.createdAt, now)
|
|
143
|
+
}));
|
|
144
|
+
const amountWidth = Math.max(...rows.map((r) => r.amount.length));
|
|
145
|
+
const labelWidth = Math.max(...rows.map((r) => r.label.length));
|
|
146
|
+
const endpointWidth = Math.max(...rows.map((r) => r.endpoint.length));
|
|
147
|
+
consola.log("");
|
|
148
|
+
for (const r of rows) {
|
|
149
|
+
const line = [
|
|
150
|
+
` ${r.amount.padStart(amountWidth)}`,
|
|
151
|
+
r.label.padEnd(labelWidth),
|
|
152
|
+
r.endpoint.padEnd(endpointWidth),
|
|
153
|
+
r.when
|
|
154
|
+
].join(" ");
|
|
155
|
+
consola.log(line.trimEnd());
|
|
156
|
+
}
|
|
157
|
+
} catch (error) {
|
|
158
|
+
const code = authErrorCode(error);
|
|
159
|
+
if (code === "UNAUTHORIZED" || code === "FORBIDDEN") {
|
|
160
|
+
consola.warn("Not authenticated. Run `vg login`, or check your VG_TOKEN / API key.");
|
|
161
|
+
} else {
|
|
162
|
+
consola.error(
|
|
163
|
+
`Failed to fetch credits: ${error instanceof Error ? error.message : String(error)}`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
process.exit(1);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
var redeemArgs = {
|
|
171
|
+
...outputArgs,
|
|
172
|
+
code: { description: "The credit code to redeem.", required: true, type: "positional" }
|
|
173
|
+
};
|
|
174
|
+
var redeemCommand = defineCommand({
|
|
175
|
+
args: redeemArgs,
|
|
176
|
+
meta: {
|
|
177
|
+
description: "Redeem a credit code for generation credit (once per account per code).",
|
|
178
|
+
name: "redeem"
|
|
179
|
+
},
|
|
180
|
+
run: async ({ args, rawArgs }) => {
|
|
181
|
+
assertKnownFlags(rawArgs, redeemArgs);
|
|
182
|
+
requireLogin();
|
|
183
|
+
try {
|
|
184
|
+
const { balanceMicro, creditedMicro } = await createClient().credits.redeem({
|
|
185
|
+
code: args.code
|
|
186
|
+
});
|
|
187
|
+
const payload = {
|
|
188
|
+
balance_micro: balanceMicro,
|
|
189
|
+
balance_usd: balanceMicro / MICRO_PER_USD,
|
|
190
|
+
credited_micro: creditedMicro,
|
|
191
|
+
credited_usd: creditedMicro / MICRO_PER_USD
|
|
192
|
+
};
|
|
193
|
+
if (!writeStructured(payload, args)) {
|
|
194
|
+
consola.success(`Added ${formatUsd(creditedMicro)}. Balance: ${formatUsd(balanceMicro)}`);
|
|
195
|
+
}
|
|
196
|
+
} catch (error) {
|
|
197
|
+
if (authErrorCode(error) === "UNAUTHORIZED") {
|
|
198
|
+
consola.warn("Not authenticated. Run `vg login`, or check your VG_TOKEN / API key.");
|
|
199
|
+
} else {
|
|
200
|
+
consola.error(
|
|
201
|
+
`Could not redeem ${args.code}: ${error instanceof Error ? error.message : String(error)}`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
process.exit(1);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
var buyArgs = {
|
|
209
|
+
...outputArgs,
|
|
210
|
+
amount: {
|
|
211
|
+
description: `Whole US dollars of credit to buy (${MIN_PURCHASE_USD}\u2013${MAX_PURCHASE_USD}).`,
|
|
212
|
+
required: true,
|
|
213
|
+
type: "positional"
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var buyCommand = defineCommand({
|
|
217
|
+
args: buyArgs,
|
|
218
|
+
meta: {
|
|
219
|
+
description: "Start a card payment for credits and print the checkout URL. A person opens it to pay; the credit lands once the payment clears.",
|
|
220
|
+
name: "buy"
|
|
221
|
+
},
|
|
222
|
+
run: async ({ args, rawArgs }) => {
|
|
223
|
+
assertKnownFlags(rawArgs, buyArgs);
|
|
224
|
+
const amountUsd = Number(args.amount.replace(/^\$/u, ""));
|
|
225
|
+
if (!Number.isInteger(amountUsd) || amountUsd < MIN_PURCHASE_USD || amountUsd > MAX_PURCHASE_USD) {
|
|
226
|
+
consola.error(
|
|
227
|
+
`Amount must be whole dollars from ${MIN_PURCHASE_USD} to ${MAX_PURCHASE_USD}, e.g. \`vg credits buy 25\`; got "${args.amount}".`
|
|
228
|
+
);
|
|
229
|
+
process.exit(2);
|
|
230
|
+
}
|
|
231
|
+
requireLogin();
|
|
232
|
+
try {
|
|
233
|
+
const { url } = await createClient().credits.checkout({ amountUsd });
|
|
234
|
+
if (writeStructured({ amount_usd: amountUsd, url }, args)) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
consola.log(`Open this link to pay $${amountUsd} by card:
|
|
238
|
+
|
|
239
|
+
${url}
|
|
240
|
+
`);
|
|
241
|
+
consola.log("Credits are added once the payment clears \u2014 check with `vg credits`.");
|
|
242
|
+
} catch (error) {
|
|
243
|
+
const code = authErrorCode(error);
|
|
244
|
+
if (code === "UNAUTHORIZED") {
|
|
245
|
+
consola.warn("Not authenticated. Run `vg login`, or check your VG_TOKEN / API key.");
|
|
246
|
+
} else if (code === "PRECONDITION_FAILED" && error instanceof Error) {
|
|
247
|
+
consola.error(error.message);
|
|
248
|
+
} else {
|
|
249
|
+
consola.error(
|
|
250
|
+
`Could not start checkout: ${error instanceof Error ? error.message : String(error)}`
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
process.exit(1);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
var creditsCommand = defineCommand({
|
|
258
|
+
// Declared so citty skips `--field <value>` when looking for a subcommand.
|
|
259
|
+
args: outputArgs,
|
|
260
|
+
default: "balance",
|
|
261
|
+
meta: {
|
|
262
|
+
description: "Show your credit balance, redeem a code, or buy credits.",
|
|
263
|
+
name: "credits"
|
|
264
|
+
},
|
|
265
|
+
subCommands: {
|
|
266
|
+
balance: balanceCommand,
|
|
267
|
+
buy: buyCommand,
|
|
268
|
+
redeem: redeemCommand
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
export {
|
|
272
|
+
creditsCommand
|
|
273
|
+
};
|