{"version":3,"file":"createDictionaryEntryPoint.mjs","names":[],"sources":["../../../src/createDictionaryEntryPoint/createDictionaryEntryPoint.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { parallelize } from '../utils/parallelize';\nimport { writeFileIfChanged } from '../writeFileIfChanged';\nimport { generateDictionaryListContent } from './generateDictionaryListContent';\nimport { getBuiltDictionariesPath } from './getBuiltDictionariesPath';\nimport { getBuiltDynamicDictionariesPath } from './getBuiltDynamicDictionariesPath';\nimport { getBuiltFetchDictionariesPath } from './getBuiltFetchDictionariesPath';\nimport { getBuiltRemoteDictionariesPath } from './getBuiltRemoteDictionariesPath';\nimport { getBuiltUnmergedDictionariesPath } from './getBuiltUnmergedDictionariesPath';\n\nconst writeDictionaryFiles = async (\n  paths: Promise<string[]>,\n  fileName: string,\n  importType: 'json' | 'javascript',\n  functionName: string,\n  format: 'cjs' | 'esm',\n  configuration = getConfiguration()\n) => {\n  const resolvedPath = await paths;\n\n  const content = generateDictionaryListContent(\n    resolvedPath,\n    functionName,\n    importType,\n    format,\n    configuration\n  );\n  const extension = format === 'cjs' ? 'cjs' : 'mjs';\n\n  const { mainDir } = configuration.system;\n\n  await writeFileIfChanged(\n    resolve(mainDir, `${fileName}.${extension}`),\n    content\n  );\n};\n\nexport type CreateDictionaryEntryPointOptions = {\n  formats?: ('cjs' | 'esm')[];\n  excludeKeys?: string[];\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryEntryPoint = async (\n  configuration = getConfiguration(),\n  options: CreateDictionaryEntryPointOptions = {}\n) => {\n  const { formats, excludeKeys = [] } = options;\n  const outputFormats = formats ?? configuration.build.outputFormat;\n  const { mainDir } = configuration.system;\n\n  await mkdir(mainDir, { recursive: true });\n\n  const writeOperations = [\n    ...outputFormats.map(\n      (format) =>\n        ({\n          paths: getBuiltDictionariesPath(configuration, excludeKeys),\n          importType: 'json',\n          functionName: 'getDictionaries',\n          fileName: 'dictionaries' as const,\n          format,\n        }) as const\n    ),\n    ...outputFormats.map(\n      (format) =>\n        ({\n          paths: getBuiltUnmergedDictionariesPath(configuration, excludeKeys),\n          importType: 'json',\n          functionName: 'getUnmergedDictionaries',\n          fileName: 'unmerged_dictionaries' as const,\n          format,\n        }) as const\n    ),\n    ...outputFormats.map(\n      (format) =>\n        ({\n          paths: getBuiltDynamicDictionariesPath(\n            configuration,\n            format,\n            excludeKeys\n          ),\n          importType: 'javascript',\n          functionName: 'getDynamicDictionaries',\n          fileName: 'dynamic_dictionaries' as const,\n          format,\n        }) as const\n    ),\n    ...outputFormats.map(\n      (format) =>\n        ({\n          paths: getBuiltFetchDictionariesPath(\n            configuration,\n            format,\n            excludeKeys\n          ),\n          importType: 'javascript',\n          functionName: 'getFetchDictionaries',\n          fileName: 'fetch_dictionaries' as const,\n          format,\n        }) as const\n    ),\n    ...outputFormats.map(\n      (format) =>\n        ({\n          paths: getBuiltRemoteDictionariesPath(configuration, excludeKeys),\n          importType: 'json',\n          functionName: 'getRemoteDictionaries',\n          fileName: 'remote_dictionaries' as const,\n          format,\n        }) as const\n    ),\n  ];\n\n  await parallelize(\n    writeOperations,\n    async ({ paths, fileName, format, functionName, importType }) =>\n      await writeDictionaryFiles(\n        paths,\n        fileName,\n        importType,\n        functionName,\n        format,\n        configuration\n      )\n  );\n};\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAM,uBAAuB,OAC3B,OACA,UACA,YACA,cACA,QACA,gBAAgB,iBAAiB,MAC9B;CAGH,MAAM,UAAU,8BACd,MAHyB,OAIzB,cACA,YACA,QACA,aACF;CACA,MAAM,YAAY,WAAW,QAAQ,QAAQ;CAE7C,MAAM,EAAE,YAAY,cAAc;CAElC,MAAM,mBACJ,QAAQ,SAAS,GAAG,SAAS,GAAG,WAAW,GAC3C,OACF;AACF;;;;AAUA,MAAa,6BAA6B,OACxC,gBAAgB,iBAAiB,GACjC,UAA6C,CAAC,MAC3C;CACH,MAAM,EAAE,SAAS,cAAc,CAAC,MAAM;CACtC,MAAM,gBAAgB,WAAW,cAAc,MAAM;CACrD,MAAM,EAAE,YAAY,cAAc;CAElC,MAAM,MAAM,SAAS,EAAE,WAAW,KAAK,CAAC;CA+DxC,MAAM,YACJ;EA7DA,GAAG,cAAc,KACd,YACE;GACC,OAAO,yBAAyB,eAAe,WAAW;GAC1D,YAAY;GACZ,cAAc;GACd,UAAU;GACV;EACF,EACJ;EACA,GAAG,cAAc,KACd,YACE;GACC,OAAO,iCAAiC,eAAe,WAAW;GAClE,YAAY;GACZ,cAAc;GACd,UAAU;GACV;EACF,EACJ;EACA,GAAG,cAAc,KACd,YACE;GACC,OAAO,gCACL,eACA,QACA,WACF;GACA,YAAY;GACZ,cAAc;GACd,UAAU;GACV;EACF,EACJ;EACA,GAAG,cAAc,KACd,YACE;GACC,OAAO,8BACL,eACA,QACA,WACF;GACA,YAAY;GACZ,cAAc;GACd,UAAU;GACV;EACF,EACJ;EACA,GAAG,cAAc,KACd,YACE;GACC,OAAO,+BAA+B,eAAe,WAAW;GAChE,YAAY;GACZ,cAAc;GACd,UAAU;GACV;EACF,EACJ;CAIc,GACd,OAAO,EAAE,OAAO,UAAU,QAAQ,cAAc,iBAC9C,MAAM,qBACJ,OACA,UACA,YACA,cACA,QACA,aACF,CACJ;AACF"}