e1ba3fe1b9
- Scrapers scripts/fetch_open5e.ts (classes/races/backgrounds/feats, CC-BY/OGL) and fetch_foundry_pf2e.ts (25 PF2e classes, OGL/ORC) → normalized JSON in src/data/srd + public/data/pf2e/classes.json. - src/lib/ruleset/normalize.ts: pure, tested normalizers → unified RulesetClass (hit die, key abilities, saves/ranks, perception, skills, caster, subclasses, profs). - compendium loaders (loadClasses/loadRaces5e/loadBackgrounds5e) + a "Classes" tab for both systems (ClassDetail) with full stats; Bestiary stays the default category. - Data-source attribution in Settings. Feeds the Phase 5 builder. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
/* Scrape Foundry VTT pf2e class packs (OGL/ORC + Paizo Community Use) →
|
|
* normalized JSON in public/data/pf2e/classes.json.
|
|
* Run: bunx tsx scripts/fetch_foundry_pf2e.ts */
|
|
import { writeFileSync } from 'node:fs';
|
|
import { normalizeFoundryClass, type FoundryClass } from '../src/lib/ruleset/normalize';
|
|
|
|
const LIST = 'https://api.github.com/repos/foundryvtt/pf2e/contents/packs/classes?ref=master';
|
|
|
|
async function main() {
|
|
const res = await fetch(LIST, { headers: { 'User-Agent': 'ttrpg-manager-scraper', Accept: 'application/vnd.github+json' } });
|
|
if (!res.ok) throw new Error(`list: ${res.status}`);
|
|
const files = (await res.json()) as { name: string; download_url: string }[];
|
|
const classFiles = files.filter((f) => f.name.endsWith('.json'));
|
|
|
|
const out = [];
|
|
for (const f of classFiles) {
|
|
const raw = (await (await fetch(f.download_url)).json()) as FoundryClass;
|
|
out.push(normalizeFoundryClass(f.name.replace(/\.json$/, ''), raw));
|
|
}
|
|
out.sort((a, b) => a.name.localeCompare(b.name));
|
|
writeFileSync('public/data/pf2e/classes.json', JSON.stringify(out));
|
|
console.log(`pf2e: classes ${out.length} (${out.map((c) => c.name).join(', ')})`);
|
|
}
|
|
|
|
main().catch((e) => { console.error(e); process.exit(1); });
|