@intlayer/chokidar 5.8.1 → 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/loadDictionaries/log.ts"],"sourcesContent":["import {\n ANSIColors,\n colorize,\n getConfiguration,\n spinnerFrames,\n} from '@intlayer/config';\nimport type { DictionariesStatus } from './loadDictionaries';\n\nexport class DictionariesLogger {\n private statuses: DictionariesStatus[] = [];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private spinnerIndex = 0;\n private renderedLines = 0;\n private readonly spinnerFrames = spinnerFrames;\n private isFinished = false;\n private readonly prefix: string;\n private lastRenderedState: string = '';\n\n constructor() {\n const configuration = getConfiguration();\n this.prefix = configuration.log.prefix;\n }\n\n update(newStatuses: DictionariesStatus[]) {\n if (this.isFinished) return;\n for (const status of newStatuses) {\n const index = this.statuses.findIndex(\n (s) =>\n s.dictionaryKey === status.dictionaryKey && s.type === status.type\n );\n if (index >= 0) {\n this.statuses[index] = status;\n } else {\n this.statuses.push(status);\n }\n }\n\n this.startSpinner();\n this.render();\n }\n\n finish() {\n this.isFinished = true;\n this.stopSpinner();\n // Render final state and keep it visible\n this.render();\n }\n\n private startSpinner() {\n if (this.spinnerTimer || this.isFinished) return;\n this.spinnerTimer = setInterval(() => {\n this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;\n this.render();\n }, 100);\n }\n\n private stopSpinner() {\n if (!this.spinnerTimer) return;\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n\n private render() {\n const { localTotal, localDone, remoteTotal, remoteDone } =\n this.computeProgress();\n\n const frame = this.spinnerFrames[this.spinnerIndex];\n const lines: string[] = [];\n\n const isLocalDone = localDone === localTotal;\n const isRemoteDone = remoteDone === remoteTotal;\n\n if (isLocalDone) {\n lines.push(\n `${this.prefix} ${colorize('✔', ANSIColors.GREEN)} local dictionaries: ${localDone}/${localTotal}`\n );\n } else {\n lines.push(\n `${this.prefix} ${colorize(frame, ANSIColors.BLUE)} local dictionaries: ${localDone}/${localTotal}`\n );\n }\n\n if (remoteTotal > 0) {\n if (isRemoteDone) {\n lines.push(\n `${this.prefix} ${colorize('✔', ANSIColors.GREEN)} remote dictionaries: ${remoteDone}/${remoteTotal}`\n );\n } else {\n lines.push(\n `${this.prefix} ${colorize(frame, ANSIColors.BLUE)} remote dictionaries: ${remoteDone}/${remoteTotal}`\n );\n }\n }\n\n // Check if the state has changed to avoid duplicate rendering\n const currentState = lines.join('\\n');\n if (currentState === this.lastRenderedState) {\n return;\n }\n this.lastRenderedState = currentState;\n\n if (this.renderedLines > 0) {\n process.stdout.write(`\\x1b[${this.renderedLines}F`);\n }\n\n const totalLinesToClear = Math.max(this.renderedLines, lines.length);\n for (let i = 0; i < totalLinesToClear; i++) {\n process.stdout.write('\\x1b[2K');\n const line = lines[i];\n if (line !== undefined) {\n process.stdout.write(line);\n }\n process.stdout.write('\\n');\n }\n\n this.renderedLines = lines.length;\n }\n\n private computeProgress() {\n const localKeys = new Set(\n this.statuses\n .filter((s) => s.type === 'local')\n .map((s) => s.dictionaryKey)\n );\n\n const localDoneKeys = new Set(\n this.statuses\n .filter(\n (s) =>\n s.type === 'local' && (s.status === 'built' || s.status === 'error')\n )\n .map((s) => s.dictionaryKey)\n );\n\n const remoteKeys = new Set(\n this.statuses\n .filter((s) => s.type === 'remote')\n .map((s) => s.dictionaryKey)\n );\n\n const remoteDoneKeys = new Set(\n this.statuses\n .filter(\n (s) =>\n s.type === 'remote' &&\n (s.status === 'fetched' ||\n s.status === 'imported' ||\n s.status === 'error')\n )\n .map((s) => s.dictionaryKey)\n );\n\n return {\n localTotal: localKeys.size,\n localDone: localDoneKeys.size,\n remoteTotal: remoteKeys.size,\n remoteDone: remoteDoneKeys.size,\n } as const;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKO;AAGA,MAAM,mBAAmB;AAAA,EACtB,WAAiC,CAAC;AAAA,EAClC,eAAsC;AAAA,EACtC,eAAe;AAAA,EACf,gBAAgB;AAAA,EACP,gBAAgB;AAAA,EACzB,aAAa;AAAA,EACJ;AAAA,EACT,oBAA4B;AAAA,EAEpC,cAAc;AACZ,UAAM,oBAAgB,gCAAiB;AACvC,SAAK,SAAS,cAAc,IAAI;AAAA,EAClC;AAAA,EAEA,OAAO,aAAmC;AACxC,QAAI,KAAK,WAAY;AACrB,eAAW,UAAU,aAAa;AAChC,YAAM,QAAQ,KAAK,SAAS;AAAA,QAC1B,CAAC,MACC,EAAE,kBAAkB,OAAO,iBAAiB,EAAE,SAAS,OAAO;AAAA,MAClE;AACA,UAAI,SAAS,GAAG;AACd,aAAK,SAAS,KAAK,IAAI;AAAA,MACzB,OAAO;AACL,aAAK,SAAS,KAAK,MAAM;AAAA,MAC3B;AAAA,IACF;AAEA,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,SAAS;AACP,SAAK,aAAa;AAClB,SAAK,YAAY;AAEjB,SAAK,OAAO;AAAA,EACd;AAAA,EAEQ,eAAe;AACrB,QAAI,KAAK,gBAAgB,KAAK,WAAY;AAC1C,SAAK,eAAe,YAAY,MAAM;AACpC,WAAK,gBAAgB,KAAK,eAAe,KAAK,KAAK,cAAc;AACjE,WAAK,OAAO;AAAA,IACd,GAAG,GAAG;AAAA,EACR;AAAA,EAEQ,cAAc;AACpB,QAAI,CAAC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M,CAAC;AACpB,UAAI,SAAS,QAAW;AACtB,gBAAQ,OAAO,MAAM,IAAI;AAAA,MAC3B;AACA,cAAQ,OAAO,MAAM,IAAI;AAAA,IAC3B;AAEA,SAAK,gBAAgB,MAAM;AAAA,EAC7B;AAAA,EAEQ,kBAAkB;AACxB,UAAM,YAAY,IAAI;AAAA,MACpB,KAAK,SACF,OAAO,CAAC,MAAM,EAAE,SAAS,OAAO,EAChC,IAAI,CAAC,MAAM,EAAE,aAAa;AAAA,IAC/B;AAEA,UAAM,gBAAgB,IAAI;AAAA,MACxB,KAAK,SACF;AAAA,QACC,CAAC,MACC,EAAE,SAAS,YAAY,EAAE,WAAW,WAAW,EAAE,WAAW;AAAA,MAChE,EACC,IAAI,CAAC,MAAM,EAAE,aAAa;AAAA,IAC/B;AAEA,UAAM,aAAa,IAAI;AAAA,MACrB,KAAK,SACF,OAAO,CAAC,MAAM,EAAE,SAAS,QAAQ,EACjC,IAAI,CAAC,MAAM,EAAE,aAAa;AAAA,IAC/B;AAEA,UAAM,iBAAiB,IAAI;AAAA,MACzB,KAAK,SACF;AAAA,QACC,CAAC,MACC,EAAE,SAAS,aACV,EAAE,WAAW,aACZ,EAAE,WAAW,cACb,EAAE,WAAW;AAAA,MACnB,EACC,IAAI,CAAC,MAAM,EAAE,aAAa;AAAA,IAC/B;AAEA,WAAO;AAAA,MACL,YAAY,UAAU;AAAA,MACtB,WAAW,cAAc;AAAA,MACzB,aAAa,WAAW;AAAA,MACxB,YAAY,eAAe;AAAA,IAC7B;AAAA,EACF;AACF;","names":[]}
@@ -35,13 +35,14 @@ var import_config = require("@intlayer/config");
35
35
  var import_built = __toESM(require("@intlayer/config/built"));
36
36
  var import_core = require("@intlayer/core");
37
37
  var import_deepmerge = __toESM(require("deepmerge"));
38
+ var import_orderDictionaries = require('./orderDictionaries.cjs');
38
39
  const checkTypesMatch = (obj1, obj2, dictionaryKey, path = []) => {
39
40
  const appLogger = (0, import_config.getAppLogger)(import_built.default);
40
41
  const type1 = (0, import_core.getNodeType)(obj1);
41
42
  const type2 = (0, import_core.getNodeType)(obj2);
42
43
  if (type1 !== type2) {
43
44
  appLogger(
44
- `Error: Dictionary "${dictionaryKey}" has a multiple content files with type mismatch at path "${path.join(".")}": Cannot merge ${type1} with ${type2}`,
45
+ `Error: Dictionary ${(0, import_config.colorizeKey)(dictionaryKey)} has a multiple content files with type mismatch at path "${path.join(".")}": Cannot merge ${type1} with ${type2}`,
45
46
  {
46
47
  level: "error"
47
48
  }
@@ -110,35 +111,30 @@ const arrayMerge = (destinationArray, sourceArray) => {
110
111
  return result;
111
112
  };
112
113
  const mergeDictionaries = (dictionaries) => {
113
- const { editor } = import_built.default;
114
- let mergedDictionaries = dictionaries[0];
114
+ const orderedDictionaries = (0, import_orderDictionaries.orderDictionaries)(dictionaries, import_built.default);
115
+ let mergedContent = orderedDictionaries[0].content;
115
116
  const mergeOptions = {
116
117
  arrayMerge
117
118
  };
118
- for (let i = 1; i < dictionaries.length; i++) {
119
- const currentDictionary = dictionaries[i];
119
+ for (let i = 1; i < orderedDictionaries.length; i++) {
120
+ const currentDictionary = orderedDictionaries[i];
120
121
  checkTypesMatch(
121
- mergedDictionaries,
122
- currentDictionary,
122
+ mergedContent,
123
+ currentDictionary.content,
123
124
  currentDictionary.key,
124
125
  []
125
126
  );
126
- const isDistant = currentDictionary.location === "distant";
127
- if (editor.dictionaryPriorityStrategy === "distant_first" && isDistant) {
128
- mergedDictionaries = (0, import_deepmerge.default)(
129
- mergedDictionaries,
130
- currentDictionary,
131
- mergeOptions
132
- );
133
- } else {
134
- mergedDictionaries = (0, import_deepmerge.default)(
135
- currentDictionary,
136
- mergedDictionaries,
137
- mergeOptions
138
- );
139
- }
127
+ mergedContent = (0, import_deepmerge.default)(
128
+ currentDictionary.content,
129
+ mergedContent,
130
+ mergeOptions
131
+ );
140
132
  }
141
- return { ...mergedDictionaries, filePath: void 0 };
133
+ return {
134
+ key: orderedDictionaries[0].key,
135
+ content: mergedContent,
136
+ localIds: dictionaries.filter((dict) => dict.localId).map((dict) => dict.localId)
137
+ };
142
138
  };
143
139
  // Annotate the CommonJS export names for ESM import in node:
144
140
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mergeDictionaries.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/core';\nimport { getNodeType } from '@intlayer/core';\nimport merge, { Options } from 'deepmerge';\n\nconst checkTypesMatch = (\n obj1: any,\n obj2: any,\n dictionaryKey: string,\n path: string[] = []\n): void => {\n const appLogger = getAppLogger(configuration);\n const type1 = getNodeType(obj1);\n const type2 = getNodeType(obj2);\n\n if (type1 !== type2) {\n appLogger(\n `Error: Dictionary \"${dictionaryKey}\" has a multiple content files with type mismatch at path \"${path.join('.')}\": Cannot merge ${type1} with ${type2}`,\n {\n level: 'error',\n }\n );\n }\n\n if (type1 === 'object' && obj1 && obj2) {\n const allKeys = new Set([...Object.keys(obj1), ...Object.keys(obj2)]);\n for (const key of allKeys) {\n if (key in obj1 && key in obj2) {\n checkTypesMatch(obj1[key], obj2[key], dictionaryKey, [...path, key]);\n }\n }\n }\n};\n\n// Custom array merge strategy that merges arrays by key when present, otherwise by index\nconst arrayMerge = (destinationArray: any[], sourceArray: any[]): any[] => {\n const isObject = (value: unknown): value is Record<string, any> =>\n !!value && typeof value === 'object' && !Array.isArray(value);\n\n const getKey = (item: any): string | number | undefined => {\n if (!isObject(item)) return undefined;\n const key = (item as any).key;\n if (typeof key === 'string' || typeof key === 'number') return key;\n return undefined;\n };\n\n const result: any[] = [];\n\n // Build a lookup for destination keyed items and track usage of all destination indices\n const destKeyToIndex = new Map<string | number, number>();\n const destUsed: boolean[] = new Array(destinationArray.length).fill(false);\n for (let i = 0; i < destinationArray.length; i++) {\n const k = getKey(destinationArray[i]);\n if (k !== undefined && !destKeyToIndex.has(k)) {\n destKeyToIndex.set(k, i);\n }\n }\n\n // First pass: respect source (already merged) order\n for (let i = 0; i < sourceArray.length; i++) {\n const sourceItem = sourceArray[i];\n const sourceKey = getKey(sourceItem);\n\n if (sourceKey !== undefined && destKeyToIndex.has(sourceKey)) {\n const destIndex = destKeyToIndex.get(sourceKey)!;\n const destItem = destinationArray[destIndex];\n destUsed[destIndex] = true;\n\n if (isObject(destItem) && isObject(sourceItem)) {\n result.push(merge(sourceItem, destItem, { arrayMerge }));\n } else {\n // Prefer destination item (later dictionary) when primitive\n result.push(destItem !== undefined ? destItem : sourceItem);\n }\n continue;\n }\n\n // Fallback to index-based merge when no key match\n const destItem = destinationArray[i];\n if (destItem !== undefined && !destUsed[i]) {\n destUsed[i] = true;\n if (isObject(destItem) && isObject(sourceItem)) {\n result.push(merge(sourceItem, destItem, { arrayMerge }));\n } else if (destItem !== undefined) {\n result.push(destItem);\n } else {\n result.push(sourceItem);\n }\n } else {\n result.push(sourceItem);\n }\n }\n\n // Second pass: append remaining unused destination items (including keyed-only in destination or extra by index)\n for (let i = 0; i < destinationArray.length; i++) {\n if (!destUsed[i]) {\n result.push(destinationArray[i]);\n destUsed[i] = true;\n }\n }\n\n return result;\n};\n\nexport const mergeDictionaries = (dictionaries: Dictionary[]): Dictionary => {\n const { editor } = configuration;\n\n let mergedDictionaries: Dictionary = dictionaries[0];\n\n // Configure deepmerge options with custom array merge strategy\n const mergeOptions: Options = {\n arrayMerge,\n };\n\n for (let i = 1; i < dictionaries.length; i++) {\n const currentDictionary = dictionaries[i];\n\n // Check types before merging\n checkTypesMatch(\n mergedDictionaries,\n currentDictionary,\n currentDictionary.key,\n []\n );\n\n const isDistant = currentDictionary.location === 'distant';\n\n if (editor.dictionaryPriorityStrategy === 'distant_first' && isDistant) {\n mergedDictionaries = merge(\n mergedDictionaries,\n currentDictionary,\n mergeOptions\n );\n } else {\n mergedDictionaries = merge(\n currentDictionary,\n mergedDictionaries,\n mergeOptions\n );\n }\n }\n\n return { ...mergedDictionaries, filePath: undefined };\n};\n"],"mappings":";;;;;;;;;;;;;;;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AAEA,SAAO;AACT;AAEO,MAAM,oBAAoB,CAAC,iBAA2C;AAC3E,QAAM,EAAE,OAAO,IAAI,aAAAF;AAEnB,MAAI,qBAAiC,aAAa,CAAC;AAGnD,QAAM,eAAwB;AAAA,IAC5B;AAAA,EACF;AAEA,WAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAC5C,UAAM,oBAAoB,aAAa,CAAC;AAGxC;AAAA,MACE;AAAA,MACA;AAAA,MACA,kBAAkB;AAAA,MAClB,CAAC;AAAA,IACH;AAEA,UAAM,YAAY,kBAAkB,aAAa;AAEjD,QAAI,OAAO,+BAA+B,mBAAmB,WAAW;AACtE,+BAAqB,iBAAAE;AAAA,QACnB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF,OAAO;AACL,+BAAqB,iBAAAA;AAAA,QACnB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,oBAAoB,UAAU,OAAU;AACtD;","names":["configuration","destItem","merge"]}
1
+ {"version":3,"sources":["../../src/mergeDictionaries.ts"],"sourcesContent":["import { colorizeKey, getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { type Dictionary, getNodeType } from '@intlayer/core';\nimport merge, { Options } from 'deepmerge';\nimport { orderDictionaries } from './orderDictionaries';\n\nconst checkTypesMatch = (\n obj1: any,\n obj2: any,\n dictionaryKey: string,\n path: string[] = []\n): void => {\n const appLogger = getAppLogger(configuration);\n const type1 = getNodeType(obj1);\n const type2 = getNodeType(obj2);\n\n if (type1 !== type2) {\n appLogger(\n `Error: Dictionary ${colorizeKey(dictionaryKey)} has a multiple content files with type mismatch at path \"${path.join('.')}\": Cannot merge ${type1} with ${type2}`,\n {\n level: 'error',\n }\n );\n }\n\n if (type1 === 'object' && obj1 && obj2) {\n const allKeys = new Set([...Object.keys(obj1), ...Object.keys(obj2)]);\n for (const key of allKeys) {\n if (key in obj1 && key in obj2) {\n checkTypesMatch(obj1[key], obj2[key], dictionaryKey, [...path, key]);\n }\n }\n }\n};\n\n// Custom array merge strategy that merges arrays by key when present, otherwise by index\nconst arrayMerge = (destinationArray: any[], sourceArray: any[]): any[] => {\n const isObject = (value: unknown): value is Record<string, any> =>\n !!value && typeof value === 'object' && !Array.isArray(value);\n\n const getKey = (item: any): string | number | undefined => {\n if (!isObject(item)) return undefined;\n const key = (item as any).key;\n if (typeof key === 'string' || typeof key === 'number') return key;\n return undefined;\n };\n\n const result: any[] = [];\n\n // Build a lookup for destination keyed items and track usage of all destination indices\n const destKeyToIndex = new Map<string | number, number>();\n const destUsed: boolean[] = new Array(destinationArray.length).fill(false);\n for (let i = 0; i < destinationArray.length; i++) {\n const k = getKey(destinationArray[i]);\n if (k !== undefined && !destKeyToIndex.has(k)) {\n destKeyToIndex.set(k, i);\n }\n }\n\n // First pass: respect source (already merged) order\n for (let i = 0; i < sourceArray.length; i++) {\n const sourceItem = sourceArray[i];\n const sourceKey = getKey(sourceItem);\n\n if (sourceKey !== undefined && destKeyToIndex.has(sourceKey)) {\n const destIndex = destKeyToIndex.get(sourceKey)!;\n const destItem = destinationArray[destIndex];\n destUsed[destIndex] = true;\n\n if (isObject(destItem) && isObject(sourceItem)) {\n result.push(merge(sourceItem, destItem, { arrayMerge }));\n } else {\n // Prefer destination item (later dictionary) when primitive\n result.push(destItem !== undefined ? destItem : sourceItem);\n }\n continue;\n }\n\n // Fallback to index-based merge when no key match\n const destItem = destinationArray[i];\n if (destItem !== undefined && !destUsed[i]) {\n destUsed[i] = true;\n if (isObject(destItem) && isObject(sourceItem)) {\n result.push(merge(sourceItem, destItem, { arrayMerge }));\n } else if (destItem !== undefined) {\n result.push(destItem);\n } else {\n result.push(sourceItem);\n }\n } else {\n result.push(sourceItem);\n }\n }\n\n // Second pass: append remaining unused destination items (including keyed-only in destination or extra by index)\n for (let i = 0; i < destinationArray.length; i++) {\n if (!destUsed[i]) {\n result.push(destinationArray[i]);\n destUsed[i] = true;\n }\n }\n\n return result;\n};\n\nexport const mergeDictionaries = (dictionaries: Dictionary[]): Dictionary => {\n // Order dictionaries based on priority strategy\n const orderedDictionaries = orderDictionaries(dictionaries, configuration);\n\n let mergedContent: Dictionary['content'] = orderedDictionaries[0].content;\n\n // Configure deepmerge options with custom array merge strategy\n const mergeOptions: Options = {\n arrayMerge,\n };\n\n for (let i = 1; i < orderedDictionaries.length; i++) {\n const currentDictionary = orderedDictionaries[i];\n\n // Check types before merging\n checkTypesMatch(\n mergedContent,\n currentDictionary.content,\n currentDictionary.key,\n []\n );\n\n mergedContent = merge(\n currentDictionary.content,\n mergedContent,\n mergeOptions\n );\n }\n\n return {\n key: orderedDictionaries[0].key,\n content: mergedContent,\n localIds: dictionaries\n .filter((dict) => dict.localId)\n .map((dict) => dict.localId!),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0C;AAC1C,mBAA0B;AAC1B,kBAA6C;AAC7C,uBAA+B;AAC/B,+BAAkC;AAElC,MAAM,kBAAkB,CACtB,MACA,MACA,eACA,OAAiB,CAAC,MACT;AACT,QAAM,gBAAY,4BAAa,aAAAA,OAAa;AAC5C,QAAM,YAAQ,yBAAY,IAAI;AAC9B,QAAM,YAAQ,yBAAY,IAAI;AAE9B,MAAI,UAAU,OAAO;AACnB;AAAA,MACE,yBAAqB,2BAAY,aAAa,CAAC,6DAA6D,KAAK,KAAK,GAAG,CAAC,mBAAmB,KAAK,SAAS,KAAK;AAAA,MAChK;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,MAAI,UAAU,YAAY,QAAQ,MAAM;AACtC,UAAM,UAAU,oBAAI,IAAI,CAAC,GAAG,OAAO,KAAK,IAAI,GAAG,GAAG,OAAO,KAAK,IAAI,CAAC,CAAC;AACpE,eAAW,OAAO,SAAS;AACzB,UAAI,OAAO,QAAQ,OAAO,MAAM;AAC9B,wBAAgB,KAAK,GA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
+ 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 orderDictionaries_exports = {};
30
+ __export(orderDictionaries_exports, {
31
+ orderDictionaries: () => orderDictionaries
32
+ });
33
+ module.exports = __toCommonJS(orderDictionaries_exports);
34
+ var import_built = __toESM(require("@intlayer/config/built"));
35
+ const orderDictionaries = (dictionaries, configuration = import_built.default) => {
36
+ const { editor } = configuration;
37
+ const { dictionaryPriorityStrategy } = editor;
38
+ if (dictionaries.length <= 1) {
39
+ return dictionaries;
40
+ }
41
+ const withIndex = dictionaries.map((dict, index) => ({ dict, index }));
42
+ const getPriority = (d) => {
43
+ const p = d.priority ?? 0;
44
+ return Number.isFinite(p) ? p : 0;
45
+ };
46
+ const getLocationWeight = (d) => {
47
+ const location = d.location ?? "distant";
48
+ if (dictionaryPriorityStrategy === "distant_first") {
49
+ return location === "distant" ? 0 : 1;
50
+ }
51
+ return location === "locale" ? 0 : 1;
52
+ };
53
+ withIndex.sort((a, b) => {
54
+ const aAuto = a.dict.autoFilled ? 1 : 0;
55
+ const bAuto = b.dict.autoFilled ? 1 : 0;
56
+ if (aAuto !== bAuto) return aAuto - bAuto;
57
+ const aP = getPriority(a.dict);
58
+ const bP = getPriority(b.dict);
59
+ if (aP !== bP) return bP - aP;
60
+ const aLoc = getLocationWeight(a.dict);
61
+ const bLoc = getLocationWeight(b.dict);
62
+ if (aLoc !== bLoc) return aLoc - bLoc;
63
+ return a.index - b.index;
64
+ });
65
+ return withIndex.map(({ dict }) => dict);
66
+ };
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ orderDictionaries
70
+ });
71
+ //# sourceMappingURL=orderDictionaries.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/orderDictionaries.ts"],"sourcesContent":["import intlayerConfig from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/core';\n\n/**\n * Orders dictionaries based on the dictionary priority strategy.\n *\n * @param dictionaries - Array of dictionaries to order\n * @param priorityStrategy - The priority strategy ('local_first' or 'distant_first')\n * @returns Ordered array of dictionaries\n */\nexport const orderDictionaries = (\n dictionaries: Dictionary[],\n configuration = intlayerConfig\n): Dictionary[] => {\n const { editor } = configuration;\n const { dictionaryPriorityStrategy } = editor;\n\n if (dictionaries.length <= 1) {\n return dictionaries;\n }\n\n // Stabilize original indices to preserve relative order for complete ties\n const withIndex = dictionaries.map((dict, index) => ({ dict, index }));\n\n const getPriority = (d: Dictionary): number => {\n const p = d.priority ?? 0;\n\n return Number.isFinite(p) ? p : 0;\n };\n\n const getLocationWeight = (d: Dictionary): number => {\n const location = d.location ?? 'distant';\n\n if (dictionaryPriorityStrategy === 'distant_first') {\n // distant should come first\n return location === 'distant' ? 0 : 1;\n }\n // default: local_first\n return location === 'locale' ? 0 : 1;\n };\n\n withIndex.sort((a, b) => {\n // 1) Non-autoFilled before autoFilled (autoFilled have lower precedence)\n const aAuto = a.dict.autoFilled ? 1 : 0;\n const bAuto = b.dict.autoFilled ? 1 : 0;\n if (aAuto !== bAuto) return aAuto - bAuto; // 0 before 1\n\n // 2) Higher priority first (larger number wins)\n const aP = getPriority(a.dict);\n const bP = getPriority(b.dict);\n if (aP !== bP) return bP - aP; // descending\n\n // 3) Location according to strategy\n const aLoc = getLocationWeight(a.dict);\n const bLoc = getLocationWeight(b.dict);\n if (aLoc !== bLoc) return aLoc - bLoc;\n\n // 4) Stable fallback by original index\n return a.index - b.index;\n });\n\n return withIndex.map(({ dict }) => dict);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2B;AAUpB,MAAM,oBAAoB,CAC/B,cACA,gBAAgB,aAAAA,YACC;AACjB,QAAM,EAAE,OAAO,IAAI;AACnB,QAAM,EAAE,2BAA2B,IAAI;AAEvC,MAAI,aAAa,UAAU,GAAG;AAC5B,WAAO;AAAA,EACT;AAGA,QAAM,YAAY,aAAa,IAAI,CAAC,MAAM,WAAW,EAAE,MAAM,MAAM,EAAE;AAErE,QAAM,cAAc,CAAC,MAA0B;AAC7C,UAAM,IAAI,EAAE,YAAY;AAExB,WAAO,OAAO,SAAS,CAAC,IAAI,IAAI;AAAA,EAClC;AAEA,QAAM,oBAAoB,CAAC,MAA0B;AACnD,UAAM,WAAW,EAAE,YAAY;AAE/B,QAAI,+BAA+B,iBAAiB;AAElD,aAAO,aAAa,YAAY,IAAI;AAAA,IACtC;AAEA,WAAO,aAAa,WAAW,IAAI;AAAA,EACrC;AAEA,YAAU,KAAK,CAAC,GAAG,MAAM;AAEvB,UAAM,QAAQ,EAAE,KAAK,aAAa,IAAI;AACtC,UAAM,QAAQ,EAAE,KAAK,aAAa,IAAI;AACtC,QAAI,UAAU,MAAO,QAAO,QAAQ;AAGpC,UAAM,KAAK,YAAY,EAAE,IAAI;AAC7B,UAAM,KAAK,YAAY,EAAE,IAAI;AAC7B,QAAI,OAAO,GAAI,QAAO,KAAK;AAG3B,UAAM,OAAO,kBAAkB,EAAE,IAAI;AACrC,UAAM,OAAO,kBAAkB,EAAE,IAAI;AACrC,QAAI,SAAS,KAAM,QAAO,OAAO;AAGjC,WAAO,EAAE,QAAQ,EAAE;AAAA,EACrB,CAAC;AAED,SAAO,UAAU,IAAI,CAAC,EAAE,KAAK,MAAM,IAAI;AACzC;","names":["intlayerConfig"]}
@@ -21,6 +21,7 @@ __export(prepareContentDeclaration_exports, {
21
21
  prepareContentDeclaration: () => prepareContentDeclaration
22
22
  });
23
23
  module.exports = __toCommonJS(prepareContentDeclaration_exports);
24
+ var import_config = require("@intlayer/config");
24
25
  var import_core = require("@intlayer/core");
25
26
  var import_fs = require("fs");
26
27
  var import_path = require("path");
@@ -47,7 +48,9 @@ const writeFilePlugin = {
47
48
  }
48
49
  (0, import_fs.writeFileSync)(abolsuteFilePath, fileContent);
49
50
  } catch (error) {
50
- throw new Error(`Error writing file to ${filePath}: ${error}`);
51
+ throw new Error(
52
+ `${import_config.x} Error writing file to ${(0, import_config.colorizePath)(filePath)}: ${error}`
53
+ );
51
54
  }
52
55
  const transformedFileContent = {
53
56
  nodeType: import_core.NodeType.File,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/prepareContentDeclaration.ts"],"sourcesContent":["import {\n deepTransformNode,\n NodeType,\n type Dictionary,\n type FileContent,\n type FileContentConstructor,\n type InsertionContent,\n type InsertionContentConstructor,\n type MarkdownContent,\n type MarkdownContentConstructor,\n type Plugins,\n} from '@intlayer/core';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { join } from 'path';\n\n/**\n * Write file plugin\n */\n\nconst writeFilePlugin: Plugins = {\n id: 'write-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.File,\n transform: (node: FileContent) => {\n const fileContent = node.content;\n const filePath = node.fixedPath;\n\n if (typeof fileContent !== 'string') {\n throw new Error('File content must be a string');\n }\n\n if (typeof filePath !== 'string') {\n throw new Error('File path must be a string');\n }\n\n // Write the file to the file system\n try {\n const abolsuteFilePath = join(process.cwd(), filePath);\n\n // Create the file directory if it doesn't exist\n const fileDirectory = join(process.cwd(), filePath);\n if (!fileDirectory.startsWith(process.cwd())) {\n throw new Error('File directory not found');\n }\n\n if (!existsSync(fileDirectory)) {\n mkdirSync(fileDirectory, { recursive: true });\n }\n\n // Write the file\n writeFileSync(abolsuteFilePath, fileContent);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n\n const transformedFileContent: FileContentConstructor = {\n nodeType: NodeType.File,\n [NodeType.File]: node.file,\n };\n\n return transformedFileContent;\n },\n};\n\n/**\n * Markdown file plugin\n */\n\nconst mardownFilePlugin: Plugins = {\n id: 'markdown-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Markdown,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const simplifiedMarkdownNode: MarkdownContentConstructor = {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: deepTransformNode(node.markdown, props),\n };\n\n return simplifiedMarkdownNode;\n },\n};\n\n/**\n * Insertion file plugin\n */\n\nconst insertionFilePlugin: Plugins = {\n id: 'insertion-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const simplifiedInsertionNode: InsertionContentConstructor = {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: deepTransformNode(node.insertion, props),\n };\n\n return simplifiedInsertionNode;\n },\n};\n\nexport const prepareContentDeclaration = async (dictionary: Dictionary) =>\n deepTransformNode(dictionary, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [writeFilePlugin, mardownFilePlugin, insertionFilePlugin],\n });\n"],"mappings":";;;;;;;;;;;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AAkB,KAAK,UAAU,KAAK;AAAA,IAC7D;AAEA,WAAO;AAAA,EACT;AACF;AAMA,MAAM,sBAA+B;AAAA,EACnC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,qBAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAOA,uBAAsB;AAC/D,UAAM,0BAAuD;AAAA,MAC3D,UAAU,qBAAS;AAAA,MACnB,CAAC,qBAAS,SAAS,GAAGA,mBAAkB,KAAK,WAAW,KAAK;AAAA,IAC/D;AAEA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,4BAA4B,OAAO,mBAC9C,+BAAkB,YAAY;AAAA,EAC5B,eAAe,WAAW;AAAA,EAC1B,SAAS,CAAC;AAAA,EACV,SAAS,CAAC,iBAAiB,mBAAmB,mBAAmB;AACnE,CAAC;","names":["deepTransformNode"]}
1
+ {"version":3,"sources":["../../src/prepareContentDeclaration.ts"],"sourcesContent":["import { colorizePath, x } from '@intlayer/config';\nimport {\n deepTransformNode,\n NodeType,\n type Dictionary,\n type FileContent,\n type FileContentConstructor,\n type InsertionContent,\n type InsertionContentConstructor,\n type MarkdownContent,\n type MarkdownContentConstructor,\n type Plugins,\n} from '@intlayer/core';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { join } from 'path';\n\n/**\n * Write file plugin\n */\n\nconst writeFilePlugin: Plugins = {\n id: 'write-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.File,\n transform: (node: FileContent) => {\n const fileContent = node.content;\n const filePath = node.fixedPath;\n\n if (typeof fileContent !== 'string') {\n throw new Error('File content must be a string');\n }\n\n if (typeof filePath !== 'string') {\n throw new Error('File path must be a string');\n }\n\n // Write the file to the file system\n try {\n const abolsuteFilePath = join(process.cwd(), filePath);\n\n // Create the file directory if it doesn't exist\n const fileDirectory = join(process.cwd(), filePath);\n if (!fileDirectory.startsWith(process.cwd())) {\n throw new Error('File directory not found');\n }\n\n if (!existsSync(fileDirectory)) {\n mkdirSync(fileDirectory, { recursive: true });\n }\n\n // Write the file\n writeFileSync(abolsuteFilePath, fileContent);\n } catch (error) {\n throw new Error(\n `${x} Error writing file to ${colorizePath(filePath)}: ${error}`\n );\n }\n\n const transformedFileContent: FileContentConstructor = {\n nodeType: NodeType.File,\n [NodeType.File]: node.file,\n };\n\n return transformedFileContent;\n },\n};\n\n/**\n * Markdown file plugin\n */\n\nconst mardownFilePlugin: Plugins = {\n id: 'markdown-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Markdown,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const simplifiedMarkdownNode: MarkdownContentConstructor = {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: deepTransformNode(node.markdown, props),\n };\n\n return simplifiedMarkdownNode;\n },\n};\n\n/**\n * Insertion file plugin\n */\n\nconst insertionFilePlugin: Plugins = {\n id: 'insertion-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const simplifiedInsertionNode: InsertionContentConstructor = {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: deepTransformNode(node.insertion, props),\n };\n\n return simplifiedInsertionNode;\n },\n};\n\nexport const prepareContentDeclaration = async (dictionary: Dictionary) =>\n deepTransformNode(dictionary, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [writeFilePlugin, mardownFilePlugin, insertionFilePlugin],\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAgC;AAChC,kBAWO;AACP,gBAAqD;AACrD,kBAAqB;AAMrB,MAAM,kBAA2B;AAAA,EAC/B,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,qBAAS;AAAA,EAC1D,WAAW,CAAC,SAAsB;AAChC,UAAM,cAAc,KAAK;AACzB,UAAM,WAAW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AAM,0BAAuD;AAAA,MAC3D,UAAU,qBAAS;AAAA,MACnB,CAAC,qBAAS,SAAS,GAAGA,mBAAkB,KAAK,WAAW,KAAK;AAAA,IAC/D;AAEA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,4BAA4B,OAAO,mBAC9C,+BAAkB,YAAY;AAAA,EAC5B,eAAe,WAAW;AAAA,EAC1B,SAAS,CAAC;AAAA,EACV,SAAS,CAAC,iBAAiB,mBAAmB,mBAAmB;AACnE,CAAC;","names":["deepTransformNode"]}
@@ -26,6 +26,7 @@ var import_cleanOutputDir = require('./cleanOutputDir.cjs');
26
26
  var import_listDictionariesPath = require('./listDictionariesPath.cjs');
27
27
  var import_loadDictionaries = require('./loadDictionaries/loadDictionaries.cjs');
28
28
  var import_declaration_file_to_dictionary = require('./transpiler/declaration_file_to_dictionary/index.cjs');
29
+ var import_writeRemoteDictionary = require('./transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.cjs');
29
30
  var import_createDictionaryEntryPoint = require('./transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs');
30
31
  var import_dictionary_to_type = require('./transpiler/dictionary_to_type/index.cjs');
31
32
  var import_writeConfiguration = require('./writeConfiguration/index.cjs');
@@ -40,14 +41,18 @@ const prepareIntlayer = async (configuration = (0, import_config.getConfiguratio
40
41
  configuration,
41
42
  projectRequire
42
43
  );
43
- const dictionariesOutput = await (0, import_declaration_file_to_dictionary.buildDictionary)(dictionaries, configuration);
44
+ const dictionariesOutput = await (0, import_declaration_file_to_dictionary.buildDictionary)(
45
+ [...dictionaries.localDictionaries, ...dictionaries.remoteDictionaries],
46
+ configuration
47
+ );
48
+ await (0, import_writeRemoteDictionary.writeRemoteDictionary)(dictionaries.remoteDictionaries, configuration);
44
49
  const dictionariesPaths = Object.values(
45
50
  dictionariesOutput?.mergedDictionaries ?? {}
46
51
  ).map((dictionary) => dictionary.dictionaryPath);
47
- (0, import_dictionary_to_type.createTypes)(dictionariesPaths);
48
- (0, import_createDictionaryEntryPoint.createDictionaryEntryPoint)(configuration);
52
+ await (0, import_dictionary_to_type.createTypes)(dictionariesPaths);
53
+ await (0, import_createDictionaryEntryPoint.createDictionaryEntryPoint)(configuration);
49
54
  appLogger("Dictionaries built");
50
- (0, import_dictionary_to_type.createModuleAugmentation)(configuration);
55
+ await (0, import_dictionary_to_type.createModuleAugmentation)(configuration);
51
56
  appLogger("Module augmentation built", {
52
57
  isVerbose: true
53
58
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n type IntlayerConfig,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { listDictionaries } from './listDictionariesPath';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createModuleAugmentation,\n createTypes,\n} from './transpiler/dictionary_to_type/index';\nimport { writeConfiguration } from './writeConfiguration';\n\nexport const prepareIntlayer = async (\n configuration: IntlayerConfig = getConfiguration(),\n projectRequire = ESMxCJSRequire,\n clean = false\n) => {\n const appLogger = getAppLogger(configuration);\n\n if (clean) {\n cleanOutputDir(configuration);\n }\n\n const files: string[] = listDictionaries(configuration);\n\n const dictionaries = await loadDictionaries(\n files,\n configuration,\n projectRequire\n );\n\n // Build locale dictionaries\n const dictionariesOutput = await buildDictionary(dictionaries, configuration);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint(configuration);\n\n appLogger('Dictionaries built');\n\n createModuleAugmentation(configuration);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n writeConfiguration(configuration);\n\n appLogger('Configuration written', {\n isVerbose: true,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKO;AACP,4BAA+B;AAC/B,kCAAiC;AACjC,8BAAiC;AACjC,4CAAgC;AAChC,wCAA2C;AAC3C,gCAGO;AACP,gCAAmC;AAE5B,MAAM,kBAAkB,OAC7B,oBAAgC,gCAAiB,GACjD,iBAAiB,8BACjB,QAAQ,UACL;AACH,QAAM,gBAAY,4BAAa,aAAa;AAE5C,MAAI,OAAO;AACT,8CAAe,aAAa;AAAA,EAC9B;AAEA,QAAM,YAAkB,8CAAiB,aAAa;AAEtD,QAAM,eAAe,UAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGA,QAAM,qBAAqB,UAAM,uDAAgB,cAAc,aAAa;AAE5E,QAAM,oBAAoB,OAAO;AAAA,IAC/B,oBAAoB,sBAAsB,CAAC;AAAA,EAC7C,EAAE,IAAI,CAAC,eAAe,WAAW,cAAc;AAE/C,6CAAY,iBAAiB;AAE7B,oEAA2B,aAAa;AAExC,YAAU,oBAAoB;AAE9B,0DAAyB,aAAa;AAEtC,YAAU,6BAA6B;AAAA,IACrC,WAAW;AAAA,EACb,CAAC;AAED,oDAAmB,aAAa;AAEhC,YAAU,yBAAyB;AAAA,IACjC,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n type IntlayerConfig,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { listDictionaries } from './listDictionariesPath';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nimport { writeRemoteDictionary } from './transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createModuleAugmentation,\n createTypes,\n} from './transpiler/dictionary_to_type/index';\nimport { writeConfiguration } from './writeConfiguration';\n\nexport const prepareIntlayer = async (\n configuration: IntlayerConfig = getConfiguration(),\n projectRequire = ESMxCJSRequire,\n clean = false\n) => {\n const appLogger = getAppLogger(configuration);\n\n if (clean) {\n cleanOutputDir(configuration);\n }\n\n const files: string[] = listDictionaries(configuration);\n\n const dictionaries = await loadDictionaries(\n files,\n configuration,\n projectRequire\n );\n\n // Build local dictionaries\n const dictionariesOutput = await buildDictionary(\n [...dictionaries.localDictionaries, ...dictionaries.remoteDictionaries],\n configuration\n );\n\n // Write remote dictionaries\n // Used as cache for next fetch\n await writeRemoteDictionary(dictionaries.remoteDictionaries, configuration);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n await createTypes(dictionariesPaths);\n\n await createDictionaryEntryPoint(configuration);\n\n appLogger('Dictionaries built');\n\n await createModuleAugmentation(configuration);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n writeConfiguration(configuration);\n\n appLogger('Configuration written', {\n isVerbose: true,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKO;AACP,4BAA+B;AAC/B,kCAAiC;AACjC,8BAAiC;AACjC,4CAAgC;AAChC,mCAAsC;AACtC,wCAA2C;AAC3C,gCAGO;AACP,gCAAmC;AAE5B,MAAM,kBAAkB,OAC7B,oBAAgC,gCAAiB,GACjD,iBAAiB,8BACjB,QAAQ,UACL;AACH,QAAM,gBAAY,4BAAa,aAAa;AAE5C,MAAI,OAAO;AACT,8CAAe,aAAa;AAAA,EAC9B;AAEA,QAAM,YAAkB,8CAAiB,aAAa;AAEtD,QAAM,eAAe,UAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGA,QAAM,qBAAqB,UAAM;AAAA,IAC/B,CAAC,GAAG,aAAa,mBAAmB,GAAG,aAAa,kBAAkB;AAAA,IACtE;AAAA,EACF;AAIA,YAAM,oDAAsB,aAAa,oBAAoB,aAAa;AAE1E,QAAM,oBAAoB,OAAO;AAAA,IAC/B,oBAAoB,sBAAsB,CAAC;AAAA,EAC7C,EAAE,IAAI,CAAC,eAAe,WAAW,cAAc;AAE/C,YAAM,uCAAY,iBAAiB;AAEnC,YAAM,8DAA2B,aAAa;AAE9C,YAAU,oBAAoB;AAE9B,YAAM,oDAAyB,aAAa;AAE5C,YAAU,6BAA6B;AAAA,IACrC,WAAW;AAAA,EACb,CAAC;AAED,oDAAmB,aAAa;AAEhC,YAAU,yBAAyB;AAAA,IACjC,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/processPerLocaleDictionary.ts"],"sourcesContent":["import { deepTransformNode, Plugins, t, type Dictionary } from '@intlayer/core';\n\n/**\n *\n * Should transform per locale dictionaries to multi-locale dictionaries\n *\n * Example:\n *\n * ```json5\n * // .intlayer/dictionaries/home.fr.json\n * { 'key': 'home', 'locale': 'fr', 'content': { 'example': \"value\", ... } },\n * ```\n *\n * Result:\n *\n * ```json5\n * // .intlayer/dictionaries/home.json\n * {\n * 'key': 'home',\n * 'content': {\n * 'example': {\n * 'nodeType': 'translation',\n * 'translation': {\n * 'fr': 'valeur',\n * }\n * }, ... } },\n * ```\n *\n * @param dictionary\n * @returns\n */\nexport const processPerLocaleDictionary = (dictionary: Dictionary) => {\n const isPerLocaleDictionary = typeof dictionary.locale === 'string';\n\n if (!isPerLocaleDictionary) {\n return dictionary;\n }\n\n const transformStringToTranslationPlugin: Plugins = {\n id: 'transform-string-to-translation-plugin',\n canHandle: (node) => typeof node === 'string' || typeof node === 'number',\n transform: (node: string | number) =>\n t({ [dictionary.locale as string]: node }),\n };\n\n return {\n ...dictionary,\n locale: undefined,\n content: deepTransformNode(dictionary.content, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [transformStringToTranslationPlugin],\n }),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA+D;AA+BxD,MAAM,6BAA6B,CAAC,eAA2B;AACpE,QAAM,wBAAwB,OAAO,WAAW,WAAW;AAE3D,MAAI,CAAC,uBAAuB;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,qCAA8C;AAAA,IAClD,IAAI;AAAA,IACJ,WAAW,CAAC,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS;AAAA,IACjE,WAAW,CAAC,aACV,eAAE,EAAE,CAAC,WAAW,MAAgB,GAAG,KAAK,CAAC;AAAA,EAC7C;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ;AAAA,IACR,aAAS,+BAAkB,WAAW,SAAS;AAAA,MAC7C,eAAe,WAAW;AAAA,MAC1B,SAAS,CAAC;AAAA,MACV,SAAS,CAAC,kCAAkC;AAAA,IAC9C,CAAC;AAAA,EACH;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/processPerLocaleDictionary.ts"],"sourcesContent":["import { deepTransformNode, Plugins, t, type Dictionary } from '@intlayer/core';\n\n/**\n *\n * Should transform per local dictionaries to multi-local dictionaries\n *\n * Example:\n *\n * ```json5\n * // .intlayer/dictionaries/home.fr.json\n * { 'key': 'home', 'locale': 'fr', 'content': { 'example': \"value\", ... } },\n * ```\n *\n * Result:\n *\n * ```json5\n * // .intlayer/dictionaries/home.json\n * {\n * 'key': 'home',\n * 'content': {\n * 'example': {\n * 'nodeType': 'translation',\n * 'translation': {\n * 'fr': 'valeur',\n * }\n * }, ... } },\n * ```\n *\n * @param dictionary\n * @returns\n */\nexport const processPerLocaleDictionary = (dictionary: Dictionary) => {\n const isPerLocaleDictionary = typeof dictionary.locale === 'string';\n\n if (!isPerLocaleDictionary) {\n return dictionary;\n }\n\n const transformStringToTranslationPlugin: Plugins = {\n id: 'transform-string-to-translation-plugin',\n canHandle: (node) => typeof node === 'string' || typeof node === 'number',\n transform: (node: string | number) =>\n t({ [dictionary.locale as string]: node }),\n };\n\n return {\n ...dictionary,\n locale: undefined,\n content: deepTransformNode(dictionary.content, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [transformStringToTranslationPlugin],\n }),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA+D;AA+BxD,MAAM,6BAA6B,CAAC,eAA2B;AACpE,QAAM,wBAAwB,OAAO,WAAW,WAAW;AAE3D,MAAI,CAAC,uBAAuB;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,qCAA8C;AAAA,IAClD,IAAI;AAAA,IACJ,WAAW,CAAC,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS;AAAA,IACjE,WAAW,CAAC,aACV,eAAE,EAAE,CAAC,WAAW,MAAgB,GAAG,KAAK,CAAC;AAAA,EAC7C;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ;AAAA,IACR,aAAS,+BAAkB,WAAW,SAAS;AAAA,MAC7C,eAAe,WAAW;AAAA,MAC1B,SAAS,CAAC;AAAA,MACV,SAAS,CAAC,kCAAkC;AAAA,IAC9C,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -23,26 +23,40 @@ __export(buildIntlayerDictionary_exports, {
23
23
  module.exports = __toCommonJS(buildIntlayerDictionary_exports);
24
24
  var import_config = require("@intlayer/config");
25
25
  var import_writeDynamicDictionary = require('./writeDynamicDictionary.cjs');
26
+ var import_writeFetchDictionary = require('./writeFetchDictionary.cjs');
26
27
  var import_writeMergedDictionary = require('./writeMergedDictionary.cjs');
27
28
  var import_writeUnmergedDictionary = require('./writeUnmergedDictionary.cjs');
28
- const buildIntlayerDictionary = async (contentDeclarations, configuration = (0, import_config.getConfiguration)(), formats = ["cjs", "esm"]) => {
29
+ const buildIntlayerDictionary = async (localDictionariesEntries, configuration = (0, import_config.getConfiguration)(), formats = ["cjs", "esm"]) => {
30
+ const { importMode } = configuration.build;
29
31
  const unmergedDictionaries = await (0, import_writeUnmergedDictionary.writeUnmergedDictionaries)(
30
- contentDeclarations,
32
+ localDictionariesEntries,
31
33
  configuration
32
34
  );
33
35
  const mergedDictionaries = await (0, import_writeMergedDictionary.writeMergedDictionaries)(
34
36
  unmergedDictionaries,
35
37
  configuration
36
38
  );
37
- const dynamicDictionaries = await (0, import_writeDynamicDictionary.writeDynamicDictionary)(
38
- mergedDictionaries,
39
- configuration,
40
- formats
41
- );
39
+ let dynamicDictionaries = null;
40
+ if (importMode === "dynamic" || importMode === "live") {
41
+ dynamicDictionaries = await (0, import_writeDynamicDictionary.writeDynamicDictionary)(
42
+ mergedDictionaries,
43
+ configuration,
44
+ formats
45
+ );
46
+ }
47
+ let fetchDictionaries = null;
48
+ if (importMode === "live") {
49
+ fetchDictionaries = await (0, import_writeFetchDictionary.writeFetchDictionary)(
50
+ dynamicDictionaries,
51
+ configuration,
52
+ formats
53
+ );
54
+ }
42
55
  return {
43
56
  unmergedDictionaries,
44
57
  mergedDictionaries,
45
- dynamicDictionaries
58
+ dynamicDictionaries,
59
+ fetchDictionaries
46
60
  };
47
61
  };
48
62
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts"],"sourcesContent":["// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { writeDynamicDictionary } from './writeDynamicDictionary';\nimport { writeMergedDictionaries } from './writeMergedDictionary';\nimport { writeUnmergedDictionaries } from './writeUnmergedDictionary';\n\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const buildIntlayerDictionary = async (\n contentDeclarations: (DictionaryAPI | Dictionary)[],\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n) => {\n const unmergedDictionaries = await writeUnmergedDictionaries(\n contentDeclarations,\n configuration\n );\n\n const mergedDictionaries = await writeMergedDictionaries(\n unmergedDictionaries,\n configuration\n );\n\n const dynamicDictionaries = await writeDynamicDictionary(\n mergedDictionaries,\n configuration,\n formats\n );\n\n return {\n unmergedDictionaries,\n mergedDictionaries,\n dynamicDictionaries,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAiC;AAEjC,oCAAuC;AACvC,mCAAwC;AACxC,qCAA0C;AAKnC,MAAM,0BAA0B,OACrC,qBACA,oBAAgB,gCAAiB,GACjC,UAA6B,CAAC,OAAO,KAAK,MACvC;AACH,QAAM,uBAAuB,UAAM;AAAA,IACjC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,qBAAqB,UAAM;AAAA,IAC/B;AAAA,IACA;AAAA,EACF;AAEA,QAAM,sBAAsB,UAAM;AAAA,IAChC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts"],"sourcesContent":["// @ts-ignore: @intlayer/backend is not built yet\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport {\n LocalizedDictionaryOutput,\n writeDynamicDictionary,\n} from './writeDynamicDictionary';\nimport { writeFetchDictionary } from './writeFetchDictionary';\nimport { writeMergedDictionaries } from './writeMergedDictionary';\nimport { writeUnmergedDictionaries } from './writeUnmergedDictionary';\n\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const buildIntlayerDictionary = async (\n localDictionariesEntries: Dictionary[],\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n) => {\n const { importMode } = configuration.build;\n\n const unmergedDictionaries = await writeUnmergedDictionaries(\n localDictionariesEntries,\n configuration\n );\n\n const mergedDictionaries = await writeMergedDictionaries(\n unmergedDictionaries,\n configuration\n );\n\n let dynamicDictionaries: LocalizedDictionaryOutput | null = null;\n\n if (importMode === 'dynamic' || importMode === 'live') {\n dynamicDictionaries = await writeDynamicDictionary(\n mergedDictionaries,\n configuration,\n formats\n );\n }\n\n let fetchDictionaries: LocalizedDictionaryOutput | null = null;\n\n if (importMode === 'live') {\n fetchDictionaries = await writeFetchDictionary(\n dynamicDictionaries!,\n configuration,\n formats\n );\n }\n\n return {\n unmergedDictionaries,\n mergedDictionaries,\n dynamicDictionaries,\n fetchDictionaries,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAiC;AAEjC,oCAGO;AACP,kCAAqC;AACrC,mCAAwC;AACxC,qCAA0C;AAKnC,MAAM,0BAA0B,OACrC,0BACA,oBAAgB,gCAAiB,GACjC,UAA6B,CAAC,OAAO,KAAK,MACvC;AACH,QAAM,EAAE,WAAW,IAAI,cAAc;AAErC,QAAM,uBAAuB,UAAM;AAAA,IACjC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,qBAAqB,UAAM;AAAA,IAC/B;AAAA,IACA;AAAA,EACF;AAEA,MAAI,sBAAwD;AAE5D,MAAI,eAAe,aAAa,eAAe,QAAQ;AACrD,0BAAsB,UAAM;AAAA,MAC1B;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,oBAAsD;AAE1D,MAAI,eAAe,QAAQ;AACzB,wBAAoB,UAAM;AAAA,MACxB;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -23,9 +23,10 @@ __export(writeDynamicDictionary_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(writeDynamicDictionary_exports);
25
25
  var import_config = require("@intlayer/config");
26
+ var import_core = require("@intlayer/core");
26
27
  var import_promises = require("fs/promises");
27
28
  var import_path = require("path");
28
- var import_getFilteredLocalesContent = require('../../../getFilteredLocalesContent.cjs');
29
+ var import_parallelize = require('../../../utils/parallelize.cjs');
29
30
  var import_formatDictionaryText = require('./formatDictionaryText.cjs');
30
31
  const generateDictionaryEntryPoint = (localedDictionariesPathsRecord, format = "esm", configuration = (0, import_config.getConfiguration)()) => {
31
32
  const { dynamicDictionariesDir } = configuration.content;
@@ -33,9 +34,8 @@ const generateDictionaryEntryPoint = (localedDictionariesPathsRecord, format = "
33
34
  const formattedDictionaryMap = Object.entries(
34
35
  localedDictionariesPathsRecord
35
36
  ).map(([locale, dictionary]) => {
36
- const relativePath = (0, import_path.relative)(
37
- dynamicDictionariesDir,
38
- dictionary.dictionaryPath
37
+ const relativePath = (0, import_config.normalizePath)(
38
+ (0, import_path.relative)(dynamicDictionariesDir, dictionary.dictionaryPath)
39
39
  );
40
40
  if (format === "esm") {
41
41
  return ` '${locale}': () => import('./${relativePath}', { assert: { type: 'json' }}).then(mod => mod.default)`;
@@ -57,47 +57,49 @@ const writeDynamicDictionary = async (mergedDictionaries, configuration = (0, im
57
57
  const { dynamicDictionariesDir } = configuration.content;
58
58
  await (0, import_promises.mkdir)((0, import_path.resolve)(dynamicDictionariesDir), { recursive: true });
59
59
  let resultDictionariesPaths = {};
60
- for await (const [key, dictionaryEntry] of Object.entries(
61
- mergedDictionaries
62
- )) {
63
- if (key === "undefined") continue;
64
- let localedDictionariesPathsRecord = {};
65
- for await (const locale of locales) {
66
- const localizedDictionary = {
67
- ...dictionaryEntry.dictionary,
68
- locale,
69
- content: (0, import_getFilteredLocalesContent.getFilteredLocalesContent)(
70
- dictionaryEntry.dictionary.content,
60
+ await (0, import_parallelize.parallelize)(
61
+ Object.entries(mergedDictionaries),
62
+ async ([key, dictionaryEntry]) => {
63
+ if (key === "undefined") return;
64
+ let localedDictionariesPathsRecord = {};
65
+ await (0, import_parallelize.parallelize)(locales, async (locale) => {
66
+ const localizedDictionary = {
67
+ ...dictionaryEntry.dictionary,
71
68
  locale,
72
- { dictionaryKey: key, keyPath: [] },
73
- defaultLocale
74
- )
75
- };
76
- const contentString = (0, import_formatDictionaryText.formatDictionaryText)(localizedDictionary);
77
- const outputFileName = `${key}.${locale}.json`;
78
- const resultFilePath = (0, import_path.resolve)(dynamicDictionariesDir, outputFileName);
79
- await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
80
- console.error(`Error creating localized ${outputFileName}:`, err);
69
+ // @ts-ignore Type instantiation is excessively deep and possibly infinite
70
+ content: (0, import_core.getLocalisedContent)(
71
+ JSON.parse(JSON.stringify(dictionaryEntry.dictionary.content)),
72
+ locale,
73
+ { dictionaryKey: key, keyPath: [] },
74
+ defaultLocale
75
+ )
76
+ };
77
+ const contentString = (0, import_formatDictionaryText.formatDictionaryText)(localizedDictionary);
78
+ const outputFileName = `${key}.${locale}.json`;
79
+ const resultFilePath = (0, import_path.resolve)(dynamicDictionariesDir, outputFileName);
80
+ await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
81
+ console.error(`Error creating localized ${outputFileName}:`, err);
82
+ });
83
+ localedDictionariesPathsRecord[locale] = {
84
+ dictionaryPath: resultFilePath,
85
+ dictionary: localizedDictionary
86
+ };
87
+ });
88
+ resultDictionariesPaths[key] = localedDictionariesPathsRecord;
89
+ await (0, import_parallelize.parallelize)(formats, async (format) => {
90
+ const extension = format === "cjs" ? "cjs" : "mjs";
91
+ const content = generateDictionaryEntryPoint(
92
+ localedDictionariesPathsRecord,
93
+ format,
94
+ configuration
95
+ );
96
+ await (0, import_promises.writeFile)(
97
+ (0, import_path.resolve)(dynamicDictionariesDir, `${key}.${extension}`),
98
+ content
99
+ );
81
100
  });
82
- localedDictionariesPathsRecord[locale] = {
83
- dictionaryPath: resultFilePath,
84
- dictionary: localizedDictionary
85
- };
86
- }
87
- resultDictionariesPaths[key] = localedDictionariesPathsRecord;
88
- for await (const format of formats) {
89
- const extension = format === "cjs" ? "cjs" : "mjs";
90
- const content = generateDictionaryEntryPoint(
91
- localedDictionariesPathsRecord,
92
- format,
93
- configuration
94
- );
95
- await (0, import_promises.writeFile)(
96
- (0, import_path.resolve)(dynamicDictionariesDir, `${key}.${extension}`),
97
- content
98
- );
99
101
  }
100
- }
102
+ );
101
103
  return resultDictionariesPaths;
102
104
  };
103
105
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.ts"],"sourcesContent":["import { getConfiguration, Locales } from '@intlayer/config';\nimport { type Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { relative, resolve } from 'path';\nimport { getFilteredLocalesContent } from '../../../getFilteredLocalesContent';\nimport { formatDictionaryText } from './formatDictionaryText';\nimport { MergedDictionaryOutput } from './writeMergedDictionary';\n\nexport type DictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type LocalizedDictionaryResult = Partial<\n Record<Locales, DictionaryResult>\n>;\n\nexport type LocalizedDictionaryOutput = Record<\n string,\n LocalizedDictionaryResult\n>;\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 { dynamicDictionariesDir } = configuration.content;\n\n let content = '';\n\n // Format Dictionary Map - map locales to functions\n const formattedDictionaryMap: string = Object.entries(\n localedDictionariesPathsRecord\n )\n .map(([locale, dictionary]) => {\n const relativePath = relative(\n dynamicDictionariesDir,\n dictionary.dictionaryPath\n );\n\n if (format === 'esm') {\n return ` '${locale}': () => import('./${relativePath}', { assert: { type: 'json' }}).then(mod => mod.default)`;\n }\n\n return ` '${locale}': () => 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/dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeDynamicDictionary = async (\n mergedDictionaries: MergedDictionaryOutput,\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n): Promise<LocalizedDictionaryOutput> => {\n const { locales, defaultLocale } = configuration.internationalization;\n const { dynamicDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dynamicDictionariesDir), { recursive: true });\n\n let resultDictionariesPaths: LocalizedDictionaryOutput = {};\n\n // Merge dictionaries with the same key and write to dictionariesDir\n for await (const [key, dictionaryEntry] of Object.entries(\n mergedDictionaries\n )) {\n if (key === 'undefined') continue;\n\n let localedDictionariesPathsRecord: LocalizedDictionaryResult = {};\n\n for await (const locale of locales) {\n const localizedDictionary = {\n ...dictionaryEntry.dictionary,\n locale,\n content: getFilteredLocalesContent(\n dictionaryEntry.dictionary.content as any,\n locale,\n { dictionaryKey: key, keyPath: [] },\n defaultLocale\n ),\n };\n\n const contentString = formatDictionaryText(localizedDictionary);\n\n const outputFileName = `${key}.${locale}.json`;\n const resultFilePath = resolve(dynamicDictionariesDir, outputFileName);\n\n // Write the localized dictionary\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating localized ${outputFileName}:`, err);\n });\n\n localedDictionariesPathsRecord[locale] = {\n dictionaryPath: resultFilePath,\n dictionary: localizedDictionary,\n };\n }\n\n resultDictionariesPaths[key] = localedDictionariesPathsRecord;\n\n for await (const format of formats) {\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n const content = generateDictionaryEntryPoint(\n localedDictionariesPathsRecord,\n format,\n configuration\n );\n\n await writeFile(\n resolve(dynamicDictionariesDir, `${key}.${extension}`),\n content\n );\n }\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0C;AAE1C,sBAAiC;AACjC,kBAAkC;AAClC,uCAA0C;AAC1C,kCAAqC;AAoB9B,MAAM,+BAA+B,CAC1C,gCACA,SAAwB,OACxB,oBAAgB,gCAAiB,MACtB;AACX,QAAM,EAAE,uBAAuB,IAAI,cAAc;AAEjD,MAAI,UAAU;AAGd,QAAM,yBAAiC,OAAO;AAAA,IAC5C;AAAA,EACF,EACG,IAAI,CAAC,CAAC,QAAQ,UAAU,MAAM;AAC7B,UAAM,mBAAe;AAAA,MACnB;AAAA,MACA,WAAW;AAAA,IACb;AAEA,QAAI,WAAW,OAAO;AACpB,aAAO,MAAM,MAAM,sBAAsB,YAAY;AAAA,IACvD;AAEA,WAAO,MAAM,MAAM,uCAAuC,YAAY;AAAA,EACxE,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,yBAAyB,OACpC,oBACA,oBAAgB,gCAAiB,GACjC,UAA6B,CAAC,OAAO,KAAK,MACH;AACvC,QAAM,EAAE,SAAS,cAAc,IAAI,cAAc;AACjD,QAAM,EAAE,uBAAuB,IAAI,cAAc;AAGjD,YAAM,2BAAM,qBAAQ,sBAAsB,GAAG,EAAE,WAAW,KAAK,CAAC;AAEhE,MAAI,0BAAqD,CAAC;AAG1D,mBAAiB,CAAC,KAAK,eAAe,KAAK,OAAO;AAAA,IAChD;AAAA,EACF,GAAG;AACD,QAAI,QAAQ,YAAa;AAEzB,QAAI,iCAA4D,CAAC;AAEjE,qBAAiB,UAAU,SAAS;AAClC,YAAM,sBAAsB;AAAA,QAC1B,GAAG,gBAAgB;AAAA,QACnB;AAAA,QACA,aAAS;AAAA,UACP,gBAAgB,WAAW;AAAA,UAC3B;AAAA,UACA,EAAE,eAAe,KAAK,SAAS,CAAC,EAAE;AAAA,UAClC;AAAA,QACF;AAAA,MACF;AAEA,YAAM,oBAAgB,kDAAqB,mBAAmB;AAE9D,YAAM,iBAAiB,GAAG,GAAG,IAAI,MAAM;AACvC,YAAM,qBAAiB,qBAAQ,wBAAwB,cAAc;AAGrE,gBAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,gBAAQ,MAAM,4BAA4B,cAAc,KAAK,GAAG;AAAA,MAClE,CAAC;AAED,qCAA+B,MAAM,IAAI;AAAA,QACvC,gBAAgB;AAAA,QAChB,YAAY;AAAA,MACd;AAAA,IACF;AAEA,4BAAwB,GAAG,IAAI;AAE/B,qBAAiB,UAAU,SAAS;AAClC,YAAM,YAAY,WAAW,QAAQ,QAAQ;AAC7C,YAAM,UAAU;AAAA,QACd;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAEA,gBAAM;AAAA,YACJ,qBAAQ,wBAAwB,GAAG,GAAG,IAAI,SAAS,EAAE;AAAA,QACrD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.ts"],"sourcesContent":["import { getConfiguration, Locales, normalizePath } from '@intlayer/config';\nimport { getLocalisedContent, type Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { relative, resolve } from 'path';\nimport { parallelize } from '../../../utils/parallelize';\nimport { formatDictionaryText } from './formatDictionaryText';\nimport { MergedDictionaryOutput } from './writeMergedDictionary';\n\nexport type DictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type LocalizedDictionaryResult = Partial<\n Record<Locales, DictionaryResult>\n>;\n\nexport type LocalizedDictionaryOutput = Record<\n string,\n LocalizedDictionaryResult\n>;\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 { dynamicDictionariesDir } = configuration.content;\n\n let content = '';\n\n // Format Dictionary Map - map locales to functions\n const formattedDictionaryMap: string = Object.entries(\n localedDictionariesPathsRecord\n )\n .map(([locale, dictionary]) => {\n const relativePath = normalizePath(\n relative(dynamicDictionariesDir, dictionary.dictionaryPath)\n );\n\n if (format === 'esm') {\n return ` '${locale}': () => import('./${relativePath}', { assert: { type: 'json' }}).then(mod => mod.default)`;\n }\n\n return ` '${locale}': () => 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/dynamic_dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeDynamicDictionary = async (\n mergedDictionaries: MergedDictionaryOutput,\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n): Promise<LocalizedDictionaryOutput> => {\n const { locales, defaultLocale } = configuration.internationalization;\n const { dynamicDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dynamicDictionariesDir), { recursive: true });\n\n let resultDictionariesPaths: LocalizedDictionaryOutput = {};\n\n // Merge dictionaries with the same key and write to dictionariesDir\n await parallelize(\n Object.entries(mergedDictionaries),\n async ([key, dictionaryEntry]) => {\n if (key === 'undefined') return;\n\n let localedDictionariesPathsRecord: LocalizedDictionaryResult = {};\n\n await parallelize(locales, async (locale) => {\n const localizedDictionary = {\n ...dictionaryEntry.dictionary,\n locale,\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n content: getLocalisedContent(\n JSON.parse(JSON.stringify(dictionaryEntry.dictionary.content)),\n locale,\n { dictionaryKey: key, keyPath: [] },\n defaultLocale\n ) as any,\n };\n\n const contentString = formatDictionaryText(localizedDictionary);\n\n const outputFileName = `${key}.${locale}.json`;\n const resultFilePath = resolve(dynamicDictionariesDir, outputFileName);\n\n // Write the localized dictionary\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating localized ${outputFileName}:`, err);\n });\n\n localedDictionariesPathsRecord[locale] = {\n dictionaryPath: resultFilePath,\n dictionary: localizedDictionary,\n };\n });\n\n resultDictionariesPaths[key] = localedDictionariesPathsRecord;\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(dynamicDictionariesDir, `${key}.${extension}`),\n content\n );\n });\n }\n );\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyD;AACzD,kBAAqD;AACrD,sBAAiC;AACjC,kBAAkC;AAClC,yBAA4B;AAC5B,kCAAqC;AAoB9B,MAAM,+BAA+B,CAC1C,gCACA,SAAwB,OACxB,oBAAgB,gCAAiB,MACtB;AACX,QAAM,EAAE,uBAAuB,IAAI,cAAc;AAEjD,MAAI,UAAU;AAGd,QAAM,yBAAiC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AwB,cAAc;AAGrE,kBAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,kBAAQ,MAAM,4BAA4B,cAAc,KAAK,GAAG;AAAA,QAClE,CAAC;AAED,uCAA+B,MAAM,IAAI;AAAA,UACvC,gBAAgB;AAAA,UAChB,YAAY;AAAA,QACd;AAAA,MACF,CAAC;AAED,8BAAwB,GAAG,IAAI;AAE/B,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,wBAAwB,GAAG,GAAG,IAAI,SAAS,EAAE;AAAA,UACrD;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,83 @@
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 writeFetchDictionary_exports = {};
20
+ __export(writeFetchDictionary_exports, {
21
+ generateDictionaryEntryPoint: () => generateDictionaryEntryPoint,
22
+ writeFetchDictionary: () => writeFetchDictionary
23
+ });
24
+ module.exports = __toCommonJS(writeFetchDictionary_exports);
25
+ var import_config = require("@intlayer/config");
26
+ var import_promises = require("fs/promises");
27
+ var import_path = require("path");
28
+ var import_parallelize = require('../../../utils/parallelize.cjs');
29
+ const generateDictionaryEntryPoint = (localedDictionariesPathsRecord, format = "esm", configuration = (0, import_config.getConfiguration)()) => {
30
+ const { fetchDictionariesDir } = configuration.content;
31
+ const { liveSyncURL } = configuration.editor;
32
+ let content = "";
33
+ const formattedDictionaryMap = Object.entries(
34
+ localedDictionariesPathsRecord
35
+ ).map(([locale, dictionary]) => {
36
+ const relativePath = (0, import_config.normalizePath)(
37
+ (0, import_path.relative)(fetchDictionariesDir, dictionary.dictionaryPath)
38
+ );
39
+ if (format === "esm") {
40
+ 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)}})()`;
41
+ }
42
+ return ` '${locale}': () => (async () => { try {return await fetch('${liveSyncURL}/dictionaries/${dictionary.dictionary.key}/${locale}').then(res => res.json())} catch (_error) {return Promise.resolve(require('./${relativePath}.cjs'))}})()`;
43
+ }).join(",\n");
44
+ content += `const content = {
45
+ ${formattedDictionaryMap}
46
+ };
47
+ `;
48
+ if (format === "esm") content += `export default content;
49
+ `;
50
+ if (format === "cjs") content += `module.exports = content;
51
+ `;
52
+ return content;
53
+ };
54
+ const writeFetchDictionary = async (dynamicDictionaries, configuration = (0, import_config.getConfiguration)(), formats = ["cjs", "esm"]) => {
55
+ const { fetchDictionariesDir } = configuration.content;
56
+ await (0, import_promises.mkdir)((0, import_path.resolve)(fetchDictionariesDir), { recursive: true });
57
+ let resultDictionariesPaths = {};
58
+ await (0, import_parallelize.parallelize)(
59
+ Object.entries(dynamicDictionaries),
60
+ async ([key, localedDictionariesPathsRecord]) => {
61
+ if (key === "undefined") return;
62
+ await (0, import_parallelize.parallelize)(formats, async (format) => {
63
+ const extension = format === "cjs" ? "cjs" : "mjs";
64
+ const content = generateDictionaryEntryPoint(
65
+ localedDictionariesPathsRecord,
66
+ format,
67
+ configuration
68
+ );
69
+ await (0, import_promises.writeFile)(
70
+ (0, import_path.resolve)(fetchDictionariesDir, `${key}.${extension}`),
71
+ content
72
+ );
73
+ });
74
+ }
75
+ );
76
+ return resultDictionariesPaths;
77
+ };
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ generateDictionaryEntryPoint,
81
+ writeFetchDictionary
82
+ });
83
+ //# sourceMappingURL=writeFetchDictionary.cjs.map