import { readFileSync, readdirSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { join } from "node:path"; const root = fileURLToPath(new URL("../", import.meta.url)); const flatten = (value, prefix = "") => Object.entries(value).flatMap(([key, v]) => typeof v === "object" ? flatten(v, `${prefix}${key}.`) : [`${prefix}${key}`], ); const locales = ["en", "ru", "es"].map((code) => JSON.parse(readFileSync(join(root, `i18n/locales/${code}.json`), "utf8")), ); const expected = flatten(locales[0]).sort(); for (let i = 1; i < locales.length; i++) if (JSON.stringify(flatten(locales[i]).sort()) !== JSON.stringify(expected)) throw Error("Locale key mismatch"); const files = (path) => readdirSync(path, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() ? files(join(path, entry.name)) : [join(path, entry.name)], ); for (const file of [ ...files(join(root, "pages")), ...files(join(root, "components")), join(root, "app.vue"), ]) { for (const match of readFileSync(file, "utf8").matchAll( /\b(?:\$t|t)\(['"]([\w.]+)['"]/g, )) if (!expected.includes(match[1])) throw Error(`${file}: Missing ${match[1]}`); } console.log( `${expected.length} keys match in en/ru/es; static template keys verified.`, );