{"version":3,"file":"generateDictionaryListContent.mjs","names":[],"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,gBAAgB,kBAAkB,KACvB;CACX,MAAM,EAAE,YAAY,cAAc;CAElC,IAAI,UAAU;CAEd,MAAM,kBAAkB,aAAa,KAAK,oBAAoB;EAC5D,cAAc,cAAc,SAAS,SAAS,eAAe,CAAC;EAC9D,IAAI,SAAS,gBAAgB,QAAQ,eAAe,CAAC;EACrD,MAAM,IAAI,YAAY,eAAe;EACtC,EAAE;AAEH,iBAAgB,SAAS,eAAe;AACtC,MAAI,WAAW,MACb,YAAW,UAAU,WAAW,KAAK,SAAS,WAAW,aAAa,GAAG,eAAe,SAAS,2BAA2B,GAAG;AACjI,MAAI,WAAW,MACb,YAAW,SAAS,WAAW,KAAK,cAAc,WAAW,aAAa;GAC5E;AAEF,YAAW;CAGX,MAAM,yBAAiC,gBACpC,KAAK,eAAe,MAAM,WAAW,GAAG,KAAK,WAAW,OAAO,CAC/D,KAAK,MAAM;AAEd,YAAW,2BAA2B,uBAAuB;AAC7D,YAAW,SAAS,aAAa;AAEjC,KAAI,WAAW,OAAO;AACpB,aAAW;AACX,aAAW,YAAY,aAAa;AACpC,aAAW;;AAGb,KAAI,WAAW,OAAO;AACpB,aAAW;AACX,aAAW,kBAAkB,aAAa,KAAK,aAAa;AAC5D,aAAW;;AAGb,QAAO"}