@replaystage/cli 0.2.0 → 0.4.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/dist/index.d.ts +51 -21
- package/dist/index.js +1149 -518
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35,7 +35,6 @@ async function uploadGameBundle(options) {
|
|
|
35
35
|
formData.append("title", options.title);
|
|
36
36
|
formData.append("tagline", options.tagline);
|
|
37
37
|
if (options.description) formData.append("description", options.description);
|
|
38
|
-
formData.append("ai_tool", options.aiTool);
|
|
39
38
|
if (options.category) formData.append("category", options.category);
|
|
40
39
|
formData.append("submission_type", options.submissionType || "maker");
|
|
41
40
|
if (options.makerName) formData.append("maker_name", options.makerName);
|
|
@@ -48,6 +47,26 @@ async function uploadGameBundle(options) {
|
|
|
48
47
|
formData.append("supportedPlatforms", options.supportedPlatforms);
|
|
49
48
|
formData.append("supported_platforms", options.supportedPlatforms);
|
|
50
49
|
}
|
|
50
|
+
if (options.aiModel) {
|
|
51
|
+
formData.append("ai_model", options.aiModel);
|
|
52
|
+
formData.append("aiModel", options.aiModel);
|
|
53
|
+
}
|
|
54
|
+
if (options.aiTool) {
|
|
55
|
+
formData.append("ai_tool", options.aiTool);
|
|
56
|
+
formData.append("aiTool", options.aiTool);
|
|
57
|
+
}
|
|
58
|
+
if (options.tags !== void 0 && options.tags !== null) {
|
|
59
|
+
const tagsVal = Array.isArray(options.tags) ? JSON.stringify(options.tags) : String(options.tags);
|
|
60
|
+
formData.append("tags", tagsVal);
|
|
61
|
+
}
|
|
62
|
+
if (options.coverBuffer) {
|
|
63
|
+
const uint82 = new Uint8Array(options.coverBuffer);
|
|
64
|
+
const fileName = options.coverFileName || "cover.png";
|
|
65
|
+
const lower = fileName.toLowerCase();
|
|
66
|
+
const mimeType = lower.endsWith(".png") ? "image/png" : lower.endsWith(".webp") ? "image/webp" : lower.endsWith(".gif") ? "image/gif" : "image/jpeg";
|
|
67
|
+
const blob2 = new Blob([uint82], { type: mimeType });
|
|
68
|
+
formData.append("cover", blob2, fileName);
|
|
69
|
+
}
|
|
51
70
|
const headers = {
|
|
52
71
|
...options.extraHeaders
|
|
53
72
|
};
|
|
@@ -102,6 +121,26 @@ async function updateGameBundle(slug, options) {
|
|
|
102
121
|
formData.append("supportedPlatforms", options.supportedPlatforms);
|
|
103
122
|
formData.append("supported_platforms", options.supportedPlatforms);
|
|
104
123
|
}
|
|
124
|
+
if (options.aiModel) {
|
|
125
|
+
formData.append("ai_model", options.aiModel);
|
|
126
|
+
formData.append("aiModel", options.aiModel);
|
|
127
|
+
}
|
|
128
|
+
if (options.aiTool) {
|
|
129
|
+
formData.append("ai_tool", options.aiTool);
|
|
130
|
+
formData.append("aiTool", options.aiTool);
|
|
131
|
+
}
|
|
132
|
+
if (options.tags !== void 0 && options.tags !== null) {
|
|
133
|
+
const tagsVal = Array.isArray(options.tags) ? JSON.stringify(options.tags) : String(options.tags);
|
|
134
|
+
formData.append("tags", tagsVal);
|
|
135
|
+
}
|
|
136
|
+
if (options.coverBuffer) {
|
|
137
|
+
const uint8 = new Uint8Array(options.coverBuffer);
|
|
138
|
+
const fileName = options.coverFileName || "cover.png";
|
|
139
|
+
const lower = fileName.toLowerCase();
|
|
140
|
+
const mimeType = lower.endsWith(".png") ? "image/png" : lower.endsWith(".webp") ? "image/webp" : lower.endsWith(".gif") ? "image/gif" : "image/jpeg";
|
|
141
|
+
const blob = new Blob([uint8], { type: mimeType });
|
|
142
|
+
formData.append("cover", blob, fileName);
|
|
143
|
+
}
|
|
105
144
|
const headers = {
|
|
106
145
|
...options.extraHeaders
|
|
107
146
|
};
|
|
@@ -158,383 +197,206 @@ async function fetchWhoami(apiUrl, token) {
|
|
|
158
197
|
}
|
|
159
198
|
|
|
160
199
|
// src/config.ts
|
|
161
|
-
import
|
|
162
|
-
import
|
|
163
|
-
import
|
|
164
|
-
function getConfigDir() {
|
|
165
|
-
return process.env.REPLAYSTAGE_CONFIG_DIR || path.join(os.homedir(), ".replaystage");
|
|
166
|
-
}
|
|
167
|
-
function getConfigPath() {
|
|
168
|
-
return path.join(getConfigDir(), "config.json");
|
|
169
|
-
}
|
|
170
|
-
function readConfig() {
|
|
171
|
-
const dir = getConfigDir();
|
|
172
|
-
for (const filename of ["config.json", "credentials.json"]) {
|
|
173
|
-
const file = path.join(dir, filename);
|
|
174
|
-
if (fs.existsSync(file)) {
|
|
175
|
-
try {
|
|
176
|
-
const raw = fs.readFileSync(file, "utf-8");
|
|
177
|
-
return JSON.parse(raw);
|
|
178
|
-
} catch {
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return {};
|
|
183
|
-
}
|
|
184
|
-
function writeConfig(config) {
|
|
185
|
-
const dir = getConfigDir();
|
|
186
|
-
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
187
|
-
const target = getConfigPath();
|
|
188
|
-
fs.writeFileSync(target, JSON.stringify(config, null, 2), {
|
|
189
|
-
encoding: "utf-8",
|
|
190
|
-
mode: 384
|
|
191
|
-
});
|
|
192
|
-
try {
|
|
193
|
-
fs.chmodSync(target, 384);
|
|
194
|
-
} catch {
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
function clearConfig() {
|
|
198
|
-
const dir = getConfigDir();
|
|
199
|
-
for (const filename of ["config.json", "credentials.json"]) {
|
|
200
|
-
const file = path.join(dir, filename);
|
|
201
|
-
if (fs.existsSync(file)) {
|
|
202
|
-
try {
|
|
203
|
-
fs.unlinkSync(file);
|
|
204
|
-
} catch {
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
function getToken() {
|
|
210
|
-
return resolveToken();
|
|
211
|
-
}
|
|
212
|
-
function setToken(token, user, apiUrl) {
|
|
213
|
-
const current = readConfig();
|
|
214
|
-
writeConfig({
|
|
215
|
-
...current,
|
|
216
|
-
...apiUrl ? { apiUrl: apiUrl.replace(/\/+$/, "") } : {},
|
|
217
|
-
token,
|
|
218
|
-
user: user || current.user
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
function clearToken() {
|
|
222
|
-
const current = readConfig();
|
|
223
|
-
current.token = void 0;
|
|
224
|
-
current.user = void 0;
|
|
225
|
-
writeConfig(current);
|
|
226
|
-
}
|
|
227
|
-
function resolveToken(cliToken) {
|
|
228
|
-
if (cliToken?.trim()) return cliToken.trim();
|
|
229
|
-
if (process.env.REPLAYSTAGE_TOKEN?.trim()) {
|
|
230
|
-
return process.env.REPLAYSTAGE_TOKEN.trim();
|
|
231
|
-
}
|
|
232
|
-
if (process.env.REPLAYSTAGE_API_TOKEN?.trim()) {
|
|
233
|
-
return process.env.REPLAYSTAGE_API_TOKEN.trim();
|
|
234
|
-
}
|
|
235
|
-
const config = readConfig();
|
|
236
|
-
return config.token || null;
|
|
237
|
-
}
|
|
238
|
-
function resolveApiUrl(cliApiUrl) {
|
|
239
|
-
if (cliApiUrl?.trim()) return cliApiUrl.trim().replace(/\/+$/, "");
|
|
240
|
-
if (process.env.REPLAYSTAGE_API_URL?.trim()) {
|
|
241
|
-
return process.env.REPLAYSTAGE_API_URL.trim().replace(/\/+$/, "");
|
|
242
|
-
}
|
|
243
|
-
const config = readConfig();
|
|
244
|
-
return (config.apiUrl || "https://replaystage.com").replace(/\/+$/, "");
|
|
245
|
-
}
|
|
200
|
+
import fs2 from "fs";
|
|
201
|
+
import os2 from "os";
|
|
202
|
+
import path2 from "path";
|
|
246
203
|
|
|
247
|
-
// src/
|
|
248
|
-
import
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
204
|
+
// src/project.ts
|
|
205
|
+
import * as fs from "fs";
|
|
206
|
+
import * as os from "os";
|
|
207
|
+
import * as path from "path";
|
|
208
|
+
|
|
209
|
+
// ../shared/src/constants.ts
|
|
210
|
+
var AI_TOOL_KEYS = [
|
|
211
|
+
"claude-code",
|
|
212
|
+
"antigravity",
|
|
213
|
+
"cursor",
|
|
214
|
+
"codex",
|
|
215
|
+
"windsurf",
|
|
216
|
+
"claude",
|
|
217
|
+
"gemini",
|
|
218
|
+
"v0",
|
|
219
|
+
"lovable",
|
|
220
|
+
"bolt"
|
|
221
|
+
];
|
|
222
|
+
var AI_TOOLS = {
|
|
223
|
+
"claude-code": {
|
|
224
|
+
id: "claude-code",
|
|
225
|
+
name: "Claude Code",
|
|
226
|
+
fullName: "Anthropic Claude Code",
|
|
227
|
+
slug: "claude-code",
|
|
228
|
+
description: "Terminal-based agentic coding and game generation by Anthropic",
|
|
229
|
+
badgeColor: "#D97706",
|
|
230
|
+
badgeBg: "bg-amber-100 text-amber-900 border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-700",
|
|
231
|
+
icon: "terminal",
|
|
232
|
+
website: "https://claude.ai/code"
|
|
233
|
+
},
|
|
234
|
+
antigravity: {
|
|
235
|
+
id: "antigravity",
|
|
236
|
+
name: "Antigravity",
|
|
237
|
+
fullName: "Antigravity Agent Platform",
|
|
238
|
+
slug: "antigravity",
|
|
239
|
+
description: "Autonomous multi-agent game productions orchestrated by Antigravity",
|
|
240
|
+
badgeColor: "#7C3AED",
|
|
241
|
+
badgeBg: "bg-purple-100 text-purple-900 border-purple-300 dark:bg-purple-950/60 dark:text-purple-200 dark:border-purple-700",
|
|
242
|
+
icon: "orbit",
|
|
243
|
+
website: "https://github.com/google-gemini/antigravity"
|
|
244
|
+
},
|
|
245
|
+
cursor: {
|
|
246
|
+
id: "cursor",
|
|
247
|
+
name: "Cursor",
|
|
248
|
+
fullName: "Cursor Composer & Agent",
|
|
249
|
+
slug: "cursor",
|
|
250
|
+
description: "Web games generated and iterated through Cursor AI Composer",
|
|
251
|
+
badgeColor: "#0F172A",
|
|
252
|
+
badgeBg: "bg-slate-100 text-slate-900 border-slate-300 dark:bg-slate-900 dark:text-slate-200 dark:border-slate-700",
|
|
253
|
+
icon: "mouse-pointer-click",
|
|
254
|
+
website: "https://cursor.com"
|
|
255
|
+
},
|
|
256
|
+
codex: {
|
|
257
|
+
id: "codex",
|
|
258
|
+
name: "ChatGPT / Codex",
|
|
259
|
+
fullName: "OpenAI ChatGPT & Codex",
|
|
260
|
+
slug: "codex",
|
|
261
|
+
description: "Games synthesized with OpenAI ChatGPT and Codex canvas sessions",
|
|
262
|
+
badgeColor: "#10A37F",
|
|
263
|
+
badgeBg: "bg-emerald-100 text-emerald-900 border-emerald-300 dark:bg-emerald-950/60 dark:text-emerald-200 dark:border-emerald-700",
|
|
264
|
+
icon: "bot",
|
|
265
|
+
website: "https://chatgpt.com"
|
|
266
|
+
},
|
|
267
|
+
windsurf: {
|
|
268
|
+
id: "windsurf",
|
|
269
|
+
name: "Windsurf",
|
|
270
|
+
fullName: "Codeium Windsurf",
|
|
271
|
+
slug: "windsurf",
|
|
272
|
+
description: "Agentic flow and web games developed with Codeium Windsurf",
|
|
273
|
+
badgeColor: "#0284C7",
|
|
274
|
+
badgeBg: "bg-sky-100 text-sky-900 border-sky-300 dark:bg-sky-950/60 dark:text-sky-200 dark:border-sky-700",
|
|
275
|
+
icon: "wind",
|
|
276
|
+
website: "https://codeium.com/windsurf"
|
|
277
|
+
},
|
|
278
|
+
claude: {
|
|
279
|
+
id: "claude",
|
|
280
|
+
name: "Claude",
|
|
281
|
+
fullName: "Anthropic Claude",
|
|
282
|
+
slug: "claude",
|
|
283
|
+
description: "Games designed and crafted with Anthropic Claude",
|
|
284
|
+
badgeColor: "#D97706",
|
|
285
|
+
badgeBg: "bg-amber-100 text-amber-900 border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-700",
|
|
286
|
+
icon: "sparkles",
|
|
287
|
+
website: "https://anthropic.com/claude"
|
|
288
|
+
},
|
|
289
|
+
gemini: {
|
|
290
|
+
id: "gemini",
|
|
291
|
+
name: "Gemini",
|
|
292
|
+
fullName: "Google Gemini",
|
|
293
|
+
slug: "gemini",
|
|
294
|
+
description: "Ultra-fast web games generated with Google Gemini models",
|
|
295
|
+
badgeColor: "#2563EB",
|
|
296
|
+
badgeBg: "bg-blue-100 text-blue-900 border-blue-300 dark:bg-blue-950/60 dark:text-blue-200 dark:border-blue-700",
|
|
297
|
+
icon: "atom",
|
|
298
|
+
website: "https://gemini.google.com"
|
|
299
|
+
},
|
|
300
|
+
v0: {
|
|
301
|
+
id: "v0",
|
|
302
|
+
name: "v0",
|
|
303
|
+
fullName: "v0 by Vercel",
|
|
304
|
+
slug: "v0",
|
|
305
|
+
description: "Generative interactive UI and canvas components synthesized by v0",
|
|
306
|
+
badgeColor: "#18181B",
|
|
307
|
+
badgeBg: "bg-zinc-100 text-zinc-900 border-zinc-300 dark:bg-zinc-800 dark:text-zinc-200 dark:border-zinc-700",
|
|
308
|
+
icon: "layers",
|
|
309
|
+
website: "https://v0.dev"
|
|
310
|
+
},
|
|
311
|
+
lovable: {
|
|
312
|
+
id: "lovable",
|
|
313
|
+
name: "Lovable",
|
|
314
|
+
fullName: "Lovable AI",
|
|
315
|
+
slug: "lovable",
|
|
316
|
+
description: "Full-stack web applications and games engineered with Lovable",
|
|
317
|
+
badgeColor: "#EC4899",
|
|
318
|
+
badgeBg: "bg-pink-100 text-pink-900 border-pink-300 dark:bg-pink-950/60 dark:text-pink-200 dark:border-pink-700",
|
|
319
|
+
icon: "heart",
|
|
320
|
+
website: "https://lovable.dev"
|
|
321
|
+
},
|
|
322
|
+
bolt: {
|
|
323
|
+
id: "bolt",
|
|
324
|
+
name: "Bolt",
|
|
325
|
+
fullName: "Bolt.new by StackBlitz",
|
|
326
|
+
slug: "bolt",
|
|
327
|
+
description: "In-browser full-stack sandbox games generated with Bolt.new",
|
|
328
|
+
badgeColor: "#EAB308",
|
|
329
|
+
badgeBg: "bg-yellow-100 text-yellow-900 border-yellow-300 dark:bg-yellow-950/60 dark:text-yellow-200 dark:border-yellow-700",
|
|
330
|
+
icon: "zap",
|
|
331
|
+
website: "https://bolt.new"
|
|
306
332
|
}
|
|
307
|
-
|
|
308
|
-
|
|
333
|
+
};
|
|
334
|
+
var GAME_CATEGORY_KEYS = [
|
|
335
|
+
"arcade",
|
|
336
|
+
"action",
|
|
337
|
+
"puzzle",
|
|
338
|
+
"strategy",
|
|
339
|
+
"simulation",
|
|
340
|
+
"racing",
|
|
341
|
+
"rpg",
|
|
342
|
+
"casual"
|
|
343
|
+
];
|
|
344
|
+
var MAX_BUNDLE_SIZE_BYTES = 25 * 1024 * 1024;
|
|
345
|
+
var MAX_HTML_SIZE_BYTES = 5 * 1024 * 1024;
|
|
346
|
+
var MAX_GAME_TITLE_LENGTH = 60;
|
|
347
|
+
var MAX_GAME_TAGLINE_LENGTH = 120;
|
|
348
|
+
var MAX_GAME_DESCRIPTION_LENGTH = 2e3;
|
|
349
|
+
var MAX_TAGS_COUNT = 6;
|
|
350
|
+
var MAX_TAG_LENGTH = 20;
|
|
351
|
+
var MAX_PROMPT_LENGTH = 4e3;
|
|
352
|
+
var MAX_AI_TOOL_LENGTH = 64;
|
|
353
|
+
var MAX_AI_MODEL_LENGTH = 80;
|
|
354
|
+
var CLAIM_TOKEN_EXPIRY_DAYS = 7;
|
|
355
|
+
var CLAIM_TOKEN_EXPIRY_MS = CLAIM_TOKEN_EXPIRY_DAYS * 24 * 60 * 60 * 1e3;
|
|
356
|
+
var PROHIBITED_EXTENSIONS = [
|
|
357
|
+
".exe",
|
|
358
|
+
".sh",
|
|
359
|
+
".bat",
|
|
360
|
+
".cmd",
|
|
361
|
+
".com",
|
|
362
|
+
".vbs",
|
|
363
|
+
".msi",
|
|
364
|
+
".ps1",
|
|
365
|
+
".env",
|
|
366
|
+
".git",
|
|
367
|
+
".pif",
|
|
368
|
+
".scr",
|
|
369
|
+
".dll",
|
|
370
|
+
".so",
|
|
371
|
+
".dylib",
|
|
372
|
+
".htaccess",
|
|
373
|
+
".php",
|
|
374
|
+
".py",
|
|
375
|
+
".rb",
|
|
376
|
+
".ini",
|
|
377
|
+
".conf"
|
|
378
|
+
];
|
|
379
|
+
function isProhibitedExtension(filePath) {
|
|
380
|
+
const normalized = filePath.split(/[/\\]/).map(
|
|
381
|
+
(seg) => seg.trim().replace(/[\s.]+$/, "").toLowerCase()
|
|
382
|
+
).join("/");
|
|
383
|
+
return PROHIBITED_EXTENSIONS.some(
|
|
384
|
+
(ext) => normalized.endsWith(ext) || normalized.includes(`${ext}/`)
|
|
309
385
|
);
|
|
310
|
-
if (res.shortUrl) {
|
|
311
|
-
console.log(
|
|
312
|
-
`${pc.yellow("\u2551")} ${pc.dim("Short Link:")} ${pc.magenta(res.shortUrl).padEnd(57)}${pc.yellow("\u2551")}`
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
if (res.claim_token) {
|
|
316
|
-
console.log(`${pc.yellow(`\u255F${border}\u2562`)}`);
|
|
317
|
-
console.log(
|
|
318
|
-
`${pc.yellow("\u2551")} \u{1F511} ${pc.bold(pc.yellow("SAFE HARBOR CLAIM TOKEN"))} (Keep private, 7-day TTL): ${pc.yellow("\u2551")}`
|
|
319
|
-
);
|
|
320
|
-
console.log(`${pc.yellow("\u2551")} ${pc.green(res.claim_token).padEnd(73)}${pc.yellow("\u2551")}`);
|
|
321
|
-
if (res.claimUrl) {
|
|
322
|
-
console.log(
|
|
323
|
-
`${pc.yellow("\u2551")} ${pc.dim("Claim URL:")} ${pc.cyan(res.claimUrl).padEnd(57)}${pc.yellow("\u2551")}`
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
console.log(`${pc.yellow(`\u255A${border}\u255D`)}
|
|
328
|
-
`);
|
|
329
386
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
process.exit(1);
|
|
345
|
-
}
|
|
346
|
-
console.log(pc2.cyan("\n\u{1F579}\uFE0F ReplayStage Authentication"));
|
|
347
|
-
console.log(`To obtain a CLI token, visit: ${pc2.underline(`${apiUrl}/settings#tokens`)}
|
|
348
|
-
`);
|
|
349
|
-
const input = await text({
|
|
350
|
-
message: "Enter your ReplayStage API token:",
|
|
351
|
-
placeholder: "rps_...",
|
|
352
|
-
validate(val) {
|
|
353
|
-
if (!val || val.trim().length === 0) return "Token cannot be empty";
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
if (typeof input !== "string") {
|
|
357
|
-
console.log(pc2.yellow("Login cancelled."));
|
|
358
|
-
process.exit(1);
|
|
359
|
-
}
|
|
360
|
-
token = input.trim();
|
|
361
|
-
}
|
|
362
|
-
try {
|
|
363
|
-
let user = void 0;
|
|
364
|
-
try {
|
|
365
|
-
user = await fetchWhoami(apiUrl, token);
|
|
366
|
-
} catch (err) {
|
|
367
|
-
if (err?.status === 401 || err?.status === 403) {
|
|
368
|
-
throw err;
|
|
369
|
-
}
|
|
370
|
-
user = { id: "user_cli", handle: "cli_user" };
|
|
371
|
-
}
|
|
372
|
-
setToken(token, user, options.apiUrl ? apiUrl : void 0);
|
|
373
|
-
if (isJson) {
|
|
374
|
-
printJson({ success: true, apiUrl, user, token: `${token.slice(0, 8)}...` });
|
|
375
|
-
} else {
|
|
376
|
-
console.log(
|
|
377
|
-
pc2.green(`
|
|
378
|
-
\u2714 Logged in successfully as ${pc2.bold(`@${user?.handle || "user"}`)}!`)
|
|
379
|
-
);
|
|
380
|
-
console.log(` ${pc2.dim("API URL:")} ${apiUrl}
|
|
381
|
-
`);
|
|
382
|
-
}
|
|
383
|
-
} catch (err) {
|
|
384
|
-
if (isJson) {
|
|
385
|
-
printErrorJson("AUTH_FAILED", err.message, 1);
|
|
386
|
-
} else {
|
|
387
|
-
console.error(pc2.red(`
|
|
388
|
-
\u2716 Login failed: ${err.message}
|
|
389
|
-
`));
|
|
390
|
-
}
|
|
391
|
-
process.exit(1);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
async function handleWhoami(options = {}) {
|
|
395
|
-
const isJson = Boolean(options.json);
|
|
396
|
-
const config = readConfig();
|
|
397
|
-
const token = resolveToken();
|
|
398
|
-
const apiUrl = resolveApiUrl(options.apiUrl);
|
|
399
|
-
if (!token) {
|
|
400
|
-
if (isJson) {
|
|
401
|
-
printJson({ authenticated: false, message: "Not logged in (anonymous upload mode)" });
|
|
402
|
-
} else {
|
|
403
|
-
console.log(
|
|
404
|
-
pc2.yellow(
|
|
405
|
-
"\nNot logged in. CLI commands run in anonymous mode with Safe Harbor claim tokens."
|
|
406
|
-
)
|
|
407
|
-
);
|
|
408
|
-
console.log(`Run ${pc2.cyan("replaystage login --token <rps_token>")} to authenticate.
|
|
409
|
-
`);
|
|
410
|
-
}
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
try {
|
|
414
|
-
let user = config.user;
|
|
415
|
-
try {
|
|
416
|
-
user = await fetchWhoami(apiUrl, token);
|
|
417
|
-
if (config.token === token) {
|
|
418
|
-
writeConfig({ ...config, user });
|
|
419
|
-
}
|
|
420
|
-
} catch (err) {
|
|
421
|
-
if (err?.status === 401 || err?.status === 403) {
|
|
422
|
-
throw err;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
if (isJson) {
|
|
426
|
-
printJson({
|
|
427
|
-
authenticated: true,
|
|
428
|
-
apiUrl,
|
|
429
|
-
user: user || null,
|
|
430
|
-
token: `${token.slice(0, 8)}...`
|
|
431
|
-
});
|
|
432
|
-
} else {
|
|
433
|
-
console.log(pc2.green("\n\u2714 Authenticated to ReplayStage"));
|
|
434
|
-
console.log(` ${pc2.dim("API URL:")} ${apiUrl}`);
|
|
435
|
-
if (user?.handle) console.log(` ${pc2.dim("Handle:")} @${user.handle}`);
|
|
436
|
-
if (user?.name) console.log(` ${pc2.dim("Name:")} ${user.name}`);
|
|
437
|
-
if (user?.email) console.log(` ${pc2.dim("Email:")} ${user.email}`);
|
|
438
|
-
console.log(` ${pc2.dim("Token:")} ${token.slice(0, 8)}...${token.slice(-4)}
|
|
439
|
-
`);
|
|
440
|
-
}
|
|
441
|
-
} catch (err) {
|
|
442
|
-
if (isJson) {
|
|
443
|
-
printErrorJson("WHOAMI_FAILED", err.message, 1);
|
|
444
|
-
} else {
|
|
445
|
-
console.error(pc2.red(`
|
|
446
|
-
\u2716 Auth check failed: ${err.message}
|
|
447
|
-
`));
|
|
448
|
-
}
|
|
449
|
-
process.exit(1);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
async function handleLogout(options = {}) {
|
|
453
|
-
const isJson = Boolean(options.json);
|
|
454
|
-
clearConfig();
|
|
455
|
-
if (isJson) {
|
|
456
|
-
printJson({ success: true, message: "Logged out successfully" });
|
|
457
|
-
} else {
|
|
458
|
-
console.log(pc2.green("\n\u2714 Stored credentials cleared successfully.\n"));
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// src/commands/publish.ts
|
|
463
|
-
import path5 from "path";
|
|
464
|
-
|
|
465
|
-
// ../shared/src/constants.ts
|
|
466
|
-
var AI_TOOL_KEYS = [
|
|
467
|
-
"claude",
|
|
468
|
-
"gemini",
|
|
469
|
-
"antigravity",
|
|
470
|
-
"cursor",
|
|
471
|
-
"chatgpt",
|
|
472
|
-
"v0",
|
|
473
|
-
"other"
|
|
474
|
-
];
|
|
475
|
-
var GAME_CATEGORY_KEYS = [
|
|
476
|
-
"arcade",
|
|
477
|
-
"action",
|
|
478
|
-
"puzzle",
|
|
479
|
-
"racing",
|
|
480
|
-
"3d",
|
|
481
|
-
"retro",
|
|
482
|
-
"chill"
|
|
483
|
-
];
|
|
484
|
-
var MAX_BUNDLE_SIZE_BYTES = 25 * 1024 * 1024;
|
|
485
|
-
var MAX_HTML_SIZE_BYTES = 5 * 1024 * 1024;
|
|
486
|
-
var MAX_GAME_TITLE_LENGTH = 60;
|
|
487
|
-
var MAX_GAME_TAGLINE_LENGTH = 120;
|
|
488
|
-
var MAX_GAME_DESCRIPTION_LENGTH = 2e3;
|
|
489
|
-
var MAX_TAGS_COUNT = 6;
|
|
490
|
-
var MAX_TAG_LENGTH = 20;
|
|
491
|
-
var MAX_PROMPT_LENGTH = 4e3;
|
|
492
|
-
var CLAIM_TOKEN_EXPIRY_DAYS = 7;
|
|
493
|
-
var CLAIM_TOKEN_EXPIRY_MS = CLAIM_TOKEN_EXPIRY_DAYS * 24 * 60 * 60 * 1e3;
|
|
494
|
-
var PROHIBITED_EXTENSIONS = [
|
|
495
|
-
".exe",
|
|
496
|
-
".sh",
|
|
497
|
-
".bat",
|
|
498
|
-
".cmd",
|
|
499
|
-
".com",
|
|
500
|
-
".vbs",
|
|
501
|
-
".msi",
|
|
502
|
-
".ps1",
|
|
503
|
-
".env",
|
|
504
|
-
".git",
|
|
505
|
-
".pif",
|
|
506
|
-
".scr",
|
|
507
|
-
".dll",
|
|
508
|
-
".so",
|
|
509
|
-
".dylib",
|
|
510
|
-
".htaccess",
|
|
511
|
-
".php",
|
|
512
|
-
".py",
|
|
513
|
-
".rb",
|
|
514
|
-
".ini",
|
|
515
|
-
".conf"
|
|
516
|
-
];
|
|
517
|
-
function isProhibitedExtension(filePath) {
|
|
518
|
-
const normalized = filePath.split(/[/\\]/).map(
|
|
519
|
-
(seg) => seg.trim().replace(/[\s.]+$/, "").toLowerCase()
|
|
520
|
-
).join("/");
|
|
521
|
-
return PROHIBITED_EXTENSIONS.some(
|
|
522
|
-
(ext) => normalized.endsWith(ext) || normalized.includes(`${ext}/`)
|
|
523
|
-
);
|
|
524
|
-
}
|
|
525
|
-
var SUBMISSION_TYPES = ["maker", "hunter"];
|
|
526
|
-
var DEFAULT_ASPECT_RATIO = "auto";
|
|
527
|
-
var ASPECT_RATIO_PRESETS = [
|
|
528
|
-
"auto",
|
|
529
|
-
"16:9",
|
|
530
|
-
"9:16",
|
|
531
|
-
"4:3",
|
|
532
|
-
"3:4",
|
|
533
|
-
"1:1"
|
|
534
|
-
];
|
|
535
|
-
var MIN_ASPECT_RATIO = 0.25;
|
|
536
|
-
var MAX_ASPECT_RATIO = 4;
|
|
537
|
-
var DEFAULT_SUPPORTED_PLATFORMS = "both";
|
|
387
|
+
var SUBMISSION_TYPES = ["maker", "hunter"];
|
|
388
|
+
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
|
+
];
|
|
397
|
+
var MIN_ASPECT_RATIO = 0.25;
|
|
398
|
+
var MAX_ASPECT_RATIO = 4;
|
|
399
|
+
var DEFAULT_SUPPORTED_PLATFORMS = "both";
|
|
538
400
|
|
|
539
401
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
540
402
|
var external_exports = {};
|
|
@@ -4891,6 +4753,46 @@ var supportedPlatformsSchema = external_exports.preprocess((val) => {
|
|
|
4891
4753
|
});
|
|
4892
4754
|
}
|
|
4893
4755
|
}).transform((val) => normalizeSupportedPlatforms(val).normalized);
|
|
4756
|
+
function normalizeToolSlug(input) {
|
|
4757
|
+
if (!input || typeof input !== "string") return "";
|
|
4758
|
+
let decoded = input;
|
|
4759
|
+
try {
|
|
4760
|
+
decoded = decodeURIComponent(input);
|
|
4761
|
+
} catch {
|
|
4762
|
+
decoded = input;
|
|
4763
|
+
}
|
|
4764
|
+
const slug = decoded.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
4765
|
+
if (slug === "chatgpt" || slug === "chatgpt-codex" || slug === "chatgptcodex" || slug === "openai-codex" || slug === "openai-chatgpt") {
|
|
4766
|
+
return "codex";
|
|
4767
|
+
}
|
|
4768
|
+
return slug;
|
|
4769
|
+
}
|
|
4770
|
+
var aiToolSchema = external_exports.preprocess(
|
|
4771
|
+
(val) => {
|
|
4772
|
+
if (val === null || val === void 0 || val === false || typeof val === "string" && val.trim() === "") {
|
|
4773
|
+
return null;
|
|
4774
|
+
}
|
|
4775
|
+
if (typeof val === "string") {
|
|
4776
|
+
const trimmed = val.trim();
|
|
4777
|
+
const lower = trimmed.toLowerCase();
|
|
4778
|
+
if (lower === "codex" || lower === "chatgpt" || lower === "chatgpt-codex" || lower === "chatgptcodex" || lower === "openai-codex" || lower === "openai-chatgpt" || lower === "chatgpt / codex" || lower === "chatgpt/codex" || normalizeToolSlug(trimmed) === "codex") {
|
|
4779
|
+
return "codex";
|
|
4780
|
+
}
|
|
4781
|
+
return trimmed;
|
|
4782
|
+
}
|
|
4783
|
+
return val;
|
|
4784
|
+
},
|
|
4785
|
+
external_exports.string({ errorMap: () => ({ message: "Invalid AI tool selection" }) }).max(MAX_AI_TOOL_LENGTH, `AI tool must be ${MAX_AI_TOOL_LENGTH} characters or less`).nullable().optional()
|
|
4786
|
+
);
|
|
4787
|
+
var aiModelSchema = external_exports.preprocess((val) => {
|
|
4788
|
+
if (val === null || typeof val === "string" && val.trim() === "") {
|
|
4789
|
+
return null;
|
|
4790
|
+
}
|
|
4791
|
+
if (typeof val === "string") {
|
|
4792
|
+
return val.trim();
|
|
4793
|
+
}
|
|
4794
|
+
return val;
|
|
4795
|
+
}, external_exports.string().max(MAX_AI_MODEL_LENGTH, `AI model must be ${MAX_AI_MODEL_LENGTH} characters or less`).nullable().optional());
|
|
4894
4796
|
var baseGameUploadObject = external_exports.object({
|
|
4895
4797
|
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`),
|
|
4896
4798
|
tagline: external_exports.string({ required_error: "Tagline is required" }).trim().max(
|
|
@@ -4901,9 +4803,8 @@ var baseGameUploadObject = external_exports.object({
|
|
|
4901
4803
|
MAX_GAME_DESCRIPTION_LENGTH,
|
|
4902
4804
|
`Description must be ${MAX_GAME_DESCRIPTION_LENGTH} characters or less`
|
|
4903
4805
|
).default(""),
|
|
4904
|
-
aiTool:
|
|
4905
|
-
|
|
4906
|
-
}),
|
|
4806
|
+
aiTool: aiToolSchema.default(null),
|
|
4807
|
+
aiModel: aiModelSchema.optional().nullable(),
|
|
4907
4808
|
primaryCategory: external_exports.enum(GAME_CATEGORY_KEYS, {
|
|
4908
4809
|
errorMap: () => ({ message: "Invalid game category selection" })
|
|
4909
4810
|
}),
|
|
@@ -4967,9 +4868,8 @@ var gameUpdateSchema = external_exports.object({
|
|
|
4967
4868
|
MAX_GAME_DESCRIPTION_LENGTH,
|
|
4968
4869
|
`Description must be ${MAX_GAME_DESCRIPTION_LENGTH} characters or less`
|
|
4969
4870
|
).optional(),
|
|
4970
|
-
aiTool:
|
|
4971
|
-
|
|
4972
|
-
}).optional(),
|
|
4871
|
+
aiTool: aiToolSchema.optional(),
|
|
4872
|
+
aiModel: aiModelSchema.optional().nullable(),
|
|
4973
4873
|
primaryCategory: external_exports.enum(GAME_CATEGORY_KEYS, {
|
|
4974
4874
|
errorMap: () => ({ message: "Invalid game category selection" })
|
|
4975
4875
|
}).optional(),
|
|
@@ -5084,6 +4984,33 @@ async function sha256(input) {
|
|
|
5084
4984
|
return hashArray.map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
5085
4985
|
}
|
|
5086
4986
|
|
|
4987
|
+
// ../shared/src/model.ts
|
|
4988
|
+
function extractRawAiModelFromHtml(html) {
|
|
4989
|
+
if (!html || typeof html !== "string") return null;
|
|
4990
|
+
const cleanHtml = html.replace(/<!--[\s\S]*?-->/g, "");
|
|
4991
|
+
const metaTagRegex = /<meta\b([^>]*)>/gi;
|
|
4992
|
+
for (const match of cleanHtml.matchAll(metaTagRegex)) {
|
|
4993
|
+
const attrs = match[1];
|
|
4994
|
+
const isModelMeta = /(?:^|\s)name\s*=\s*(["']?)replaystage:models?\1(?:\s|$|\/)/i.test(attrs);
|
|
4995
|
+
if (!isModelMeta) continue;
|
|
4996
|
+
const contentMatch = /(?:^|\s)content\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(attrs);
|
|
4997
|
+
if (contentMatch) {
|
|
4998
|
+
const content = contentMatch[1] ?? contentMatch[2] ?? contentMatch[3] ?? "";
|
|
4999
|
+
const trimmed = content.trim();
|
|
5000
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
5001
|
+
}
|
|
5002
|
+
}
|
|
5003
|
+
return null;
|
|
5004
|
+
}
|
|
5005
|
+
function extractAiModelFromHtml(html) {
|
|
5006
|
+
const raw = extractRawAiModelFromHtml(html);
|
|
5007
|
+
if (!raw) return null;
|
|
5008
|
+
const truncated = raw.slice(0, MAX_AI_MODEL_LENGTH);
|
|
5009
|
+
const parsed = aiModelSchema.safeParse(truncated);
|
|
5010
|
+
if (!parsed.success || !parsed.data) return null;
|
|
5011
|
+
return parsed.data;
|
|
5012
|
+
}
|
|
5013
|
+
|
|
5087
5014
|
// ../shared/src/sanitizer.ts
|
|
5088
5015
|
var FORBIDDEN_SEGMENT_EXACT = /* @__PURE__ */ new Set([
|
|
5089
5016
|
".replaystage.json",
|
|
@@ -5164,6 +5091,30 @@ function isIgnoredZipEntry(entryPath) {
|
|
|
5164
5091
|
return normalized.startsWith("__MACOSX/") || normalized.includes("/__MACOSX/") || normalized.endsWith(".DS_Store") || normalized.endsWith("Thumbs.db") || normalized.startsWith("._") || normalized.includes("/._");
|
|
5165
5092
|
}
|
|
5166
5093
|
var MAX_COVER_IMAGE_BYTES = 2 * 1024 * 1024;
|
|
5094
|
+
function validateCoverImageBytes(bytes) {
|
|
5095
|
+
if (!bytes || bytes.byteLength < 12) {
|
|
5096
|
+
return { valid: false, error: "Cover image is empty or truncated" };
|
|
5097
|
+
}
|
|
5098
|
+
if (bytes.byteLength > MAX_COVER_IMAGE_BYTES) {
|
|
5099
|
+
return { valid: false, error: "Cover image exceeds the 2 MB maximum limit" };
|
|
5100
|
+
}
|
|
5101
|
+
if (bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71 && bytes[4] === 13 && bytes[5] === 10 && bytes[6] === 26 && bytes[7] === 10) {
|
|
5102
|
+
return { valid: true, mimeType: "image/png", ext: "png" };
|
|
5103
|
+
}
|
|
5104
|
+
if (bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) {
|
|
5105
|
+
return { valid: true, mimeType: "image/jpeg", ext: "jpg" };
|
|
5106
|
+
}
|
|
5107
|
+
if (bytes[0] === 82 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 70 && bytes[8] === 87 && bytes[9] === 69 && bytes[10] === 66 && bytes[11] === 80) {
|
|
5108
|
+
return { valid: true, mimeType: "image/webp", ext: "webp" };
|
|
5109
|
+
}
|
|
5110
|
+
if (bytes[0] === 71 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 56 && (bytes[4] === 55 || bytes[4] === 57) && bytes[5] === 97) {
|
|
5111
|
+
return { valid: true, mimeType: "image/gif", ext: "gif" };
|
|
5112
|
+
}
|
|
5113
|
+
return {
|
|
5114
|
+
valid: false,
|
|
5115
|
+
error: "Unsupported cover image format (must be PNG, JPEG, WebP, or GIF)"
|
|
5116
|
+
};
|
|
5117
|
+
}
|
|
5167
5118
|
function findEntryHtmlFile(paths) {
|
|
5168
5119
|
const cleanPaths = paths.filter((p) => !isIgnoredZipEntry(p)).map((p) => p.replace(/\\/g, "/").replace(/^\.?\//, ""));
|
|
5169
5120
|
if (cleanPaths.includes("index.html")) {
|
|
@@ -5200,33 +5151,592 @@ function findEntryHtmlFile(paths) {
|
|
|
5200
5151
|
const prefix = lastSlash >= 0 ? entryPath.slice(0, lastSlash + 1) : "";
|
|
5201
5152
|
return { entryPath, prefix };
|
|
5202
5153
|
}
|
|
5203
|
-
if (allIndices.length > 1) {
|
|
5204
|
-
const dirs = new Set(
|
|
5205
|
-
allIndices.map((p) => {
|
|
5206
|
-
const lastSlash = p.lastIndexOf("/");
|
|
5207
|
-
return lastSlash >= 0 ? p.slice(0, lastSlash + 1) : "";
|
|
5208
|
-
})
|
|
5209
|
-
);
|
|
5210
|
-
if (dirs.size === 1) {
|
|
5211
|
-
const htmlEntry = allIndices.find((p) => p.endsWith("/index.html") || p === "index.html");
|
|
5212
|
-
if (htmlEntry) {
|
|
5213
|
-
const lastSlash = htmlEntry.lastIndexOf("/");
|
|
5214
|
-
const prefix = lastSlash >= 0 ? htmlEntry.slice(0, lastSlash + 1) : "";
|
|
5215
|
-
return { entryPath: htmlEntry, prefix };
|
|
5154
|
+
if (allIndices.length > 1) {
|
|
5155
|
+
const dirs = new Set(
|
|
5156
|
+
allIndices.map((p) => {
|
|
5157
|
+
const lastSlash = p.lastIndexOf("/");
|
|
5158
|
+
return lastSlash >= 0 ? p.slice(0, lastSlash + 1) : "";
|
|
5159
|
+
})
|
|
5160
|
+
);
|
|
5161
|
+
if (dirs.size === 1) {
|
|
5162
|
+
const htmlEntry = allIndices.find((p) => p.endsWith("/index.html") || p === "index.html");
|
|
5163
|
+
if (htmlEntry) {
|
|
5164
|
+
const lastSlash = htmlEntry.lastIndexOf("/");
|
|
5165
|
+
const prefix = lastSlash >= 0 ? htmlEntry.slice(0, lastSlash + 1) : "";
|
|
5166
|
+
return { entryPath: htmlEntry, prefix };
|
|
5167
|
+
}
|
|
5168
|
+
}
|
|
5169
|
+
}
|
|
5170
|
+
return { entryPath: null, prefix: "" };
|
|
5171
|
+
}
|
|
5172
|
+
|
|
5173
|
+
// ../shared/src/tags.ts
|
|
5174
|
+
function normalizeTags(input) {
|
|
5175
|
+
if (input === null || input === void 0) return [];
|
|
5176
|
+
let rawList = [];
|
|
5177
|
+
if (Array.isArray(input)) {
|
|
5178
|
+
rawList = input;
|
|
5179
|
+
} else if (typeof input === "string") {
|
|
5180
|
+
const trimmed = input.trim();
|
|
5181
|
+
if (trimmed === "" || trimmed === "null" || trimmed === "undefined") {
|
|
5182
|
+
return [];
|
|
5183
|
+
}
|
|
5184
|
+
if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
|
|
5185
|
+
try {
|
|
5186
|
+
const parsed = JSON.parse(trimmed);
|
|
5187
|
+
if (Array.isArray(parsed)) {
|
|
5188
|
+
rawList = parsed;
|
|
5189
|
+
} else {
|
|
5190
|
+
rawList = trimmed.slice(1, -1).split(",");
|
|
5191
|
+
}
|
|
5192
|
+
} catch {
|
|
5193
|
+
rawList = trimmed.slice(1, -1).split(",");
|
|
5194
|
+
}
|
|
5195
|
+
} else {
|
|
5196
|
+
rawList = trimmed.split(",");
|
|
5197
|
+
}
|
|
5198
|
+
} else {
|
|
5199
|
+
return [];
|
|
5200
|
+
}
|
|
5201
|
+
const result = [];
|
|
5202
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5203
|
+
for (const item of rawList) {
|
|
5204
|
+
if (typeof item !== "string") continue;
|
|
5205
|
+
const formatted = item.trim().toLowerCase().replace(/[\s_]+/g, "-").replace(/^-+|-+$/g, "");
|
|
5206
|
+
if (!formatted) continue;
|
|
5207
|
+
const parseResult = tagSchema.safeParse(formatted);
|
|
5208
|
+
if (!parseResult.success) continue;
|
|
5209
|
+
const validTag = parseResult.data;
|
|
5210
|
+
if (!seen.has(validTag)) {
|
|
5211
|
+
seen.add(validTag);
|
|
5212
|
+
result.push(validTag);
|
|
5213
|
+
if (result.length >= MAX_TAGS_COUNT) {
|
|
5214
|
+
break;
|
|
5215
|
+
}
|
|
5216
|
+
}
|
|
5217
|
+
}
|
|
5218
|
+
return result;
|
|
5219
|
+
}
|
|
5220
|
+
function extractRawTagsFromHtml(html) {
|
|
5221
|
+
if (!html || typeof html !== "string") return null;
|
|
5222
|
+
const cleanHtml = html.replace(/<!--[\s\S]*?-->/g, "");
|
|
5223
|
+
const metaTagRegex = /<meta\b([^>]*)>/gi;
|
|
5224
|
+
for (const match of cleanHtml.matchAll(metaTagRegex)) {
|
|
5225
|
+
const attrs = match[1];
|
|
5226
|
+
const isTagsMeta = /(?:^|\s)name\s*=\s*(["']?)replaystage:tags?\1(?:\s|$|\/)/i.test(attrs);
|
|
5227
|
+
if (!isTagsMeta) continue;
|
|
5228
|
+
const contentMatch = /(?:^|\s)content\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(attrs);
|
|
5229
|
+
if (contentMatch) {
|
|
5230
|
+
const content = contentMatch[1] ?? contentMatch[2] ?? contentMatch[3] ?? "";
|
|
5231
|
+
const trimmed = content.trim();
|
|
5232
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
5233
|
+
}
|
|
5234
|
+
}
|
|
5235
|
+
return null;
|
|
5236
|
+
}
|
|
5237
|
+
function extractTagsFromHtml(html) {
|
|
5238
|
+
const raw = extractRawTagsFromHtml(html);
|
|
5239
|
+
if (!raw) return [];
|
|
5240
|
+
return normalizeTags(raw);
|
|
5241
|
+
}
|
|
5242
|
+
|
|
5243
|
+
// src/project.ts
|
|
5244
|
+
function resolveProjectDirectory(targetPath) {
|
|
5245
|
+
try {
|
|
5246
|
+
const resolved = path.resolve(targetPath);
|
|
5247
|
+
if (resolved.toLowerCase().endsWith(".zip")) {
|
|
5248
|
+
return null;
|
|
5249
|
+
}
|
|
5250
|
+
if (resolved.includes("seed-games")) {
|
|
5251
|
+
return null;
|
|
5252
|
+
}
|
|
5253
|
+
if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) {
|
|
5254
|
+
if (resolved === path.resolve(os.tmpdir())) {
|
|
5255
|
+
return null;
|
|
5256
|
+
}
|
|
5257
|
+
return resolved;
|
|
5258
|
+
}
|
|
5259
|
+
if (fs.existsSync(resolved) && fs.statSync(resolved).isFile()) {
|
|
5260
|
+
const parentDir = path.dirname(resolved);
|
|
5261
|
+
if (parentDir === path.resolve(os.tmpdir())) {
|
|
5262
|
+
return null;
|
|
5263
|
+
}
|
|
5264
|
+
return parentDir;
|
|
5265
|
+
}
|
|
5266
|
+
return resolved;
|
|
5267
|
+
} catch {
|
|
5268
|
+
return path.resolve(targetPath);
|
|
5269
|
+
}
|
|
5270
|
+
}
|
|
5271
|
+
function getProjectConfigPath(targetDir) {
|
|
5272
|
+
const dir = resolveProjectDirectory(targetDir);
|
|
5273
|
+
return dir ? path.join(dir, ".replaystage.json") : null;
|
|
5274
|
+
}
|
|
5275
|
+
function readProjectConfig(targetDir) {
|
|
5276
|
+
const configPath = getProjectConfigPath(targetDir);
|
|
5277
|
+
if (!configPath || !fs.existsSync(configPath)) {
|
|
5278
|
+
return null;
|
|
5279
|
+
}
|
|
5280
|
+
try {
|
|
5281
|
+
const raw = fs.readFileSync(configPath, "utf-8");
|
|
5282
|
+
const parsed = JSON.parse(raw);
|
|
5283
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
5284
|
+
return null;
|
|
5285
|
+
}
|
|
5286
|
+
if ("slug" in parsed) {
|
|
5287
|
+
if (typeof parsed.slug !== "string" || !parsed.slug.trim()) {
|
|
5288
|
+
return null;
|
|
5289
|
+
}
|
|
5290
|
+
}
|
|
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";
|
|
5292
|
+
if (!hasValidKey) {
|
|
5293
|
+
return null;
|
|
5294
|
+
}
|
|
5295
|
+
if (parsed.tags !== void 0) {
|
|
5296
|
+
parsed.tags = normalizeTags(parsed.tags);
|
|
5297
|
+
}
|
|
5298
|
+
return parsed;
|
|
5299
|
+
} catch {
|
|
5300
|
+
return null;
|
|
5301
|
+
}
|
|
5302
|
+
}
|
|
5303
|
+
function writeProjectConfig(targetDir, config) {
|
|
5304
|
+
const configPath = getProjectConfigPath(targetDir);
|
|
5305
|
+
if (!configPath) {
|
|
5306
|
+
return;
|
|
5307
|
+
}
|
|
5308
|
+
const dir = path.dirname(configPath);
|
|
5309
|
+
if (!fs.existsSync(dir)) {
|
|
5310
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
5311
|
+
}
|
|
5312
|
+
const toWrite = { ...config };
|
|
5313
|
+
if (toWrite.tags !== void 0) {
|
|
5314
|
+
toWrite.tags = normalizeTags(toWrite.tags);
|
|
5315
|
+
}
|
|
5316
|
+
fs.writeFileSync(configPath, `${JSON.stringify(toWrite, null, 2)}
|
|
5317
|
+
`, "utf-8");
|
|
5318
|
+
}
|
|
5319
|
+
function incrementVersion(currentVersion) {
|
|
5320
|
+
if (!currentVersion || typeof currentVersion !== "string") return "0.2.0";
|
|
5321
|
+
const sanitized = currentVersion.trim().replace(/^v/i, "");
|
|
5322
|
+
const parts = sanitized.split(".").map((n) => Number.parseInt(n, 10));
|
|
5323
|
+
if (parts.length === 3 && !parts.some(Number.isNaN)) {
|
|
5324
|
+
return `${parts[0]}.${parts[1] + 1}.0`;
|
|
5325
|
+
}
|
|
5326
|
+
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
5327
|
+
return `${parts[0]}.${parts[1] + 1}.0`;
|
|
5328
|
+
}
|
|
5329
|
+
return "0.2.0";
|
|
5330
|
+
}
|
|
5331
|
+
function promoteDraftVersion(currentVersion) {
|
|
5332
|
+
if (!currentVersion || typeof currentVersion !== "string") return "1.0.0";
|
|
5333
|
+
const sanitized = currentVersion.trim().replace(/^v/i, "");
|
|
5334
|
+
if (sanitized.startsWith("0.")) {
|
|
5335
|
+
return "1.0.0";
|
|
5336
|
+
}
|
|
5337
|
+
return incrementVersion(currentVersion);
|
|
5338
|
+
}
|
|
5339
|
+
|
|
5340
|
+
// src/config.ts
|
|
5341
|
+
function getConfigDir() {
|
|
5342
|
+
return process.env.REPLAYSTAGE_CONFIG_DIR || path2.join(os2.homedir(), ".replaystage");
|
|
5343
|
+
}
|
|
5344
|
+
function getConfigPath() {
|
|
5345
|
+
return path2.join(getConfigDir(), "config.json");
|
|
5346
|
+
}
|
|
5347
|
+
function readConfig() {
|
|
5348
|
+
const dir = getConfigDir();
|
|
5349
|
+
for (const filename of ["config.json", "credentials.json"]) {
|
|
5350
|
+
const file = path2.join(dir, filename);
|
|
5351
|
+
if (fs2.existsSync(file)) {
|
|
5352
|
+
try {
|
|
5353
|
+
const raw = fs2.readFileSync(file, "utf-8");
|
|
5354
|
+
return JSON.parse(raw);
|
|
5355
|
+
} catch {
|
|
5356
|
+
}
|
|
5357
|
+
}
|
|
5358
|
+
}
|
|
5359
|
+
return {};
|
|
5360
|
+
}
|
|
5361
|
+
function writeConfig(config) {
|
|
5362
|
+
const dir = getConfigDir();
|
|
5363
|
+
fs2.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
5364
|
+
const target = getConfigPath();
|
|
5365
|
+
fs2.writeFileSync(target, JSON.stringify(config, null, 2), {
|
|
5366
|
+
encoding: "utf-8",
|
|
5367
|
+
mode: 384
|
|
5368
|
+
});
|
|
5369
|
+
try {
|
|
5370
|
+
fs2.chmodSync(target, 384);
|
|
5371
|
+
} catch {
|
|
5372
|
+
}
|
|
5373
|
+
}
|
|
5374
|
+
function clearConfig() {
|
|
5375
|
+
const dir = getConfigDir();
|
|
5376
|
+
for (const filename of ["config.json", "credentials.json"]) {
|
|
5377
|
+
const file = path2.join(dir, filename);
|
|
5378
|
+
if (fs2.existsSync(file)) {
|
|
5379
|
+
try {
|
|
5380
|
+
fs2.unlinkSync(file);
|
|
5381
|
+
} catch {
|
|
5382
|
+
}
|
|
5383
|
+
}
|
|
5384
|
+
}
|
|
5385
|
+
}
|
|
5386
|
+
function getToken() {
|
|
5387
|
+
return resolveToken();
|
|
5388
|
+
}
|
|
5389
|
+
function setToken(token, user, apiUrl) {
|
|
5390
|
+
const current = readConfig();
|
|
5391
|
+
writeConfig({
|
|
5392
|
+
...current,
|
|
5393
|
+
...apiUrl ? { apiUrl: apiUrl.replace(/\/+$/, "") } : {},
|
|
5394
|
+
token,
|
|
5395
|
+
user: user || current.user
|
|
5396
|
+
});
|
|
5397
|
+
}
|
|
5398
|
+
function clearToken() {
|
|
5399
|
+
const current = readConfig();
|
|
5400
|
+
current.token = void 0;
|
|
5401
|
+
current.user = void 0;
|
|
5402
|
+
writeConfig(current);
|
|
5403
|
+
}
|
|
5404
|
+
function resolveToken(cliToken) {
|
|
5405
|
+
if (cliToken?.trim()) return cliToken.trim();
|
|
5406
|
+
if (process.env.REPLAYSTAGE_TOKEN?.trim()) {
|
|
5407
|
+
return process.env.REPLAYSTAGE_TOKEN.trim();
|
|
5408
|
+
}
|
|
5409
|
+
if (process.env.REPLAYSTAGE_API_TOKEN?.trim()) {
|
|
5410
|
+
return process.env.REPLAYSTAGE_API_TOKEN.trim();
|
|
5411
|
+
}
|
|
5412
|
+
const config = readConfig();
|
|
5413
|
+
return config.token || null;
|
|
5414
|
+
}
|
|
5415
|
+
function resolveApiUrl(cliApiUrl) {
|
|
5416
|
+
if (cliApiUrl?.trim()) return cliApiUrl.trim().replace(/\/+$/, "");
|
|
5417
|
+
if (process.env.REPLAYSTAGE_API_URL?.trim()) {
|
|
5418
|
+
return process.env.REPLAYSTAGE_API_URL.trim().replace(/\/+$/, "");
|
|
5419
|
+
}
|
|
5420
|
+
const config = readConfig();
|
|
5421
|
+
return (config.apiUrl || "https://replaystage.com").replace(/\/+$/, "");
|
|
5422
|
+
}
|
|
5423
|
+
|
|
5424
|
+
// src/ui.ts
|
|
5425
|
+
import pc from "picocolors";
|
|
5426
|
+
function printJson(data) {
|
|
5427
|
+
process.stdout.write(`${JSON.stringify(data, null, 2)}
|
|
5428
|
+
`);
|
|
5429
|
+
}
|
|
5430
|
+
function printErrorJson(error, message, code = 1, extra) {
|
|
5431
|
+
process.stdout.write(
|
|
5432
|
+
`${JSON.stringify({ success: false, code, error, message, ...extra }, null, 2)}
|
|
5433
|
+
`
|
|
5434
|
+
);
|
|
5435
|
+
}
|
|
5436
|
+
function logInfo(message, isJsonMode = false) {
|
|
5437
|
+
if (isJsonMode) return;
|
|
5438
|
+
process.stderr.write(`${pc.cyan("\u2139 ") + message}
|
|
5439
|
+
`);
|
|
5440
|
+
}
|
|
5441
|
+
function logSuccess(message, isJsonMode = false) {
|
|
5442
|
+
if (isJsonMode) return;
|
|
5443
|
+
process.stderr.write(`${pc.green("\u2714 ") + message}
|
|
5444
|
+
`);
|
|
5445
|
+
}
|
|
5446
|
+
function logWarn(message, isJsonMode = false) {
|
|
5447
|
+
if (isJsonMode) return;
|
|
5448
|
+
process.stderr.write(`${pc.yellow("\u26A0 ") + message}
|
|
5449
|
+
`);
|
|
5450
|
+
}
|
|
5451
|
+
function logError(message, isJsonMode = false) {
|
|
5452
|
+
if (isJsonMode) return;
|
|
5453
|
+
process.stderr.write(`${pc.red("\u2716 ") + message}
|
|
5454
|
+
`);
|
|
5455
|
+
}
|
|
5456
|
+
function printPublishSuccess(res) {
|
|
5457
|
+
const border = "\u2550".repeat(64);
|
|
5458
|
+
console.log(`
|
|
5459
|
+
${pc.yellow(`\u2554${border}\u2557`)}`);
|
|
5460
|
+
console.log(
|
|
5461
|
+
`${pc.yellow("\u2551")} \u{1F579}\uFE0F ${pc.bold(pc.white("REPLAYSTAGE PUBLISH SUCCESSFUL"))}${" ".repeat(30)}${pc.yellow("\u2551")}`
|
|
5462
|
+
);
|
|
5463
|
+
console.log(`${pc.yellow(`\u2560${border}\u2563`)}`);
|
|
5464
|
+
console.log(
|
|
5465
|
+
`${pc.yellow("\u2551")} ${pc.dim("Game:")} ${res.title.padEnd(48)}${pc.yellow("\u2551")}`
|
|
5466
|
+
);
|
|
5467
|
+
console.log(
|
|
5468
|
+
`${pc.yellow("\u2551")} ${pc.dim("Slug:")} ${res.slug.padEnd(48)}${pc.yellow("\u2551")}`
|
|
5469
|
+
);
|
|
5470
|
+
if (res.aiTool) {
|
|
5471
|
+
console.log(
|
|
5472
|
+
`${pc.yellow("\u2551")} ${pc.dim("AI Tool:")} ${res.aiTool.padEnd(48)}${pc.yellow("\u2551")}`
|
|
5473
|
+
);
|
|
5474
|
+
}
|
|
5475
|
+
if (res.tags && res.tags.length > 0) {
|
|
5476
|
+
const formattedTags = res.tags.map((t) => `#${t}`).join(" ");
|
|
5477
|
+
console.log(
|
|
5478
|
+
`${pc.yellow("\u2551")} ${pc.dim("Tags:")} ${formattedTags.padEnd(48)}${pc.yellow("\u2551")}`
|
|
5479
|
+
);
|
|
5480
|
+
}
|
|
5481
|
+
if (res.aspectRatio) {
|
|
5482
|
+
console.log(
|
|
5483
|
+
`${pc.yellow("\u2551")} ${pc.dim("Ratio:")} ${res.aspectRatio.padEnd(48)}${pc.yellow("\u2551")}`
|
|
5484
|
+
);
|
|
5485
|
+
}
|
|
5486
|
+
const plat = res.supportedPlatforms || res.platforms;
|
|
5487
|
+
if (plat) {
|
|
5488
|
+
console.log(`${pc.yellow("\u2551")} ${pc.dim("Platforms:")} ${plat.padEnd(48)}${pc.yellow("\u2551")}`);
|
|
5489
|
+
}
|
|
5490
|
+
console.log(
|
|
5491
|
+
`${pc.yellow("\u2551")} ${pc.dim("Play URL:")} ${pc.cyan(res.url).padEnd(57)}${pc.yellow("\u2551")}`
|
|
5492
|
+
);
|
|
5493
|
+
if (res.shortUrl) {
|
|
5494
|
+
console.log(
|
|
5495
|
+
`${pc.yellow("\u2551")} ${pc.dim("Short Link:")} ${pc.magenta(res.shortUrl).padEnd(57)}${pc.yellow("\u2551")}`
|
|
5496
|
+
);
|
|
5497
|
+
}
|
|
5498
|
+
if (res.claim_token) {
|
|
5499
|
+
console.log(`${pc.yellow(`\u255F${border}\u2562`)}`);
|
|
5500
|
+
console.log(
|
|
5501
|
+
`${pc.yellow("\u2551")} \u{1F511} ${pc.bold(pc.yellow("SAFE HARBOR CLAIM TOKEN"))} (Keep private, 7-day TTL): ${pc.yellow("\u2551")}`
|
|
5502
|
+
);
|
|
5503
|
+
console.log(`${pc.yellow("\u2551")} ${pc.green(res.claim_token).padEnd(73)}${pc.yellow("\u2551")}`);
|
|
5504
|
+
if (res.claimUrl) {
|
|
5505
|
+
console.log(
|
|
5506
|
+
`${pc.yellow("\u2551")} ${pc.dim("Claim URL:")} ${pc.cyan(res.claimUrl).padEnd(57)}${pc.yellow("\u2551")}`
|
|
5507
|
+
);
|
|
5508
|
+
}
|
|
5509
|
+
}
|
|
5510
|
+
console.log(`${pc.yellow(`\u255A${border}\u255D`)}
|
|
5511
|
+
`);
|
|
5512
|
+
}
|
|
5513
|
+
|
|
5514
|
+
// src/commands/auth.ts
|
|
5515
|
+
async function handleLogin(options = {}) {
|
|
5516
|
+
const isJson = Boolean(options.json);
|
|
5517
|
+
let token = options.token?.trim();
|
|
5518
|
+
const apiUrl = resolveApiUrl(options.apiUrl);
|
|
5519
|
+
if (!token) {
|
|
5520
|
+
if (isJson || !process.stdout.isTTY) {
|
|
5521
|
+
if (isJson) {
|
|
5522
|
+
printErrorJson("TOKEN_REQUIRED", "Authentication token is required via --token", 1);
|
|
5523
|
+
} else {
|
|
5524
|
+
console.error(pc2.red("Error: --token is required in non-interactive environment."));
|
|
5525
|
+
console.error(`Generate your token at ${apiUrl}/settings#tokens`);
|
|
5526
|
+
}
|
|
5527
|
+
process.exit(1);
|
|
5528
|
+
}
|
|
5529
|
+
console.log(pc2.cyan("\n\u{1F579}\uFE0F ReplayStage Authentication"));
|
|
5530
|
+
console.log(`To obtain a CLI token, visit: ${pc2.underline(`${apiUrl}/settings#tokens`)}
|
|
5531
|
+
`);
|
|
5532
|
+
const input = await text({
|
|
5533
|
+
message: "Enter your ReplayStage API token:",
|
|
5534
|
+
placeholder: "rps_...",
|
|
5535
|
+
validate(val) {
|
|
5536
|
+
if (!val || val.trim().length === 0) return "Token cannot be empty";
|
|
5537
|
+
}
|
|
5538
|
+
});
|
|
5539
|
+
if (typeof input !== "string") {
|
|
5540
|
+
console.log(pc2.yellow("Login cancelled."));
|
|
5541
|
+
process.exit(1);
|
|
5542
|
+
}
|
|
5543
|
+
token = input.trim();
|
|
5544
|
+
}
|
|
5545
|
+
try {
|
|
5546
|
+
let user = void 0;
|
|
5547
|
+
try {
|
|
5548
|
+
user = await fetchWhoami(apiUrl, token);
|
|
5549
|
+
} catch (err) {
|
|
5550
|
+
if (err?.status === 401 || err?.status === 403) {
|
|
5551
|
+
throw err;
|
|
5552
|
+
}
|
|
5553
|
+
user = { id: "user_cli", handle: "cli_user" };
|
|
5554
|
+
}
|
|
5555
|
+
setToken(token, user, options.apiUrl ? apiUrl : void 0);
|
|
5556
|
+
if (isJson) {
|
|
5557
|
+
printJson({ success: true, apiUrl, user, token: `${token.slice(0, 8)}...` });
|
|
5558
|
+
} else {
|
|
5559
|
+
console.log(
|
|
5560
|
+
pc2.green(`
|
|
5561
|
+
\u2714 Logged in successfully as ${pc2.bold(`@${user?.handle || "user"}`)}!`)
|
|
5562
|
+
);
|
|
5563
|
+
console.log(` ${pc2.dim("API URL:")} ${apiUrl}
|
|
5564
|
+
`);
|
|
5565
|
+
}
|
|
5566
|
+
} catch (err) {
|
|
5567
|
+
if (isJson) {
|
|
5568
|
+
printErrorJson("AUTH_FAILED", err.message, 1);
|
|
5569
|
+
} else {
|
|
5570
|
+
console.error(pc2.red(`
|
|
5571
|
+
\u2716 Login failed: ${err.message}
|
|
5572
|
+
`));
|
|
5573
|
+
}
|
|
5574
|
+
process.exit(1);
|
|
5575
|
+
}
|
|
5576
|
+
}
|
|
5577
|
+
async function handleWhoami(options = {}) {
|
|
5578
|
+
const isJson = Boolean(options.json);
|
|
5579
|
+
const config = readConfig();
|
|
5580
|
+
const token = resolveToken();
|
|
5581
|
+
const apiUrl = resolveApiUrl(options.apiUrl);
|
|
5582
|
+
if (!token) {
|
|
5583
|
+
if (isJson) {
|
|
5584
|
+
printJson({ authenticated: false, message: "Not logged in (anonymous upload mode)" });
|
|
5585
|
+
} else {
|
|
5586
|
+
console.log(
|
|
5587
|
+
pc2.yellow(
|
|
5588
|
+
"\nNot logged in. CLI commands run in anonymous mode with Safe Harbor claim tokens."
|
|
5589
|
+
)
|
|
5590
|
+
);
|
|
5591
|
+
console.log(`Run ${pc2.cyan("replaystage login --token <rps_token>")} to authenticate.
|
|
5592
|
+
`);
|
|
5593
|
+
}
|
|
5594
|
+
return;
|
|
5595
|
+
}
|
|
5596
|
+
try {
|
|
5597
|
+
let user = config.user;
|
|
5598
|
+
try {
|
|
5599
|
+
user = await fetchWhoami(apiUrl, token);
|
|
5600
|
+
if (config.token === token) {
|
|
5601
|
+
writeConfig({ ...config, user });
|
|
5602
|
+
}
|
|
5603
|
+
} catch (err) {
|
|
5604
|
+
if (err?.status === 401 || err?.status === 403) {
|
|
5605
|
+
throw err;
|
|
5216
5606
|
}
|
|
5217
5607
|
}
|
|
5608
|
+
if (isJson) {
|
|
5609
|
+
printJson({
|
|
5610
|
+
authenticated: true,
|
|
5611
|
+
apiUrl,
|
|
5612
|
+
user: user || null,
|
|
5613
|
+
token: `${token.slice(0, 8)}...`
|
|
5614
|
+
});
|
|
5615
|
+
} else {
|
|
5616
|
+
console.log(pc2.green("\n\u2714 Authenticated to ReplayStage"));
|
|
5617
|
+
console.log(` ${pc2.dim("API URL:")} ${apiUrl}`);
|
|
5618
|
+
if (user?.handle) console.log(` ${pc2.dim("Handle:")} @${user.handle}`);
|
|
5619
|
+
if (user?.name) console.log(` ${pc2.dim("Name:")} ${user.name}`);
|
|
5620
|
+
if (user?.email) console.log(` ${pc2.dim("Email:")} ${user.email}`);
|
|
5621
|
+
console.log(` ${pc2.dim("Token:")} ${token.slice(0, 8)}...${token.slice(-4)}
|
|
5622
|
+
`);
|
|
5623
|
+
}
|
|
5624
|
+
} catch (err) {
|
|
5625
|
+
if (isJson) {
|
|
5626
|
+
printErrorJson("WHOAMI_FAILED", err.message, 1);
|
|
5627
|
+
} else {
|
|
5628
|
+
console.error(pc2.red(`
|
|
5629
|
+
\u2716 Auth check failed: ${err.message}
|
|
5630
|
+
`));
|
|
5631
|
+
}
|
|
5632
|
+
process.exit(1);
|
|
5633
|
+
}
|
|
5634
|
+
}
|
|
5635
|
+
async function handleLogout(options = {}) {
|
|
5636
|
+
const isJson = Boolean(options.json);
|
|
5637
|
+
clearConfig();
|
|
5638
|
+
if (isJson) {
|
|
5639
|
+
printJson({ success: true, message: "Logged out successfully" });
|
|
5640
|
+
} else {
|
|
5641
|
+
console.log(pc2.green("\n\u2714 Stored credentials cleared successfully.\n"));
|
|
5218
5642
|
}
|
|
5219
|
-
return { entryPath: null, prefix: "" };
|
|
5220
5643
|
}
|
|
5221
5644
|
|
|
5222
5645
|
// src/commands/publish.ts
|
|
5646
|
+
import fs5 from "fs";
|
|
5647
|
+
import path5 from "path";
|
|
5223
5648
|
import pc3 from "picocolors";
|
|
5224
5649
|
|
|
5225
5650
|
// src/packager.ts
|
|
5226
5651
|
import crypto from "crypto";
|
|
5227
|
-
import
|
|
5228
|
-
import
|
|
5652
|
+
import fs3 from "fs";
|
|
5653
|
+
import path3 from "path";
|
|
5229
5654
|
import * as fflate from "fflate";
|
|
5655
|
+
var COVER_PRECEDENCE_FILES = [
|
|
5656
|
+
"cover.png",
|
|
5657
|
+
"cover.jpg",
|
|
5658
|
+
"cover.jpeg",
|
|
5659
|
+
"cover.webp",
|
|
5660
|
+
"cover.gif"
|
|
5661
|
+
];
|
|
5662
|
+
function detectSiblingCover(targetPath) {
|
|
5663
|
+
const resolved = path3.resolve(process.cwd(), targetPath || ".");
|
|
5664
|
+
if (!fs3.existsSync(resolved)) return null;
|
|
5665
|
+
const stat = fs3.statSync(resolved);
|
|
5666
|
+
if (stat.isFile()) {
|
|
5667
|
+
const ext = path3.extname(resolved).toLowerCase();
|
|
5668
|
+
if (ext === ".html" || ext === ".htm") {
|
|
5669
|
+
return scanDirectoryForCover(path3.dirname(resolved), "sibling");
|
|
5670
|
+
}
|
|
5671
|
+
if (ext === ".zip") {
|
|
5672
|
+
try {
|
|
5673
|
+
const zipContent = fs3.readFileSync(resolved);
|
|
5674
|
+
const unzipped = fflate.unzipSync(new Uint8Array(zipContent));
|
|
5675
|
+
const entryPaths = Object.keys(unzipped);
|
|
5676
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
5677
|
+
for (const ep of entryPaths) {
|
|
5678
|
+
if (isIgnoredZipEntry(ep)) continue;
|
|
5679
|
+
const clean = ep.replace(/\\/g, "/").replace(/^\.?\//, "");
|
|
5680
|
+
lookup.set(clean.toLowerCase(), ep);
|
|
5681
|
+
}
|
|
5682
|
+
for (const candidate of COVER_PRECEDENCE_FILES) {
|
|
5683
|
+
const matchedKey = lookup.get(candidate);
|
|
5684
|
+
if (matchedKey) {
|
|
5685
|
+
const rawBytes = unzipped[matchedKey];
|
|
5686
|
+
const check = validateCoverImageBytes(rawBytes);
|
|
5687
|
+
if (check.valid && check.ext && check.mimeType) {
|
|
5688
|
+
return {
|
|
5689
|
+
source: "bundle",
|
|
5690
|
+
fileName: path3.basename(matchedKey),
|
|
5691
|
+
buffer: Buffer.from(rawBytes),
|
|
5692
|
+
ext: check.ext,
|
|
5693
|
+
mimeType: check.mimeType
|
|
5694
|
+
};
|
|
5695
|
+
}
|
|
5696
|
+
}
|
|
5697
|
+
}
|
|
5698
|
+
} catch {
|
|
5699
|
+
}
|
|
5700
|
+
return scanDirectoryForCover(path3.dirname(resolved), "sibling");
|
|
5701
|
+
}
|
|
5702
|
+
return null;
|
|
5703
|
+
}
|
|
5704
|
+
if (stat.isDirectory()) {
|
|
5705
|
+
return scanDirectoryForCover(resolved, "bundle");
|
|
5706
|
+
}
|
|
5707
|
+
return null;
|
|
5708
|
+
}
|
|
5709
|
+
function scanDirectoryForCover(dirPath, source) {
|
|
5710
|
+
try {
|
|
5711
|
+
const entries = fs3.readdirSync(dirPath, { withFileTypes: true });
|
|
5712
|
+
const entryMap = /* @__PURE__ */ new Map();
|
|
5713
|
+
for (const entry of entries) {
|
|
5714
|
+
if (entry.isFile()) {
|
|
5715
|
+
entryMap.set(entry.name.toLowerCase(), entry);
|
|
5716
|
+
}
|
|
5717
|
+
}
|
|
5718
|
+
for (const candidate of COVER_PRECEDENCE_FILES) {
|
|
5719
|
+
const match = entryMap.get(candidate);
|
|
5720
|
+
if (match) {
|
|
5721
|
+
const fullPath = path3.join(dirPath, match.name);
|
|
5722
|
+
const buf = fs3.readFileSync(fullPath);
|
|
5723
|
+
const check = validateCoverImageBytes(new Uint8Array(buf));
|
|
5724
|
+
if (check.valid && check.ext && check.mimeType) {
|
|
5725
|
+
return {
|
|
5726
|
+
source,
|
|
5727
|
+
fileName: match.name,
|
|
5728
|
+
filePath: fullPath,
|
|
5729
|
+
buffer: buf,
|
|
5730
|
+
ext: check.ext,
|
|
5731
|
+
mimeType: check.mimeType
|
|
5732
|
+
};
|
|
5733
|
+
}
|
|
5734
|
+
}
|
|
5735
|
+
}
|
|
5736
|
+
} catch {
|
|
5737
|
+
}
|
|
5738
|
+
return null;
|
|
5739
|
+
}
|
|
5230
5740
|
function extractHtmlMetadata(html) {
|
|
5231
5741
|
let title;
|
|
5232
5742
|
let tagline;
|
|
@@ -5240,11 +5750,15 @@ function extractHtmlMetadata(html) {
|
|
|
5240
5750
|
}
|
|
5241
5751
|
const rawAspect = extractRawAspectRatioFromHtml(html);
|
|
5242
5752
|
const aspectNorm = rawAspect ? normalizeAspectRatio(rawAspect) : null;
|
|
5753
|
+
const model = extractAiModelFromHtml(html);
|
|
5754
|
+
const tags = extractTagsFromHtml(html);
|
|
5243
5755
|
return {
|
|
5244
5756
|
title,
|
|
5245
5757
|
tagline,
|
|
5246
5758
|
rawAspectRatio: rawAspect ?? void 0,
|
|
5247
|
-
aspectRatio: aspectNorm?.valid ? aspectNorm.normalized : void 0
|
|
5759
|
+
aspectRatio: aspectNorm?.valid ? aspectNorm.normalized : void 0,
|
|
5760
|
+
model: model ?? null,
|
|
5761
|
+
tags: tags.length > 0 ? tags : void 0
|
|
5248
5762
|
};
|
|
5249
5763
|
}
|
|
5250
5764
|
function computeSha256(buf) {
|
|
@@ -5260,40 +5774,47 @@ function createZipFromFiles(fileMap) {
|
|
|
5260
5774
|
return Buffer.from(zipped);
|
|
5261
5775
|
}
|
|
5262
5776
|
async function packageGame(targetPath) {
|
|
5263
|
-
const resolved =
|
|
5264
|
-
if (!
|
|
5777
|
+
const resolved = path3.resolve(process.cwd(), targetPath || ".");
|
|
5778
|
+
if (!fs3.existsSync(resolved)) {
|
|
5265
5779
|
throw new Error(`Target path does not exist: ${resolved}`);
|
|
5266
5780
|
}
|
|
5267
|
-
const stat =
|
|
5781
|
+
const stat = fs3.statSync(resolved);
|
|
5268
5782
|
if (stat.isFile()) {
|
|
5269
|
-
const ext =
|
|
5783
|
+
const ext = path3.extname(resolved).toLowerCase();
|
|
5270
5784
|
if (ext === ".html" || ext === ".htm") {
|
|
5271
|
-
const content =
|
|
5785
|
+
const content = fs3.readFileSync(resolved);
|
|
5272
5786
|
if (content.length > MAX_HTML_SIZE_BYTES) {
|
|
5273
5787
|
throw new Error(
|
|
5274
5788
|
`Single HTML file exceeds maximum allowed size of 5MB (${(content.length / (1024 * 1024)).toFixed(2)} MB)`
|
|
5275
5789
|
);
|
|
5276
5790
|
}
|
|
5277
5791
|
const meta = extractHtmlMetadata(content.toString("utf-8"));
|
|
5278
|
-
const
|
|
5792
|
+
const files = { "index.html": content };
|
|
5793
|
+
const detectedCover = detectSiblingCover(resolved);
|
|
5794
|
+
if (detectedCover && detectedCover.buffer) {
|
|
5795
|
+
files[detectedCover.fileName] = detectedCover.buffer;
|
|
5796
|
+
}
|
|
5797
|
+
const zipBuffer = createZipFromFiles(files);
|
|
5279
5798
|
const fileHash = computeSha256(zipBuffer);
|
|
5280
5799
|
return {
|
|
5281
5800
|
format: "single-html",
|
|
5282
5801
|
entryPoint: "index.html",
|
|
5283
|
-
fileCount:
|
|
5802
|
+
fileCount: Object.keys(files).length,
|
|
5284
5803
|
totalBytes: content.length,
|
|
5285
|
-
totalSizeBytes:
|
|
5804
|
+
totalSizeBytes: Object.values(files).reduce((acc, b) => acc + b.length, 0),
|
|
5286
5805
|
buffer: zipBuffer,
|
|
5287
5806
|
bundleBuffer: zipBuffer,
|
|
5288
5807
|
fileHash,
|
|
5289
|
-
files:
|
|
5808
|
+
files: Object.keys(files),
|
|
5290
5809
|
extractedTitle: meta.title,
|
|
5291
5810
|
extractedTagline: meta.tagline,
|
|
5292
|
-
extractedAspectRatio: meta.aspectRatio
|
|
5811
|
+
extractedAspectRatio: meta.aspectRatio,
|
|
5812
|
+
extractedModel: meta.model ?? null,
|
|
5813
|
+
extractedTags: meta.tags
|
|
5293
5814
|
};
|
|
5294
5815
|
}
|
|
5295
5816
|
if (ext === ".zip") {
|
|
5296
|
-
const content =
|
|
5817
|
+
const content = fs3.readFileSync(resolved);
|
|
5297
5818
|
if (content.length > MAX_BUNDLE_SIZE_BYTES) {
|
|
5298
5819
|
throw new Error(
|
|
5299
5820
|
`Zip archive exceeds maximum allowed size of 25MB (${(content.length / (1024 * 1024)).toFixed(2)} MB)`
|
|
@@ -5329,6 +5850,8 @@ async function packageGame(targetPath) {
|
|
|
5329
5850
|
let extractedTitle;
|
|
5330
5851
|
let extractedTagline;
|
|
5331
5852
|
let extractedAspectRatio;
|
|
5853
|
+
let extractedModel;
|
|
5854
|
+
let extractedTags;
|
|
5332
5855
|
if (unzipped[entryRes.entryPath]) {
|
|
5333
5856
|
const meta = extractHtmlMetadata(
|
|
5334
5857
|
Buffer.from(unzipped[entryRes.entryPath]).toString("utf-8")
|
|
@@ -5336,6 +5859,8 @@ async function packageGame(targetPath) {
|
|
|
5336
5859
|
extractedTitle = meta.title;
|
|
5337
5860
|
extractedTagline = meta.tagline;
|
|
5338
5861
|
extractedAspectRatio = meta.aspectRatio;
|
|
5862
|
+
extractedModel = meta.model;
|
|
5863
|
+
extractedTags = meta.tags;
|
|
5339
5864
|
}
|
|
5340
5865
|
return {
|
|
5341
5866
|
format: "zip",
|
|
@@ -5349,7 +5874,9 @@ async function packageGame(targetPath) {
|
|
|
5349
5874
|
files: filteredFiles,
|
|
5350
5875
|
extractedTitle,
|
|
5351
5876
|
extractedTagline,
|
|
5352
|
-
extractedAspectRatio
|
|
5877
|
+
extractedAspectRatio,
|
|
5878
|
+
extractedModel: extractedModel ?? null,
|
|
5879
|
+
extractedTags
|
|
5353
5880
|
};
|
|
5354
5881
|
}
|
|
5355
5882
|
throw new Error(
|
|
@@ -5358,13 +5885,13 @@ async function packageGame(targetPath) {
|
|
|
5358
5885
|
}
|
|
5359
5886
|
if (stat.isDirectory()) {
|
|
5360
5887
|
let walk2 = function(currentDir, relDir) {
|
|
5361
|
-
const dirEntries =
|
|
5888
|
+
const dirEntries = fs3.readdirSync(currentDir, { withFileTypes: true });
|
|
5362
5889
|
for (const entry of dirEntries) {
|
|
5363
5890
|
const name = entry.name;
|
|
5364
5891
|
if (name.startsWith(".") || name === ".replaystage.json" || name.startsWith(".replaystage") || name === "node_modules" || name === "__MACOSX" || name === "Thumbs.db" || isIgnoredZipEntry(name)) {
|
|
5365
5892
|
continue;
|
|
5366
5893
|
}
|
|
5367
|
-
const fullPath =
|
|
5894
|
+
const fullPath = path3.join(currentDir, name);
|
|
5368
5895
|
const relPath = relDir ? `${relDir}/${name}` : name;
|
|
5369
5896
|
const normalizedRelPath = relPath.replace(/\\/g, "/");
|
|
5370
5897
|
if (isIgnoredZipEntry(normalizedRelPath)) {
|
|
@@ -5382,14 +5909,14 @@ async function packageGame(targetPath) {
|
|
|
5382
5909
|
if (!validation.valid) {
|
|
5383
5910
|
throw new Error(`Invalid file path in directory: ${validation.error}`);
|
|
5384
5911
|
}
|
|
5385
|
-
const fileStat =
|
|
5912
|
+
const fileStat = fs3.statSync(fullPath);
|
|
5386
5913
|
totalSizeBytes += fileStat.size;
|
|
5387
5914
|
if (totalSizeBytes > MAX_BUNDLE_SIZE_BYTES) {
|
|
5388
5915
|
throw new Error(
|
|
5389
5916
|
`Game bundle exceeds maximum allowed size of 25MB (${(totalSizeBytes / (1024 * 1024)).toFixed(2)} MB).`
|
|
5390
5917
|
);
|
|
5391
5918
|
}
|
|
5392
|
-
const buf =
|
|
5919
|
+
const buf = fs3.readFileSync(fullPath);
|
|
5393
5920
|
fileEntries[normalizedRelPath] = buf;
|
|
5394
5921
|
filesList.push(normalizedRelPath);
|
|
5395
5922
|
}
|
|
@@ -5413,12 +5940,16 @@ async function packageGame(targetPath) {
|
|
|
5413
5940
|
let extractedTitle;
|
|
5414
5941
|
let extractedTagline;
|
|
5415
5942
|
let extractedAspectRatio;
|
|
5943
|
+
let extractedModel;
|
|
5944
|
+
let extractedTags;
|
|
5416
5945
|
const entryBuf = fileEntries[entryResolution.entryPath];
|
|
5417
5946
|
if (entryBuf) {
|
|
5418
5947
|
const meta = extractHtmlMetadata(entryBuf.toString("utf-8"));
|
|
5419
5948
|
extractedTitle = meta.title;
|
|
5420
5949
|
extractedTagline = meta.tagline;
|
|
5421
5950
|
extractedAspectRatio = meta.aspectRatio;
|
|
5951
|
+
extractedModel = meta.model;
|
|
5952
|
+
extractedTags = meta.tags;
|
|
5422
5953
|
}
|
|
5423
5954
|
const zipBuffer = createZipFromFiles(fileEntries);
|
|
5424
5955
|
const fileHash = computeSha256(zipBuffer);
|
|
@@ -5434,105 +5965,14 @@ async function packageGame(targetPath) {
|
|
|
5434
5965
|
files: filesList,
|
|
5435
5966
|
extractedTitle,
|
|
5436
5967
|
extractedTagline,
|
|
5437
|
-
extractedAspectRatio
|
|
5968
|
+
extractedAspectRatio,
|
|
5969
|
+
extractedModel: extractedModel ?? null,
|
|
5970
|
+
extractedTags
|
|
5438
5971
|
};
|
|
5439
5972
|
}
|
|
5440
5973
|
throw new Error(`Invalid target path: '${targetPath}' is neither a file nor a directory.`);
|
|
5441
5974
|
}
|
|
5442
5975
|
|
|
5443
|
-
// src/project.ts
|
|
5444
|
-
import * as fs3 from "fs";
|
|
5445
|
-
import * as os2 from "os";
|
|
5446
|
-
import * as path3 from "path";
|
|
5447
|
-
function resolveProjectDirectory(targetPath) {
|
|
5448
|
-
try {
|
|
5449
|
-
const resolved = path3.resolve(targetPath);
|
|
5450
|
-
if (resolved.toLowerCase().endsWith(".zip")) {
|
|
5451
|
-
return null;
|
|
5452
|
-
}
|
|
5453
|
-
if (resolved.includes("seed-games")) {
|
|
5454
|
-
return null;
|
|
5455
|
-
}
|
|
5456
|
-
if (fs3.existsSync(resolved) && fs3.statSync(resolved).isDirectory()) {
|
|
5457
|
-
if (resolved === path3.resolve(os2.tmpdir())) {
|
|
5458
|
-
return null;
|
|
5459
|
-
}
|
|
5460
|
-
return resolved;
|
|
5461
|
-
}
|
|
5462
|
-
if (fs3.existsSync(resolved) && fs3.statSync(resolved).isFile()) {
|
|
5463
|
-
const parentDir = path3.dirname(resolved);
|
|
5464
|
-
if (parentDir === path3.resolve(os2.tmpdir())) {
|
|
5465
|
-
return null;
|
|
5466
|
-
}
|
|
5467
|
-
return parentDir;
|
|
5468
|
-
}
|
|
5469
|
-
return resolved;
|
|
5470
|
-
} catch {
|
|
5471
|
-
return path3.resolve(targetPath);
|
|
5472
|
-
}
|
|
5473
|
-
}
|
|
5474
|
-
function getProjectConfigPath(targetDir) {
|
|
5475
|
-
const dir = resolveProjectDirectory(targetDir);
|
|
5476
|
-
return dir ? path3.join(dir, ".replaystage.json") : null;
|
|
5477
|
-
}
|
|
5478
|
-
function readProjectConfig(targetDir) {
|
|
5479
|
-
const configPath = getProjectConfigPath(targetDir);
|
|
5480
|
-
if (!configPath || !fs3.existsSync(configPath)) {
|
|
5481
|
-
return null;
|
|
5482
|
-
}
|
|
5483
|
-
try {
|
|
5484
|
-
const raw = fs3.readFileSync(configPath, "utf-8");
|
|
5485
|
-
const parsed = JSON.parse(raw);
|
|
5486
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
5487
|
-
return null;
|
|
5488
|
-
}
|
|
5489
|
-
if ("slug" in parsed) {
|
|
5490
|
-
if (typeof parsed.slug !== "string" || !parsed.slug.trim()) {
|
|
5491
|
-
return null;
|
|
5492
|
-
}
|
|
5493
|
-
}
|
|
5494
|
-
const hasValidKey = typeof parsed.slug === "string" && parsed.slug.trim().length > 0 || typeof parsed.supportedPlatforms === "string" || typeof parsed.platforms === "string" || typeof parsed.aspectRatio === "string";
|
|
5495
|
-
if (!hasValidKey) {
|
|
5496
|
-
return null;
|
|
5497
|
-
}
|
|
5498
|
-
return parsed;
|
|
5499
|
-
} catch {
|
|
5500
|
-
return null;
|
|
5501
|
-
}
|
|
5502
|
-
}
|
|
5503
|
-
function writeProjectConfig(targetDir, config) {
|
|
5504
|
-
const configPath = getProjectConfigPath(targetDir);
|
|
5505
|
-
if (!configPath) {
|
|
5506
|
-
return;
|
|
5507
|
-
}
|
|
5508
|
-
const dir = path3.dirname(configPath);
|
|
5509
|
-
if (!fs3.existsSync(dir)) {
|
|
5510
|
-
fs3.mkdirSync(dir, { recursive: true });
|
|
5511
|
-
}
|
|
5512
|
-
fs3.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}
|
|
5513
|
-
`, "utf-8");
|
|
5514
|
-
}
|
|
5515
|
-
function incrementVersion(currentVersion) {
|
|
5516
|
-
if (!currentVersion || typeof currentVersion !== "string") return "0.2.0";
|
|
5517
|
-
const sanitized = currentVersion.trim().replace(/^v/i, "");
|
|
5518
|
-
const parts = sanitized.split(".").map((n) => Number.parseInt(n, 10));
|
|
5519
|
-
if (parts.length === 3 && !parts.some(Number.isNaN)) {
|
|
5520
|
-
return `${parts[0]}.${parts[1] + 1}.0`;
|
|
5521
|
-
}
|
|
5522
|
-
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
5523
|
-
return `${parts[0]}.${parts[1] + 1}.0`;
|
|
5524
|
-
}
|
|
5525
|
-
return "0.2.0";
|
|
5526
|
-
}
|
|
5527
|
-
function promoteDraftVersion(currentVersion) {
|
|
5528
|
-
if (!currentVersion || typeof currentVersion !== "string") return "1.0.0";
|
|
5529
|
-
const sanitized = currentVersion.trim().replace(/^v/i, "");
|
|
5530
|
-
if (sanitized.startsWith("0.")) {
|
|
5531
|
-
return "1.0.0";
|
|
5532
|
-
}
|
|
5533
|
-
return incrementVersion(currentVersion);
|
|
5534
|
-
}
|
|
5535
|
-
|
|
5536
5976
|
// src/validation.ts
|
|
5537
5977
|
import crypto2 from "crypto";
|
|
5538
5978
|
import fs4 from "fs";
|
|
@@ -5573,11 +6013,13 @@ async function validateGamePackage(targetPath) {
|
|
|
5573
6013
|
let detectedAspectRatio = "auto";
|
|
5574
6014
|
let detectedPlatforms = DEFAULT_SUPPORTED_PLATFORMS;
|
|
5575
6015
|
let hasPlatformMeta = false;
|
|
6016
|
+
let detectedModel = null;
|
|
5576
6017
|
if (!fs4.existsSync(resolved)) {
|
|
5577
6018
|
return {
|
|
5578
6019
|
valid: false,
|
|
5579
6020
|
targetPath,
|
|
5580
6021
|
aspectRatio: detectedAspectRatio,
|
|
6022
|
+
aiModel: detectedModel,
|
|
5581
6023
|
supportedPlatforms: detectedPlatforms,
|
|
5582
6024
|
platforms: detectedPlatforms,
|
|
5583
6025
|
hasPlatformMeta,
|
|
@@ -5600,6 +6042,7 @@ async function validateGamePackage(targetPath) {
|
|
|
5600
6042
|
if (!depCheck.valid) {
|
|
5601
6043
|
errors.push(...depCheck.errors);
|
|
5602
6044
|
}
|
|
6045
|
+
detectedModel = extractAiModelFromHtml(htmlStr);
|
|
5603
6046
|
const rawMeta = extractRawAspectRatioFromHtml(htmlStr);
|
|
5604
6047
|
if (rawMeta) {
|
|
5605
6048
|
const norm = normalizeAspectRatio(rawMeta);
|
|
@@ -5638,6 +6081,7 @@ async function validateGamePackage(targetPath) {
|
|
|
5638
6081
|
if (!depCheck.valid) {
|
|
5639
6082
|
errors.push(...depCheck.errors);
|
|
5640
6083
|
}
|
|
6084
|
+
detectedModel = extractAiModelFromHtml(htmlContent);
|
|
5641
6085
|
const rawMeta = extractRawAspectRatioFromHtml(htmlContent);
|
|
5642
6086
|
if (rawMeta) {
|
|
5643
6087
|
const norm = normalizeAspectRatio(rawMeta);
|
|
@@ -5739,6 +6183,7 @@ async function validateGamePackage(targetPath) {
|
|
|
5739
6183
|
if (!depCheck.valid) {
|
|
5740
6184
|
errors.push(...depCheck.errors);
|
|
5741
6185
|
}
|
|
6186
|
+
detectedModel = extractAiModelFromHtml(htmlContent);
|
|
5742
6187
|
const rawMeta = extractRawAspectRatioFromHtml(htmlContent);
|
|
5743
6188
|
if (rawMeta) {
|
|
5744
6189
|
const norm = normalizeAspectRatio(rawMeta);
|
|
@@ -5782,6 +6227,7 @@ async function validateGamePackage(targetPath) {
|
|
|
5782
6227
|
valid: false,
|
|
5783
6228
|
targetPath,
|
|
5784
6229
|
aspectRatio: detectedAspectRatio,
|
|
6230
|
+
aiModel: detectedModel,
|
|
5785
6231
|
supportedPlatforms: detectedPlatforms,
|
|
5786
6232
|
platforms: detectedPlatforms,
|
|
5787
6233
|
hasPlatformMeta,
|
|
@@ -5809,9 +6255,11 @@ async function validateGamePackage(targetPath) {
|
|
|
5809
6255
|
fileHash: deterministicHash,
|
|
5810
6256
|
files: pkg.files,
|
|
5811
6257
|
aspectRatio: detectedAspectRatio !== "auto" ? detectedAspectRatio : pkg.extractedAspectRatio ?? detectedAspectRatio,
|
|
6258
|
+
aiModel: detectedModel || pkg.extractedModel || null,
|
|
5812
6259
|
supportedPlatforms: detectedPlatforms,
|
|
5813
6260
|
platforms: detectedPlatforms,
|
|
5814
6261
|
hasPlatformMeta,
|
|
6262
|
+
tags: pkg.extractedTags ?? [],
|
|
5815
6263
|
errors: [],
|
|
5816
6264
|
warnings
|
|
5817
6265
|
};
|
|
@@ -5820,6 +6268,7 @@ async function validateGamePackage(targetPath) {
|
|
|
5820
6268
|
valid: false,
|
|
5821
6269
|
targetPath,
|
|
5822
6270
|
aspectRatio: detectedAspectRatio,
|
|
6271
|
+
aiModel: detectedModel,
|
|
5823
6272
|
supportedPlatforms: detectedPlatforms,
|
|
5824
6273
|
platforms: detectedPlatforms,
|
|
5825
6274
|
hasPlatformMeta,
|
|
@@ -5893,10 +6342,6 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
5893
6342
|
}
|
|
5894
6343
|
if (tagline.length < 3) tagline = "An arcade game on ReplayStage";
|
|
5895
6344
|
if (tagline.length > 120) tagline = tagline.slice(0, 120);
|
|
5896
|
-
let aiTool = (options.tool || "other").toLowerCase().trim();
|
|
5897
|
-
if (!AI_TOOL_KEYS.includes(aiTool)) {
|
|
5898
|
-
aiTool = "other";
|
|
5899
|
-
}
|
|
5900
6345
|
let category = options.category?.toLowerCase().trim();
|
|
5901
6346
|
if (category && !GAME_CATEGORY_KEYS.includes(category)) {
|
|
5902
6347
|
category = void 0;
|
|
@@ -5904,6 +6349,114 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
5904
6349
|
const token = options.anonymous ? null : resolveToken(options.token);
|
|
5905
6350
|
const apiUrl = resolveApiUrl(options.apiUrl);
|
|
5906
6351
|
const existingConfig = !options.fresh ? readProjectConfig(resolvedPath) : null;
|
|
6352
|
+
let aiTool = "";
|
|
6353
|
+
if (options.tool !== void 0) {
|
|
6354
|
+
const parsedTool = aiToolSchema.safeParse(options.tool);
|
|
6355
|
+
if (!parsedTool.success) {
|
|
6356
|
+
const errorMsg = parsedTool.error.errors[0]?.message || `Invalid AI tool: ${options.tool}`;
|
|
6357
|
+
if (isJson) {
|
|
6358
|
+
printErrorJson("INVALID_OPTIONS", errorMsg, 1);
|
|
6359
|
+
} else {
|
|
6360
|
+
console.error(pc3.red(`
|
|
6361
|
+
\u2716 Invalid option: ${errorMsg}
|
|
6362
|
+
`));
|
|
6363
|
+
}
|
|
6364
|
+
process.exit(1);
|
|
6365
|
+
}
|
|
6366
|
+
const rawTool = parsedTool.data;
|
|
6367
|
+
if (rawTool) {
|
|
6368
|
+
const matchedPreset = AI_TOOL_KEYS.find(
|
|
6369
|
+
(key) => key.toLowerCase() === rawTool.toLowerCase() || AI_TOOLS[key] && AI_TOOLS[key].name.toLowerCase() === rawTool.toLowerCase()
|
|
6370
|
+
);
|
|
6371
|
+
aiTool = matchedPreset ? matchedPreset : rawTool;
|
|
6372
|
+
} else {
|
|
6373
|
+
aiTool = "";
|
|
6374
|
+
}
|
|
6375
|
+
} else if (existingConfig?.aiTool && existingConfig.aiTool !== "other") {
|
|
6376
|
+
aiTool = existingConfig.aiTool;
|
|
6377
|
+
}
|
|
6378
|
+
let resolvedModel = null;
|
|
6379
|
+
if (options.model !== void 0) {
|
|
6380
|
+
const parsedModel = aiModelSchema.safeParse(options.model);
|
|
6381
|
+
if (!parsedModel.success) {
|
|
6382
|
+
const errorMsg = parsedModel.error.errors[0]?.message || `Invalid AI model: ${options.model}`;
|
|
6383
|
+
if (isJson) {
|
|
6384
|
+
printErrorJson("INVALID_OPTIONS", errorMsg, 1);
|
|
6385
|
+
} else {
|
|
6386
|
+
console.error(pc3.red(`
|
|
6387
|
+
\u2716 Invalid option: ${errorMsg}
|
|
6388
|
+
`));
|
|
6389
|
+
}
|
|
6390
|
+
process.exit(1);
|
|
6391
|
+
}
|
|
6392
|
+
resolvedModel = parsedModel.data ?? null;
|
|
6393
|
+
} else if (bundle.extractedModel) {
|
|
6394
|
+
resolvedModel = bundle.extractedModel;
|
|
6395
|
+
} else if (existingConfig?.aiModel) {
|
|
6396
|
+
resolvedModel = existingConfig.aiModel;
|
|
6397
|
+
}
|
|
6398
|
+
let coverBuffer;
|
|
6399
|
+
let coverFileName;
|
|
6400
|
+
if (options.cover !== void 0 && options.cover !== "") {
|
|
6401
|
+
const resolvedCoverPath = path5.resolve(process.cwd(), options.cover);
|
|
6402
|
+
if (!fs5.existsSync(resolvedCoverPath)) {
|
|
6403
|
+
const errorMsg = `Cover image file does not exist: ${resolvedCoverPath}`;
|
|
6404
|
+
if (isJson) {
|
|
6405
|
+
printErrorJson("INVALID_OPTIONS", errorMsg, 1);
|
|
6406
|
+
} else {
|
|
6407
|
+
console.error(pc3.red(`
|
|
6408
|
+
\u2716 Invalid option: ${errorMsg}
|
|
6409
|
+
`));
|
|
6410
|
+
}
|
|
6411
|
+
process.exit(1);
|
|
6412
|
+
}
|
|
6413
|
+
const stat = fs5.statSync(resolvedCoverPath);
|
|
6414
|
+
if (!stat.isFile()) {
|
|
6415
|
+
const errorMsg = `Specified cover path is not a file: ${resolvedCoverPath}`;
|
|
6416
|
+
if (isJson) {
|
|
6417
|
+
printErrorJson("INVALID_OPTIONS", errorMsg, 1);
|
|
6418
|
+
} else {
|
|
6419
|
+
console.error(pc3.red(`
|
|
6420
|
+
\u2716 Invalid option: ${errorMsg}
|
|
6421
|
+
`));
|
|
6422
|
+
}
|
|
6423
|
+
process.exit(1);
|
|
6424
|
+
}
|
|
6425
|
+
const ext = path5.extname(resolvedCoverPath).toLowerCase().replace(".", "");
|
|
6426
|
+
const allowedExts = ["png", "jpg", "jpeg", "webp", "gif"];
|
|
6427
|
+
if (!allowedExts.includes(ext)) {
|
|
6428
|
+
const errorMsg = `Unsupported cover image format: '.${ext}'. Supported formats are PNG, JPG, JPEG, WebP, GIF.`;
|
|
6429
|
+
if (isJson) {
|
|
6430
|
+
printErrorJson("INVALID_OPTIONS", errorMsg, 1);
|
|
6431
|
+
} else {
|
|
6432
|
+
console.error(pc3.red(`
|
|
6433
|
+
\u2716 Invalid option: ${errorMsg}
|
|
6434
|
+
`));
|
|
6435
|
+
}
|
|
6436
|
+
process.exit(1);
|
|
6437
|
+
}
|
|
6438
|
+
const rawCoverBytes = fs5.readFileSync(resolvedCoverPath);
|
|
6439
|
+
const coverValidation = validateCoverImageBytes(new Uint8Array(rawCoverBytes));
|
|
6440
|
+
if (!coverValidation.valid) {
|
|
6441
|
+
const errorMsg = `Invalid cover image: ${coverValidation.error || "Corrupted image file"}`;
|
|
6442
|
+
if (isJson) {
|
|
6443
|
+
printErrorJson("INVALID_OPTIONS", errorMsg, 1);
|
|
6444
|
+
} else {
|
|
6445
|
+
console.error(pc3.red(`
|
|
6446
|
+
\u2716 Invalid option: ${errorMsg}
|
|
6447
|
+
`));
|
|
6448
|
+
}
|
|
6449
|
+
process.exit(1);
|
|
6450
|
+
}
|
|
6451
|
+
coverBuffer = rawCoverBytes;
|
|
6452
|
+
coverFileName = path5.basename(resolvedCoverPath);
|
|
6453
|
+
} else {
|
|
6454
|
+
const detected = detectSiblingCover(resolvedPath);
|
|
6455
|
+
if (detected) {
|
|
6456
|
+
coverBuffer = detected.buffer;
|
|
6457
|
+
coverFileName = detected.fileName;
|
|
6458
|
+
}
|
|
6459
|
+
}
|
|
5907
6460
|
let resolvedAspectRatio = "auto";
|
|
5908
6461
|
if (options.aspectRatio) {
|
|
5909
6462
|
const norm = normalizeAspectRatio(options.aspectRatio);
|
|
@@ -5949,6 +6502,47 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
5949
6502
|
} else if (validation.supportedPlatforms) {
|
|
5950
6503
|
resolvedPlatforms = validation.supportedPlatforms;
|
|
5951
6504
|
}
|
|
6505
|
+
let resolvedTags = [];
|
|
6506
|
+
if (options.tags !== void 0) {
|
|
6507
|
+
const rawTags = options.tags.split(",").map((t) => t.trim()).filter(Boolean);
|
|
6508
|
+
if (rawTags.length > 0) {
|
|
6509
|
+
if (rawTags.length > MAX_TAGS_COUNT) {
|
|
6510
|
+
const errorMsg = `Too many tags: maximum ${MAX_TAGS_COUNT} tags allowed, but received ${rawTags.length}`;
|
|
6511
|
+
if (isJson) {
|
|
6512
|
+
printErrorJson("INVALID_OPTIONS", errorMsg, 1);
|
|
6513
|
+
} else {
|
|
6514
|
+
console.error(pc3.red(`
|
|
6515
|
+
\u2716 Invalid option: ${errorMsg}
|
|
6516
|
+
`));
|
|
6517
|
+
}
|
|
6518
|
+
process.exit(1);
|
|
6519
|
+
}
|
|
6520
|
+
for (const rawTag of rawTags) {
|
|
6521
|
+
const formatted = rawTag.toLowerCase().replace(/[\s_]+/g, "-").replace(/^-+|-+$/g, "");
|
|
6522
|
+
const parsedTag = tagSchema.safeParse(formatted);
|
|
6523
|
+
if (!parsedTag.success) {
|
|
6524
|
+
const errorMsg = `Invalid tag '${rawTag}': ${parsedTag.error.errors[0]?.message || "invalid tag format"}`;
|
|
6525
|
+
if (isJson) {
|
|
6526
|
+
printErrorJson("INVALID_OPTIONS", errorMsg, 1);
|
|
6527
|
+
} else {
|
|
6528
|
+
console.error(pc3.red(`
|
|
6529
|
+
\u2716 Invalid option: ${errorMsg}
|
|
6530
|
+
`));
|
|
6531
|
+
}
|
|
6532
|
+
process.exit(1);
|
|
6533
|
+
}
|
|
6534
|
+
}
|
|
6535
|
+
resolvedTags = normalizeTags(rawTags);
|
|
6536
|
+
} else {
|
|
6537
|
+
resolvedTags = [];
|
|
6538
|
+
}
|
|
6539
|
+
} else if (bundle.extractedTags && bundle.extractedTags.length > 0) {
|
|
6540
|
+
resolvedTags = bundle.extractedTags;
|
|
6541
|
+
} else if (existingConfig?.tags && Array.isArray(existingConfig.tags) && existingConfig.tags.length > 0) {
|
|
6542
|
+
resolvedTags = normalizeTags(existingConfig.tags);
|
|
6543
|
+
} else {
|
|
6544
|
+
resolvedTags = [];
|
|
6545
|
+
}
|
|
5952
6546
|
if (existingConfig?.slug) {
|
|
5953
6547
|
logInfo(
|
|
5954
6548
|
`Updating existing stage '${existingConfig.slug}' (current version: ${existingConfig.version || "0.1.0"})...`,
|
|
@@ -5967,6 +6561,11 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
5967
6561
|
supportedPlatforms: resolvedPlatforms,
|
|
5968
6562
|
manageToken: existingConfig.manageToken,
|
|
5969
6563
|
token,
|
|
6564
|
+
aiModel: resolvedModel,
|
|
6565
|
+
aiTool,
|
|
6566
|
+
tags: resolvedTags,
|
|
6567
|
+
coverBuffer,
|
|
6568
|
+
coverFileName,
|
|
5970
6569
|
errorMsgFallback: "Failed to update stage"
|
|
5971
6570
|
});
|
|
5972
6571
|
const resolvedVis = updateResult.visibility || visibility || existingConfig.visibility;
|
|
@@ -5981,7 +6580,10 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
5981
6580
|
visibility: resolvedVis,
|
|
5982
6581
|
aspectRatio: resolvedAspectRatio,
|
|
5983
6582
|
supportedPlatforms: resolvedPlatforms,
|
|
5984
|
-
platforms: resolvedPlatforms
|
|
6583
|
+
platforms: resolvedPlatforms,
|
|
6584
|
+
aiModel: resolvedModel !== void 0 ? resolvedModel : existingConfig.aiModel ?? null,
|
|
6585
|
+
aiTool: aiTool || void 0,
|
|
6586
|
+
tags: resolvedTags
|
|
5985
6587
|
};
|
|
5986
6588
|
writeProjectConfig(resolvedPath, updatedConfig);
|
|
5987
6589
|
if (isJson) {
|
|
@@ -5997,6 +6599,9 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
5997
6599
|
aspectRatio: updatedConfig.aspectRatio,
|
|
5998
6600
|
supportedPlatforms: resolvedPlatforms,
|
|
5999
6601
|
platforms: resolvedPlatforms,
|
|
6602
|
+
aiModel: updatedConfig.aiModel,
|
|
6603
|
+
aiTool: updatedConfig.aiTool,
|
|
6604
|
+
tags: resolvedTags,
|
|
6000
6605
|
promotedToPublic: updateResult.promotedToPublic,
|
|
6001
6606
|
fileHash: updateResult.fileHash || bundle.fileHash,
|
|
6002
6607
|
updated: true
|
|
@@ -6017,6 +6622,9 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6017
6622
|
if (updatedConfig.supportedPlatforms) {
|
|
6018
6623
|
console.log(` Platforms: ${pc3.bold(updatedConfig.supportedPlatforms)}`);
|
|
6019
6624
|
}
|
|
6625
|
+
if (resolvedTags.length > 0) {
|
|
6626
|
+
console.log(` Tags: ${resolvedTags.map((t) => pc3.cyan(`#${t}`)).join(" ")}`);
|
|
6627
|
+
}
|
|
6020
6628
|
if (options.changelog) {
|
|
6021
6629
|
console.log(` Changelog: "${options.changelog}"`);
|
|
6022
6630
|
}
|
|
@@ -6054,6 +6662,10 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6054
6662
|
tagline,
|
|
6055
6663
|
description: options.description,
|
|
6056
6664
|
aiTool,
|
|
6665
|
+
aiModel: resolvedModel,
|
|
6666
|
+
tags: resolvedTags,
|
|
6667
|
+
coverBuffer,
|
|
6668
|
+
coverFileName,
|
|
6057
6669
|
category,
|
|
6058
6670
|
token,
|
|
6059
6671
|
fileHash: bundle.fileHash,
|
|
@@ -6077,7 +6689,10 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6077
6689
|
visibility: initialVisibility,
|
|
6078
6690
|
aspectRatio: resolvedAspectRatio,
|
|
6079
6691
|
supportedPlatforms: resolvedPlatforms,
|
|
6080
|
-
platforms: resolvedPlatforms
|
|
6692
|
+
platforms: resolvedPlatforms,
|
|
6693
|
+
aiModel: resolvedModel,
|
|
6694
|
+
aiTool: aiTool || void 0,
|
|
6695
|
+
tags: resolvedTags
|
|
6081
6696
|
});
|
|
6082
6697
|
if (isJson) {
|
|
6083
6698
|
printJson({
|
|
@@ -6096,7 +6711,10 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6096
6711
|
visibility: initialVisibility,
|
|
6097
6712
|
aspectRatio: resolvedAspectRatio,
|
|
6098
6713
|
supportedPlatforms: resolvedPlatforms,
|
|
6099
|
-
platforms: resolvedPlatforms
|
|
6714
|
+
platforms: resolvedPlatforms,
|
|
6715
|
+
aiModel: resolvedModel,
|
|
6716
|
+
aiTool: aiTool || void 0,
|
|
6717
|
+
tags: resolvedTags
|
|
6100
6718
|
});
|
|
6101
6719
|
} else {
|
|
6102
6720
|
printPublishSuccess({
|
|
@@ -6107,6 +6725,7 @@ async function handlePublish(targetPath = ".", options = {}) {
|
|
|
6107
6725
|
claim_token: result.claim_token,
|
|
6108
6726
|
claimUrl: result.claimUrl,
|
|
6109
6727
|
aiTool,
|
|
6728
|
+
tags: resolvedTags,
|
|
6110
6729
|
fileHash: bundle.fileHash,
|
|
6111
6730
|
aspectRatio: resolvedAspectRatio,
|
|
6112
6731
|
supportedPlatforms: resolvedPlatforms
|
|
@@ -6170,7 +6789,7 @@ async function handleValidate(targetPath = ".", options = {}) {
|
|
|
6170
6789
|
|
|
6171
6790
|
// src/fingerprint.ts
|
|
6172
6791
|
import crypto3 from "crypto";
|
|
6173
|
-
import
|
|
6792
|
+
import fs6 from "fs";
|
|
6174
6793
|
async function computeFingerprint(input) {
|
|
6175
6794
|
if (typeof input === "string") {
|
|
6176
6795
|
return sha256(input);
|
|
@@ -6180,20 +6799,29 @@ async function computeFingerprint(input) {
|
|
|
6180
6799
|
return hash.digest("hex").toLowerCase();
|
|
6181
6800
|
}
|
|
6182
6801
|
async function computeFileFingerprint(filePath) {
|
|
6183
|
-
const content =
|
|
6802
|
+
const content = fs6.readFileSync(filePath);
|
|
6184
6803
|
return computeFingerprint(content);
|
|
6185
6804
|
}
|
|
6186
6805
|
|
|
6187
6806
|
// src/index.ts
|
|
6188
6807
|
function createProgram() {
|
|
6189
6808
|
const program = new Command();
|
|
6190
|
-
program.name("replaystage").description("ReplayStage CLI: Deploy and share web games from command line and AI agents").version("0.
|
|
6809
|
+
program.name("replaystage").description("ReplayStage CLI: Deploy and share web games from command line and AI agents").version("0.4.0");
|
|
6191
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>", "Catchy one-line arcade tagline (3-120 characters)").option("-d, --description <desc>", "Gameplay instructions or description").option(
|
|
6192
6811
|
"--tool <tool>",
|
|
6193
6812
|
"AI tool used to generate the game (claude, gemini, antigravity, cursor, etc.)"
|
|
6813
|
+
).option(
|
|
6814
|
+
"-m, --model <model>",
|
|
6815
|
+
"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)"
|
|
6194
6819
|
).option(
|
|
6195
6820
|
"--category <category>",
|
|
6196
|
-
"Game category (arcade, action, puzzle,
|
|
6821
|
+
"Game category (arcade, action, puzzle, strategy, simulation, racing, rpg, casual)"
|
|
6822
|
+
).option(
|
|
6823
|
+
"--tags <tags>",
|
|
6824
|
+
"Comma-separated feature tags (e.g., 3d, retro, physics, roguelike, cozy; max 6 tags)"
|
|
6197
6825
|
).option(
|
|
6198
6826
|
"--aspect-ratio <ratio>",
|
|
6199
6827
|
"Display aspect ratio (auto, 16:9, 9:16, 4:3, 3:4, 1:1, or custom W:H)"
|
|
@@ -6243,6 +6871,7 @@ if (isDirectCliExecution) {
|
|
|
6243
6871
|
void runCli(process.argv);
|
|
6244
6872
|
}
|
|
6245
6873
|
export {
|
|
6874
|
+
COVER_PRECEDENCE_FILES,
|
|
6246
6875
|
checkHtmlDependencies,
|
|
6247
6876
|
clearConfig,
|
|
6248
6877
|
clearToken,
|
|
@@ -6251,6 +6880,7 @@ export {
|
|
|
6251
6880
|
computeSha256,
|
|
6252
6881
|
createProgram,
|
|
6253
6882
|
createZipFromFiles,
|
|
6883
|
+
detectSiblingCover,
|
|
6254
6884
|
extractHtmlMetadata,
|
|
6255
6885
|
fetchWhoami,
|
|
6256
6886
|
getConfigDir,
|
|
@@ -6273,6 +6903,7 @@ export {
|
|
|
6273
6903
|
resolveProjectDirectory,
|
|
6274
6904
|
resolveToken,
|
|
6275
6905
|
runCli,
|
|
6906
|
+
writeProjectConfig as saveProjectConfig,
|
|
6276
6907
|
setToken,
|
|
6277
6908
|
updateGame,
|
|
6278
6909
|
updateGameBundle,
|