Skip to content

Commit

Permalink
clean up convert script
Browse files Browse the repository at this point in the history
fix lint and remove MISSING after it was deleted in 3636d19
  • Loading branch information
scheibo committed Aug 27, 2024
1 parent 652db3e commit 50b3c1b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions stats/convert
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ try {
const fs = require('fs/promises');
const path = require('path');

const stats = require('./build');
const {Dex, toID} = require('@pkmn/dex');
const gens = stats.newGenerations(Dex);
const stringify = require('json-stringify-pretty-compact');

const stats = require('./build');

const gens = stats.newGenerations(Dex);

const MONTH = /^\d{4}-\d{2}$/;
const UNSUPPORTED = ['1v1', 'challengecup1vs1'];

Expand Down Expand Up @@ -70,8 +72,7 @@ async function convert(month, out, split) {
for (const file of await fs.readdir(month)) {
if (!file.endsWith('txt')) continue;
const base = file.slice(0, -4); // .txt
if (MISSING[path.basename(month)]?.includes(base)) continue; // sigh
const [format, cutoff] = base.split('-')
const [format, cutoff] = base.split('-');
try {
await fs.mkdir(path.join(out, format), {mode: 0o755});
} catch (err) {
Expand Down Expand Up @@ -117,7 +118,8 @@ async function write(out, gen, dir, base, split) {
// NOTE: deliberately limiting concurrency to avoid opening too many files
await fs.writeFile(
path.join(out, `${toID(pokemon)}.json`),
JSON.stringify(display.pokemon[pokemon]));
JSON.stringify(display.pokemon[pokemon]),
);
}
} else {
return fs.writeFile(`${out}.json`, stringify(display));
Expand All @@ -128,4 +130,4 @@ function usage(msg) {
if (msg) console.error(msg);
console.error(`Usage: convert <path/to/input> <path/to/output> [--split]`);
process.exit(1);
}
}

0 comments on commit 50b3c1b

Please sign in to comment.