@intlayer/chokidar 5.8.1 → 6.0.0-canary.1

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 (219) 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} +11 -19
  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 +13 -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 +108 -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/dictionaryStatus.cjs.map +1 -1
  59. package/dist/cjs/writeContentDeclaration/formatCode.cjs +7 -4
  60. package/dist/cjs/writeContentDeclaration/formatCode.cjs.map +1 -1
  61. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +6 -2
  62. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
  63. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +43 -25
  64. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
  65. package/dist/esm/chokidar/watcher.mjs +16 -21
  66. package/dist/esm/chokidar/watcher.mjs.map +1 -1
  67. package/dist/esm/fetchDistantDictionaries.mjs +24 -28
  68. package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
  69. package/dist/esm/fetchDistantDictionaryKeysAndUpdateTimestamp.mjs +21 -0
  70. package/dist/esm/fetchDistantDictionaryKeysAndUpdateTimestamp.mjs.map +1 -0
  71. package/dist/esm/filterInvalidDictionaries.mjs +40 -0
  72. package/dist/esm/filterInvalidDictionaries.mjs.map +1 -0
  73. package/dist/esm/getBuiltFetchDictionariesPath.mjs +18 -0
  74. package/dist/esm/getBuiltFetchDictionariesPath.mjs.map +1 -0
  75. package/dist/esm/getBuiltRemoteDictionariesPath.mjs +17 -0
  76. package/dist/esm/getBuiltRemoteDictionariesPath.mjs.map +1 -0
  77. package/dist/esm/index.mjs +10 -9
  78. package/dist/esm/index.mjs.map +1 -1
  79. package/dist/esm/loadDictionaries/index.mjs +2 -2
  80. package/dist/esm/loadDictionaries/index.mjs.map +1 -1
  81. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +61 -18
  82. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
  83. package/dist/esm/loadDictionaries/loadDictionaries.mjs +132 -53
  84. package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
  85. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +73 -0
  86. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -0
  87. package/dist/esm/loadDictionaries/log.mjs +125 -0
  88. package/dist/esm/loadDictionaries/log.mjs.map +1 -0
  89. package/dist/esm/mergeDictionaries.mjs +19 -23
  90. package/dist/esm/mergeDictionaries.mjs.map +1 -1
  91. package/dist/esm/orderDictionaries.mjs +37 -0
  92. package/dist/esm/orderDictionaries.mjs.map +1 -0
  93. package/dist/esm/prepareContentDeclaration.mjs +4 -1
  94. package/dist/esm/prepareContentDeclaration.mjs.map +1 -1
  95. package/dist/esm/prepareIntlayer.mjs +9 -4
  96. package/dist/esm/prepareIntlayer.mjs.map +1 -1
  97. package/dist/esm/processPerLocaleDictionary.mjs.map +1 -1
  98. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs +25 -9
  99. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -1
  100. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs +45 -43
  101. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs.map +1 -1
  102. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs +58 -0
  103. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs.map +1 -0
  104. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs +29 -21
  105. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs.map +1 -1
  106. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs +28 -0
  107. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs.map +1 -0
  108. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs +45 -30
  109. package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs.map +1 -1
  110. package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +39 -34
  111. package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
  112. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +4 -6
  113. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
  114. package/dist/esm/transpiler/dictionary_to_type/createType.mjs +17 -16
  115. package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
  116. package/dist/esm/utils/formatter.mjs +15 -0
  117. package/dist/esm/utils/formatter.mjs.map +1 -0
  118. package/dist/esm/utils/parallelize.mjs +9 -0
  119. package/dist/esm/utils/parallelize.mjs.map +1 -0
  120. package/dist/esm/utils/runOnce.mjs +2 -1
  121. package/dist/esm/utils/runOnce.mjs.map +1 -1
  122. package/dist/esm/writeContentDeclaration/formatCode.mjs +8 -5
  123. package/dist/esm/writeContentDeclaration/formatCode.mjs.map +1 -1
  124. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +6 -2
  125. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
  126. package/dist/esm/writeContentDeclaration/writeJSFile.mjs +40 -22
  127. package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
  128. package/dist/types/chokidar/watcher.d.ts.map +1 -1
  129. package/dist/types/fetchDistantDictionaries.d.ts +2 -1
  130. package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
  131. package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts +3 -0
  132. package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts.map +1 -0
  133. package/dist/types/filterInvalidDictionaries.d.ts +3 -0
  134. package/dist/types/filterInvalidDictionaries.d.ts.map +1 -0
  135. package/dist/types/getBuiltFetchDictionariesPath.d.ts +5 -0
  136. package/dist/types/getBuiltFetchDictionariesPath.d.ts.map +1 -0
  137. package/dist/types/getBuiltRemoteDictionariesPath.d.ts +5 -0
  138. package/dist/types/getBuiltRemoteDictionariesPath.d.ts.map +1 -0
  139. package/dist/types/index.d.ts +4 -4
  140. package/dist/types/index.d.ts.map +1 -1
  141. package/dist/types/loadDictionaries/index.d.ts +2 -2
  142. package/dist/types/loadDictionaries/index.d.ts.map +1 -1
  143. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +4 -1
  144. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
  145. package/dist/types/loadDictionaries/loadDictionaries.d.ts +11 -1
  146. package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
  147. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +6 -0
  148. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -0
  149. package/dist/types/loadDictionaries/log.d.ts +19 -0
  150. package/dist/types/loadDictionaries/log.d.ts.map +1 -0
  151. package/dist/types/mergeDictionaries.d.ts +1 -1
  152. package/dist/types/mergeDictionaries.d.ts.map +1 -1
  153. package/dist/types/orderDictionaries.d.ts +10 -0
  154. package/dist/types/orderDictionaries.d.ts.map +1 -0
  155. package/dist/types/prepareContentDeclaration.d.ts.map +1 -1
  156. package/dist/types/prepareIntlayer.d.ts.map +1 -1
  157. package/dist/types/processPerLocaleDictionary.d.ts +1 -1
  158. package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +1 -0
  159. package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts.map +1 -1
  160. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +4 -3
  161. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +1 -1
  162. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts +1 -1
  163. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts.map +1 -1
  164. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts +23 -0
  165. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts.map +1 -0
  166. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts +1 -1
  167. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts.map +1 -1
  168. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts +19 -0
  169. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts.map +1 -0
  170. package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.d.ts.map +1 -1
  171. package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts +1 -1
  172. package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts.map +1 -1
  173. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +1 -1
  174. package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts.map +1 -1
  175. package/dist/types/transpiler/dictionary_to_type/createType.d.ts +1 -1
  176. package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +1 -1
  177. package/dist/types/utils/formatter.d.ts +4 -0
  178. package/dist/types/utils/formatter.d.ts.map +1 -0
  179. package/dist/types/utils/parallelize.d.ts +2 -0
  180. package/dist/types/utils/parallelize.d.ts.map +1 -0
  181. package/dist/types/utils/runOnce.d.ts +1 -1
  182. package/dist/types/utils/runOnce.d.ts.map +1 -1
  183. package/dist/types/writeContentDeclaration/dictionaryStatus.d.ts +1 -1
  184. package/dist/types/writeContentDeclaration/dictionaryStatus.d.ts.map +1 -1
  185. package/dist/types/writeContentDeclaration/formatCode.d.ts.map +1 -1
  186. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +1 -1
  187. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
  188. package/dist/types/writeContentDeclaration/writeJSFile.d.ts +1 -1
  189. package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -1
  190. package/package.json +17 -15
  191. package/dist/cjs/checkDictionaryChanges.cjs +0 -58
  192. package/dist/cjs/checkDictionaryChanges.cjs.map +0 -1
  193. package/dist/cjs/fetchDistantDictionaryKeys.cjs.map +0 -1
  194. package/dist/cjs/getFilteredLocalesContent.cjs +0 -70
  195. package/dist/cjs/getFilteredLocalesContent.cjs.map +0 -1
  196. package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs +0 -44
  197. package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs.map +0 -1
  198. package/dist/cjs/log.cjs +0 -296
  199. package/dist/cjs/log.cjs.map +0 -1
  200. package/dist/esm/checkDictionaryChanges.mjs +0 -37
  201. package/dist/esm/checkDictionaryChanges.mjs.map +0 -1
  202. package/dist/esm/fetchDistantDictionaryKeys.mjs +0 -29
  203. package/dist/esm/fetchDistantDictionaryKeys.mjs.map +0 -1
  204. package/dist/esm/getFilteredLocalesContent.mjs +0 -49
  205. package/dist/esm/getFilteredLocalesContent.mjs.map +0 -1
  206. package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs +0 -20
  207. package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs.map +0 -1
  208. package/dist/esm/log.mjs +0 -262
  209. package/dist/esm/log.mjs.map +0 -1
  210. package/dist/types/checkDictionaryChanges.d.ts +0 -3
  211. package/dist/types/checkDictionaryChanges.d.ts.map +0 -1
  212. package/dist/types/fetchDistantDictionaryKeys.d.ts +0 -3
  213. package/dist/types/fetchDistantDictionaryKeys.d.ts.map +0 -1
  214. package/dist/types/getFilteredLocalesContent.d.ts +0 -4
  215. package/dist/types/getFilteredLocalesContent.d.ts.map +0 -1
  216. package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts +0 -8
  217. package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts.map +0 -1
  218. package/dist/types/log.d.ts +0 -45
  219. package/dist/types/log.d.ts.map +0 -1
