mkmrare/cmd/convert.ts

37 lines
811 B
TypeScript
Raw Normal View History

2019-11-21 15:56:34 +00:00
import { existsSync } from "fs";
2019-11-21 16:06:46 +00:00
import { asyncLoadJSON, asyncSaveJSON } from "../lib";
2019-11-21 14:16:04 +00:00
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();