vibedgames 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +3 -2
  2. package/assets/align-framing.py +242 -0
  3. package/assets/render-model.py +406 -0
  4. package/assets/tilemap-editor.html +630 -0
  5. package/dist/THIRD_PARTY_NOTICES.txt +2 -2
  6. package/dist/{chunk-56OY4TEP.js → chunk-2SBBKY5C.js} +1361 -4493
  7. package/dist/{chunk-FC233UKH.js → chunk-2ZKS7V72.js} +16 -16
  8. package/dist/chunk-37LLKM73.js +124 -0
  9. package/dist/{chunk-BMTHAVMS.js → chunk-3HGBIUM5.js} +22 -19
  10. package/dist/chunk-3UGGMFJJ.js +22 -0
  11. package/dist/{chunk-3HUWAJQH.js → chunk-42K3BJJH.js} +93 -76
  12. package/dist/{chunk-ST5FC2W3.js → chunk-43P4U7CB.js} +20 -11
  13. package/dist/chunk-4RYTTD4D.js +53 -0
  14. package/dist/{chunk-WSRIF6K4.js → chunk-4UU622RK.js} +5 -4
  15. package/dist/chunk-52E6EKZV.js +72 -0
  16. package/dist/chunk-6IUFHPMV.js +62 -0
  17. package/dist/chunk-6KXXZXSO.js +475 -0
  18. package/dist/chunk-72KHWZMN.js +87 -0
  19. package/dist/{chunk-ZCYWDKYP.js → chunk-A556KALN.js} +14 -13
  20. package/dist/{chunk-UFR6G6BL.js → chunk-ABTUEIRC.js} +554 -254
  21. package/dist/chunk-ALPTHSUT.js +132 -0
  22. package/dist/{chunk-PEUP4MZR.js → chunk-AWJNAGPE.js} +6 -3
  23. package/dist/chunk-BJAN3RMY.js +48 -0
  24. package/dist/{chunk-HNRVSBRK.js → chunk-BN3Q7UEC.js} +20 -17
  25. package/dist/chunk-BZOMEG3X.js +412 -0
  26. package/dist/{chunk-ZYCSYJWX.js → chunk-COSLGSVO.js} +14 -24
  27. package/dist/{chunk-KZBZNTM4.js → chunk-CTY2WZQK.js} +9 -13
  28. package/dist/chunk-DH6WPL3X.js +47 -0
  29. package/dist/chunk-DPLFCKXP.js +80 -0
  30. package/dist/{chunk-K2U7L4RU.js → chunk-E3FJUPLT.js} +15 -21
  31. package/dist/chunk-E7NDOZ27.js +428 -0
  32. package/dist/{chunk-TBQ5BU3Q.js → chunk-F42QKWBB.js} +18 -18
  33. package/dist/chunk-F4J6XCHT.js +73 -0
  34. package/dist/chunk-FB3UDZAV.js +168 -0
  35. package/dist/chunk-FJXPMA63.js +48 -0
  36. package/dist/chunk-FNJL6Z5C.js +71 -0
  37. package/dist/chunk-G63MXDX2.js +45 -0
  38. package/dist/{chunk-VFFOT7KD.js → chunk-G66HRVDW.js} +1 -1
  39. package/dist/{chunk-AXTLPJ2F.js → chunk-H2C4QUTG.js} +8 -7
  40. package/dist/{chunk-H3IPLBXQ.js → chunk-HRKVAXNN.js} +17 -14
  41. package/dist/chunk-HSCTPDEU.js +126 -0
  42. package/dist/{chunk-UXCWSWWX.js → chunk-HSMG6U7J.js} +8 -7
  43. package/dist/chunk-I5LELJSK.js +22 -0
  44. package/dist/{chunk-7CXMMC5S.js → chunk-JN4WZCR7.js} +5 -4
  45. package/dist/{chunk-7QZSDU52.js → chunk-K36EOII3.js} +5 -4
  46. package/dist/chunk-KLFBAFXD.js +25 -0
  47. package/dist/{chunk-355VG7EO.js → chunk-LONQWRTR.js} +107 -77
  48. package/dist/{chunk-Z5TFZQ5U.js → chunk-LORGE2NB.js} +68 -62
  49. package/dist/{chunk-LY2GQ32S.js → chunk-MEAO33XW.js} +22 -20
  50. package/dist/{chunk-OD2MNYXD.js → chunk-MR5KIFI7.js} +23 -22
  51. package/dist/{chunk-2VUUMXAQ.js → chunk-N2UHAQXC.js} +18 -11
  52. package/dist/chunk-NG2X3SMF.js +91 -0
  53. package/dist/chunk-OFJIG4K3.js +6482 -0
  54. package/dist/chunk-P74GTK23.js +91 -0
  55. package/dist/chunk-PKM3JOKQ.js +62 -0
  56. package/dist/{chunk-NDHXM4PL.js → chunk-Q3XQPNF6.js} +12 -12
  57. package/dist/{chunk-RXHTGX7C.js → chunk-Q5NZNXJE.js} +6 -10
  58. package/dist/chunk-QEKVZ7BX.js +57 -0
  59. package/dist/chunk-QNWCBPVO.js +215 -0
  60. package/dist/{chunk-US6QZICZ.js → chunk-RPJR3S5S.js} +32 -18
  61. package/dist/chunk-RPSUFZAG.js +3307 -0
  62. package/dist/chunk-RRI23NK2.js +40 -0
  63. package/dist/{chunk-6EWHKL7Z.js → chunk-SXYQL4GK.js} +7 -6
  64. package/dist/{chunk-ZI6PKVXG.js → chunk-TMPBGXT4.js} +6 -5
  65. package/dist/{chunk-UZM6OSW5.js → chunk-UPHB5HWO.js} +15 -13
  66. package/dist/chunk-UTSSDFQL.js +64 -0
  67. package/dist/chunk-V5ADM3WC.js +741 -0
  68. package/dist/{chunk-25BAMW5X.js → chunk-VIEKOGKG.js} +18 -2
  69. package/dist/chunk-VUV5U4J5.js +117 -0
  70. package/dist/{chunk-LXS3NJYD.js → chunk-VZEJ2ZHE.js} +14 -15
  71. package/dist/chunk-W2QPNAZ3.js +58 -0
  72. package/dist/chunk-YLUB6252.js +45 -0
  73. package/dist/{chunk-Z4Z24FWO.js → chunk-YNCYMWER.js} +8 -5
  74. package/dist/chunk-YXOGRERG.js +91 -0
  75. package/dist/index.js +39 -36
  76. package/package.json +31 -16
  77. package/templates/none/src/main.ts +4 -0
  78. package/templates/none/vite.config.ts +0 -2
  79. package/templates/phaser/src/main.ts +0 -1
  80. package/templates/phaser/src/scenes/game-scene.ts +10 -8
  81. package/templates/phaser/vite.config.ts +0 -2
  82. package/templates/react-r3f/src/app.tsx +3 -1
  83. package/templates/react-r3f/src/main.tsx +1 -0
  84. package/templates/react-r3f/vite.config.ts +0 -2
  85. package/templates/threejs/src/main.ts +10 -1
  86. package/templates/threejs/vite.config.ts +0 -2
  87. package/LICENSE +0 -21
  88. package/dist/chunk-J6PKNPI2.js +0 -26
