From 6fc21111aa958321fd346057231d05eb68f933b2 Mon Sep 17 00:00:00 2001 From: mtkennerly Date: Thu, 6 Oct 2022 16:50:00 +0800 Subject: [PATCH] Add script for finding duplicate entries --- .editorconfig | 3 +++ package.json | 1 + src/bin.ts | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/.editorconfig b/.editorconfig index 7f17c6dd..5b3c69f7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,3 +8,6 @@ trim_trailing_whitespace = true [*.{json,md,yaml,yml}] indent_size = 2 + +[data/wiki-game-cache.yaml] +trim_trailing_whitespace = false diff --git a/package.json b/package.json index f39bb98a..af4923c8 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/bin.ts b/src/bin.ts index aa30c095..55bf3391 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -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("") || file.includes("")) { + 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) {