UNPKG

@intlayer/unmerged-dictionaries-entry

Version:

Provides the entry path for Intlayer dictionaries, solving filesystem retrieval issues for bundlers like Webpack and Rollup.

31 lines (29 loc) 1.13 kB
import { existsSync, readFileSync, readdirSync } from "node:fs"; import { basename, extname, join } from "node:path"; import { build, system } from "@intlayer/config/built"; //#region src/index.ts /** * @intlayer/unmerged-dictionaries-entry is a package that only returns the unmerged dictionary entry file. * Using an external package allow to alias it in the bundle configuration (such as webpack). * The alias allow hot reload the app (such as nextjs) on any dictionary change. */ const getUnmergedDictionaries = (configuration = { system, build }) => { const { system: system$1 } = configuration; const { unmergedDictionariesDir } = system$1; const dictionaries = {}; if (existsSync(unmergedDictionariesDir)) { const files = readdirSync(unmergedDictionariesDir).filter((file) => file.endsWith(".json")); for (const file of files) { const key = basename(file, extname(file)); const content = readFileSync(join(unmergedDictionariesDir, file), "utf-8"); dictionaries[key] = JSON.parse(content); } } return dictionaries; }; //#endregion export { getUnmergedDictionaries }; //# sourceMappingURL=index.mjs.map