@@ -7,12 +7,13 @@ var __dirname = __pathDirname(__filename);
7
7
  import {
8
8
  getConfig,
9
9
  saveConfig
10
- } from "./chunk-RXHTGX7C.js";
10
+ } from "./chunk-Q5NZNXJE.js";
11
11
  import {
12
12
  isJsonNumber,
13
13
  isJsonObject,
14
- isJsonString
15
- } from "./chunk-J6PKNPI2.js";
14
+ isJsonString,
15
+ parseJson
16
+ } from "./chunk-RPSUFZAG.js";
16
17
 
17
18
  // ../../packages/contract/src/auth/oauth-scopes.ts
18
19
  var OAUTH_SCOPES = {
@@ -43,7 +44,7 @@ var authUrl = (baseUrl, path) => `${new URL(baseUrl).origin}/api/auth${path}`;
43
44
  var OAuthError = class extends Error {
44
45
  code;
45
46
  constructor(code, description) {
46
- super(description ? `${code}: ${description}` : code);
47
+ super(description !== void 0 && description !== "" ? `${code}: ${description}` : code);
47
48
  this.code = code;
48
49
  this.name = "OAuthError";
49
50
  }
@@ -54,11 +55,7 @@ var postForm = async (url, body) => {
54
55
  headers: { accept: "application/json" },
55
56
  method: "POST"
56
57
  });
57
- let data = null;
58
- try {
59
- data = await res.json();
60
- } catch {
61
- }
58
+ const data = await res.text().then(parseJson).catch(() => null);
62
59
  if (!isJsonObject(data)) {
63
60
  throw new OAuthError("server_error", `HTTP ${res.status}`);
64
61
  }
@@ -117,7 +114,7 @@ var pollDeviceToken = async (baseUrl, deviceCode) => toConfig(
117
114
  grant_type: DEVICE_CODE_GRANT_TYPE
118
115
  })
