Check repository tools with community lint

This commit is contained in:
vorotamoroz
2026-07-27 09:07:20 +00:00
parent 2b95766d4f
commit f1e382c6ed
10 changed files with 151 additions and 98 deletions
+11 -10
View File
@@ -1,29 +1,30 @@
// Convert Human-Editable format (YAML) to Application convenient Message Resources (JSON)
import { readFile, writeFile } from "fs/promises";
import { join, resolve } from "path";
import { parse } from "yaml";
import { glob } from "tinyglobby";
import { objectToDotted } from "./messagelib";
const fsPromises = process.getBuiltinModule("node:fs/promises");
const path = process.getBuiltinModule("node:path");
const __dirname = import.meta.dirname;
const targetDir = resolve(join(__dirname, "../src/common/messagesYAML/"));
console.log(`Target directory: ${targetDir}`);
const targetDir = path.resolve(path.join(__dirname, "../src/common/messagesYAML/"));
process.stdout.write(`Target directory: ${targetDir}\n`);
const files = await glob(`*.yaml`, { expandDirectories: false, absolute: true, cwd: targetDir });
for (const file of files) {
const filePath = resolve(file);
const content = await readFile(filePath, "utf-8");
const jsonDataSrc = parse(content);
const filePath = path.resolve(file);
const content = await fsPromises.readFile(filePath, "utf-8");
const jsonDataSrc: unknown = parse(content);
const jsonDataD2 = objectToDotted(jsonDataSrc);
const jsonData = Object.fromEntries(
Object.entries(jsonDataD2)
.map(([key, value]) => [key.endsWith("._value") ? key.slice(0, -7) : key, value])
.map(([key, value]): [string, unknown] => [key.endsWith("._value") ? key.slice(0, -7) : key, value])
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
);
const yamlData = JSON.stringify(jsonData, null, 4) + "\n";
const yamlFilePath = filePath.replace(/\.yaml$/, ".json").replace("YAML", "Json");
await writeFile(yamlFilePath, yamlData, "utf-8");
console.log(`Converted ${filePath} to ${yamlFilePath}`);
await fsPromises.writeFile(yamlFilePath, yamlData, "utf-8");
process.stdout.write(`Converted ${filePath} to ${yamlFilePath}\n`);
}
// console.dir(files, { depth: 0 });