-
Notifications
You must be signed in to change notification settings - Fork 6
/
imageCheck.ts
76 lines (67 loc) · 2.47 KB
/
imageCheck.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* In order to run this script, use Node 16 and convert it to js with `tsc`
*/
import * as fs from 'fs';
import * as chalk from 'chalk';
import { listOfPokemon } from './src/utils/listOfPokemon';
const targetFile = `./images.md`;
const buildFile: string[] = [];
const alphabet: string[] = [];
let exists = 0;
const normalize = (str: string) => str.toLowerCase().replace(/\s/g, '-');
const toPercentage = (num, den) => `${((num / den) * 100).toFixed(0)}%`;
function missingByGeneration(list) {
const generationPoints = [
{ start: 0, end: 151 },
{ start: 151, end: 251 },
{ start: 251, end: 386 },
{ start: 386, end: 493 },
{ start: 493, end: 649 },
{ start: 649, end: 721 },
{ start: 721, end: 807 },
{ start: 808, end: 905 },
{ start: 906, end: 1008 }
];
const resultMap = generationPoints.map((point, idx) => {
const generationList = list.slice(point.start, point.end);
const total = point.end - point.start;
let generationTotal = 0;
const generationMissing: string[] = [];
for (const pokemon of generationList) {
if (fs.existsSync(`src/img/${normalize(pokemon)}.jpg`)) {
generationTotal += 1;
} else {
generationMissing.push(pokemon);
}
}
return `${(chalk as any).blue(`[Gen ${idx + 1}]`)}: ${(chalk as any).yellow(
`${generationTotal}/${total}`,
)} ${(chalk as any).red(toPercentage(generationTotal, total))}, missing: ${
generationMissing.length === 0 ? 'none' : generationMissing.join(', ')
}\n`;
});
console.log(resultMap.join('\n'));
}
console.log(`Checking for images...`);
const pokemonList = [...listOfPokemon].sort();
for (const pokemon of pokemonList) {
if (!alphabet.includes(pokemon.charAt(0))) {
alphabet.push(pokemon.charAt(0));
buildFile.push(`## ${pokemon.charAt(0)}`);
}
if (fs.existsSync(`src/img/${normalize(pokemon)}.jpg`)) {
buildFile.push(`- [x] ${pokemon}`);
exists++;
} else {
buildFile.push(`- [ ] ${pokemon}`);
}
}
fs.writeFile(targetFile, buildFile.join('\n'), (err) => {
if (err) throw new Error('Failed to write file.');
console.log(
`Wrote ${targetFile} file with ${exists}/${listOfPokemon.length} ${(chalk as any).green(
toPercentage(exists, listOfPokemon.length),
)} entries.`,
);
});
missingByGeneration(listOfPokemon);