UNPKG

@intlayer/chokidar

Version:

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

23 lines 1.01 kB
import { writeFile } from "fs/promises"; import { resolve } from "path"; import { getConfiguration } from "@intlayer/config"; const writeDictionary = async (dictionaries, configuration = getConfiguration()) => { const { dictionariesDir } = configuration.content; const resultDictionariesPaths = []; for await (const dictionaryContent of dictionaries) { const isDevelopment = process.env.NODE_ENV === "development"; const contentString = isDevelopment ? JSON.stringify(dictionaryContent, null, 2) : JSON.stringify(dictionaryContent); const key = dictionaryContent.key; const outputFileName = `${key}.json`; const resultFilePath = resolve(dictionariesDir, outputFileName); await writeFile(resultFilePath, contentString, "utf8").catch((err) => { console.error(`Error creating ${outputFileName}:`, err); }); resultDictionariesPaths.push(resultFilePath); } return resultDictionariesPaths; }; export { writeDictionary }; //# sourceMappingURL=writeDictionary.mjs.map