UNPKG

@intlayer/chokidar

Version:

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

43 lines (41 loc) 2.14 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const require_runtime = require('../_virtual/_rolldown/runtime.cjs'); const require_utils_getPathHash = require('../utils/getPathHash.cjs'); let node_path = require("node:path"); let _intlayer_config_node = require("@intlayer/config/node"); let _intlayer_config_utils = require("@intlayer/config/utils"); //#region src/createDictionaryEntryPoint/generateDictionaryListContent.ts /** * This function generates the content of the dictionary list file */ const generateDictionaryListContent = (dictionaries, functionName, importType, format = "esm", configuration = (0, _intlayer_config_node.getConfiguration)()) => { const { mainDir } = configuration.system; let content = ""; const dictionariesRef = dictionaries.map((dictionaryPath) => ({ relativePath: (0, _intlayer_config_utils.normalizePath)((0, node_path.relative)(mainDir, dictionaryPath)), id: (0, node_path.basename)(dictionaryPath, (0, node_path.extname)(dictionaryPath)), hash: `_${require_utils_getPathHash.getPathHash(dictionaryPath)}` })); dictionariesRef.forEach((dictionary) => { if (format === "esm") content += `import ${dictionary.hash} from '${dictionary.relativePath}'${importType === "json" ? " with { type: 'json' }" : ""};\n`; if (format === "cjs") content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\n`; }); content += "\n"; const formattedDictionaryMap = dictionariesRef.map((dictionary) => ` "${dictionary.id}": ${dictionary.hash}`).join(",\n"); content += `const dictionaries = {\n${formattedDictionaryMap}\n};\n`; content += `const ${functionName} = () => dictionaries;\n`; if (format === "esm") { content += `\n`; content += `export { ${functionName} };\n`; content += `export default dictionaries;\n`; } if (format === "cjs") { content += `\n`; content += `module.exports.${functionName} = ${functionName};\n`; content += `module.exports = dictionaries;\n`; } return content; }; //#endregion exports.generateDictionaryListContent = generateDictionaryListContent; //# sourceMappingURL=generateDictionaryListContent.cjs.map