Add script for finding duplicate entries

This commit is contained in:
mtkennerly 2022-10-06 16:50:00 +08:00
parent 891ca12890
commit 6fc21111aa
No known key found for this signature in database
GPG key ID: E764BE00BE6E6408
3 changed files with 32 additions and 0 deletions

View file

@ -8,3 +8,6 @@ trim_trailing_whitespace = true
[*.{json,md,yaml,yml}]
indent_size = 2
[data/wiki-game-cache.yaml]
trim_trailing_whitespace = false

View file

@ -12,6 +12,7 @@
"schema:normal": "ajv validate -s ./data/schema.yaml -d ./data/manifest.yaml",
"schema:strict": "ajv validate -s ./data/schema.strict.yaml -d ./data/manifest.yaml",
"stats": "ts-node ./src/bin.ts --stats",
"duplicates": "ts-node ./src/bin.ts --duplicates",
"steam": "ts-node ./src/bin.ts --steam"
},
"devDependencies": {

View file

@ -10,6 +10,7 @@ interface Cli {
wiki?: boolean,
manifest?: boolean,
stats?: boolean,
duplicates?: boolean,
all?: boolean,
irregularPathUntagged?: boolean,
skipUntil?: string,
@ -52,6 +53,33 @@ async function main() {
process.exit(0);
}
if (args.duplicates) {
const data: {[key: string]: Array<{ name: string; pageId: number }>} = {};
for (const [name, info] of Object.entries(manifest.data)) {
const key = JSON.stringify(info);
let safe = false;
for (const file of Object.keys(info.files ?? {})) {
if (file.includes("<game>") || file.includes("<base>")) {
safe = true;
}
}
if (safe) {
continue;
}
if (!(key in data)) {
data[key] = [];
}
data[key].push({ name, pageId: wikiCache.data[name]?.pageId ?? 0 });
}
for (const games of Object.values(data)) {
if (games.length > 1) {
const lines = games.map(({ name, pageId }) => `[${pageId}] ${name}`);
console.log(`\nSame manifest entry:\n - ${lines.join("\n - ")}`);
}
}
process.exit(0);
}
try {
if (args.wiki) {
if (args.recent) {