UNPKG

@intlayer/unmerged-dictionaries-entry

Version:

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

32 lines (30 loc) 1.33 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); let node_fs = require("node:fs"); let node_path = require("node:path"); let _intlayer_config_built = require("@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: _intlayer_config_built.system, build: _intlayer_config_built.build }) => { const { system: system$1 } = configuration; const { unmergedDictionariesDir } = system$1; const dictionaries = {}; if ((0, node_fs.existsSync)(unmergedDictionariesDir)) { const files = (0, node_fs.readdirSync)(unmergedDictionariesDir).filter((file) => file.endsWith(".json")); for (const file of files) { const key = (0, node_path.basename)(file, (0, node_path.extname)(file)); const content = (0, node_fs.readFileSync)((0, node_path.join)(unmergedDictionariesDir, file), "utf-8"); dictionaries[key] = JSON.parse(content); } } return dictionaries; }; //#endregion exports.getUnmergedDictionaries = getUnmergedDictionaries; //# sourceMappingURL=index.cjs.map