@@ -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,SAAS,wBAAwB;AAEjC,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,yBAAyB;AAClC,SAAS,kCAAkC;AAC3C,SAAS,4BAA4B;AA0B9B,MAAM,0BAA0B,OACrC,qBACA,gBAAgB,iBAAiB,MACG;AACpC,QAAM,EAAE,gBAAgB,IAAI,cAAc;AAG1C,QAAM,MAAM,QAAQ,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,eAAe,2BAA2B,UAAU;AAAA,IACvD;AAEA,UAAM,mBAAmB,kBAAkB,uBAAuB;AAElE,UAAM,gBAAgB,qBAAqB,gBAAgB;AAE3D,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,iBAAiB,QAAQ,iBAAiB,cAAc;AAG9D,UAAM,UAAU,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,SAAS,wBAAwB;AAEjC,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,yBAAyB;AAClC,SAAS,kCAAkC;AAC3C,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AA0B9B,MAAM,0BAA0B,OACrC,qBACA,gBAAgB,iBAAiB,MACG;AACpC,QAAM,EAAE,gBAAgB,IAAI,cAAc;AAG1C,QAAM,MAAM,QAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,QAAM,UAAU,MAAM;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,eAAe,2BAA2B,UAAU;AAAA,MACvD;AAEA,YAAM,mBAAmB,kBAAkB,uBAAuB;AAElE,YAAM,gBAAgB,qBAAqB,gBAAgB;AAE3D,YAAM,iBAAiB,GAAG,GAAG;AAC7B,YAAM,iBAAiB,QAAQ,iBAAiB,cAAc;AAG9D,YAAM,UAAU,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,28 @@
1
+ import { getConfiguration } from "@intlayer/config";
2
+ import { mkdir, writeFile } from "fs/promises";
3
+ import { resolve } from "path";
4
+ import { filterInvalidDictionaries } from "../../../filterInvalidDictionaries.mjs";
5
+ import { formatDistantDictionaries } from "../../../loadDictionaries/index.mjs";
6
+ import { parallelize } from "../../../utils/parallelize.mjs";
7
+ import { formatDictionaryText } from "./formatDictionaryText.mjs";
8
+ const writeRemoteDictionary = async (remoteDictionaries, configuration = getConfiguration()) => {
9
+ const { remoteDictionariesDir } = configuration.content;
10
+ await mkdir(resolve(remoteDictionariesDir), { recursive: true });
11
+ const filteredDictionaries = filterInvalidDictionaries(remoteDictionaries);
12
+ await parallelize(
13
+ filteredDictionaries.filter((dictionary) => dictionary.key !== "undefined"),
14
+ async (dictionary) => {
15
+ const outputFileName = `${dictionary.key}.json`;
16
+ const resultFilePath = resolve(remoteDictionariesDir, outputFileName);
17
+ const contentString = formatDictionaryText(dictionary);
18
+ await writeFile(resultFilePath, contentString, "utf8").catch((err) => {
19
+ console.error(`Error creating merged ${outputFileName}:`, err);
20
+ });
21
+ }
22
+ );
23
+ return formatDistantDictionaries(remoteDictionaries);
24
+ };
25
+ export {
26
+ writeRemoteDictionary
27
+ };
28
+ //# sourceMappingURL=writeRemoteDictionary.mjs.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,SAAS,wBAAwB;AAEjC,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,iCAAiC;AAC1C,SAAS,iCAAiC;AAC1C,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AAkB9B,MAAM,wBAAwB,OACnC,oBACA,gBAAgB,iBAAiB,MACP;AAC1B,QAAM,EAAE,sBAAsB,IAAI,cAAc;AAGhD,QAAM,MAAM,QAAQ,qBAAqB,GAAG,EAAE,WAAW,KAAK,CAAC;AAE/D,QAAM,uBAAuB,0BAA0B,kBAAkB;AAGzE,QAAM;AAAA,IACJ,qBAAqB,OAAO,CAAC,eAAe,WAAW,QAAQ,WAAW;AAAA,IAC1E,OAAO,eAAe;AACpB,YAAM,iBAAiB,GAAG,WAAW,GAAG;AACxC,YAAM,iBAAiB,QAAQ,uBAAuB,cAAc;AAEpE,YAAM,gBAAgB,qBAAqB,UAAU;AAGrD,YAAM,UAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,gBAAQ,MAAM,yBAAyB,cAAc,KAAK,GAAG;AAAA,MAC/D,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,0BAA0B,kBAAkB;AACrD;","names":[]}
@@ -1,39 +1,54 @@
1
- import { getConfiguration } from "@intlayer/config";
1
+ import { getConfiguration, x } from "@intlayer/config";
2
2
  import { mkdir, writeFile } from "fs/promises";
