@intlayer/chokidar 5.8.1-canary.0 → 6.0.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/dist/cjs/chokidar/watcher.cjs +15 -20
  2. package/dist/cjs/chokidar/watcher.cjs.map +1 -1
  3. package/dist/cjs/fetchDistantDictionaries.cjs +18 -37
  4. package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
  5. package/dist/cjs/{fetchDistantDictionaryKeys.cjs → fetchDistantDictionaryKeysAndUpdateTimestamp.cjs} +10 -10
  6. package/dist/cjs/fetchDistantDictionaryKeysAndUpdateTimestamp.cjs.map +1 -0
  7. package/dist/cjs/filterInvalidDictionaries.cjs +70 -0
  8. package/dist/cjs/filterInvalidDictionaries.cjs.map +1 -0
  9. package/dist/cjs/getBuiltFetchDictionariesPath.cjs +52 -0
  10. package/dist/cjs/getBuiltFetchDictionariesPath.cjs.map +1 -0
  11. package/dist/cjs/getBuiltRemoteDictionariesPath.cjs +51 -0
  12. package/dist/cjs/getBuiltRemoteDictionariesPath.cjs.map +1 -0
  13. package/dist/cjs/index.cjs +10 -11
  14. package/dist/cjs/index.cjs.map +1 -1
  15. package/dist/cjs/loadDictionaries/index.cjs +4 -4
  16. package/dist/cjs/loadDictionaries/index.cjs.map +1 -1
  17. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +57 -17
  18. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
  19. package/dist/cjs/loadDictionaries/loadDictionaries.cjs +128 -53
  20. package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
  21. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +101 -0
  22. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -0
  23. package/dist/cjs/loadDictionaries/log.cjs +144 -0
  24. package/dist/cjs/loadDictionaries/log.cjs.map +1 -0
  25. package/dist/cjs/mergeDictionaries.cjs +18 -22
  26. package/dist/cjs/mergeDictionaries.cjs.map +1 -1
  27. package/dist/cjs/orderDictionaries.cjs +71 -0
  28. package/dist/cjs/orderDictionaries.cjs.map +1 -0
  29. package/dist/cjs/prepareContentDeclaration.cjs +4 -1
  30. package/dist/cjs/prepareContentDeclaration.cjs.map +1 -1
  31. package/dist/cjs/prepareIntlayer.cjs +9 -4
  32. package/dist/cjs/prepareIntlayer.cjs.map +1 -1
  33. package/dist/cjs/processPerLocaleDictionary.cjs.map +1 -1
  34. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs +22 -8
  35. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs.map +1 -1
  36. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.cjs +44 -42
  37. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.cjs.map +1 -1
  38. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.cjs +83 -0
  39. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.cjs.map +1 -0
  40. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.cjs +29 -21
  41. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.cjs.map +1 -1
  42. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.cjs +52 -0
  43. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.cjs.map +1 -0
  44. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.cjs +44 -29
  45. package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.cjs.map +1 -1
  46. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs +39 -34
  47. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +1 -1
  48. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +4 -6
  49. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
  50. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +17 -16
  51. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -1
  52. package/dist/cjs/utils/formatter.cjs +50 -0
  53. package/dist/cjs/utils/formatter.cjs.map +1 -0
  54. package/dist/cjs/utils/parallelize.cjs +43 -0
  55. package/dist/cjs/utils/parallelize.cjs.map +1 -0
  56. package/dist/cjs/utils/runOnce.cjs +2 -1
  57. package/dist/cjs/utils/runOnce.cjs.map +1 -1
  58. package/dist/cjs/writeContentDeclaration/formatCode.cjs +7 -4
  59. package/dist/cjs/writeContentDeclaration/formatCode.cjs.map +1 -1
  60. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +5 -1
  61. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
  62. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +43 -25
  63. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
  64. package/dist/esm/chokidar/watcher.mjs +16 -21
  65. package/dist/esm/chokidar/watcher.mjs.map +1 -1
  66. package/dist/esm/fetchDistantDictionaries.mjs +24 -28
  67. package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
  68. package/dist/esm/{fetchDistantDictionaryKeys.mjs → fetchDistantDictionaryKeysAndUpdateTimestamp.mjs} +6 -6
  69. package/dist/esm/fetchDistantDictionaryKeysAndUpdateTimestamp.mjs.map +1 -0
  70. package/dist/esm/filterInvalidDictionaries.mjs +40 -0
  71. package/dist/esm/filterInvalidDictionaries.mjs.map +1 -0
  72. package/dist/esm/getBuiltFetchDictionariesPath.mjs +18 -0
  73. package/dist/esm/getBuiltFetchDictionariesPath.mjs.map +1 -0
  74. package/dist/esm/getBuiltRemoteDictionariesPath.mjs +17 -0
  75. package/dist/esm/getBuiltRemoteDictionariesPath.mjs.map +1 -0
  76. package/dist/esm/index.mjs +8 -9
  77. package/dist/esm/index.mjs.map +1 -1
  78. package/dist/esm/loadDictionaries/index.mjs +2 -2
  79. package/dist/esm/loadDictionaries/index.mjs.map +1 -1
  80. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +61 -18
  81. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
  82. package/dist/esm/loadDictionaries/loadDictionaries.mjs +132 -53
  83. package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
  84. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +66 -0
  85. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -0
  86. package/dist/esm/loadDictionaries/log.mjs +125 -0
  87. package/dist/esm/loadDictionaries/log.mjs.map +1 -0
  88. package/dist/esm/mergeDictionaries.mjs +19 -23
  89. package/dist/esm/mergeDictionaries.mjs.map +1 -1
  90. package/dist/esm/orderDictionaries.mjs +37 -0
  91. package/dist/esm/orderDictionaries.mjs.map +1 -0
  92. package/dist/esm/prepareContentDeclaration.mjs +4 -1
  93. package/dist/esm/prepareContentDeclaration.mjs.map +1 -1
  94. package/dist/esm/prepareIntlayer.mjs +9 -4
  95. package/dist/esm/prepareIntlayer.mjs.map +1 -1
  96. package/dist/esm/processPerLocaleDictionary.mjs.map +1 -1
  97. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs +25 -9
  98. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -1
  99. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs +45 -43
  100. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs.map +1 -1
  101. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs +58 -0
  102. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs.map +1 -0
  103. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs +29 -21
  104. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs.map +1 -1
  105. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs +28 -0
  106. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs.map +1 -0
  107. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs +45 -30
  108. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs.map +1 -1
  109. package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +39 -34
  110. package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
  111. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +4 -6
  112. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
  113. package/dist/esm/transpiler/dictionary_to_type/createType.mjs +17 -16
  114. package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
  115. package/dist/esm/utils/formatter.mjs +15 -0
  116. package/dist/esm/utils/formatter.mjs.map +1 -0
  117. package/dist/esm/utils/parallelize.mjs +9 -0
  118. package/dist/esm/utils/parallelize.mjs.map +1 -0
  119. package/dist/esm/utils/runOnce.mjs +2 -1
  120. package/dist/esm/utils/runOnce.mjs.map +1 -1
  121. package/dist/esm/writeContentDeclaration/formatCode.mjs +8 -5
  122. package/dist/esm/writeContentDeclaration/formatCode.mjs.map +1 -1
  123. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +5 -1
  124. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
  125. package/dist/esm/writeContentDeclaration/writeJSFile.mjs +40 -22
  126. package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
  127. package/dist/types/chokidar/watcher.d.ts.map +1 -1
  128. package/dist/types/fetchDistantDictionaries.d.ts +2 -1
  129. package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
  130. package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts +3 -0
  131. package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts.map +1 -0
  132. package/dist/types/filterInvalidDictionaries.d.ts +3 -0
  133. package/dist/types/filterInvalidDictionaries.d.ts.map +1 -0
  134. package/dist/types/getBuiltFetchDictionariesPath.d.ts +5 -0
  135. package/dist/types/getBuiltFetchDictionariesPath.d.ts.map +1 -0
  136. package/dist/types/getBuiltRemoteDictionariesPath.d.ts +5 -0
  137. package/dist/types/getBuiltRemoteDictionariesPath.d.ts.map +1 -0
  138. package/dist/types/index.d.ts +3 -4
  139. package/dist/types/index.d.ts.map +1 -1
  140. package/dist/types/loadDictionaries/index.d.ts +2 -2
  141. package/dist/types/loadDictionaries/index.d.ts.map +1 -1
  142. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +4 -1
  143. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
  144. package/dist/types/loadDictionaries/loadDictionaries.d.ts +11 -1
  145. package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
  146. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +6 -0
  147. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -0
  148. package/dist/types/loadDictionaries/log.d.ts +19 -0
  149. package/dist/types/loadDictionaries/log.d.ts.map +1 -0
  150. package/dist/types/mergeDictionaries.d.ts +1 -1
  151. package/dist/types/mergeDictionaries.d.ts.map +1 -1
  152. package/dist/types/orderDictionaries.d.ts +10 -0
  153. package/dist/types/orderDictionaries.d.ts.map +1 -0
  154. package/dist/types/prepareContentDeclaration.d.ts.map +1 -1
  155. package/dist/types/prepareIntlayer.d.ts.map +1 -1
  156. package/dist/types/processPerLocaleDictionary.d.ts +1 -1
  157. package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +1 -0
  158. package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts.map +1 -1
  159. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +4 -3
  160. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +1 -1
  161. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts +1 -1
  162. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts.map +1 -1
  163. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts +23 -0
  164. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts.map +1 -0
  165. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts +1 -1
  166. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts.map +1 -1
  167. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts +19 -0
  168. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts.map +1 -0
  169. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.d.ts.map +1 -1
  170. package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts +1 -1
  171. package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts.map +1 -1
  172. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +1 -1
  173. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts.map +1 -1
  174. package/dist/types/transpiler/dictionary_to_type/createType.d.ts +1 -1
  175. package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +1 -1
  176. package/dist/types/utils/formatter.d.ts +4 -0
  177. package/dist/types/utils/formatter.d.ts.map +1 -0
  178. package/dist/types/utils/parallelize.d.ts +2 -0
  179. package/dist/types/utils/parallelize.d.ts.map +1 -0
  180. package/dist/types/utils/runOnce.d.ts +1 -1
  181. package/dist/types/utils/runOnce.d.ts.map +1 -1
  182. package/dist/types/writeContentDeclaration/formatCode.d.ts.map +1 -1
  183. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +1 -1
  184. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
  185. package/dist/types/writeContentDeclaration/writeJSFile.d.ts +1 -1
  186. package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -1
  187. package/package.json +19 -17
  188. package/dist/cjs/checkDictionaryChanges.cjs +0 -58
  189. package/dist/cjs/checkDictionaryChanges.cjs.map +0 -1
  190. package/dist/cjs/fetchDistantDictionaryKeys.cjs.map +0 -1
  191. package/dist/cjs/getFilteredLocalesContent.cjs +0 -70
  192. package/dist/cjs/getFilteredLocalesContent.cjs.map +0 -1
  193. package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs +0 -44
  194. package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs.map +0 -1
  195. package/dist/cjs/log.cjs +0 -296
  196. package/dist/cjs/log.cjs.map +0 -1
  197. package/dist/esm/checkDictionaryChanges.mjs +0 -37
  198. package/dist/esm/checkDictionaryChanges.mjs.map +0 -1
  199. package/dist/esm/fetchDistantDictionaryKeys.mjs.map +0 -1
  200. package/dist/esm/getFilteredLocalesContent.mjs +0 -49
  201. package/dist/esm/getFilteredLocalesContent.mjs.map +0 -1
  202. package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs +0 -20
  203. package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs.map +0 -1
  204. package/dist/esm/log.mjs +0 -262
  205. package/dist/esm/log.mjs.map +0 -1
  206. package/dist/types/checkDictionaryChanges.d.ts +0 -3
  207. package/dist/types/checkDictionaryChanges.d.ts.map +0 -1
  208. package/dist/types/fetchDistantDictionaryKeys.d.ts +0 -3
  209. package/dist/types/fetchDistantDictionaryKeys.d.ts.map +0 -1
  210. package/dist/types/getFilteredLocalesContent.d.ts +0 -4
  211. package/dist/types/getFilteredLocalesContent.d.ts.map +0 -1
  212. package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts +0 -8
  213. package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts.map +0 -1
  214. package/dist/types/log.d.ts +0 -45
  215. package/dist/types/log.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.ts"],"sourcesContent":["import { getConfiguration, normalizePath } from '@intlayer/config';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { relative, resolve } from 'path';\nimport { parallelize } from '../../../utils/parallelize';\nimport type {\n LocalizedDictionaryOutput,\n LocalizedDictionaryResult,\n} from './writeDynamicDictionary';\n\n/**\n * This function generates the content of the dictionary list file\n */\nexport const generateDictionaryEntryPoint = (\n localedDictionariesPathsRecord: LocalizedDictionaryResult,\n format: 'cjs' | 'esm' = 'esm',\n configuration = getConfiguration()\n): string => {\n const { fetchDictionariesDir } = configuration.content;\n const { liveSyncURL } = configuration.editor;\n\n let content = '';\n\n const formattedDictionaryMap: string = Object.entries(\n localedDictionariesPathsRecord\n )\n .map(([locale, dictionary]) => {\n const relativePath = normalizePath(\n relative(fetchDictionariesDir, dictionary.dictionaryPath)\n );\n\n if (format === 'esm') {\n return ` '${locale}': () => (async () => { try {return await fetch('${liveSyncURL}/dictionaries/${dictionary.dictionary.key}/${locale}').then(res => res.json())} catch (_error) {return await import('./${relativePath}', { assert: { type: 'json' }}).then(mod => mod.default)}})()`;\n }\n\n return ` '${locale}': () => (async () => { try {return await fetch('${liveSyncURL}/dictionaries/${dictionary.dictionary.key}/${locale}').then(res => res.json())} catch (_error) {return Promise.resolve(require('./${relativePath}'))}})()`;\n })\n .join(',\\n');\n\n content += `const content = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n if (format === 'esm') content += `export default content;\\n`;\n if (format === 'cjs') content += `module.exports = content;\\n`;\n\n return content;\n};\n\n/**\n * Write the localized dictionaries to the dictionariesDir\n * @param mergedDictionaries - The merged dictionaries\n * @param configuration - The configuration\n * @returns The final dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/fetch_dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeFetchDictionary = async (\n dynamicDictionaries: LocalizedDictionaryOutput,\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n): Promise<LocalizedDictionaryOutput> => {\n const { fetchDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(fetchDictionariesDir), { recursive: true });\n\n let resultDictionariesPaths: LocalizedDictionaryOutput = {};\n\n // Write entry points for each dictionary in parallel\n await parallelize(\n Object.entries(dynamicDictionaries),\n async ([key, localedDictionariesPathsRecord]) => {\n if (key === 'undefined') return;\n\n await parallelize(formats, async (format) => {\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n const content = generateDictionaryEntryPoint(\n localedDictionariesPathsRecord,\n format,\n configuration\n );\n\n await writeFile(\n resolve(fetchDictionariesDir, `${key}.${extension}`),\n content\n );\n });\n }\n );\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAgD;AAChD,sBAAiC;AACjC,kBAAkC;AAClC,yBAA4B;AASrB,MAAM,+BAA+B,CAC1C,gCACA,SAAwB,OACxB,oBAAgB,gCAAiB,MACtB;AACX,QAAM,EAAE,qBAAqB,IAAI,cAAc;AAC/C,QAAM,EAAE,YAAY,IAAI,cAAc;AAEtC,MAAI,UAAU;AAEd,QAAM,yBAAiC,OAAO;AAAA,IAC5C;AAAA,EACF,EACG,IAAI,CAAC,CAAC,QAAQ,UAAU,MAAM;AAC7B,UAAM,mBAAe;AAAA,UACnB,sBAAS,sBAAsB,WAAW,cAAc;AAAA,IAC1D;AAEA,QAAI,WAAW,OAAO;AACpB,aAAO,MAAM,MAAM,oDAAoD,WAAW,iBAAiB,WAAW,WAAW,GAAG,IAAI,MAAM,sEAAsE,YAAY;AAAA,IAC1N;AAEA,WAAO,MAAM,MAAM,oDAAoD,WAAW,iBAAiB,WAAW,WAAW,GAAG,IAAI,MAAM,iFAAiF,YAAY;AAAA,EACrO,CAAC,EACA,KAAK,KAAK;AAEb,aAAW;AAAA,EAAsB,sBAAsB;AAAA;AAAA;AAEvD,MAAI,WAAW,MAAO,YAAW;AAAA;AACjC,MAAI,WAAW,MAAO,YAAW;AAAA;AAEjC,SAAO;AACT;AAkBO,MAAM,uBAAuB,OAClC,qBACA,oBAAgB,gCAAiB,GACjC,UAA6B,CAAC,OAAO,KAAK,MACH;AACvC,QAAM,EAAE,qBAAqB,IAAI,cAAc;AAG/C,YAAM,2BAAM,qBAAQ,oBAAoB,GAAG,EAAE,WAAW,KAAK,CAAC;AAE9D,MAAI,0BAAqD,CAAC;AAG1D,YAAM;AAAA,IACJ,OAAO,QAAQ,mBAAmB;AAAA,IAClC,OAAO,CAAC,KAAK,8BAA8B,MAAM;AAC/C,UAAI,QAAQ,YAAa;AAEzB,gBAAM,gCAAY,SAAS,OAAO,WAAW;AAC3C,cAAM,YAAY,WAAW,QAAQ,QAAQ;AAC7C,cAAM,UAAU;AAAA,UACd;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,kBAAM;AAAA,cACJ,qBAAQ,sBAAsB,GAAG,GAAG,IAAI,SAAS,EAAE;AAAA,UACnD;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -26,31 +26,39 @@ var import_promises = require("fs/promises");
26
26
  var import_path = require("path");
27
27
  var import_mergeDictionaries = require('../../../mergeDictionaries.cjs');
28
28
  var import_processPerLocaleDictionary = require('../../../processPerLocaleDictionary.cjs');
29
+ var import_parallelize = require('../../../utils/parallelize.cjs');
29
30
  var import_formatDictionaryText = require('./formatDictionaryText.cjs');
30
31
  const writeMergedDictionaries = async (groupedDictionaries, configuration = (0, import_config.getConfiguration)()) => {
31
32
  const { dictionariesDir } = configuration.content;
32
33
  await (0, import_promises.mkdir)((0, import_path.resolve)(dictionariesDir), { recursive: true });
33
- let resultDictionariesPaths = {};
34
- for await (const [key, dictionariesEntry] of Object.entries(
35
- groupedDictionaries
36
- )) {
37
- if (key === "undefined") continue;
38
- const multiLocaleDictionaries = dictionariesEntry.dictionaries.map(
39
- (dictionary) => (0, import_processPerLocaleDictionary.processPerLocaleDictionary)(dictionary)
40
- );
41
- const mergedDictionary = (0, import_mergeDictionaries.mergeDictionaries)(multiLocaleDictionaries);
42
- const contentString = (0, import_formatDictionaryText.formatDictionaryText)(mergedDictionary);
43
- const outputFileName = `${key}.json`;
44
- const resultFilePath = (0, import_path.resolve)(dictionariesDir, outputFileName);
45
- await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
46
- console.error(`Error creating merged ${outputFileName}:`, err);
47
- });
48
- resultDictionariesPaths[key] = {
49
- dictionaryPath: resultFilePath,
50
- dictionary: mergedDictionary
51
- };
52
- }
53
- return resultDictionariesPaths;
34
+ const results = await (0, import_parallelize.parallelize)(
35
+ Object.entries(groupedDictionaries),
36
+ async ([key, dictionariesEntry]) => {
37
+ if (key === "undefined") {
38
+ return void 0;
39
+ }
40
+ const multiLocaleDictionaries = dictionariesEntry.dictionaries.map(
41
+ (dictionary) => (0, import_processPerLocaleDictionary.processPerLocaleDictionary)(dictionary)
42
+ );
43
+ const mergedDictionary = (0, import_mergeDictionaries.mergeDictionaries)(multiLocaleDictionaries);
44
+ const contentString = (0, import_formatDictionaryText.formatDictionaryText)(mergedDictionary);
45
+ const outputFileName = `${key}.json`;
46
+ const resultFilePath = (0, import_path.resolve)(dictionariesDir, outputFileName);
47
+ await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
48
+ console.error(`Error creating merged ${outputFileName}:`, err);
49
+ });
50
+ return [
51
+ key,
52
+ {
53
+ dictionaryPath: resultFilePath,
54
+ dictionary: mergedDictionary
55
+ }
56
+ ];
57
+ }
58
+ );
59
+ return Object.fromEntries(
60
+ results.filter(Boolean)
61
+ );
54
62
  };
55
63
  // Annotate the CommonJS export names for ESM import in node:
56
64
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { mergeDictionaries } from '../../../mergeDictionaries';\nimport { processPerLocaleDictionary } from '../../../processPerLocaleDictionary';\nimport { formatDictionaryText } from './formatDictionaryText';\nimport { UnmergedDictionaryOutput } from './writeUnmergedDictionary';\n\nexport type MergedDictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type MergedDictionaryOutput = Record<string, MergedDictionaryResult>;\n\n/**\n * Write the merged dictionaries to the dictionariesDir\n * @param groupedDictionaries - The grouped dictionaries\n * @param configuration - The configuration\n * @returns The merged dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeMergedDictionaries = async (\n groupedDictionaries: UnmergedDictionaryOutput,\n configuration = getConfiguration()\n): Promise<MergedDictionaryOutput> => {\n const { dictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n let resultDictionariesPaths: MergedDictionaryOutput = {};\n\n // Merge dictionaries with the same key and write to dictionariesDir\n for await (const [key, dictionariesEntry] of Object.entries(\n groupedDictionaries\n )) {\n if (key === 'undefined') continue;\n\n const multiLocaleDictionaries = dictionariesEntry.dictionaries.map(\n (dictionary) => processPerLocaleDictionary(dictionary)\n );\n\n const mergedDictionary = mergeDictionaries(multiLocaleDictionaries);\n\n const contentString = formatDictionaryText(mergedDictionary);\n\n const outputFileName = `${key}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Write the merged dictionary\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating merged ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths[key] = {\n dictionaryPath: resultFilePath,\n dictionary: mergedDictionary,\n };\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,sBAAiC;AACjC,kBAAwB;AACxB,+BAAkC;AAClC,wCAA2C;AAC3C,kCAAqC;AA0B9B,MAAM,0BAA0B,OACrC,qBACA,oBAAgB,gCAAiB,MACG;AACpC,QAAM,EAAE,gBAAgB,IAAI,cAAc;AAG1C,YAAM,2BAAM,qBAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,MAAI,0BAAkD,CAAC;AAGvD,mBAAiB,CAAC,KAAK,iBAAiB,KAAK,OAAO;AAAA,IAClD;AAAA,EACF,GAAG;AACD,QAAI,QAAQ,YAAa;AAEzB,UAAM,0BAA0B,kBAAkB,aAAa;AAAA,MAC7D,CAAC,mBAAe,8DAA2B,UAAU;AAAA,IACvD;AAEA,UAAM,uBAAmB,4CAAkB,uBAAuB;AAElE,UAAM,oBAAgB,kDAAqB,gBAAgB;AAE3D,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,qBAAiB,qBAAQ,iBAAiB,cAAc;AAG9D,cAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,yBAAyB,cAAc,KAAK,GAAG;AAAA,IAC/D,CAAC;AAED,4BAAwB,GAAG,IAAI;AAAA,MAC7B,gBAAgB;AAAA,MAChB,YAAY;AAAA,IACd;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { mergeDictionaries } from '../../../mergeDictionaries';\nimport { processPerLocaleDictionary } from '../../../processPerLocaleDictionary';\nimport { parallelize } from '../../../utils/parallelize';\nimport { formatDictionaryText } from './formatDictionaryText';\nimport { UnmergedDictionaryOutput } from './writeUnmergedDictionary';\n\nexport type MergedDictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type MergedDictionaryOutput = Record<string, MergedDictionaryResult>;\n\n/**\n * Write the merged dictionaries to the dictionariesDir\n * @param groupedDictionaries - The grouped dictionaries\n * @param configuration - The configuration\n * @returns The merged dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/dictionary/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeMergedDictionaries = async (\n groupedDictionaries: UnmergedDictionaryOutput,\n configuration = getConfiguration()\n): Promise<MergedDictionaryOutput> => {\n const { dictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n const results = await parallelize(\n Object.entries(groupedDictionaries),\n async ([key, dictionariesEntry]) => {\n if (key === 'undefined') {\n return undefined as unknown as readonly [\n string,\n MergedDictionaryResult,\n ];\n }\n\n const multiLocaleDictionaries = dictionariesEntry.dictionaries.map(\n (dictionary) => processPerLocaleDictionary(dictionary)\n );\n\n const mergedDictionary = mergeDictionaries(multiLocaleDictionaries);\n\n const contentString = formatDictionaryText(mergedDictionary);\n\n const outputFileName = `${key}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Write the merged dictionary\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating merged ${outputFileName}:`, err);\n });\n\n return [\n key,\n {\n dictionaryPath: resultFilePath,\n dictionary: mergedDictionary,\n } as MergedDictionaryResult,\n ] as const;\n }\n );\n\n return Object.fromEntries(\n results.filter(Boolean) as Array<readonly [string, MergedDictionaryResult]>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,sBAAiC;AACjC,kBAAwB;AACxB,+BAAkC;AAClC,wCAA2C;AAC3C,yBAA4B;AAC5B,kCAAqC;AA0B9B,MAAM,0BAA0B,OACrC,qBACA,oBAAgB,gCAAiB,MACG;AACpC,QAAM,EAAE,gBAAgB,IAAI,cAAc;AAG1C,YAAM,2BAAM,qBAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,QAAM,UAAU,UAAM;AAAA,IACpB,OAAO,QAAQ,mBAAmB;AAAA,IAClC,OAAO,CAAC,KAAK,iBAAiB,MAAM;AAClC,UAAI,QAAQ,aAAa;AACvB,eAAO;AAAA,MAIT;AAEA,YAAM,0BAA0B,kBAAkB,aAAa;AAAA,QAC7D,CAAC,mBAAe,8DAA2B,UAAU;AAAA,MACvD;AAEA,YAAM,uBAAmB,4CAAkB,uBAAuB;AAElE,YAAM,oBAAgB,kDAAqB,gBAAgB;AAE3D,YAAM,iBAAiB,GAAG,GAAG;AAC7B,YAAM,qBAAiB,qBAAQ,iBAAiB,cAAc;AAG9D,gBAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,gBAAQ,MAAM,yBAAyB,cAAc,KAAK,GAAG;AAAA,MAC/D,CAAC;AAED,aAAO;AAAA,QACL;AAAA,QACA;AAAA,UACE,gBAAgB;AAAA,UAChB,YAAY;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,OAAO;AAAA,IACZ,QAAQ,OAAO,OAAO;AAAA,EACxB;AACF;","names":[]}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var writeRemoteDictionary_exports = {};
20
+ __export(writeRemoteDictionary_exports, {
21
+ writeRemoteDictionary: () => writeRemoteDictionary
22
+ });
23
+ module.exports = __toCommonJS(writeRemoteDictionary_exports);
24
+ var import_config = require("@intlayer/config");
25
+ var import_promises = require("fs/promises");
26
+ var import_path = require("path");
27
+ var import_filterInvalidDictionaries = require('../../../filterInvalidDictionaries.cjs');
28
+ var import_loadDictionaries = require('../../../loadDictionaries/index.cjs');
29
+ var import_parallelize = require('../../../utils/parallelize.cjs');
30
+ var import_formatDictionaryText = require('./formatDictionaryText.cjs');
31
+ const writeRemoteDictionary = async (remoteDictionaries, configuration = (0, import_config.getConfiguration)()) => {
32
+ const { remoteDictionariesDir } = configuration.content;
33
+ await (0, import_promises.mkdir)((0, import_path.resolve)(remoteDictionariesDir), { recursive: true });
34
+ const filteredDictionaries = (0, import_filterInvalidDictionaries.filterInvalidDictionaries)(remoteDictionaries);
35
+ await (0, import_parallelize.parallelize)(
36
+ filteredDictionaries.filter((dictionary) => dictionary.key !== "undefined"),
37
+ async (dictionary) => {
38
+ const outputFileName = `${dictionary.key}.json`;
39
+ const resultFilePath = (0, import_path.resolve)(remoteDictionariesDir, outputFileName);
40
+ const contentString = (0, import_formatDictionaryText.formatDictionaryText)(dictionary);
41
+ await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
42
+ console.error(`Error creating merged ${outputFileName}:`, err);
43
+ });
44
+ }
45
+ );
46
+ return (0, import_loadDictionaries.formatDistantDictionaries)(remoteDictionaries);
47
+ };
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ writeRemoteDictionary
51
+ });
52
+ //# sourceMappingURL=writeRemoteDictionary.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { filterInvalidDictionaries } from '../../../filterInvalidDictionaries';\nimport { formatDistantDictionaries } from '../../../loadDictionaries';\nimport { parallelize } from '../../../utils/parallelize';\nimport { formatDictionaryText } from './formatDictionaryText';\n\n/**\n * Write the localized dictionaries to the dictionariesDir\n * @param mergedDictionaries - The merged dictionaries\n * @param configuration - The configuration\n * @returns The final dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/fetch_dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeRemoteDictionary = async (\n remoteDictionaries: Dictionary[],\n configuration = getConfiguration()\n): Promise<Dictionary[]> => {\n const { remoteDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(remoteDictionariesDir), { recursive: true });\n\n const filteredDictionaries = filterInvalidDictionaries(remoteDictionaries);\n\n // Merge dictionaries with the same key and write to dictionariesDir\n await parallelize(\n filteredDictionaries.filter((dictionary) => dictionary.key !== 'undefined'),\n async (dictionary) => {\n const outputFileName = `${dictionary.key}.json`;\n const resultFilePath = resolve(remoteDictionariesDir, outputFileName);\n\n const contentString = formatDictionaryText(dictionary);\n\n // Write the merged dictionary\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating merged ${outputFileName}:`, err);\n });\n }\n );\n\n return formatDistantDictionaries(remoteDictionaries);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,sBAAiC;AACjC,kBAAwB;AACxB,uCAA0C;AAC1C,8BAA0C;AAC1C,yBAA4B;AAC5B,kCAAqC;AAkB9B,MAAM,wBAAwB,OACnC,oBACA,oBAAgB,gCAAiB,MACP;AAC1B,QAAM,EAAE,sBAAsB,IAAI,cAAc;AAGhD,YAAM,2BAAM,qBAAQ,qBAAqB,GAAG,EAAE,WAAW,KAAK,CAAC;AAE/D,QAAM,2BAAuB,4DAA0B,kBAAkB;AAGzE,YAAM;AAAA,IACJ,qBAAqB,OAAO,CAAC,eAAe,WAAW,QAAQ,WAAW;AAAA,IAC1E,OAAO,eAAe;AACpB,YAAM,iBAAiB,GAAG,WAAW,GAAG;AACxC,YAAM,qBAAiB,qBAAQ,uBAAuB,cAAc;AAEpE,YAAM,oBAAgB,kDAAqB,UAAU;AAGrD,gBAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,gBAAQ,MAAM,yBAAyB,cAAc,KAAK,GAAG;AAAA,MAC/D,CAAC;AAAA,IACH;AAAA,EACF;AAEA,aAAO,mDAA0B,kBAAkB;AACrD;","names":[]}
@@ -24,39 +24,54 @@ module.exports = __toCommonJS(writeUnmergedDictionary_exports);
24
24
  var import_config = require("@intlayer/config");
25
25
  var import_promises = require("fs/promises");
26
26
  var import_path = require("path");
27
+ var import_filterInvalidDictionaries = require('../../../filterInvalidDictionaries.cjs');
28
+ var import_orderDictionaries = require('../../../orderDictionaries.cjs');
29
+ var import_parallelize = require('../../../utils/parallelize.cjs');
27
30
  var import_formatDictionaryText = require('./formatDictionaryText.cjs');
28
- const groupDictionariesByKey = (dictionaries) => {
29
- return dictionaries.reduce(
30
- (acc, dictionary) => {
31
- const key = dictionary.key;
32
- if (!acc[key]) {
33
- acc[key] = [];
34
- }
35
- acc[key].push(dictionary);
36
- return acc;
37
- },
38
- {}
39
- );
40
- };
31
+ const groupDictionariesByKey = (dictionaries) => dictionaries.reduce(
32
+ (acc, dictionary) => {
33
+ const key = dictionary.key;
34
+ if (!acc[key]) {
35
+ acc[key] = [];
36
+ }
37
+ acc[key].push(dictionary);
38
+ return acc;
39
+ },
40
+ {}
41
+ );
41
42
  const writeUnmergedDictionaries = async (dictionaries, configuration = (0, import_config.getConfiguration)()) => {
42
43
  const { unmergedDictionariesDir } = configuration.content;
43
44
  await (0, import_promises.mkdir)((0, import_path.resolve)(unmergedDictionariesDir), { recursive: true });
44
- const groupedDictionaries = groupDictionariesByKey(dictionaries);
45
- let resultDictionariesPaths = {};
46
- for await (const [key, dictionaries2] of Object.entries(groupedDictionaries)) {
47
- if (key === "undefined") continue;
48
- const contentString = (0, import_formatDictionaryText.formatDictionaryText)(dictionaries2);
49
- const outputFileName = `${key}.json`;
50
- const unmergedFilePath = (0, import_path.resolve)(unmergedDictionariesDir, outputFileName);
51
- await (0, import_promises.writeFile)(unmergedFilePath, contentString, "utf8").catch((err) => {
52
- console.error(`Error creating unmerged ${outputFileName}:`, err);
53
- });
54
- resultDictionariesPaths[key] = {
55
- dictionaryPath: unmergedFilePath,
56
- dictionaries: dictionaries2
57
- };
58
- }
59
- return resultDictionariesPaths;
45
+ const filteredDictionaries = (0, import_filterInvalidDictionaries.filterInvalidDictionaries)(dictionaries);
46
+ const groupedDictionaries = groupDictionariesByKey(filteredDictionaries);
47
+ const results = await (0, import_parallelize.parallelize)(
48
+ Object.entries(groupedDictionaries),
49
+ async ([key, dictionaries2]) => {
50
+ if (key === "undefined") {
51
+ return void 0;
52
+ }
53
+ const orderedDictionaries = (0, import_orderDictionaries.orderDictionaries)(
54
+ dictionaries2,
55
+ configuration
56
+ );
57
+ const contentString = (0, import_formatDictionaryText.formatDictionaryText)(orderedDictionaries);
58
+ const outputFileName = `${key}.json`;
59
+ const unmergedFilePath = (0, import_path.resolve)(unmergedDictionariesDir, outputFileName);
60
+ await (0, import_promises.writeFile)(unmergedFilePath, contentString, "utf8").catch((err) => {
61
+ console.error(`${import_config.x} Error creating unmerged ${outputFileName}:`, err);
62
+ });
63
+ return [
64
+ key,
65
+ {
66
+ dictionaryPath: unmergedFilePath,
67
+ dictionaries: dictionaries2
68
+ }
69
+ ];
70
+ }
71
+ );
72
+ return Object.fromEntries(
73
+ results.filter(Boolean)
74
+ );
60
75
  };
61
76
  // Annotate the CommonJS export names for ESM import in node:
62
77
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { formatDictionaryText } from './formatDictionaryText';\n\nconst groupDictionariesByKey = (\n dictionaries: Dictionary[]\n): Record<string, Dictionary[]> => {\n return dictionaries.reduce(\n (acc, dictionary) => {\n const key = dictionary.key;\n if (!acc[key]) {\n acc[key] = [];\n }\n acc[key].push(dictionary);\n return acc;\n },\n {} as Record<string, Dictionary[]>\n );\n};\n\nexport type UnmergedDictionaryResult = {\n dictionaryPath: string;\n dictionaries: Dictionary[];\n};\n\nexport type UnmergedDictionaryOutput = Record<string, UnmergedDictionaryResult>;\n\n/**\n * Write the unmerged dictionaries to the unmergedDictionariesDir\n * @param dictionaries - The dictionaries to write\n * @param configuration - The configuration\n * @returns The grouped dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * console.log(unmergedDictionaries);\n *\n * // .intlayer/unmerged_dictionaries/home.json\n * // {\n * // [\n * // { key: 'home', content: { ... } },\n * // { key: 'home', content: { ... } },\n * // ],\n * // }\n * ```\n */\nexport const writeUnmergedDictionaries = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n): Promise<UnmergedDictionaryOutput> => {\n const { unmergedDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(unmergedDictionariesDir), { recursive: true });\n\n // Group dictionaries by key and write to unmergedDictionariesDir\n const groupedDictionaries = groupDictionariesByKey(dictionaries);\n\n let resultDictionariesPaths: UnmergedDictionaryOutput = {};\n\n for await (const [key, dictionaries] of Object.entries(groupedDictionaries)) {\n if (key === 'undefined') continue;\n\n const contentString = formatDictionaryText(dictionaries);\n\n const outputFileName = `${key}.json`;\n const unmergedFilePath = resolve(unmergedDictionariesDir, outputFileName);\n\n // Write the grouped dictionaries\n await writeFile(unmergedFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating unmerged ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths[key] = {\n dictionaryPath: unmergedFilePath,\n dictionaries: dictionaries,\n };\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,sBAAiC;AACjC,kBAAwB;AACxB,kCAAqC;AAErC,MAAM,yBAAyB,CAC7B,iBACiC;AACjC,SAAO,aAAa;AAAA,IAClB,CAAC,KAAK,eAAe;AACnB,YAAM,MAAM,WAAW;AACvB,UAAI,CAAC,IAAI,GAAG,GAAG;AACb,YAAI,GAAG,IAAI,CAAC;AAAA,MACd;AACA,UAAI,GAAG,EAAE,KAAK,UAAU;AACxB,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;AA6BO,MAAM,4BAA4B,OACvC,cACA,oBAAgB,gCAAiB,MACK;AACtC,QAAM,EAAE,wBAAwB,IAAI,cAAc;AAGlD,YAAM,2BAAM,qBAAQ,uBAAuB,GAAG,EAAE,WAAW,KAAK,CAAC;AAGjE,QAAM,sBAAsB,uBAAuB,YAAY;AAE/D,MAAI,0BAAoD,CAAC;AAEzD,mBAAiB,CAAC,KAAKA,aAAY,KAAK,OAAO,QAAQ,mBAAmB,GAAG;AAC3E,QAAI,QAAQ,YAAa;AAEzB,UAAM,oBAAgB,kDAAqBA,aAAY;AAEvD,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,uBAAmB,qBAAQ,yBAAyB,cAAc;AAGxE,cAAM,2BAAU,kBAAkB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACtE,cAAQ,MAAM,2BAA2B,cAAc,KAAK,GAAG;AAAA,IACjE,CAAC;AAED,4BAAwB,GAAG,IAAI;AAAA,MAC7B,gBAAgB;AAAA,MAChB,cAAcA;AAAA,IAChB;AAAA,EACF;AAEA,SAAO;AACT;","names":["dictionaries"]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.ts"],"sourcesContent":["import { getConfiguration, x } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { filterInvalidDictionaries } from '../../../filterInvalidDictionaries';\nimport { orderDictionaries } from '../../../orderDictionaries';\nimport { parallelize } from '../../../utils/parallelize';\nimport { formatDictionaryText } from './formatDictionaryText';\n\nconst groupDictionariesByKey = (\n dictionaries: Dictionary[]\n): Record<string, Dictionary[]> =>\n dictionaries.reduce(\n (acc, dictionary) => {\n const key = dictionary.key;\n if (!acc[key]) {\n acc[key] = [];\n }\n acc[key].push(dictionary);\n return acc;\n },\n {} as Record<string, Dictionary[]>\n );\n\nexport type UnmergedDictionaryResult = {\n dictionaryPath: string;\n dictionaries: Dictionary[];\n};\n\nexport type UnmergedDictionaryOutput = Record<string, UnmergedDictionaryResult>;\n\n/**\n * Write the unmerged dictionaries to the unmergedDictionariesDir\n * @param dictionaries - The dictionaries to write\n * @param configuration - The configuration\n * @returns The grouped dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * console.log(unmergedDictionaries);\n *\n * // .intlayer/unmerged_dictionaries/home.json\n * // {\n * // [\n * // { key: 'home', content: { ... } },\n * // { key: 'home', content: { ... } },\n * // ],\n * // }\n * ```\n */\nexport const writeUnmergedDictionaries = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n): Promise<UnmergedDictionaryOutput> => {\n const { unmergedDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(unmergedDictionariesDir), { recursive: true });\n\n const filteredDictionaries = filterInvalidDictionaries(dictionaries);\n\n // Group dictionaries by key and write to unmergedDictionariesDir\n const groupedDictionaries = groupDictionariesByKey(filteredDictionaries);\n\n const results = await parallelize(\n Object.entries(groupedDictionaries),\n async ([key, dictionaries]) => {\n if (key === 'undefined') {\n return undefined as unknown as readonly [\n string,\n UnmergedDictionaryResult,\n ];\n }\n\n const orderedDictionaries = orderDictionaries(\n dictionaries,\n configuration\n );\n const contentString = formatDictionaryText(orderedDictionaries);\n\n const outputFileName = `${key}.json`;\n const unmergedFilePath = resolve(unmergedDictionariesDir, outputFileName);\n\n // Write the grouped dictionaries\n await writeFile(unmergedFilePath, contentString, 'utf8').catch((err) => {\n console.error(`${x} Error creating unmerged ${outputFileName}:`, err);\n });\n\n return [\n key,\n {\n dictionaryPath: unmergedFilePath,\n dictionaries: dictionaries,\n } as UnmergedDictionaryResult,\n ] as const;\n }\n );\n\n return Object.fromEntries(\n results.filter(Boolean) as Array<\n readonly [string, UnmergedDictionaryResult]\n >\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AAEpC,sBAAiC;AACjC,kBAAwB;AACxB,uCAA0C;AAC1C,+BAAkC;AAClC,yBAA4B;AAC5B,kCAAqC;AAErC,MAAM,yBAAyB,CAC7B,iBAEA,aAAa;AAAA,EACX,CAAC,KAAK,eAAe;AACnB,UAAM,MAAM,WAAW;AACvB,QAAI,CAAC,IAAI,GAAG,GAAG;AACb,UAAI,GAAG,IAAI,CAAC;AAAA,IACd;AACA,QAAI,GAAG,EAAE,KAAK,UAAU;AACxB,WAAO;AAAA,EACT;AAAA,EACA,CAAC;AACH;AA6BK,MAAM,4BAA4B,OACvC,cACA,oBAAgB,gCAAiB,MACK;AACtC,QAAM,EAAE,wBAAwB,IAAI,cAAc;AAGlD,YAAM,2BAAM,qBAAQ,uBAAuB,GAAG,EAAE,WAAW,KAAK,CAAC;AAEjE,QAAM,2BAAuB,4DAA0B,YAAY;AAGnE,QAAM,sBAAsB,uBAAuB,oBAAoB;AAEvE,QAAM,UAAU,UAAM;AAAA,IACpB,OAAO,QAAQ,mBAAmB;AAAA,IAClC,OAAO,CAAC,KAAKA,aAAY,MAAM;AAC7B,UAAI,QAAQ,aAAa;AACvB,eAAO;AAAA,MAIT;AAEA,YAAM,0BAAsB;AAAA,QAC1BA;AAAA,QACA;AAAA,MACF;AACA,YAAM,oBAAgB,kDAAqB,mBAAmB;AAE9D,YAAM,iBAAiB,GAAG,GAAG;AAC7B,YAAM,uBAAmB,qBAAQ,yBAAyB,cAAc;AAGxE,gBAAM,2BAAU,kBAAkB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACtE,gBAAQ,MAAM,GAAG,eAAC,4BAA4B,cAAc,KAAK,GAAG;AAAA,MACtE,CAAC;AAED,aAAO;AAAA,QACL;AAAA,QACA;AAAA,UACE,gBAAgB;AAAA,UAChB,cAAcA;AAAA,QAChB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,OAAO;AAAA,IACZ,QAAQ,OAAO,OAAO;AAAA,EAGxB;AACF;","names":["dictionaries"]}
@@ -22,11 +22,14 @@ __export(createDictionaryEntryPoint_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(createDictionaryEntryPoint_exports);
24
24
  var import_config = require("@intlayer/config");
25
- var import_fs = require("fs");
25
+ var import_promises = require("fs/promises");
26
26
  var import_path = require("path");
27
27
  var import_getBuiltDictionariesPath = require('../../getBuiltDictionariesPath.cjs');
28
28
  var import_getBuiltDynamicDictionariesPath = require('../../getBuiltDynamicDictionariesPath.cjs');
29
+ var import_getBuiltFetchDictionariesPath = require('../../getBuiltFetchDictionariesPath.cjs');
30
+ var import_getBuiltRemoteDictionariesPath = require('../../getBuiltRemoteDictionariesPath.cjs');
29
31
  var import_getBuiltUnmergedDictionariesPath = require('../../getBuiltUnmergedDictionariesPath.cjs');
32
+ var import_parallelize = require('../../utils/parallelize.cjs');
30
33
  var import_generateDictionaryListContent = require('./generateDictionaryListContent.cjs');
31
34
  const filterDictionaries = (paths, keys) => {
32
35
  if (!keys) return paths;
@@ -34,50 +37,52 @@ const filterDictionaries = (paths, keys) => {
34
37
  (path) => keys.some((key) => path.endsWith(`${key}.json`))
35
38
  );
36
39
  };
37
- const writeDictionaryFiles = (paths, fileName, format, configuration = (0, import_config.getConfiguration)()) => {
40
+ const writeDictionaryFiles = async (paths, fileName, format, configuration = (0, import_config.getConfiguration)()) => {
38
41
  const content = (0, import_generateDictionaryListContent.generateDictionaryListContent)(paths, format, configuration);
39
42
  const extension = format === "cjs" ? "cjs" : "mjs";
40
43
  const { mainDir } = configuration.content;
41
- (0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, `${fileName}.${extension}`), content);
44
+ await (0, import_promises.writeFile)((0, import_path.resolve)(mainDir, `${fileName}.${extension}`), content);
42
45
  };
43
- const createDictionaryEntryPoint = (configuration = (0, import_config.getConfiguration)(), dictionariesKeys, formats = ["cjs", "esm"]) => {
46
+ const createDictionaryEntryPoint = async (configuration = (0, import_config.getConfiguration)(), dictionariesKeys, formats = ["cjs", "esm"]) => {
44
47
  const { mainDir } = configuration.content;
45
- if (!(0, import_fs.existsSync)(mainDir)) {
46
- (0, import_fs.mkdirSync)(mainDir, { recursive: true });
47
- }
48
+ await (0, import_promises.mkdir)(mainDir, { recursive: true });
49
+ const remoteDictionariesPath = (0, import_getBuiltRemoteDictionariesPath.getBuiltRemoteDictionariesPath)(configuration);
48
50
  const dictionariesPath = filterDictionaries(
49
51
  (0, import_getBuiltDictionariesPath.getBuiltDictionariesPath)(configuration),
50
52
  dictionariesKeys
51
53
  );
52
- for (const format of formats) {
53
- writeDictionaryFiles(
54
- dictionariesPath,
55
- "dictionaries",
56
- format,
57
- configuration
58
- );
59
- }
60
54
  const unmergedDictionariesPath = (0, import_getBuiltUnmergedDictionariesPath.getBuiltUnmergedDictionariesPath)(configuration);
61
- for (const format of formats) {
62
- writeDictionaryFiles(
63
- unmergedDictionariesPath,
64
- "unmerged_dictionaries",
65
- format,
66
- configuration
67
- );
68
- }
69
- for (const format of formats) {
70
- const dynamicDictionariesPathCJS = (0, import_getBuiltDynamicDictionariesPath.getBuiltDynamicDictionariesPath)(
71
- configuration,
55
+ const writeOperations = [
56
+ ...formats.map((format) => ({
57
+ paths: remoteDictionariesPath,
58
+ fileName: "remote_dictionaries",
72
59
  format
73
- );
74
- writeDictionaryFiles(
75
- dynamicDictionariesPathCJS,
76
- "dynamic_dictionaries",
77
- format,
78
- configuration
79
- );
80
- }
60
+ })),
61
+ ...formats.map((format) => ({
62
+ paths: dictionariesPath,
63
+ fileName: "dictionaries",
64
+ format
65
+ })),
66
+ ...formats.map((format) => ({
67
+ paths: unmergedDictionariesPath,
68
+ fileName: "unmerged_dictionaries",
69
+ format
70
+ })),
71
+ ...formats.map((format) => ({
72
+ paths: (0, import_getBuiltDynamicDictionariesPath.getBuiltDynamicDictionariesPath)(configuration, format),
73
+ fileName: "dynamic_dictionaries",
74
+ format
75
+ })),
76
+ ...formats.map((format) => ({
77
+ paths: (0, import_getBuiltFetchDictionariesPath.getBuiltFetchDictionariesPath)(configuration, format),
78
+ fileName: "fetch_dictionaries",
79
+ format
80
+ }))
81
+ ];
82
+ await (0, import_parallelize.parallelize)(
83
+ writeOperations,
84
+ async ({ paths, fileName, format }) => writeDictionaryFiles(paths, fileName, format, configuration)
85
+ );
81
86
  };
82
87
  // Annotate the CommonJS export names for ESM import in node:
83
88
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { getBuiltDictionariesPath } from '../../getBuiltDictionariesPath';\nimport { getBuiltDynamicDictionariesPath } from '../../getBuiltDynamicDictionariesPath';\nimport { getBuiltUnmergedDictionariesPath } from '../../getBuiltUnmergedDictionariesPath';\nimport { generateDictionaryListContent } from './generateDictionaryListContent';\n\nconst filterDictionaries = (paths: string[], keys?: string[]) => {\n if (!keys) return paths;\n return paths.filter((path) =>\n keys.some((key) => path.endsWith(`${key}.json`))\n );\n};\n\nconst writeDictionaryFiles = (\n paths: string[],\n fileName: string,\n format: 'cjs' | 'esm',\n configuration = getConfiguration()\n) => {\n const content = generateDictionaryListContent(paths, format, configuration);\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n\n const { mainDir } = configuration.content;\n\n writeFileSync(resolve(mainDir, `${fileName}.${extension}`), content);\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryEntryPoint = (\n configuration = getConfiguration(),\n dictionariesKeys?: string[],\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n) => {\n const { mainDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath = filterDictionaries(\n getBuiltDictionariesPath(configuration),\n dictionariesKeys\n );\n\n for (const format of formats) {\n writeDictionaryFiles(\n dictionariesPath,\n 'dictionaries',\n format,\n configuration\n );\n }\n\n const unmergedDictionariesPath =\n getBuiltUnmergedDictionariesPath(configuration);\n\n for (const format of formats) {\n writeDictionaryFiles(\n unmergedDictionariesPath,\n 'unmerged_dictionaries',\n format,\n configuration\n );\n }\n\n for (const format of formats) {\n const dynamicDictionariesPathCJS = getBuiltDynamicDictionariesPath(\n configuration,\n format\n );\n\n writeDictionaryFiles(\n dynamicDictionariesPathCJS,\n 'dynamic_dictionaries',\n format,\n configuration\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AACjC,gBAAqD;AACrD,kBAAwB;AACxB,sCAAyC;AACzC,6CAAgD;AAChD,8CAAiD;AACjD,2CAA8C;AAE9C,MAAM,qBAAqB,CAAC,OAAiB,SAAoB;AAC/D,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,MAAM;AAAA,IAAO,CAAC,SACnB,KAAK,KAAK,CAAC,QAAQ,KAAK,SAAS,GAAG,GAAG,OAAO,CAAC;AAAA,EACjD;AACF;AAEA,MAAM,uBAAuB,CAC3B,OACA,UACA,QACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,cAAU,oEAA8B,OAAO,QAAQ,aAAa;AAC1E,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,mCAAc,qBAAQ,SAAS,GAAG,QAAQ,IAAI,SAAS,EAAE,GAAG,OAAO;AACrE;AAKO,MAAM,6BAA6B,CACxC,oBAAgB,gCAAiB,GACjC,kBACA,UAA6B,CAAC,OAAO,KAAK,MACvC;AACH,QAAM,EAAE,QAAQ,IAAI,cAAc;AAGlC,MAAI,KAAC,sBAAW,OAAO,GAAG;AACxB,6BAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAAmB;AAAA,QACvB,0DAAyB,aAAa;AAAA,IACtC;AAAA,EACF;AAEA,aAAW,UAAU,SAAS;AAC5B;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,+BACJ,0EAAiC,aAAa;AAEhD,aAAW,UAAU,SAAS;AAC5B;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,aAAW,UAAU,SAAS;AAC5B,UAAM,iCAA6B;AAAA,MACjC;AAAA,MACA;AAAA,IACF;AAEA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getBuiltDictionariesPath } from '../../getBuiltDictionariesPath';\nimport { getBuiltDynamicDictionariesPath } from '../../getBuiltDynamicDictionariesPath';\nimport { getBuiltFetchDictionariesPath } from '../../getBuiltFetchDictionariesPath';\nimport { getBuiltRemoteDictionariesPath } from '../../getBuiltRemoteDictionariesPath';\nimport { getBuiltUnmergedDictionariesPath } from '../../getBuiltUnmergedDictionariesPath';\nimport { parallelize } from '../../utils/parallelize';\nimport { generateDictionaryListContent } from './generateDictionaryListContent';\n\nconst filterDictionaries = (paths: string[], keys?: string[]) => {\n if (!keys) return paths;\n return paths.filter((path) =>\n keys.some((key) => path.endsWith(`${key}.json`))\n );\n};\n\nconst writeDictionaryFiles = async (\n paths: string[],\n fileName: string,\n format: 'cjs' | 'esm',\n configuration = getConfiguration()\n) => {\n const content = generateDictionaryListContent(paths, format, configuration);\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n\n const { mainDir } = configuration.content;\n\n await writeFile(resolve(mainDir, `${fileName}.${extension}`), content);\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryEntryPoint = async (\n configuration = getConfiguration(),\n dictionariesKeys?: string[],\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n) => {\n const { mainDir } = configuration.content;\n\n await mkdir(mainDir, { recursive: true });\n\n const remoteDictionariesPath = getBuiltRemoteDictionariesPath(configuration);\n const dictionariesPath = filterDictionaries(\n getBuiltDictionariesPath(configuration),\n dictionariesKeys\n );\n const unmergedDictionariesPath =\n getBuiltUnmergedDictionariesPath(configuration);\n\n const writeOperations = [\n ...formats.map((format) => ({\n paths: remoteDictionariesPath,\n fileName: 'remote_dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: dictionariesPath,\n fileName: 'dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: unmergedDictionariesPath,\n fileName: 'unmerged_dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: getBuiltDynamicDictionariesPath(configuration, format),\n fileName: 'dynamic_dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: getBuiltFetchDictionariesPath(configuration, format),\n fileName: 'fetch_dictionaries' as const,\n format,\n })),\n ];\n\n await parallelize(writeOperations, async ({ paths, fileName, format }) =>\n writeDictionaryFiles(paths, fileName, format, configuration)\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AACjC,sBAAiC;AACjC,kBAAwB;AACxB,sCAAyC;AACzC,6CAAgD;AAChD,2CAA8C;AAC9C,4CAA+C;AAC/C,8CAAiD;AACjD,yBAA4B;AAC5B,2CAA8C;AAE9C,MAAM,qBAAqB,CAAC,OAAiB,SAAoB;AAC/D,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,MAAM;AAAA,IAAO,CAAC,SACnB,KAAK,KAAK,CAAC,QAAQ,KAAK,SAAS,GAAG,GAAG,OAAO,CAAC;AAAA,EACjD;AACF;AAEA,MAAM,uBAAuB,OAC3B,OACA,UACA,QACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,cAAU,oEAA8B,OAAO,QAAQ,aAAa;AAC1E,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,YAAM,+BAAU,qBAAQ,SAAS,GAAG,QAAQ,IAAI,SAAS,EAAE,GAAG,OAAO;AACvE;AAKO,MAAM,6BAA6B,OACxC,oBAAgB,gCAAiB,GACjC,kBACA,UAA6B,CAAC,OAAO,KAAK,MACvC;AACH,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,YAAM,uBAAM,SAAS,EAAE,WAAW,KAAK,CAAC;AAExC,QAAM,6BAAyB,sEAA+B,aAAa;AAC3E,QAAM,mBAAmB;AAAA,QACvB,0DAAyB,aAAa;AAAA,IACtC;AAAA,EACF;AACA,QAAM,+BACJ,0EAAiC,aAAa;AAEhD,QAAM,kBAAkB;AAAA,IACtB,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,WAAO,wEAAgC,eAAe,MAAM;AAAA,MAC5D,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,WAAO,oEAA8B,eAAe,MAAM;AAAA,MAC1D,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,YAAM;AAAA,IAAY;AAAA,IAAiB,OAAO,EAAE,OAAO,UAAU,OAAO,MAClE,qBAAqB,OAAO,UAAU,QAAQ,aAAa;AAAA,EAC7D;AACF;","names":[]}
@@ -34,7 +34,7 @@ __export(createModuleAugmentation_exports, {
34
34
  module.exports = __toCommonJS(createModuleAugmentation_exports);
35
35
  var import_config = require("@intlayer/config");
36
36
  var import_fast_glob = __toESM(require("fast-glob"));
37
- var import_fs = require("fs");
37
+ var import_promises = require("fs/promises");
38
38
  var import_path = require("path");
39
39
  var import_getFileHash = require('../../utils/getFileHash.cjs');
40
40
  var import_kebabCaseToCamelCase = require('../../utils/kebabCaseToCamelCase.cjs');
@@ -90,11 +90,9 @@ ${formattedDictionaryMap}
90
90
  fileContent += `}`;
91
91
  return fileContent;
92
92
  };
93
- const createModuleAugmentation = (configuration = (0, import_config.getConfiguration)()) => {
93
+ const createModuleAugmentation = async (configuration = (0, import_config.getConfiguration)()) => {
94
94
  const { moduleAugmentationDir, typesDir } = configuration.content;
95
- if (!(0, import_fs.existsSync)(moduleAugmentationDir)) {
96
- (0, import_fs.mkdirSync)(moduleAugmentationDir, { recursive: true });
97
- }
95
+ await (0, import_promises.mkdir)(moduleAugmentationDir, { recursive: true });
98
96
  const dictionariesTypesDefinitions = import_fast_glob.default.sync(
99
97
  (0, import_config.normalizePath)(`${typesDir}/*.ts`),
100
98
  {
@@ -102,7 +100,7 @@ const createModuleAugmentation = (configuration = (0, import_config.getConfigura
102
100
  }
103
101
  );
104
102
  const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);
105
- (0, import_fs.writeFileSync)((0, import_path.join)(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
103
+ await (0, import_promises.writeFile)((0, import_path.join)(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
106
104
  };
107
105
  // Annotate the CommonJS export names for ESM import in node:
108
106
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { Locales, getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, join, relative } from 'path';\nimport { getFileHash } from '../../utils/getFileHash';\nimport { kebabCaseToCamelCase } from '../../utils/kebabCaseToCamelCase';\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\nconst formatLocales = (locales: Locales[]): string =>\n locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (\n typeFiles: string[],\n configuration = getConfiguration()\n): string => {\n const { content, internationalization } = configuration;\n const { moduleAugmentationDir } = content;\n const { locales, requiredLocales, strictMode } = internationalization;\n\n let fileContent =\n \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id (without the extension)\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n fileContent += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n });\n\n fileContent += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": typeof ${dictionary.hash};`)\n .join('\\n');\n\n const requiredLocalesValues =\n requiredLocales.length > 0\n ? requiredLocales.filter((locale) =>\n locales.map((locale) => String(locale)).includes(String(locale))\n )\n : locales;\n\n const formattedLocales = formatLocales(locales);\n const formattedRequiredLocales = formatLocales(requiredLocalesValues);\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<DeclaredLocales, Content> {}`\n : strictMode === 'inclusive'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n fileContent += `declare module 'intlayer' {\\n`;\n fileContent += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n fileContent += ` type DeclaredLocales = ${formattedLocales};\\n`;\n fileContent += ` type RequiredLocales = ${formattedRequiredLocales};\\n`;\n fileContent += ` type ExtractedLocales = Extract<Locales, RequiredLocales>;\\n`;\n fileContent += ` type ExcludedLocales = Exclude<Locales, RequiredLocales>;\\n`;\n fileContent += ` ${strictModeRecord}\\n`;\n fileContent += `}`;\n\n return fileContent;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = (\n configuration = getConfiguration()\n) => {\n const { moduleAugmentationDir, typesDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionariesTypesDefinitions: string[] = fg.sync(\n normalizePath(`${typesDir}/*.ts`),\n {\n ignore: ['**/*.d.ts'],\n }\n );\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyD;AACzD,uBAAe;AACf,gBAAqD;AACrD,kBAAkD;AAClD,yBAA4B;AAC5B,kCAAqC;AAE9B,MAAM,cAAc,CAAC,QAC1B,OAAG,kDAAqB,GAAG,CAAC;AAE9B,MAAM,gBAAgB,CAAC,YACrB,QACG,IAAI,CAAC,WAAW;AACf,aAAW,OAAO,uBAAS;AACzB,QAAI,sBAAQ,GAA2B,MAAM,QAAQ;AACnD,aAAO,WAAW,GAAG;AAAA,IACvB;AAAA,EACF;AACF,CAAC,EACA,KAAK,KAAK;AAKf,MAAM,2BAA2B,CAC/B,WACA,oBAAgB,gCAAiB,MACtB;AACX,QAAM,EAAE,SAAS,qBAAqB,IAAI;AAC1C,QAAM,EAAE,sBAAsB,IAAI;AAClC,QAAM,EAAE,SAAS,iBAAiB,WAAW,IAAI;AAEjD,MAAI,cACF;AAEF,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,SAAK,sBAAS,uBAAuB,cAAc,CAAC;AAAA,IAClE,QAAI,sBAAS,oBAAgB,qBAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,QAAI,gCAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,mBAAe,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AAAA,EAC3E,CAAC;AAED,iBAAe;AAGf,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,aAAa,WAAW,IAAI,GAAG,EACxE,KAAK,IAAI;AAEZ,QAAM,wBACJ,gBAAgB,SAAS,IACrB,gBAAgB;AAAA,IAAO,CAAC,WACtB,QAAQ,IAAI,CAACA,YAAW,OAAOA,OAAM,CAAC,EAAE,SAAS,OAAO,MAAM,CAAC;AAAA,EACjE,IACA;AAEN,QAAM,mBAAmB,cAAc,OAAO;AAC9C,QAAM,2BAA2B,cAAc,qBAAqB;AAEpE,QAAM,mBACJ,eAAe,WACX,kFACA,eAAe,cACb,8HACA;AAsBR,iBAAe;AAAA;AACf,iBAAe;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACxF,iBAAe,4BAA4B,gBAAgB;AAAA;AAC3D,iBAAe,4BAA4B,wBAAwB;AAAA;AACnE,iBAAe;AAAA;AACf,iBAAe;AAAA;AACf,iBAAe,KAAK,gBAAgB;AAAA;AACpC,iBAAe;AAEf,SAAO;AACT;AAKO,MAAM,2BAA2B,CACtC,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,uBAAuB,SAAS,IAAI,cAAc;AAG1D,MAAI,KAAC,sBAAW,qBAAqB,GAAG;AACtC,6BAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,+BAAyC,iBAAAC,QAAG;AAAA,QAChD,6BAAc,GAAG,QAAQ,OAAO;AAAA,IAChC;AAAA,MACE,QAAQ,CAAC,WAAW;AAAA,IACtB;AAAA,EACF;AAGA,QAAM,YAAY,yBAAyB,4BAA4B;AACvE,mCAAc,kBAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["locale","fg"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { Locales, getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { basename, extname, join, relative } from 'path';\nimport { getFileHash } from '../../utils/getFileHash';\nimport { kebabCaseToCamelCase } from '../../utils/kebabCaseToCamelCase';\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\nconst formatLocales = (locales: Locales[]): string =>\n locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (\n typeFiles: string[],\n configuration = getConfiguration()\n): string => {\n const { content, internationalization } = configuration;\n const { moduleAugmentationDir } = content;\n const { locales, requiredLocales, strictMode } = internationalization;\n\n let fileContent =\n \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id (without the extension)\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n fileContent += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n });\n\n fileContent += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": typeof ${dictionary.hash};`)\n .join('\\n');\n\n const requiredLocalesValues =\n requiredLocales.length > 0\n ? requiredLocales.filter((locale) =>\n locales.map((locale) => String(locale)).includes(String(locale))\n )\n : locales;\n\n const formattedLocales = formatLocales(locales);\n const formattedRequiredLocales = formatLocales(requiredLocalesValues);\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<DeclaredLocales, Content> {}`\n : strictMode === 'inclusive'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n fileContent += `declare module 'intlayer' {\\n`;\n fileContent += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n fileContent += ` type DeclaredLocales = ${formattedLocales};\\n`;\n fileContent += ` type RequiredLocales = ${formattedRequiredLocales};\\n`;\n fileContent += ` type ExtractedLocales = Extract<Locales, RequiredLocales>;\\n`;\n fileContent += ` type ExcludedLocales = Exclude<Locales, RequiredLocales>;\\n`;\n fileContent += ` ${strictModeRecord}\\n`;\n fileContent += `}`;\n\n return fileContent;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = async (\n configuration = getConfiguration()\n) => {\n const { moduleAugmentationDir, typesDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n await mkdir(moduleAugmentationDir, { recursive: true });\n\n const dictionariesTypesDefinitions: string[] = fg.sync(\n normalizePath(`${typesDir}/*.ts`),\n {\n ignore: ['**/*.d.ts'],\n }\n );\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n await writeFile(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyD;AACzD,uBAAe;AACf,sBAAiC;AACjC,kBAAkD;AAClD,yBAA4B;AAC5B,kCAAqC;AAE9B,MAAM,cAAc,CAAC,QAC1B,OAAG,kDAAqB,GAAG,CAAC;AAE9B,MAAM,gBAAgB,CAAC,YACrB,QACG,IAAI,CAAC,WAAW;AACf,aAAW,OAAO,uBAAS;AACzB,QAAI,sBAAQ,GAA2B,MAAM,QAAQ;AACnD,aAAO,WAAW,GAAG;AAAA,IACvB;AAAA,EACF;AACF,CAAC,EACA,KAAK,KAAK;AAKf,MAAM,2BAA2B,CAC/B,WACA,oBAAgB,gCAAiB,MACtB;AACX,QAAM,EAAE,SAAS,qBAAqB,IAAI;AAC1C,QAAM,EAAE,sBAAsB,IAAI;AAClC,QAAM,EAAE,SAAS,iBAAiB,WAAW,IAAI;AAEjD,MAAI,cACF;AAEF,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,SAAK,sBAAS,uBAAuB,cAAc,CAAC;AAAA,IAClE,QAAI,sBAAS,oBAAgB,qBAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,QAAI,gCAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,mBAAe,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AAAA,EAC3E,CAAC;AAED,iBAAe;AAGf,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,aAAa,WAAW,IAAI,GAAG,EACxE,KAAK,IAAI;AAEZ,QAAM,wBACJ,gBAAgB,SAAS,IACrB,gBAAgB;AAAA,IAAO,CAAC,WACtB,QAAQ,IAAI,CAACA,YAAW,OAAOA,OAAM,CAAC,EAAE,SAAS,OAAO,MAAM,CAAC;AAAA,EACjE,IACA;AAEN,QAAM,mBAAmB,cAAc,OAAO;AAC9C,QAAM,2BAA2B,cAAc,qBAAqB;AAEpE,QAAM,mBACJ,eAAe,WACX,kFACA,eAAe,cACb,8HACA;AAsBR,iBAAe;AAAA;AACf,iBAAe;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACxF,iBAAe,4BAA4B,gBAAgB;AAAA;AAC3D,iBAAe,4BAA4B,wBAAwB;AAAA;AACnE,iBAAe;AAAA;AACf,iBAAe;AAAA;AACf,iBAAe,KAAK,gBAAgB;AAAA;AACpC,iBAAe;AAEf,SAAO;AACT;AAKO,MAAM,2BAA2B,OACtC,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,uBAAuB,SAAS,IAAI,cAAc;AAG1D,YAAM,uBAAM,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAEtD,QAAM,+BAAyC,iBAAAC,QAAG;AAAA,QAChD,6BAAc,GAAG,QAAQ,OAAO;AAAA,IAChC;AAAA,MACE,QAAQ,CAAC,WAAW;AAAA,IACtB;AAAA,EACF;AAGA,QAAM,YAAY,yBAAyB,4BAA4B;AACvE,YAAM,+BAAU,kBAAK,uBAAuB,eAAe,GAAG,SAAS;AACzE;","names":["locale","fg"]}
@@ -23,8 +23,9 @@ __export(createType_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(createType_exports);
25
25
  var import_config = require("@intlayer/config");
26
- var import_fs = require("fs");
26
+ var import_promises = require("fs/promises");
27
27
  var import_path = require("path");
28
+ var import_parallelize = require('../../utils/parallelize.cjs');
28
29
  const requireUncached = (module2) => {
29
30
  delete import_config.ESMxCJSRequire.cache[import_config.ESMxCJSRequire.resolve(module2)];
30
31
  return (0, import_config.ESMxCJSRequire)(module2);
@@ -35,23 +36,23 @@ const generateTypeScriptType = (dictionary) => {
35
36
  export default ${jsonString} as const;
36
37
  `;
37
38
  };
38
- const createTypes = (dictionariesPaths, configuration = (0, import_config.getConfiguration)()) => {
39
+ const createTypes = async (dictionariesPaths, configuration = (0, import_config.getConfiguration)()) => {
39
40
  const { typesDir } = configuration.content;
40
- const resultTypesPaths = [];
41
- if (!(0, import_fs.existsSync)(typesDir)) {
42
- (0, import_fs.mkdirSync)(typesDir, { recursive: true });
43
- }
44
- for (const dictionaryPath of dictionariesPaths) {
45
- const dictionary = requireUncached(dictionaryPath);
46
- if (!dictionary.key) {
47
- continue;
41
+ await (0, import_promises.mkdir)(typesDir, { recursive: true });
42
+ const results = await (0, import_parallelize.parallelize)(
43
+ dictionariesPaths,
44
+ async (dictionaryPath) => {
45
+ const dictionary = requireUncached(dictionaryPath);
46
+ if (!dictionary.key) {
47
+ return void 0;
48
+ }
49
+ const typeDefinition = generateTypeScriptType(dictionary);
50
+ const outputPath = (0, import_path.resolve)(typesDir, `${dictionary.key}.ts`);
51
+ await (0, import_promises.writeFile)(outputPath, typeDefinition);
52
+ return outputPath;
48
53
  }
49
- const typeDefinition = generateTypeScriptType(dictionary);
50
- const outputPath = (0, import_path.resolve)(typesDir, `${dictionary.key}.ts`);
51
- (0, import_fs.writeFileSync)(outputPath, typeDefinition);
52
- resultTypesPaths.push(outputPath);
53
- }
54
- return resultTypesPaths;
54
+ );
55
+ return results.filter(Boolean);
55
56
  };
56
57
  // Annotate the CommonJS export names for ESM import in node:
57
58
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n getConfiguration,\n IntlayerConfig,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\n\nconst requireUncached = (module: string) => {\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];\n return ESMxCJSRequire(module);\n};\n\nexport const generateTypeScriptType = (dictionary: Dictionary) => {\n const jsonString = JSON.stringify(dictionary, null, 2);\n\n return `/* eslint-disable */\\nexport default ${jsonString} as const;\\n`;\n};\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = (\n dictionariesPaths: string[],\n configuration: IntlayerConfig = getConfiguration()\n): string[] => {\n const { typesDir } = configuration.content;\n const resultTypesPaths: string[] = [];\n\n // Create type folders if they don't exist\n if (!existsSync(typesDir)) {\n mkdirSync(typesDir, { recursive: true });\n }\n\n for (const dictionaryPath of dictionariesPaths) {\n const dictionary: Dictionary = requireUncached(dictionaryPath);\n\n if (!dictionary.key) {\n // Skip dictionary if it doesn't have a key, if not exported as default etc\n continue;\n }\n\n const typeDefinition: string = generateTypeScriptType(dictionary);\n\n const outputPath: string = resolve(typesDir, `${dictionary.key}.ts`);\n\n writeFileSync(outputPath, typeDefinition);\n\n resultTypesPaths.push(outputPath);\n }\n\n return resultTypesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAIO;AAEP,gBAAqD;AACrD,kBAAwB;AAExB,MAAM,kBAAkB,CAACA,YAAmB;AAC1C,SAAO,6BAAe,MAAM,6BAAe,QAAQA,OAAM,CAAC;AAC1D,aAAO,8BAAeA,OAAM;AAC9B;AAEO,MAAM,yBAAyB,CAAC,eAA2B;AAChE,QAAM,aAAa,KAAK,UAAU,YAAY,MAAM,CAAC;AAErD,SAAO;AAAA,iBAAwC,UAAU;AAAA;AAC3D;AAIO,MAAM,cAAc,CACzB,mBACA,oBAAgC,gCAAiB,MACpC;AACb,QAAM,EAAE,SAAS,IAAI,cAAc;AACnC,QAAM,mBAA6B,CAAC;AAGpC,MAAI,KAAC,sBAAW,QAAQ,GAAG;AACzB,6BAAU,UAAU,EAAE,WAAW,KAAK,CAAC;AAAA,EACzC;AAEA,aAAW,kBAAkB,mBAAmB;AAC9C,UAAM,aAAyB,gBAAgB,cAAc;AAE7D,QAAI,CAAC,WAAW,KAAK;AAEnB;AAAA,IACF;AAEA,UAAM,iBAAyB,uBAAuB,UAAU;AAEhE,UAAM,iBAAqB,qBAAQ,UAAU,GAAG,WAAW,GAAG,KAAK;AAEnE,iCAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":["module"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n getConfiguration,\n IntlayerConfig,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { parallelize } from '../../utils/parallelize';\n\nconst requireUncached = (module: string) => {\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];\n return ESMxCJSRequire(module);\n};\n\nexport const generateTypeScriptType = (dictionary: Dictionary) => {\n const jsonString = JSON.stringify(dictionary, null, 2);\n\n return `/* eslint-disable */\\nexport default ${jsonString} as const;\\n`;\n};\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = async (\n dictionariesPaths: string[],\n configuration: IntlayerConfig = getConfiguration()\n): Promise<string[]> => {\n const { typesDir } = configuration.content;\n\n // Create type folders if they don't exist\n await mkdir(typesDir, { recursive: true });\n\n const results = await parallelize(\n dictionariesPaths,\n async (dictionaryPath): Promise<string | undefined> => {\n const dictionary: Dictionary = requireUncached(dictionaryPath);\n\n if (!dictionary.key) {\n return undefined;\n }\n\n const typeDefinition: string = generateTypeScriptType(dictionary);\n\n const outputPath: string = resolve(typesDir, `${dictionary.key}.ts`);\n\n await writeFile(outputPath, typeDefinition);\n\n return outputPath;\n }\n );\n\n return results.filter(Boolean) as string[];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAIO;AAEP,sBAAiC;AACjC,kBAAwB;AACxB,yBAA4B;AAE5B,MAAM,kBAAkB,CAACA,YAAmB;AAC1C,SAAO,6BAAe,MAAM,6BAAe,QAAQA,OAAM,CAAC;AAC1D,aAAO,8BAAeA,OAAM;AAC9B;AAEO,MAAM,yBAAyB,CAAC,eAA2B;AAChE,QAAM,aAAa,KAAK,UAAU,YAAY,MAAM,CAAC;AAErD,SAAO;AAAA,iBAAwC,UAAU;AAAA;AAC3D;AAIO,MAAM,cAAc,OACzB,mBACA,oBAAgC,gCAAiB,MAC3B;AACtB,QAAM,EAAE,SAAS,IAAI,cAAc;AAGnC,YAAM,uBAAM,UAAU,EAAE,WAAW,KAAK,CAAC;AAEzC,QAAM,UAAU,UAAM;AAAA,IACpB;AAAA,IACA,OAAO,mBAAgD;AACrD,YAAM,aAAyB,gBAAgB,cAAc;AAE7D,UAAI,CAAC,WAAW,KAAK;AACnB,eAAO;AAAA,MACT;AAEA,YAAM,iBAAyB,uBAAuB,UAAU;AAEhE,YAAM,iBAAqB,qBAAQ,UAAU,GAAG,WAAW,GAAG,KAAK;AAEnE,gBAAM,2BAAU,YAAY,cAAc;AAE1C,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO,QAAQ,OAAO,OAAO;AAC/B;","names":["module"]}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var formatter_exports = {};
30
+ __export(formatter_exports, {
31
+ formatLocale: () => formatLocale,
32
+ formatPath: () => formatPath
33
+ });
34
+ module.exports = __toCommonJS(formatter_exports);
35
+ var import_config = require("@intlayer/config");
36
+ var import_built = __toESM(require("@intlayer/config/built"));
37
+ var import_core = require("@intlayer/core");
38
+ var import_path = require("path");
39
+ const formatPath = (path, color) => [path].flat().map(
40
+ (path2) => path2.startsWith("/") ? (0, import_path.relative)(import_built.default.content.baseDir, path2) : path2
41
+ ).map(
42
+ (relativePath) => color === false ? relativePath : (0, import_config.colorizePath)(relativePath, color)
43
+ ).join(`, `);
44
+ const formatLocale = (locale, color = import_config.ANSIColors.GREEN) => [locale].flat().map((locale2) => `${(0, import_core.getLocaleName)(locale2, import_config.Locales.ENGLISH)} (${locale2})`).map((text) => color === false ? text : (0, import_config.colorize)(text, color)).join(`, `);
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ formatLocale,
48
+ formatPath
49
+ });
50
+ //# sourceMappingURL=formatter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/formatter.ts"],"sourcesContent":["import { ANSIColors, colorize, colorizePath, Locales } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { getLocaleName } from '@intlayer/core';\nimport { relative } from 'path';\n\nexport const formatPath = (\n path: string | string[],\n color?: ANSIColors | false\n) =>\n [path]\n .flat()\n .map((path) =>\n path.startsWith('/')\n ? relative(configuration.content.baseDir, path)\n : path\n )\n .map((relativePath) =>\n color === false ? relativePath : colorizePath(relativePath, color)\n )\n .join(`, `);\n\nexport const formatLocale = (\n locale: Locales | Locales[],\n color: ANSIColors | false = ANSIColors.GREEN\n) =>\n [locale]\n .flat()\n .map((locale) => `${getLocaleName(locale, Locales.ENGLISH)} (${locale})`)\n .map((text) => (color === false ? text : colorize(text, color)))\n .join(`, `);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4D;AAC5D,mBAA0B;AAC1B,kBAA8B;AAC9B,kBAAyB;AAElB,MAAM,aAAa,CACxB,MACA,UAEA,CAAC,IAAI,EACF,KAAK,EACL;AAAA,EAAI,CAACA,UACJA,MAAK,WAAW,GAAG,QACf,sBAAS,aAAAC,QAAc,QAAQ,SAASD,KAAI,IAC5CA;AACN,EACC;AAAA,EAAI,CAAC,iBACJ,UAAU,QAAQ,mBAAe,4BAAa,cAAc,KAAK;AACnE,EACC,KAAK,IAAI;AAEP,MAAM,eAAe,CAC1B,QACA,QAA4B,yBAAW,UAEvC,CAAC,MAAM,EACJ,KAAK,EACL,IAAI,CAACE,YAAW,OAAG,2BAAcA,SAAQ,sBAAQ,OAAO,CAAC,KAAKA,OAAM,GAAG,EACvE,IAAI,CAAC,SAAU,UAAU,QAAQ,WAAO,wBAAS,MAAM,KAAK,CAAE,EAC9D,KAAK,IAAI;","names":["path","configuration","locale"]}