mkmrare/convert.ts

37 lines
812 B
TypeScript
Raw Normal View History

2019-11-21 15:56:34 +00:00
import { existsSync } from "fs";
2019-11-21 14:16:04 +00:00
import { asyncLoadJSON, asyncSaveJSON } from "./utils";
interface JSONCard {
mcmId: number;
2019-11-21 15:56:34 +00:00
set: string;
2019-11-21 14:16:04 +00:00
}
interface JSONSet {
cards: JSONCard[];
}
type JSONDB = Record<string, JSONSet>;
async function run() {
2019-11-21 15:56:34 +00:00
if (!existsSync("AllPrintings.json")) {
console.error(
"AllPrintings.json not found. Download from: https://www.mtgjson.com/files/AllPrintings.json"
);
process.exit(1);
}
console.info("Loading AllPrintings.json");
2019-11-21 14:16:04 +00:00
const db = await asyncLoadJSON<JSONDB>("AllPrintings.json");
let acc = {};
for (const set in db) {
2019-11-21 15:56:34 +00:00
db[set].cards.forEach(c => {
c.set = set;
acc[c.mcmId] = c;
});
2019-11-21 14:16:04 +00:00
}
asyncSaveJSON("mcmCards.json", acc);
2019-11-21 15:56:34 +00:00
console.info("Saved converted info to mcmCards.json. You're ready to go!");
2019-11-21 14:16:04 +00:00
}
run();