119
116
  );
120
- var needsRefresh = (config, now = Date.now()) => Boolean(config.refreshToken && config.expiresAt && config.expiresAt - EXPIRY_MARGIN_MS <= now);
117
+ var needsRefresh = (config, now = Date.now()) => config.refreshToken !== void 0 && config.refreshToken !== "" && config.expiresAt !== void 0 && config.expiresAt !== 0 && config.expiresAt - EXPIRY_MARGIN_MS <= now;
121
118
  var refresh = async (config) => {
122
119
  const next = toConfig(
123
120
  config.baseUrl,
@@ -134,14 +131,14 @@ var refresh = async (config) => {
134
131
  };
135
132
  var refreshing = null;
136
133
  var getAccessToken = async () => {
137
- if (process.env.VG_TOKEN) {
134
+ if (process.env.VG_TOKEN !== void 0 && process.env.VG_TOKEN !== "") {
138
135
  return process.env.VG_TOKEN;
139
136
  }
140
137
  const config = getConfig();
141
138
  if (!config) {
142
139
  return null;
143
140
  }
144
- if (!needsRefresh(config) || !config.refreshToken) {
141
+ if (!needsRefresh(config) || config.refreshToken === void 0 || config.refreshToken === "") {
145
142
  return config.token;
146
143
  }
147
144
  refreshing ??= refresh({ ...config, refreshToken: config.refreshToken });
@@ -160,17 +157,14 @@ var getAccessToken = async () => {
160
157
  }
161
158
  };
162
159
  var revokeLogin = async (config) => {
163
- if (!config.refreshToken) {
160
+ if (config.refreshToken === void 0 || config.refreshToken === "") {
164
161
  return;
165
162
  }
166
- try {
167
- await postForm(authUrl(config.baseUrl, "/oauth2/revoke"), {
168
- client_id: CLI_OAUTH_CLIENT_ID,
169
- token: config.refreshToken,
170
- token_type_hint: "refresh_token"
171
- });
172
- } catch {
173
- }
163
+ await postForm(authUrl(config.baseUrl, "/oauth2/revoke"), {
164
+ client_id: CLI_OAUTH_CLIENT_ID,
165
+ token: config.refreshToken,
166
+ token_type_hint: "refresh_token"
167
+ }).catch(() => null);
174
168
  };
175
169
 
176
170
  export {
@@ -0,0 +1,428 @@
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
+ buildManifest,
9
+ resolveBuildDir
10
+ } from "./chunk-X75Y7LUW.js";
11
+ import {
12
+ packBuild,
13
+ packSource
14
+ } from "./chunk-42K3BJJH.js";
15
+ import "./chunk-G66HRVDW.js";
16
+ import {
17
+ SLUG_RE,
18
+ findProjectRoot,
19
+ projectConfigPath,
20
+ readProjectConfig,
21
+ writeProjectConfig
22
+ } from "./chunk-TMPBGXT4.js";
23
+ import {
24
+ assertKnownFlags
25
+ } from "./chunk-RZ4DIJQW.js";
26
+ import {
27
+ createClient
28
+ } from "./chunk-CTY2WZQK.js";
29
+ import "./chunk-E3FJUPLT.js";
30
+ import "./chunk-Q5NZNXJE.js";
31
+ import {
32
+ isJsonOutput,
33
+ outputArgs,
34
+ writeStructured
35
+ } from "./chunk-COSLGSVO.js";
36
+ import {
37
+ defineCommand
38
+ } from "./chunk-MBXCVCC4.js";
39
+ import {
40
+ consola
41
+ } from "./chunk-D2RF35HJ.js";
42
+ import "./chunk-YNCYMWER.js";
43
+ import "./chunk-AWJNAGPE.js";
44
+ import {
45
+ external_exports,
46
+ isJsonString
47
+ } from "./chunk-RPSUFZAG.js";
48
+ import "./chunk-2SBBKY5C.js";
49
+ import "./chunk-GKDUYJ7R.js";
50
+
51
+ // src/commands/deploy.ts
52
+ import { existsSync, readFileSync as readFileSync2, rmSync } from "node:fs";
53
+ import { tmpdir } from "node:os";
54
+ import path from "node:path";
55
+
56
+ // ../../packages/contract/src/deploy/deploy-schema.ts
57
+ var MAX_FILE_SIZE = 10 * 1024 * 1024;
58
+ var MAX_TOTAL_SIZE = 200 * 1024 * 1024;
59
+ var MAX_FILE_COUNT = 500;
60
+ var MAX_SOURCE_SIZE = 100 * 1024 * 1024;
61
+ var MAX_UPLOAD_BODY = 100 * 1024 * 1024;
62
+ var slugSchema = external_exports.string().min(3).max(40).regex(/^[a-z0-9][a-z0-9-]*[a-z0-9]$/u, {
63
+ message: "slug must be lowercase alphanumeric with hyphens"
64
+ });
65
+ var fileSchema = external_exports.object({
66
+ contentType: external_exports.string().min(1).max(127),
67
+ path: external_exports.string().min(1).max(512).refine((p) => !p.startsWith("/"), "path must be relative").refine((p) => !p.includes(".."), "path must not contain ..").describe(
68
+ "The file's path from the game's root, e.g. `index.html` or `assets/hero.png`; no leading `/` and no `..`"
69
+ ),
70
+ sha256: external_exports.string().length(64).describe("The SHA-256 of the file's bytes as 64 hex characters, as `sha256sum` prints it"),
71
+ size: external_exports.number().int().nonnegative().max(MAX_FILE_SIZE).describe(
72
+ `The file's exact size in bytes, at most ${MAX_FILE_SIZE} (10 MB); publish checks the uploaded file has this size`
73
+ )
74
+ });
75
+ var createInput = external_exports.object({
76
+ files: external_exports.array(fileSchema).min(1).max(MAX_FILE_COUNT),
77
+ name: external_exports.string().max(120).optional(),
78
+ slug: slugSchema,
79
+ source: external_exports.object({
80
+ bytes: external_exports.number().int().positive().max(MAX_SOURCE_SIZE),
81
+ sha256: external_exports.string().length(64)
82
+ }).optional()
83
+ });
84
+ var finalizeInput = external_exports.object({
85
+ deploymentId: external_exports.string()
86
+ });
87
+ var deleteInput = external_exports.object({
88
+ gameId: external_exports.string().describe(
89
+ "The id of one of your games: a game's `id` in the deployments list, or the `gameId` deploy returned"
90
+ )
91
+ });
92
+ var getSourceInput = external_exports.object({
93
+ slug: slugSchema.describe(
94
+ "The slug of the game to fork, as in its address `{slug}.vibedgames.com`, e.g. `space-pong`; any game deployed with source can be forked"
95
+ )
96
+ });
97
+ var inlineFileSchema = external_exports.object({
98
+ content: external_exports.string().describe("The file's text, or with `encoding: url` a generated asset's URL"),
99
+ contentType: external_exports.string().min(1).max(127).optional().describe(
100
+ "The MIME type to serve the file with, e.g. `text/html; charset=utf-8`; omit to infer it from the path's extension"
101
+ ),
102
+ encoding: external_exports.enum(["utf-8", "url"]).default("utf-8").describe(
103
+ "How to read `content`: `utf-8` (the default) stores it as the file's text; `url` fetches it from a URL a generate tool returned (other hosts are refused), up to 10 MB a file and 32 MB a call"
104
+ ),
105
+ path: fileSchema.shape.path
106
+ });
107
+ var presignedFileSchema = fileSchema.extend({
108
+ contentType: fileSchema.shape.contentType.optional().describe(
109
+ "The MIME type to serve the file with, and the Content-Type to PUT it with, e.g. `image/png`; omit to infer it from the path's extension"
110
+ )
111
+ });
112
+ var uploadInput = external_exports.object({
113
+ bundle: external_exports.boolean().default(false).describe(
114
+ "true returns a `bundleUpload` URL to PUT the whole built game to as one gzipped tar, `index.html` at its root (`tar -czf game.tgz -C dist .`); a later call with `publish: true` unpacks it. The usual way in. Default false"
115
+ ),
116
+ deploymentId: external_exports.string().optional().describe(
117
+ "The `deploymentId` an earlier deploy call for this slug returned, to add files to that staged deployment or publish it; omit to stage a new one"
118
+ ),
119
+ files: external_exports.array(inlineFileSchema).max(MAX_FILE_COUNT).default([]).describe(
120
+ "Files sent in the call itself: text, or a generated asset's URL with `encoding: url`. A path already staged is replaced. Default none"
121
+ ),
122
+ name: external_exports.string().max(120).optional().describe(
123
+ "The game's display name, up to 120 characters, e.g. `Space Pong`; omit to keep the name it has"
124
+ ),
125
+ presign: external_exports.array(presignedFileSchema).max(MAX_FILE_COUNT).default([]).describe(
126
+ "Files you PUT yourself: each returns a signed URL in `uploads`, valid 15 minutes, to PUT its bytes to with the `headers` given; list a file again to renew its URL. Default none"
127
+ ),
128
+ publish: external_exports.boolean().default(false).describe(
129
+ "true makes the staged deployment live at `{slug}.vibedgames.com` once this call's files are in (it needs `index.html` and every presigned file at its declared size), then removes the previous one. Default false: the files stay staged"
130
+ ),
131
+ slug: slugSchema.describe(
132
+ "The game's slug, which makes its address `{slug}.vibedgames.com`: 3 to 40 lowercase letters, digits and hyphens, no hyphen at either end, e.g. `space-pong`. A new slug becomes your game, one another account owns is refused; pass the same one on every call of a deployment"
133
+ ),
134
+ source: external_exports.boolean().default(false).describe(
135
+ "With `publish: true`, also keep the deployment's files (up to 64 MB) as the game's forkable source, which fork downloads. Default false; not with `sourceArchive`"
136
+ ),
137
+ sourceArchive: external_exports.object({
138
+ bytes: external_exports.number().int().positive().max(MAX_SOURCE_SIZE).describe(
139
+ `The archive's exact size in bytes, at most ${MAX_SOURCE_SIZE} (100 MB); publish checks the upload has this size`
140
+ ),
141
+ sha256: external_exports.string().length(64).describe("The SHA-256 of the archive's bytes as 64 hex characters")
142
+ }).optional().describe(
143
+ "Your own forkable source archive (a .tar.gz of the project, what `vg deploy --source` packs), which you PUT to the `sourceUpload` URL this call returns; omit for none. Not with `source: true`"
144
+ )
145
+ });
146
+
147
+ // src/lib/upload.ts
148
+ import { readFileSync } from "node:fs";
149
+ var uploadAll = async ({
150
+ files,
151
+ uploads,
152
+ concurrency = 6,
153
+ onProgress
154
+ }) => {
155
+ const byPath = new Map(files.map((f) => [f.path, f]));
156
+ let done = 0;
157
+ let cursor = 0;
158
+ const worker = async () => {
159
+ const idx = cursor;
160
+ cursor += 1;
161
+ if (idx >= uploads.length) {
162
+ return;
163
+ }
164
+ const upload = uploads[idx];
165
+ if (!upload) {
166
+ return;
167
+ }
168
+ const file = byPath.get(upload.path);
169
+ if (!file) {
170
+ throw new Error(`Missing file for upload target: ${upload.path}`);
171
+ }
172
+ const body = readFileSync(file.absolutePath);
173
+ const res = await fetch(upload.url, {
174
+ body,
175
+ headers: upload.headers,
176
+ method: "PUT"
177
+ });
178
+ if (!res.ok) {
179
+ const text = await res.text().catch(() => "");
180
+ throw new Error(`Upload failed for ${upload.path}: ${res.status} ${res.statusText} ${text}`);
181
+ }
182
+ done += 1;
183
+ onProgress?.(done, uploads.length);
184
+ await worker();
185
+ };
186
+ const workers = Array.from({ length: Math.min(concurrency, uploads.length) }, async () => {
187
+ await worker();
188
+ });
189
+ await Promise.all(workers);
190
+ };
191
+
192
+ // src/commands/deploy.ts
193
+ var deployArgs = {
194
+ dir: {
195
+ default: ".",
196
+ description: "Directory to deploy",
197
+ required: false,
198
+ type: "positional"
199
+ },
200
+ slug: {
201
+ description: "Override the slug (bypasses vibedgames.json)",
202
+ required: false,
203
+ type: "string"
204
+ },
205
+ source: {
206
+ default: false,
207
+ description: "Also upload a forkable source archive, letting anyone logged in fork the project.",
208
+ type: "boolean"
209
+ },
210
+ ...outputArgs
211
+ };
212
+ var formatBytes = (n) => {
213
+ if (n < 1024) {
214
+ return `${n} B`;
215
+ }
216
+ if (n < 1024 * 1024) {
217
+ return `${(n / 1024).toFixed(1)} KB`;
218
+ }
219
+ return `${(n / (1024 * 1024)).toFixed(1)} MB`;
220
+ };
221
+ var resolveDeployDir = (dir, say) => {
222
+ const build = resolveBuildDir(dir);
223
+ if (build.kind === "build") {
224
+ say(`Project root detected \u2014 deploying its build output ${build.name}/ instead.`);
225
+ } else if (build.kind === "unbuilt") {
226
+ consola.warn(
227
+ "This looks like an unbuilt project (package.json, no dist/build/out) \u2014 run the build first, or the deployed index.html will reference missing source files."
228
+ );
229
+ }
230
+ return build.dir;
231
+ };
232
+ var promptForConfig = async (dir, say) => {
233
+ if (!process.stdin.isTTY) {
234
+ consola.error(
235
+ "No slug specified and no vibedgames.json found.\n Pass --slug <name> when running without a TTY (e.g. in CI or from a coding agent).\n Example: vg deploy ./dist --slug my-game"
236
+ );
237
+ process.exit(1);
238
+ }
239
+ const slug = await consola.prompt("Slug (e.g. pong):", { type: "text" });
240
+ if (!isJsonString(slug) || !SLUG_RE.test(slug)) {
241
+ consola.error("Invalid slug. Use lowercase letters, digits, hyphens.");
242
+ process.exit(1);
243
+ }
244
+ const name = await consola.prompt("Name (optional):", { type: "text" });
245
+ const config = {
246
+ name: isJsonString(name) && name.length > 0 ? name : void 0,
247
+ slug
248
+ };
249
+ writeProjectConfig(dir, config);
250
+ say(`Wrote ${projectConfigPath(dir)}`);
251
+ return config;
252
+ };
253
+ var resolveDeployConfig = async (dir, slugOverride, say) => {
254
+ let config = null;
255
+ try {
256
+ config = readProjectConfig(dir);
257
+ } catch (error) {
258
+ consola.error(error instanceof Error ? error.message : String(error));
259
+ process.exit(1);
260
+ }
261
+ if (slugOverride !== void 0 && slugOverride !== "") {
262
+ config = { name: config?.name, slug: slugOverride };
263
+ }
264
+ config ??= await promptForConfig(dir, say);
265
+ if (!SLUG_RE.test(config.slug)) {
266
+ consola.error(`Invalid slug in vibedgames.json: ${config.slug}`);
267
+ process.exit(1);
268
+ }
269
+ return config;
270
+ };
271
+ var packForkableSource = async (dir, slug, say) => {
272
+ const root = findProjectRoot(dir);
273
+ if (root === null || root === "") {
274
+ consola.warn("No vibedgames.json found above the deploy dir \u2014 skipping source upload.");
275
+ return null;
276
+ }
277
+ try {
278
+ const archive = await packSource(root, path.join(tmpdir(), "vibedgames"));
279
+ say(
280
+ `Source: ${archive.files.length} files, ${formatBytes(archive.bytes)} \u2014 forkable via \`vg fork ${slug}\``
281
+ );
282
+ return archive;
283
+ } catch (error) {
284
+ consola.error(
285
+ `Source archive failed: ${error instanceof Error ? error.message : String(error)}`
286
+ );
287
+ return process.exit(1);
288
+ }
289
+ };
290
+ var putArchive = async (archivePath, upload, what) => {
291
+ const res = await fetch(upload.url, {
292
+ body: readFileSync2(archivePath),
293
+ headers: upload.headers,
294
+ method: "PUT"
295
+ });
296
+ if (!res.ok) {
297
+ throw new Error(`${what} upload failed: ${res.status} ${res.statusText}`);
298
+ }
299
+ };
300
+ var publishDeployment = async (client, { deploymentId, slug }) => {
301
+ try {
302
+ const published = await client.deploy.upload({ deploymentId, publish: true, slug });
303
+ if (published.url === null) {
304
+ throw new Error("The deployment did not publish.");
305
+ }
306
+ return { url: published.url };
307
+ } catch (error) {
308
+ consola.error(error instanceof Error ? error.message : String(error));
309
+ return process.exit(1);
310
+ }
311
+ };
312
+ var deployCommand = defineCommand({
313
+ args: deployArgs,
314
+ meta: {
315
+ description: "Deploy a game to vibedgames",
316
+ name: "deploy"
317
+ },
318
+ run: async ({ args, rawArgs }) => {
319
+ assertKnownFlags(rawArgs, deployArgs);
320
+ const structured = isJsonOutput(args) || Boolean(args.field);
321
+ const say = structured ? () => null : (message) => {
322
+ consola.info(message);
323
+ };
324
+ const dir = path.resolve(args.dir);
325
+ if (!existsSync(dir)) {
326
+ consola.error(`Directory does not exist: ${dir}`);
327
+ process.exit(1);
328
+ }
329
+ const deployDir = resolveDeployDir(dir, say);
330
+ const config = await resolveDeployConfig(dir, args.slug, say);
331
+ const manifest = buildManifest(deployDir);
332
+ if (manifest.length === 0) {
333
+ consola.error(`No files found in ${deployDir}`);
334
+ process.exit(1);
335
+ }
336
+ const hasIndex = manifest.some((f) => f.path === "index.html");
337
+ if (!hasIndex) {
338
+ consola.error("Deployment must contain an index.html at the root.");
339
+ process.exit(1);
340
+ }
341
+ const totalBytes = manifest.reduce((acc, f) => acc + f.size, 0);
342
+ say(`Deploying ${config.slug}: ${manifest.length} files, ${formatBytes(totalBytes)}`);
343
+ const sourceArchive = args.source ? await packForkableSource(dir, config.slug, say) : null;
344
+ const tmp = path.join(tmpdir(), "vibedgames");
345
+ const bundle = await packBuild(
346
+ deployDir,
347
+ manifest.map((f) => f.path),
348
+ tmp
349
+ );
350
+ const cleanUp = () => {
351
+ rmSync(bundle.path, { force: true });
352
+ if (sourceArchive) {
353
+ rmSync(sourceArchive.path, { force: true });
354
+ }
355
+ };
356
+ const client = createClient();
357
+ const started = Date.now();
358
+ const asBundle = bundle.bytes <= MAX_UPLOAD_BODY;
359
+ let created;
360
+ try {
361
+ created = await client.deploy.upload({
362
+ bundle: asBundle,
363
+ name: config.name,
364
+ presign: asBundle ? [] : manifest.map((f) => ({
365
+ contentType: f.contentType,
366
+ path: f.path,
367
+ sha256: f.sha256,
368
+ size: f.size
369
+ })),
370
+ slug: config.slug,
371
+ sourceArchive: sourceArchive ? { bytes: sourceArchive.bytes, sha256: sourceArchive.sha256 } : void 0
372
+ });
373
+ if (!structured) {
374
+ consola.start(
375
+ asBundle ? `Uploading ${formatBytes(bundle.bytes)}` : `Uploading ${manifest.length} files (too large for one bundle)`
376
+ );
377
+ }
378
+ if (asBundle) {
379
+ if (!created.bundleUpload) {
380
+ throw new Error("The server returned no bundle upload URL.");
381
+ }
382
+ await putArchive(bundle.path, created.bundleUpload, "bundle");
383
+ } else {
384
+ await uploadAll({
385
+ files: manifest,
386
+ onProgress: (done, total) => {
387
+ if (done === total || done % 10 === 0) {
388
+ say(`Uploaded ${done}/${total}`);
389
+ }
390
+ },
391
+ uploads: created.uploads
392
+ });
393
+ }
394
+ if (sourceArchive && created.sourceUpload) {
395
+ await putArchive(sourceArchive.path, created.sourceUpload, "source");
396
+ }
397
+ } catch (error) {
398
+ cleanUp();
399
+ consola.error(error instanceof Error ? error.message : String(error));
400
+ process.exit(1);
401
+ }
402
+ cleanUp();
403
+ const published = await publishDeployment(client, {
404
+ deploymentId: created.deploymentId,
405
+ slug: config.slug
406
+ });
407
+ const elapsedMs = Date.now() - started;
408
+ if (writeStructured(
409
+ {
410
+ bytes: totalBytes,
411
+ deployment_id: created.deploymentId,
412
+ elapsed_ms: elapsedMs,
413
+ files: manifest.length,
414
+ slug: config.slug,
415
+ source: sourceArchive ? { bytes: sourceArchive.bytes, files: sourceArchive.files.length } : null,
416
+ url: published.url
417
+ },
418
+ args
419
+ )) {
420
+ return;
421
+ }
422
+ consola.success(`Deployed ${config.slug} in ${(elapsedMs / 1e3).toFixed(1)}s`);
423
+ consola.log(` ${published.url}`);
424
+ }
425
+ });
426
+ export {
427
+ deployCommand
428
+ };
@@ -14,24 +14,24 @@ import {
14
14
  // src/lib/run.ts
15
15
  var import_cross_spawn = __toESM(require_cross_spawn(), 1);
16
16
  var isMissingCommand = (result) => result.code !== 0 && /ENOENT|not found|not recognized/iu.test(result.output);
17
- var run = (cmd, args, cwd) => (
18
- // oxlint-disable-next-line promise/avoid-new -- child_process.spawn is event-based
19
- new Promise((resolve) => {
20
- const chunks = [];
21
- const child = (0, import_cross_spawn.default)(cmd, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
22
- const collect = (c) => {
23
- chunks.push(c);
24
- };
25
- child.stdout?.on("data", collect);
26
- child.stderr?.on("data", collect);
27
- child.on("error", (err) => resolve({ code: 1, output: `${err.message}
28
- ` }));
29
- child.on(
30
- "close",
31
- (code) => resolve({ code: code ?? 1, output: Buffer.concat(chunks).toString("utf-8") })
32
- );
33
- })
34
- );
17
+ var run = async (cmd, args, cwd) => {
18
+ const { promise, resolve } = Promise.withResolvers();
19
+ const chunks = [];
20
+ const child = (0, import_cross_spawn.default)(cmd, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
21
+ const collect = (c) => {
22
+ chunks.push(c);
23
+ };
24
+ child.stdout?.on("data", collect);
25
+ child.stderr?.on("data", collect);
26
+ child.on("error", (err) => {
27
+ resolve({ code: 1, output: `${err.message}
28
+ ` });
29
+ });
30
+ child.on("close", (code) => {
31
+ resolve({ code: code ?? 1, output: Buffer.concat(chunks).toString("utf-8") });
32
+ });
33
+ return await promise;
34
+ };
35
35
 
36
36
  export {
37
37
  isMissingCommand,
@@ -0,0 +1,73 @@
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
+ buildSequenceGif,
9
+ fail,
10
+ failUsage,
11
+ getString,
12
+ main,
13
+ parseArgs,
14
+ parseColor
15
+ } from "./chunk-OFJIG4K3.js";
16
+ import "./chunk-2SBBKY5C.js";
17
+ import "./chunk-GKDUYJ7R.js";
18
+
19
+ // src/commands/asset/build-sequence-gif.ts
20
+ import { mkdirSync, writeFileSync } from "node:fs";
21
+ import path from "node:path";
22
+ var run = (argv) => {
23
+ main(() => {
24
+ const args = parseArgs([...argv], {
25
+ values: ["durations-ms", "flat-bg", "input-dir", "order", "out", "pattern"]
26
+ });
27
+ const inputDir = getString(args, "input-dir") ?? "";
28
+ const order = getString(args, "order") ?? "";
29
+ const out = getString(args, "out") ?? "";
30
+ if (inputDir === "") {
31
+ failUsage("--input-dir is required");
32
+ }
33
+ if (order === "") {
34
+ failUsage("--order is required, e.g. --order 01,03,02,04");
35
+ }
36
+ if (out === "") {
37
+ failUsage("--out is required");
38
+ }
39
+ const ids = order.split(",").map((part) => part.trim()).filter(Boolean);
40
+ if (ids.length === 0) {
41
+ fail("No frames selected");
42
+ }
43
+ const pattern = getString(args, "pattern") ?? "frame-{id}.png";
44
+ const durationsSpec = getString(args, "durations-ms") ?? "";
45
+ let durations = null;
46
+ if (durationsSpec !== "") {
47
+ durations = durationsSpec.split(",").map((part) => part.trim()).filter(Boolean).map(Number);
48
+ if (durations.length !== ids.length) {
49
+ fail("durations-ms length must match frame order length");
50
+ }
51
+ }
52
+ const flatBg = getString(args, "flat-bg") ?? "";
53
+ const frames = ids.map((id, i) => ({
54
+ delayMs: durations?.[i] ?? 120,
55
+ path: path.resolve(inputDir, pattern.replace("{id}", id))
56
+ }));
57
+ let gif;
58
+ try {
59
+ gif = buildSequenceGif(frames, flatBg === "" ? null : parseColor(flatBg));
60
+ } catch (error) {
61
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
62
+ fail(`frame file not found: ${"path" in error ? String(error.path) : "undefined"}`);
63
+ }
64
+ throw error;
65
+ }
66
+ mkdirSync(path.dirname(path.resolve(out)), { recursive: true });
67
+ writeFileSync(out, gif);
68
+ console.log(out);
69
+ });
70
+ };
71
+ export {
72
+ run
73
+ };