* web: update to ESLint 9 ESLint 9 has been out for awhile now, and all of the plug-ins that we use have caught up, so it is time to bite the bullet and upgrade. This commit: - upgrades to ESLint 9, and upgrades all associated plugins - Replaces the `.eslintrc` and `.eslintignore` files with the new, "flat" configuration file, "eslint.config.mjs". - Places the previous "precommit" and "nightmare" rules in `./scripts/eslint.precommit.mjs` and `./scripts/eslint.nightmare.mjs`, respectively - Replaces the scripted wrappers for eslint (`eslint`, `eslint-precommit`) with a single executable that takes the arguments `--precommit`, which applies a stricter set of rules, and `--nightmare`, which applies an even more terrifyingly strict set of rules. - Provides the scripted wrapper `./scripts/eslint.mjs` so that eslint can be run from `bun`, if one so chooses. - Fixes *all* of the lint `eslint.config.mjs` now finds, including removing all of the `eslint` styling rules and overrides because Eslint now proudly leaves that entirely up to Prettier. To shut Dependabot up about ESLint. * Added explanation for no-console removal. * web: did not need the old and unmaintained nightmare mode; it can be configured directly.
67 lines
2.2 KiB
JavaScript
67 lines
2.2 KiB
JavaScript
import { spawnSync } from "child_process";
|
|
import fs from "fs";
|
|
import path from "path";
|
|
import process from "process";
|
|
|
|
const localizeRules = JSON.parse(fs.readFileSync("./lit-localize.json", "utf-8"));
|
|
|
|
function generatedFileIsUpToDateWithXliffSource(loc) {
|
|
const xliff = path.join("./xliff", `${loc}.xlf`);
|
|
const gened = path.join("./src/locales", `${loc}.ts`);
|
|
|
|
// Returns false if: the expected XLF file doesn't exist, The expected
|
|
// generated file doesn't exist, or the XLF file is newer (has a higher date)
|
|
// than the generated file. The missing XLF file is important enough it
|
|
// generates a unique error message and halts the build.
|
|
|
|
try {
|
|
var xlfStat = fs.statSync(xliff);
|
|
} catch (_error) {
|
|
console.error(`lit-localize expected '${loc}.xlf', but XLF file is not present`);
|
|
process.exit(1);
|
|
}
|
|
|
|
// If the generated file doesn't exist, of course it's not up to date.
|
|
try {
|
|
var genedStat = fs.statSync(gened);
|
|
} catch (_error) {
|
|
return false;
|
|
}
|
|
|
|
// if the generated file is the same age or older (date is greater) than the xliff file, it's
|
|
// presumed to have been generated by that file and is up-to-date.
|
|
return genedStat.mtimeMs >= xlfStat.mtimeMs;
|
|
}
|
|
|
|
// For all the expected files, find out if any aren't up-to-date.
|
|
|
|
const upToDate = localizeRules.targetLocales.reduce(
|
|
(acc, loc) => acc && generatedFileIsUpToDateWithXliffSource(loc),
|
|
true,
|
|
);
|
|
|
|
if (!upToDate) {
|
|
const status = spawnSync("npm", ["run", "build-locales:build"], { encoding: "utf8" });
|
|
|
|
// Count all the missing message warnings
|
|
const counts = status.stderr.split("\n").reduce((acc, line) => {
|
|
const match = /^([\w-]+) message/.exec(line);
|
|
if (!match) {
|
|
return acc;
|
|
}
|
|
acc.set(match[1], (acc.get(match[1]) || 0) + 1);
|
|
return acc;
|
|
}, new Map());
|
|
|
|
const locales = Array.from(counts.keys());
|
|
locales.sort();
|
|
|
|
const report = locales
|
|
.map((locale) => `Locale '${locale}' has ${counts.get(locale)} missing translations`)
|
|
.join("\n");
|
|
|
|
console.log(`Translation tables rebuilt.\n${report}\n`);
|
|
}
|
|
|
|
console.log("Locale ./src is up-to-date");
|