{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/generateDictionaryListContent.ts"],"sourcesContent":["import { getConfiguration, normalizePath } from '@intlayer/config';\nimport { basename, extname, relative } from 'path';\nimport { getFileHash } from '../../utils/getFileHash';\n\n/**\n * This function generates the content of the dictionary list file\n */\nexport const generateDictionaryListContent = (\n  dictionaries: string[],\n  format: 'cjs' | 'esm' = 'esm',\n  configuration = getConfiguration()\n): string => {\n  const { mainDir } = configuration.content;\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: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n  }));\n\n  // Import all dictionaries\n  dictionariesRef.forEach((dictionary) => {\n    if (format === 'esm')\n      content += `import ${dictionary.hash} from '${dictionary.relativePath}' 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  if (format === 'esm')\n    content += `export default {\\n${formattedDictionaryMap}\\n};\\n`;\n  if (format === 'cjs')\n    content += `module.exports = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n  return content;\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,qBAAqB;AAChD,SAAS,UAAU,SAAS,gBAAgB;AAC5C,SAAS,mBAAmB;AAKrB,MAAM,gCAAgC,CAC3C,cACA,SAAwB,OACxB,gBAAgB,iBAAiB,MACtB;AACX,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,MAAI,UAAU;AAEd,QAAM,kBAAkB,aAAa,IAAI,CAAC,oBAAoB;AAAA,IAC5D,cAAc,cAAc,SAAS,SAAS,cAAc,CAAC;AAAA,IAC7D,IAAI,SAAS,gBAAgB,QAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,IAAI,YAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,QAAI,WAAW;AACb,iBAAW,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AACvE,QAAI,WAAW;AACb,iBAAW,SAAS,WAAW,IAAI,eAAe,WAAW,YAAY;AAAA;AAAA,EAC7E,CAAC;AAED,aAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,MAAM,WAAW,EAAE,MAAM,WAAW,IAAI,EAAE,EAC9D,KAAK,KAAK;AAEb,MAAI,WAAW;AACb,eAAW;AAAA,EAAqB,sBAAsB;AAAA;AAAA;AACxD,MAAI,WAAW;AACb,eAAW;AAAA,EAAuB,sBAAsB;AAAA;AAAA;AAE1D,SAAO;AACT;","names":[]}