@replaystage/cli 2.0.0 → 2.1.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 +9 -6
- package/dist/commands/admin.js +6 -1
- package/dist/commands/auth.js +14 -4
- package/dist/commands/creator.d.ts +3 -0
- package/dist/commands/creator.js +293 -17
- package/dist/http.d.ts +4 -0
- package/dist/http.js +82 -44
- package/dist/index.d.ts +1 -1
- package/dist/index.js +23 -5
- package/dist/manifest.js +2 -2
- package/dist/output.js +1 -1
- package/dist/validate.d.ts +1 -0
- package/dist/validate.js +37 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,18 +6,21 @@ Unified, zero-dependency agent-native CLI for **ReplayStage** ([replaystage.com]
|
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
# 1. Mint a personal API Key (RSKEY_...) at https://studio.replaystage.com/account
|
|
9
|
-
npx -y replaystage login --token
|
|
9
|
+
echo "RSKEY_..." | npx -y replaystage login --token-stdin --json
|
|
10
10
|
|
|
11
|
-
# 2. Initialize
|
|
11
|
+
# 2. Initialize manifest or sync latest @replaystage/sdk into your portrait game repo
|
|
12
12
|
npx -y replaystage init my-game --title "My Game" --zh "我的游戏" --genre arcade --json
|
|
13
|
+
npx -y replaystage sdk sync
|
|
13
14
|
|
|
14
|
-
# 3. Validate your build output offline
|
|
15
|
-
npx -y replaystage validate ./dist --json
|
|
15
|
+
# 3. Validate your build output offline (--strict fails on warnings)
|
|
16
|
+
npx -y replaystage validate ./dist --strict --json
|
|
16
17
|
|
|
17
|
-
# 4.
|
|
18
|
+
# 4. Dry-run or publish (new games default to unlisted preview; pass --live to publish publicly)
|
|
19
|
+
npx -y replaystage publish ./dist --dry-run --json
|
|
18
20
|
npx -y replaystage publish ./dist --json
|
|
19
21
|
|
|
20
|
-
# 5.
|
|
22
|
+
# 5. Update metadata/artwork without re-uploading the bundle, or promote to public Lobby
|
|
23
|
+
npx -y replaystage update my-game --json
|
|
21
24
|
npx -y replaystage visibility my-game live --json
|
|
22
25
|
```
|
|
23
26
|
|
package/dist/commands/admin.js
CHANGED
|
@@ -268,8 +268,10 @@ export async function cmdAdmin(args, opts) {
|
|
|
268
268
|
}
|
|
269
269
|
async function probeUrl(label, url) {
|
|
270
270
|
const started = Date.now();
|
|
271
|
+
const controller = new AbortController();
|
|
272
|
+
const timer = setTimeout(() => controller.abort(), 12_000);
|
|
271
273
|
try {
|
|
272
|
-
const res = await fetch(url, { redirect: 'manual' });
|
|
274
|
+
const res = await fetch(url, { redirect: 'manual', signal: controller.signal });
|
|
273
275
|
const ms = Date.now() - started;
|
|
274
276
|
const ok = res.status >= 200 && res.status < 400;
|
|
275
277
|
let extra = '';
|
|
@@ -294,6 +296,9 @@ async function probeUrl(label, url) {
|
|
|
294
296
|
extra: err instanceof Error ? err.message : String(err),
|
|
295
297
|
};
|
|
296
298
|
}
|
|
299
|
+
finally {
|
|
300
|
+
clearTimeout(timer);
|
|
301
|
+
}
|
|
297
302
|
}
|
|
298
303
|
export async function cmdAudit(args, opts) {
|
|
299
304
|
const liveFlag = extractBoolFlag(args, ['--live']);
|
package/dist/commands/auth.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { clearStoredToken, getConfigFilePath, readStoredConfig, requireAuthToken, resolveApiBase, writeStoredConfig, } from '../config.js';
|
|
2
2
|
import { apiRequestJson } from '../http.js';
|
|
3
|
-
import { CliError, assertNoUnknownFlags, emitSuccess, extractFlag, } from '../output.js';
|
|
3
|
+
import { CliError, assertNoUnknownFlags, emitSuccess, extractBoolFlag, extractFlag, } from '../output.js';
|
|
4
|
+
async function readTokenFromStdin() {
|
|
5
|
+
const chunks = [];
|
|
6
|
+
for await (const chunk of process.stdin) {
|
|
7
|
+
chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);
|
|
8
|
+
}
|
|
9
|
+
return Buffer.concat(chunks).toString('utf8').trim();
|
|
10
|
+
}
|
|
4
11
|
export async function cmdLogin(args, opts) {
|
|
5
|
-
const
|
|
12
|
+
const stdinFlag = extractBoolFlag(args, ['--token-stdin']);
|
|
13
|
+
const { value: flagToken, rest } = extractFlag(stdinFlag.rest, ['--token', '-t']);
|
|
6
14
|
assertNoUnknownFlags(rest);
|
|
7
|
-
const token =
|
|
15
|
+
const token = stdinFlag.present
|
|
16
|
+
? await readTokenFromStdin()
|
|
17
|
+
: (flagToken || opts.token || rest[0] || '').trim();
|
|
8
18
|
if (!token) {
|
|
9
|
-
throw new CliError('INVALID_ARGUMENTS', 'Usage: replaystage login --token <RSKEY_...> [--api <url>] [--json]');
|
|
19
|
+
throw new CliError('INVALID_ARGUMENTS', 'Usage: replaystage login --token <RSKEY_...> | --token-stdin [--api <url>] [--json]');
|
|
10
20
|
}
|
|
11
21
|
if (!token.startsWith('RSKEY_') && !token.startsWith('RSSESS_')) {
|
|
12
22
|
throw new CliError('INVALID_TOKEN_FORMAT', 'Expected an account API key starting with "RSKEY_" (mint one at https://studio.replaystage.com/account).');
|
|
@@ -3,6 +3,9 @@ export declare function cmdInit(args: string[], opts: GlobalOptions): Promise<vo
|
|
|
3
3
|
export declare function cmdCreateGame(args: string[], opts: GlobalOptions): Promise<void>;
|
|
4
4
|
export declare function cmdValidate(args: string[], opts: GlobalOptions): Promise<void>;
|
|
5
5
|
export declare function cmdPublish(args: string[], opts: GlobalOptions): Promise<void>;
|
|
6
|
+
export declare function cmdUpdate(args: string[], opts: GlobalOptions): Promise<void>;
|
|
7
|
+
export declare function cmdDelete(args: string[], opts: GlobalOptions): Promise<void>;
|
|
8
|
+
export declare function cmdSdk(args: string[], opts: GlobalOptions): Promise<void>;
|
|
6
9
|
export declare function cmdGames(args: string[], opts: GlobalOptions): Promise<void>;
|
|
7
10
|
export declare function cmdReleases(args: string[], opts: GlobalOptions): Promise<void>;
|
|
8
11
|
export declare function cmdRollback(args: string[], opts: GlobalOptions): Promise<void>;
|
package/dist/commands/creator.js
CHANGED
|
@@ -2,9 +2,9 @@ import { cp, mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises'
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { DEFAULT_PORTAL_ORIGIN, DEFAULT_STUDIO_ORIGIN, findPlatformWorkspaceRoot, requireAuthToken, resolveApiBase, } from '../config.js';
|
|
4
4
|
import { apiRequestJson } from '../http.js';
|
|
5
|
-
import { HEX_COLOR_RE, SLUG_RE, VALID_CREATOR_VISIBILITIES, VALID_GENRES, buildStarterManifest, slugToTitle, writeStarterManifest, } from '../manifest.js';
|
|
5
|
+
import { HEX_COLOR_RE, SLUG_RE, VALID_CREATOR_VISIBILITIES, VALID_GENRES, buildStarterManifest, loadAndValidateManifest, slugToTitle, writeStarterManifest, } from '../manifest.js';
|
|
6
6
|
import { CliError, assertNoUnknownFlags, emitSuccess, extractBoolFlag, extractFlag, } from '../output.js';
|
|
7
|
-
import { validateProjectBundle } from '../validate.js';
|
|
7
|
+
import { discoverMediaFile, validateProjectBundle } from '../validate.js';
|
|
8
8
|
async function exists(targetPath) {
|
|
9
9
|
try {
|
|
10
10
|
await stat(targetPath);
|
|
@@ -52,15 +52,15 @@ export async function cmdInit(args, opts) {
|
|
|
52
52
|
assertNoUnknownFlags(rest);
|
|
53
53
|
const slug = rest[0]?.trim().toLowerCase();
|
|
54
54
|
if (!slug || !SLUG_RE.test(slug) || slug.length < 3 || slug.length > 48) {
|
|
55
|
-
throw new CliError('INVALID_ARGUMENTS', 'Usage: replaystage init <slug> [--dir <path>] [--title "<English>"] [--zh "<中文>"] [--genre arcade|puzzle|mystery|strategy] [--accent "#
|
|
55
|
+
throw new CliError('INVALID_ARGUMENTS', 'Usage: replaystage init <slug> [--dir <path>] [--title "<English>"] [--zh "<中文>"] [--genre arcade|puzzle|mystery|strategy] [--accent "#0F62FE"] [--force]');
|
|
56
56
|
}
|
|
57
57
|
const genre = (genreFlag.value || 'arcade');
|
|
58
58
|
if (!VALID_GENRES.includes(genre)) {
|
|
59
59
|
throw new CliError('INVALID_ARGUMENTS', `Invalid --genre "${genre}". Expected one of: ${VALID_GENRES.join(', ')}`);
|
|
60
60
|
}
|
|
61
|
-
const accentColor = accentFlag.value || '#
|
|
61
|
+
const accentColor = accentFlag.value || '#0F62FE';
|
|
62
62
|
if (!HEX_COLOR_RE.test(accentColor)) {
|
|
63
|
-
throw new CliError('INVALID_ARGUMENTS', `Invalid --accent "${accentColor}". Expected 6-digit hex like "#
|
|
63
|
+
throw new CliError('INVALID_ARGUMENTS', `Invalid --accent "${accentColor}". Expected 6-digit hex like "#0F62FE".`);
|
|
64
64
|
}
|
|
65
65
|
const targetDir = path.resolve(opts.cwd, dirFlag.value || '.');
|
|
66
66
|
await mkdir(targetDir, { recursive: true });
|
|
@@ -173,27 +173,95 @@ export async function cmdCreateGame(args, opts) {
|
|
|
173
173
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
|
174
174
|
<title>${titleEn}</title>
|
|
175
175
|
<style>
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
:root { color-scheme: light dark; --bg: #f4f7fb; --card: #ffffff; --ink: #0f172a; --muted: #475569; --accent: #0f62fe; --accent-ink: #ffffff; }
|
|
177
|
+
:root[data-theme='dark'] { --bg: #0b111b; --card: #111a29; --ink: #f1f5f9; --muted: #94a3b8; --accent: #38bdf8; --accent-ink: #061826; }
|
|
178
|
+
html, body { margin: 0; height: 100dvh; overflow: hidden; touch-action: manipulation; background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, sans-serif; display: grid; place-items: center; }
|
|
179
|
+
main { text-align: center; padding: 24px; width: min(320px, 90vw); background: var(--card); border-radius: 20px; box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12); display: grid; gap: 12px; }
|
|
180
|
+
h1 { margin: 0; font-size: 1.5rem; }
|
|
181
|
+
p { margin: 0; color: var(--muted); }
|
|
182
|
+
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
|
|
183
|
+
button { padding: 12px 20px; border-radius: 11px; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 15px; font-weight: 700; cursor: pointer; }
|
|
184
|
+
button.ghost { background: transparent; color: var(--muted); border: 1px solid color-mix(in oklab, var(--muted) 30%, transparent); }
|
|
185
|
+
[hidden] { display: none !important; }
|
|
179
186
|
</style>
|
|
180
187
|
</head>
|
|
181
188
|
<body>
|
|
182
189
|
<main>
|
|
183
|
-
<h1>${titleEn}</h1>
|
|
190
|
+
<h1 id="title">${titleEn}</h1>
|
|
184
191
|
<p id="score">Score: 0</p>
|
|
185
|
-
<
|
|
192
|
+
<div class="row">
|
|
193
|
+
<button id="start" type="button">Start</button>
|
|
194
|
+
<button id="tap" type="button" hidden>Tap +1</button>
|
|
195
|
+
<button id="pause" type="button" class="ghost" hidden>Pause</button>
|
|
196
|
+
<button id="resume" type="button" hidden>Resume</button>
|
|
197
|
+
<button id="finish" type="button" class="ghost" hidden>Finish</button>
|
|
198
|
+
<button id="share" type="button" class="ghost" hidden>Share</button>
|
|
199
|
+
</div>
|
|
186
200
|
</main>
|
|
187
201
|
<script type="module">
|
|
188
|
-
import {
|
|
202
|
+
import { initReplayStageGame } from 'https://replaystage.com/sdk/v1/replaystage.esm.js';
|
|
203
|
+
const titleMap = { en: ${JSON.stringify(titleEn)}, 'zh-Hans': ${JSON.stringify(titleZh)} };
|
|
189
204
|
let score = 0;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
document.getElementById('
|
|
205
|
+
let playing = false;
|
|
206
|
+
|
|
207
|
+
const elTitle = document.getElementById('title');
|
|
208
|
+
const elScore = document.getElementById('score');
|
|
209
|
+
const btnStart = document.getElementById('start');
|
|
210
|
+
const btnTap = document.getElementById('tap');
|
|
211
|
+
const btnPause = document.getElementById('pause');
|
|
212
|
+
const btnResume = document.getElementById('resume');
|
|
213
|
+
const btnFinish = document.getElementById('finish');
|
|
214
|
+
const btnShare = document.getElementById('share');
|
|
215
|
+
|
|
216
|
+
const rs = initReplayStageGame({
|
|
217
|
+
gameVersion: '1.0.0',
|
|
218
|
+
onLocaleChange: render,
|
|
219
|
+
onThemeChange: theme => { document.documentElement.dataset.theme = theme; },
|
|
220
|
+
onPauseChange: render,
|
|
221
|
+
});
|
|
222
|
+
document.documentElement.dataset.theme = rs.theme;
|
|
223
|
+
|
|
224
|
+
function render() {
|
|
225
|
+
const zh = rs.locale === 'zh-Hans';
|
|
226
|
+
elTitle.textContent = zh ? titleMap['zh-Hans'] : titleMap.en;
|
|
227
|
+
elScore.textContent = (zh ? '得分:' : 'Score: ') + score + (rs.paused ? (zh ? '(已暂停)' : ' (Paused)') : '');
|
|
228
|
+
btnStart.textContent = zh ? '开始游戏' : 'Start';
|
|
229
|
+
btnTap.textContent = zh ? '点按 +1' : 'Tap +1';
|
|
230
|
+
btnPause.textContent = zh ? '暂停' : 'Pause';
|
|
231
|
+
btnResume.textContent = zh ? '继续' : 'Resume';
|
|
232
|
+
btnFinish.textContent = zh ? '结算' : 'Finish';
|
|
233
|
+
btnShare.textContent = zh ? '分享挑战' : 'Share';
|
|
234
|
+
btnStart.hidden = playing;
|
|
235
|
+
btnTap.hidden = !playing || rs.paused;
|
|
236
|
+
btnPause.hidden = !playing || rs.paused;
|
|
237
|
+
btnResume.hidden = !playing || !rs.paused;
|
|
238
|
+
btnFinish.hidden = !playing;
|
|
239
|
+
btnShare.hidden = playing || score <= 0;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
btnStart.addEventListener('click', () => {
|
|
243
|
+
score = 0;
|
|
244
|
+
playing = true;
|
|
245
|
+
rs.gameplayStart();
|
|
246
|
+
render();
|
|
247
|
+
});
|
|
248
|
+
btnTap.addEventListener('click', () => {
|
|
193
249
|
score += 1;
|
|
194
|
-
|
|
195
|
-
|
|
250
|
+
rs.haptics.tap();
|
|
251
|
+
render();
|
|
252
|
+
});
|
|
253
|
+
btnPause.addEventListener('click', () => { rs.pause(); render(); });
|
|
254
|
+
btnResume.addEventListener('click', () => { rs.resume(); render(); });
|
|
255
|
+
btnFinish.addEventListener('click', () => {
|
|
256
|
+
playing = false;
|
|
257
|
+
rs.gameplayStop();
|
|
258
|
+
rs.reportResult({ score, scoreUnit: 'pts', completed: true });
|
|
259
|
+
render();
|
|
260
|
+
});
|
|
261
|
+
btnShare.addEventListener('click', () => {
|
|
262
|
+
rs.shareChallenge({ title: elTitle.textContent + ' — ' + score, score, scoreUnit: 'pts' });
|
|
196
263
|
});
|
|
264
|
+
render();
|
|
197
265
|
</script>
|
|
198
266
|
</body>
|
|
199
267
|
</html>
|
|
@@ -233,6 +301,8 @@ export async function cmdValidate(args, opts) {
|
|
|
233
301
|
rest = manifestFlag.rest;
|
|
234
302
|
const versionFlag = extractFlag(rest, ['--version']);
|
|
235
303
|
rest = versionFlag.rest;
|
|
304
|
+
const strictFlag = extractBoolFlag(rest, ['--strict']);
|
|
305
|
+
rest = strictFlag.rest;
|
|
236
306
|
assertNoUnknownFlags(rest);
|
|
237
307
|
const distDir = rest[0] || 'dist';
|
|
238
308
|
const report = await validateProjectBundle({
|
|
@@ -241,6 +311,16 @@ export async function cmdValidate(args, opts) {
|
|
|
241
311
|
manifestPath: manifestFlag.value,
|
|
242
312
|
versionOverride: versionFlag.value,
|
|
243
313
|
});
|
|
314
|
+
if (strictFlag.present && report.warnings.length > 0) {
|
|
315
|
+
throw new CliError('VALIDATION_WARNINGS', `Strict validation failed with ${report.warnings.length} warning(s). Resolve all warnings or omit --strict.`, {
|
|
316
|
+
details: {
|
|
317
|
+
slug: report.slug,
|
|
318
|
+
version: report.version,
|
|
319
|
+
warnings: report.warnings,
|
|
320
|
+
errors: report.warnings,
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
}
|
|
244
324
|
emitSuccess(opts, {
|
|
245
325
|
slug: report.slug,
|
|
246
326
|
version: report.version,
|
|
@@ -284,6 +364,8 @@ export async function cmdPublish(args, opts) {
|
|
|
284
364
|
rest = hiddenFlag.rest;
|
|
285
365
|
const skipHealthFlag = extractBoolFlag(rest, ['--skip-health']);
|
|
286
366
|
rest = skipHealthFlag.rest;
|
|
367
|
+
const dryRunFlag = extractBoolFlag(rest, ['--dry-run']);
|
|
368
|
+
rest = dryRunFlag.rest;
|
|
287
369
|
assertNoUnknownFlags(rest);
|
|
288
370
|
const selectedVisFlags = [
|
|
289
371
|
visFlag.value,
|
|
@@ -308,6 +390,30 @@ export async function cmdPublish(args, opts) {
|
|
|
308
390
|
manifestPath: manifestFlag.value,
|
|
309
391
|
versionOverride: versionFlag.value,
|
|
310
392
|
});
|
|
393
|
+
if (dryRunFlag.present) {
|
|
394
|
+
emitSuccess(opts, {
|
|
395
|
+
dryRun: true,
|
|
396
|
+
slug: report.slug,
|
|
397
|
+
version: report.version,
|
|
398
|
+
visibility: explicitVisibility ?? 'unlisted (new) / preserve (existing)',
|
|
399
|
+
entryPath: report.entryPath,
|
|
400
|
+
bundle: { fileCount: report.fileCount, totalBytes: report.totalBytes },
|
|
401
|
+
media: report.media.map(m => ({ slot: m.slot, filename: m.filename, bytes: m.bytes })),
|
|
402
|
+
warnings: report.warnings,
|
|
403
|
+
}, () => {
|
|
404
|
+
const lines = [
|
|
405
|
+
`[DRY RUN] Would publish ${report.slug} v${report.version}`,
|
|
406
|
+
` Dist: ${report.distDir} (${report.fileCount} files, ${formatBytes(report.totalBytes)}, entry ${report.entryPath})`,
|
|
407
|
+
` Media: ${report.media.length > 0 ? report.media.map(m => `${m.slot}=${m.filename}`).join(', ') : '(none discovered)'}`,
|
|
408
|
+
` Visibility: ${explicitVisibility ?? 'unlisted (new) / preserve (existing)'}`,
|
|
409
|
+
];
|
|
410
|
+
for (const w of report.warnings) {
|
|
411
|
+
lines.push(` [WARN] ${w}`);
|
|
412
|
+
}
|
|
413
|
+
return lines;
|
|
414
|
+
});
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
311
417
|
const apiBase = await resolveApiBase(opts.apiBase);
|
|
312
418
|
const token = await requireAuthToken({
|
|
313
419
|
flagToken: opts.token,
|
|
@@ -387,13 +493,18 @@ export async function cmdPublish(args, opts) {
|
|
|
387
493
|
// 6. Verify live edge health unless skipped
|
|
388
494
|
let health = null;
|
|
389
495
|
if (!skipHealthFlag.present && releaseRes.origin) {
|
|
496
|
+
const controller = new AbortController();
|
|
497
|
+
const timer = setTimeout(() => controller.abort(), 10_000);
|
|
390
498
|
try {
|
|
391
|
-
const probe = await fetch(`${releaseRes.origin}/_rs/health
|
|
499
|
+
const probe = await fetch(`${releaseRes.origin}/_rs/health`, { signal: controller.signal });
|
|
392
500
|
health = { ok: probe.ok, status: probe.status };
|
|
393
501
|
}
|
|
394
502
|
catch {
|
|
395
503
|
health = { ok: false, status: 0 };
|
|
396
504
|
}
|
|
505
|
+
finally {
|
|
506
|
+
clearTimeout(timer);
|
|
507
|
+
}
|
|
397
508
|
}
|
|
398
509
|
const playUrl = releaseRes.playUrl || `${DEFAULT_PORTAL_ORIGIN}/play/${slug}`;
|
|
399
510
|
const studioUrl = `${DEFAULT_STUDIO_ORIGIN}/games/${slug}`;
|
|
@@ -419,13 +530,178 @@ export async function cmdPublish(args, opts) {
|
|
|
419
530
|
` Game Origin: ${releaseRes.origin}`,
|
|
420
531
|
` Emulator: ${emulatorUrl}`,
|
|
421
532
|
` Bundle: ${report.fileCount} files (${formatBytes(report.totalBytes)})`,
|
|
533
|
+
` Media: ${mediaUploaded.length > 0 ? mediaUploaded.join(', ') : '(none uploaded)'}`,
|
|
422
534
|
];
|
|
423
535
|
if (releaseRes.visibility === 'unlisted') {
|
|
424
536
|
lines.push(` Preview: Unlisted (noindex, direct-link playable). Promote when ready with: replaystage visibility ${slug} live`);
|
|
425
537
|
}
|
|
538
|
+
for (const w of report.warnings) {
|
|
539
|
+
lines.push(` [WARN] ${w}`);
|
|
540
|
+
}
|
|
426
541
|
return lines;
|
|
427
542
|
});
|
|
428
543
|
}
|
|
544
|
+
export async function cmdUpdate(args, opts) {
|
|
545
|
+
let rest = args;
|
|
546
|
+
const manifestFlag = extractFlag(rest, ['--manifest', '-m']);
|
|
547
|
+
rest = manifestFlag.rest;
|
|
548
|
+
const visFlag = extractFlag(rest, ['--visibility']);
|
|
549
|
+
rest = visFlag.rest;
|
|
550
|
+
assertNoUnknownFlags(rest);
|
|
551
|
+
const manifestPath = manifestFlag.value
|
|
552
|
+
? path.resolve(opts.cwd, manifestFlag.value)
|
|
553
|
+
: path.resolve(opts.cwd, 'replaystage.manifest.json');
|
|
554
|
+
const { manifest, manifestPath: resolvedManifestPath } = await loadAndValidateManifest(manifestPath);
|
|
555
|
+
const slug = rest[0]?.trim().toLowerCase() || manifest.slug;
|
|
556
|
+
if (!SLUG_RE.test(slug)) {
|
|
557
|
+
throw new CliError('INVALID_ARGUMENTS', 'Usage: replaystage update [slug] [--manifest <path>] [--visibility live|beta|unlisted|hidden] [--json]');
|
|
558
|
+
}
|
|
559
|
+
if (manifest.slug !== slug) {
|
|
560
|
+
throw new CliError('SLUG_MISMATCH', `Manifest slug "${manifest.slug}" does not match target slug "${slug}".`);
|
|
561
|
+
}
|
|
562
|
+
if (visFlag.value && !VALID_CREATOR_VISIBILITIES.includes(visFlag.value)) {
|
|
563
|
+
throw new CliError('INVALID_ARGUMENTS', `Invalid visibility "${visFlag.value}". Allowed: ${VALID_CREATOR_VISIBILITIES.join(', ')}.`);
|
|
564
|
+
}
|
|
565
|
+
const apiBase = await resolveApiBase(opts.apiBase);
|
|
566
|
+
const token = await requireAuthToken({ flagToken: opts.token, cwd: opts.cwd });
|
|
567
|
+
const repoDir = path.dirname(resolvedManifestPath);
|
|
568
|
+
const mediaUploaded = [];
|
|
569
|
+
for (const slot of ['icon', 'cover']) {
|
|
570
|
+
const discovered = await discoverMediaFile(slot, manifest.artwork[slot], slug, repoDir);
|
|
571
|
+
if (discovered) {
|
|
572
|
+
const bytes = await readFile(discovered.absPath);
|
|
573
|
+
await apiRequestJson({
|
|
574
|
+
apiBase,
|
|
575
|
+
method: 'PUT',
|
|
576
|
+
path: `/v1/publish/${encodeURIComponent(slug)}/media/${encodeURIComponent(discovered.filename)}`,
|
|
577
|
+
token,
|
|
578
|
+
rawBody: bytes,
|
|
579
|
+
contentType: discovered.contentType,
|
|
580
|
+
});
|
|
581
|
+
mediaUploaded.push(`/media/${slug}/${discovered.filename}`);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
const res = await apiRequestJson({
|
|
585
|
+
apiBase,
|
|
586
|
+
method: 'PUT',
|
|
587
|
+
path: `/v1/creator/games/${encodeURIComponent(slug)}`,
|
|
588
|
+
token,
|
|
589
|
+
body: {
|
|
590
|
+
manifest,
|
|
591
|
+
...(visFlag.value ? { visibility: visFlag.value } : {}),
|
|
592
|
+
},
|
|
593
|
+
});
|
|
594
|
+
emitSuccess(opts, {
|
|
595
|
+
slug,
|
|
596
|
+
manifestPath: resolvedManifestPath,
|
|
597
|
+
mediaUploaded,
|
|
598
|
+
game: res.game,
|
|
599
|
+
}, () => [
|
|
600
|
+
`Updated metadata for "${slug}" from ${resolvedManifestPath}`,
|
|
601
|
+
...(mediaUploaded.length > 0 ? [` Media synced: ${mediaUploaded.join(', ')}`] : []),
|
|
602
|
+
]);
|
|
603
|
+
}
|
|
604
|
+
export async function cmdDelete(args, opts) {
|
|
605
|
+
const yesFlag = extractBoolFlag(args, ['--yes', '-y']);
|
|
606
|
+
assertNoUnknownFlags(yesFlag.rest);
|
|
607
|
+
const slug = yesFlag.rest[0]?.trim().toLowerCase();
|
|
608
|
+
if (!slug || !SLUG_RE.test(slug)) {
|
|
609
|
+
throw new CliError('INVALID_ARGUMENTS', 'Usage: replaystage delete <slug> --yes [--json]');
|
|
610
|
+
}
|
|
611
|
+
if (!yesFlag.present) {
|
|
612
|
+
throw new CliError('CONFIRMATION_REQUIRED', `Deleting "${slug}" removes its catalog entry and revokes its CI tokens. Re-run with --yes to confirm.`);
|
|
613
|
+
}
|
|
614
|
+
const apiBase = await resolveApiBase(opts.apiBase);
|
|
615
|
+
const token = await requireAuthToken({ flagToken: opts.token, cwd: opts.cwd });
|
|
616
|
+
const res = await apiRequestJson({
|
|
617
|
+
apiBase,
|
|
618
|
+
method: 'DELETE',
|
|
619
|
+
path: `/v1/creator/games/${encodeURIComponent(slug)}`,
|
|
620
|
+
token,
|
|
621
|
+
});
|
|
622
|
+
emitSuccess(opts, { slug, deleted: res.deleted ?? true }, () => [
|
|
623
|
+
`Deleted "${slug}" and revoked its scoped CI tokens.`,
|
|
624
|
+
]);
|
|
625
|
+
}
|
|
626
|
+
export async function cmdSdk(args, opts) {
|
|
627
|
+
const [sub, ...restArgs] = args;
|
|
628
|
+
if (sub !== 'sync') {
|
|
629
|
+
throw new CliError('INVALID_ARGUMENTS', 'Usage: replaystage sdk sync [targetDir] [--url <sdkBaseUrl>] [--json]');
|
|
630
|
+
}
|
|
631
|
+
const urlFlag = extractFlag(restArgs, ['--url']);
|
|
632
|
+
assertNoUnknownFlags(urlFlag.rest);
|
|
633
|
+
const targetDir = path.resolve(opts.cwd, urlFlag.rest[0] || 'src/sdk');
|
|
634
|
+
await mkdir(targetDir, { recursive: true });
|
|
635
|
+
const workspaceRoot = await findPlatformWorkspaceRoot(opts.cwd);
|
|
636
|
+
let version = 'unknown';
|
|
637
|
+
let source = '';
|
|
638
|
+
let esmContent;
|
|
639
|
+
let dtsContent;
|
|
640
|
+
if (!urlFlag.value && workspaceRoot && (await exists(path.join(workspaceRoot, 'apps', 'portal', 'public', 'sdk', 'v1', 'replaystage.esm.js')))) {
|
|
641
|
+
const localSdkDir = path.join(workspaceRoot, 'apps', 'portal', 'public', 'sdk', 'v1');
|
|
642
|
+
source = localSdkDir;
|
|
643
|
+
const manifestJson = JSON.parse(await readFile(path.join(localSdkDir, 'manifest.json'), 'utf8'));
|
|
644
|
+
version = manifestJson.version ?? 'unknown';
|
|
645
|
+
esmContent = await readFile(path.join(localSdkDir, 'replaystage.esm.js'), 'utf8');
|
|
646
|
+
dtsContent = await readFile(path.join(localSdkDir, 'replaystage.d.ts'), 'utf8');
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
const base = (urlFlag.value || `${DEFAULT_PORTAL_ORIGIN}/sdk/v1`).replace(/\/+$/, '');
|
|
650
|
+
source = base;
|
|
651
|
+
const fetchText = async (url) => {
|
|
652
|
+
const controller = new AbortController();
|
|
653
|
+
const timer = setTimeout(() => controller.abort(), 20_000);
|
|
654
|
+
try {
|
|
655
|
+
const res = await fetch(url, { signal: controller.signal });
|
|
656
|
+
if (!res.ok) {
|
|
657
|
+
throw new CliError('SDK_FETCH_FAILED', `Failed to fetch ${url}: HTTP ${res.status}`, {
|
|
658
|
+
status: res.status,
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
return await res.text();
|
|
662
|
+
}
|
|
663
|
+
catch (err) {
|
|
664
|
+
if (err instanceof CliError)
|
|
665
|
+
throw err;
|
|
666
|
+
throw new CliError('NETWORK_ERROR', `Failed to fetch ${url}: ${err instanceof Error ? err.message : String(err)}`);
|
|
667
|
+
}
|
|
668
|
+
finally {
|
|
669
|
+
clearTimeout(timer);
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
const [manifestRaw, esmRaw, dtsRaw] = await Promise.all([
|
|
673
|
+
fetchText(`${base}/manifest.json`),
|
|
674
|
+
fetchText(`${base}/replaystage.esm.js`),
|
|
675
|
+
fetchText(`${base}/replaystage.d.ts`),
|
|
676
|
+
]);
|
|
677
|
+
const manifestJson = JSON.parse(manifestRaw);
|
|
678
|
+
version = manifestJson.version ?? 'unknown';
|
|
679
|
+
if (manifestJson.sizes?.esmBytes !== undefined &&
|
|
680
|
+
Buffer.byteLength(esmRaw, 'utf8') !== manifestJson.sizes.esmBytes) {
|
|
681
|
+
throw new CliError('SDK_INTEGRITY_MISMATCH', `Downloaded replaystage.esm.js size (${Buffer.byteLength(esmRaw, 'utf8')} B) does not match manifest (${manifestJson.sizes.esmBytes} B).`);
|
|
682
|
+
}
|
|
683
|
+
esmContent = esmRaw;
|
|
684
|
+
dtsContent = dtsRaw;
|
|
685
|
+
}
|
|
686
|
+
const esmPath = path.join(targetDir, 'replaystage.esm.js');
|
|
687
|
+
const dtsPath = path.join(targetDir, 'replaystage.esm.d.ts');
|
|
688
|
+
await Promise.all([
|
|
689
|
+
writeFile(esmPath, esmContent, 'utf8'),
|
|
690
|
+
writeFile(dtsPath, dtsContent, 'utf8'),
|
|
691
|
+
]);
|
|
692
|
+
const esmBytes = Buffer.byteLength(esmContent, 'utf8');
|
|
693
|
+
emitSuccess(opts, {
|
|
694
|
+
version,
|
|
695
|
+
source,
|
|
696
|
+
targetDir,
|
|
697
|
+
files: [esmPath, dtsPath],
|
|
698
|
+
esmBytes,
|
|
699
|
+
}, () => [
|
|
700
|
+
`Synced @replaystage/sdk v${version} (${formatBytes(esmBytes)}) -> ${targetDir}`,
|
|
701
|
+
` ${esmPath}`,
|
|
702
|
+
` ${dtsPath}`,
|
|
703
|
+
]);
|
|
704
|
+
}
|
|
429
705
|
export async function cmdGames(args, opts) {
|
|
430
706
|
assertNoUnknownFlags(args);
|
|
431
707
|
const apiBase = await resolveApiBase(opts.apiBase);
|
package/dist/http.d.ts
CHANGED
|
@@ -6,5 +6,9 @@ export interface ApiRequestOptions {
|
|
|
6
6
|
body?: unknown;
|
|
7
7
|
rawBody?: Uint8Array;
|
|
8
8
|
contentType?: string;
|
|
9
|
+
/** Per-attempt timeout in milliseconds (default: 45s for binary uploads, 25s otherwise). */
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
/** Maximum retries on transient network/timeout/429/5xx errors (default: 2 for idempotent methods, 0 for POST). */
|
|
12
|
+
retries?: number;
|
|
9
13
|
}
|
|
10
14
|
export declare function apiRequestJson<T = Record<string, unknown>>(opts: ApiRequestOptions): Promise<T>;
|
package/dist/http.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { CliError } from './output.js';
|
|
2
|
+
const RETRYABLE_STATUSES = new Set([408, 429, 500, 502, 503, 504]);
|
|
3
|
+
function delay(ms) {
|
|
4
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
5
|
+
}
|
|
6
|
+
function parseRetryAfterMs(header) {
|
|
7
|
+
if (!header)
|
|
8
|
+
return null;
|
|
9
|
+
const seconds = Number(header.trim());
|
|
10
|
+
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
11
|
+
return Math.min(10_000, Math.round(seconds * 1000));
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
2
15
|
export async function apiRequestJson(opts) {
|
|
3
16
|
const headers = {
|
|
4
17
|
Accept: 'application/json',
|
|
@@ -16,54 +29,79 @@ export async function apiRequestJson(opts) {
|
|
|
16
29
|
requestBody = JSON.stringify(opts.body);
|
|
17
30
|
}
|
|
18
31
|
const url = `${opts.apiBase.replace(/\/+$/, '')}${opts.path}`;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
headers,
|
|
24
|
-
body: requestBody,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
throw new CliError('NETWORK_ERROR', `Failed to reach ${url}: ${err instanceof Error ? err.message : String(err)}`);
|
|
29
|
-
}
|
|
30
|
-
const text = await res.text();
|
|
31
|
-
let parsed = {};
|
|
32
|
-
if (text) {
|
|
32
|
+
const timeoutMs = opts.timeoutMs ?? (opts.rawBody !== undefined ? 45_000 : 25_000);
|
|
33
|
+
const maxRetries = opts.retries ?? (opts.method === 'POST' ? 0 : 2);
|
|
34
|
+
for (let attempt = 0; attempt <= maxRetries; attempt += 1) {
|
|
35
|
+
let res;
|
|
33
36
|
try {
|
|
34
|
-
|
|
37
|
+
const controller = new AbortController();
|
|
38
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
39
|
+
try {
|
|
40
|
+
res = await fetch(url, {
|
|
41
|
+
method: opts.method,
|
|
42
|
+
headers,
|
|
43
|
+
body: requestBody,
|
|
44
|
+
signal: controller.signal,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
}
|
|
35
50
|
}
|
|
36
|
-
catch {
|
|
37
|
-
|
|
51
|
+
catch (err) {
|
|
52
|
+
const isTimeout = err instanceof Error && err.name === 'AbortError';
|
|
53
|
+
if (attempt < maxRetries) {
|
|
54
|
+
await delay(350 * 2 ** attempt);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
throw new CliError(isTimeout ? 'REQUEST_TIMEOUT' : 'NETWORK_ERROR', isTimeout
|
|
58
|
+
? `Request timed out after ${timeoutMs}ms: ${opts.method} ${url}`
|
|
59
|
+
: `Failed to reach ${url}: ${err instanceof Error ? err.message : String(err)}`);
|
|
38
60
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const details = {
|
|
54
|
-
method: opts.method,
|
|
55
|
-
path: opts.path,
|
|
56
|
-
};
|
|
57
|
-
if (Array.isArray(parsed.details)) {
|
|
58
|
-
details.errors = parsed.details;
|
|
61
|
+
if (!res.ok && RETRYABLE_STATUSES.has(res.status) && attempt < maxRetries) {
|
|
62
|
+
const retryMs = parseRetryAfterMs(res.headers.get('retry-after')) ?? 350 * 2 ** attempt;
|
|
63
|
+
await delay(retryMs);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const text = await res.text();
|
|
67
|
+
let parsed = {};
|
|
68
|
+
if (text) {
|
|
69
|
+
try {
|
|
70
|
+
parsed = JSON.parse(text);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
parsed = { raw: text };
|
|
74
|
+
}
|
|
59
75
|
}
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
if (!res.ok) {
|
|
77
|
+
const serverCode = typeof parsed.code === 'string' ? parsed.code : undefined;
|
|
78
|
+
const serverError = typeof parsed.error === 'string' ? parsed.error : `HTTP ${res.status}`;
|
|
79
|
+
const mappedCode = serverCode ||
|
|
80
|
+
(res.status === 401
|
|
81
|
+
? 'AUTH_INVALID'
|
|
82
|
+
: res.status === 403
|
|
83
|
+
? 'FORBIDDEN'
|
|
84
|
+
: res.status === 404
|
|
85
|
+
? 'NOT_FOUND'
|
|
86
|
+
: res.status === 409
|
|
87
|
+
? 'CONFLICT'
|
|
88
|
+
: `HTTP_${res.status}`);
|
|
89
|
+
const details = {
|
|
90
|
+
method: opts.method,
|
|
91
|
+
path: opts.path,
|
|
92
|
+
};
|
|
93
|
+
if (Array.isArray(parsed.details)) {
|
|
94
|
+
details.errors = parsed.details;
|
|
95
|
+
}
|
|
96
|
+
else if (parsed.details && typeof parsed.details === 'object') {
|
|
97
|
+
Object.assign(details, parsed.details);
|
|
98
|
+
}
|
|
99
|
+
throw new CliError(mappedCode, serverError, {
|
|
100
|
+
status: res.status,
|
|
101
|
+
details,
|
|
102
|
+
});
|
|
62
103
|
}
|
|
63
|
-
|
|
64
|
-
status: res.status,
|
|
65
|
-
details,
|
|
66
|
-
});
|
|
104
|
+
return parsed;
|
|
67
105
|
}
|
|
68
|
-
|
|
106
|
+
throw new CliError('NETWORK_ERROR', `Failed to complete request to ${url}`);
|
|
69
107
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type OutputStreams } from './output.js';
|
|
2
|
-
export declare const CLI_VERSION
|
|
2
|
+
export declare const CLI_VERSION: string;
|
|
3
3
|
export { CliError } from './output.js';
|
|
4
4
|
export { validateManifestObject, buildStarterManifest } from './manifest.js';
|
|
5
5
|
export { validateProjectBundle } from './validate.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
1
2
|
import { cmdAdmin, cmdAudit, cmdCatalog, cmdDaily } from './commands/admin.js';
|
|
2
3
|
import { cmdLogin, cmdLogout, cmdWhoami } from './commands/auth.js';
|
|
3
|
-
import { cmdCreateGame, cmdGames, cmdInit, cmdPublish, cmdReleases, cmdRollback, cmdStats, cmdTokens, cmdValidate, cmdVisibility, } from './commands/creator.js';
|
|
4
|
+
import { cmdCreateGame, cmdDelete, cmdGames, cmdInit, cmdPublish, cmdReleases, cmdRollback, cmdSdk, cmdStats, cmdTokens, cmdUpdate, cmdValidate, cmdVisibility, } from './commands/creator.js';
|
|
4
5
|
import { CliError, DEFAULT_STREAMS, emitError, emitSuccess, extractBoolFlag, extractFlag, } from './output.js';
|
|
5
|
-
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const pkgJson = require('../package.json');
|
|
8
|
+
export const CLI_VERSION = pkgJson.version ?? '2.1.0';
|
|
6
9
|
export { CliError } from './output.js';
|
|
7
10
|
export { validateManifestObject, buildStarterManifest } from './manifest.js';
|
|
8
11
|
export { validateProjectBundle } from './validate.js';
|
|
@@ -17,15 +20,18 @@ Global Flags:
|
|
|
17
20
|
-v, --version Print CLI version
|
|
18
21
|
|
|
19
22
|
Authentication:
|
|
20
|
-
login --token <RSKEY_> Validate and save personal API key (
|
|
23
|
+
login --token <RSKEY_> Validate and save personal API key (also supports --token-stdin)
|
|
21
24
|
whoami Show authenticated creator identity, role, and scopes
|
|
22
25
|
logout Clear saved local credentials
|
|
23
26
|
|
|
24
27
|
Creator Workflow:
|
|
25
28
|
init <slug> Create starter replaystage.manifest.json in the current directory
|
|
26
29
|
create-game <slug> Scaffold a complete Tier 2 portrait starter game project
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
sdk sync [dir] Download latest @replaystage/sdk ESM bundle & .d.ts into src/sdk
|
|
31
|
+
validate [distDir] Run offline preflight checks (--strict fails on warnings)
|
|
32
|
+
publish [distDir] Upload immutable bundle + media (--dry-run previews without upload)
|
|
33
|
+
update [slug] Sync manifest metadata & artwork without re-uploading bundle
|
|
34
|
+
delete <slug> --yes Delete a game slot and revoke its CI tokens
|
|
29
35
|
games List your registered games
|
|
30
36
|
releases <slug> List immutable release history
|
|
31
37
|
rollback <slug> <ver> Atomically switch live pointer back to a previous version
|
|
@@ -77,8 +83,11 @@ export async function runCli(rawArgs, runtime = {}) {
|
|
|
77
83
|
'logout',
|
|
78
84
|
'init',
|
|
79
85
|
'create-game',
|
|
86
|
+
'sdk',
|
|
80
87
|
'validate',
|
|
81
88
|
'publish',
|
|
89
|
+
'update',
|
|
90
|
+
'delete',
|
|
82
91
|
'games',
|
|
83
92
|
'releases',
|
|
84
93
|
'rollback',
|
|
@@ -109,12 +118,21 @@ export async function runCli(rawArgs, runtime = {}) {
|
|
|
109
118
|
case 'create-game':
|
|
110
119
|
await cmdCreateGame(cmdArgs, opts);
|
|
111
120
|
break;
|
|
121
|
+
case 'sdk':
|
|
122
|
+
await cmdSdk(cmdArgs, opts);
|
|
123
|
+
break;
|
|
112
124
|
case 'validate':
|
|
113
125
|
await cmdValidate(cmdArgs, opts);
|
|
114
126
|
break;
|
|
115
127
|
case 'publish':
|
|
116
128
|
await cmdPublish(cmdArgs, opts);
|
|
117
129
|
break;
|
|
130
|
+
case 'update':
|
|
131
|
+
await cmdUpdate(cmdArgs, opts);
|
|
132
|
+
break;
|
|
133
|
+
case 'delete':
|
|
134
|
+
await cmdDelete(cmdArgs, opts);
|
|
135
|
+
break;
|
|
118
136
|
case 'games':
|
|
119
137
|
await cmdGames(cmdArgs, opts);
|
|
120
138
|
break;
|
package/dist/manifest.js
CHANGED
|
@@ -43,7 +43,7 @@ export function validateManifestObject(raw) {
|
|
|
43
43
|
errors.push(`genre must be one of: ${VALID_GENRES.join(', ')}`);
|
|
44
44
|
}
|
|
45
45
|
if (!isNonEmptyString(m.accentColor) || !HEX_COLOR_RE.test(m.accentColor)) {
|
|
46
|
-
errors.push('accentColor must be a 6-digit hex color (e.g. "#
|
|
46
|
+
errors.push('accentColor must be a 6-digit hex color (e.g. "#0F62FE")');
|
|
47
47
|
}
|
|
48
48
|
if (!isNonEmptyString(m.aspectRatio) || !ASPECT_RATIO_RE.test(m.aspectRatio)) {
|
|
49
49
|
errors.push('aspectRatio must match "<w>:<h>" (e.g. "9:16")');
|
|
@@ -131,7 +131,7 @@ export function buildStarterManifest(options) {
|
|
|
131
131
|
const titleEn = options.titleEn?.trim() || slugToTitle(options.slug);
|
|
132
132
|
const titleZh = options.titleZh?.trim() || titleEn;
|
|
133
133
|
const genre = options.genre ?? 'arcade';
|
|
134
|
-
const accentColor = options.accentColor ?? '#
|
|
134
|
+
const accentColor = options.accentColor ?? '#0F62FE';
|
|
135
135
|
return {
|
|
136
136
|
schemaVersion: 1,
|
|
137
137
|
slug: options.slug,
|
package/dist/output.js
CHANGED
|
@@ -63,7 +63,7 @@ export function extractFlag(args, names) {
|
|
|
63
63
|
for (const name of names) {
|
|
64
64
|
if (arg === name) {
|
|
65
65
|
const next = args[i + 1];
|
|
66
|
-
if (next === undefined || next
|
|
66
|
+
if (next === undefined || /^-[a-zA-Z-]/.test(next)) {
|
|
67
67
|
throw new CliError('INVALID_ARGUMENTS', `Flag "${name}" requires a value.`);
|
|
68
68
|
}
|
|
69
69
|
value = next;
|
package/dist/validate.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export interface ValidationReport {
|
|
|
30
30
|
warnings: string[];
|
|
31
31
|
manifest: ReplayStageManifest;
|
|
32
32
|
}
|
|
33
|
+
export declare function discoverMediaFile(slot: 'icon' | 'cover', artworkUrl: string, slug: string, repoDir: string, distDir?: string): Promise<DiscoveredMediaItem | null>;
|
|
33
34
|
export declare function validateProjectBundle(options: {
|
|
34
35
|
cwd: string;
|
|
35
36
|
distDir?: string;
|
package/dist/validate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readdir, stat } from 'node:fs/promises';
|
|
1
|
+
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { loadAndValidateManifest } from './manifest.js';
|
|
4
4
|
import { CliError } from './output.js';
|
|
@@ -56,7 +56,7 @@ async function fileExists(target) {
|
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
async function discoverMediaFile(slot, artworkUrl, slug, repoDir, distDir) {
|
|
59
|
+
export async function discoverMediaFile(slot, artworkUrl, slug, repoDir, distDir) {
|
|
60
60
|
// Expected format: `/media/<slug>/<filename>` (or direct local path)
|
|
61
61
|
const expectedPrefix = `/media/${slug}/`;
|
|
62
62
|
let filename = '';
|
|
@@ -81,8 +81,9 @@ async function discoverMediaFile(slot, artworkUrl, slug, repoDir, distDir) {
|
|
|
81
81
|
path.join(repoDir, 'media', filename),
|
|
82
82
|
path.join(repoDir, 'public', filename),
|
|
83
83
|
path.join(repoDir, filename),
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
...(distDir
|
|
85
|
+
? [path.join(distDir, 'media', slug, filename), path.join(distDir, filename)]
|
|
86
|
+
: []),
|
|
86
87
|
];
|
|
87
88
|
for (const candidate of candidates) {
|
|
88
89
|
if (await fileExists(candidate)) {
|
|
@@ -168,17 +169,45 @@ export async function validateProjectBundle(options) {
|
|
|
168
169
|
}
|
|
169
170
|
await walk(resolvedDistDir, '');
|
|
170
171
|
const normalizedEntry = manifest.runtime.entryPath.replace(/^\/+/, '') || 'index.html';
|
|
171
|
-
const
|
|
172
|
-
if (!
|
|
172
|
+
const entryItem = files.find(f => f.relPath === normalizedEntry);
|
|
173
|
+
if (!entryItem) {
|
|
173
174
|
throw new CliError('ENTRY_MISSING', `Entry file "${normalizedEntry}" (from runtime.entryPath) was not found inside ${resolvedDistDir}.`, { details: { entryPath: normalizedEntry, distDir: resolvedDistDir } });
|
|
174
175
|
}
|
|
176
|
+
// Static entry HTML sanity checks (catch common blank-screen & bridge security mistakes early)
|
|
177
|
+
try {
|
|
178
|
+
const entryHtml = await readFile(entryItem.absPath, 'utf8');
|
|
179
|
+
if (/https?:\/\/(?:localhost|127\.0\.0\.1)(?::\d+)?/i.test(entryHtml)) {
|
|
180
|
+
warnings.push(`Entry "${normalizedEntry}" references a localhost/127.0.0.1 URL — replace dev URLs before publishing.`);
|
|
181
|
+
}
|
|
182
|
+
if (/postMessage\s*\([^)]*,\s*['"]\*['"]\s*\)/.test(entryHtml)) {
|
|
183
|
+
warnings.push(`Entry "${normalizedEntry}" uses wildcard postMessage(..., '*') — use @replaystage/sdk for strict origin checks.`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
// non-fatal if entry cannot be decoded as UTF-8
|
|
188
|
+
}
|
|
189
|
+
if (manifest.runtime.originSlug !== manifest.slug) {
|
|
190
|
+
warnings.push(`runtime.originSlug ("${manifest.runtime.originSlug}") differs from slug ("${manifest.slug}").`);
|
|
191
|
+
}
|
|
192
|
+
if (manifest.locales.en.tagline.includes('in an instant portrait stage.') ||
|
|
193
|
+
manifest.locales['zh-Hans'].tagline.includes('在竖屏舞台点开即玩')) {
|
|
194
|
+
warnings.push('Manifest still contains starter placeholder tagline copy — replace with real bilingual copy before going live.');
|
|
195
|
+
}
|
|
175
196
|
const media = [];
|
|
176
197
|
const iconMedia = await discoverMediaFile('icon', manifest.artwork.icon, manifest.slug, repoDir, resolvedDistDir);
|
|
177
|
-
if (iconMedia)
|
|
198
|
+
if (iconMedia) {
|
|
178
199
|
media.push(iconMedia);
|
|
200
|
+
}
|
|
201
|
+
else if (!manifest.artwork.icon.startsWith('http://') && !manifest.artwork.icon.startsWith('https://')) {
|
|
202
|
+
warnings.push(`Artwork "icon" (${manifest.artwork.icon}) was not found locally — add public/media/${manifest.slug}/${path.basename(manifest.artwork.icon)} so lobby cards render cleanly.`);
|
|
203
|
+
}
|
|
179
204
|
const coverMedia = await discoverMediaFile('cover', manifest.artwork.cover, manifest.slug, repoDir, resolvedDistDir);
|
|
180
|
-
if (coverMedia)
|
|
205
|
+
if (coverMedia) {
|
|
181
206
|
media.push(coverMedia);
|
|
207
|
+
}
|
|
208
|
+
else if (!manifest.artwork.cover.startsWith('http://') && !manifest.artwork.cover.startsWith('https://')) {
|
|
209
|
+
warnings.push(`Artwork "cover" (${manifest.artwork.cover}) was not found locally — add public/media/${manifest.slug}/${path.basename(manifest.artwork.cover)} so lobby cards render cleanly.`);
|
|
210
|
+
}
|
|
182
211
|
const version = options.versionOverride?.trim() || manifest.version;
|
|
183
212
|
return {
|
|
184
213
|
slug: manifest.slug,
|
package/package.json
CHANGED