vibedgames 0.1.0 → 0.2.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 +13 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/commands/completions.js +3 -0
- package/dist/commands/generate.js +6 -6
- package/dist/commands/init.js +1 -9
- package/dist/commands/login.js +1 -5
- package/dist/commands/new.js +61 -3
- package/dist/commands/update.d.ts +13 -0
- package/dist/commands/update.js +68 -0
- package/dist/index.js +9 -0
- package/dist/lib/config.d.ts +1 -0
- package/dist/lib/config.js +1 -1
- package/dist/lib/media-download.js +21 -3
- package/dist/lib/media-poll.d.ts +1 -1
- package/dist/lib/media-poll.js +3 -3
- package/dist/lib/media-upload.d.ts +1 -1
- package/dist/lib/media-upload.js +2 -2
- package/dist/lib/run.d.ts +5 -0
- package/dist/lib/run.js +9 -0
- package/dist/lib/update.d.ts +10 -0
- package/dist/lib/update.js +98 -0
- package/package.json +1 -1
|
@@ -58,7 +58,7 @@ const runCommand = defineCommand({
|
|
|
58
58
|
const finalInput = parseRunInput(rawArgs);
|
|
59
59
|
const client = createClient();
|
|
60
60
|
const endpoint_id = args.endpoint_id;
|
|
61
|
-
const submission = await client.
|
|
61
|
+
const submission = await client.generate.forward.mutate({
|
|
62
62
|
target: "queue",
|
|
63
63
|
method: "POST",
|
|
64
64
|
path: `/${endpointPath(endpoint_id)}`,
|
|
@@ -165,7 +165,7 @@ const statusCommand = defineCommand({
|
|
|
165
165
|
: action === "result"
|
|
166
166
|
? `/${ep}/requests/${args.request_id}`
|
|
167
167
|
: `/${ep}/requests/${args.request_id}/status`;
|
|
168
|
-
const data = await client.
|
|
168
|
+
const data = await client.generate.forward.mutate({
|
|
169
169
|
target: "queue",
|
|
170
170
|
method: action === "cancel" ? "PUT" : "GET",
|
|
171
171
|
path,
|
|
@@ -256,7 +256,7 @@ const modelsCommand = defineCommand({
|
|
|
256
256
|
if (expand.length > 0)
|
|
257
257
|
query.expand = expand;
|
|
258
258
|
const client = createClient();
|
|
259
|
-
const data = await client.
|
|
259
|
+
const data = await client.generate.forward.mutate({
|
|
260
260
|
target: "platform",
|
|
261
261
|
method: "GET",
|
|
262
262
|
path: "/v1/models",
|
|
@@ -305,7 +305,7 @@ const schemaCommand = defineCommand({
|
|
|
305
305
|
run: async ({ args }) => {
|
|
306
306
|
const expand = args.format === "openapi" ? ["openapi-3.0"] : [];
|
|
307
307
|
const client = createClient();
|
|
308
|
-
const data = await client.
|
|
308
|
+
const data = await client.generate.forward.mutate({
|
|
309
309
|
target: "platform",
|
|
310
310
|
method: "GET",
|
|
311
311
|
path: "/v1/models",
|
|
@@ -327,7 +327,7 @@ const pricingCommand = defineCommand({
|
|
|
327
327
|
},
|
|
328
328
|
run: async ({ args }) => {
|
|
329
329
|
const client = createClient();
|
|
330
|
-
const data = await client.
|
|
330
|
+
const data = await client.generate.forward.mutate({
|
|
331
331
|
target: "platform",
|
|
332
332
|
method: "GET",
|
|
333
333
|
path: "/v1/models/pricing",
|
|
@@ -345,7 +345,7 @@ const docsCommand = defineCommand({
|
|
|
345
345
|
},
|
|
346
346
|
run: async ({ args }) => {
|
|
347
347
|
const client = createClient();
|
|
348
|
-
const data = await client.
|
|
348
|
+
const data = await client.generate.forward.mutate({
|
|
349
349
|
target: "docs",
|
|
350
350
|
method: "POST",
|
|
351
351
|
path: "/docs/mcp",
|
package/dist/commands/init.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { defineCommand } from "citty";
|
|
2
2
|
import consola from "consola";
|
|
3
|
-
import
|
|
3
|
+
import { run } from "../lib/run.js";
|
|
4
4
|
const REPO = "kyh/vibedgames";
|
|
5
5
|
const PKG = "vibedgames";
|
|
6
6
|
const DEFAULT_AGENTS = "claude-code,cursor,codex";
|
|
7
7
|
const description = "Install/update vibedgames skills and the vg CLI";
|
|
8
|
-
const run = (cmd, args) => new Promise((resolve) => {
|
|
9
|
-
const chunks = [];
|
|
10
|
-
const child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
11
|
-
child.stdout?.on("data", (c) => chunks.push(c));
|
|
12
|
-
child.stderr?.on("data", (c) => chunks.push(c));
|
|
13
|
-
child.on("error", (err) => resolve({ code: 1, output: `${err.message}\n` }));
|
|
14
|
-
child.on("close", (code) => resolve({ code: code ?? 1, output: Buffer.concat(chunks).toString("utf8") }));
|
|
15
|
-
});
|
|
16
8
|
const skillsAddArgs = (agents, global, yes) => {
|
|
17
9
|
const args = ["-y", "skills", "add", REPO];
|
|
18
10
|
for (const agent of agents)
|
package/dist/commands/login.js
CHANGED
|
@@ -6,11 +6,7 @@ import { getBaseUrl, saveConfig } from "../lib/config.js";
|
|
|
6
6
|
const POLL_INTERVAL_MS = 2_000;
|
|
7
7
|
const MAX_POLLS = 150; // 5 min at 2s intervals
|
|
8
8
|
function openBrowser(url) {
|
|
9
|
-
const cmd = process.platform === "darwin"
|
|
10
|
-
? "open"
|
|
11
|
-
: process.platform === "win32"
|
|
12
|
-
? "start"
|
|
13
|
-
: "xdg-open";
|
|
9
|
+
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
14
10
|
exec(`${cmd} "${url}"`);
|
|
15
11
|
}
|
|
16
12
|
function sleep(ms) {
|
package/dist/commands/new.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { defineCommand } from "citty";
|
|
4
4
|
import consola from "consola";
|
|
@@ -22,6 +22,9 @@ const ENGINES = {
|
|
|
22
22
|
repo: "pachoclo/vite-threejs-ts-template",
|
|
23
23
|
label: "Three.js + Vite + TypeScript (community)",
|
|
24
24
|
skill: "threejs",
|
|
25
|
+
postNotes: [
|
|
26
|
+
"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.",
|
|
27
|
+
],
|
|
25
28
|
},
|
|
26
29
|
// React Three Fiber. Same author as the threejs preset — Vite + TS +
|
|
27
30
|
// React 18 + R3F 8 + drei, with leva and r3f-perf wired up for debug.
|
|
@@ -130,7 +133,11 @@ export const newCommand = defineCommand({
|
|
|
130
133
|
process.exit(1);
|
|
131
134
|
}
|
|
132
135
|
const preset = args.template
|
|
133
|
-
? {
|
|
136
|
+
? {
|
|
137
|
+
repo: args.template,
|
|
138
|
+
label: `custom: ${args.template}`,
|
|
139
|
+
skill: "deploy",
|
|
140
|
+
}
|
|
134
141
|
: ENGINES[args.engine];
|
|
135
142
|
if (!preset) {
|
|
136
143
|
consola.error(`Unknown engine: ${args.engine}. Use one of: ${Object.keys(ENGINES).join(", ")}.`);
|
|
@@ -158,7 +165,13 @@ export const newCommand = defineCommand({
|
|
|
158
165
|
process.exit(1);
|
|
159
166
|
}
|
|
160
167
|
}
|
|
161
|
-
// Post-process: name + vibedgames.json
|
|
168
|
+
// Post-process: strip template-repo artifacts, then name + vibedgames.json
|
|
169
|
+
// + README link to skills.
|
|
170
|
+
if (!("inline" in preset)) {
|
|
171
|
+
cleanTemplateArtifacts(target);
|
|
172
|
+
ensureViteConfig(target);
|
|
173
|
+
ensureTypecheckScript(target);
|
|
174
|
+
}
|
|
162
175
|
rewritePackageName(target, slug);
|
|
163
176
|
writeVibedgamesJson(target, slug);
|
|
164
177
|
writeReadme(target, slug, preset);
|
|
@@ -181,6 +194,51 @@ async function fetchTemplate(repo, target, force) {
|
|
|
181
194
|
const emitter = tiged(repo, { force, verbose: false, mode: "tar" });
|
|
182
195
|
await emitter.clone(target);
|
|
183
196
|
}
|
|
197
|
+
/** Remove template-repo artifacts that never apply to a scaffolded game:
|
|
198
|
+
* the template's own lockfile (wrong for whatever package manager the user
|
|
199
|
+
* runs) and its CI workflows (reference the template repo, fail elsewhere). */
|
|
200
|
+
function cleanTemplateArtifacts(target) {
|
|
201
|
+
for (const f of ["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lockb", "bun.lock"]) {
|
|
202
|
+
const p = resolve(target, f);
|
|
203
|
+
if (existsSync(p))
|
|
204
|
+
rmSync(p);
|
|
205
|
+
}
|
|
206
|
+
const gh = resolve(target, ".github");
|
|
207
|
+
if (existsSync(gh))
|
|
208
|
+
rmSync(gh, { recursive: true });
|
|
209
|
+
}
|
|
210
|
+
/** Some templates (threejs) ship no vite config at all, which means no
|
|
211
|
+
* relative `base` — write a minimal one so built asset URLs are relative
|
|
212
|
+
* and the bundle works wherever it's hosted. Never touches templates that
|
|
213
|
+
* bring their own config (phaser uses a vite/ config dir wired into its
|
|
214
|
+
* npm scripts). */
|
|
215
|
+
function ensureViteConfig(target) {
|
|
216
|
+
const hasConfig = ["vite.config.ts", "vite.config.js", "vite.config.mjs"].some((f) => existsSync(resolve(target, f))) || existsSync(resolve(target, "vite"));
|
|
217
|
+
if (hasConfig)
|
|
218
|
+
return;
|
|
219
|
+
writeFileSync(resolve(target, "vite.config.ts"), `import { defineConfig } from "vite";\n\nexport default defineConfig({\n base: "./",\n});\n`);
|
|
220
|
+
}
|
|
221
|
+
/** Agents lean on \`npm run typecheck\` to verify changes without a full
|
|
222
|
+
* build — add it when the template doesn't define one. */
|
|
223
|
+
function ensureTypecheckScript(target) {
|
|
224
|
+
const pkgPath = resolve(target, "package.json");
|
|
225
|
+
if (!existsSync(pkgPath))
|
|
226
|
+
return;
|
|
227
|
+
try {
|
|
228
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
229
|
+
const scripts = typeof pkg.scripts === "object" && pkg.scripts !== null
|
|
230
|
+
? pkg.scripts
|
|
231
|
+
: {};
|
|
232
|
+
if (typeof scripts.typecheck === "string")
|
|
233
|
+
return;
|
|
234
|
+
scripts.typecheck = "tsc --noEmit";
|
|
235
|
+
pkg.scripts = scripts;
|
|
236
|
+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
// malformed package.json — rewritePackageName will warn about it
|
|
240
|
+
}
|
|
241
|
+
}
|
|
184
242
|
function writeInlineTemplate(target, slug, force) {
|
|
185
243
|
for (const file of NONE_FILES) {
|
|
186
244
|
const path = resolve(target, file.path);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const updateCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly global: {
|
|
3
|
+
readonly type: "boolean";
|
|
4
|
+
readonly description: "Update skills installed in the user directory instead of the project";
|
|
5
|
+
readonly default: false;
|
|
6
|
+
readonly alias: "g";
|
|
7
|
+
};
|
|
8
|
+
readonly auto: {
|
|
9
|
+
readonly type: "boolean";
|
|
10
|
+
readonly description: "(internal) silent background mode: only update when npm has a newer version";
|
|
11
|
+
readonly default: false;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { defineCommand } from "citty";
|
|
3
|
+
import consola from "consola";
|
|
4
|
+
import { run } from "../lib/run.js";
|
|
5
|
+
import { fetchLatestVersion, isNewerVersion } from "../lib/update.js";
|
|
6
|
+
const PKG = "vibedgames";
|
|
7
|
+
const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
|
|
8
|
+
const skillsUpdateArgs = (global) => {
|
|
9
|
+
const args = ["-y", "skills", "update", "-y"];
|
|
10
|
+
if (global)
|
|
11
|
+
args.push("-g");
|
|
12
|
+
return args;
|
|
13
|
+
};
|
|
14
|
+
export const updateCommand = defineCommand({
|
|
15
|
+
meta: {
|
|
16
|
+
name: "update",
|
|
17
|
+
description: "Update the vg CLI and vibedgames skills to latest (runs automatically once a day; disable with VG_NO_AUTO_UPDATE=1)",
|
|
18
|
+
},
|
|
19
|
+
args: {
|
|
20
|
+
global: {
|
|
21
|
+
type: "boolean",
|
|
22
|
+
description: "Update skills installed in the user directory instead of the project",
|
|
23
|
+
default: false,
|
|
24
|
+
alias: "g",
|
|
25
|
+
},
|
|
26
|
+
auto: {
|
|
27
|
+
type: "boolean",
|
|
28
|
+
description: "(internal) silent background mode: only update when npm has a newer version",
|
|
29
|
+
default: false,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
run: async ({ args }) => {
|
|
33
|
+
if (args.auto) {
|
|
34
|
+
const latest = await fetchLatestVersion();
|
|
35
|
+
if (!latest || !isNewerVersion(latest, pkg.version))
|
|
36
|
+
return;
|
|
37
|
+
await Promise.all([
|
|
38
|
+
run("npm", ["install", "-g", PKG]),
|
|
39
|
+
run("npx", skillsUpdateArgs(args.global)),
|
|
40
|
+
]);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
consola.start("Updating the vg CLI and vibedgames skills...");
|
|
44
|
+
const [cli, skills] = await Promise.all([
|
|
45
|
+
run("npm", ["install", "-g", PKG]),
|
|
46
|
+
run("npx", skillsUpdateArgs(args.global)),
|
|
47
|
+
]);
|
|
48
|
+
if (cli.code === 0) {
|
|
49
|
+
consola.success("vg CLI updated to latest");
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (cli.output.trim())
|
|
53
|
+
consola.warn(cli.output.trim());
|
|
54
|
+
consola.warn(`Couldn't update the vg CLI (npm exit ${cli.code}). Update manually: npm install -g ${PKG}`);
|
|
55
|
+
}
|
|
56
|
+
if (skills.code === 0) {
|
|
57
|
+
consola.success("Skills updated to latest");
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
if (skills.output.trim())
|
|
61
|
+
consola.warn(skills.output.trim());
|
|
62
|
+
consola.warn(`'skills update' exited with code ${skills.code}. If skills aren't installed here yet, run: vg init`);
|
|
63
|
+
}
|
|
64
|
+
if (cli.code !== 0 && skills.code !== 0) {
|
|
65
|
+
throw new Error("update failed for both the CLI and skills");
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
});
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,9 @@ import { initCommand } from "./commands/init.js";
|
|
|
9
9
|
import { loginCommand } from "./commands/login.js";
|
|
10
10
|
import { logoutCommand } from "./commands/logout.js";
|
|
11
11
|
import { newCommand } from "./commands/new.js";
|
|
12
|
+
import { updateCommand } from "./commands/update.js";
|
|
12
13
|
import { whoamiCommand } from "./commands/whoami.js";
|
|
14
|
+
import { maybeScheduleAutoUpdate } from "./lib/update.js";
|
|
13
15
|
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
14
16
|
const main = defineCommand({
|
|
15
17
|
meta: {
|
|
@@ -25,8 +27,15 @@ const main = defineCommand({
|
|
|
25
27
|
deploy: deployCommand,
|
|
26
28
|
fork: forkCommand,
|
|
27
29
|
generate: generateCommand,
|
|
30
|
+
update: updateCommand,
|
|
28
31
|
completions: completionsCommand,
|
|
29
32
|
whoami: whoamiCommand,
|
|
30
33
|
},
|
|
31
34
|
});
|
|
35
|
+
// Skip for update/init (they already update) and completions (runs in shell
|
|
36
|
+
// startup — must stay side-effect free).
|
|
37
|
+
const subcommand = process.argv[2];
|
|
38
|
+
if (subcommand && !["update", "init", "completions"].includes(subcommand)) {
|
|
39
|
+
maybeScheduleAutoUpdate();
|
|
40
|
+
}
|
|
32
41
|
runMain(main);
|
package/dist/lib/config.d.ts
CHANGED
package/dist/lib/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
function getConfigDir() {
|
|
4
|
+
export function getConfigDir() {
|
|
5
5
|
const xdg = process.env.XDG_CONFIG_HOME;
|
|
6
6
|
const base = xdg ?? join(homedir(), ".config");
|
|
7
7
|
return join(base, "vg");
|
|
@@ -5,8 +5,23 @@ import { isRecord } from "./types.js";
|
|
|
5
5
|
// response payloads where `content_type` is missing (some endpoints
|
|
6
6
|
// omit it).
|
|
7
7
|
const MEDIA_EXT = new Set([
|
|
8
|
-
"png",
|
|
9
|
-
"
|
|
8
|
+
"png",
|
|
9
|
+
"jpg",
|
|
10
|
+
"jpeg",
|
|
11
|
+
"webp",
|
|
12
|
+
"gif",
|
|
13
|
+
"bmp",
|
|
14
|
+
"tif",
|
|
15
|
+
"tiff",
|
|
16
|
+
"avif",
|
|
17
|
+
"mp4",
|
|
18
|
+
"mov",
|
|
19
|
+
"webm",
|
|
20
|
+
"mp3",
|
|
21
|
+
"wav",
|
|
22
|
+
"ogg",
|
|
23
|
+
"flac",
|
|
24
|
+
"m4a",
|
|
10
25
|
]);
|
|
11
26
|
/**
|
|
12
27
|
* Walk a fal result payload and pull out anything that looks like a media
|
|
@@ -131,7 +146,10 @@ export async function downloadMedia(opts) {
|
|
|
131
146
|
// Handle both POSIX and Windows separators regardless of host OS so a
|
|
132
147
|
// `..\\..\\evil` payload sent to a Linux client is still flattened.
|
|
133
148
|
function sanitizeFilename(name) {
|
|
134
|
-
const base = name
|
|
149
|
+
const base = name
|
|
150
|
+
.replace(/[\\/]+/g, "/")
|
|
151
|
+
.split("/")
|
|
152
|
+
.pop() ?? "";
|
|
135
153
|
if (!base || base === "." || base === "..")
|
|
136
154
|
return null;
|
|
137
155
|
return base;
|
package/dist/lib/media-poll.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ type CompletedResult = {
|
|
|
9
9
|
/**
|
|
10
10
|
* Poll fal's queue from the client side until the job reaches a
|
|
11
11
|
* terminal status, then fetch the result. The Worker isn't in the
|
|
12
|
-
* loop — it's only along for each individual `
|
|
12
|
+
* loop — it's only along for each individual `generate.forward` hop.
|
|
13
13
|
*/
|
|
14
14
|
export declare function waitForCompletion(client: Client, endpoint_id: string, request_id: string, opts: {
|
|
15
15
|
quiet: boolean;
|
package/dist/lib/media-poll.js
CHANGED
|
@@ -25,7 +25,7 @@ const POLL_TIMEOUT_MS = 30 * 60 * 1000;
|
|
|
25
25
|
/**
|
|
26
26
|
* Poll fal's queue from the client side until the job reaches a
|
|
27
27
|
* terminal status, then fetch the result. The Worker isn't in the
|
|
28
|
-
* loop — it's only along for each individual `
|
|
28
|
+
* loop — it's only along for each individual `generate.forward` hop.
|
|
29
29
|
*/
|
|
30
30
|
export async function waitForCompletion(client, endpoint_id, request_id, opts) {
|
|
31
31
|
const ep = queueAppId(endpoint_id);
|
|
@@ -37,7 +37,7 @@ export async function waitForCompletion(client, endpoint_id, request_id, opts) {
|
|
|
37
37
|
`(endpoint=${endpoint_id} request_id=${request_id}). ` +
|
|
38
38
|
`Use \`vg generate status ${endpoint_id} ${request_id} --result\` to check later.`);
|
|
39
39
|
}
|
|
40
|
-
const raw = await client.
|
|
40
|
+
const raw = await client.generate.forward.mutate({
|
|
41
41
|
target: "queue",
|
|
42
42
|
method: "GET",
|
|
43
43
|
path: `/${ep}/requests/${request_id}/status`,
|
|
@@ -58,7 +58,7 @@ export async function waitForCompletion(client, endpoint_id, request_id, opts) {
|
|
|
58
58
|
}
|
|
59
59
|
await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
|
|
60
60
|
}
|
|
61
|
-
const result = await client.
|
|
61
|
+
const result = await client.generate.forward.mutate({
|
|
62
62
|
target: "queue",
|
|
63
63
|
method: "GET",
|
|
64
64
|
path: `/${ep}/requests/${request_id}`,
|
|
@@ -3,7 +3,7 @@ import type { LocalFile } from "./media-args.js";
|
|
|
3
3
|
type Client = ReturnType<typeof createClient>;
|
|
4
4
|
/**
|
|
5
5
|
* Upload one local file directly to fal's CDN. The proxy hands us a
|
|
6
|
-
* presigned upload slot (upload_url + file_url) via the `
|
|
6
|
+
* presigned upload slot (upload_url + file_url) via the `generate.forward`
|
|
7
7
|
* storage target; bytes go straight from the client to fal, never
|
|
8
8
|
* through the worker. The returned file_url is a stable fal CDN URL
|
|
9
9
|
* that can be reused across runs without re-uploading.
|
package/dist/lib/media-upload.js
CHANGED
|
@@ -2,13 +2,13 @@ import { openAsBlob } from "node:fs";
|
|
|
2
2
|
import { isRecord } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Upload one local file directly to fal's CDN. The proxy hands us a
|
|
5
|
-
* presigned upload slot (upload_url + file_url) via the `
|
|
5
|
+
* presigned upload slot (upload_url + file_url) via the `generate.forward`
|
|
6
6
|
* storage target; bytes go straight from the client to fal, never
|
|
7
7
|
* through the worker. The returned file_url is a stable fal CDN URL
|
|
8
8
|
* that can be reused across runs without re-uploading.
|
|
9
9
|
*/
|
|
10
10
|
export async function uploadFile(client, file) {
|
|
11
|
-
const slot = await client.
|
|
11
|
+
const slot = await client.generate.forward.mutate({
|
|
12
12
|
target: "storage",
|
|
13
13
|
method: "POST",
|
|
14
14
|
path: "/storage/upload/initiate",
|
package/dist/lib/run.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import spawn from "cross-spawn";
|
|
2
|
+
export const run = (cmd, args) => new Promise((resolve) => {
|
|
3
|
+
const chunks = [];
|
|
4
|
+
const child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
5
|
+
child.stdout?.on("data", (c) => chunks.push(c));
|
|
6
|
+
child.stderr?.on("data", (c) => chunks.push(c));
|
|
7
|
+
child.on("error", (err) => resolve({ code: 1, output: `${err.message}\n` }));
|
|
8
|
+
child.on("close", (code) => resolve({ code: code ?? 1, output: Buffer.concat(chunks).toString("utf8") }));
|
|
9
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function markUpdateChecked(): void;
|
|
2
|
+
export declare function isNewerVersion(latest: string, current: string): boolean;
|
|
3
|
+
export declare function fetchLatestVersion(): Promise<string | null>;
|
|
4
|
+
/**
|
|
5
|
+
* Fire-and-forget background update: at most once per day (and never in CI
|
|
6
|
+
* or with VG_NO_AUTO_UPDATE set), re-invoke this CLI as a detached
|
|
7
|
+
* `vg update --auto`, which only applies anything when npm has a newer
|
|
8
|
+
* version. The foreground command pays no latency and prints nothing.
|
|
9
|
+
*/
|
|
10
|
+
export declare function maybeScheduleAutoUpdate(): void;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { getConfigDir } from "./config.js";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
6
|
+
const VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
7
|
+
function getCachePath() {
|
|
8
|
+
return join(getConfigDir(), "update-check.json");
|
|
9
|
+
}
|
|
10
|
+
function getLastCheckedAt() {
|
|
11
|
+
const path = getCachePath();
|
|
12
|
+
if (!existsSync(path))
|
|
13
|
+
return 0;
|
|
14
|
+
try {
|
|
15
|
+
const data = JSON.parse(readFileSync(path, "utf-8"));
|
|
16
|
+
if (typeof data === "object" && data !== null && "lastCheckedAt" in data) {
|
|
17
|
+
const ts = data.lastCheckedAt;
|
|
18
|
+
if (typeof ts === "number")
|
|
19
|
+
return ts;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// corrupt cache — treat as never checked
|
|
24
|
+
}
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
export function markUpdateChecked() {
|
|
28
|
+
const dir = getConfigDir();
|
|
29
|
+
try {
|
|
30
|
+
if (!existsSync(dir))
|
|
31
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
32
|
+
writeFileSync(getCachePath(), JSON.stringify({ lastCheckedAt: Date.now() }, null, 2));
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// best-effort; worst case we check again next run
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function isNewerVersion(latest, current) {
|
|
39
|
+
if (!VERSION_RE.test(latest) || !VERSION_RE.test(current))
|
|
40
|
+
return false;
|
|
41
|
+
const a = latest.split(".").map(Number);
|
|
42
|
+
const b = current.split(".").map(Number);
|
|
43
|
+
for (let i = 0; i < 3; i++) {
|
|
44
|
+
const left = a[i] ?? 0;
|
|
45
|
+
const right = b[i] ?? 0;
|
|
46
|
+
if (left > right)
|
|
47
|
+
return true;
|
|
48
|
+
if (left < right)
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
export async function fetchLatestVersion() {
|
|
54
|
+
const registry = process.env.VG_REGISTRY_URL ?? "https://registry.npmjs.org";
|
|
55
|
+
try {
|
|
56
|
+
const res = await fetch(`${registry}/vibedgames/latest`, {
|
|
57
|
+
signal: AbortSignal.timeout(5000),
|
|
58
|
+
});
|
|
59
|
+
if (!res.ok)
|
|
60
|
+
return null;
|
|
61
|
+
const data = await res.json();
|
|
62
|
+
if (typeof data === "object" && data !== null && "version" in data) {
|
|
63
|
+
const version = data.version;
|
|
64
|
+
if (typeof version === "string")
|
|
65
|
+
return version;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// offline or registry down — skip this round
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Fire-and-forget background update: at most once per day (and never in CI
|
|
75
|
+
* or with VG_NO_AUTO_UPDATE set), re-invoke this CLI as a detached
|
|
76
|
+
* `vg update --auto`, which only applies anything when npm has a newer
|
|
77
|
+
* version. The foreground command pays no latency and prints nothing.
|
|
78
|
+
*/
|
|
79
|
+
export function maybeScheduleAutoUpdate() {
|
|
80
|
+
if (process.env.VG_NO_AUTO_UPDATE || process.env.CI)
|
|
81
|
+
return;
|
|
82
|
+
const script = process.argv[1];
|
|
83
|
+
if (!script)
|
|
84
|
+
return;
|
|
85
|
+
if (Date.now() - getLastCheckedAt() < CHECK_INTERVAL_MS)
|
|
86
|
+
return;
|
|
87
|
+
markUpdateChecked();
|
|
88
|
+
try {
|
|
89
|
+
const child = spawn(process.execPath, [script, "update", "--auto"], {
|
|
90
|
+
detached: true,
|
|
91
|
+
stdio: "ignore",
|
|
92
|
+
});
|
|
93
|
+
child.unref();
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// best-effort; worst case we try again next run
|
|
97
|
+
}
|
|
98
|
+
}
|