{"version":3,"file":"generateDictionaryListContent.cjs","names":["getPathHash"],"sources":["../../../src/createDictionaryEntryPoint/generateDictionaryListContent.ts"],"sourcesContent":["import { basename, extname, relative } from 'node:path';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { normalizePath } from '@intlayer/config/utils';\nimport { getPathHash } from '../utils/getPathHash';\n\n/**\n * This function generates the content of the dictionary list file\n */\nexport const generateDictionaryListContent = (\n  dictionaries: string[],\n  functionName: string,\n  importType: 'json' | 'javascript',\n  format: 'cjs' | 'esm' = 'esm',\n  configuration = getConfiguration()\n): string => {\n  const { mainDir } = configuration.system;\n\n  let content = '';\n\n  const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n    relativePath: normalizePath(relative(mainDir, dictionaryPath)),\n    id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n    hash: `_${getPathHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n  }));\n\n  dictionariesRef.forEach((dictionary) => {\n    if (format === 'esm')\n      content += `import ${dictionary.hash} from '${dictionary.relativePath}'${importType === 'json' ? \" with { type: 'json' }\" : ''};\\n`;\n    if (format === 'cjs')\n      content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n  });\n\n  content += '\\n';\n\n  // Format Dictionary Map\n  const formattedDictionaryMap: string = dictionariesRef\n    .map((dictionary) => `  \"${dictionary.id}\": ${dictionary.hash}`)\n    .join(',\\n');\n\n  content += `const dictionaries = {\\n${formattedDictionaryMap}\\n};\\n`;\n  content += `const ${functionName} = () => dictionaries;\\n`;\n\n  if (format === 'esm') {\n    content += `\\n`;\n    content += `export { ${functionName} };\\n`;\n    content += `export default dictionaries;\\n`;\n  }\n\n  if (format === 'cjs') {\n    content += `\\n`;\n    content += `module.exports.${functionName} = ${functionName};\\n`;\n    content += `module.exports = dictionaries;\\n`;\n  }\n\n  return content;\n};\n"],"mappings":";;;;;;;;;;;AAQA,MAAa,iCACX,cACA,cACA,YACA,SAAwB,OACxB,4DAAiC,MACtB;CACX,MAAM,EAAE,YAAY,cAAc;CAElC,IAAI,UAAU;CAEd,MAAM,kBAAkB,aAAa,KAAK,oBAAoB;EAC5D,gFAAqC,SAAS,cAAc,CAAC;EAC7D,4BAAa,uCAAwB,cAAc,CAAC;EACpD,MAAM,IAAIA,sCAAY,cAAc;CACtC,EAAE;CAEF,gBAAgB,SAAS,eAAe;EACtC,IAAI,WAAW,OACb,WAAW,UAAU,WAAW,KAAK,SAAS,WAAW,aAAa,GAAG,eAAe,SAAS,2BAA2B,GAAG;EACjI,IAAI,WAAW,OACb,WAAW,SAAS,WAAW,KAAK,cAAc,WAAW,aAAa;CAC9E,CAAC;CAED,WAAW;CAGX,MAAM,yBAAiC,gBACpC,KAAK,eAAe,MAAM,WAAW,GAAG,KAAK,WAAW,MAAM,EAC9D,KAAK,KAAK;CAEb,WAAW,2BAA2B,uBAAuB;CAC7D,WAAW,SAAS,aAAa;CAEjC,IAAI,WAAW,OAAO;EACpB,WAAW;EACX,WAAW,YAAY,aAAa;EACpC,WAAW;CACb;CAEA,IAAI,WAAW,OAAO;EACpB,WAAW;EACX,WAAW,kBAAkB,aAAa,KAAK,aAAa;EAC5D,WAAW;CACb;CAEA,OAAO;AACT"}