UNPKG

@intlayer/chokidar

Version:

Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.

28 lines 1.1 kB
import { mkdir, writeFile } from "fs/promises"; import { resolve } from "path"; import { getConfiguration } from "@intlayer/config"; const { content } = getConfiguration(); const { reactIntlMessagesDir } = content; const writeDictionary = async (dictionariesDeclaration) => { const resultDictionariesPaths = []; for (const [nameSpace, localContent] of Object.entries( dictionariesDeclaration )) { for await (const [locale, content2] of Object.entries(localContent)) { const contentString = JSON.stringify(content2); const outputFileName = `${nameSpace}.json`; const resultDirPath = resolve(reactIntlMessagesDir, locale); const resultFilePath = resolve(resultDirPath, outputFileName); await mkdir(resultDirPath, { recursive: true }); await writeFile(resultFilePath, contentString, "utf8").catch((err) => { console.error(`Error creating ${outputFileName}:`, err); }); resultDictionariesPaths.push(resultFilePath); } } return resultDictionariesPaths; }; export { writeDictionary }; //# sourceMappingURL=writeDictionary.mjs.map