vibedgames 0.0.2 → 0.0.4
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 +16 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/commands/completions.d.ts +7 -0
- package/dist/commands/completions.js +138 -0
- package/dist/commands/deploy.d.ts +9 -9
- package/dist/commands/deploy.js +6 -0
- package/dist/commands/init.d.ts +20 -0
- package/dist/commands/init.js +89 -0
- package/dist/commands/login.js +2 -2
- package/dist/commands/media.d.ts +1 -0
- package/dist/commands/media.js +401 -0
- package/dist/commands/new.d.ts +26 -0
- package/dist/commands/new.js +229 -0
- package/dist/index.js +11 -3
- package/dist/lib/api.js +14 -7
- package/dist/lib/config-file.js +18 -3
- package/dist/lib/config.js +5 -4
- package/dist/lib/media-args.d.ts +28 -0
- package/dist/lib/media-args.js +199 -0
- package/dist/lib/media-download.d.ts +31 -0
- package/dist/lib/media-download.js +190 -0
- package/dist/lib/media-poll.d.ts +17 -0
- package/dist/lib/media-poll.js +80 -0
- package/dist/lib/media-upload.d.ts +12 -0
- package/dist/lib/media-upload.js +51 -0
- package/dist/lib/types.d.ts +2 -0
- package/dist/lib/types.js +4 -0
- package/package.json +13 -9
- package/dist/commands/list.d.ts +0 -1
- package/dist/commands/list.js +0 -23
- package/dist/commands/rm.d.ts +0 -12
- package/dist/commands/rm.js +0 -35
- package/dist/commands/skills.d.ts +0 -8
- package/dist/commands/skills.js +0 -53
- package/dist/prompt-E6QYABXJ.js +0 -754
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import consola from "consola";
|
|
3
|
+
import { createClient } from "../lib/api.js";
|
|
4
|
+
import { parseDownloadFlag, parseRunInput, readExplicitLocalFile, } from "../lib/media-args.js";
|
|
5
|
+
import { downloadMedia, extractMediaRefs } from "../lib/media-download.js";
|
|
6
|
+
import { endpointPath, queueAppId, waitForCompletion } from "../lib/media-poll.js";
|
|
7
|
+
import { uploadFile } from "../lib/media-upload.js";
|
|
8
|
+
import { isRecord } from "../lib/types.js";
|
|
9
|
+
// Action-specific fields for the status-command payload. `result` wraps
|
|
10
|
+
// the raw fal payload under `result:` so fal's own keys can't clobber
|
|
11
|
+
// our top-level (action / endpoint_id / request_id). `status` cherry-
|
|
12
|
+
// picks known fields for the same reason.
|
|
13
|
+
function buildActionFields(action, data) {
|
|
14
|
+
if (action === "result")
|
|
15
|
+
return { result: data };
|
|
16
|
+
if (action === "status" && isRecord(data)) {
|
|
17
|
+
return {
|
|
18
|
+
status: typeof data.status === "string" ? data.status : undefined,
|
|
19
|
+
queue_position: typeof data.queue_position === "number" ? data.queue_position : undefined,
|
|
20
|
+
logs: data.logs,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
function isJsonOutput(args) {
|
|
26
|
+
return Boolean(args.json) || process.env.VG_JSON_OUTPUT === "1";
|
|
27
|
+
}
|
|
28
|
+
function writeJson(value) {
|
|
29
|
+
process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
30
|
+
}
|
|
31
|
+
function extractMediaUrls(result) {
|
|
32
|
+
return extractMediaRefs(result).map((r) => r.url);
|
|
33
|
+
}
|
|
34
|
+
// ---- run --------------------------------------------------------------------
|
|
35
|
+
const runCommand = defineCommand({
|
|
36
|
+
meta: { name: "run", description: "Run a fal model (waits for result by default)." },
|
|
37
|
+
args: {
|
|
38
|
+
endpoint_id: {
|
|
39
|
+
type: "positional",
|
|
40
|
+
required: true,
|
|
41
|
+
description: "Model endpoint ID, e.g. fal-ai/flux/dev.",
|
|
42
|
+
},
|
|
43
|
+
async: {
|
|
44
|
+
type: "boolean",
|
|
45
|
+
description: "Submit to queue and return request_id without waiting.",
|
|
46
|
+
},
|
|
47
|
+
download: {
|
|
48
|
+
type: "string",
|
|
49
|
+
description: "Download media from result. Optional value is a path or template with {index},{name},{ext},{request_id}.",
|
|
50
|
+
},
|
|
51
|
+
json: { type: "boolean", description: "Print structured JSON to stdout." },
|
|
52
|
+
quiet: { type: "boolean", description: "Suppress progress output during sync runs." },
|
|
53
|
+
},
|
|
54
|
+
run: async ({ args, rawArgs }) => {
|
|
55
|
+
const downloadFlag = parseDownloadFlag(rawArgs);
|
|
56
|
+
// parseRunInput already skips non-`--` tokens, so the positional
|
|
57
|
+
// endpoint_id and any subcommand name in argv are no-ops.
|
|
58
|
+
const finalInput = parseRunInput(rawArgs);
|
|
59
|
+
const client = createClient();
|
|
60
|
+
const submission = await client.media.forward.mutate({
|
|
61
|
+
target: "queue",
|
|
62
|
+
method: "POST",
|
|
63
|
+
path: `/${endpointPath(args.endpoint_id)}`,
|
|
64
|
+
body: finalInput,
|
|
65
|
+
});
|
|
66
|
+
const requestId = isRecord(submission) && typeof submission.request_id === "string"
|
|
67
|
+
? submission.request_id
|
|
68
|
+
: null;
|
|
69
|
+
if (!requestId) {
|
|
70
|
+
throw new Error("fal queue submit did not return a request_id.");
|
|
71
|
+
}
|
|
72
|
+
const endpoint_id = args.endpoint_id;
|
|
73
|
+
if (args.async) {
|
|
74
|
+
const payload = {
|
|
75
|
+
status: "submitted",
|
|
76
|
+
endpoint_id,
|
|
77
|
+
request_id: requestId,
|
|
78
|
+
hint: `Check status: vg media status ${endpoint_id} ${requestId}`,
|
|
79
|
+
};
|
|
80
|
+
if (isJsonOutput(args))
|
|
81
|
+
writeJson(payload);
|
|
82
|
+
else {
|
|
83
|
+
consola.success(`Submitted ${endpoint_id}`);
|
|
84
|
+
consola.log(` request_id: ${requestId}`);
|
|
85
|
+
}
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const completed = await waitForCompletion(client, endpoint_id, requestId, {
|
|
89
|
+
quiet: Boolean(args.quiet) || isJsonOutput(args),
|
|
90
|
+
});
|
|
91
|
+
let downloaded;
|
|
92
|
+
if (downloadFlag.mode === "on") {
|
|
93
|
+
const refs = extractMediaRefs(completed.result);
|
|
94
|
+
downloaded = await downloadMedia({
|
|
95
|
+
refs,
|
|
96
|
+
template: downloadFlag.template,
|
|
97
|
+
requestId: completed.request_id,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const payload = {
|
|
101
|
+
status: "completed",
|
|
102
|
+
endpoint_id,
|
|
103
|
+
request_id: completed.request_id,
|
|
104
|
+
result: completed.result,
|
|
105
|
+
...(downloaded ? { downloaded_files: downloaded.downloaded } : {}),
|
|
106
|
+
...(downloaded && downloaded.failed.length > 0
|
|
107
|
+
? { download_failures: downloaded.failed }
|
|
108
|
+
: {}),
|
|
109
|
+
};
|
|
110
|
+
if (isJsonOutput(args)) {
|
|
111
|
+
writeJson(payload);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
consola.success(`Run completed (${completed.request_id})`);
|
|
115
|
+
if (downloaded) {
|
|
116
|
+
for (const path of downloaded.downloaded)
|
|
117
|
+
consola.log(` ${path}`);
|
|
118
|
+
for (const f of downloaded.failed)
|
|
119
|
+
consola.warn(` failed: ${f.url} (${f.error})`);
|
|
120
|
+
}
|
|
121
|
+
if (!downloaded?.downloaded.length) {
|
|
122
|
+
for (const url of extractMediaUrls(completed.result))
|
|
123
|
+
consola.log(` ${url}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (downloaded && downloaded.failed.length > 0 && downloaded.downloaded.length === 0) {
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
// ---- status -----------------------------------------------------------------
|
|
132
|
+
const statusCommand = defineCommand({
|
|
133
|
+
meta: {
|
|
134
|
+
name: "status",
|
|
135
|
+
description: "Check job status, fetch result, or cancel.",
|
|
136
|
+
},
|
|
137
|
+
args: {
|
|
138
|
+
endpoint_id: { type: "positional", required: true },
|
|
139
|
+
request_id: { type: "positional", required: true },
|
|
140
|
+
result: { type: "boolean", description: "Fetch the completed result." },
|
|
141
|
+
cancel: { type: "boolean", description: "Cancel the job." },
|
|
142
|
+
logs: { type: "boolean", description: "Include logs." },
|
|
143
|
+
download: {
|
|
144
|
+
type: "string",
|
|
145
|
+
description: "Download media from the result (implies --result).",
|
|
146
|
+
},
|
|
147
|
+
json: { type: "boolean" },
|
|
148
|
+
},
|
|
149
|
+
run: async ({ args, rawArgs }) => {
|
|
150
|
+
if (args.result && args.cancel) {
|
|
151
|
+
consola.error("Pick one of --result or --cancel.");
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
const downloadFlag = parseDownloadFlag(rawArgs);
|
|
155
|
+
const wantResult = args.result || downloadFlag.mode === "on";
|
|
156
|
+
const action = args.cancel
|
|
157
|
+
? "cancel"
|
|
158
|
+
: wantResult
|
|
159
|
+
? "result"
|
|
160
|
+
: "status";
|
|
161
|
+
const ep = queueAppId(args.endpoint_id);
|
|
162
|
+
const client = createClient();
|
|
163
|
+
const path = action === "cancel"
|
|
164
|
+
? `/${ep}/requests/${args.request_id}/cancel`
|
|
165
|
+
: action === "result"
|
|
166
|
+
? `/${ep}/requests/${args.request_id}`
|
|
167
|
+
: `/${ep}/requests/${args.request_id}/status`;
|
|
168
|
+
const data = await client.media.forward.mutate({
|
|
169
|
+
target: "queue",
|
|
170
|
+
method: action === "cancel" ? "PUT" : "GET",
|
|
171
|
+
path,
|
|
172
|
+
query: action === "status" && args.logs ? { logs: "1" } : undefined,
|
|
173
|
+
});
|
|
174
|
+
let downloaded;
|
|
175
|
+
if (action === "result" && downloadFlag.mode === "on") {
|
|
176
|
+
const refs = extractMediaRefs(data);
|
|
177
|
+
downloaded = await downloadMedia({
|
|
178
|
+
refs,
|
|
179
|
+
template: downloadFlag.template,
|
|
180
|
+
requestId: args.request_id,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
const actionFields = buildActionFields(action, data);
|
|
184
|
+
const payload = {
|
|
185
|
+
action,
|
|
186
|
+
endpoint_id: args.endpoint_id,
|
|
187
|
+
request_id: args.request_id,
|
|
188
|
+
...actionFields,
|
|
189
|
+
...(downloaded ? { downloaded_files: downloaded.downloaded } : {}),
|
|
190
|
+
...(downloaded && downloaded.failed.length > 0
|
|
191
|
+
? { download_failures: downloaded.failed }
|
|
192
|
+
: {}),
|
|
193
|
+
};
|
|
194
|
+
if (isJsonOutput(args)) {
|
|
195
|
+
writeJson(payload);
|
|
196
|
+
}
|
|
197
|
+
else if (action === "status") {
|
|
198
|
+
const status = isRecord(data) && typeof data.status === "string" ? data.status : "?";
|
|
199
|
+
consola.log(`status: ${status}`);
|
|
200
|
+
if (isRecord(data) && typeof data.queue_position === "number") {
|
|
201
|
+
consola.log(`queue_position: ${data.queue_position}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
consola.success(`${action} ${args.endpoint_id} ${args.request_id}`);
|
|
206
|
+
if (downloaded) {
|
|
207
|
+
for (const p of downloaded.downloaded)
|
|
208
|
+
consola.log(` ${p}`);
|
|
209
|
+
for (const f of downloaded.failed)
|
|
210
|
+
consola.warn(` failed: ${f.url} (${f.error})`);
|
|
211
|
+
}
|
|
212
|
+
if (action === "result" && !downloaded?.downloaded.length) {
|
|
213
|
+
for (const url of extractMediaUrls(data))
|
|
214
|
+
consola.log(` ${url}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (downloaded && downloaded.failed.length > 0 && downloaded.downloaded.length === 0) {
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
// ---- models -----------------------------------------------------------------
|
|
223
|
+
const modelsCommand = defineCommand({
|
|
224
|
+
meta: { name: "models", description: "Search/list fal models." },
|
|
225
|
+
args: {
|
|
226
|
+
query: { type: "positional", required: false, description: "Search query." },
|
|
227
|
+
category: { type: "string", description: "Filter by category." },
|
|
228
|
+
status: { type: "string", description: "active (default) | deprecated | all" },
|
|
229
|
+
limit: { type: "string", description: "Max results (default 20)." },
|
|
230
|
+
cursor: { type: "string", description: "Pagination cursor from a prior response." },
|
|
231
|
+
endpoint_id: {
|
|
232
|
+
type: "string",
|
|
233
|
+
description: "Specific endpoint id(s); repeat or comma-separate.",
|
|
234
|
+
},
|
|
235
|
+
expand: {
|
|
236
|
+
type: "string",
|
|
237
|
+
description: "Expand fields: openapi-3.0, enterprise_status. Repeat or comma-separate.",
|
|
238
|
+
},
|
|
239
|
+
json: { type: "boolean" },
|
|
240
|
+
},
|
|
241
|
+
run: async ({ args }) => {
|
|
242
|
+
const query = {};
|
|
243
|
+
if (args.query)
|
|
244
|
+
query.q = args.query;
|
|
245
|
+
if (args.category)
|
|
246
|
+
query.category = args.category;
|
|
247
|
+
if (args.status && args.status !== "all")
|
|
248
|
+
query.status = args.status;
|
|
249
|
+
query.limit = args.limit ?? "20";
|
|
250
|
+
if (args.cursor)
|
|
251
|
+
query.cursor = args.cursor;
|
|
252
|
+
const endpointIds = splitList(args.endpoint_id);
|
|
253
|
+
if (endpointIds.length > 0)
|
|
254
|
+
query.endpoint_id = endpointIds;
|
|
255
|
+
const expand = splitList(args.expand);
|
|
256
|
+
if (expand.length > 0)
|
|
257
|
+
query.expand = expand;
|
|
258
|
+
const client = createClient();
|
|
259
|
+
const data = await client.media.forward.mutate({
|
|
260
|
+
target: "platform",
|
|
261
|
+
method: "GET",
|
|
262
|
+
path: "/v1/models",
|
|
263
|
+
query,
|
|
264
|
+
});
|
|
265
|
+
if (isJsonOutput(args))
|
|
266
|
+
writeJson(data);
|
|
267
|
+
else
|
|
268
|
+
printModels(data);
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
function splitList(value) {
|
|
272
|
+
if (!value)
|
|
273
|
+
return [];
|
|
274
|
+
return value
|
|
275
|
+
.split(",")
|
|
276
|
+
.map((s) => s.trim())
|
|
277
|
+
.filter(Boolean);
|
|
278
|
+
}
|
|
279
|
+
function printModels(data) {
|
|
280
|
+
const models = isRecord(data) && Array.isArray(data.models) ? data.models : [];
|
|
281
|
+
for (const m of models) {
|
|
282
|
+
if (!isRecord(m))
|
|
283
|
+
continue;
|
|
284
|
+
const id = String(m.endpoint_id ?? "?");
|
|
285
|
+
const meta = isRecord(m.metadata) ? m.metadata : {};
|
|
286
|
+
const tags = [];
|
|
287
|
+
if (meta.category)
|
|
288
|
+
tags.push(String(meta.category));
|
|
289
|
+
if (meta.status)
|
|
290
|
+
tags.push(String(meta.status));
|
|
291
|
+
consola.log(`${id}${tags.length > 0 ? ` [${tags.join(", ")}]` : ""}`);
|
|
292
|
+
}
|
|
293
|
+
if (isRecord(data) && data.next_cursor) {
|
|
294
|
+
consola.log(`\nnext_cursor: ${String(data.next_cursor)}`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// ---- schema -----------------------------------------------------------------
|
|
298
|
+
const schemaCommand = defineCommand({
|
|
299
|
+
meta: { name: "schema", description: "Fetch a model's input/output schema." },
|
|
300
|
+
args: {
|
|
301
|
+
endpoint_id: { type: "positional", required: true },
|
|
302
|
+
format: { type: "string", description: "compact (default) | openapi" },
|
|
303
|
+
json: { type: "boolean" },
|
|
304
|
+
},
|
|
305
|
+
run: async ({ args }) => {
|
|
306
|
+
const expand = args.format === "openapi" ? ["openapi-3.0"] : [];
|
|
307
|
+
const client = createClient();
|
|
308
|
+
const data = await client.media.forward.mutate({
|
|
309
|
+
target: "platform",
|
|
310
|
+
method: "GET",
|
|
311
|
+
path: "/v1/models",
|
|
312
|
+
query: {
|
|
313
|
+
endpoint_id: args.endpoint_id,
|
|
314
|
+
limit: "1",
|
|
315
|
+
...(expand.length > 0 ? { expand } : {}),
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
writeJson(data);
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
// ---- pricing ----------------------------------------------------------------
|
|
322
|
+
const pricingCommand = defineCommand({
|
|
323
|
+
meta: { name: "pricing", description: "Fetch pricing for a model." },
|
|
324
|
+
args: {
|
|
325
|
+
endpoint_id: { type: "positional", required: true },
|
|
326
|
+
json: { type: "boolean" },
|
|
327
|
+
},
|
|
328
|
+
run: async ({ args }) => {
|
|
329
|
+
const client = createClient();
|
|
330
|
+
const data = await client.media.forward.mutate({
|
|
331
|
+
target: "platform",
|
|
332
|
+
method: "GET",
|
|
333
|
+
path: "/v1/models/pricing",
|
|
334
|
+
query: { endpoint_id: args.endpoint_id },
|
|
335
|
+
});
|
|
336
|
+
writeJson(data);
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
// ---- docs -------------------------------------------------------------------
|
|
340
|
+
const docsCommand = defineCommand({
|
|
341
|
+
meta: { name: "docs", description: "Search fal documentation." },
|
|
342
|
+
args: {
|
|
343
|
+
query: { type: "positional", required: true },
|
|
344
|
+
json: { type: "boolean" },
|
|
345
|
+
},
|
|
346
|
+
run: async ({ args }) => {
|
|
347
|
+
const client = createClient();
|
|
348
|
+
const data = await client.media.forward.mutate({
|
|
349
|
+
target: "docs",
|
|
350
|
+
method: "POST",
|
|
351
|
+
path: "/docs/mcp",
|
|
352
|
+
body: {
|
|
353
|
+
jsonrpc: "2.0",
|
|
354
|
+
id: 1,
|
|
355
|
+
method: "tools/call",
|
|
356
|
+
params: { name: "search_fal", arguments: { query: args.query } },
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
writeJson(data);
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
// ---- upload -----------------------------------------------------------------
|
|
363
|
+
const uploadCommand = defineCommand({
|
|
364
|
+
meta: {
|
|
365
|
+
name: "upload",
|
|
366
|
+
description: "Upload a local file to fal CDN. Returns a stable URL.",
|
|
367
|
+
},
|
|
368
|
+
args: {
|
|
369
|
+
path: { type: "positional", required: true },
|
|
370
|
+
json: { type: "boolean" },
|
|
371
|
+
},
|
|
372
|
+
run: async ({ args }) => {
|
|
373
|
+
const stat = readExplicitLocalFile(args.path);
|
|
374
|
+
if (!stat) {
|
|
375
|
+
consola.error(`File not found: ${args.path}`);
|
|
376
|
+
process.exit(1);
|
|
377
|
+
}
|
|
378
|
+
const client = createClient();
|
|
379
|
+
const url = await uploadFile(client, stat);
|
|
380
|
+
if (isJsonOutput(args))
|
|
381
|
+
writeJson({ url });
|
|
382
|
+
else
|
|
383
|
+
process.stdout.write(url + "\n");
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
// ---- top-level --------------------------------------------------------------
|
|
387
|
+
export const mediaCommand = defineCommand({
|
|
388
|
+
meta: {
|
|
389
|
+
name: "media",
|
|
390
|
+
description: "Generate, edit, and inspect media via fal.ai (mirrors the genmedia CLI surface).",
|
|
391
|
+
},
|
|
392
|
+
subCommands: {
|
|
393
|
+
run: runCommand,
|
|
394
|
+
status: statusCommand,
|
|
395
|
+
models: modelsCommand,
|
|
396
|
+
schema: schemaCommand,
|
|
397
|
+
pricing: pricingCommand,
|
|
398
|
+
docs: docsCommand,
|
|
399
|
+
upload: uploadCommand,
|
|
400
|
+
},
|
|
401
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
readonly engine: {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly description: "Engine preset: phaser (default), threejs, or none.";
|
|
10
|
+
readonly default: "phaser";
|
|
11
|
+
};
|
|
12
|
+
readonly template: {
|
|
13
|
+
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
|
+
};
|
|
21
|
+
readonly force: {
|
|
22
|
+
readonly type: "boolean";
|
|
23
|
+
readonly description: "Overwrite an existing target directory.";
|
|
24
|
+
readonly default: false;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { defineCommand } from "citty";
|
|
4
|
+
import consola from "consola";
|
|
5
|
+
import tiged from "tiged";
|
|
6
|
+
const SLUG_RE = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/;
|
|
7
|
+
const ENGINES = {
|
|
8
|
+
// phaserjs/template-vite-ts is the official Phaser 4 + Vite + TypeScript
|
|
9
|
+
// starter (despite the description still saying "Phaser 3" — package.json
|
|
10
|
+
// pins phaser@^4). Pulled fresh on each `vg new`.
|
|
11
|
+
phaser: {
|
|
12
|
+
repo: "phaserjs/template-vite-ts",
|
|
13
|
+
label: "Phaser 4 + Vite + TypeScript (official)",
|
|
14
|
+
skill: "phaser",
|
|
15
|
+
postNotes: [
|
|
16
|
+
"The phaser template ships a `log.js` telemetry shim and uses `vite/config.*.mjs` for build configs — both are upstream, not vibedgames.",
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
// No officially-blessed Three.js starter exists. Using the most-starred
|
|
20
|
+
// community Vite+TS starter that's been kept current.
|
|
21
|
+
threejs: {
|
|
22
|
+
repo: "pachoclo/vite-threejs-ts-template",
|
|
23
|
+
label: "Three.js + Vite + TypeScript (community)",
|
|
24
|
+
skill: "threejs",
|
|
25
|
+
},
|
|
26
|
+
// React Three Fiber. Same author as the threejs preset — Vite + TS +
|
|
27
|
+
// React 18 + R3F 8 + drei, with leva and r3f-perf wired up for debug.
|
|
28
|
+
// The pmndrs org doesn't ship an official R3F starter (its templates
|
|
29
|
+
// are all Next.js-based), and the highest-starred R3F template on
|
|
30
|
+
// GitHub is still on CRA + React 17, so this is the cleanest current
|
|
31
|
+
// option for an agent.
|
|
32
|
+
"react-r3f": {
|
|
33
|
+
repo: "pachoclo/vite-r3f-ts-template",
|
|
34
|
+
label: "React + React Three Fiber + Vite + TypeScript (community)",
|
|
35
|
+
skill: "threejs",
|
|
36
|
+
},
|
|
37
|
+
// Engine-agnostic fallback for "I'll wire it up myself" / non-canvas
|
|
38
|
+
// games. Stays inline so we don't get blocked on a network fetch when
|
|
39
|
+
// the user explicitly asked for a minimal start.
|
|
40
|
+
none: {
|
|
41
|
+
inline: true,
|
|
42
|
+
label: "minimal Vite + TypeScript canvas",
|
|
43
|
+
skill: "deploy",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
const NONE_FILES = [
|
|
47
|
+
{
|
|
48
|
+
path: "package.json",
|
|
49
|
+
content: (slug) => `${JSON.stringify({
|
|
50
|
+
name: slug,
|
|
51
|
+
version: "0.0.0",
|
|
52
|
+
private: true,
|
|
53
|
+
type: "module",
|
|
54
|
+
scripts: {
|
|
55
|
+
dev: "vite",
|
|
56
|
+
build: "vite build",
|
|
57
|
+
preview: "vite preview",
|
|
58
|
+
},
|
|
59
|
+
devDependencies: { typescript: "^5.6.0", vite: "^7.0.0" },
|
|
60
|
+
}, null, 2)}\n`,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
path: "tsconfig.json",
|
|
64
|
+
content: () => `${JSON.stringify({
|
|
65
|
+
compilerOptions: {
|
|
66
|
+
target: "ES2022",
|
|
67
|
+
lib: ["ES2022", "DOM", "DOM.Iterable"],
|
|
68
|
+
module: "Preserve",
|
|
69
|
+
moduleResolution: "Bundler",
|
|
70
|
+
strict: true,
|
|
71
|
+
noUncheckedIndexedAccess: true,
|
|
72
|
+
isolatedModules: true,
|
|
73
|
+
esModuleInterop: true,
|
|
74
|
+
skipLibCheck: true,
|
|
75
|
+
noEmit: true,
|
|
76
|
+
types: ["vite/client"],
|
|
77
|
+
},
|
|
78
|
+
include: ["src", "vite.config.ts"],
|
|
79
|
+
}, null, 2)}\n`,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
path: "vite.config.ts",
|
|
83
|
+
content: () => `import { defineConfig } from "vite";\n\nexport default defineConfig({\n base: "./",\n server: { port: 5173 },\n});\n`,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
path: "index.html",
|
|
87
|
+
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`,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
path: "src/main.ts",
|
|
91
|
+
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`,
|
|
92
|
+
},
|
|
93
|
+
{ path: ".gitignore", content: () => `node_modules\ndist\n.DS_Store\n` },
|
|
94
|
+
];
|
|
95
|
+
export const newCommand = defineCommand({
|
|
96
|
+
meta: {
|
|
97
|
+
name: "new",
|
|
98
|
+
description: "Scaffold a new browser game. Pulls an official engine template (phaser, threejs) or generates a minimal canvas starter.",
|
|
99
|
+
},
|
|
100
|
+
args: {
|
|
101
|
+
slug: {
|
|
102
|
+
type: "positional",
|
|
103
|
+
description: "Lowercase, hyphenated slug — used as the directory name and deploy subdomain.",
|
|
104
|
+
required: true,
|
|
105
|
+
},
|
|
106
|
+
engine: {
|
|
107
|
+
type: "string",
|
|
108
|
+
description: "Engine preset: phaser (default), threejs, or none.",
|
|
109
|
+
default: "phaser",
|
|
110
|
+
},
|
|
111
|
+
template: {
|
|
112
|
+
type: "string",
|
|
113
|
+
description: "Override the engine preset and fetch from an arbitrary degit spec (e.g. owner/repo, owner/repo#branch). Skips the engine preset entirely.",
|
|
114
|
+
},
|
|
115
|
+
here: {
|
|
116
|
+
type: "boolean",
|
|
117
|
+
description: "Write into the current directory instead of creating <slug>/.",
|
|
118
|
+
default: false,
|
|
119
|
+
},
|
|
120
|
+
force: {
|
|
121
|
+
type: "boolean",
|
|
122
|
+
description: "Overwrite an existing target directory.",
|
|
123
|
+
default: false,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
run: async ({ args }) => {
|
|
127
|
+
const slug = args.slug.trim().toLowerCase();
|
|
128
|
+
if (!SLUG_RE.test(slug)) {
|
|
129
|
+
consola.error(`Invalid slug: ${args.slug}\n Use lowercase letters, digits, and hyphens (e.g. "asteroid-belt").`);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
const preset = args.template
|
|
133
|
+
? { repo: args.template, label: `custom: ${args.template}`, skill: "deploy" }
|
|
134
|
+
: ENGINES[args.engine];
|
|
135
|
+
if (!preset) {
|
|
136
|
+
consola.error(`Unknown engine: ${args.engine}. Use one of: ${Object.keys(ENGINES).join(", ")}.`);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
const target = args.here ? process.cwd() : resolve(process.cwd(), slug);
|
|
140
|
+
if (!args.here) {
|
|
141
|
+
if (existsSync(target) && !args.force) {
|
|
142
|
+
consola.error(`Directory ${target} already exists. Pass --force to overwrite, or pick a different slug.`);
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
mkdirSync(target, { recursive: true });
|
|
146
|
+
}
|
|
147
|
+
consola.start(`Scaffolding ${slug} with ${preset.label}`);
|
|
148
|
+
if ("inline" in preset) {
|
|
149
|
+
writeInlineTemplate(target, slug, args.force);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
try {
|
|
153
|
+
await fetchTemplate(preset.repo, target, args.force);
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
consola.error(`Failed to fetch template ${preset.repo}: ${err instanceof Error ? err.message : String(err)}\n ` +
|
|
157
|
+
`Check your network connection, or pass --engine none to scaffold a minimal starter offline.`);
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// Post-process: name + vibedgames.json + README link to skills.
|
|
162
|
+
rewritePackageName(target, slug);
|
|
163
|
+
writeVibedgamesJson(target, slug);
|
|
164
|
+
writeReadme(target, slug, preset);
|
|
165
|
+
consola.success(`Scaffolded ${slug} in ${target}`);
|
|
166
|
+
if ("postNotes" in preset && preset.postNotes) {
|
|
167
|
+
for (const n of preset.postNotes)
|
|
168
|
+
consola.info(n);
|
|
169
|
+
}
|
|
170
|
+
consola.log("");
|
|
171
|
+
consola.info("Next steps:");
|
|
172
|
+
consola.log(` cd ${args.here ? "." : slug}`);
|
|
173
|
+
consola.log(" npm install");
|
|
174
|
+
consola.log(" npm run dev");
|
|
175
|
+
consola.log(" # then: npm run build && vg deploy ./dist");
|
|
176
|
+
consola.log("");
|
|
177
|
+
consola.log(`Skill to load for engine work: ${preset.skill} (Claude Code: triggered automatically by package.json deps)`);
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
async function fetchTemplate(repo, target, force) {
|
|
181
|
+
const emitter = tiged(repo, { force, verbose: false, mode: "tar" });
|
|
182
|
+
await emitter.clone(target);
|
|
183
|
+
}
|
|
184
|
+
function writeInlineTemplate(target, slug, force) {
|
|
185
|
+
for (const file of NONE_FILES) {
|
|
186
|
+
const path = resolve(target, file.path);
|
|
187
|
+
if (existsSync(path) && !force)
|
|
188
|
+
continue;
|
|
189
|
+
mkdirSync(path.slice(0, path.lastIndexOf("/")), { recursive: true });
|
|
190
|
+
writeFileSync(path, file.content(slug));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function rewritePackageName(target, slug) {
|
|
194
|
+
const pkgPath = resolve(target, "package.json");
|
|
195
|
+
if (!existsSync(pkgPath))
|
|
196
|
+
return;
|
|
197
|
+
try {
|
|
198
|
+
const raw = readFileSync(pkgPath, "utf8");
|
|
199
|
+
const pkg = JSON.parse(raw);
|
|
200
|
+
pkg.name = slug;
|
|
201
|
+
delete pkg.repository;
|
|
202
|
+
delete pkg.bugs;
|
|
203
|
+
delete pkg.homepage;
|
|
204
|
+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
205
|
+
}
|
|
206
|
+
catch (err) {
|
|
207
|
+
consola.warn(`Could not rewrite package.json name to ${slug}: ${err instanceof Error ? err.message : String(err)}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function writeVibedgamesJson(target, slug) {
|
|
211
|
+
writeFileSync(resolve(target, "vibedgames.json"), `${JSON.stringify({ slug, name: slug.replace(/-/g, " ") }, null, 2)}\n`);
|
|
212
|
+
}
|
|
213
|
+
function writeReadme(target, slug, preset) {
|
|
214
|
+
const readmePath = resolve(target, "README.md");
|
|
215
|
+
// Keep the template's README if present (it usually has engine docs).
|
|
216
|
+
// Append a vibedgames-specific footer so devs see the deploy flow.
|
|
217
|
+
const footer = `\n\n---\n\n## Vibedgames\n\n` +
|
|
218
|
+
`This project was scaffolded with \`vg new ${slug}\` (${preset.label}).\n\n` +
|
|
219
|
+
`\`\`\`sh\nnpm install\nnpm run dev # local preview\nnpm run build\nvg deploy ./dist # ships to ${slug}.vibedgames.com\n\`\`\`\n\n` +
|
|
220
|
+
`For engine-specific work, the \`${preset.skill}\` skill loads automatically in Claude Code.\n`;
|
|
221
|
+
if (existsSync(readmePath)) {
|
|
222
|
+
const existing = readFileSync(readmePath, "utf8");
|
|
223
|
+
if (existing.includes("## Vibedgames"))
|
|
224
|
+
return;
|
|
225
|
+
writeFileSync(readmePath, existing.replace(/\s*$/, "") + footer);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
writeFileSync(readmePath, `# ${slug}${footer}`);
|
|
229
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
2
3
|
import { defineCommand, runMain } from "citty";
|
|
4
|
+
import { completionsCommand } from "./commands/completions.js";
|
|
3
5
|
import { deployCommand } from "./commands/deploy.js";
|
|
6
|
+
import { initCommand } from "./commands/init.js";
|
|
4
7
|
import { loginCommand } from "./commands/login.js";
|
|
5
8
|
import { logoutCommand } from "./commands/logout.js";
|
|
6
|
-
import {
|
|
9
|
+
import { mediaCommand } from "./commands/media.js";
|
|
10
|
+
import { newCommand } from "./commands/new.js";
|
|
7
11
|
import { whoamiCommand } from "./commands/whoami.js";
|
|
12
|
+
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
8
13
|
const main = defineCommand({
|
|
9
14
|
meta: {
|
|
10
15
|
name: "vg",
|
|
11
|
-
version:
|
|
16
|
+
version: pkg.version,
|
|
12
17
|
description: "vibedgames CLI",
|
|
13
18
|
},
|
|
14
19
|
subCommands: {
|
|
20
|
+
new: newCommand,
|
|
21
|
+
init: initCommand,
|
|
15
22
|
login: loginCommand,
|
|
16
23
|
logout: logoutCommand,
|
|
17
24
|
deploy: deployCommand,
|
|
18
|
-
|
|
25
|
+
media: mediaCommand,
|
|
26
|
+
completions: completionsCommand,
|
|
19
27
|
whoami: whoamiCommand,
|
|
20
28
|
},
|
|
21
29
|
});
|