41 lines
892 B
TypeScript
41 lines
892 B
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
|
|
const LANG_MAP: Record<string, string> = {
|
|
english: "en",
|
|
italian: "it",
|
|
german: "de",
|
|
french: "fr",
|
|
spanish: "es",
|
|
};
|
|
|
|
const POS_MAP: Record<string, string> = {
|
|
nouns: "noun",
|
|
verbs: "verb",
|
|
adverbs: "adverb",
|
|
adjectives: "adjective",
|
|
};
|
|
|
|
/**
|
|
* Creates the base JSON file with word, language, and pos.
|
|
* No logging — the orchestrator handles all console output.
|
|
*/
|
|
export function createBaseJson(
|
|
word: string,
|
|
outputDir: string,
|
|
rawLanguage: string,
|
|
rawPos: string,
|
|
): void {
|
|
const targetFilePath = path.join(outputDir, `${word}.json`);
|
|
|
|
const dbLanguage = LANG_MAP[rawLanguage] || rawLanguage;
|
|
const dbPos = POS_MAP[rawPos] || rawPos;
|
|
|
|
const initialData = { word, language: dbLanguage, pos: dbPos };
|
|
|
|
fs.writeFileSync(
|
|
targetFilePath,
|
|
JSON.stringify(initialData, null, 2),
|
|
"utf-8",
|
|
);
|
|
}
|