import * as yargs from "yargs"; import { readCardFile, toURL } from "./genurls"; import { existsSync, readFileSync } from "fs"; yargs .scriptName("mtgetk") .usage("$0 [args]") .command( "genurl", "Generate card images", yargs => yargs .positional("input", { type: "string", alias: "i", default: "in.json", describe: "Input JSON file generated by decode.py" }) .positional("cookie", { type: "string", alias: "c", default: "cookie.txt", describe: "File contaning cookie data (required for requesting images)" }) .positional("only-url", { type: "boolean", alias: "u", default: false, describe: "Only generate URLs" }), argv => { let generateImages = !argv["only-url"]; let cookie = ""; if (generateImages) { if (!existsSync(argv.cookie)) { console.warn( "Cookie file not specified or invalid, will generate URLs instead of images" ); generateImages = false; } else { const cookieFile = readFileSync(argv.cookie); cookie = cookieFile.toString(); } } else { console.warn("Not generating images"); } const cards = readCardFile(argv.input); console.log(`Loaded ${cards.length} cards`); const urls = cards.map((c, i) => toURL(c, { set: "RNG", num: i, total: cards.length }) ); if (generateImages) { //TODO } else { urls.forEach((u, i) => console.log(`${cards[i].name}:\n${u}\n`)); } } ).argv;