1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-01-31 20:15:25 +01:00
upscayl/scripts/validate-schema.js

37 lines
1.0 KiB
JavaScript
Raw Normal View History

2024-12-15 14:25:18 +05:30
const Ajv = require("ajv");
const path = require("path");
const fs = require("fs");
const { generateSchema } = require("./generate-schema");
const ajv = new Ajv();
console.log("Validating language files...");
// Load the base language file (en.json)
const enJsonPath = path.join(__dirname, "..", "renderer", "locales", "en.json");
const enJson = JSON.parse(fs.readFileSync(enJsonPath, "utf-8"));
// Generate the schema for en.json
const enSchema = generateSchema(enJson);
const validate = ajv.compile(enSchema);
// Validate other language files
const localesDir = path.join(__dirname, "..", "renderer", "locales");
const languageFiles = fs
.readdirSync(localesDir)
.filter((file) => file !== "en.json");
languageFiles.forEach((file) => {
const filePath = path.join(localesDir, file);
const jsonData = JSON.parse(fs.readFileSync(filePath, "utf-8"));
const valid = validate(jsonData);
if (!valid) {
console.error(`Errors in ${file}:`);
console.error(validate.errors);
} else {
console.log(`${file} is valid.`);
}
});