@replaystage/cli 0.4.0 → 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 +17 -3
- package/dist/index.js +516 -173
- 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;
|
|
34
|
+
}
|
|
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
|
+
}
|
|
43
|
+
}
|
|
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
|
+
}
|
|
18
55
|
}
|
|
19
|
-
|
|
20
|
-
|
|
56
|
+
const fieldErrors = extractFieldErrors(data);
|
|
57
|
+
if (fieldErrors) {
|
|
58
|
+
for (const [field, msgs] of Object.entries(fieldErrors)) {
|
|
59
|
+
parts.push(`${field}: ${msgs.join(", ")}`);
|
|
60
|
+
}
|
|
21
61
|
}
|
|
22
|
-
|
|
23
|
-
|
|
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"}`;
|
|
24
76
|
}
|
|
25
|
-
|
|
26
|
-
|
|
77
|
+
const detailStr = formatValidationDetails(data);
|
|
78
|
+
if (detailStr && !baseMsg.includes(detailStr)) {
|
|
79
|
+
return `${baseMsg}: ${detailStr}`;
|
|
27
80
|
}
|
|
28
|
-
return
|
|
81
|
+
return baseMsg;
|
|
29
82
|
}
|
|
30
83
|
async function uploadGameBundle(options) {
|
|
31
84
|
const formData = new FormData();
|
|
@@ -33,7 +86,7 @@ async function uploadGameBundle(options) {
|
|
|
33
86
|
const blob = new Blob([uint8], { type: "application/zip" });
|
|
34
87
|
formData.append("bundle", blob, "bundle.zip");
|
|
35
88
|
formData.append("title", options.title);
|
|
36
|
-
formData.append("tagline", options.tagline);
|
|
89
|
+
formData.append("tagline", options.tagline ?? "");
|
|
37
90
|
if (options.description) formData.append("description", options.description);
|
|
38
91
|
if (options.category) formData.append("category", options.category);
|
|
39
92
|
formData.append("submission_type", options.submissionType || "maker");
|
|
@@ -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
|
};
|
|
@@ -112,8 +173,9 @@ async function updateGameBundle(slug, options) {
|
|
|
112
173
|
formData.append("bundle", blob, "bundle.zip");
|
|
113
174
|
}
|
|
114
175
|
if (options.title) formData.append("title", options.title);
|
|
115
|
-
if (options.tagline) formData.append("tagline", options.tagline);
|
|
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(
|
|
4799
|
-
MAX_GAME_TAGLINE_LENGTH,
|
|
4800
|
-
`Tagline must be ${MAX_GAME_TAGLINE_LENGTH} characters or less`
|
|
4801
|
-
),
|
|
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"),
|
|
@@ -4819,7 +4969,6 @@ var baseGameUploadObject = external_exports.object({
|
|
|
4819
4969
|
aspectRatio: aspectRatioSchema.default(DEFAULT_ASPECT_RATIO),
|
|
4820
4970
|
supportedPlatforms: supportedPlatformsSchema.default(DEFAULT_SUPPORTED_PLATFORMS),
|
|
4821
4971
|
changelog: external_exports.string().trim().max(500).optional(),
|
|
4822
|
-
slug: slugSchema.optional(),
|
|
4823
4972
|
fileHash: external_exports.string().regex(SHA256_REGEX, "Invalid SHA-256 hash format").optional(),
|
|
4824
4973
|
sourceCode: external_exports.string().max(MAX_HTML_SIZE_BYTES, "Single-file HTML cannot exceed 5MB").optional().nullable(),
|
|
4825
4974
|
thumbnailUrl: thumbnailUrlSchema.optional().nullable(),
|
|
@@ -4829,27 +4978,7 @@ var baseGameUploadObject = external_exports.object({
|
|
|
4829
4978
|
mobile: external_exports.string().max(300).optional()
|
|
4830
4979
|
}).optional().nullable()
|
|
4831
4980
|
});
|
|
4832
|
-
var gameUploadSchema =
|
|
4833
|
-
if (val && typeof val === "object" && !Array.isArray(val)) {
|
|
4834
|
-
const raw = { ...val };
|
|
4835
|
-
if (raw.visibility === "draft" && (raw.tagline === void 0 || raw.tagline === null)) {
|
|
4836
|
-
raw.tagline = "";
|
|
4837
|
-
}
|
|
4838
|
-
return raw;
|
|
4839
|
-
}
|
|
4840
|
-
return val;
|
|
4841
|
-
}, baseGameUploadObject).superRefine((data, ctx) => {
|
|
4842
|
-
if (data.visibility !== "draft" && (!data.tagline || data.tagline.trim().length < 3)) {
|
|
4843
|
-
ctx.addIssue({
|
|
4844
|
-
code: external_exports.ZodIssueCode.too_small,
|
|
4845
|
-
minimum: 3,
|
|
4846
|
-
type: "string",
|
|
4847
|
-
inclusive: true,
|
|
4848
|
-
path: ["tagline"],
|
|
4849
|
-
message: "Tagline must be at least 3 characters"
|
|
4850
|
-
});
|
|
4851
|
-
}
|
|
4852
|
-
}).transform((data) => {
|
|
4981
|
+
var gameUploadSchema = baseGameUploadObject.transform((data) => {
|
|
4853
4982
|
if (data.submissionType === "hunter" && !data.isOss) {
|
|
4854
4983
|
return {
|
|
4855
4984
|
...data,
|
|
@@ -4860,10 +4989,7 @@ var gameUploadSchema = external_exports.preprocess((val) => {
|
|
|
4860
4989
|
});
|
|
4861
4990
|
var gameUpdateSchema = external_exports.object({
|
|
4862
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(),
|
|
4863
|
-
tagline: external_exports.string().trim().max(
|
|
4864
|
-
MAX_GAME_TAGLINE_LENGTH,
|
|
4865
|
-
`Tagline must be ${MAX_GAME_TAGLINE_LENGTH} characters or less`
|
|
4866
|
-
).optional(),
|
|
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),
|
|
4867
4993
|
description: external_exports.string().max(
|
|
4868
4994
|
MAX_GAME_DESCRIPTION_LENGTH,
|
|
4869
4995
|
`Description must be ${MAX_GAME_DESCRIPTION_LENGTH} characters or less`
|
|
@@ -4917,11 +5043,11 @@ var claimAuthorshipSchema = external_exports.object({
|
|
|
4917
5043
|
]).optional().nullable(),
|
|
4918
5044
|
notes: external_exports.string().max(1e3, "Notes must be 1000 characters or less").optional().nullable()
|
|
4919
5045
|
});
|
|
4920
|
-
var
|
|
4921
|
-
gameId: external_exports.string().min(1, "Game ID is required"),
|
|
4922
|
-
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(),
|
|
4923
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"),
|
|
4924
|
-
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"),
|
|
4925
5051
|
confirmTakedown: external_exports.literal(true, {
|
|
4926
5052
|
errorMap: () => ({
|
|
4927
5053
|
message: "You must check the confirmation box to proceed with instant takedown"
|
|
@@ -5081,6 +5207,9 @@ function validateZipEntryPath(rawPath) {
|
|
|
5081
5207
|
return { valid: false, error: `Prohibited system or environment file: ${cleanPath}` };
|
|
5082
5208
|
}
|
|
5083
5209
|
}
|
|
5210
|
+
if (!isAllowedFileExtension(cleanPath)) {
|
|
5211
|
+
return { valid: false, error: `Unsupported or disallowed file extension: ${cleanPath}` };
|
|
5212
|
+
}
|
|
5084
5213
|
return {
|
|
5085
5214
|
valid: true,
|
|
5086
5215
|
normalizedPath: cleanPath
|
|
@@ -5088,7 +5217,18 @@ function validateZipEntryPath(rawPath) {
|
|
|
5088
5217
|
}
|
|
5089
5218
|
function isIgnoredZipEntry(entryPath) {
|
|
5090
5219
|
const normalized = entryPath.replace(/\\/g, "/");
|
|
5091
|
-
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);
|
|
5092
5232
|
}
|
|
5093
5233
|
var MAX_COVER_IMAGE_BYTES = 2 * 1024 * 1024;
|
|
5094
5234
|
function validateCoverImageBytes(bytes) {
|
|
@@ -5241,13 +5381,28 @@ function extractTagsFromHtml(html) {
|
|
|
5241
5381
|
}
|
|
5242
5382
|
|
|
5243
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
|
+
}
|
|
5244
5399
|
function resolveProjectDirectory(targetPath) {
|
|
5245
5400
|
try {
|
|
5246
5401
|
const resolved = path.resolve(targetPath);
|
|
5247
5402
|
if (resolved.toLowerCase().endsWith(".zip")) {
|
|
5248
5403
|
return null;
|
|
5249
5404
|
}
|
|
5250
|
-
if (resolved
|
|
5405
|
+
if (isReplaystageRepoSeedGamesFixture(resolved)) {
|
|
5251
5406
|
return null;
|
|
5252
5407
|
}
|
|
5253
5408
|
if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) {
|
|
@@ -5288,7 +5443,7 @@ function readProjectConfig(targetDir) {
|
|
|
5288
5443
|
return null;
|
|
5289
5444
|
}
|
|
5290
5445
|
}
|
|
5291
|
-
const hasValidKey = typeof parsed.slug === "string" && parsed.slug.trim().length > 0 || 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";
|
|
5292
5447
|
if (!hasValidKey) {
|
|
5293
5448
|
return null;
|
|
5294
5449
|
}
|
|
@@ -5396,10 +5551,15 @@ function setToken(token, user, apiUrl) {
|
|
|
5396
5551
|
});
|
|
5397
5552
|
}
|
|
5398
5553
|
function clearToken() {
|
|
5399
|
-
const
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
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
|
+
}
|
|
5403
5563
|
}
|
|
5404
5564
|
function resolveToken(cliToken) {
|
|
5405
5565
|
if (cliToken?.trim()) return cliToken.trim();
|
|
@@ -5429,7 +5589,7 @@ function printJson(data) {
|
|
|
5429
5589
|
}
|
|
5430
5590
|
function printErrorJson(error, message, code = 1, extra) {
|
|
5431
5591
|
process.stdout.write(
|
|
5432
|
-
`${JSON.stringify({ success: false, code, error, message, ...extra }, null, 2)}
|
|
5592
|
+
`${JSON.stringify({ ok: false, success: false, code, error, message, ...extra }, null, 2)}
|
|
5433
5593
|
`
|
|
5434
5594
|
);
|
|
5435
5595
|
}
|
|
@@ -5544,17 +5704,26 @@ async function handleLogin(options = {}) {
|
|
|
5544
5704
|
}
|
|
5545
5705
|
try {
|
|
5546
5706
|
let user = void 0;
|
|
5707
|
+
let offlineWarning = void 0;
|
|
5547
5708
|
try {
|
|
5548
5709
|
user = await fetchWhoami(apiUrl, token);
|
|
5549
5710
|
} catch (err) {
|
|
5550
|
-
if (
|
|
5711
|
+
if (typeof err?.status === "number") {
|
|
5551
5712
|
throw err;
|
|
5552
5713
|
}
|
|
5553
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);
|
|
5554
5717
|
}
|
|
5555
5718
|
setToken(token, user, options.apiUrl ? apiUrl : void 0);
|
|
5556
5719
|
if (isJson) {
|
|
5557
|
-
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
|
+
});
|
|
5558
5727
|
} else {
|
|
5559
5728
|
console.log(
|
|
5560
5729
|
pc2.green(`
|
|
@@ -5634,11 +5803,26 @@ async function handleWhoami(options = {}) {
|
|
|
5634
5803
|
}
|
|
5635
5804
|
async function handleLogout(options = {}) {
|
|
5636
5805
|
const isJson = Boolean(options.json);
|
|
5637
|
-
|
|
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;
|
|
5638
5812
|
if (isJson) {
|
|
5639
|
-
printJson({
|
|
5813
|
+
printJson({
|
|
5814
|
+
success: true,
|
|
5815
|
+
message: "Logged out successfully",
|
|
5816
|
+
...envWarning ? { warning: envWarning, envTokenActive: true } : {}
|
|
5817
|
+
});
|
|
5640
5818
|
} else {
|
|
5641
|
-
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
|
+
}
|
|
5642
5826
|
}
|
|
5643
5827
|
}
|
|
5644
5828
|
|
|
@@ -5742,7 +5926,8 @@ function extractHtmlMetadata(html) {
|
|
|
5742
5926
|
let tagline;
|
|
5743
5927
|
const titleMatch = html.match(/<\s*title[^>]*>([\s\S]*?)<\s*\/\s*title>/i);
|
|
5744
5928
|
if (titleMatch?.[1]) {
|
|
5745
|
-
|
|
5929
|
+
const strippedInner = titleMatch[1].replace(/<[^>]+>/g, "");
|
|
5930
|
+
title = extractHtmlTitle(`<title>${strippedInner}</title>`) ?? void 0;
|
|
5746
5931
|
}
|
|
5747
5932
|
const descMatch = html.match(/<\s*meta[^>]+name=["']description["'][^>]+content=["']([^"']*)["']/i) || html.match(/<\s*meta[^>]+content=["']([^"']*)["'][^>]+name=["']description["']/i);
|
|
5748
5933
|
if (descMatch?.[1]) {
|
|
@@ -5761,6 +5946,34 @@ function extractHtmlMetadata(html) {
|
|
|
5761
5946
|
tags: tags.length > 0 ? tags : void 0
|
|
5762
5947
|
};
|
|
5763
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
|
+
]);
|
|
5764
5977
|
function computeSha256(buf) {
|
|
5765
5978
|
return crypto.createHash("sha256").update(buf).digest("hex").toLowerCase();
|
|
5766
5979
|
}
|
|
@@ -5791,7 +6004,7 @@ async function packageGame(targetPath) {
|
|
|
5791
6004
|
const meta = extractHtmlMetadata(content.toString("utf-8"));
|
|
5792
6005
|
const files = { "index.html": content };
|
|
5793
6006
|
const detectedCover = detectSiblingCover(resolved);
|
|
5794
|
-
if (detectedCover
|
|
6007
|
+
if (detectedCover?.buffer) {
|
|
5795
6008
|
files[detectedCover.fileName] = detectedCover.buffer;
|
|
5796
6009
|
}
|
|
5797
6010
|
const zipBuffer = createZipFromFiles(files);
|
|
@@ -5824,13 +6037,29 @@ async function packageGame(targetPath) {
|
|
|
5824
6037
|
const entryPaths = Object.keys(unzipped);
|
|
5825
6038
|
for (const entryPath of entryPaths) {
|
|
5826
6039
|
if (isIgnoredZipEntry(entryPath)) continue;
|
|
5827
|
-
const
|
|
6040
|
+
const normSlash = entryPath.replace(/\\/g, "/");
|
|
6041
|
+
const normLower = normSlash.toLowerCase();
|
|
5828
6042
|
const segments = normLower.split("/").filter(Boolean);
|
|
5829
6043
|
if (segments.some((seg) => seg === ".replaystage.json" || seg.startsWith(".replaystage"))) {
|
|
5830
6044
|
throw new Error(
|
|
5831
6045
|
`Prohibited file in zip archive: '${entryPath}'. ReplayStage state files contain secret management tokens and must not be included in game archives.`
|
|
5832
6046
|
);
|
|
5833
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
|
+
}
|
|
5834
6063
|
const validRes = validateZipEntryPath(entryPath);
|
|
5835
6064
|
if (!validRes.valid) {
|
|
5836
6065
|
throw new Error(`Invalid file in zip archive: ${validRes.error}`);
|
|
@@ -5846,16 +6075,17 @@ async function packageGame(targetPath) {
|
|
|
5846
6075
|
);
|
|
5847
6076
|
}
|
|
5848
6077
|
const fileHash = computeSha256(content);
|
|
5849
|
-
const filteredFiles = entryPaths.filter(
|
|
6078
|
+
const filteredFiles = entryPaths.filter(
|
|
6079
|
+
(p) => !isIgnoredZipEntry(p) && !p.replace(/\\/g, "/").endsWith("/")
|
|
6080
|
+
);
|
|
5850
6081
|
let extractedTitle;
|
|
5851
6082
|
let extractedTagline;
|
|
5852
6083
|
let extractedAspectRatio;
|
|
5853
6084
|
let extractedModel;
|
|
5854
6085
|
let extractedTags;
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
);
|
|
6086
|
+
const rawEntryBytes = findRawZipEntryBytes(unzipped, entryRes.entryPath);
|
|
6087
|
+
if (rawEntryBytes) {
|
|
6088
|
+
const meta = extractHtmlMetadata(Buffer.from(rawEntryBytes).toString("utf-8"));
|
|
5859
6089
|
extractedTitle = meta.title;
|
|
5860
6090
|
extractedTagline = meta.tagline;
|
|
5861
6091
|
extractedAspectRatio = meta.aspectRatio;
|
|
@@ -6006,6 +6236,17 @@ function checkHtmlDependencies(content) {
|
|
|
6006
6236
|
}
|
|
6007
6237
|
return { valid: errors.length === 0, errors };
|
|
6008
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
|
+
}
|
|
6009
6250
|
async function validateGamePackage(targetPath) {
|
|
6010
6251
|
const resolved = path4.resolve(process.cwd(), targetPath || ".");
|
|
6011
6252
|
const errors = [];
|
|
@@ -6075,8 +6316,9 @@ async function validateGamePackage(targetPath) {
|
|
|
6075
6316
|
const unzipped = fflate2.unzipSync(new Uint8Array(content));
|
|
6076
6317
|
const entryPaths = Object.keys(unzipped);
|
|
6077
6318
|
const entryRes = findEntryHtmlFile(entryPaths);
|
|
6078
|
-
|
|
6079
|
-
|
|
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");
|
|
6080
6322
|
const depCheck = checkHtmlDependencies(htmlContent);
|
|
6081
6323
|
if (!depCheck.valid) {
|
|
6082
6324
|
errors.push(...depCheck.errors);
|
|
@@ -6122,24 +6364,33 @@ async function validateGamePackage(targetPath) {
|
|
|
6122
6364
|
}
|
|
6123
6365
|
for (const entry of entries) {
|
|
6124
6366
|
const name = entry.name;
|
|
6125
|
-
|
|
6126
|
-
continue;
|
|
6127
|
-
}
|
|
6367
|
+
const lowerName = name.toLowerCase();
|
|
6128
6368
|
const fullPath = path4.join(currentDir, name);
|
|
6129
6369
|
const relPath = relDir ? `${relDir}/${name}` : name;
|
|
6130
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
|
+
}
|
|
6131
6380
|
if (isIgnoredZipEntry(normalizedRelPath)) continue;
|
|
6132
6381
|
if (entry.isDirectory()) {
|
|
6133
6382
|
scan2(fullPath, relPath);
|
|
6134
6383
|
} else if (entry.isFile()) {
|
|
6135
6384
|
if (isProhibitedExtension(normalizedRelPath)) {
|
|
6136
6385
|
errors.push(
|
|
6137
|
-
`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.`
|
|
6138
6387
|
);
|
|
6388
|
+
continue;
|
|
6139
6389
|
}
|
|
6140
6390
|
const pathValidation = validateZipEntryPath(normalizedRelPath);
|
|
6141
6391
|
if (!pathValidation.valid) {
|
|
6142
6392
|
errors.push(`Invalid file path in directory: ${pathValidation.error}`);
|
|
6393
|
+
continue;
|
|
6143
6394
|
}
|
|
6144
6395
|
try {
|
|
6145
6396
|
const fileStat = fs4.statSync(fullPath);
|
|
@@ -6155,15 +6406,6 @@ async function validateGamePackage(targetPath) {
|
|
|
6155
6406
|
const collectedFiles = [];
|
|
6156
6407
|
let totalSize = 0;
|
|
6157
6408
|
scan2(resolved, "");
|
|
6158
|
-
try {
|
|
6159
|
-
const rootEntries = fs4.readdirSync(resolved);
|
|
6160
|
-
for (const entry of rootEntries) {
|
|
6161
|
-
if (entry === ".env" || entry.startsWith(".env.") || entry === ".git" || entry.endsWith(".exe")) {
|
|
6162
|
-
errors.push(`Prohibited file detected: '${entry}'`);
|
|
6163
|
-
}
|
|
6164
|
-
}
|
|
6165
|
-
} catch {
|
|
6166
|
-
}
|
|
6167
6409
|
if (totalSize > MAX_BUNDLE_SIZE_BYTES) {
|
|
6168
6410
|
errors.push(
|
|
6169
6411
|
`Total game size exceeds 25MB limit (${(totalSize / (1024 * 1024)).toFixed(2)} MB).`
|
|
@@ -6281,6 +6523,11 @@ async function validateGamePackage(targetPath) {
|
|
|
6281
6523
|
// src/commands/publish.ts
|
|
6282
6524
|
async function handlePublish(targetPath = ".", options = {}) {
|
|
6283
6525
|
const isJson = Boolean(options.json);
|
|
6526
|
+
let exitHandled = false;
|
|
6527
|
+
const exitWithError = (code = 1) => {
|
|
6528
|
+
exitHandled = true;
|
|
6529
|
+
return process.exit(code);
|
|
6530
|
+
};
|
|
6284
6531
|
try {
|
|
6285
6532
|
const visibilityFlagsCount = [
|
|
6286
6533
|
Boolean(options.draft),
|
|
@@ -6296,7 +6543,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6296
6543
|
\u2716 Invalid options: ${errorMsg}
|
|
6297
6544
|
`));
|
|
6298
6545
|
}
|
|
6299
|
-
|
|
6546
|
+
exitWithError(1);
|
|
6300
6547
|
}
|
|
6301
6548
|
let visibility = void 0;
|
|
6302
6549
|
if (options.draft) {
|
|
@@ -6306,6 +6553,22 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6306
6553
|
} else if (options.public) {
|
|
6307
6554
|
visibility = "public";
|
|
6308
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
|
+
}
|
|
6309
6572
|
const resolvedPath = path5.resolve(process.cwd(), targetPath || ".");
|
|
6310
6573
|
logInfo(`Validating game package at ${resolvedPath}...`, isJson);
|
|
6311
6574
|
const validation = await validateGamePackage(resolvedPath);
|
|
@@ -6319,36 +6582,45 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6319
6582
|
${validation.errors.join("\n ")}
|
|
6320
6583
|
`));
|
|
6321
6584
|
}
|
|
6322
|
-
|
|
6585
|
+
exitWithError(1);
|
|
6586
|
+
}
|
|
6587
|
+
for (const warning of validation.warnings) {
|
|
6588
|
+
logWarn(warning, isJson);
|
|
6323
6589
|
}
|
|
6324
6590
|
logInfo("Packaging game bundle...", isJson);
|
|
6325
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;
|
|
6326
6595
|
let title = options.title?.trim();
|
|
6327
|
-
if (!title &&
|
|
6328
|
-
title =
|
|
6596
|
+
if (!title && existingConfig?.title?.trim()) {
|
|
6597
|
+
title = existingConfig.title.trim();
|
|
6598
|
+
}
|
|
6599
|
+
if (!title && bundle.extractedTitle?.trim()) {
|
|
6600
|
+
title = bundle.extractedTitle.trim();
|
|
6329
6601
|
}
|
|
6330
6602
|
if (!title) {
|
|
6331
|
-
|
|
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();
|
|
6332
6606
|
title = title.replace(/\b\w/g, (c) => c.toUpperCase());
|
|
6333
6607
|
}
|
|
6334
6608
|
if (title.length < 2) title = "Web Game";
|
|
6335
6609
|
if (title.length > 60) title = title.slice(0, 60);
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
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;
|
|
6615
|
+
let tagline = "";
|
|
6616
|
+
if (options.tagline !== void 0) {
|
|
6617
|
+
tagline = options.tagline.trim();
|
|
6618
|
+
} else if (bundle.extractedTagline?.trim()) {
|
|
6619
|
+
tagline = bundle.extractedTagline.trim();
|
|
6620
|
+
} else if (existingConfig?.tagline?.trim()) {
|
|
6621
|
+
tagline = existingConfig.tagline.trim();
|
|
6339
6622
|
}
|
|
6340
|
-
if (!tagline) {
|
|
6341
|
-
tagline = "Playable web game deployed to ReplayStage";
|
|
6342
|
-
}
|
|
6343
|
-
if (tagline.length < 3) tagline = "An arcade game on ReplayStage";
|
|
6344
6623
|
if (tagline.length > 120) tagline = tagline.slice(0, 120);
|
|
6345
|
-
let category = options.category?.toLowerCase().trim();
|
|
6346
|
-
if (category && !GAME_CATEGORY_KEYS.includes(category)) {
|
|
6347
|
-
category = void 0;
|
|
6348
|
-
}
|
|
6349
|
-
const token = options.anonymous ? null : resolveToken(options.token);
|
|
6350
|
-
const apiUrl = resolveApiUrl(options.apiUrl);
|
|
6351
|
-
const existingConfig = !options.fresh ? readProjectConfig(resolvedPath) : null;
|
|
6352
6624
|
let aiTool = "";
|
|
6353
6625
|
if (options.tool !== void 0) {
|
|
6354
6626
|
const parsedTool = aiToolSchema.safeParse(options.tool);
|
|
@@ -6361,7 +6633,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6361
6633
|
\u2716 Invalid option: ${errorMsg}
|
|
6362
6634
|
`));
|
|
6363
6635
|
}
|
|
6364
|
-
|
|
6636
|
+
exitWithError(1);
|
|
6365
6637
|
}
|
|
6366
6638
|
const rawTool = parsedTool.data;
|
|
6367
6639
|
if (rawTool) {
|
|
@@ -6387,7 +6659,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6387
6659
|
\u2716 Invalid option: ${errorMsg}
|
|
6388
6660
|
`));
|
|
6389
6661
|
}
|
|
6390
|
-
|
|
6662
|
+
exitWithError(1);
|
|
6391
6663
|
}
|
|
6392
6664
|
resolvedModel = parsedModel.data ?? null;
|
|
6393
6665
|
} else if (bundle.extractedModel) {
|
|
@@ -6408,7 +6680,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6408
6680
|
\u2716 Invalid option: ${errorMsg}
|
|
6409
6681
|
`));
|
|
6410
6682
|
}
|
|
6411
|
-
|
|
6683
|
+
exitWithError(1);
|
|
6412
6684
|
}
|
|
6413
6685
|
const stat = fs5.statSync(resolvedCoverPath);
|
|
6414
6686
|
if (!stat.isFile()) {
|
|
@@ -6420,7 +6692,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6420
6692
|
\u2716 Invalid option: ${errorMsg}
|
|
6421
6693
|
`));
|
|
6422
6694
|
}
|
|
6423
|
-
|
|
6695
|
+
exitWithError(1);
|
|
6424
6696
|
}
|
|
6425
6697
|
const ext = path5.extname(resolvedCoverPath).toLowerCase().replace(".", "");
|
|
6426
6698
|
const allowedExts = ["png", "jpg", "jpeg", "webp", "gif"];
|
|
@@ -6433,7 +6705,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6433
6705
|
\u2716 Invalid option: ${errorMsg}
|
|
6434
6706
|
`));
|
|
6435
6707
|
}
|
|
6436
|
-
|
|
6708
|
+
exitWithError(1);
|
|
6437
6709
|
}
|
|
6438
6710
|
const rawCoverBytes = fs5.readFileSync(resolvedCoverPath);
|
|
6439
6711
|
const coverValidation = validateCoverImageBytes(new Uint8Array(rawCoverBytes));
|
|
@@ -6446,7 +6718,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6446
6718
|
\u2716 Invalid option: ${errorMsg}
|
|
6447
6719
|
`));
|
|
6448
6720
|
}
|
|
6449
|
-
|
|
6721
|
+
exitWithError(1);
|
|
6450
6722
|
}
|
|
6451
6723
|
coverBuffer = rawCoverBytes;
|
|
6452
6724
|
coverFileName = path5.basename(resolvedCoverPath);
|
|
@@ -6469,7 +6741,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6469
6741
|
\u2716 Invalid option: ${errorMsg}
|
|
6470
6742
|
`));
|
|
6471
6743
|
}
|
|
6472
|
-
|
|
6744
|
+
exitWithError(1);
|
|
6473
6745
|
}
|
|
6474
6746
|
resolvedAspectRatio = norm.normalized;
|
|
6475
6747
|
} else if (validation.aspectRatio && validation.aspectRatio !== "auto") {
|
|
@@ -6489,7 +6761,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6489
6761
|
\u2716 Invalid option: ${errorMsg}
|
|
6490
6762
|
`));
|
|
6491
6763
|
}
|
|
6492
|
-
|
|
6764
|
+
exitWithError(1);
|
|
6493
6765
|
}
|
|
6494
6766
|
resolvedPlatforms = norm.normalized;
|
|
6495
6767
|
} else if (validation.hasPlatformMeta && validation.supportedPlatforms) {
|
|
@@ -6515,7 +6787,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6515
6787
|
\u2716 Invalid option: ${errorMsg}
|
|
6516
6788
|
`));
|
|
6517
6789
|
}
|
|
6518
|
-
|
|
6790
|
+
exitWithError(1);
|
|
6519
6791
|
}
|
|
6520
6792
|
for (const rawTag of rawTags) {
|
|
6521
6793
|
const formatted = rawTag.toLowerCase().replace(/[\s_]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -6529,7 +6801,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6529
6801
|
\u2716 Invalid option: ${errorMsg}
|
|
6530
6802
|
`));
|
|
6531
6803
|
}
|
|
6532
|
-
|
|
6804
|
+
exitWithError(1);
|
|
6533
6805
|
}
|
|
6534
6806
|
}
|
|
6535
6807
|
resolvedTags = normalizeTags(rawTags);
|
|
@@ -6553,16 +6825,17 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6553
6825
|
apiUrl,
|
|
6554
6826
|
bundleBuffer: bundle.bundleBuffer,
|
|
6555
6827
|
title,
|
|
6556
|
-
tagline,
|
|
6828
|
+
tagline: options.tagline !== void 0 ? tagline : tagline || void 0,
|
|
6557
6829
|
description: options.description,
|
|
6830
|
+
category: updateCategory,
|
|
6558
6831
|
visibility,
|
|
6559
6832
|
changelog: options.changelog,
|
|
6560
6833
|
aspectRatio: resolvedAspectRatio,
|
|
6561
6834
|
supportedPlatforms: resolvedPlatforms,
|
|
6562
6835
|
manageToken: existingConfig.manageToken,
|
|
6563
6836
|
token,
|
|
6564
|
-
aiModel: resolvedModel,
|
|
6565
|
-
aiTool,
|
|
6837
|
+
aiModel: options.model !== void 0 ? resolvedModel ?? "" : resolvedModel ?? void 0,
|
|
6838
|
+
aiTool: options.tool !== void 0 ? aiTool : aiTool || void 0,
|
|
6566
6839
|
tags: resolvedTags,
|
|
6567
6840
|
coverBuffer,
|
|
6568
6841
|
coverFileName,
|
|
@@ -6576,26 +6849,32 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6576
6849
|
apiUrl,
|
|
6577
6850
|
version: newVersion,
|
|
6578
6851
|
title: title || existingConfig.title,
|
|
6852
|
+
tagline: tagline || void 0,
|
|
6853
|
+
category: updateCategory || validExistingCategory,
|
|
6579
6854
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6580
6855
|
visibility: resolvedVis,
|
|
6581
6856
|
aspectRatio: resolvedAspectRatio,
|
|
6582
6857
|
supportedPlatforms: resolvedPlatforms,
|
|
6583
6858
|
platforms: resolvedPlatforms,
|
|
6584
|
-
aiModel:
|
|
6859
|
+
aiModel: options.model !== void 0 ? resolvedModel : resolvedModel !== null ? resolvedModel : existingConfig.aiModel ?? null,
|
|
6585
6860
|
aiTool: aiTool || void 0,
|
|
6586
6861
|
tags: resolvedTags
|
|
6587
6862
|
};
|
|
6588
6863
|
writeProjectConfig(resolvedPath, updatedConfig);
|
|
6864
|
+
const resolvedSlug = updateResult.slug || existingConfig.slug;
|
|
6865
|
+
const playUrl = resolvePlayableUrl(apiUrl, updateResult, resolvedSlug);
|
|
6589
6866
|
if (isJson) {
|
|
6590
6867
|
printJson({
|
|
6591
6868
|
success: true,
|
|
6592
|
-
slug:
|
|
6593
|
-
url:
|
|
6869
|
+
slug: resolvedSlug,
|
|
6870
|
+
url: playUrl,
|
|
6871
|
+
fullUrl: playUrl,
|
|
6594
6872
|
shortUrl: updateResult.shortUrl,
|
|
6595
6873
|
embedUrl: updateResult.embedUrl,
|
|
6596
6874
|
semver: updatedConfig.version,
|
|
6597
6875
|
versionNumber: updateResult.versionNumber,
|
|
6598
6876
|
visibility: updatedConfig.visibility,
|
|
6877
|
+
category: updatedConfig.category,
|
|
6599
6878
|
aspectRatio: updatedConfig.aspectRatio,
|
|
6600
6879
|
supportedPlatforms: resolvedPlatforms,
|
|
6601
6880
|
platforms: resolvedPlatforms,
|
|
@@ -6613,9 +6892,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6613
6892
|
\u2714 Stage '${existingConfig.slug}' successfully updated to v${updatedConfig.version}!`
|
|
6614
6893
|
)
|
|
6615
6894
|
);
|
|
6616
|
-
console.log(
|
|
6617
|
-
` Play URL: ${pc3.cyan(updateResult.url || `https://replaystage.com/g/${existingConfig.slug}`)}`
|
|
6618
|
-
);
|
|
6895
|
+
console.log(` Play URL: ${pc3.cyan(playUrl)}`);
|
|
6619
6896
|
if (updatedConfig.visibility) {
|
|
6620
6897
|
console.log(` Visibility: ${pc3.bold(updatedConfig.visibility)}`);
|
|
6621
6898
|
}
|
|
@@ -6631,24 +6908,32 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6631
6908
|
console.log(pc3.dim(" \u2139 Project state updated in .replaystage.json\n"));
|
|
6632
6909
|
}
|
|
6633
6910
|
} catch (err) {
|
|
6634
|
-
const
|
|
6635
|
-
|
|
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";
|
|
6636
6918
|
if (isJson) {
|
|
6637
6919
|
printErrorJson(err.code || "UPDATE_FAILED", actionableMessage, 1, {
|
|
6638
|
-
status: err.status
|
|
6920
|
+
status: err.status,
|
|
6921
|
+
...err.fieldErrors ? { fieldErrors: err.fieldErrors } : {}
|
|
6639
6922
|
});
|
|
6640
6923
|
} else {
|
|
6641
6924
|
console.error(pc3.red(`
|
|
6642
6925
|
\u2716 Update failed: ${err.message}`));
|
|
6643
|
-
if (
|
|
6926
|
+
if (isRecoverableWithFresh) {
|
|
6644
6927
|
console.error(
|
|
6645
6928
|
pc3.yellow(
|
|
6646
6929
|
"\n\u{1F4A1} Tip: Run 'replaystage publish --fresh' to deploy as a brand new stage.\n"
|
|
6647
6930
|
)
|
|
6648
6931
|
);
|
|
6932
|
+
} else {
|
|
6933
|
+
console.error();
|
|
6649
6934
|
}
|
|
6650
6935
|
}
|
|
6651
|
-
|
|
6936
|
+
exitWithError(1);
|
|
6652
6937
|
}
|
|
6653
6938
|
} else {
|
|
6654
6939
|
logInfo(
|
|
@@ -6679,12 +6964,15 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6679
6964
|
});
|
|
6680
6965
|
const initialVersion = result.semver || (visibility === "draft" ? "0.1.0" : "1.0.0");
|
|
6681
6966
|
const initialVisibility = result.visibility || visibility || (token ? "public" : "unlisted_claimable");
|
|
6967
|
+
const playUrl = resolvePlayableUrl(apiUrl, result, result.slug);
|
|
6682
6968
|
writeProjectConfig(resolvedPath, {
|
|
6683
6969
|
slug: result.slug,
|
|
6684
6970
|
manageToken: result.claim_token || result.claimToken,
|
|
6685
6971
|
apiUrl,
|
|
6686
6972
|
version: initialVersion,
|
|
6687
6973
|
title,
|
|
6974
|
+
tagline: tagline || void 0,
|
|
6975
|
+
category,
|
|
6688
6976
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6689
6977
|
visibility: initialVisibility,
|
|
6690
6978
|
aspectRatio: resolvedAspectRatio,
|
|
@@ -6698,7 +6986,8 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6698
6986
|
printJson({
|
|
6699
6987
|
success: true,
|
|
6700
6988
|
slug: result.slug,
|
|
6701
|
-
url:
|
|
6989
|
+
url: playUrl,
|
|
6990
|
+
fullUrl: playUrl,
|
|
6702
6991
|
shortUrl: result.shortUrl,
|
|
6703
6992
|
embedUrl: result.embedUrl,
|
|
6704
6993
|
fileHash: result.fileHash || bundle.fileHash,
|
|
@@ -6709,6 +6998,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6709
6998
|
status: result.status,
|
|
6710
6999
|
semver: initialVersion,
|
|
6711
7000
|
visibility: initialVisibility,
|
|
7001
|
+
category,
|
|
6712
7002
|
aspectRatio: resolvedAspectRatio,
|
|
6713
7003
|
supportedPlatforms: resolvedPlatforms,
|
|
6714
7004
|
platforms: resolvedPlatforms,
|
|
@@ -6720,7 +7010,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6720
7010
|
printPublishSuccess({
|
|
6721
7011
|
title,
|
|
6722
7012
|
slug: result.slug,
|
|
6723
|
-
url:
|
|
7013
|
+
url: playUrl,
|
|
6724
7014
|
shortUrl: result.shortUrl,
|
|
6725
7015
|
claim_token: result.claim_token,
|
|
6726
7016
|
claimUrl: result.claimUrl,
|
|
@@ -6737,8 +7027,14 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6737
7027
|
}
|
|
6738
7028
|
}
|
|
6739
7029
|
} catch (err) {
|
|
7030
|
+
if (exitHandled) {
|
|
7031
|
+
throw err;
|
|
7032
|
+
}
|
|
6740
7033
|
if (isJson) {
|
|
6741
|
-
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
|
+
});
|
|
6742
7038
|
} else {
|
|
6743
7039
|
console.error(pc3.red(`
|
|
6744
7040
|
\u2716 Publish failed: ${err.message}
|
|
@@ -6782,9 +7078,14 @@ async function handleValidate(targetPath = ".", options = {}) {
|
|
|
6782
7078
|
console.log(` ${pc4.dim("Bundle Size:")} ${sizeMb} MB (limit: 25 MB)`);
|
|
6783
7079
|
console.log(` ${pc4.dim("SHA-256:")} ${pc4.yellow(result.sha256 || "")}`);
|
|
6784
7080
|
console.log(
|
|
6785
|
-
` ${pc4.dim("Sanitization:")} ${pc4.green("Passed (clean bundle, no prohibited files)")}
|
|
6786
|
-
`
|
|
7081
|
+
` ${pc4.dim("Sanitization:")} ${pc4.green("Passed (clean bundle, no prohibited files)")}`
|
|
6787
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();
|
|
6788
7089
|
}
|
|
6789
7090
|
|
|
6790
7091
|
// src/fingerprint.ts
|
|
@@ -6804,19 +7105,16 @@ async function computeFileFingerprint(filePath) {
|
|
|
6804
7105
|
}
|
|
6805
7106
|
|
|
6806
7107
|
// src/index.ts
|
|
6807
|
-
function createProgram() {
|
|
7108
|
+
function createProgram(opts) {
|
|
6808
7109
|
const program = new Command();
|
|
6809
|
-
program.name("replaystage").description("ReplayStage CLI: Deploy and share web games from command line and AI agents").version("0.
|
|
6810
|
-
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>", "
|
|
7110
|
+
program.name("replaystage").description("ReplayStage CLI: Deploy and share web games from command line and AI agents").version("0.5.0");
|
|
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(
|
|
6811
7112
|
"--tool <tool>",
|
|
6812
|
-
"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.)"
|
|
6813
7114
|
).option(
|
|
6814
7115
|
"-m, --model <model>",
|
|
6815
7116
|
"AI model used to synthesize the game (e.g., Claude Sonnet 5.5, GPT-6 Astra, Gemini 4 Carbon)"
|
|
6816
|
-
).option(
|
|
6817
|
-
"--cover <path>",
|
|
6818
|
-
"Path to custom cartridge cover image (PNG, JPG, WebP, GIF, max 2MB)"
|
|
6819
|
-
).option(
|
|
7117
|
+
).option("--cover <path>", "Path to custom cartridge cover image (PNG, JPG, WebP, GIF, max 2MB)").option(
|
|
6820
7118
|
"--category <category>",
|
|
6821
7119
|
"Game category (arcade, action, puzzle, strategy, simulation, racing, rpg, casual)"
|
|
6822
7120
|
).option(
|
|
@@ -6843,31 +7141,72 @@ function createProgram() {
|
|
|
6843
7141
|
program.command("logout").description("Clear stored credentials").option("--json", "Output machine-readable JSON").action(async (options) => {
|
|
6844
7142
|
await handleLogout(options);
|
|
6845
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);
|
|
6846
7159
|
return program;
|
|
6847
7160
|
}
|
|
6848
|
-
var _cliExecuted = false;
|
|
6849
7161
|
async function runCli(argv = process.argv) {
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
const program = createProgram();
|
|
7162
|
+
const isJson = argv.includes("--json");
|
|
7163
|
+
const program = createProgram({ jsonMode: isJson });
|
|
6853
7164
|
try {
|
|
6854
7165
|
await program.parseAsync(argv);
|
|
6855
7166
|
} catch (err) {
|
|
6856
|
-
|
|
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();
|
|
6857
7172
|
if (isJson) {
|
|
7173
|
+
const errorCode = isCommanderParseError ? "INVALID_OPTIONS" : "CLI_ERROR";
|
|
6858
7174
|
process.stdout.write(
|
|
6859
|
-
`${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
|
+
)}
|
|
6860
7189
|
`
|
|
6861
7190
|
);
|
|
6862
|
-
} else {
|
|
6863
|
-
console.error(err
|
|
7191
|
+
} else if (!isCommanderParseError) {
|
|
7192
|
+
console.error(err?.message || String(err));
|
|
6864
7193
|
}
|
|
6865
|
-
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;
|
|
6866
7207
|
}
|
|
6867
7208
|
}
|
|
6868
|
-
|
|
6869
|
-
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"));
|
|
6870
|
-
if (isDirectCliExecution) {
|
|
7209
|
+
if (isDirectCliExecution()) {
|
|
6871
7210
|
void runCli(process.argv);
|
|
6872
7211
|
}
|
|
6873
7212
|
export {
|
|
@@ -6881,6 +7220,8 @@ export {
|
|
|
6881
7220
|
createProgram,
|
|
6882
7221
|
createZipFromFiles,
|
|
6883
7222
|
detectSiblingCover,
|
|
7223
|
+
extractErrorMessage,
|
|
7224
|
+
extractFieldErrors,
|
|
6884
7225
|
extractHtmlMetadata,
|
|
6885
7226
|
fetchWhoami,
|
|
6886
7227
|
getConfigDir,
|
|
@@ -6888,6 +7229,7 @@ export {
|
|
|
6888
7229
|
getProjectConfigPath,
|
|
6889
7230
|
getToken,
|
|
6890
7231
|
incrementVersion,
|
|
7232
|
+
isDirectCliExecution,
|
|
6891
7233
|
logError,
|
|
6892
7234
|
logInfo,
|
|
6893
7235
|
logSuccess,
|
|
@@ -6900,6 +7242,7 @@ export {
|
|
|
6900
7242
|
readConfig,
|
|
6901
7243
|
readProjectConfig,
|
|
6902
7244
|
resolveApiUrl,
|
|
7245
|
+
resolvePlayableUrl,
|
|
6903
7246
|
resolveProjectDirectory,
|
|
6904
7247
|
resolveToken,
|
|
6905
7248
|
runCli,
|