3
3
  import { resolve } from "path";
4
+ import { filterInvalidDictionaries } from "../../../filterInvalidDictionaries.mjs";
5
+ import { orderDictionaries } from "../../../orderDictionaries.mjs";
6
+ import { parallelize } from "../../../utils/parallelize.mjs";
4
7
  import { formatDictionaryText } from "./formatDictionaryText.mjs";
5
- const groupDictionariesByKey = (dictionaries) => {
6
- return dictionaries.reduce(
7
- (acc, dictionary) => {
8
- const key = dictionary.key;
9
- if (!acc[key]) {
10
- acc[key] = [];
11
- }
12
- acc[key].push(dictionary);
13
- return acc;
14
- },
15
- {}
16
- );
17
- };
8
+ const groupDictionariesByKey = (dictionaries) => dictionaries.reduce(
9
+ (acc, dictionary) => {
10
+ const key = dictionary.key;
11
+ if (!acc[key]) {
12
+ acc[key] = [];
13
+ }
14
+ acc[key].push(dictionary);
15
+ return acc;
16
+ },
17
+ {}
18
+ );
18
19
  const writeUnmergedDictionaries = async (dictionaries, configuration = getConfiguration()) => {
19
20
  const { unmergedDictionariesDir } = configuration.content;
20
21
  await mkdir(resolve(unmergedDictionariesDir), { recursive: true });
21
- const groupedDictionaries = groupDictionariesByKey(dictionaries);
22
- let resultDictionariesPaths = {};
23
- for await (const [key, dictionaries2] of Object.entries(groupedDictionaries)) {
24
- if (key === "undefined") continue;
25
- const contentString = formatDictionaryText(dictionaries2);
26
- const outputFileName = `${key}.json`;
27
- const unmergedFilePath = resolve(unmergedDictionariesDir, outputFileName);
28
- await writeFile(unmergedFilePath, contentString, "utf8").catch((err) => {
29
- console.error(`Error creating unmerged ${outputFileName}:`, err);
30
- });
31
- resultDictionariesPaths[key] = {
32
- dictionaryPath: unmergedFilePath,
33
- dictionaries: dictionaries2
34
- };
35
- }
36
- return resultDictionariesPaths;
22
+ const filteredDictionaries = filterInvalidDictionaries(dictionaries);
23
+ const groupedDictionaries = groupDictionariesByKey(filteredDictionaries);
24
+ const results = await parallelize(
25
+ Object.entries(groupedDictionaries),
26
+ async ([key, dictionaries2]) => {
27
+ if (key === "undefined") {
28
+ return void 0;
29
+ }
30
+ const orderedDictionaries = orderDictionaries(
31
+ dictionaries2,
32
+ configuration
33
+ );
34
+ const contentString = formatDictionaryText(orderedDictionaries);
35
+ const outputFileName = `${key}.json`;
36
+ const unmergedFilePath = resolve(unmergedDictionariesDir, outputFileName);
37
+ await writeFile(unmergedFilePath, contentString, "utf8").catch((err) => {
38
+ console.error(`${x} Error creating unmerged ${outputFileName}:`, err);
39
+ });
40
+ return [
41
+ key,
42
+ {
43
+ dictionaryPath: unmergedFilePath,
44
+ dictionaries: dictionaries2
45
+ }
46
+ ];
47
+ }
48
+ );
49
+ return Object.fromEntries(
50
+ results.filter(Boolean)
51
+ );
37
52
  };
