@replaystage/cli 0.4.1 → 0.5.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 +16 -6
- package/dist/index.d.ts +15 -2
- package/dist/index.js +502 -140
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,6 +5,9 @@ var __export = (target, all) => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
8
|
+
import fs7 from "fs";
|
|
9
|
+
import path7 from "path";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
8
11
|
import { Command } from "commander";
|
|
9
12
|
|
|
10
13
|
// src/commands/auth.ts
|
|
@@ -12,20 +15,70 @@ import { text } from "@clack/prompts";
|
|
|
12
15
|
import pc2 from "picocolors";
|
|
13
16
|
|
|
14
17
|
// src/client.ts
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
function resolvePlayableUrl(apiUrl, result, fallbackSlug) {
|
|
19
|
+
const cleanApiUrl = (apiUrl || "https://replaystage.com").replace(/\/+$/, "");
|
|
20
|
+
if (result.fullUrl) {
|
|
21
|
+
return result.fullUrl.startsWith("http") ? result.fullUrl : `${cleanApiUrl}${result.fullUrl.startsWith("/") ? result.fullUrl : `/${result.fullUrl}`}`;
|
|
22
|
+
}
|
|
23
|
+
if (result.url?.startsWith("http")) {
|
|
24
|
+
return result.url;
|
|
25
|
+
}
|
|
26
|
+
const relPath = result.url || `/g/${result.slug || fallbackSlug || ""}`;
|
|
27
|
+
const normalizedRel = relPath.startsWith("/") ? relPath : `/${relPath}`;
|
|
28
|
+
return `${cleanApiUrl}${normalizedRel}`;
|
|
29
|
+
}
|
|
30
|
+
function extractFieldErrors(data) {
|
|
31
|
+
const rawFieldErrors = data?.error?.details?.fieldErrors ?? data?.details?.fieldErrors ?? data?.error?.fieldErrors ?? data?.fieldErrors;
|
|
32
|
+
if (!rawFieldErrors || typeof rawFieldErrors !== "object") {
|
|
33
|
+
return void 0;
|
|
18
34
|
}
|
|
19
|
-
|
|
20
|
-
|
|
35
|
+
const cleaned = {};
|
|
36
|
+
for (const [field, msgs] of Object.entries(rawFieldErrors)) {
|
|
37
|
+
if (Array.isArray(msgs)) {
|
|
38
|
+
const strs = msgs.filter((m) => typeof m === "string" && m.trim().length > 0);
|
|
39
|
+
if (strs.length > 0) cleaned[field] = strs;
|
|
40
|
+
} else if (typeof msgs === "string" && msgs.trim().length > 0) {
|
|
41
|
+
cleaned[field] = [msgs.trim()];
|
|
42
|
+
}
|
|
21
43
|
}
|
|
22
|
-
|
|
23
|
-
|
|
44
|
+
return Object.keys(cleaned).length > 0 ? cleaned : void 0;
|
|
45
|
+
}
|
|
46
|
+
function formatValidationDetails(data) {
|
|
47
|
+
const parts = [];
|
|
48
|
+
const rawFormErrors = data?.error?.details?.formErrors ?? data?.details?.formErrors ?? data?.formErrors;
|
|
49
|
+
if (Array.isArray(rawFormErrors)) {
|
|
50
|
+
for (const msg of rawFormErrors) {
|
|
51
|
+
if (typeof msg === "string" && msg.trim()) {
|
|
52
|
+
parts.push(msg.trim());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
24
55
|
}
|
|
25
|
-
|
|
26
|
-
|
|
56
|
+
const fieldErrors = extractFieldErrors(data);
|
|
57
|
+
if (fieldErrors) {
|
|
58
|
+
for (const [field, msgs] of Object.entries(fieldErrors)) {
|
|
59
|
+
parts.push(`${field}: ${msgs.join(", ")}`);
|
|
60
|
+
}
|
|
27
61
|
}
|
|
28
|
-
return
|
|
62
|
+
return parts.join("; ");
|
|
63
|
+
}
|
|
64
|
+
function extractErrorMessage(data, fallback, statusText, statusCode) {
|
|
65
|
+
let baseMsg = "";
|
|
66
|
+
if (typeof data?.error?.message === "string" && data.error.message.trim()) {
|
|
67
|
+
baseMsg = data.error.message.trim();
|
|
68
|
+
} else if (typeof data?.message === "string" && data.message.trim()) {
|
|
69
|
+
baseMsg = data.message.trim();
|
|
70
|
+
} else if (typeof data?.error === "string" && data.error.trim()) {
|
|
71
|
+
baseMsg = data.error.trim();
|
|
72
|
+
} else if (fallback) {
|
|
73
|
+
baseMsg = fallback;
|
|
74
|
+
} else {
|
|
75
|
+
baseMsg = `HTTP ${statusCode || 500}: ${statusText || "Internal Error"}`;
|
|
76
|
+
}
|
|
77
|
+
const detailStr = formatValidationDetails(data);
|
|
78
|
+
if (detailStr && !baseMsg.includes(detailStr)) {
|
|
79
|
+
return `${baseMsg}: ${detailStr}`;
|
|
80
|
+
}
|
|
81
|
+
return baseMsg;
|
|
29
82
|
}
|
|
30
83
|
async function uploadGameBundle(options) {
|
|
31
84
|
const formData = new FormData();
|
|
@@ -79,7 +132,8 @@ async function uploadGameBundle(options) {
|
|
|
79
132
|
const response = await fetch(endpoint, {
|
|
80
133
|
method: "POST",
|
|
81
134
|
headers,
|
|
82
|
-
body: formData
|
|
135
|
+
body: formData,
|
|
136
|
+
signal: AbortSignal.timeout(6e4)
|
|
83
137
|
});
|
|
84
138
|
const data = await response.json().catch(() => ({}));
|
|
85
139
|
if (!response.ok) {
|
|
@@ -91,13 +145,20 @@ async function uploadGameBundle(options) {
|
|
|
91
145
|
);
|
|
92
146
|
const err = new Error(errorMsg);
|
|
93
147
|
err.status = response.status;
|
|
94
|
-
err.code = typeof data?.code === "string" ? data.code : typeof data?.error === "string" ? data.error : "UPLOAD_ERROR";
|
|
148
|
+
err.code = typeof data?.code === "string" ? data.code : typeof data?.error?.code === "string" ? data.error.code : typeof data?.error === "string" ? data.error : "UPLOAD_ERROR";
|
|
149
|
+
const fieldErrors = extractFieldErrors(data);
|
|
150
|
+
if (fieldErrors) {
|
|
151
|
+
err.fieldErrors = fieldErrors;
|
|
152
|
+
}
|
|
95
153
|
err.data = data;
|
|
96
154
|
throw err;
|
|
97
155
|
}
|
|
98
156
|
const claimToken = data.claim_token || data.claimToken;
|
|
157
|
+
const fullUrl = resolvePlayableUrl(options.apiUrl, data, data.slug);
|
|
99
158
|
return {
|
|
100
159
|
...data,
|
|
160
|
+
url: fullUrl,
|
|
161
|
+
fullUrl,
|
|
101
162
|
claim_token: claimToken,
|
|
102
163
|
claimToken
|
|
103
164
|
};
|
|
@@ -114,6 +175,7 @@ async function updateGameBundle(slug, options) {
|
|
|
114
175
|
if (options.title) formData.append("title", options.title);
|
|
115
176
|
if (options.tagline !== void 0) formData.append("tagline", options.tagline);
|
|
116
177
|
if (options.description) formData.append("description", options.description);
|
|
178
|
+
if (options.category) formData.append("category", options.category);
|
|
117
179
|
if (options.visibility) formData.append("visibility", options.visibility);
|
|
118
180
|
if (options.changelog) formData.append("changelog", options.changelog);
|
|
119
181
|
if (options.aspectRatio) formData.append("aspect_ratio", options.aspectRatio);
|
|
@@ -121,11 +183,11 @@ async function updateGameBundle(slug, options) {
|
|
|
121
183
|
formData.append("supportedPlatforms", options.supportedPlatforms);
|
|
122
184
|
formData.append("supported_platforms", options.supportedPlatforms);
|
|
123
185
|
}
|
|
124
|
-
if (options.aiModel) {
|
|
186
|
+
if (typeof options.aiModel === "string") {
|
|
125
187
|
formData.append("ai_model", options.aiModel);
|
|
126
188
|
formData.append("aiModel", options.aiModel);
|
|
127
189
|
}
|
|
128
|
-
if (options.aiTool) {
|
|
190
|
+
if (options.aiTool !== void 0) {
|
|
129
191
|
formData.append("ai_tool", options.aiTool);
|
|
130
192
|
formData.append("aiTool", options.aiTool);
|
|
131
193
|
}
|
|
@@ -154,7 +216,8 @@ async function updateGameBundle(slug, options) {
|
|
|
154
216
|
const response = await fetch(endpoint, {
|
|
155
217
|
method: "PATCH",
|
|
156
218
|
headers,
|
|
157
|
-
body: formData
|
|
219
|
+
body: formData,
|
|
220
|
+
signal: AbortSignal.timeout(6e4)
|
|
158
221
|
});
|
|
159
222
|
const data = await response.json().catch(() => ({}));
|
|
160
223
|
if (!response.ok) {
|
|
@@ -166,14 +229,21 @@ async function updateGameBundle(slug, options) {
|
|
|
166
229
|
);
|
|
167
230
|
const err = new Error(errorMsg);
|
|
168
231
|
err.status = response.status;
|
|
169
|
-
err.code = typeof data?.code === "string" ? data.code : typeof data?.error === "string" ? data.error : "UPDATE_ERROR";
|
|
232
|
+
err.code = typeof data?.code === "string" ? data.code : typeof data?.error?.code === "string" ? data.error.code : typeof data?.error === "string" ? data.error : "UPDATE_ERROR";
|
|
233
|
+
const fieldErrors = extractFieldErrors(data);
|
|
234
|
+
if (fieldErrors) {
|
|
235
|
+
err.fieldErrors = fieldErrors;
|
|
236
|
+
}
|
|
170
237
|
err.data = data;
|
|
171
238
|
throw err;
|
|
172
239
|
}
|
|
240
|
+
const resolvedSlug = data.slug || slug;
|
|
241
|
+
const fullUrl = resolvePlayableUrl(apiUrl, data, resolvedSlug);
|
|
173
242
|
return {
|
|
174
243
|
...data,
|
|
175
|
-
slug:
|
|
176
|
-
url:
|
|
244
|
+
slug: resolvedSlug,
|
|
245
|
+
url: fullUrl,
|
|
246
|
+
fullUrl
|
|
177
247
|
};
|
|
178
248
|
}
|
|
179
249
|
var updateGame = updateGameBundle;
|
|
@@ -183,12 +253,18 @@ async function fetchWhoami(apiUrl, token) {
|
|
|
183
253
|
method: "GET",
|
|
184
254
|
headers: {
|
|
185
255
|
Authorization: `Bearer ${token}`
|
|
186
|
-
}
|
|
256
|
+
},
|
|
257
|
+
signal: AbortSignal.timeout(15e3)
|
|
187
258
|
});
|
|
188
259
|
const data = await response.json().catch(() => ({}));
|
|
189
260
|
if (!response.ok) {
|
|
190
261
|
const err = new Error(
|
|
191
|
-
|
|
262
|
+
extractErrorMessage(
|
|
263
|
+
data,
|
|
264
|
+
`Authentication check failed (HTTP ${response.status})`,
|
|
265
|
+
response.statusText,
|
|
266
|
+
response.status
|
|
267
|
+
)
|
|
192
268
|
);
|
|
193
269
|
err.status = response.status;
|
|
194
270
|
throw err;
|
|
@@ -341,8 +417,92 @@ var GAME_CATEGORY_KEYS = [
|
|
|
341
417
|
"rpg",
|
|
342
418
|
"casual"
|
|
343
419
|
];
|
|
420
|
+
var MIME_TYPES = {
|
|
421
|
+
// Web Core
|
|
422
|
+
html: "text/html; charset=utf-8",
|
|
423
|
+
htm: "text/html; charset=utf-8",
|
|
424
|
+
css: "text/css; charset=utf-8",
|
|
425
|
+
js: "application/javascript; charset=utf-8",
|
|
426
|
+
mjs: "application/javascript; charset=utf-8",
|
|
427
|
+
cjs: "application/javascript; charset=utf-8",
|
|
428
|
+
json: "application/json; charset=utf-8",
|
|
429
|
+
webmanifest: "application/manifest+json; charset=utf-8",
|
|
430
|
+
xml: "application/xml",
|
|
431
|
+
txt: "text/plain; charset=utf-8",
|
|
432
|
+
log: "text/plain; charset=utf-8",
|
|
433
|
+
csv: "text/csv; charset=utf-8",
|
|
434
|
+
md: "text/markdown; charset=utf-8",
|
|
435
|
+
// Shaders
|
|
436
|
+
glsl: "text/plain; charset=utf-8",
|
|
437
|
+
vert: "text/plain; charset=utf-8",
|
|
438
|
+
frag: "text/plain; charset=utf-8",
|
|
439
|
+
wgsl: "text/plain; charset=utf-8",
|
|
440
|
+
// WebAssembly
|
|
441
|
+
wasm: "application/wasm",
|
|
442
|
+
// Images & Textures
|
|
443
|
+
png: "image/png",
|
|
444
|
+
jpg: "image/jpeg",
|
|
445
|
+
jpeg: "image/jpeg",
|
|
446
|
+
gif: "image/gif",
|
|
447
|
+
webp: "image/webp",
|
|
448
|
+
svg: "image/svg+xml",
|
|
449
|
+
ico: "image/x-icon",
|
|
450
|
+
bmp: "image/bmp",
|
|
451
|
+
avif: "image/avif",
|
|
452
|
+
ktx2: "image/ktx2",
|
|
453
|
+
hdr: "image/vnd.radiance",
|
|
454
|
+
// Audio
|
|
455
|
+
mp3: "audio/mpeg",
|
|
456
|
+
wav: "audio/wav",
|
|
457
|
+
ogg: "audio/ogg",
|
|
458
|
+
opus: "audio/opus",
|
|
459
|
+
aac: "audio/aac",
|
|
460
|
+
flac: "audio/flac",
|
|
461
|
+
m4a: "audio/mp4",
|
|
462
|
+
weba: "audio/webm",
|
|
463
|
+
mid: "audio/midi",
|
|
464
|
+
midi: "audio/midi",
|
|
465
|
+
// Video
|
|
466
|
+
mp4: "video/mp4",
|
|
467
|
+
webm: "video/webm",
|
|
468
|
+
ogv: "video/ogg",
|
|
469
|
+
// 3D Models, Game Engine Packs & Binary Assets
|
|
470
|
+
glb: "model/gltf-binary",
|
|
471
|
+
gltf: "model/gltf+json",
|
|
472
|
+
bin: "application/octet-stream",
|
|
473
|
+
dat: "application/octet-stream",
|
|
474
|
+
pck: "application/octet-stream",
|
|
475
|
+
atlas: "text/plain; charset=utf-8",
|
|
476
|
+
fnt: "text/plain; charset=utf-8",
|
|
477
|
+
obj: "text/plain",
|
|
478
|
+
mtl: "text/plain",
|
|
479
|
+
// Fonts
|
|
480
|
+
woff: "font/woff",
|
|
481
|
+
woff2: "font/woff2",
|
|
482
|
+
ttf: "font/ttf",
|
|
483
|
+
otf: "font/otf",
|
|
484
|
+
eot: "application/vnd.ms-fontobject",
|
|
485
|
+
// Maps
|
|
486
|
+
map: "application/json; charset=utf-8"
|
|
487
|
+
};
|
|
488
|
+
var ALLOWED_FILE_EXTENSIONS = Object.keys(MIME_TYPES).map(
|
|
489
|
+
(ext) => `.${ext}`
|
|
490
|
+
);
|
|
491
|
+
function extractCleanExtension(filePath) {
|
|
492
|
+
const base = filePath.split(/[/\\]/).pop()?.trim().replace(/[\s.]+$/, "") ?? "";
|
|
493
|
+
const dot = base.lastIndexOf(".");
|
|
494
|
+
if (dot <= 0 || dot === base.length - 1) {
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
497
|
+
return base.slice(dot + 1).toLowerCase();
|
|
498
|
+
}
|
|
499
|
+
function isAllowedFileExtension(filePath) {
|
|
500
|
+
const ext = extractCleanExtension(filePath);
|
|
501
|
+
return Boolean(ext && MIME_TYPES[ext]);
|
|
502
|
+
}
|
|
344
503
|
var MAX_BUNDLE_SIZE_BYTES = 25 * 1024 * 1024;
|
|
345
504
|
var MAX_HTML_SIZE_BYTES = 5 * 1024 * 1024;
|
|
505
|
+
var MAX_INLINE_SOURCE_BYTES = 256 * 1024;
|
|
346
506
|
var MAX_GAME_TITLE_LENGTH = 60;
|
|
347
507
|
var MAX_GAME_TAGLINE_LENGTH = 120;
|
|
348
508
|
var MAX_GAME_DESCRIPTION_LENGTH = 2e3;
|
|
@@ -386,14 +546,7 @@ function isProhibitedExtension(filePath) {
|
|
|
386
546
|
}
|
|
387
547
|
var SUBMISSION_TYPES = ["maker", "hunter"];
|
|
388
548
|
var DEFAULT_ASPECT_RATIO = "auto";
|
|
389
|
-
var ASPECT_RATIO_PRESETS = [
|
|
390
|
-
"auto",
|
|
391
|
-
"16:9",
|
|
392
|
-
"9:16",
|
|
393
|
-
"4:3",
|
|
394
|
-
"3:4",
|
|
395
|
-
"1:1"
|
|
396
|
-
];
|
|
549
|
+
var ASPECT_RATIO_PRESETS = ["auto", "16:9", "9:16", "4:3", "3:4", "1:1"];
|
|
397
550
|
var MIN_ASPECT_RATIO = 0.25;
|
|
398
551
|
var MAX_ASPECT_RATIO = 4;
|
|
399
552
|
var DEFAULT_SUPPORTED_PLATFORMS = "both";
|
|
@@ -876,8 +1029,8 @@ function getErrorMap() {
|
|
|
876
1029
|
|
|
877
1030
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
|
|
878
1031
|
var makeIssue = (params) => {
|
|
879
|
-
const { data, path:
|
|
880
|
-
const fullPath = [...
|
|
1032
|
+
const { data, path: path8, errorMaps, issueData } = params;
|
|
1033
|
+
const fullPath = [...path8, ...issueData.path || []];
|
|
881
1034
|
const fullIssue = {
|
|
882
1035
|
...issueData,
|
|
883
1036
|
path: fullPath
|
|
@@ -993,11 +1146,11 @@ var errorUtil;
|
|
|
993
1146
|
|
|
994
1147
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
995
1148
|
var ParseInputLazyPath = class {
|
|
996
|
-
constructor(parent, value,
|
|
1149
|
+
constructor(parent, value, path8, key) {
|
|
997
1150
|
this._cachedPath = [];
|
|
998
1151
|
this.parent = parent;
|
|
999
1152
|
this.data = value;
|
|
1000
|
-
this._path =
|
|
1153
|
+
this._path = path8;
|
|
1001
1154
|
this._key = key;
|
|
1002
1155
|
}
|
|
1003
1156
|
get path() {
|
|
@@ -4795,10 +4948,7 @@ var aiModelSchema = external_exports.preprocess((val) => {
|
|
|
4795
4948
|
}, external_exports.string().max(MAX_AI_MODEL_LENGTH, `AI model must be ${MAX_AI_MODEL_LENGTH} characters or less`).nullable().optional());
|
|
4796
4949
|
var baseGameUploadObject = external_exports.object({
|
|
4797
4950
|
title: external_exports.string().trim().min(2, "Title must be at least 2 characters").max(MAX_GAME_TITLE_LENGTH, `Title must be ${MAX_GAME_TITLE_LENGTH} characters or less`),
|
|
4798
|
-
tagline: external_exports.string().trim().max(
|
|
4799
|
-
MAX_GAME_TAGLINE_LENGTH,
|
|
4800
|
-
`Tagline must be ${MAX_GAME_TAGLINE_LENGTH} characters or less`
|
|
4801
|
-
).nullable().optional().transform((val) => val ?? ""),
|
|
4951
|
+
tagline: external_exports.string().trim().max(MAX_GAME_TAGLINE_LENGTH, `Tagline must be ${MAX_GAME_TAGLINE_LENGTH} characters or less`).nullable().optional().transform((val) => val ?? ""),
|
|
4802
4952
|
description: external_exports.string().max(
|
|
4803
4953
|
MAX_GAME_DESCRIPTION_LENGTH,
|
|
4804
4954
|
`Description must be ${MAX_GAME_DESCRIPTION_LENGTH} characters or less`
|
|
@@ -4807,7 +4957,7 @@ var baseGameUploadObject = external_exports.object({
|
|
|
4807
4957
|
aiModel: aiModelSchema.optional().nullable(),
|
|
4808
4958
|
primaryCategory: external_exports.enum(GAME_CATEGORY_KEYS, {
|
|
4809
4959
|
errorMap: () => ({ message: "Invalid game category selection" })
|
|
4810
|
-
}),
|
|
4960
|
+
}).default("arcade"),
|
|
4811
4961
|
prompt: external_exports.string().max(MAX_PROMPT_LENGTH, `Prompt must be ${MAX_PROMPT_LENGTH} characters or less`).optional().nullable(),
|
|
4812
4962
|
tags: external_exports.array(tagSchema).max(MAX_TAGS_COUNT, `A maximum of ${MAX_TAGS_COUNT} tags is allowed`).default([]),
|
|
4813
4963
|
submissionType: external_exports.enum(SUBMISSION_TYPES).default("maker"),
|
|
@@ -4839,10 +4989,7 @@ var gameUploadSchema = baseGameUploadObject.transform((data) => {
|
|
|
4839
4989
|
});
|
|
4840
4990
|
var gameUpdateSchema = external_exports.object({
|
|
4841
4991
|
title: external_exports.string().trim().min(2, "Title must be at least 2 characters").max(MAX_GAME_TITLE_LENGTH, `Title must be ${MAX_GAME_TITLE_LENGTH} characters or less`).optional(),
|
|
4842
|
-
tagline: external_exports.string().trim().max(
|
|
4843
|
-
MAX_GAME_TAGLINE_LENGTH,
|
|
4844
|
-
`Tagline must be ${MAX_GAME_TAGLINE_LENGTH} characters or less`
|
|
4845
|
-
).nullable().optional().transform((val) => val === null ? "" : val),
|
|
4992
|
+
tagline: external_exports.string().trim().max(MAX_GAME_TAGLINE_LENGTH, `Tagline must be ${MAX_GAME_TAGLINE_LENGTH} characters or less`).nullable().optional().transform((val) => val === null ? "" : val),
|
|
4846
4993
|
description: external_exports.string().max(
|
|
4847
4994
|
MAX_GAME_DESCRIPTION_LENGTH,
|
|
4848
4995
|
`Description must be ${MAX_GAME_DESCRIPTION_LENGTH} characters or less`
|
|
@@ -4896,11 +5043,11 @@ var claimAuthorshipSchema = external_exports.object({
|
|
|
4896
5043
|
]).optional().nullable(),
|
|
4897
5044
|
notes: external_exports.string().max(1e3, "Notes must be 1000 characters or less").optional().nullable()
|
|
4898
5045
|
});
|
|
4899
|
-
var
|
|
4900
|
-
gameId: external_exports.string().min(1, "Game ID is required"),
|
|
4901
|
-
fileHash: external_exports.string().regex(SHA256_REGEX, "A valid 64-character SHA-256 fingerprint is required"),
|
|
5046
|
+
var takedownRequestSchema = external_exports.object({
|
|
5047
|
+
gameId: external_exports.string().min(1, "Game ID is required").optional(),
|
|
5048
|
+
fileHash: external_exports.string().regex(SHA256_REGEX, "A valid 64-character SHA-256 fingerprint is required").optional().nullable(),
|
|
4902
5049
|
reason: external_exports.string().trim().min(10, "Please provide at least 10 characters explaining the takedown reason").max(1e3, "Reason must be 1000 characters or less"),
|
|
4903
|
-
reporterEmail: external_exports.
|
|
5050
|
+
reporterEmail: external_exports.string({ required_error: "A valid contact email is required" }).trim().toLowerCase().email("A valid contact email is required"),
|
|
4904
5051
|
confirmTakedown: external_exports.literal(true, {
|
|
4905
5052
|
errorMap: () => ({
|
|
4906
5053
|
message: "You must check the confirmation box to proceed with instant takedown"
|
|
@@ -5060,6 +5207,9 @@ function validateZipEntryPath(rawPath) {
|
|
|
5060
5207
|
return { valid: false, error: `Prohibited system or environment file: ${cleanPath}` };
|
|
5061
5208
|
}
|
|
5062
5209
|
}
|
|
5210
|
+
if (!isAllowedFileExtension(cleanPath)) {
|
|
5211
|
+
return { valid: false, error: `Unsupported or disallowed file extension: ${cleanPath}` };
|
|
5212
|
+
}
|
|
5063
5213
|
return {
|
|
5064
5214
|
valid: true,
|
|
5065
5215
|
normalizedPath: cleanPath
|
|
@@ -5067,7 +5217,18 @@ function validateZipEntryPath(rawPath) {
|
|
|
5067
5217
|
}
|
|
5068
5218
|
function isIgnoredZipEntry(entryPath) {
|
|
5069
5219
|
const normalized = entryPath.replace(/\\/g, "/");
|
|
5070
|
-
return normalized.startsWith("__MACOSX/") || normalized.includes("/__MACOSX/") || normalized.endsWith(".DS_Store") || normalized.endsWith("Thumbs.db") || normalized.startsWith("._") || normalized.includes("/._");
|
|
5220
|
+
return normalized === "__MACOSX" || normalized.endsWith("/__MACOSX") || normalized.startsWith("__MACOSX/") || normalized.includes("/__MACOSX/") || normalized.endsWith(".DS_Store") || normalized.endsWith("Thumbs.db") || normalized.startsWith("._") || normalized.includes("/._");
|
|
5221
|
+
}
|
|
5222
|
+
function extractHtmlTitle(html) {
|
|
5223
|
+
const match = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
|
|
5224
|
+
if (!match || !match[1]) return null;
|
|
5225
|
+
const cleaned = match[1].replace(/\s+/g, " ").trim();
|
|
5226
|
+
if (!cleaned) return null;
|
|
5227
|
+
const lower = cleaned.toLowerCase();
|
|
5228
|
+
if (lower === "document" || lower === "untitled" || lower === "index" || lower === "vite app") {
|
|
5229
|
+
return null;
|
|
5230
|
+
}
|
|
5231
|
+
return cleaned.slice(0, 60);
|
|
5071
5232
|
}
|
|
5072
5233
|
var MAX_COVER_IMAGE_BYTES = 2 * 1024 * 1024;
|
|
5073
5234
|
function validateCoverImageBytes(bytes) {
|
|
@@ -5220,13 +5381,28 @@ function extractTagsFromHtml(html) {
|
|
|
5220
5381
|
}
|
|
5221
5382
|
|
|
5222
5383
|
// src/project.ts
|
|
5384
|
+
function isReplaystageRepoSeedGamesFixture(resolvedPath) {
|
|
5385
|
+
let current = resolvedPath;
|
|
5386
|
+
while (true) {
|
|
5387
|
+
if (path.basename(current) === "seed-games") {
|
|
5388
|
+
const repoCandidate = path.dirname(current);
|
|
5389
|
+
if (fs.existsSync(path.join(repoCandidate, "pnpm-workspace.yaml")) && fs.existsSync(path.join(repoCandidate, "packages", "cli", "package.json"))) {
|
|
5390
|
+
return true;
|
|
5391
|
+
}
|
|
5392
|
+
}
|
|
5393
|
+
const parent = path.dirname(current);
|
|
5394
|
+
if (parent === current) break;
|
|
5395
|
+
current = parent;
|
|
5396
|
+
}
|
|
5397
|
+
return false;
|
|
5398
|
+
}
|
|
5223
5399
|
function resolveProjectDirectory(targetPath) {
|
|
5224
5400
|
try {
|
|
5225
5401
|
const resolved = path.resolve(targetPath);
|
|
5226
5402
|
if (resolved.toLowerCase().endsWith(".zip")) {
|
|
5227
5403
|
return null;
|
|
5228
5404
|
}
|
|
5229
|
-
if (resolved
|
|
5405
|
+
if (isReplaystageRepoSeedGamesFixture(resolved)) {
|
|
5230
5406
|
return null;
|
|
5231
5407
|
}
|
|
5232
5408
|
if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) {
|
|
@@ -5267,7 +5443,7 @@ function readProjectConfig(targetDir) {
|
|
|
5267
5443
|
return null;
|
|
5268
5444
|
}
|
|
5269
5445
|
}
|
|
5270
|
-
const hasValidKey = typeof parsed.slug === "string" && parsed.slug.trim().length > 0 || typeof parsed.tagline === "string" || typeof parsed.supportedPlatforms === "string" || typeof parsed.platforms === "string" || typeof parsed.aspectRatio === "string" || typeof parsed.aiModel === "string" || typeof parsed.aiTool === "string" || Array.isArray(parsed.tags) || typeof parsed.tags === "string";
|
|
5446
|
+
const hasValidKey = typeof parsed.slug === "string" && parsed.slug.trim().length > 0 || typeof parsed.title === "string" || typeof parsed.tagline === "string" || typeof parsed.category === "string" || typeof parsed.supportedPlatforms === "string" || typeof parsed.platforms === "string" || typeof parsed.aspectRatio === "string" || typeof parsed.aiModel === "string" || typeof parsed.aiTool === "string" || Array.isArray(parsed.tags) || typeof parsed.tags === "string";
|
|
5271
5447
|
if (!hasValidKey) {
|
|
5272
5448
|
return null;
|
|
5273
5449
|
}
|
|
@@ -5375,10 +5551,15 @@ function setToken(token, user, apiUrl) {
|
|
|
5375
5551
|
});
|
|
5376
5552
|
}
|
|
5377
5553
|
function clearToken() {
|
|
5378
|
-
const
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5554
|
+
const { token: _token, user: _user, ...rest } = readConfig();
|
|
5555
|
+
writeConfig(rest);
|
|
5556
|
+
const legacyCreds = path2.join(getConfigDir(), "credentials.json");
|
|
5557
|
+
if (fs2.existsSync(legacyCreds)) {
|
|
5558
|
+
try {
|
|
5559
|
+
fs2.unlinkSync(legacyCreds);
|
|
5560
|
+
} catch {
|
|
5561
|
+
}
|
|
5562
|
+
}
|
|
5382
5563
|
}
|
|
5383
5564
|
function resolveToken(cliToken) {
|
|
5384
5565
|
if (cliToken?.trim()) return cliToken.trim();
|
|
@@ -5408,7 +5589,7 @@ function printJson(data) {
|
|
|
5408
5589
|
}
|
|
5409
5590
|
function printErrorJson(error, message, code = 1, extra) {
|
|
5410
5591
|
process.stdout.write(
|
|
5411
|
-
`${JSON.stringify({ success: false, code, error, message, ...extra }, null, 2)}
|
|
5592
|
+
`${JSON.stringify({ ok: false, success: false, code, error, message, ...extra }, null, 2)}
|
|
5412
5593
|
`
|
|
5413
5594
|
);
|
|
5414
5595
|
}
|
|
@@ -5523,17 +5704,26 @@ async function handleLogin(options = {}) {
|
|
|
5523
5704
|
}
|
|
5524
5705
|
try {
|
|
5525
5706
|
let user = void 0;
|
|
5707
|
+
let offlineWarning = void 0;
|
|
5526
5708
|
try {
|
|
5527
5709
|
user = await fetchWhoami(apiUrl, token);
|
|
5528
5710
|
} catch (err) {
|
|
5529
|
-
if (
|
|
5711
|
+
if (typeof err?.status === "number") {
|
|
5530
5712
|
throw err;
|
|
5531
5713
|
}
|
|
5532
5714
|
user = { id: "user_cli", handle: "cli_user" };
|
|
5715
|
+
offlineWarning = `Could not reach ${apiUrl} (${err?.message || "network error"}). Token saved locally without remote verification.`;
|
|
5716
|
+
logWarn(offlineWarning, isJson);
|
|
5533
5717
|
}
|
|
5534
5718
|
setToken(token, user, options.apiUrl ? apiUrl : void 0);
|
|
5535
5719
|
if (isJson) {
|
|
5536
|
-
printJson({
|
|
5720
|
+
printJson({
|
|
5721
|
+
success: true,
|
|
5722
|
+
apiUrl,
|
|
5723
|
+
user,
|
|
5724
|
+
token: `${token.slice(0, 8)}...`,
|
|
5725
|
+
...offlineWarning ? { verified: false, warning: offlineWarning } : { verified: true }
|
|
5726
|
+
});
|
|
5537
5727
|
} else {
|
|
5538
5728
|
console.log(
|
|
5539
5729
|
pc2.green(`
|
|
@@ -5613,11 +5803,26 @@ async function handleWhoami(options = {}) {
|
|
|
5613
5803
|
}
|
|
5614
5804
|
async function handleLogout(options = {}) {
|
|
5615
5805
|
const isJson = Boolean(options.json);
|
|
5616
|
-
|
|
5806
|
+
clearToken();
|
|
5807
|
+
const activeEnvVars = [
|
|
5808
|
+
process.env.REPLAYSTAGE_TOKEN?.trim() ? "REPLAYSTAGE_TOKEN" : null,
|
|
5809
|
+
process.env.REPLAYSTAGE_API_TOKEN?.trim() ? "REPLAYSTAGE_API_TOKEN" : null
|
|
5810
|
+
].filter((v) => Boolean(v));
|
|
5811
|
+
const envWarning = activeEnvVars.length > 0 ? `Environment variable ${activeEnvVars.join(" / ")} is set in your environment and will still authenticate CLI commands until unset.` : void 0;
|
|
5617
5812
|
if (isJson) {
|
|
5618
|
-
printJson({
|
|
5813
|
+
printJson({
|
|
5814
|
+
success: true,
|
|
5815
|
+
message: "Logged out successfully",
|
|
5816
|
+
...envWarning ? { warning: envWarning, envTokenActive: true } : {}
|
|
5817
|
+
});
|
|
5619
5818
|
} else {
|
|
5620
|
-
console.log(pc2.green("\n\u2714 Stored credentials cleared successfully
|
|
5819
|
+
console.log(pc2.green("\n\u2714 Stored credentials cleared successfully."));
|
|
5820
|
+
if (envWarning) {
|
|
5821
|
+
console.error(pc2.yellow(` \u26A0 ${envWarning}
|
|
5822
|
+
`));
|
|
5823
|
+
} else {
|
|
5824
|
+
console.log();
|
|
5825
|
+
}
|
|
5621
5826
|
}
|
|
5622
5827
|
}
|
|
5623
5828
|
|
|
@@ -5721,7 +5926,8 @@ function extractHtmlMetadata(html) {
|
|
|
5721
5926
|
let tagline;
|
|
5722
5927
|
const titleMatch = html.match(/<\s*title[^>]*>([\s\S]*?)<\s*\/\s*title>/i);
|
|
5723
5928
|
if (titleMatch?.[1]) {
|
|
5724
|
-
|
|
5929
|
+
const strippedInner = titleMatch[1].replace(/<[^>]+>/g, "");
|
|
5930
|
+
title = extractHtmlTitle(`<title>${strippedInner}</title>`) ?? void 0;
|
|
5725
5931
|
}
|
|
5726
5932
|
const descMatch = html.match(/<\s*meta[^>]+name=["']description["'][^>]+content=["']([^"']*)["']/i) || html.match(/<\s*meta[^>]+content=["']([^"']*)["'][^>]+name=["']description["']/i);
|
|
5727
5933
|
if (descMatch?.[1]) {
|
|
@@ -5740,6 +5946,34 @@ function extractHtmlMetadata(html) {
|
|
|
5740
5946
|
tags: tags.length > 0 ? tags : void 0
|
|
5741
5947
|
};
|
|
5742
5948
|
}
|
|
5949
|
+
function findRawZipEntryBytes(unzipped, normalizedTarget) {
|
|
5950
|
+
if (unzipped[normalizedTarget]) return unzipped[normalizedTarget];
|
|
5951
|
+
for (const rawKey of Object.keys(unzipped)) {
|
|
5952
|
+
if (isIgnoredZipEntry(rawKey)) continue;
|
|
5953
|
+
const normalizedKey = rawKey.replace(/\\/g, "/").replace(/^\.?\//, "");
|
|
5954
|
+
if (normalizedKey === normalizedTarget) {
|
|
5955
|
+
return unzipped[rawKey];
|
|
5956
|
+
}
|
|
5957
|
+
}
|
|
5958
|
+
return void 0;
|
|
5959
|
+
}
|
|
5960
|
+
var FORBIDDEN_ZIP_DIR_SEGMENTS = /* @__PURE__ */ new Set([
|
|
5961
|
+
".git",
|
|
5962
|
+
".github",
|
|
5963
|
+
"node_modules",
|
|
5964
|
+
".aws",
|
|
5965
|
+
".ssh",
|
|
5966
|
+
".bashrc",
|
|
5967
|
+
".bash_profile",
|
|
5968
|
+
".bash_history",
|
|
5969
|
+
".bash_logout",
|
|
5970
|
+
".zshrc",
|
|
5971
|
+
".zprofile",
|
|
5972
|
+
".zsh_history",
|
|
5973
|
+
".profile",
|
|
5974
|
+
".npmrc",
|
|
5975
|
+
".netrc"
|
|
5976
|
+
]);
|
|
5743
5977
|
function computeSha256(buf) {
|
|
5744
5978
|
return crypto.createHash("sha256").update(buf).digest("hex").toLowerCase();
|
|
5745
5979
|
}
|
|
@@ -5770,7 +6004,7 @@ async function packageGame(targetPath) {
|
|
|
5770
6004
|
const meta = extractHtmlMetadata(content.toString("utf-8"));
|
|
5771
6005
|
const files = { "index.html": content };
|
|
5772
6006
|
const detectedCover = detectSiblingCover(resolved);
|
|
5773
|
-
if (detectedCover
|
|
6007
|
+
if (detectedCover?.buffer) {
|
|
5774
6008
|
files[detectedCover.fileName] = detectedCover.buffer;
|
|
5775
6009
|
}
|
|
5776
6010
|
const zipBuffer = createZipFromFiles(files);
|
|
@@ -5803,13 +6037,29 @@ async function packageGame(targetPath) {
|
|
|
5803
6037
|
const entryPaths = Object.keys(unzipped);
|
|
5804
6038
|
for (const entryPath of entryPaths) {
|
|
5805
6039
|
if (isIgnoredZipEntry(entryPath)) continue;
|
|
5806
|
-
const
|
|
6040
|
+
const normSlash = entryPath.replace(/\\/g, "/");
|
|
6041
|
+
const normLower = normSlash.toLowerCase();
|
|
5807
6042
|
const segments = normLower.split("/").filter(Boolean);
|
|
5808
6043
|
if (segments.some((seg) => seg === ".replaystage.json" || seg.startsWith(".replaystage"))) {
|
|
5809
6044
|
throw new Error(
|
|
5810
6045
|
`Prohibited file in zip archive: '${entryPath}'. ReplayStage state files contain secret management tokens and must not be included in game archives.`
|
|
5811
6046
|
);
|
|
5812
6047
|
}
|
|
6048
|
+
if (segments.some((seg) => seg === ".." || /^\.{2,}$/.test(seg))) {
|
|
6049
|
+
throw new Error(
|
|
6050
|
+
"Invalid file in zip archive: Directory traversal ('..') is prohibited in zip entry path"
|
|
6051
|
+
);
|
|
6052
|
+
}
|
|
6053
|
+
if (segments.some(
|
|
6054
|
+
(seg) => seg === ".env" || seg.startsWith(".env.") || seg.startsWith(".env-") || seg.startsWith(".env_") || FORBIDDEN_ZIP_DIR_SEGMENTS.has(seg)
|
|
6055
|
+
)) {
|
|
6056
|
+
throw new Error(
|
|
6057
|
+
`Invalid file in zip archive: Prohibited system or environment file: ${entryPath}`
|
|
6058
|
+
);
|
|
6059
|
+
}
|
|
6060
|
+
if (normSlash.endsWith("/")) {
|
|
6061
|
+
continue;
|
|
6062
|
+
}
|
|
5813
6063
|
const validRes = validateZipEntryPath(entryPath);
|
|
5814
6064
|
if (!validRes.valid) {
|
|
5815
6065
|
throw new Error(`Invalid file in zip archive: ${validRes.error}`);
|
|
@@ -5825,16 +6075,17 @@ async function packageGame(targetPath) {
|
|
|
5825
6075
|
);
|
|
5826
6076
|
}
|
|
5827
6077
|
const fileHash = computeSha256(content);
|
|
5828
|
-
const filteredFiles = entryPaths.filter(
|
|
6078
|
+
const filteredFiles = entryPaths.filter(
|
|
6079
|
+
(p) => !isIgnoredZipEntry(p) && !p.replace(/\\/g, "/").endsWith("/")
|
|
6080
|
+
);
|
|
5829
6081
|
let extractedTitle;
|
|
5830
6082
|
let extractedTagline;
|
|
5831
6083
|
let extractedAspectRatio;
|
|
5832
6084
|
let extractedModel;
|
|
5833
6085
|
let extractedTags;
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
);
|
|
6086
|
+
const rawEntryBytes = findRawZipEntryBytes(unzipped, entryRes.entryPath);
|
|
6087
|
+
if (rawEntryBytes) {
|
|
6088
|
+
const meta = extractHtmlMetadata(Buffer.from(rawEntryBytes).toString("utf-8"));
|
|
5838
6089
|
extractedTitle = meta.title;
|
|
5839
6090
|
extractedTagline = meta.tagline;
|
|
5840
6091
|
extractedAspectRatio = meta.aspectRatio;
|
|
@@ -5985,6 +6236,17 @@ function checkHtmlDependencies(content) {
|
|
|
5985
6236
|
}
|
|
5986
6237
|
return { valid: errors.length === 0, errors };
|
|
5987
6238
|
}
|
|
6239
|
+
function findRawZipEntryBytes2(unzipped, normalizedTarget) {
|
|
6240
|
+
if (unzipped[normalizedTarget]) return unzipped[normalizedTarget];
|
|
6241
|
+
for (const rawKey of Object.keys(unzipped)) {
|
|
6242
|
+
if (isIgnoredZipEntry(rawKey)) continue;
|
|
6243
|
+
const normalizedKey = rawKey.replace(/\\/g, "/").replace(/^\.?\//, "");
|
|
6244
|
+
if (normalizedKey === normalizedTarget) {
|
|
6245
|
+
return unzipped[rawKey];
|
|
6246
|
+
}
|
|
6247
|
+
}
|
|
6248
|
+
return void 0;
|
|
6249
|
+
}
|
|
5988
6250
|
async function validateGamePackage(targetPath) {
|
|
5989
6251
|
const resolved = path4.resolve(process.cwd(), targetPath || ".");
|
|
5990
6252
|
const errors = [];
|
|
@@ -6054,8 +6316,9 @@ async function validateGamePackage(targetPath) {
|
|
|
6054
6316
|
const unzipped = fflate2.unzipSync(new Uint8Array(content));
|
|
6055
6317
|
const entryPaths = Object.keys(unzipped);
|
|
6056
6318
|
const entryRes = findEntryHtmlFile(entryPaths);
|
|
6057
|
-
|
|
6058
|
-
|
|
6319
|
+
const rawEntryBytes = entryRes.entryPath ? findRawZipEntryBytes2(unzipped, entryRes.entryPath) : void 0;
|
|
6320
|
+
if (entryRes.entryPath && rawEntryBytes) {
|
|
6321
|
+
const htmlContent = Buffer.from(rawEntryBytes).toString("utf-8");
|
|
6059
6322
|
const depCheck = checkHtmlDependencies(htmlContent);
|
|
6060
6323
|
if (!depCheck.valid) {
|
|
6061
6324
|
errors.push(...depCheck.errors);
|
|
@@ -6101,24 +6364,33 @@ async function validateGamePackage(targetPath) {
|
|
|
6101
6364
|
}
|
|
6102
6365
|
for (const entry of entries) {
|
|
6103
6366
|
const name = entry.name;
|
|
6104
|
-
|
|
6105
|
-
continue;
|
|
6106
|
-
}
|
|
6367
|
+
const lowerName = name.toLowerCase();
|
|
6107
6368
|
const fullPath = path4.join(currentDir, name);
|
|
6108
6369
|
const relPath = relDir ? `${relDir}/${name}` : name;
|
|
6109
6370
|
const normalizedRelPath = relPath.replace(/\\/g, "/");
|
|
6371
|
+
if (entry.isFile() && (lowerName === ".env" || lowerName.startsWith(".env.") || lowerName.startsWith(".env-") || lowerName.startsWith(".env_"))) {
|
|
6372
|
+
warnings.push(
|
|
6373
|
+
`Environment file '${normalizedRelPath}' detected in directory and automatically excluded from bundle.`
|
|
6374
|
+
);
|
|
6375
|
+
continue;
|
|
6376
|
+
}
|
|
6377
|
+
if (name.startsWith(".") || name === ".replaystage.json" || name.startsWith(".replaystage") || name === "node_modules" || name === "__MACOSX" || name === "Thumbs.db" || isIgnoredZipEntry(name)) {
|
|
6378
|
+
continue;
|
|
6379
|
+
}
|
|
6110
6380
|
if (isIgnoredZipEntry(normalizedRelPath)) continue;
|
|
6111
6381
|
if (entry.isDirectory()) {
|
|
6112
6382
|
scan2(fullPath, relPath);
|
|
6113
6383
|
} else if (entry.isFile()) {
|
|
6114
6384
|
if (isProhibitedExtension(normalizedRelPath)) {
|
|
6115
6385
|
errors.push(
|
|
6116
|
-
`Prohibited file detected: '${normalizedRelPath}'. Executables, scripts, and sensitive files (.exe, .
|
|
6386
|
+
`Prohibited file detected: '${normalizedRelPath}'. Executables, scripts, and sensitive files (.exe, .sh, etc.) are not permitted.`
|
|
6117
6387
|
);
|
|
6388
|
+
continue;
|
|
6118
6389
|
}
|
|
6119
6390
|
const pathValidation = validateZipEntryPath(normalizedRelPath);
|
|
6120
6391
|
if (!pathValidation.valid) {
|
|
6121
6392
|
errors.push(`Invalid file path in directory: ${pathValidation.error}`);
|
|
6393
|
+
continue;
|
|
6122
6394
|
}
|
|
6123
6395
|
try {
|
|
6124
6396
|
const fileStat = fs4.statSync(fullPath);
|
|
@@ -6134,15 +6406,6 @@ async function validateGamePackage(targetPath) {
|
|
|
6134
6406
|
const collectedFiles = [];
|
|
6135
6407
|
let totalSize = 0;
|
|
6136
6408
|
scan2(resolved, "");
|
|
6137
|
-
try {
|
|
6138
|
-
const rootEntries = fs4.readdirSync(resolved);
|
|
6139
|
-
for (const entry of rootEntries) {
|
|
6140
|
-
if (entry === ".env" || entry.startsWith(".env.") || entry === ".git" || entry.endsWith(".exe")) {
|
|
6141
|
-
errors.push(`Prohibited file detected: '${entry}'`);
|
|
6142
|
-
}
|
|
6143
|
-
}
|
|
6144
|
-
} catch {
|
|
6145
|
-
}
|
|
6146
6409
|
if (totalSize > MAX_BUNDLE_SIZE_BYTES) {
|
|
6147
6410
|
errors.push(
|
|
6148
6411
|
`Total game size exceeds 25MB limit (${(totalSize / (1024 * 1024)).toFixed(2)} MB).`
|
|
@@ -6260,6 +6523,11 @@ async function validateGamePackage(targetPath) {
|
|
|
6260
6523
|
// src/commands/publish.ts
|
|
6261
6524
|
async function handlePublish(targetPath = ".", options = {}) {
|
|
6262
6525
|
const isJson = Boolean(options.json);
|
|
6526
|
+
let exitHandled = false;
|
|
6527
|
+
const exitWithError = (code = 1) => {
|
|
6528
|
+
exitHandled = true;
|
|
6529
|
+
return process.exit(code);
|
|
6530
|
+
};
|
|
6263
6531
|
try {
|
|
6264
6532
|
const visibilityFlagsCount = [
|
|
6265
6533
|
Boolean(options.draft),
|
|
@@ -6275,7 +6543,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6275
6543
|
\u2716 Invalid options: ${errorMsg}
|
|
6276
6544
|
`));
|
|
6277
6545
|
}
|
|
6278
|
-
|
|
6546
|
+
exitWithError(1);
|
|
6279
6547
|
}
|
|
6280
6548
|
let visibility = void 0;
|
|
6281
6549
|
if (options.draft) {
|
|
@@ -6285,6 +6553,22 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6285
6553
|
} else if (options.public) {
|
|
6286
6554
|
visibility = "public";
|
|
6287
6555
|
}
|
|
6556
|
+
let explicitCategory = void 0;
|
|
6557
|
+
if (options.category !== void 0) {
|
|
6558
|
+
const normalizedCat = options.category.toLowerCase().trim();
|
|
6559
|
+
if (!normalizedCat || !GAME_CATEGORY_KEYS.includes(normalizedCat)) {
|
|
6560
|
+
const errorMsg = `Invalid category '${options.category}'. Expected one of: ${GAME_CATEGORY_KEYS.join(", ")}`;
|
|
6561
|
+
if (isJson) {
|
|
6562
|
+
printErrorJson("INVALID_OPTIONS", errorMsg, 1);
|
|
6563
|
+
} else {
|
|
6564
|
+
console.error(pc3.red(`
|
|
6565
|
+
\u2716 Invalid option: ${errorMsg}
|
|
6566
|
+
`));
|
|
6567
|
+
}
|
|
6568
|
+
exitWithError(1);
|
|
6569
|
+
}
|
|
6570
|
+
explicitCategory = normalizedCat;
|
|
6571
|
+
}
|
|
6288
6572
|
const resolvedPath = path5.resolve(process.cwd(), targetPath || ".");
|
|
6289
6573
|
logInfo(`Validating game package at ${resolvedPath}...`, isJson);
|
|
6290
6574
|
const validation = await validateGamePackage(resolvedPath);
|
|
@@ -6298,27 +6582,36 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6298
6582
|
${validation.errors.join("\n ")}
|
|
6299
6583
|
`));
|
|
6300
6584
|
}
|
|
6301
|
-
|
|
6585
|
+
exitWithError(1);
|
|
6586
|
+
}
|
|
6587
|
+
for (const warning of validation.warnings) {
|
|
6588
|
+
logWarn(warning, isJson);
|
|
6302
6589
|
}
|
|
6303
6590
|
logInfo("Packaging game bundle...", isJson);
|
|
6304
6591
|
const bundle = await packageGame(resolvedPath);
|
|
6592
|
+
const token = options.anonymous ? null : resolveToken(options.token);
|
|
6593
|
+
const apiUrl = resolveApiUrl(options.apiUrl);
|
|
6594
|
+
const existingConfig = !options.fresh ? readProjectConfig(resolvedPath) : null;
|
|
6305
6595
|
let title = options.title?.trim();
|
|
6306
|
-
if (!title &&
|
|
6307
|
-
title =
|
|
6596
|
+
if (!title && existingConfig?.title?.trim()) {
|
|
6597
|
+
title = existingConfig.title.trim();
|
|
6598
|
+
}
|
|
6599
|
+
if (!title && bundle.extractedTitle?.trim()) {
|
|
6600
|
+
title = bundle.extractedTitle.trim();
|
|
6308
6601
|
}
|
|
6309
6602
|
if (!title) {
|
|
6310
|
-
|
|
6603
|
+
const rawBase = fs5.statSync(resolvedPath).isFile() ? path5.basename(resolvedPath).replace(/\.html?$/i, "") : path5.basename(resolvedPath);
|
|
6604
|
+
const effectiveBase = rawBase.toLowerCase() === "index" ? path5.basename(path5.dirname(resolvedPath)) : rawBase;
|
|
6605
|
+
title = effectiveBase.replace(/[-_.]+/g, " ").trim();
|
|
6311
6606
|
title = title.replace(/\b\w/g, (c) => c.toUpperCase());
|
|
6312
6607
|
}
|
|
6313
6608
|
if (title.length < 2) title = "Web Game";
|
|
6314
6609
|
if (title.length > 60) title = title.slice(0, 60);
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
const
|
|
6320
|
-
const apiUrl = resolveApiUrl(options.apiUrl);
|
|
6321
|
-
const existingConfig = !options.fresh ? readProjectConfig(resolvedPath) : null;
|
|
6610
|
+
const validExistingCategory = existingConfig?.category && GAME_CATEGORY_KEYS.includes(
|
|
6611
|
+
existingConfig.category.toLowerCase().trim()
|
|
6612
|
+
) ? existingConfig.category.toLowerCase().trim() : void 0;
|
|
6613
|
+
const category = explicitCategory || validExistingCategory || "arcade";
|
|
6614
|
+
const updateCategory = explicitCategory || validExistingCategory;
|
|
6322
6615
|
let tagline = "";
|
|
6323
6616
|
if (options.tagline !== void 0) {
|
|
6324
6617
|
tagline = options.tagline.trim();
|
|
@@ -6340,7 +6633,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6340
6633
|
\u2716 Invalid option: ${errorMsg}
|
|
6341
6634
|
`));
|
|
6342
6635
|
}
|
|
6343
|
-
|
|
6636
|
+
exitWithError(1);
|
|
6344
6637
|
}
|
|
6345
6638
|
const rawTool = parsedTool.data;
|
|
6346
6639
|
if (rawTool) {
|
|
@@ -6366,7 +6659,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6366
6659
|
\u2716 Invalid option: ${errorMsg}
|
|
6367
6660
|
`));
|
|
6368
6661
|
}
|
|
6369
|
-
|
|
6662
|
+
exitWithError(1);
|
|
6370
6663
|
}
|
|
6371
6664
|
resolvedModel = parsedModel.data ?? null;
|
|
6372
6665
|
} else if (bundle.extractedModel) {
|
|
@@ -6387,7 +6680,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6387
6680
|
\u2716 Invalid option: ${errorMsg}
|
|
6388
6681
|
`));
|
|
6389
6682
|
}
|
|
6390
|
-
|
|
6683
|
+
exitWithError(1);
|
|
6391
6684
|
}
|
|
6392
6685
|
const stat = fs5.statSync(resolvedCoverPath);
|
|
6393
6686
|
if (!stat.isFile()) {
|
|
@@ -6399,7 +6692,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6399
6692
|
\u2716 Invalid option: ${errorMsg}
|
|
6400
6693
|
`));
|
|
6401
6694
|
}
|
|
6402
|
-
|
|
6695
|
+
exitWithError(1);
|
|
6403
6696
|
}
|
|
6404
6697
|
const ext = path5.extname(resolvedCoverPath).toLowerCase().replace(".", "");
|
|
6405
6698
|
const allowedExts = ["png", "jpg", "jpeg", "webp", "gif"];
|
|
@@ -6412,7 +6705,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6412
6705
|
\u2716 Invalid option: ${errorMsg}
|
|
6413
6706
|
`));
|
|
6414
6707
|
}
|
|
6415
|
-
|
|
6708
|
+
exitWithError(1);
|
|
6416
6709
|
}
|
|
6417
6710
|
const rawCoverBytes = fs5.readFileSync(resolvedCoverPath);
|
|
6418
6711
|
const coverValidation = validateCoverImageBytes(new Uint8Array(rawCoverBytes));
|
|
@@ -6425,7 +6718,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6425
6718
|
\u2716 Invalid option: ${errorMsg}
|
|
6426
6719
|
`));
|
|
6427
6720
|
}
|
|
6428
|
-
|
|
6721
|
+
exitWithError(1);
|
|
6429
6722
|
}
|
|
6430
6723
|
coverBuffer = rawCoverBytes;
|
|
6431
6724
|
coverFileName = path5.basename(resolvedCoverPath);
|
|
@@ -6448,7 +6741,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6448
6741
|
\u2716 Invalid option: ${errorMsg}
|
|
6449
6742
|
`));
|
|
6450
6743
|
}
|
|
6451
|
-
|
|
6744
|
+
exitWithError(1);
|
|
6452
6745
|
}
|
|
6453
6746
|
resolvedAspectRatio = norm.normalized;
|
|
6454
6747
|
} else if (validation.aspectRatio && validation.aspectRatio !== "auto") {
|
|
@@ -6468,7 +6761,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6468
6761
|
\u2716 Invalid option: ${errorMsg}
|
|
6469
6762
|
`));
|
|
6470
6763
|
}
|
|
6471
|
-
|
|
6764
|
+
exitWithError(1);
|
|
6472
6765
|
}
|
|
6473
6766
|
resolvedPlatforms = norm.normalized;
|
|
6474
6767
|
} else if (validation.hasPlatformMeta && validation.supportedPlatforms) {
|
|
@@ -6494,7 +6787,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6494
6787
|
\u2716 Invalid option: ${errorMsg}
|
|
6495
6788
|
`));
|
|
6496
6789
|
}
|
|
6497
|
-
|
|
6790
|
+
exitWithError(1);
|
|
6498
6791
|
}
|
|
6499
6792
|
for (const rawTag of rawTags) {
|
|
6500
6793
|
const formatted = rawTag.toLowerCase().replace(/[\s_]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -6508,7 +6801,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6508
6801
|
\u2716 Invalid option: ${errorMsg}
|
|
6509
6802
|
`));
|
|
6510
6803
|
}
|
|
6511
|
-
|
|
6804
|
+
exitWithError(1);
|
|
6512
6805
|
}
|
|
6513
6806
|
}
|
|
6514
6807
|
resolvedTags = normalizeTags(rawTags);
|
|
@@ -6534,14 +6827,15 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6534
6827
|
title,
|
|
6535
6828
|
tagline: options.tagline !== void 0 ? tagline : tagline || void 0,
|
|
6536
6829
|
description: options.description,
|
|
6830
|
+
category: updateCategory,
|
|
6537
6831
|
visibility,
|
|
6538
6832
|
changelog: options.changelog,
|
|
6539
6833
|
aspectRatio: resolvedAspectRatio,
|
|
6540
6834
|
supportedPlatforms: resolvedPlatforms,
|
|
6541
6835
|
manageToken: existingConfig.manageToken,
|
|
6542
6836
|
token,
|
|
6543
|
-
aiModel: resolvedModel,
|
|
6544
|
-
aiTool,
|
|
6837
|
+
aiModel: options.model !== void 0 ? resolvedModel ?? "" : resolvedModel ?? void 0,
|
|
6838
|
+
aiTool: options.tool !== void 0 ? aiTool : aiTool || void 0,
|
|
6545
6839
|
tags: resolvedTags,
|
|
6546
6840
|
coverBuffer,
|
|
6547
6841
|
coverFileName,
|
|
@@ -6556,26 +6850,31 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6556
6850
|
version: newVersion,
|
|
6557
6851
|
title: title || existingConfig.title,
|
|
6558
6852
|
tagline: tagline || void 0,
|
|
6853
|
+
category: updateCategory || validExistingCategory,
|
|
6559
6854
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6560
6855
|
visibility: resolvedVis,
|
|
6561
6856
|
aspectRatio: resolvedAspectRatio,
|
|
6562
6857
|
supportedPlatforms: resolvedPlatforms,
|
|
6563
6858
|
platforms: resolvedPlatforms,
|
|
6564
|
-
aiModel:
|
|
6859
|
+
aiModel: options.model !== void 0 ? resolvedModel : resolvedModel !== null ? resolvedModel : existingConfig.aiModel ?? null,
|
|
6565
6860
|
aiTool: aiTool || void 0,
|
|
6566
6861
|
tags: resolvedTags
|
|
6567
6862
|
};
|
|
6568
6863
|
writeProjectConfig(resolvedPath, updatedConfig);
|
|
6864
|
+
const resolvedSlug = updateResult.slug || existingConfig.slug;
|
|
6865
|
+
const playUrl = resolvePlayableUrl(apiUrl, updateResult, resolvedSlug);
|
|
6569
6866
|
if (isJson) {
|
|
6570
6867
|
printJson({
|
|
6571
6868
|
success: true,
|
|
6572
|
-
slug:
|
|
6573
|
-
url:
|
|
6869
|
+
slug: resolvedSlug,
|
|
6870
|
+
url: playUrl,
|
|
6871
|
+
fullUrl: playUrl,
|
|
6574
6872
|
shortUrl: updateResult.shortUrl,
|
|
6575
6873
|
embedUrl: updateResult.embedUrl,
|
|
6576
6874
|
semver: updatedConfig.version,
|
|
6577
6875
|
versionNumber: updateResult.versionNumber,
|
|
6578
6876
|
visibility: updatedConfig.visibility,
|
|
6877
|
+
category: updatedConfig.category,
|
|
6579
6878
|
aspectRatio: updatedConfig.aspectRatio,
|
|
6580
6879
|
supportedPlatforms: resolvedPlatforms,
|
|
6581
6880
|
platforms: resolvedPlatforms,
|
|
@@ -6593,9 +6892,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6593
6892
|
\u2714 Stage '${existingConfig.slug}' successfully updated to v${updatedConfig.version}!`
|
|
6594
6893
|
)
|
|
6595
6894
|
);
|
|
6596
|
-
console.log(
|
|
6597
|
-
` Play URL: ${pc3.cyan(updateResult.url || `https://replaystage.com/g/${existingConfig.slug}`)}`
|
|
6598
|
-
);
|
|
6895
|
+
console.log(` Play URL: ${pc3.cyan(playUrl)}`);
|
|
6599
6896
|
if (updatedConfig.visibility) {
|
|
6600
6897
|
console.log(` Visibility: ${pc3.bold(updatedConfig.visibility)}`);
|
|
6601
6898
|
}
|
|
@@ -6611,24 +6908,32 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6611
6908
|
console.log(pc3.dim(" \u2139 Project state updated in .replaystage.json\n"));
|
|
6612
6909
|
}
|
|
6613
6910
|
} catch (err) {
|
|
6614
|
-
const
|
|
6615
|
-
|
|
6911
|
+
const NON_RECOVERABLE_403_CODES = /* @__PURE__ */ new Set([
|
|
6912
|
+
"HASH_BLOCKED",
|
|
6913
|
+
"TAKEDOWN_BLOCKED",
|
|
6914
|
+
"COPYRIGHT_RESTRICTED"
|
|
6915
|
+
]);
|
|
6916
|
+
const isRecoverableWithFresh = err.status === 404 || err.status === 401 || err.status === 403 && !NON_RECOVERABLE_403_CODES.has(String(err.code || ""));
|
|
6917
|
+
const actionableMessage = isRecoverableWithFresh ? `${err.message}. If this stage was deleted or manage token expired, run with --fresh to deploy as a new stage.` : err.message || "Failed to update stage";
|
|
6616
6918
|
if (isJson) {
|
|
6617
6919
|
printErrorJson(err.code || "UPDATE_FAILED", actionableMessage, 1, {
|
|
6618
|
-
status: err.status
|
|
6920
|
+
status: err.status,
|
|
6921
|
+
...err.fieldErrors ? { fieldErrors: err.fieldErrors } : {}
|
|
6619
6922
|
});
|
|
6620
6923
|
} else {
|
|
6621
6924
|
console.error(pc3.red(`
|
|
6622
6925
|
\u2716 Update failed: ${err.message}`));
|
|
6623
|
-
if (
|
|
6926
|
+
if (isRecoverableWithFresh) {
|
|
6624
6927
|
console.error(
|
|
6625
6928
|
pc3.yellow(
|
|
6626
6929
|
"\n\u{1F4A1} Tip: Run 'replaystage publish --fresh' to deploy as a brand new stage.\n"
|
|
6627
6930
|
)
|
|
6628
6931
|
);
|
|
6932
|
+
} else {
|
|
6933
|
+
console.error();
|
|
6629
6934
|
}
|
|
6630
6935
|
}
|
|
6631
|
-
|
|
6936
|
+
exitWithError(1);
|
|
6632
6937
|
}
|
|
6633
6938
|
} else {
|
|
6634
6939
|
logInfo(
|
|
@@ -6659,6 +6964,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6659
6964
|
});
|
|
6660
6965
|
const initialVersion = result.semver || (visibility === "draft" ? "0.1.0" : "1.0.0");
|
|
6661
6966
|
const initialVisibility = result.visibility || visibility || (token ? "public" : "unlisted_claimable");
|
|
6967
|
+
const playUrl = resolvePlayableUrl(apiUrl, result, result.slug);
|
|
6662
6968
|
writeProjectConfig(resolvedPath, {
|
|
6663
6969
|
slug: result.slug,
|
|
6664
6970
|
manageToken: result.claim_token || result.claimToken,
|
|
@@ -6666,6 +6972,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6666
6972
|
version: initialVersion,
|
|
6667
6973
|
title,
|
|
6668
6974
|
tagline: tagline || void 0,
|
|
6975
|
+
category,
|
|
6669
6976
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6670
6977
|
visibility: initialVisibility,
|
|
6671
6978
|
aspectRatio: resolvedAspectRatio,
|
|
@@ -6679,7 +6986,8 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6679
6986
|
printJson({
|
|
6680
6987
|
success: true,
|
|
6681
6988
|
slug: result.slug,
|
|
6682
|
-
url:
|
|
6989
|
+
url: playUrl,
|
|
6990
|
+
fullUrl: playUrl,
|
|
6683
6991
|
shortUrl: result.shortUrl,
|
|
6684
6992
|
embedUrl: result.embedUrl,
|
|
6685
6993
|
fileHash: result.fileHash || bundle.fileHash,
|
|
@@ -6690,6 +6998,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6690
6998
|
status: result.status,
|
|
6691
6999
|
semver: initialVersion,
|
|
6692
7000
|
visibility: initialVisibility,
|
|
7001
|
+
category,
|
|
6693
7002
|
aspectRatio: resolvedAspectRatio,
|
|
6694
7003
|
supportedPlatforms: resolvedPlatforms,
|
|
6695
7004
|
platforms: resolvedPlatforms,
|
|
@@ -6701,7 +7010,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6701
7010
|
printPublishSuccess({
|
|
6702
7011
|
title,
|
|
6703
7012
|
slug: result.slug,
|
|
6704
|
-
url:
|
|
7013
|
+
url: playUrl,
|
|
6705
7014
|
shortUrl: result.shortUrl,
|
|
6706
7015
|
claim_token: result.claim_token,
|
|
6707
7016
|
claimUrl: result.claimUrl,
|
|
@@ -6718,8 +7027,14 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6718
7027
|
}
|
|
6719
7028
|
}
|
|
6720
7029
|
} catch (err) {
|
|
7030
|
+
if (exitHandled) {
|
|
7031
|
+
throw err;
|
|
7032
|
+
}
|
|
6721
7033
|
if (isJson) {
|
|
6722
|
-
printErrorJson(err.code || "UPLOAD_FAILED", err.message || "Failed to publish game", 1
|
|
7034
|
+
printErrorJson(err.code || "UPLOAD_FAILED", err.message || "Failed to publish game", 1, {
|
|
7035
|
+
...typeof err.status === "number" ? { status: err.status } : {},
|
|
7036
|
+
...err.fieldErrors ? { fieldErrors: err.fieldErrors } : {}
|
|
7037
|
+
});
|
|
6723
7038
|
} else {
|
|
6724
7039
|
console.error(pc3.red(`
|
|
6725
7040
|
\u2716 Publish failed: ${err.message}
|
|
@@ -6763,9 +7078,14 @@ async function handleValidate(targetPath = ".", options = {}) {
|
|
|
6763
7078
|
console.log(` ${pc4.dim("Bundle Size:")} ${sizeMb} MB (limit: 25 MB)`);
|
|
6764
7079
|
console.log(` ${pc4.dim("SHA-256:")} ${pc4.yellow(result.sha256 || "")}`);
|
|
6765
7080
|
console.log(
|
|
6766
|
-
` ${pc4.dim("Sanitization:")} ${pc4.green("Passed (clean bundle, no prohibited files)")}
|
|
6767
|
-
`
|
|
7081
|
+
` ${pc4.dim("Sanitization:")} ${pc4.green("Passed (clean bundle, no prohibited files)")}`
|
|
6768
7082
|
);
|
|
7083
|
+
if (result.warnings && result.warnings.length > 0) {
|
|
7084
|
+
for (const w of result.warnings) {
|
|
7085
|
+
console.log(pc4.yellow(` \u26A0 ${w}`));
|
|
7086
|
+
}
|
|
7087
|
+
}
|
|
7088
|
+
console.log();
|
|
6769
7089
|
}
|
|
6770
7090
|
|
|
6771
7091
|
// src/fingerprint.ts
|
|
@@ -6785,19 +7105,16 @@ async function computeFileFingerprint(filePath) {
|
|
|
6785
7105
|
}
|
|
6786
7106
|
|
|
6787
7107
|
// src/index.ts
|
|
6788
|
-
function createProgram() {
|
|
7108
|
+
function createProgram(opts) {
|
|
6789
7109
|
const program = new Command();
|
|
6790
|
-
program.name("replaystage").description("ReplayStage CLI: Deploy and share web games from command line and AI agents").version("0.
|
|
7110
|
+
program.name("replaystage").description("ReplayStage CLI: Deploy and share web games from command line and AI agents").version("0.5.0");
|
|
6791
7111
|
program.command("publish [path]").description("Package and deploy a web game to ReplayStage").option("-t, --title <title>", "Game title (2-60 characters)").option("-g, --tagline <tagline>", "Optional one-line arcade tagline (max 120 characters)").option("-d, --description <desc>", "Gameplay instructions or description").option(
|
|
6792
7112
|
"--tool <tool>",
|
|
6793
|
-
"AI tool used to generate the game (claude,
|
|
7113
|
+
"AI tool used to generate the game (claude-code, codex, antigravity, cursor, windsurf, claude, gemini, etc.)"
|
|
6794
7114
|
).option(
|
|
6795
7115
|
"-m, --model <model>",
|
|
6796
7116
|
"AI model used to synthesize the game (e.g., Claude Sonnet 5.5, GPT-6 Astra, Gemini 4 Carbon)"
|
|
6797
|
-
).option(
|
|
6798
|
-
"--cover <path>",
|
|
6799
|
-
"Path to custom cartridge cover image (PNG, JPG, WebP, GIF, max 2MB)"
|
|
6800
|
-
).option(
|
|
7117
|
+
).option("--cover <path>", "Path to custom cartridge cover image (PNG, JPG, WebP, GIF, max 2MB)").option(
|
|
6801
7118
|
"--category <category>",
|
|
6802
7119
|
"Game category (arcade, action, puzzle, strategy, simulation, racing, rpg, casual)"
|
|
6803
7120
|
).option(
|
|
@@ -6824,31 +7141,72 @@ function createProgram() {
|
|
|
6824
7141
|
program.command("logout").description("Clear stored credentials").option("--json", "Output machine-readable JSON").action(async (options) => {
|
|
6825
7142
|
await handleLogout(options);
|
|
6826
7143
|
});
|
|
7144
|
+
const configureCommandTree = (cmd) => {
|
|
7145
|
+
cmd.exitOverride();
|
|
7146
|
+
cmd.configureOutput({
|
|
7147
|
+
writeOut: (str) => process.stdout.write(str),
|
|
7148
|
+
writeErr: (str) => {
|
|
7149
|
+
if (!opts?.jsonMode) {
|
|
7150
|
+
process.stderr.write(str);
|
|
7151
|
+
}
|
|
7152
|
+
}
|
|
7153
|
+
});
|
|
7154
|
+
for (const sub of cmd.commands) {
|
|
7155
|
+
configureCommandTree(sub);
|
|
7156
|
+
}
|
|
7157
|
+
};
|
|
7158
|
+
configureCommandTree(program);
|
|
6827
7159
|
return program;
|
|
6828
7160
|
}
|
|
6829
|
-
var _cliExecuted = false;
|
|
6830
7161
|
async function runCli(argv = process.argv) {
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
const program = createProgram();
|
|
7162
|
+
const isJson = argv.includes("--json");
|
|
7163
|
+
const program = createProgram({ jsonMode: isJson });
|
|
6834
7164
|
try {
|
|
6835
7165
|
await program.parseAsync(argv);
|
|
6836
7166
|
} catch (err) {
|
|
6837
|
-
|
|
7167
|
+
if (err && (err.code === "commander.helpDisplayed" || err.code === "commander.help" || err.code === "commander.version" || err.exitCode === 0)) {
|
|
7168
|
+
return;
|
|
7169
|
+
}
|
|
7170
|
+
const isCommanderParseError = err?.name === "CommanderError" || typeof err?.code === "string" && err.code.startsWith("commander.");
|
|
7171
|
+
const cleanMessage = String(err?.message || "Invalid CLI options").replace(/^error:\s*/i, "").trim();
|
|
6838
7172
|
if (isJson) {
|
|
7173
|
+
const errorCode = isCommanderParseError ? "INVALID_OPTIONS" : "CLI_ERROR";
|
|
6839
7174
|
process.stdout.write(
|
|
6840
|
-
`${JSON.stringify(
|
|
7175
|
+
`${JSON.stringify(
|
|
7176
|
+
{
|
|
7177
|
+
ok: false,
|
|
7178
|
+
success: false,
|
|
7179
|
+
code: errorCode,
|
|
7180
|
+
message: cleanMessage,
|
|
7181
|
+
error: {
|
|
7182
|
+
code: errorCode,
|
|
7183
|
+
message: cleanMessage
|
|
7184
|
+
}
|
|
7185
|
+
},
|
|
7186
|
+
null,
|
|
7187
|
+
2
|
|
7188
|
+
)}
|
|
6841
7189
|
`
|
|
6842
7190
|
);
|
|
6843
|
-
} else {
|
|
6844
|
-
console.error(err
|
|
7191
|
+
} else if (!isCommanderParseError) {
|
|
7192
|
+
console.error(err?.message || String(err));
|
|
6845
7193
|
}
|
|
6846
|
-
process.exit(1);
|
|
7194
|
+
process.exit(typeof err?.exitCode === "number" && err.exitCode > 0 ? err.exitCode : 1);
|
|
7195
|
+
}
|
|
7196
|
+
}
|
|
7197
|
+
function isDirectCliExecution(argv1 = typeof process !== "undefined" ? process.argv[1] : void 0, moduleUrl = import.meta.url) {
|
|
7198
|
+
if (!argv1 || process.env.VITEST) {
|
|
7199
|
+
return false;
|
|
7200
|
+
}
|
|
7201
|
+
try {
|
|
7202
|
+
const currentFile = fs7.realpathSync(fileURLToPath(moduleUrl));
|
|
7203
|
+
const invokedFile = fs7.realpathSync(path7.resolve(argv1));
|
|
7204
|
+
return currentFile === invokedFile;
|
|
7205
|
+
} catch {
|
|
7206
|
+
return false;
|
|
6847
7207
|
}
|
|
6848
7208
|
}
|
|
6849
|
-
|
|
6850
|
-
var isDirectCliExecution = Boolean(argv1) && !process.env.VITEST && (argv1.endsWith("replaystage.js") || argv1.endsWith("/replaystage") || argv1.endsWith("\\replaystage") || argv1.endsWith("index.js") || argv1.endsWith("index.mjs"));
|
|
6851
|
-
if (isDirectCliExecution) {
|
|
7209
|
+
if (isDirectCliExecution()) {
|
|
6852
7210
|
void runCli(process.argv);
|
|
6853
7211
|
}
|
|
6854
7212
|
export {
|
|
@@ -6862,6 +7220,8 @@ export {
|
|
|
6862
7220
|
createProgram,
|
|
6863
7221
|
createZipFromFiles,
|
|
6864
7222
|
detectSiblingCover,
|
|
7223
|
+
extractErrorMessage,
|
|
7224
|
+
extractFieldErrors,
|
|
6865
7225
|
extractHtmlMetadata,
|
|
6866
7226
|
fetchWhoami,
|
|
6867
7227
|
getConfigDir,
|
|
@@ -6869,6 +7229,7 @@ export {
|
|
|
6869
7229
|
getProjectConfigPath,
|
|
6870
7230
|
getToken,
|
|
6871
7231
|
incrementVersion,
|
|
7232
|
+
isDirectCliExecution,
|
|
6872
7233
|
logError,
|
|
6873
7234
|
logInfo,
|
|
6874
7235
|
logSuccess,
|
|
@@ -6881,6 +7242,7 @@ export {
|
|
|
6881
7242
|
readConfig,
|
|
6882
7243
|
readProjectConfig,
|
|
6883
7244
|
resolveApiUrl,
|
|
7245
|
+
resolvePlayableUrl,
|
|
6884
7246
|
resolveProjectDirectory,
|
|
6885
7247
|
resolveToken,
|
|
6886
7248
|
runCli,
|