vibedgames 0.0.6 → 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 +14 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/commands/completions.js +21 -18
- package/dist/commands/generate.d.ts +1 -0
- package/dist/commands/{media.js → generate.js} +18 -18
- 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 +11 -2
- package/dist/lib/config.d.ts +1 -0
- package/dist/lib/config.js +1 -1
- package/dist/lib/media-args.d.ts +4 -4
- package/dist/lib/media-args.js +6 -12
- package/dist/lib/media-download.js +21 -3
- package/dist/lib/media-poll.d.ts +1 -1
- package/dist/lib/media-poll.js +6 -6
- 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
- package/dist/commands/media.d.ts +0 -1
|
@@ -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
|
+
}
|
package/package.json
CHANGED
package/dist/commands/media.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const mediaCommand: import("citty").CommandDef<import("citty").ArgsDef>;
|