38
53
  export {
39
54
  writeUnmergedDictionaries
@@ -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,SAAS,wBAAwB;AAEjC,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,4BAA4B;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,gBAAgB,iBAAiB,MACK;AACtC,QAAM,EAAE,wBAAwB,IAAI,cAAc;AAGlD,QAAM,MAAM,QAAQ,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,gBAAgB,qBAAqBA,aAAY;AAEvD,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,mBAAmB,QAAQ,yBAAyB,cAAc;AAGxE,UAAM,UAAU,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,SAAS,kBAAkB,SAAS;AAEpC,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,iCAAiC;AAC1C,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;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,gBAAgB,iBAAiB,MACK;AACtC,QAAM,EAAE,wBAAwB,IAAI,cAAc;AAGlD,QAAM,MAAM,QAAQ,uBAAuB,GAAG,EAAE,WAAW,KAAK,CAAC;AAEjE,QAAM,uBAAuB,0BAA0B,YAAY;AAGnE,QAAM,sBAAsB,uBAAuB,oBAAoB;AAEvE,QAAM,UAAU,MAAM;AAAA,IACpB,OAAO,QAAQ,mBAAmB;AAAA,IAClC,OAAO,CAAC,KAAKA,aAAY,MAAM;AAC7B,UAAI,QAAQ,aAAa;AACvB,eAAO;AAAA,MAIT;AAEA,YAAM,sBAAsB;AAAA,QAC1BA;AAAA,QACA;AAAA,MACF;AACA,YAAM,gBAAgB,qBAAqB,mBAAmB;AAE9D,YAAM,iBAAiB,GAAG,GAAG;AAC7B,YAAM,mBAAmB,QAAQ,yBAAyB,cAAc;AAGxE,YAAM,UAAU,kBAAkB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACtE,gBAAQ,MAAM,GAAG,CAAC,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"]}
@@ -1,9 +1,12 @@
1
1
  import { getConfiguration } from "@intlayer/config";
2
- import { existsSync, mkdirSync, writeFileSync } from "fs";
2
+ import { mkdir, writeFile } from "fs/promises";
3
3
  import { resolve } from "path";
4
4
  import { getBuiltDictionariesPath } from "../../getBuiltDictionariesPath.mjs";
5
5
  import { getBuiltDynamicDictionariesPath } from "../../getBuiltDynamicDictionariesPath.mjs";
6
+ import { getBuiltFetchDictionariesPath } from "../../getBuiltFetchDictionariesPath.mjs";
7
+ import { getBuiltRemoteDictionariesPath } from "../../getBuiltRemoteDictionariesPath.mjs";
6
8
  import { getBuiltUnmergedDictionariesPath } from "../../getBuiltUnmergedDictionariesPath.mjs";
9
+ import { parallelize } from "../../utils/parallelize.mjs";
7
10
  import { generateDictionaryListContent } from "./generateDictionaryListContent.mjs";
8
11
  const filterDictionaries = (paths, keys) => {
9
12
  if (!keys) return paths;
@@ -11,50 +14,52 @@ const filterDictionaries = (paths, keys) => {
11
14
  (path) => keys.some((key) => path.endsWith(`${key}.json`))
12
15
  );
13
16
  };
14
- const writeDictionaryFiles = (paths, fileName, format, configuration = getConfiguration()) => {
17
+ const writeDictionaryFiles = async (paths, fileName, format, configuration = getConfiguration()) => {
15
18
  const content = generateDictionaryListContent(paths, format, configuration);
16
19
  const extension = format === "cjs" ? "cjs" : "mjs";
17
20
  const { mainDir } = configuration.content;
18
- writeFileSync(resolve(mainDir, `${fileName}.${extension}`), content);
21
+ await writeFile(resolve(mainDir, `${fileName}.${extension}`), content);
19
22
  };
20
- const createDictionaryEntryPoint = (configuration = getConfiguration(), dictionariesKeys, formats = ["cjs", "esm"]) => {
23
+ const createDictionaryEntryPoint = async (configuration = getConfiguration(), dictionariesKeys, formats = ["cjs", "esm"]) => {
21
24
  const { mainDir } = configuration.content;
22
- if (!existsSync(mainDir)) {
23
- mkdirSync(mainDir, { recursive: true });
24
- }
25
+ await mkdir(mainDir, { recursive: true });
26
+ const remoteDictionariesPath = getBuiltRemoteDictionariesPath(configuration);
25
27
  const dictionariesPath = filterDictionaries(
26
28
  getBuiltDictionariesPath(configuration),
27
29
  dictionariesKeys
28
30
  );
29
- for (const format of formats) {
30
- writeDictionaryFiles(
31
- dictionariesPath,
32
- "dictionaries",
33
- format,
34
- configuration
35
- );
36
- }
37
31
  const unmergedDictionariesPath = getBuiltUnmergedDictionariesPath(configuration);
38
- for (const format of formats) {
39
- writeDictionaryFiles(
40
- unmergedDictionariesPath,
41
- "unmerged_dictionaries",
42
- format,
43
- configuration
44
- );
45
- }
46
- for (const format of formats) {
47
- const dynamicDictionariesPathCJS = getBuiltDynamicDictionariesPath(
48
- configuration,
32
+ const writeOperations = [
33
+ ...formats.map((format) => ({
34
+ paths: remoteDictionariesPath,
35
+ fileName: "remote_dictionaries",
49
36
  format
50
- );
51
- writeDictionaryFiles(
52
- dynamicDictionariesPathCJS,
53
- "dynamic_dictionaries",
54
- format,
55
- configuration
56
- );
57
- }
37
+ })),
38
+ ...formats.map((format) => ({
39
+ paths: dictionariesPath,
40
+ fileName: "dictionaries",
41
+ format
42
+ })),
43
+ ...formats.map((format) => ({
44
+ paths: unmergedDictionariesPath,
45
+ fileName: "unmerged_dictionaries",
46
+ format
47
+ })),
48
+ ...formats.map((format) => ({
49
+ paths: getBuiltDynamicDictionariesPath(configuration, format),
50
+ fileName: "dynamic_dictionaries",
51
+ format
52
+ })),
53
+ ...formats.map((format) => ({
54
+ paths: getBuiltFetchDictionariesPath(configuration, format),
55
+ fileName: "fetch_dictionaries",
56
+ format
57
+ }))
58
+ ];
59
+ await parallelize(
60
+ writeOperations,
61
+ async ({ paths, fileName, format }) => writeDictionaryFiles(paths, fileName, format, configuration)
62
+ );
58
63
  };
59
64
  export {
60
65
  createDictionaryEntryPoint
@@ -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,SAAS,wBAAwB;AACjC,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,eAAe;AACxB,SAAS,gCAAgC;AACzC,SAAS,uCAAuC;AAChD,SAAS,wCAAwC;AACjD,SAAS,qCAAqC;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,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,UAAU,8BAA8B,OAAO,QAAQ,aAAa;AAC1E,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,gBAAc,QAAQ,SAAS,GAAG,QAAQ,IAAI,SAAS,EAAE,GAAG,OAAO;AACrE;AAKO,MAAM,6BAA6B,CACxC,gBAAgB,iBAAiB,GACjC,kBACA,UAA6B,CAAC,OAAO,KAAK,MACvC;AACH,QAAM,EAAE,QAAQ,IAAI,cAAc;AAGlC,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAAmB;AAAA,IACvB,yBAAyB,aAAa;AAAA,IACtC;AAAA,EACF;AAEA,aAAW,UAAU,SAAS;AAC5B;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,2BACJ,iCAAiC,aAAa;AAEhD,aAAW,UAAU,SAAS;AAC5B;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,aAAW,UAAU,SAAS;AAC5B,UAAM,6BAA6B;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,SAAS,wBAAwB;AACjC,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,gCAAgC;AACzC,SAAS,uCAAuC;AAChD,SAAS,qCAAqC;AAC9C,SAAS,sCAAsC;AAC/C,SAAS,wCAAwC;AACjD,SAAS,mBAAmB;AAC5B,SAAS,qCAAqC;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,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,UAAU,8BAA8B,OAAO,QAAQ,aAAa;AAC1E,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,QAAM,UAAU,QAAQ,SAAS,GAAG,QAAQ,IAAI,SAAS,EAAE,GAAG,OAAO;AACvE;AAKO,MAAM,6BAA6B,OACxC,gBAAgB,iBAAiB,GACjC,kBACA,UAA6B,CAAC,OAAO,KAAK,MACvC;AACH,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,QAAM,MAAM,SAAS,EAAE,WAAW,KAAK,CAAC;AAExC,QAAM,yBAAyB,+BAA+B,aAAa;AAC3E,QAAM,mBAAmB;AAAA,IACvB,yBAAyB,aAAa;AAAA,IACtC;AAAA,EACF;AACA,QAAM,2BACJ,iCAAiC,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,OAAO,gCAAgC,eAAe,MAAM;AAAA,MAC5D,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO,8BAA8B,eAAe,MAAM;AAAA,MAC1D,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,QAAM;AAAA,IAAY;AAAA,IAAiB,OAAO,EAAE,OAAO,UAAU,OAAO,MAClE,qBAAqB,OAAO,UAAU,QAAQ,aAAa;AAAA,EAC7D;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import { Locales, getConfiguration, normalizePath } from "@intlayer/config";
2
2
  import fg from "fast-glob";
3
- import { existsSync, mkdirSync, writeFileSync } from "fs";
3
+ import { mkdir, writeFile } from "fs/promises";
4
4
  import { basename, extname, join, relative } from "path";
5
5
  import { getFileHash } from "../../utils/getFileHash.mjs";
6
6
  import { kebabCaseToCamelCase } from "../../utils/kebabCaseToCamelCase.mjs";
@@ -56,11 +56,9 @@ ${formattedDictionaryMap}
56
56
  fileContent += `}`;
57
57
  return fileContent;
58
58
  };
59
- const createModuleAugmentation = (configuration = getConfiguration()) => {
59
+ const createModuleAugmentation = async (configuration = getConfiguration()) => {
60
60
  const { moduleAugmentationDir, typesDir } = configuration.content;
61
- if (!existsSync(moduleAugmentationDir)) {
62
- mkdirSync(moduleAugmentationDir, { recursive: true });
63
- }
61
+ await mkdir(moduleAugmentationDir, { recursive: true });
64
62
  const dictionariesTypesDefinitions = fg.sync(
65
63
  normalizePath(`${typesDir}/*.ts`),
66
64
  {
@@ -68,7 +66,7 @@ const createModuleAugmentation = (configuration = getConfiguration()) => {
68
66
  }
69
67
  );
70
68
  const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);
71
- writeFileSync(join(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
69
+ await writeFile(join(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
72
70
  };
73
71
  export {
74
72
  createModuleAugmentation,
@@ -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,SAAS,SAAS,kBAAkB,qBAAqB;AACzD,OAAO,QAAQ;AACf,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,SAAS,MAAM,gBAAgB;AAClD,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AAE9B,MAAM,cAAc,CAAC,QAC1B,GAAG,qBAAqB,GAAG,CAAC;AAE9B,MAAM,gBAAgB,CAAC,YACrB,QACG,IAAI,CAAC,WAAW;AACf,aAAW,OAAO,SAAS;AACzB,QAAI,QAAQ,GAA2B,MAAM,QAAQ;AACnD,aAAO,WAAW,GAAG;AAAA,IACvB;AAAA,EACF;AACF,CAAC,EACA,KAAK,KAAK;AAKf,MAAM,2BAA2B,CAC/B,WACA,gBAAgB,iBAAiB,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,KAAK,SAAS,uBAAuB,cAAc,CAAC;AAAA,IAClE,IAAI,SAAS,gBAAgB,QAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,IAAI,YAAY,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,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,EAAE,uBAAuB,SAAS,IAAI,cAAc;AAG1D,MAAI,CAAC,WAAW,qBAAqB,GAAG;AACtC,cAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,+BAAyC,GAAG;AAAA,IAChD,cAAc,GAAG,QAAQ,OAAO;AAAA,IAChC;AAAA,MACE,QAAQ,CAAC,WAAW;AAAA,IACtB;AAAA,EACF;AAGA,QAAM,YAAY,yBAAyB,4BAA4B;AACvE,gBAAc,KAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["locale"]}
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,SAAS,SAAS,kBAAkB,qBAAqB;AACzD,OAAO,QAAQ;AACf,SAAS,OAAO,iBAAiB;AACjC,SAAS,UAAU,SAAS,MAAM,gBAAgB;AAClD,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AAE9B,MAAM,cAAc,CAAC,QAC1B,GAAG,qBAAqB,GAAG,CAAC;AAE9B,MAAM,gBAAgB,CAAC,YACrB,QACG,IAAI,CAAC,WAAW;AACf,aAAW,OAAO,SAAS;AACzB,QAAI,QAAQ,GAA2B,MAAM,QAAQ;AACnD,aAAO,WAAW,GAAG;AAAA,IACvB;AAAA,EACF;AACF,CAAC,EACA,KAAK,KAAK;AAKf,MAAM,2BAA2B,CAC/B,WACA,gBAAgB,iBAAiB,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,KAAK,SAAS,uBAAuB,cAAc,CAAC;AAAA,IAClE,IAAI,SAAS,gBAAgB,QAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,IAAI,YAAY,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,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,EAAE,uBAAuB,SAAS,IAAI,cAAc;AAG1D,QAAM,MAAM,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAEtD,QAAM,+BAAyC,GAAG;AAAA,IAChD,cAAc,GAAG,QAAQ,OAAO;AAAA,IAChC;AAAA,MACE,QAAQ,CAAC,WAAW;AAAA,IACtB;AAAA,EACF;AAGA,QAAM,YAAY,yBAAyB,4BAA4B;AACvE,QAAM,UAAU,KAAK,uBAAuB,eAAe,GAAG,SAAS;AACzE;","names":["locale"]}
@@ -2,8 +2,9 @@ import {
2
2
  ESMxCJSRequire,
3
3
  getConfiguration
4
4
  } from "@intlayer/config";
5
- import { existsSync, mkdirSync, writeFileSync } from "fs";
5
+ import { mkdir, writeFile } from "fs/promises";
6
6
  import { resolve } from "path";
7
+ import { parallelize } from "../../utils/parallelize.mjs";
7
8
  const requireUncached = (module) => {
8
9
  delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];
9
10
  return ESMxCJSRequire(module);
@@ -14,23 +15,23 @@ const generateTypeScriptType = (dictionary) => {
14
15
  export default ${jsonString} as const;
15
16
  `;
16
17
  };
17
- const createTypes = (dictionariesPaths, configuration = getConfiguration()) => {
18
+ const createTypes = async (dictionariesPaths, configuration = getConfiguration()) => {
18
19
  const { typesDir } = configuration.content;
19
- const resultTypesPaths = [];
20
- if (!existsSync(typesDir)) {
21
- mkdirSync(typesDir, { recursive: true });
22
- }
23
- for (const dictionaryPath of dictionariesPaths) {
24
- const dictionary = requireUncached(dictionaryPath);
25
- if (!dictionary.key) {
26
- continue;
20
+ await mkdir(typesDir, { recursive: true });
21
+ const results = await parallelize(
22
+ dictionariesPaths,
23
+ async (dictionaryPath) => {
24
+ const dictionary = requireUncached(dictionaryPath);
25
+ if (!dictionary.key) {
26
+ return void 0;
27
+ }
28
+ const typeDefinition = generateTypeScriptType(dictionary);
29
+ const outputPath = resolve(typesDir, `${dictionary.key}.ts`);
30
+ await writeFile(outputPath, typeDefinition);
31
+ return outputPath;
27
32
  }
28
- const typeDefinition = generateTypeScriptType(dictionary);
29
- const outputPath = resolve(typesDir, `${dictionary.key}.ts`);
30
- writeFileSync(outputPath, typeDefinition);
31
- resultTypesPaths.push(outputPath);
32
- }
33
- return resultTypesPaths;
33
+ );
34
+ return results.filter(Boolean);
34
35
  };
35
36
  export {
36
37
  createTypes,
@@ -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,EACE;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,eAAe;AAExB,MAAM,kBAAkB,CAAC,WAAmB;AAC1C,SAAO,eAAe,MAAM,eAAe,QAAQ,MAAM,CAAC;AAC1D,SAAO,eAAe,MAAM;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,gBAAgC,iBAAiB,MACpC;AACb,QAAM,EAAE,SAAS,IAAI,cAAc;AACnC,QAAM,mBAA6B,CAAC;AAGpC,MAAI,CAAC,WAAW,QAAQ,GAAG;AACzB,cAAU,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,aAAqB,QAAQ,UAAU,GAAG,WAAW,GAAG,KAAK;AAEnE,kBAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
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,EACE;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAE5B,MAAM,kBAAkB,CAAC,WAAmB;AAC1C,SAAO,eAAe,MAAM,eAAe,QAAQ,MAAM,CAAC;AAC1D,SAAO,eAAe,MAAM;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,gBAAgC,iBAAiB,MAC3B;AACtB,QAAM,EAAE,SAAS,IAAI,cAAc;AAGnC,QAAM,MAAM,UAAU,EAAE,WAAW,KAAK,CAAC;AAEzC,QAAM,UAAU,MAAM;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,aAAqB,QAAQ,UAAU,GAAG,WAAW,GAAG,KAAK;AAEnE,YAAM,UAAU,YAAY,cAAc;AAE1C,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO,QAAQ,OAAO,OAAO;AAC/B;","names":[]}
@@ -0,0 +1,15 @@
1
+ import { ANSIColors, colorize, colorizePath, Locales } from "@intlayer/config";
2
+ import configuration from "@intlayer/config/built";
3
+ import { getLocaleName } from "@intlayer/core";
4
+ import { relative } from "path";
5
+ const formatPath = (path, color) => [path].flat().map(
6
+ (path2) => path2.startsWith("/") ? relative(configuration.content.baseDir, path2) : path2
7
+ ).map(
8
+ (relativePath) => color === false ? relativePath : colorizePath(relativePath, color)
9
+ ).join(`, `);
10
+ const formatLocale = (locale, color = ANSIColors.GREEN) => [locale].flat().map((locale2) => `${getLocaleName(locale2, Locales.ENGLISH)} (${locale2})`).map((text) => color === false ? text : colorize(text, color)).join(`, `);
11
+ export {
12
+ formatLocale,
13
+ formatPath
14
+ };
15
+ //# sourceMappingURL=formatter.mjs.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,SAAS,YAAY,UAAU,cAAc,eAAe;AAC5D,OAAO,mBAAmB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AAElB,MAAM,aAAa,CACxB,MACA,UAEA,CAAC,IAAI,EACF,KAAK,EACL;AAAA,EAAI,CAACA,UACJA,MAAK,WAAW,GAAG,IACf,SAAS,cAAc,QAAQ,SAASA,KAAI,IAC5CA;AACN,EACC;AAAA,EAAI,CAAC,iBACJ,UAAU,QAAQ,eAAe,aAAa,cAAc,KAAK;AACnE,EACC,KAAK,IAAI;AAEP,MAAM,eAAe,CAC1B,QACA,QAA4B,WAAW,UAEvC,CAAC,MAAM,EACJ,KAAK,EACL,IAAI,CAACC,YAAW,GAAG,cAAcA,SAAQ,QAAQ,OAAO,CAAC,KAAKA,OAAM,GAAG,EACvE,IAAI,CAAC,SAAU,UAAU,QAAQ,OAAO,SAAS,MAAM,KAAK,CAAE,EAC9D,KAAK,IAAI;","names":["path","locale"]}
@@ -0,0 +1,9 @@
1
+ import pLimit from "p-limit";
2
+ const parallelize = async (items, callback, parallelLimit = 10) => {
3
+ const limit = pLimit(parallelLimit);
4
+ return Promise.all(items.map((item) => limit(() => callback(item))));
5
+ };
6
+ export {
7
+ parallelize
8
+ };
9
+ //# sourceMappingURL=parallelize.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/parallelize.ts"],"sourcesContent":["import pLimit from 'p-limit';\n\nexport const parallelize = async <T, R>(\n items: T[],\n callback: (item: T) => Promise<R>,\n parallelLimit: number = 10\n): Promise<R[]> => {\n const limit = pLimit(parallelLimit);\n return Promise.all(items.map((item) => limit(() => callback(item))));\n};\n"],"mappings":"AAAA,OAAO,YAAY;AAEZ,MAAM,cAAc,OACzB,OACA,UACA,gBAAwB,OACP;AACjB,QAAM,QAAQ,OAAO,aAAa;AAClC,SAAO,QAAQ,IAAI,MAAM,IAAI,CAAC,SAAS,MAAM,MAAM,SAAS,IAAI,CAAC,CAAC,CAAC;AACrE;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import { mkdir, stat, unlink, writeFile } from "fs/promises";
2
2
  import { dirname } from "path";
3
- const runOnce = async (sentinelFilePath, callback, cacheTimeoutMs = 60 * 1e3) => {
3
+ const runOnce = async (sentinelFilePath, callback, onIsCached, cacheTimeoutMs = 60 * 1e3) => {
4
4
  const currentTimestamp = Date.now();
5
5
  const timeoutDuration = cacheTimeoutMs;
6
6
  try {
@@ -9,6 +9,7 @@ const runOnce = async (sentinelFilePath, callback, cacheTimeoutMs = 60 * 1e3) =>
9
9
  if (sentinelAge > timeoutDuration) {
10
10
  await unlink(sentinelFilePath);
11
11
  } else {
12
+ await onIsCached?.();
12
13
  return;
13
14
  }
14
15
  } catch (err) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/runOnce.ts"],"sourcesContent":["import { mkdir, stat, unlink, writeFile } from 'fs/promises';\nimport { dirname } from 'path';\n\n/**\n * Ensures a callback function runs only once within a specified time window across multiple processes.\n * Uses a sentinel file to coordinate execution and prevent duplicate work.\n *\n * @param sentinelFilePath - Path to the sentinel file used for coordination\n * @param callback - The function to execute (should be async)\n * @param cacheTimeoutMs - Time window in milliseconds during which the sentinel is considered valid (default: 60000ms = 1 minute)\n *\n * @example\n * ```typescript\n * await runPrepareIntlayerOnce(\n * '/tmp/intlayer-sentinel',\n * async () => {\n * // Your initialization logic here\n * await prepareIntlayer();\n * },\n * 30 * 1000 // 30 seconds cache\n * );\n * ```\n *\n * @throws {Error} When there are unexpected filesystem errors\n */\nexport const runOnce = async (\n sentinelFilePath: string,\n callback: () => void | Promise<void>,\n cacheTimeoutMs: number = 60 * 1000 // 1 minute in milliseconds\n) => {\n const currentTimestamp = Date.now();\n const timeoutDuration = cacheTimeoutMs;\n\n try {\n // Check if sentinel file exists and get its stats\n const sentinelStats = await stat(sentinelFilePath);\n const sentinelAge = currentTimestamp - sentinelStats.mtime.getTime();\n\n // If sentinel is older than the timeout, delete it and rebuild\n if (sentinelAge > timeoutDuration) {\n await unlink(sentinelFilePath);\n // Fall through to create new sentinel and rebuild\n } else {\n // Sentinel is recent, no need to rebuild\n return;\n }\n } catch (err: any) {\n if (err.code === 'ENOENT') {\n // File doesn't exist, continue to create it\n } else {\n throw err; // unexpected FS error\n }\n }\n\n try {\n // Ensure the directory exists before writing the file\n await mkdir(dirname(sentinelFilePath), { recursive: true });\n\n // O_EXCL ensures only the *first* process can create the file\n await writeFile(sentinelFilePath, String(currentTimestamp), { flag: 'wx' });\n } catch (err: any) {\n if (err.code === 'EEXIST') {\n // Another process already created it → we're done\n return;\n }\n throw err; // unexpected FS error\n }\n\n await callback();\n};\n"],"mappings":"AAAA,SAAS,OAAO,MAAM,QAAQ,iBAAiB;AAC/C,SAAS,eAAe;AAwBjB,MAAM,UAAU,OACrB,kBACA,UACA,iBAAyB,KAAK,QAC3B;AACH,QAAM,mBAAmB,KAAK,IAAI;AAClC,QAAM,kBAAkB;AAExB,MAAI;AAEF,UAAM,gBAAgB,MAAM,KAAK,gBAAgB;AACjD,UAAM,cAAc,mBAAmB,cAAc,MAAM,QAAQ;AAGnE,QAAI,cAAc,iBAAiB;AACjC,YAAM,OAAO,gBAAgB;AAAA,IAE/B,OAAO;AAEL;AAAA,IACF;AAAA,EACF,SAAS,KAAU;AACjB,QAAI,IAAI,SAAS,UAAU;AAAA,IAE3B,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF;AAEA,MAAI;AAEF,UAAM,MAAM,QAAQ,gBAAgB,GAAG,EAAE,WAAW,KAAK,CAAC;AAG1D,UAAM,UAAU,kBAAkB,OAAO,gBAAgB,GAAG,EAAE,MAAM,KAAK,CAAC;AAAA,EAC5E,SAAS,KAAU;AACjB,QAAI,IAAI,SAAS,UAAU;AAEzB;AAAA,IACF;AACA,UAAM;AAAA,EACR;AAEA,QAAM,SAAS;AACjB;","names":[]}
1
+ {"version":3,"sources":["../../../src/utils/runOnce.ts"],"sourcesContent":["import { mkdir, stat, unlink, writeFile } from 'fs/promises';\nimport { dirname } from 'path';\n\n/**\n * Ensures a callback function runs only once within a specified time window across multiple processes.\n * Uses a sentinel file to coordinate execution and prevent duplicate work.\n *\n * @param sentinelFilePath - Path to the sentinel file used for coordination\n * @param callback - The function to execute (should be async)\n * @param cacheTimeoutMs - Time window in milliseconds during which the sentinel is considered valid (default: 60000ms = 1 minute)\n *\n * @example\n * ```typescript\n * await runPrepareIntlayerOnce(\n * '/tmp/intlayer-sentinel',\n * async () => {\n * // Your initialization logic here\n * await prepareIntlayer();\n * },\n * 30 * 1000 // 30 seconds cache\n * );\n * ```\n *\n * @throws {Error} When there are unexpected filesystem errors\n */\nexport const runOnce = async (\n sentinelFilePath: string,\n callback: () => void | Promise<void>,\n onIsCached?: () => void | Promise<void>,\n cacheTimeoutMs: number = 60 * 1000 // 1 minute in milliseconds\n) => {\n const currentTimestamp = Date.now();\n const timeoutDuration = cacheTimeoutMs;\n\n try {\n // Check if sentinel file exists and get its stats\n const sentinelStats = await stat(sentinelFilePath);\n const sentinelAge = currentTimestamp - sentinelStats.mtime.getTime();\n\n // If sentinel is older than the timeout, delete it and rebuild\n if (sentinelAge > timeoutDuration) {\n await unlink(sentinelFilePath);\n // Fall through to create new sentinel and rebuild\n } else {\n await onIsCached?.();\n // Sentinel is recent, no need to rebuild\n return;\n }\n } catch (err: any) {\n if (err.code === 'ENOENT') {\n // File doesn't exist, continue to create it\n } else {\n throw err; // unexpected FS error\n }\n }\n\n try {\n // Ensure the directory exists before writing the file\n await mkdir(dirname(sentinelFilePath), { recursive: true });\n\n // O_EXCL ensures only the *first* process can create the file\n await writeFile(sentinelFilePath, String(currentTimestamp), { flag: 'wx' });\n } catch (err: any) {\n if (err.code === 'EEXIST') {\n // Another process already created it → we're done\n return;\n }\n throw err; // unexpected FS error\n }\n\n await callback();\n};\n"],"mappings":"AAAA,SAAS,OAAO,MAAM,QAAQ,iBAAiB;AAC/C,SAAS,eAAe;AAwBjB,MAAM,UAAU,OACrB,kBACA,UACA,YACA,iBAAyB,KAAK,QAC3B;AACH,QAAM,mBAAmB,KAAK,IAAI;AAClC,QAAM,kBAAkB;AAExB,MAAI;AAEF,UAAM,gBAAgB,MAAM,KAAK,gBAAgB;AACjD,UAAM,cAAc,mBAAmB,cAAc,MAAM,QAAQ;AAGnE,QAAI,cAAc,iBAAiB;AACjC,YAAM,OAAO,gBAAgB;AAAA,IAE/B,OAAO;AACL,YAAM,aAAa;AAEnB;AAAA,IACF;AAAA,EACF,SAAS,KAAU;AACjB,QAAI,IAAI,SAAS,UAAU;AAAA,IAE3B,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF;AAEA,MAAI;AAEF,UAAM,MAAM,QAAQ,gBAAgB,GAAG,EAAE,WAAW,KAAK,CAAC;AAG1D,UAAM,UAAU,kBAAkB,OAAO,gBAAgB,GAAG,EAAE,MAAM,KAAK,CAAC;AAAA,EAC5E,SAAS,KAAU;AACjB,QAAI,IAAI,SAAS,UAAU;AAEzB;AAAA,IACF;AACA,UAAM;AAAA,EACR;AAEA,QAAM,SAAS;AACjB;","names":[]}
@@ -1,4 +1,4 @@
1
- import { getAppLogger } from "@intlayer/config";
1
+ import { ANSIColors, getAppLogger } from "@intlayer/config";
2
2
  import configuration from "@intlayer/config/built";
3
3
  import { relative } from "path";
4
4
  const formatCode = async (filePath, code) => {
@@ -17,10 +17,13 @@ const formatCode = async (filePath, code) => {
17
17
  // Explicitly provide the filepath so Prettier can infer the parser
18
18
  });
19
19
  const relativePath = relative(configuration.content.baseDir, filePath);
20
- appLogger(`Applied Prettier formatting to ${relativePath}`, {
21
- level: "info",
22
- isVerbose: true
23
- });
20
+ appLogger(
21
+ `Applied Prettier formatting to ${ANSIColors.GREY}${relativePath}${ANSIColors.RESET}`,
22
+ {
23
+ level: "info",
24
+ isVerbose: true
25
+ }
26
+ );
24
27
  return formattedCode;
25
28
  } catch (error) {
26
29
  const err = error;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/writeContentDeclaration/formatCode.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { relative } from 'path';\n\nexport const formatCode = async (filePath: string, code: string) => {\n const appLogger = getAppLogger(configuration);\n // Try to import prettier if it exists\n let prettier: any;\n try {\n prettier = require('prettier');\n } catch (error) {\n // Prettier is not installed, continue without it\n }\n\n // Apply Prettier formatting if it's available\n if (prettier) {\n try {\n // Try to find a prettier config file\n const prettierConfig = await prettier.resolveConfig(filePath ?? '');\n\n // Format the code with Prettier\n const formattedCode = await prettier.format(code, {\n ...prettierConfig,\n filepath: filePath, // Explicitly provide the filepath so Prettier can infer the parser\n });\n\n const relativePath = relative(configuration.content.baseDir, filePath);\n\n appLogger(`Applied Prettier formatting to ${relativePath}`, {\n level: 'info',\n isVerbose: true,\n });\n\n return formattedCode;\n } catch (error) {\n const err = error as Error;\n appLogger(\n `Failed to apply Prettier formatting to ${filePath}: ${err.message}`,\n {\n level: 'warn',\n isVerbose: true,\n }\n );\n // Continue with unformatted code on prettier error\n }\n }\n\n return code;\n};\n"],"mappings":"AAAA,SAAS,oBAAoB;AAC7B,OAAO,mBAAmB;AAC1B,SAAS,gBAAgB;AAElB,MAAM,aAAa,OAAO,UAAkB,SAAiB;AAClE,QAAM,YAAY,aAAa,aAAa;AAE5C,MAAI;AACJ,MAAI;AACF,eAAW,QAAQ,UAAU;AAAA,EAC/B,SAAS,OAAO;AAAA,EAEhB;AAGA,MAAI,UAAU;AACZ,QAAI;AAEF,YAAM,iBAAiB,MAAM,SAAS,cAAc,YAAY,EAAE;AAGlE,YAAM,gBAAgB,MAAM,SAAS,OAAO,MAAM;AAAA,QAChD,GAAG;AAAA,QACH,UAAU;AAAA;AAAA,MACZ,CAAC;AAED,YAAM,eAAe,SAAS,cAAc,QAAQ,SAAS,QAAQ;AAErE,gBAAU,kCAAkC,YAAY,IAAI;AAAA,QAC1D,OAAO;AAAA,QACP,WAAW;AAAA,MACb,CAAC;AAED,aAAO;AAAA,IACT,SAAS,OAAO;AACd,YAAM,MAAM;AACZ;AAAA,QACE,0CAA0C,QAAQ,KAAK,IAAI,OAAO;AAAA,QAClE;AAAA,UACE,OAAO;AAAA,UACP,WAAW;AAAA,QACb;AAAA,MACF;AAAA,IAEF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/writeContentDeclaration/formatCode.ts"],"sourcesContent":["import { ANSIColors, getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { relative } from 'path';\n\nexport const formatCode = async (filePath: string, code: string) => {\n const appLogger = getAppLogger(configuration);\n // Try to import prettier if it exists\n let prettier: any;\n try {\n prettier = require('prettier');\n } catch (error) {\n // Prettier is not installed, continue without it\n }\n\n // Apply Prettier formatting if it's available\n if (prettier) {\n try {\n // Try to find a prettier config file\n const prettierConfig = await prettier.resolveConfig(filePath ?? '');\n\n // Format the code with Prettier\n const formattedCode = await prettier.format(code, {\n ...prettierConfig,\n filepath: filePath, // Explicitly provide the filepath so Prettier can infer the parser\n });\n\n const relativePath = relative(configuration.content.baseDir, filePath);\n\n appLogger(\n `Applied Prettier formatting to ${ANSIColors.GREY}${relativePath}${ANSIColors.RESET}`,\n {\n level: 'info',\n isVerbose: true,\n }\n );\n\n return formattedCode;\n } catch (error) {\n const err = error as Error;\n appLogger(\n `Failed to apply Prettier formatting to ${filePath}: ${err.message}`,\n {\n level: 'warn',\n isVerbose: true,\n }\n );\n // Continue with unformatted code on prettier error\n }\n }\n\n return code;\n};\n"],"mappings":"AAAA,SAAS,YAAY,oBAAoB;AACzC,OAAO,mBAAmB;AAC1B,SAAS,gBAAgB;AAElB,MAAM,aAAa,OAAO,UAAkB,SAAiB;AAClE,QAAM,YAAY,aAAa,aAAa;AAE5C,MAAI;AACJ,MAAI;AACF,eAAW,QAAQ,UAAU;AAAA,EAC/B,SAAS,OAAO;AAAA,EAEhB;AAGA,MAAI,UAAU;AACZ,QAAI;AAEF,YAAM,iBAAiB,MAAM,SAAS,cAAc,YAAY,EAAE;AAGlE,YAAM,gBAAgB,MAAM,SAAS,OAAO,MAAM;AAAA,QAChD,GAAG;AAAA,QACH,UAAU;AAAA;AAAA,MACZ,CAAC;AAED,YAAM,eAAe,SAAS,cAAc,QAAQ,SAAS,QAAQ;AAErE;AAAA,QACE,kCAAkC,WAAW,IAAI,GAAG,YAAY,GAAG,WAAW,KAAK;AAAA,QACnF;AAAA,UACE,OAAO;AAAA,UACP,WAAW;AAAA,QACb;AAAA,MACF;AAEA,aAAO;AAAA,IACT,SAAS,OAAO;AACd,YAAM,MAAM;AACZ;AAAA,QACE,0CAA0C,QAAQ,KAAK,IAAI,OAAO;AAAA,QAClE;AAAA,UACE,OAAO;AAAA,UACP,WAAW;AAAA,QACb;AAAA,MACF;AAAA,IAEF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,4 +1,5 @@
1
1
  import configuration from "@intlayer/config/built";
2
+ import { colorizePath, x } from "@intlayer/config/client";
2
3
  import dictionariesRecord from "@intlayer/unmerged-dictionaries-entry";
3
4
  import deepEqual from "deep-equal";
4
5
  import { existsSync } from "fs";
@@ -41,7 +42,7 @@ const writeContentDeclaration = async (dictionary, config = configuration, newDi
41
42
  formattedContentDeclaration
42
43
  );
43
44
  return {
44
- status: "reimported in new location",
45
+ status: "new content file",
45
46
  path: contentDeclarationPath
46
47
  };
47
48
  }
@@ -81,7 +82,10 @@ const writeFileWithDirectories = async (filePath, data) => {
81
82
  await writeJSFile(filePath, data);
82
83
  }
83
84
  } catch (error) {
84
- throw new Error(`Error writing file to ${filePath}: ${error}`);
85
+ console.error(data);
86
+ throw new Error(
87
+ `${x} Error writing file to ${colorizePath(filePath)}: ${error}`
88
+ );
85
89
  }
86
90
  };
87
91
  export {