@netmind/arena-cli 0.32.1 → 0.32.2
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.js +17 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2316,12 +2316,28 @@ var META_TYPES = ["weekly-arena", "general"];
|
|
|
2316
2316
|
var ALIAS_MAP = {
|
|
2317
2317
|
"ftg-tournament": "ftg"
|
|
2318
2318
|
};
|
|
2319
|
+
async function readMarkdown(fetchImpl, url) {
|
|
2320
|
+
const res = await fetchImpl(url);
|
|
2321
|
+
if (!res.ok) return null;
|
|
2322
|
+
const text = await res.text();
|
|
2323
|
+
return text.trimStart().startsWith("<!") ? null : text;
|
|
2324
|
+
}
|
|
2325
|
+
async function fetchRules(type, fetchImpl = fetch) {
|
|
2326
|
+
const fetchType = ALIAS_MAP[type] ?? type;
|
|
2327
|
+
const frontendUrl = process.env.ARENA_FRONTEND_URL || DEFAULT_FRONTEND_URL;
|
|
2328
|
+
const builtIn = await readMarkdown(fetchImpl, `${frontendUrl}/games/${fetchType}.md`);
|
|
2329
|
+
if (builtIn !== null) return builtIn;
|
|
2330
|
+
const catalog = await readMarkdown(fetchImpl, `${getApiUrl()}/products/${encodeURIComponent(type)}/guide.md`);
|
|
2331
|
+
if (catalog !== null) return catalog;
|
|
2332
|
+
throw new Error(`Unknown game type: ${type}. Run 'arena rules' to see available types.`);
|
|
2333
|
+
}
|
|
2319
2334
|
var rulesCmd2 = new Command11("rules").description("Show game rules for a specific game type").argument("[type]", "Game type (e.g. debate, forum, stock-prediction)").action(async (type) => {
|
|
2320
2335
|
if (!type) {
|
|
2321
2336
|
console.log("Available game types:");
|
|
2322
2337
|
for (const t of GAME_TYPES) {
|
|
2323
2338
|
console.log(` ${t}`);
|
|
2324
2339
|
}
|
|
2340
|
+
console.log("\nGames from the product catalog (e.g. othello, gomoku, liars-dice) work too.");
|
|
2325
2341
|
console.log("\nUsage: arena rules <type>");
|
|
2326
2342
|
return;
|
|
2327
2343
|
}
|
|
@@ -2331,18 +2347,8 @@ var rulesCmd2 = new Command11("rules").description("Show game rules for a specif
|
|
|
2331
2347
|
);
|
|
2332
2348
|
return;
|
|
2333
2349
|
}
|
|
2334
|
-
const fetchType = ALIAS_MAP[type] ?? type;
|
|
2335
2350
|
try {
|
|
2336
|
-
|
|
2337
|
-
const url = `${frontendUrl}/games/${fetchType}.md`;
|
|
2338
|
-
const res = await fetch(url);
|
|
2339
|
-
const text = await res.text();
|
|
2340
|
-
if (!res.ok || text.trimStart().startsWith("<!")) {
|
|
2341
|
-
throw new Error(
|
|
2342
|
-
`Unknown game type: ${type}. Run 'arena rules' to see available types.`
|
|
2343
|
-
);
|
|
2344
|
-
}
|
|
2345
|
-
console.log(text);
|
|
2351
|
+
console.log(await fetchRules(type));
|
|
2346
2352
|
} catch (e) {
|
|
2347
2353
|
printError(e.message);
|
|
2348
2354
|
process.exit(1);
|