@intlayer/cli 8.4.4 → 8.4.6

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 (305) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs +186 -1
  2. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  3. package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
  4. package/dist/cjs/_virtual/_utils_asset.cjs +98 -0
  5. package/dist/cjs/auth/login.cjs +90 -2
  6. package/dist/cjs/auth/login.cjs.map +1 -1
  7. package/dist/cjs/build.cjs +30 -1
  8. package/dist/cjs/build.cjs.map +1 -1
  9. package/dist/cjs/ci.cjs +76 -1
  10. package/dist/cjs/ci.cjs.map +1 -1
  11. package/dist/cjs/cli.cjs +485 -1
  12. package/dist/cjs/cli.cjs.map +1 -1
  13. package/dist/cjs/config.cjs +15 -1
  14. package/dist/cjs/config.cjs.map +1 -1
  15. package/dist/cjs/editor.cjs +50 -1
  16. package/dist/cjs/editor.cjs.map +1 -1
  17. package/dist/cjs/extract.cjs +108 -1
  18. package/dist/cjs/extract.cjs.map +1 -1
  19. package/dist/cjs/fill/deepMergeContent.cjs +27 -1
  20. package/dist/cjs/fill/deepMergeContent.cjs.map +1 -1
  21. package/dist/cjs/fill/fill.cjs +89 -1
  22. package/dist/cjs/fill/fill.cjs.map +1 -1
  23. package/dist/cjs/fill/formatAutoFilledFilePath.cjs +32 -1
  24. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
  25. package/dist/cjs/fill/formatFillData.cjs +91 -1
  26. package/dist/cjs/fill/formatFillData.cjs.map +1 -1
  27. package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs +26 -1
  28. package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs.map +1 -1
  29. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs +51 -1
  30. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs.map +1 -1
  31. package/dist/cjs/fill/index.cjs +6 -1
  32. package/dist/cjs/fill/listTranslationsTasks.cjs +72 -1
  33. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -1
  34. package/dist/cjs/fill/translateDictionary.cjs +241 -1
  35. package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
  36. package/dist/cjs/fill/writeFill.cjs +53 -1
  37. package/dist/cjs/fill/writeFill.cjs.map +1 -1
  38. package/dist/cjs/getTargetDictionary.cjs +36 -1
  39. package/dist/cjs/getTargetDictionary.cjs.map +1 -1
  40. package/dist/cjs/index.cjs +44 -1
  41. package/dist/cjs/init.cjs +22 -1
  42. package/dist/cjs/init.cjs.map +1 -1
  43. package/dist/cjs/initMCP.cjs +69 -1
  44. package/dist/cjs/initMCP.cjs.map +1 -1
  45. package/dist/cjs/initSkills.cjs +93 -1
  46. package/dist/cjs/initSkills.cjs.map +1 -1
  47. package/dist/cjs/listContentDeclaration.cjs +42 -1
  48. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  49. package/dist/cjs/listProjects.cjs +28 -1
  50. package/dist/cjs/listProjects.cjs.map +1 -1
  51. package/dist/cjs/liveSync.cjs +153 -8
  52. package/dist/cjs/liveSync.cjs.map +1 -1
  53. package/dist/cjs/pull.cjs +153 -1
  54. package/dist/cjs/pull.cjs.map +1 -1
  55. package/dist/cjs/push/pullLog.cjs +105 -3
  56. package/dist/cjs/push/pullLog.cjs.map +1 -1
  57. package/dist/cjs/push/push.cjs +212 -1
  58. package/dist/cjs/push/push.cjs.map +1 -1
  59. package/dist/cjs/pushConfig.cjs +22 -1
  60. package/dist/cjs/pushConfig.cjs.map +1 -1
  61. package/dist/cjs/pushLog.cjs +86 -3
  62. package/dist/cjs/pushLog.cjs.map +1 -1
  63. package/dist/cjs/reviewDoc/reviewDoc.cjs +73 -1
  64. package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
  65. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +98 -1
  66. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
  67. package/dist/cjs/searchDoc.cjs +41 -1
  68. package/dist/cjs/searchDoc.cjs.map +1 -1
  69. package/dist/cjs/test/index.cjs +7 -1
  70. package/dist/cjs/test/listMissingTranslations.cjs +66 -1
  71. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  72. package/dist/cjs/test/test.cjs +56 -1
  73. package/dist/cjs/test/test.cjs.map +1 -1
  74. package/dist/cjs/translateDoc/index.cjs +9 -1
  75. package/dist/cjs/translateDoc/translateDoc.cjs +79 -1
  76. package/dist/cjs/translateDoc/translateDoc.cjs.map +1 -1
  77. package/dist/cjs/translateDoc/translateFile.cjs +106 -2
  78. package/dist/cjs/translateDoc/translateFile.cjs.map +1 -1
  79. package/dist/cjs/translateDoc/validation.cjs +49 -5
  80. package/dist/cjs/translateDoc/validation.cjs.map +1 -1
  81. package/dist/cjs/translation-alignment/alignBlocks.cjs +67 -1
  82. package/dist/cjs/translation-alignment/alignBlocks.cjs.map +1 -1
  83. package/dist/cjs/translation-alignment/computeSimilarity.cjs +25 -1
  84. package/dist/cjs/translation-alignment/computeSimilarity.cjs.map +1 -1
  85. package/dist/cjs/translation-alignment/fingerprintBlock.cjs +23 -1
  86. package/dist/cjs/translation-alignment/fingerprintBlock.cjs.map +1 -1
  87. package/dist/cjs/translation-alignment/index.cjs +22 -1
  88. package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs +18 -1
  89. package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs.map +1 -1
  90. package/dist/cjs/translation-alignment/normalizeBlock.cjs +22 -1
  91. package/dist/cjs/translation-alignment/normalizeBlock.cjs.map +1 -1
  92. package/dist/cjs/translation-alignment/pipeline.cjs +37 -1
  93. package/dist/cjs/translation-alignment/pipeline.cjs.map +1 -1
  94. package/dist/cjs/translation-alignment/planActions.cjs +46 -1
  95. package/dist/cjs/translation-alignment/planActions.cjs.map +1 -1
  96. package/dist/cjs/translation-alignment/rebuildDocument.cjs +49 -2
  97. package/dist/cjs/translation-alignment/rebuildDocument.cjs.map +1 -1
  98. package/dist/cjs/translation-alignment/segmentDocument.cjs +66 -5
  99. package/dist/cjs/translation-alignment/segmentDocument.cjs.map +1 -1
  100. package/dist/cjs/utils/calculateChunks.cjs +89 -2
  101. package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
  102. package/dist/cjs/utils/checkAccess.cjs +83 -1
  103. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  104. package/dist/cjs/utils/checkConfigConsistency.cjs +16 -1
  105. package/dist/cjs/utils/checkConfigConsistency.cjs.map +1 -1
  106. package/dist/cjs/utils/checkFileModifiedRange.cjs +81 -1
  107. package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
  108. package/dist/cjs/utils/checkLastUpdateTime.cjs +19 -1
  109. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
  110. package/dist/cjs/utils/chunkInference.cjs +45 -1
  111. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  112. package/dist/cjs/utils/fixChunkStartEndChars.cjs +27 -3
  113. package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
  114. package/dist/cjs/utils/formatTimeDiff.cjs +20 -1
  115. package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
  116. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +16 -1
  117. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
  118. package/dist/cjs/utils/getOutputFilePath.cjs +108 -1
  119. package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
  120. package/dist/cjs/utils/getParentPackageJSON.cjs +20 -1
  121. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
  122. package/dist/cjs/utils/listSpecialChars.cjs +54 -2
  123. package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
  124. package/dist/cjs/utils/mapChunksBetweenFiles.cjs +102 -1
  125. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
  126. package/dist/cjs/utils/openBrowser.cjs +19 -1
  127. package/dist/cjs/utils/openBrowser.cjs.map +1 -1
  128. package/dist/cjs/utils/reorderParagraphs.cjs +91 -3
  129. package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
  130. package/dist/cjs/utils/setupAI.cjs +66 -1
  131. package/dist/cjs/utils/setupAI.cjs.map +1 -1
  132. package/dist/cjs/watch.cjs +47 -1
  133. package/dist/cjs/watch.cjs.map +1 -1
  134. package/dist/esm/IntlayerEventListener.mjs +183 -1
  135. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  136. package/dist/esm/_virtual/_rolldown/runtime.mjs +8 -0
  137. package/dist/esm/_virtual/_utils_asset.mjs +97 -0
  138. package/dist/esm/auth/login.mjs +86 -2
  139. package/dist/esm/auth/login.mjs.map +1 -1
  140. package/dist/esm/build.mjs +28 -1
  141. package/dist/esm/build.mjs.map +1 -1
  142. package/dist/esm/ci.mjs +74 -1
  143. package/dist/esm/ci.mjs.map +1 -1
  144. package/dist/esm/cli.mjs +482 -1
  145. package/dist/esm/cli.mjs.map +1 -1
  146. package/dist/esm/config.mjs +13 -1
  147. package/dist/esm/config.mjs.map +1 -1
  148. package/dist/esm/editor.mjs +50 -1
  149. package/dist/esm/editor.mjs.map +1 -0
  150. package/dist/esm/extract.mjs +104 -1
  151. package/dist/esm/extract.mjs.map +1 -1
  152. package/dist/esm/fill/deepMergeContent.mjs +25 -1
  153. package/dist/esm/fill/deepMergeContent.mjs.map +1 -1
  154. package/dist/esm/fill/fill.mjs +86 -1
  155. package/dist/esm/fill/fill.mjs.map +1 -1
  156. package/dist/esm/fill/formatAutoFilledFilePath.mjs +30 -1
  157. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
  158. package/dist/esm/fill/formatFillData.mjs +89 -1
  159. package/dist/esm/fill/formatFillData.mjs.map +1 -1
  160. package/dist/esm/fill/getAvailableLocalesInDictionary.mjs +24 -1
  161. package/dist/esm/fill/getAvailableLocalesInDictionary.mjs.map +1 -1
  162. package/dist/esm/fill/getFilterMissingContentPerLocale.mjs +49 -1
  163. package/dist/esm/fill/getFilterMissingContentPerLocale.mjs.map +1 -1
  164. package/dist/esm/fill/index.mjs +4 -1
  165. package/dist/esm/fill/listTranslationsTasks.mjs +69 -1
  166. package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -1
  167. package/dist/esm/fill/translateDictionary.mjs +238 -1
  168. package/dist/esm/fill/translateDictionary.mjs.map +1 -1
  169. package/dist/esm/fill/writeFill.mjs +51 -1
  170. package/dist/esm/fill/writeFill.mjs.map +1 -1
  171. package/dist/esm/getTargetDictionary.mjs +33 -1
  172. package/dist/esm/getTargetDictionary.mjs.map +1 -1
  173. package/dist/esm/index.mjs +20 -1
  174. package/dist/esm/init.mjs +19 -1
  175. package/dist/esm/init.mjs.map +1 -1
  176. package/dist/esm/initMCP.mjs +65 -1
  177. package/dist/esm/initMCP.mjs.map +1 -1
  178. package/dist/esm/initSkills.mjs +87 -1
  179. package/dist/esm/initSkills.mjs.map +1 -1
  180. package/dist/esm/listContentDeclaration.mjs +39 -1
  181. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  182. package/dist/esm/listProjects.mjs +26 -1
  183. package/dist/esm/listProjects.mjs.map +1 -1
  184. package/dist/esm/liveSync.mjs +150 -8
  185. package/dist/esm/liveSync.mjs.map +1 -1
  186. package/dist/esm/pull.mjs +150 -1
  187. package/dist/esm/pull.mjs.map +1 -1
  188. package/dist/esm/push/pullLog.mjs +102 -3
  189. package/dist/esm/push/pullLog.mjs.map +1 -1
  190. package/dist/esm/push/push.mjs +208 -1
  191. package/dist/esm/push/push.mjs.map +1 -1
  192. package/dist/esm/pushConfig.mjs +20 -1
  193. package/dist/esm/pushConfig.mjs.map +1 -1
  194. package/dist/esm/pushLog.mjs +83 -3
  195. package/dist/esm/pushLog.mjs.map +1 -1
  196. package/dist/esm/reviewDoc/reviewDoc.mjs +69 -1
  197. package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
  198. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +95 -1
  199. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
  200. package/dist/esm/searchDoc.mjs +39 -1
  201. package/dist/esm/searchDoc.mjs.map +1 -1
  202. package/dist/esm/test/index.mjs +4 -1
  203. package/dist/esm/test/listMissingTranslations.mjs +63 -1
  204. package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
  205. package/dist/esm/test/test.mjs +53 -1
  206. package/dist/esm/test/test.mjs.map +1 -1
  207. package/dist/esm/translateDoc/index.mjs +5 -1
  208. package/dist/esm/translateDoc/translateDoc.mjs +75 -1
  209. package/dist/esm/translateDoc/translateDoc.mjs.map +1 -1
  210. package/dist/esm/translateDoc/translateFile.mjs +103 -2
  211. package/dist/esm/translateDoc/translateFile.mjs.map +1 -1
  212. package/dist/esm/translateDoc/validation.mjs +46 -5
  213. package/dist/esm/translateDoc/validation.mjs.map +1 -1
  214. package/dist/esm/translation-alignment/alignBlocks.mjs +66 -1
  215. package/dist/esm/translation-alignment/alignBlocks.mjs.map +1 -1
  216. package/dist/esm/translation-alignment/computeSimilarity.mjs +22 -1
  217. package/dist/esm/translation-alignment/computeSimilarity.mjs.map +1 -1
  218. package/dist/esm/translation-alignment/fingerprintBlock.mjs +20 -1
  219. package/dist/esm/translation-alignment/fingerprintBlock.mjs.map +1 -1
  220. package/dist/esm/translation-alignment/index.mjs +11 -1
  221. package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs +16 -1
  222. package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs.map +1 -1
  223. package/dist/esm/translation-alignment/normalizeBlock.mjs +20 -1
  224. package/dist/esm/translation-alignment/normalizeBlock.mjs.map +1 -1
  225. package/dist/esm/translation-alignment/pipeline.mjs +35 -1
  226. package/dist/esm/translation-alignment/pipeline.mjs.map +1 -1
  227. package/dist/esm/translation-alignment/planActions.mjs +44 -1
  228. package/dist/esm/translation-alignment/planActions.mjs.map +1 -1
  229. package/dist/esm/translation-alignment/rebuildDocument.mjs +46 -2
  230. package/dist/esm/translation-alignment/rebuildDocument.mjs.map +1 -1
  231. package/dist/esm/translation-alignment/segmentDocument.mjs +64 -5
  232. package/dist/esm/translation-alignment/segmentDocument.mjs.map +1 -1
  233. package/dist/esm/utils/calculateChunks.mjs +87 -2
  234. package/dist/esm/utils/calculateChunks.mjs.map +1 -1
  235. package/dist/esm/utils/checkAccess.mjs +79 -1
  236. package/dist/esm/utils/checkAccess.mjs.map +1 -1
  237. package/dist/esm/utils/checkConfigConsistency.mjs +14 -1
  238. package/dist/esm/utils/checkConfigConsistency.mjs.map +1 -1
  239. package/dist/esm/utils/checkFileModifiedRange.mjs +80 -1
  240. package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
  241. package/dist/esm/utils/checkLastUpdateTime.mjs +17 -1
  242. package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
  243. package/dist/esm/utils/chunkInference.mjs +43 -1
  244. package/dist/esm/utils/chunkInference.mjs.map +1 -1
  245. package/dist/esm/utils/fixChunkStartEndChars.mjs +25 -3
  246. package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
  247. package/dist/esm/utils/formatTimeDiff.mjs +18 -1
  248. package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
  249. package/dist/esm/utils/getIsFileUpdatedRecently.mjs +14 -1
  250. package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
  251. package/dist/esm/utils/getOutputFilePath.mjs +104 -1
  252. package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
  253. package/dist/esm/utils/getParentPackageJSON.mjs +18 -1
  254. package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
  255. package/dist/esm/utils/listSpecialChars.mjs +52 -2
  256. package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
  257. package/dist/esm/utils/mapChunksBetweenFiles.mjs +100 -1
  258. package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
  259. package/dist/esm/utils/openBrowser.mjs +17 -1
  260. package/dist/esm/utils/openBrowser.mjs.map +1 -1
  261. package/dist/esm/utils/reorderParagraphs.mjs +90 -3
  262. package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
  263. package/dist/esm/utils/setupAI.mjs +63 -1
  264. package/dist/esm/utils/setupAI.mjs.map +1 -1
  265. package/dist/esm/watch.mjs +45 -1
  266. package/dist/esm/watch.mjs.map +1 -1
  267. package/dist/types/fill/fill.d.ts +1 -1
  268. package/dist/types/fill/fill.d.ts.map +1 -1
  269. package/dist/types/fill/formatFillData.d.ts.map +1 -1
  270. package/dist/types/fill/translateDictionary.d.ts +1 -1
  271. package/dist/types/getTargetDictionary.d.ts +19 -2
  272. package/dist/types/getTargetDictionary.d.ts.map +1 -0
  273. package/dist/types/index.d.ts +2 -2
  274. package/dist/types/reviewDoc/reviewDocBlockAware.d.ts +1 -1
  275. package/dist/types/test/index.d.ts +2 -2
  276. package/dist/types/test/listMissingTranslations.d.ts +28 -2
  277. package/dist/types/test/listMissingTranslations.d.ts.map +1 -0
  278. package/dist/types/test/test.d.ts +11 -2
  279. package/dist/types/test/test.d.ts.map +1 -0
  280. package/dist/types/translateDoc/index.d.ts +1 -1
  281. package/dist/types/translateDoc/translateDoc.d.ts +1 -1
  282. package/dist/types/translateDoc/translateFile.d.ts +1 -1
  283. package/dist/types/translateDoc/types.d.ts +48 -2
  284. package/dist/types/translateDoc/types.d.ts.map +1 -0
  285. package/dist/types/utils/chunkInference.d.ts +1 -1
  286. package/dist/types/utils/getOutputFilePath.d.ts +18 -1
  287. package/dist/types/utils/getOutputFilePath.d.ts.map +1 -1
  288. package/dist/types/utils/setupAI.d.ts +21 -2
  289. package/dist/types/utils/setupAI.d.ts.map +1 -0
  290. package/package.json +12 -12
  291. package/dist/cjs/_utils_asset-ghp_Cjwk.cjs +0 -2
  292. package/dist/cjs/chunk-Bmb41Sf3.cjs +0 -1
  293. package/dist/esm/_utils_asset-B187VPMw.mjs +0 -2
  294. package/dist/esm/editor-D8BGlLzF.mjs +0 -2
  295. package/dist/esm/editor-D8BGlLzF.mjs.map +0 -1
  296. package/dist/types/getTargetDictionary-RBSRtaQj.d.ts +0 -19
  297. package/dist/types/getTargetDictionary-RBSRtaQj.d.ts.map +0 -1
  298. package/dist/types/listMissingTranslations-DxKw7nqI.d.ts +0 -28
  299. package/dist/types/listMissingTranslations-DxKw7nqI.d.ts.map +0 -1
  300. package/dist/types/setupAI-Bosjx7ah.d.ts +0 -21
  301. package/dist/types/setupAI-Bosjx7ah.d.ts.map +0 -1
  302. package/dist/types/test-DUTiJR5_.d.ts +0 -11
  303. package/dist/types/test-DUTiJR5_.d.ts.map +0 -1
  304. package/dist/types/types-BKvc3FmV.d.ts +0 -48
  305. package/dist/types/types-BKvc3FmV.d.ts.map +0 -1
package/dist/cjs/pull.cjs CHANGED
@@ -1,2 +1,154 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-Bmb41Sf3.cjs`),t=require(`./utils/checkAccess.cjs`),n=require(`./push/pullLog.cjs`);let r=require(`node:fs`),i=require(`node:path`),a=require(`@intlayer/chokidar/build`),o=require(`@intlayer/chokidar/cli`),s=require(`@intlayer/chokidar/utils`),c=require(`@intlayer/config/colors`);c=e.t(c);let l=require(`@intlayer/config/logger`),u=require(`@intlayer/config/node`),d=require(`@intlayer/unmerged-dictionaries-entry`),f=require(`@intlayer/api`),p=require(`@intlayer/config/utils`);const m=async e=>{let m=(0,l.getAppLogger)(e?.configOptions?.override);try{let l=(0,u.getConfiguration)(e?.configOptions);if((0,o.logConfigDetails)(e?.configOptions),!await t.checkCMSAuth(l))return;let h=(0,f.getIntlayerAPIProxy)(void 0,l),g=(0,d.getUnmergedDictionaries)(l),_=await h.dictionary.getDictionariesUpdateTimestamp();if(!_.data)throw Error(`No distant dictionaries found`);let v=_.data;e?.dictionaries&&(v=Object.fromEntries(Object.entries(v).filter(([t])=>e.dictionaries?.includes(t)))),v=Object.fromEntries(Object.entries(v).filter(([e])=>{let t=g[e]?.[0]?.location??l.dictionary?.location??`remote`;return t===`remote`||t===`hybrid`}));let y=(0,i.join)(l.system.mainDir,`remote_dictionaries.cjs`),b=l.build?.require??(0,p.getProjectRequire)(),x=(0,r.existsSync)(y)?b(y):{},S=Object.entries(v),C=S.filter(([e,t])=>{if(!t)return!0;let n=typeof t==`object`?t.updatedAt:t,r=x[e];if(!r)return!0;let i=r?.updatedAt,a=typeof i==`number`?i:i?new Date(i).getTime():void 0;return typeof a==`number`?n>a:!0}).map(([e])=>e),w=S.filter(([e,t])=>{let n=typeof t==`object`?t.updatedAt:t,r=x[e]?.updatedAt,i=typeof r==`number`?r:r?new Date(r).getTime():void 0;return typeof i==`number`&&typeof n==`number`&&i>=n}).map(([e])=>e);if(S.length===0){m(`No dictionaries to fetch`,{level:`error`});return}m(`Fetching dictionaries:`);let T=[...w.map(e=>({dictionaryKey:e,status:`imported`})),...C.map(e=>({dictionaryKey:e,status:`pending`}))],E=new n.PullLogger;E.update(T.map(e=>({dictionaryKey:e.dictionaryKey,status:e.status})));let D=[];await(0,s.parallelize)(T,async t=>{let n=t.status===`imported`||t.status===`up-to-date`;n||(t.status=`fetching`,E.update([{dictionaryKey:t.dictionaryKey,status:`fetching`}]));try{let r;if(n&&(r=x[t.dictionaryKey]),r||=(await h.dictionary.getDictionary(t.dictionaryKey)).data,!r)throw Error(`Dictionary ${t.dictionaryKey} not found on remote`);let i=g[t.dictionaryKey]?.find(e=>e.location===`hybrid`);i&&(r={...r,location:`hybrid`,filePath:i.filePath,localId:i.localId});let{status:o}=await(0,a.writeContentDeclaration)(r,l,e);t.status=o,E.update([{dictionaryKey:t.dictionaryKey,status:o}]),D.push(r)}catch(e){t.status=`error`,t.error=e,t.errorMessage=`Error fetching dictionary ${t.dictionaryKey}: ${e}`,E.update([{dictionaryKey:t.dictionaryKey,status:`error`}])}},5),E.finish();let O=e=>{switch(e){case`fetched`:case`imported`:case`updated`:case`up-to-date`:case`reimported in JSON`:case`new content file`:return`✔`;case`error`:return`✖`;default:return`⏲`}},k=e=>{switch(e){case`fetched`:case`imported`:case`updated`:case`up-to-date`:return c.GREEN;case`reimported in JSON`:case`new content file`:return c.YELLOW;case`error`:return c.RED;default:return c.BLUE}};for(let e of T){let t=O(e.status),n=k(e.status);m(` - ${e.dictionaryKey} ${c.GREY}[${n}${t} ${e.status}${c.GREY}]${c.RESET}`)}for(let e of T)e.errorMessage&&m(e.errorMessage,{level:`error`})}catch(e){m(e,{level:`error`})}};exports.pull=m;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_utils_checkAccess = require('./utils/checkAccess.cjs');
4
+ const require_push_pullLog = require('./push/pullLog.cjs');
5
+ let node_fs = require("node:fs");
6
+ let node_path = require("node:path");
7
+ let _intlayer_chokidar_build = require("@intlayer/chokidar/build");
8
+ let _intlayer_chokidar_cli = require("@intlayer/chokidar/cli");
9
+ let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
10
+ let _intlayer_config_colors = require("@intlayer/config/colors");
11
+ _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
12
+ let _intlayer_config_logger = require("@intlayer/config/logger");
13
+ let _intlayer_config_node = require("@intlayer/config/node");
14
+ let _intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
15
+ let _intlayer_api = require("@intlayer/api");
16
+ let _intlayer_config_utils = require("@intlayer/config/utils");
17
+
18
+ //#region src/pull.ts
19
+ /**
20
+ * Fetch distant dictionaries and write them locally,
21
+ * with progress indicators and concurrency control.
22
+ */
23
+ const pull = async (options) => {
24
+ const appLogger = (0, _intlayer_config_logger.getAppLogger)(options?.configOptions?.override);
25
+ try {
26
+ const config = (0, _intlayer_config_node.getConfiguration)(options?.configOptions);
27
+ (0, _intlayer_chokidar_cli.logConfigDetails)(options?.configOptions);
28
+ if (!await require_utils_checkAccess.checkCMSAuth(config)) return;
29
+ const intlayerAPI = (0, _intlayer_api.getIntlayerAPIProxy)(void 0, config);
30
+ const unmergedDictionariesRecord = (0, _intlayer_unmerged_dictionaries_entry.getUnmergedDictionaries)(config);
31
+ const getDictionariesUpdateTimestampResult = await intlayerAPI.dictionary.getDictionariesUpdateTimestamp();
32
+ if (!getDictionariesUpdateTimestampResult.data) throw new Error("No distant dictionaries found");
33
+ let distantDictionariesUpdateTimeStamp = getDictionariesUpdateTimestampResult.data;
34
+ if (options?.dictionaries) distantDictionariesUpdateTimeStamp = Object.fromEntries(Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) => options.dictionaries?.includes(key)));
35
+ distantDictionariesUpdateTimeStamp = Object.fromEntries(Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) => {
36
+ const location = unmergedDictionariesRecord[key]?.[0]?.location ?? config.dictionary?.location ?? "remote";
37
+ return location === "remote" || location === "hybrid";
38
+ }));
39
+ const remoteDictionariesPath = (0, node_path.join)(config.system.mainDir, "remote_dictionaries.cjs");
40
+ const requireFunction = config.build?.require ?? (0, _intlayer_config_utils.getProjectRequire)();
41
+ const remoteDictionariesRecord = (0, node_fs.existsSync)(remoteDictionariesPath) ? requireFunction(remoteDictionariesPath) : {};
42
+ const entries = Object.entries(distantDictionariesUpdateTimeStamp);
43
+ const keysToFetch = entries.filter(([key, remoteUpdatedAtValue]) => {
44
+ if (!remoteUpdatedAtValue) return true;
45
+ const remoteUpdatedAt = typeof remoteUpdatedAtValue === "object" ? remoteUpdatedAtValue.updatedAt : remoteUpdatedAtValue;
46
+ const local = remoteDictionariesRecord[key];
47
+ if (!local) return true;
48
+ const localUpdatedAtRaw = local?.updatedAt;
49
+ const localUpdatedAt = typeof localUpdatedAtRaw === "number" ? localUpdatedAtRaw : localUpdatedAtRaw ? new Date(localUpdatedAtRaw).getTime() : void 0;
50
+ if (typeof localUpdatedAt !== "number") return true;
51
+ return remoteUpdatedAt > localUpdatedAt;
52
+ }).map(([key]) => key);
53
+ const cachedKeys = entries.filter(([key, remoteUpdatedAtValue]) => {
54
+ const remoteUpdatedAt = typeof remoteUpdatedAtValue === "object" ? remoteUpdatedAtValue.updatedAt : remoteUpdatedAtValue;
55
+ const localUpdatedAtRaw = remoteDictionariesRecord[key]?.updatedAt;
56
+ const localUpdatedAt = typeof localUpdatedAtRaw === "number" ? localUpdatedAtRaw : localUpdatedAtRaw ? new Date(localUpdatedAtRaw).getTime() : void 0;
57
+ return typeof localUpdatedAt === "number" && typeof remoteUpdatedAt === "number" && localUpdatedAt >= remoteUpdatedAt;
58
+ }).map(([key]) => key);
59
+ if (entries.length === 0) {
60
+ appLogger("No dictionaries to fetch", { level: "error" });
61
+ return;
62
+ }
63
+ appLogger("Fetching dictionaries:");
64
+ const dictionariesStatuses = [...cachedKeys.map((dictionaryKey) => ({
65
+ dictionaryKey,
66
+ status: "imported"
67
+ })), ...keysToFetch.map((dictionaryKey) => ({
68
+ dictionaryKey,
69
+ status: "pending"
70
+ }))];
71
+ const logger = new require_push_pullLog.PullLogger();
72
+ logger.update(dictionariesStatuses.map((s) => ({
73
+ dictionaryKey: s.dictionaryKey,
74
+ status: s.status
75
+ })));
76
+ const successfullyFetchedDictionaries = [];
77
+ const processDictionary = async (statusObj) => {
78
+ const isCached = statusObj.status === "imported" || statusObj.status === "up-to-date";
79
+ if (!isCached) {
80
+ statusObj.status = "fetching";
81
+ logger.update([{
82
+ dictionaryKey: statusObj.dictionaryKey,
83
+ status: "fetching"
84
+ }]);
85
+ }
86
+ try {
87
+ let sourceDictionary;
88
+ if (isCached) sourceDictionary = remoteDictionariesRecord[statusObj.dictionaryKey];
89
+ if (!sourceDictionary) sourceDictionary = (await intlayerAPI.dictionary.getDictionary(statusObj.dictionaryKey)).data;
90
+ if (!sourceDictionary) throw new Error(`Dictionary ${statusObj.dictionaryKey} not found on remote`);
91
+ const localAndRemoteDictionary = unmergedDictionariesRecord[statusObj.dictionaryKey]?.find((d) => d.location === "hybrid");
92
+ if (localAndRemoteDictionary) sourceDictionary = {
93
+ ...sourceDictionary,
94
+ location: "hybrid",
95
+ filePath: localAndRemoteDictionary.filePath,
96
+ localId: localAndRemoteDictionary.localId
97
+ };
98
+ const { status } = await (0, _intlayer_chokidar_build.writeContentDeclaration)(sourceDictionary, config, options);
99
+ statusObj.status = status;
100
+ logger.update([{
101
+ dictionaryKey: statusObj.dictionaryKey,
102
+ status
103
+ }]);
104
+ successfullyFetchedDictionaries.push(sourceDictionary);
105
+ } catch (error) {
106
+ statusObj.status = "error";
107
+ statusObj.error = error;
108
+ statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;
109
+ logger.update([{
110
+ dictionaryKey: statusObj.dictionaryKey,
111
+ status: "error"
112
+ }]);
113
+ }
114
+ };
115
+ await (0, _intlayer_chokidar_utils.parallelize)(dictionariesStatuses, processDictionary, 5);
116
+ logger.finish();
117
+ const iconFor = (status) => {
118
+ switch (status) {
119
+ case "fetched":
120
+ case "imported":
121
+ case "updated":
122
+ case "up-to-date":
123
+ case "reimported in JSON":
124
+ case "new content file": return "✔";
125
+ case "error": return "✖";
126
+ default: return "⏲";
127
+ }
128
+ };
129
+ const colorFor = (status) => {
130
+ switch (status) {
131
+ case "fetched":
132
+ case "imported":
133
+ case "updated":
134
+ case "up-to-date": return _intlayer_config_colors.GREEN;
135
+ case "reimported in JSON":
136
+ case "new content file": return _intlayer_config_colors.YELLOW;
137
+ case "error": return _intlayer_config_colors.RED;
138
+ default: return _intlayer_config_colors.BLUE;
139
+ }
140
+ };
141
+ for (const s of dictionariesStatuses) {
142
+ const icon = iconFor(s.status);
143
+ const color = colorFor(s.status);
144
+ appLogger(` - ${s.dictionaryKey} ${_intlayer_config_colors.GREY}[${color}${icon} ${s.status}${_intlayer_config_colors.GREY}]${_intlayer_config_colors.RESET}`);
145
+ }
146
+ for (const statusObj of dictionariesStatuses) if (statusObj.errorMessage) appLogger(statusObj.errorMessage, { level: "error" });
147
+ } catch (error) {
148
+ appLogger(error, { level: "error" });
149
+ }
150
+ };
151
+
152
+ //#endregion
153
+ exports.pull = pull;
2
154
  //# sourceMappingURL=pull.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"pull.cjs","names":["checkCMSAuth","PullLogger","ANSIColors"],"sources":["../../src/pull.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n type DictionaryStatus,\n writeContentDeclaration,\n} from '@intlayer/chokidar/build';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport { parallelize } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { getProjectRequire } from '@intlayer/config/utils';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { PullLogger, type PullStatus } from './push/pullLog';\nimport { checkCMSAuth } from './utils/checkAccess';\n\ntype PullOptions = {\n dictionaries?: string[];\n newDictionariesPath?: string;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionaryKey: string;\n status: DictionaryStatus | 'pending' | 'fetching' | 'error';\n error?: Error;\n errorMessage?: string;\n};\n\n/**\n * Fetch distant dictionaries and write them locally,\n * with progress indicators and concurrency control.\n */\nexport const pull = async (options?: PullOptions): Promise<void> => {\n const appLogger = getAppLogger(options?.configOptions?.override);\n\n try {\n const config = getConfiguration(options?.configOptions);\n logConfigDetails(options?.configOptions);\n\n const hasCMSAuth = await checkCMSAuth(config);\n\n if (!hasCMSAuth) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(config);\n\n // Get remote update timestamps map\n const getDictionariesUpdateTimestampResult =\n await intlayerAPI.dictionary.getDictionariesUpdateTimestamp();\n\n if (!getDictionariesUpdateTimestampResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n let distantDictionariesUpdateTimeStamp: Record<string, any> =\n getDictionariesUpdateTimestampResult.data;\n\n // Optional filtering by requested dictionaries\n if (options?.dictionaries) {\n distantDictionariesUpdateTimeStamp = Object.fromEntries(\n Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) =>\n options.dictionaries?.includes(key)\n )\n );\n }\n\n // Filter by location\n distantDictionariesUpdateTimeStamp = Object.fromEntries(\n Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) => {\n const localDictionaries = unmergedDictionariesRecord[key];\n const location =\n localDictionaries?.[0]?.location ??\n config.dictionary?.location ??\n 'remote';\n\n return location === 'remote' || location === 'hybrid';\n })\n );\n\n // Load local cached remote dictionaries (if any)\n const remoteDictionariesPath = join(\n config.system.mainDir,\n 'remote_dictionaries.cjs'\n );\n const requireFunction = config.build?.require ?? getProjectRequire();\n const remoteDictionariesRecord: Record<string, any> = existsSync(\n remoteDictionariesPath\n )\n ? (requireFunction(remoteDictionariesPath) as any)\n : {};\n\n // Determine which keys need fetching by comparing updatedAt with local cache\n const entries = Object.entries(distantDictionariesUpdateTimeStamp);\n const keysToFetch = entries\n .filter(([key, remoteUpdatedAtValue]) => {\n if (!remoteUpdatedAtValue) return true;\n\n const remoteUpdatedAt =\n typeof remoteUpdatedAtValue === 'object'\n ? (remoteUpdatedAtValue as any).updatedAt\n : remoteUpdatedAtValue;\n\n const local = (remoteDictionariesRecord as any)[key];\n if (!local) return true;\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n if (typeof localUpdatedAt !== 'number') return true;\n return remoteUpdatedAt > localUpdatedAt;\n })\n .map(([key]) => key);\n\n const cachedKeys = entries\n .filter(([key, remoteUpdatedAtValue]) => {\n const remoteUpdatedAt =\n typeof remoteUpdatedAtValue === 'object'\n ? (remoteUpdatedAtValue as any).updatedAt\n : remoteUpdatedAtValue;\n\n const local = (remoteDictionariesRecord as any)[key];\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n return (\n typeof localUpdatedAt === 'number' &&\n typeof remoteUpdatedAt === 'number' &&\n localUpdatedAt >= remoteUpdatedAt\n );\n })\n .map(([key]) => key);\n\n // Check if dictionaries list is empty\n if (entries.length === 0) {\n appLogger('No dictionaries to fetch', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Fetching dictionaries:');\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = [\n ...cachedKeys.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'imported' as DictionaryStatus,\n })),\n ...keysToFetch.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'pending' as const,\n })),\n ];\n\n // Initialize aggregated logger\n const logger = new PullLogger();\n logger.update(\n dictionariesStatuses.map<PullStatus>((s) => ({\n dictionaryKey: s.dictionaryKey,\n status: s.status,\n }))\n );\n\n const successfullyFetchedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n const isCached =\n statusObj.status === 'imported' || statusObj.status === 'up-to-date';\n\n if (!isCached) {\n statusObj.status = 'fetching';\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'fetching' },\n ]);\n }\n\n try {\n let sourceDictionary: Dictionary | undefined;\n\n if (isCached) {\n sourceDictionary = remoteDictionariesRecord[\n statusObj.dictionaryKey\n ] as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n // Fetch the dictionary\n const getDictionaryResult =\n await intlayerAPI.dictionary.getDictionary(statusObj.dictionaryKey);\n\n sourceDictionary = getDictionaryResult.data as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n throw new Error(\n `Dictionary ${statusObj.dictionaryKey} not found on remote`\n );\n }\n\n // Check if there is a local version of this dictionary that is hybrid\n const localDictionaries =\n unmergedDictionariesRecord[statusObj.dictionaryKey];\n const localAndRemoteDictionary = localDictionaries?.find(\n (d) => d.location === 'hybrid'\n );\n\n if (localAndRemoteDictionary) {\n // We want to preserve the local properties but use the remote content\n sourceDictionary = {\n ...sourceDictionary,\n location: 'hybrid',\n filePath: localAndRemoteDictionary.filePath,\n localId: localAndRemoteDictionary.localId,\n };\n }\n\n // Now, write the dictionary to local file\n const { status } = await writeContentDeclaration(\n sourceDictionary,\n config,\n options\n );\n\n statusObj.status = status;\n logger.update([{ dictionaryKey: statusObj.dictionaryKey, status }]);\n\n successfullyFetchedDictionaries.push(sourceDictionary);\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'error' },\n ]);\n }\n };\n\n // Process dictionaries in parallel with concurrency limit\n await parallelize(dictionariesStatuses, processDictionary, 5);\n\n // Stop the logger and render final state\n logger.finish();\n\n // Per-dictionary summary\n const iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n case 'reimported in JSON':\n case 'new content file':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n };\n\n const colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n return ANSIColors.GREEN;\n case 'reimported in JSON':\n case 'new content file':\n return ANSIColors.YELLOW;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n };\n\n for (const s of dictionariesStatuses) {\n const icon = iconFor(s.status);\n const color = colorFor(s.status);\n appLogger(\n ` - ${s.dictionaryKey} ${ANSIColors.GREY}[${color}${icon} ${s.status}${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n"],"mappings":"4jBAsCA,MAAa,EAAO,KAAO,IAAyC,CAClE,IAAM,GAAA,EAAA,EAAA,cAAyB,GAAS,eAAe,SAAS,CAEhE,GAAI,CACF,IAAM,GAAA,EAAA,EAAA,kBAA0B,GAAS,cAAc,CAKvD,IAJA,EAAA,EAAA,kBAAiB,GAAS,cAAc,CAIpC,CAFe,MAAMA,EAAAA,aAAa,EAAO,CAE5B,OAEjB,IAAM,GAAA,EAAA,EAAA,qBAAkC,IAAA,GAAW,EAAO,CAEpD,GAAA,EAAA,EAAA,yBAAqD,EAAO,CAG5D,EACJ,MAAM,EAAY,WAAW,gCAAgC,CAE/D,GAAI,CAAC,EAAqC,KACxC,MAAU,MAAM,gCAAgC,CAGlD,IAAI,EACF,EAAqC,KAGnC,GAAS,eACX,EAAqC,OAAO,YAC1C,OAAO,QAAQ,EAAmC,CAAC,QAAQ,CAAC,KAC1D,EAAQ,cAAc,SAAS,EAAI,CACpC,CACF,EAIH,EAAqC,OAAO,YAC1C,OAAO,QAAQ,EAAmC,CAAC,QAAQ,CAAC,KAAS,CAEnE,IAAM,EADoB,EAA2B,KAE/B,IAAI,UACxB,EAAO,YAAY,UACnB,SAEF,OAAO,IAAa,UAAY,IAAa,UAC7C,CACH,CAGD,IAAM,GAAA,EAAA,EAAA,MACJ,EAAO,OAAO,QACd,0BACD,CACK,EAAkB,EAAO,OAAO,UAAA,EAAA,EAAA,oBAA8B,CAC9D,GAAA,EAAA,EAAA,YACJ,EACD,CACI,EAAgB,EAAuB,CACxC,EAAE,CAGA,EAAU,OAAO,QAAQ,EAAmC,CAC5D,EAAc,EACjB,QAAQ,CAAC,EAAK,KAA0B,CACvC,GAAI,CAAC,EAAsB,MAAO,GAElC,IAA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IAAK,IAAM,KAAa,EAClB,EAAU,cACZ,EAAU,EAAU,aAAc,CAChC,MAAO,QACR,CAAC,OAGC,EAAO,CACd,EAAU,EAAO,CACf,MAAO,QACR,CAAC"}
1
+ {"version":3,"file":"pull.cjs","names":["checkCMSAuth","PullLogger","ANSIColors"],"sources":["../../src/pull.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n type DictionaryStatus,\n writeContentDeclaration,\n} from '@intlayer/chokidar/build';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport { parallelize } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { getProjectRequire } from '@intlayer/config/utils';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { PullLogger, type PullStatus } from './push/pullLog';\nimport { checkCMSAuth } from './utils/checkAccess';\n\ntype PullOptions = {\n dictionaries?: string[];\n newDictionariesPath?: string;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionaryKey: string;\n status: DictionaryStatus | 'pending' | 'fetching' | 'error';\n error?: Error;\n errorMessage?: string;\n};\n\n/**\n * Fetch distant dictionaries and write them locally,\n * with progress indicators and concurrency control.\n */\nexport const pull = async (options?: PullOptions): Promise<void> => {\n const appLogger = getAppLogger(options?.configOptions?.override);\n\n try {\n const config = getConfiguration(options?.configOptions);\n logConfigDetails(options?.configOptions);\n\n const hasCMSAuth = await checkCMSAuth(config);\n\n if (!hasCMSAuth) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(config);\n\n // Get remote update timestamps map\n const getDictionariesUpdateTimestampResult =\n await intlayerAPI.dictionary.getDictionariesUpdateTimestamp();\n\n if (!getDictionariesUpdateTimestampResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n let distantDictionariesUpdateTimeStamp: Record<string, any> =\n getDictionariesUpdateTimestampResult.data;\n\n // Optional filtering by requested dictionaries\n if (options?.dictionaries) {\n distantDictionariesUpdateTimeStamp = Object.fromEntries(\n Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) =>\n options.dictionaries?.includes(key)\n )\n );\n }\n\n // Filter by location\n distantDictionariesUpdateTimeStamp = Object.fromEntries(\n Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) => {\n const localDictionaries = unmergedDictionariesRecord[key];\n const location =\n localDictionaries?.[0]?.location ??\n config.dictionary?.location ??\n 'remote';\n\n return location === 'remote' || location === 'hybrid';\n })\n );\n\n // Load local cached remote dictionaries (if any)\n const remoteDictionariesPath = join(\n config.system.mainDir,\n 'remote_dictionaries.cjs'\n );\n const requireFunction = config.build?.require ?? getProjectRequire();\n const remoteDictionariesRecord: Record<string, any> = existsSync(\n remoteDictionariesPath\n )\n ? (requireFunction(remoteDictionariesPath) as any)\n : {};\n\n // Determine which keys need fetching by comparing updatedAt with local cache\n const entries = Object.entries(distantDictionariesUpdateTimeStamp);\n const keysToFetch = entries\n .filter(([key, remoteUpdatedAtValue]) => {\n if (!remoteUpdatedAtValue) return true;\n\n const remoteUpdatedAt =\n typeof remoteUpdatedAtValue === 'object'\n ? (remoteUpdatedAtValue as any).updatedAt\n : remoteUpdatedAtValue;\n\n const local = (remoteDictionariesRecord as any)[key];\n if (!local) return true;\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n if (typeof localUpdatedAt !== 'number') return true;\n return remoteUpdatedAt > localUpdatedAt;\n })\n .map(([key]) => key);\n\n const cachedKeys = entries\n .filter(([key, remoteUpdatedAtValue]) => {\n const remoteUpdatedAt =\n typeof remoteUpdatedAtValue === 'object'\n ? (remoteUpdatedAtValue as any).updatedAt\n : remoteUpdatedAtValue;\n\n const local = (remoteDictionariesRecord as any)[key];\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n return (\n typeof localUpdatedAt === 'number' &&\n typeof remoteUpdatedAt === 'number' &&\n localUpdatedAt >= remoteUpdatedAt\n );\n })\n .map(([key]) => key);\n\n // Check if dictionaries list is empty\n if (entries.length === 0) {\n appLogger('No dictionaries to fetch', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Fetching dictionaries:');\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = [\n ...cachedKeys.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'imported' as DictionaryStatus,\n })),\n ...keysToFetch.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'pending' as const,\n })),\n ];\n\n // Initialize aggregated logger\n const logger = new PullLogger();\n logger.update(\n dictionariesStatuses.map<PullStatus>((s) => ({\n dictionaryKey: s.dictionaryKey,\n status: s.status,\n }))\n );\n\n const successfullyFetchedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n const isCached =\n statusObj.status === 'imported' || statusObj.status === 'up-to-date';\n\n if (!isCached) {\n statusObj.status = 'fetching';\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'fetching' },\n ]);\n }\n\n try {\n let sourceDictionary: Dictionary | undefined;\n\n if (isCached) {\n sourceDictionary = remoteDictionariesRecord[\n statusObj.dictionaryKey\n ] as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n // Fetch the dictionary\n const getDictionaryResult =\n await intlayerAPI.dictionary.getDictionary(statusObj.dictionaryKey);\n\n sourceDictionary = getDictionaryResult.data as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n throw new Error(\n `Dictionary ${statusObj.dictionaryKey} not found on remote`\n );\n }\n\n // Check if there is a local version of this dictionary that is hybrid\n const localDictionaries =\n unmergedDictionariesRecord[statusObj.dictionaryKey];\n const localAndRemoteDictionary = localDictionaries?.find(\n (d) => d.location === 'hybrid'\n );\n\n if (localAndRemoteDictionary) {\n // We want to preserve the local properties but use the remote content\n sourceDictionary = {\n ...sourceDictionary,\n location: 'hybrid',\n filePath: localAndRemoteDictionary.filePath,\n localId: localAndRemoteDictionary.localId,\n };\n }\n\n // Now, write the dictionary to local file\n const { status } = await writeContentDeclaration(\n sourceDictionary,\n config,\n options\n );\n\n statusObj.status = status;\n logger.update([{ dictionaryKey: statusObj.dictionaryKey, status }]);\n\n successfullyFetchedDictionaries.push(sourceDictionary);\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'error' },\n ]);\n }\n };\n\n // Process dictionaries in parallel with concurrency limit\n await parallelize(dictionariesStatuses, processDictionary, 5);\n\n // Stop the logger and render final state\n logger.finish();\n\n // Per-dictionary summary\n const iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n case 'reimported in JSON':\n case 'new content file':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n };\n\n const colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n return ANSIColors.GREEN;\n case 'reimported in JSON':\n case 'new content file':\n return ANSIColors.YELLOW;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n };\n\n for (const s of dictionariesStatuses) {\n const icon = iconFor(s.status);\n const color = colorFor(s.status);\n appLogger(\n ` - ${s.dictionaryKey} ${ANSIColors.GREY}[${color}${icon} ${s.status}${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,OAAO,OAAO,YAAyC;CAClE,MAAM,sDAAyB,SAAS,eAAe,SAAS;AAEhE,KAAI;EACF,MAAM,qDAA0B,SAAS,cAAc;AACvD,+CAAiB,SAAS,cAAc;AAIxC,MAAI,CAFe,MAAMA,uCAAa,OAAO,CAE5B;EAEjB,MAAM,qDAAkC,QAAW,OAAO;EAE1D,MAAM,gGAAqD,OAAO;EAGlE,MAAM,uCACJ,MAAM,YAAY,WAAW,gCAAgC;AAE/D,MAAI,CAAC,qCAAqC,KACxC,OAAM,IAAI,MAAM,gCAAgC;EAGlD,IAAI,qCACF,qCAAqC;AAGvC,MAAI,SAAS,aACX,sCAAqC,OAAO,YAC1C,OAAO,QAAQ,mCAAmC,CAAC,QAAQ,CAAC,SAC1D,QAAQ,cAAc,SAAS,IAAI,CACpC,CACF;AAIH,uCAAqC,OAAO,YAC1C,OAAO,QAAQ,mCAAmC,CAAC,QAAQ,CAAC,SAAS;GAEnE,MAAM,WADoB,2BAA2B,OAE/B,IAAI,YACxB,OAAO,YAAY,YACnB;AAEF,UAAO,aAAa,YAAY,aAAa;IAC7C,CACH;EAGD,MAAM,6CACJ,OAAO,OAAO,SACd,0BACD;EACD,MAAM,kBAAkB,OAAO,OAAO,0DAA8B;EACpE,MAAM,mDACJ,uBACD,GACI,gBAAgB,uBAAuB,GACxC,EAAE;EAGN,MAAM,UAAU,OAAO,QAAQ,mCAAmC;EAClE,MAAM,cAAc,QACjB,QAAQ,CAAC,KAAK,0BAA0B;AACvC,OAAI,CAAC,qBAAsB,QAAO;G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,MAAM,QAAQ,SAAS,EAAE,OAAO;AAChC,aACE,MAAM,EAAE,cAAc,GAAGA,wBAAW,KAAK,GAAG,QAAQ,KAAK,GAAG,EAAE,SAASA,wBAAW,KAAK,GAAGA,wBAAW,QACtG;;AAIH,OAAK,MAAM,aAAa,qBACtB,KAAI,UAAU,aACZ,WAAU,UAAU,cAAc,EAChC,OAAO,SACR,CAAC;UAGC,OAAO;AACd,YAAU,OAAO,EACf,OAAO,SACR,CAAC"}
@@ -1,4 +1,106 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`);let t=require(`@intlayer/config/colors`);t=e.t(t);let n=require(`@intlayer/config/logger`),r=require(`@intlayer/config/node`);var i=class{statuses=[];spinnerTimer=null;spinnerIndex=0;renderedLines=0;spinnerFrames=n.spinnerFrames;isFinished=!1;prefix;lastRenderedState=``;constructor(){this.prefix=(0,r.getConfiguration)().log.prefix}update(e){if(!this.isFinished){for(let t of e){let e=this.statuses.findIndex(e=>e.dictionaryKey===t.dictionaryKey);e>=0?this.statuses[e]=t:this.statuses.push(t)}this.startSpinner(),this.render()}}finish(){this.isFinished=!0,this.stopSpinner(),this.render()}startSpinner(){this.spinnerTimer||this.isFinished||(this.spinnerTimer=setInterval(()=>{this.spinnerIndex=(this.spinnerIndex+1)%this.spinnerFrames.length,this.render()},100))}stopSpinner(){this.spinnerTimer&&=(clearInterval(this.spinnerTimer),null)}render(){let{total:e,done:r,success:i,errors:a}=this.computeProgress(),o=this.spinnerFrames[this.spinnerIndex],s=[],c=r===e,l=`dictionaries: ${r}/${e}`,u=[];i>0&&u.push(`ok: ${i}`),a>0&&u.push((0,n.colorize)(`errors: ${a}`,t.RED));let d=u.length>0?` (${u.join(`, `)})`:``;c?s.push(`${this.prefix} ${(0,n.colorize)(`✔`,t.GREEN)} fetched ${l}${d}`):s.push(`${this.prefix} ${(0,n.colorize)(o,t.BLUE)} fetching ${l}${d}`);let f=s.join(`
2
- `);if(f===this.lastRenderedState)return;this.lastRenderedState=f,this.renderedLines>0&&process.stdout.write(`\x1b[${this.renderedLines}F`);let p=Math.max(this.renderedLines,s.length);for(let e=0;e<p;e++){process.stdout.write(`\x1B[2K`);let t=s[e];t!==void 0&&process.stdout.write(t),process.stdout.write(`
3
- `)}this.renderedLines=s.length}computeProgress(){let e=new Set(this.statuses.map(e=>e.dictionaryKey)),t=new Set([`fetched`,`imported`,`updated`,`up-to-date`,`reimported in JSON`,`new content file`,`error`]),n=new Set([`fetched`,`imported`,`updated`,`up-to-date`,`reimported in JSON`,`new content file`]),r=this.statuses.filter(e=>t.has(e.status)).length,i=this.statuses.filter(e=>n.has(e.status)).length,a=this.statuses.filter(e=>e.status===`error`).length;return{total:e.size,done:r,success:i,errors:a}}};exports.PullLogger=i;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ let _intlayer_config_colors = require("@intlayer/config/colors");
4
+ _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
5
+ let _intlayer_config_logger = require("@intlayer/config/logger");
6
+ let _intlayer_config_node = require("@intlayer/config/node");
7
+
8
+ //#region src/push/pullLog.ts
9
+ var PullLogger = class {
10
+ statuses = [];
11
+ spinnerTimer = null;
12
+ spinnerIndex = 0;
13
+ renderedLines = 0;
14
+ spinnerFrames = _intlayer_config_logger.spinnerFrames;
15
+ isFinished = false;
16
+ prefix;
17
+ lastRenderedState = "";
18
+ constructor() {
19
+ this.prefix = (0, _intlayer_config_node.getConfiguration)().log.prefix;
20
+ }
21
+ update(newStatuses) {
22
+ if (this.isFinished) return;
23
+ for (const status of newStatuses) {
24
+ const index = this.statuses.findIndex((s) => s.dictionaryKey === status.dictionaryKey);
25
+ if (index >= 0) this.statuses[index] = status;
26
+ else this.statuses.push(status);
27
+ }
28
+ this.startSpinner();
29
+ this.render();
30
+ }
31
+ finish() {
32
+ this.isFinished = true;
33
+ this.stopSpinner();
34
+ this.render();
35
+ }
36
+ startSpinner() {
37
+ if (this.spinnerTimer || this.isFinished) return;
38
+ this.spinnerTimer = setInterval(() => {
39
+ this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;
40
+ this.render();
41
+ }, 100);
42
+ }
43
+ stopSpinner() {
44
+ if (!this.spinnerTimer) return;
45
+ clearInterval(this.spinnerTimer);
46
+ this.spinnerTimer = null;
47
+ }
48
+ render() {
49
+ const { total, done, success, errors } = this.computeProgress();
50
+ const frame = this.spinnerFrames[this.spinnerIndex];
51
+ const lines = [];
52
+ const isDone = done === total;
53
+ const progressLabel = `dictionaries: ${done}/${total}`;
54
+ const details = [];
55
+ if (success > 0) details.push(`ok: ${success}`);
56
+ if (errors > 0) details.push((0, _intlayer_config_logger.colorize)(`errors: ${errors}`, _intlayer_config_colors.RED));
57
+ const suffix = details.length > 0 ? ` (${details.join(", ")})` : "";
58
+ if (isDone) lines.push(`${this.prefix} ${(0, _intlayer_config_logger.colorize)("✔", _intlayer_config_colors.GREEN)} fetched ${progressLabel}${suffix}`);
59
+ else lines.push(`${this.prefix} ${(0, _intlayer_config_logger.colorize)(frame, _intlayer_config_colors.BLUE)} fetching ${progressLabel}${suffix}`);
60
+ const currentState = lines.join("\n");
61
+ if (currentState === this.lastRenderedState) return;
62
+ this.lastRenderedState = currentState;
63
+ if (this.renderedLines > 0) process.stdout.write(`\x1b[${this.renderedLines}F`);
64
+ const totalLinesToClear = Math.max(this.renderedLines, lines.length);
65
+ for (let i = 0; i < totalLinesToClear; i++) {
66
+ process.stdout.write("\x1B[2K");
67
+ const line = lines[i];
68
+ if (line !== void 0) process.stdout.write(line);
69
+ process.stdout.write("\n");
70
+ }
71
+ this.renderedLines = lines.length;
72
+ }
73
+ computeProgress() {
74
+ const keys = new Set(this.statuses.map((s) => s.dictionaryKey));
75
+ const doneSet = new Set([
76
+ "fetched",
77
+ "imported",
78
+ "updated",
79
+ "up-to-date",
80
+ "reimported in JSON",
81
+ "new content file",
82
+ "error"
83
+ ]);
84
+ const successesSet = new Set([
85
+ "fetched",
86
+ "imported",
87
+ "updated",
88
+ "up-to-date",
89
+ "reimported in JSON",
90
+ "new content file"
91
+ ]);
92
+ const done = this.statuses.filter((s) => doneSet.has(s.status)).length;
93
+ const success = this.statuses.filter((s) => successesSet.has(s.status)).length;
94
+ const errors = this.statuses.filter((s) => s.status === "error").length;
95
+ return {
96
+ total: keys.size,
97
+ done,
98
+ success,
99
+ errors
100
+ };
101
+ }
102
+ };
103
+
104
+ //#endregion
105
+ exports.PullLogger = PullLogger;
4
106
  //# sourceMappingURL=pullLog.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"pullLog.cjs","names":["spinnerFrames","ANSIColors"],"sources":["../../../src/push/pullLog.ts"],"sourcesContent":["import type { DictionaryStatus } from '@intlayer/chokidar/build';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, spinnerFrames } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\n\nexport type PullStatus = {\n dictionaryKey: string;\n status: DictionaryStatus | 'pending' | 'fetching';\n errorMessage?: string;\n};\n\nexport class PullLogger {\n private statuses: PullStatus[] = [];\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: PullStatus[]) {\n if (this.isFinished) return;\n for (const status of newStatuses) {\n const index = this.statuses.findIndex(\n (s) => s.dictionaryKey === status.dictionaryKey\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 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 { total, done, success, errors } = this.computeProgress();\n\n const frame = this.spinnerFrames[this.spinnerIndex];\n const lines: string[] = [];\n\n const isDone = done === total;\n const progressLabel = `dictionaries: ${done}/${total}`;\n const details: string[] = [];\n if (success > 0) details.push(`ok: ${success}`);\n if (errors > 0) details.push(colorize(`errors: ${errors}`, ANSIColors.RED));\n\n const suffix = details.length > 0 ? ` (${details.join(', ')})` : '';\n\n if (isDone) {\n lines.push(\n `${this.prefix} ${colorize('✔', ANSIColors.GREEN)} fetched ${progressLabel}${suffix}`\n );\n } else {\n lines.push(\n `${this.prefix} ${colorize(frame, ANSIColors.BLUE)} fetching ${progressLabel}${suffix}`\n );\n }\n\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 keys = new Set(this.statuses.map((s) => s.dictionaryKey));\n\n const doneSet = new Set<DictionaryStatus | 'error'>([\n 'fetched',\n 'imported',\n 'updated',\n 'up-to-date',\n 'reimported in JSON',\n 'new content file',\n 'error',\n ] as const);\n\n const successesSet = new Set<DictionaryStatus>([\n 'fetched',\n 'imported',\n 'updated',\n 'up-to-date',\n 'reimported in JSON',\n 'new content file',\n ] as const);\n\n const done = this.statuses.filter((s) =>\n doneSet.has(s.status as any)\n ).length;\n const success = this.statuses.filter((s) =>\n successesSet.has(s.status as any)\n ).length;\n const errors = this.statuses.filter((s) => s.status === 'error').length;\n\n return {\n total: keys.size,\n done,\n success,\n errors,\n } as const;\n }\n}\n"],"mappings":"0OAWA,IAAa,EAAb,KAAwB,CACtB,SAAiC,EAAE,CACnC,aAA8C,KAC9C,aAAuB,EACvB,cAAwB,EACxB,cAAiCA,EAAAA,cACjC,WAAqB,GACrB,OACA,kBAAoC,GAEpC,aAAc,CAEZ,KAAK,QAAA,EAAA,EAAA,mBADmC,CACZ,IAAI,OAGlC,OAAO,EAA2B,CAC5B,SAAK,WACT,KAAK,IAAM,KAAU,EAAa,CAChC,IAAM,EAAQ,KAAK,SAAS,UACzB,GAAM,EAAE,gBAAkB,EAAO,cACnC,CACG,GAAS,EACX,KAAK,SAAS,GAAS,EAEvB,KAAK,SAAS,KAAK,EAAO,CAI9B,KAAK,cAAc,CACnB,KAAK,QAAQ,EAGf,QAAS,CACP,KAAK,WAAa,GAClB,KAAK,aAAa,CAClB,KAAK,QAAQ,CAGf,cAAuB,CACjB,KAAK,cAAgB,KAAK,aAC9B,KAAK,aAAe,gBAAkB,CACpC,KAAK,cAAgB,KAAK,aAAe,GAAK,KAAK,cAAc,OACjE,KAAK,QAAQ,EACZ,IAAI,EAGT,aAAsB,CACf,AAEL,KAAK,gBADL,cAAc,KAAK,aAAa,CACZ,MAGtB,QAAiB,CACf,GAAM,CAAE,QAAO,OAAM,UAAS,UAAW,KAAK,iBAAiB,CAEzD,EAAQ,KAAK,cAAc,KAAK,cAChC,EAAkB,EAAE,CAEpB,EAAS,IAAS,EAClB,EAAgB,iBAAiB,EAAK,GAAG,IACzC,EAAoB,EAAE,CACxB,EAAU,GAAG,EAAQ,KAAK,OAAO,IAAU,CAC3C,EAAS,GAAG,EAAQ,MAAA,EAAA,EAAA,UAAc,WAAW,IAAUC,EAAW,IAAI,CAAC,CAE3E,IAAM,EAAS,EAAQ,OAAS,EAAI,KAAK,EAAQ,KAAK,KAAK,CAAC,GAAK,GAE7D,EACF,EAAM,KACJ,GAAG,KAAK,OAAO,IAAA,EAAA,EAAA,UAAY,IAAKA,EAAW,MAAM,CAAC,WAAW,IAAgB,IAC9E,CAED,EAAM,KACJ,GAAG,KAAK,OAAO,IAAA,EAAA,EAAA,UAAY,EAAOA,EAAW,KAAK,CAAC,YAAY,IAAgB,IAChF,CAGH,IAAM,EAAe,EAAM,KAAK;EAAK,CACrC,GAAI,IAAiB,KAAK,kBACxB,OAEF,KAAK,kBAAoB,EAErB,KAAK,cAAgB,GACvB,QAAQ,OAAO,MAAM,QAAQ,KAAK,cAAc,GAAG,CAGrD,IAAM,EAAoB,KAAK,IAAI,KAAK,cAAe,EAAM,OAAO,CACpE,IAAK,IAAI,EAAI,EAAG,EAAI,EAAmB,IAAK,CAC1C,QAAQ,OAAO,MAAM,UAAU,CAC/B,IAAM,EAAO,EAAM,GACf,IAAS,IAAA,IACX,QAAQ,OAAO,MAAM,EAAK,CAE5B,QAAQ,OAAO,MAAM;EAAK,CAG5B,KAAK,cAAgB,EAAM,OAG7B,iBAA0B,CACxB,IAAM,EAAO,IAAI,IAAI,KAAK,SAAS,IAAK,GAAM,EAAE,cAAc,CAAC,CAEzD,EAAU,IAAI,IAAgC,CAClD,UACA,WACA,UACA,aACA,qBACA,mBACA,QACD,CAAU,CAEL,EAAe,IAAI,IAAsB,CAC7C,UACA,WACA,UACA,aACA,qBACA,mBACD,CAAU,CAEL,EAAO,KAAK,SAAS,OAAQ,GACjC,EAAQ,IAAI,EAAE,OAAc,CAC7B,CAAC,OACI,EAAU,KAAK,SAAS,OAAQ,GACpC,EAAa,IAAI,EAAE,OAAc,CAClC,CAAC,OACI,EAAS,KAAK,SAAS,OAAQ,GAAM,EAAE,SAAW,QAAQ,CAAC,OAEjE,MAAO,CACL,MAAO,EAAK,KACZ,OACA,UACA,SACD"}
1
+ {"version":3,"file":"pullLog.cjs","names":["spinnerFrames","ANSIColors"],"sources":["../../../src/push/pullLog.ts"],"sourcesContent":["import type { DictionaryStatus } from '@intlayer/chokidar/build';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, spinnerFrames } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\n\nexport type PullStatus = {\n dictionaryKey: string;\n status: DictionaryStatus | 'pending' | 'fetching';\n errorMessage?: string;\n};\n\nexport class PullLogger {\n private statuses: PullStatus[] = [];\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: PullStatus[]) {\n if (this.isFinished) return;\n for (const status of newStatuses) {\n const index = this.statuses.findIndex(\n (s) => s.dictionaryKey === status.dictionaryKey\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 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 { total, done, success, errors } = this.computeProgress();\n\n const frame = this.spinnerFrames[this.spinnerIndex];\n const lines: string[] = [];\n\n const isDone = done === total;\n const progressLabel = `dictionaries: ${done}/${total}`;\n const details: string[] = [];\n if (success > 0) details.push(`ok: ${success}`);\n if (errors > 0) details.push(colorize(`errors: ${errors}`, ANSIColors.RED));\n\n const suffix = details.length > 0 ? ` (${details.join(', ')})` : '';\n\n if (isDone) {\n lines.push(\n `${this.prefix} ${colorize('✔', ANSIColors.GREEN)} fetched ${progressLabel}${suffix}`\n );\n } else {\n lines.push(\n `${this.prefix} ${colorize(frame, ANSIColors.BLUE)} fetching ${progressLabel}${suffix}`\n );\n }\n\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 keys = new Set(this.statuses.map((s) => s.dictionaryKey));\n\n const doneSet = new Set<DictionaryStatus | 'error'>([\n 'fetched',\n 'imported',\n 'updated',\n 'up-to-date',\n 'reimported in JSON',\n 'new content file',\n 'error',\n ] as const);\n\n const successesSet = new Set<DictionaryStatus>([\n 'fetched',\n 'imported',\n 'updated',\n 'up-to-date',\n 'reimported in JSON',\n 'new content file',\n ] as const);\n\n const done = this.statuses.filter((s) =>\n doneSet.has(s.status as any)\n ).length;\n const success = this.statuses.filter((s) =>\n successesSet.has(s.status as any)\n ).length;\n const errors = this.statuses.filter((s) => s.status === 'error').length;\n\n return {\n total: keys.size,\n done,\n success,\n errors,\n } as const;\n }\n}\n"],"mappings":";;;;;;;;AAWA,IAAa,aAAb,MAAwB;CACtB,AAAQ,WAAyB,EAAE;CACnC,AAAQ,eAAsC;CAC9C,AAAQ,eAAe;CACvB,AAAQ,gBAAgB;CACxB,AAAiB,gBAAgBA;CACjC,AAAQ,aAAa;CACrB,AAAiB;CACjB,AAAQ,oBAA4B;CAEpC,cAAc;AAEZ,OAAK,sDADmC,CACZ,IAAI;;CAGlC,OAAO,aAA2B;AAChC,MAAI,KAAK,WAAY;AACrB,OAAK,MAAM,UAAU,aAAa;GAChC,MAAM,QAAQ,KAAK,SAAS,WACzB,MAAM,EAAE,kBAAkB,OAAO,cACnC;AACD,OAAI,SAAS,EACX,MAAK,SAAS,SAAS;OAE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Ae,MAAM,OAAO;AACpE,OAAK,IAAI,IAAI,GAAG,IAAI,mBAAmB,KAAK;AAC1C,WAAQ,OAAO,MAAM,UAAU;GAC/B,MAAM,OAAO,MAAM;AACnB,OAAI,SAAS,OACX,SAAQ,OAAO,MAAM,KAAK;AAE5B,WAAQ,OAAO,MAAM,KAAK;;AAG5B,OAAK,gBAAgB,MAAM;;CAG7B,AAAQ,kBAAkB;EACxB,MAAM,OAAO,IAAI,IAAI,KAAK,SAAS,KAAK,MAAM,EAAE,cAAc,CAAC;EAE/D,MAAM,UAAU,IAAI,IAAgC;GAClD;GACA;GACA;GACA;GACA;GACA;GACA;GACD,CAAU;EAEX,MAAM,eAAe,IAAI,IAAsB;GAC7C;GACA;GACA;GACA;GACA;GACA;GACD,CAAU;EAEX,MAAM,OAAO,KAAK,SAAS,QAAQ,MACjC,QAAQ,IAAI,EAAE,OAAc,CAC7B,CAAC;EACF,MAAM,UAAU,KAAK,SAAS,QAAQ,MACpC,aAAa,IAAI,EAAE,OAAc,CAClC,CAAC;EACF,MAAM,SAAS,KAAK,SAAS,QAAQ,MAAM,EAAE,WAAW,QAAQ,CAAC;AAEjE,SAAO;GACL,OAAO,KAAK;GACZ;GACA;GACA;GACD"}
@@ -1,2 +1,213 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`../utils/checkAccess.cjs`),n=require(`../pushLog.cjs`);let r=require(`node:path`),i=require(`@intlayer/chokidar/build`),a=require(`@intlayer/chokidar/cli`),o=require(`@intlayer/chokidar/utils`),s=require(`@intlayer/config/colors`);s=e.t(s);let c=require(`@intlayer/config/logger`),l=require(`@intlayer/config/node`),u=require(`@intlayer/unmerged-dictionaries-entry`),d=require(`@intlayer/api`),f=require(`node:fs/promises`);f=e.t(f);const p={pushed:{icon:`✔`,color:s.GREEN},modified:{icon:`✔`,color:s.GREEN},error:{icon:`✖`,color:s.RED},default:{icon:`⏲`,color:s.BLUE}},m=e=>p[e]??p.default,h=async e=>{let f=(0,l.getConfiguration)(e?.configOptions);(0,a.logConfigDetails)(e?.configOptions);let p=(0,c.getAppLogger)(f);e?.build===!0?await(0,i.prepareIntlayer)(f,{forceRun:!0}):e?.build===void 0&&await(0,i.prepareIntlayer)(f);try{if(!await t.checkCMSAuth(f))return;let l=(0,d.getIntlayerAPIProxy)(void 0,f),h=(0,u.getUnmergedDictionaries)(f),_=Object.values(h).flat(),v=Array.from(new Set(_.map(e=>e.location).filter(e=>e&&![`remote`,`local`,`hybrid`].includes(e)))),y=[];if(v.length>0){let{multiselect:e,confirm:t,isCancel:n}=await import(`@clack/prompts`);if(v.length===1){let e=await t({message:`Do you want to push dictionaries with custom location ${(0,c.colorize)(v[0],s.BLUE,s.RESET)}?`,initialValue:!1});if(n(e))return;e&&(y=[v[0]])}else{let t=await e({message:`Select custom locations to push:`,options:v.map(e=>({value:e,label:e})),required:!1});if(n(t))return;y=t}}let b=_.filter(e=>{let t=e.location??f.dictionary?.location??`local`;return t===`remote`||t===`hybrid`||y.includes(t)});if(b.length===0){p(`No dictionaries found to push. Only dictionaries with location ${(0,c.colorize)(`remote`,s.BLUE,s.RESET)}, ${(0,c.colorize)(`hybrid`,s.BLUE,s.RESET)} or selected custom locations are pushed.`,{level:`warn`}),p(`You can set the location in your dictionary file (e.g. ${(0,c.colorize)(`{ key: 'my-key', location: 'hybrid', ... }`,s.BLUE,s.RESET)} or globally in your intlayer.config.ts file (e.g. ${(0,c.colorize)(`{ dictionary: { location: 'hybrid' } }`,s.BLUE,s.RESET)}).`,{level:`info`});return}let x=Object.keys(h);if(e?.dictionaries){let t=e.dictionaries.filter(e=>!x.includes(e));t.length>0&&p(`The following dictionaries do not exist: ${t.join(`, `)} and have been ignored.`,{level:`error`}),b=b.filter(t=>e.dictionaries?.includes(t.key))}if(e?.gitOptions){let t=await(0,a.listGitFiles)(e.gitOptions);b=b.filter(e=>t.includes((0,r.join)(f.system.baseDir,e.filePath??``)))}if(b.length===0){p(`No local dictionaries found`,{level:`error`});return}p(`Pushing dictionaries:`);let S=b.map(e=>({dictionary:e,status:`pending`})),C=new n.PushLogger;C.update(S.map(e=>({dictionaryKey:e.dictionary.key,status:`pending`})));let w=[];await(0,o.parallelize)(S,async e=>{e.status=`pushing`,C.update([{dictionaryKey:e.dictionary.key,status:`pushing`}]);try{let t=await l.dictionary.pushDictionaries([e.dictionary]),n=t.data?.updatedDictionaries??[],r=t.data?.newDictionaries??[],a=[...n,...r];for(let e of a){let t=h[e.key]?.find(t=>t.localId===e.localId);t&&await(0,i.writeContentDeclaration)({...t,id:e.id},f)}n.some(t=>t.key===e.dictionary.key)?(e.status=`modified`,w.push(e.dictionary),C.update([{dictionaryKey:e.dictionary.key,status:`modified`}])):r.some(t=>t.key===e.dictionary.key)?(e.status=`pushed`,w.push(e.dictionary),C.update([{dictionaryKey:e.dictionary.key,status:`pushed`}])):e.status=`unknown`}catch(t){e.status=`error`,e.error=t,e.errorMessage=`Error pushing dictionary ${e.dictionary.key}: ${t}`,C.update([{dictionaryKey:e.dictionary.key,status:`error`}])}},5),C.finish();for(let e of S){let{icon:t,color:n}=m(e.status);p(` - ${(0,c.colorizeKey)(e.dictionary.key)} ${s.GREY}[${n}${t} ${e.status}${s.GREY}]${s.RESET}`)}for(let e of S)e.errorMessage&&p(e.errorMessage,{level:`error`});let T=e?.deleteLocaleDictionary,E=e?.keepLocaleDictionary;if(T&&E)throw Error(`Cannot specify both --deleteLocaleDictionary and --keepLocaleDictionary options.`);if(T)await g(w,e);else if(!E){let t=w.filter(e=>e.location===`remote`),n=t.map(e=>e.key);if(t.length>0){let{confirm:r,isCancel:i}=await import(`@clack/prompts`),a=await r({message:`Do you want to delete the local dictionaries that were successfully pushed? ${(0,c.colorize)(`(Dictionaries:`,s.GREY,s.RESET)} ${(0,c.colorizeKey)(n)}${(0,c.colorize)(`)`,s.GREY,s.RESET)}`,initialValue:!1});if(i(a))return;a&&await g(t,e)}}}catch(e){p(e,{level:`error`})}},g=async(e,t)=>{let n=(0,c.getAppLogger)((0,l.getConfiguration)(t?.configOptions)),r=new Set;for(let t of e){let{filePath:e}=t;if(!e){n(`Dictionary ${(0,c.colorizeKey)(t.key)} does not have a file path`,{level:`error`});continue}r.add(e)}for(let e of r)try{let t=await f.lstat(e);t.isFile()?(await f.unlink(e),n(`Deleted file ${(0,o.formatPath)(e)}`,{})):t.isDirectory()?n(`Path is a directory ${(0,o.formatPath)(e)}, skipping.`,{}):n(`Unknown file type for ${(0,o.formatPath)(e)}, skipping.`,{})}catch(t){n(`Error deleting ${(0,o.formatPath)(e)}: ${t}`,{level:`error`})}};exports.push=h;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_utils_checkAccess = require('../utils/checkAccess.cjs');
4
+ const require_pushLog = require('../pushLog.cjs');
5
+ let node_path = require("node:path");
6
+ let _intlayer_chokidar_build = require("@intlayer/chokidar/build");
7
+ let _intlayer_chokidar_cli = require("@intlayer/chokidar/cli");
8
+ let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
9
+ let _intlayer_config_colors = require("@intlayer/config/colors");
10
+ _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
11
+ let _intlayer_config_logger = require("@intlayer/config/logger");
12
+ let _intlayer_config_node = require("@intlayer/config/node");
13
+ let _intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
14
+ let _intlayer_api = require("@intlayer/api");
15
+ let node_fs_promises = require("node:fs/promises");
16
+ node_fs_promises = require_runtime.__toESM(node_fs_promises);
17
+
18
+ //#region src/push/push.ts
19
+ const statusIconsAndColors = {
20
+ pushed: {
21
+ icon: "✔",
22
+ color: _intlayer_config_colors.GREEN
23
+ },
24
+ modified: {
25
+ icon: "✔",
26
+ color: _intlayer_config_colors.GREEN
27
+ },
28
+ error: {
29
+ icon: "✖",
30
+ color: _intlayer_config_colors.RED
31
+ },
32
+ default: {
33
+ icon: "⏲",
34
+ color: _intlayer_config_colors.BLUE
35
+ }
36
+ };
37
+ const getIconAndColor = (status) => {
38
+ return statusIconsAndColors[status] ?? statusIconsAndColors.default;
39
+ };
40
+ /**
41
+ * Get all local dictionaries and push them simultaneously.
42
+ */
43
+ const push = async (options) => {
44
+ const config = (0, _intlayer_config_node.getConfiguration)(options?.configOptions);
45
+ (0, _intlayer_chokidar_cli.logConfigDetails)(options?.configOptions);
46
+ const appLogger = (0, _intlayer_config_logger.getAppLogger)(config);
47
+ if (options?.build === true) await (0, _intlayer_chokidar_build.prepareIntlayer)(config, { forceRun: true });
48
+ else if (typeof options?.build === "undefined") await (0, _intlayer_chokidar_build.prepareIntlayer)(config);
49
+ try {
50
+ if (!await require_utils_checkAccess.checkCMSAuth(config)) return;
51
+ const intlayerAPI = (0, _intlayer_api.getIntlayerAPIProxy)(void 0, config);
52
+ const unmergedDictionariesRecord = (0, _intlayer_unmerged_dictionaries_entry.getUnmergedDictionaries)(config);
53
+ const allDictionaries = Object.values(unmergedDictionariesRecord).flat();
54
+ const customLocations = Array.from(new Set(allDictionaries.map((dictionary) => dictionary.location).filter((location) => location && ![
55
+ "remote",
56
+ "local",
57
+ "hybrid"
58
+ ].includes(location))));
59
+ let selectedCustomLocations = [];
60
+ if (customLocations.length > 0) {
61
+ const { multiselect, confirm, isCancel } = await import("@clack/prompts");
62
+ if (customLocations.length === 1) {
63
+ const shouldPush = await confirm({
64
+ message: `Do you want to push dictionaries with custom location ${(0, _intlayer_config_logger.colorize)(customLocations[0], _intlayer_config_colors.BLUE, _intlayer_config_colors.RESET)}?`,
65
+ initialValue: false
66
+ });
67
+ if (isCancel(shouldPush)) return;
68
+ if (shouldPush) selectedCustomLocations = [customLocations[0]];
69
+ } else {
70
+ const selected = await multiselect({
71
+ message: "Select custom locations to push:",
72
+ options: customLocations.map((location) => ({
73
+ value: location,
74
+ label: location
75
+ })),
76
+ required: false
77
+ });
78
+ if (isCancel(selected)) return;
79
+ selectedCustomLocations = selected;
80
+ }
81
+ }
82
+ let dictionaries = allDictionaries.filter((dictionary) => {
83
+ const location = dictionary.location ?? config.dictionary?.location ?? "local";
84
+ return location === "remote" || location === "hybrid" || selectedCustomLocations.includes(location);
85
+ });
86
+ if (dictionaries.length === 0) {
87
+ appLogger(`No dictionaries found to push. Only dictionaries with location ${(0, _intlayer_config_logger.colorize)("remote", _intlayer_config_colors.BLUE, _intlayer_config_colors.RESET)}, ${(0, _intlayer_config_logger.colorize)("hybrid", _intlayer_config_colors.BLUE, _intlayer_config_colors.RESET)} or selected custom locations are pushed.`, { level: "warn" });
88
+ appLogger(`You can set the location in your dictionary file (e.g. ${(0, _intlayer_config_logger.colorize)("{ key: 'my-key', location: 'hybrid', ... }", _intlayer_config_colors.BLUE, _intlayer_config_colors.RESET)} or globally in your intlayer.config.ts file (e.g. ${(0, _intlayer_config_logger.colorize)("{ dictionary: { location: 'hybrid' } }", _intlayer_config_colors.BLUE, _intlayer_config_colors.RESET)}).`, { level: "info" });
89
+ return;
90
+ }
91
+ const existingDictionariesKeys = Object.keys(unmergedDictionariesRecord);
92
+ if (options?.dictionaries) {
93
+ const noneExistingDictionariesOption = options.dictionaries.filter((dictionaryId) => !existingDictionariesKeys.includes(dictionaryId));
94
+ if (noneExistingDictionariesOption.length > 0) appLogger(`The following dictionaries do not exist: ${noneExistingDictionariesOption.join(", ")} and have been ignored.`, { level: "error" });
95
+ dictionaries = dictionaries.filter((dictionary) => options.dictionaries?.includes(dictionary.key));
96
+ }
97
+ if (options?.gitOptions) {
98
+ const gitFiles = await (0, _intlayer_chokidar_cli.listGitFiles)(options.gitOptions);
99
+ dictionaries = dictionaries.filter((dictionary) => gitFiles.includes((0, node_path.join)(config.system.baseDir, dictionary.filePath ?? "")));
100
+ }
101
+ if (dictionaries.length === 0) {
102
+ appLogger("No local dictionaries found", { level: "error" });
103
+ return;
104
+ }
105
+ appLogger("Pushing dictionaries:");
106
+ const dictionariesStatuses = dictionaries.map((dictionary) => ({
107
+ dictionary,
108
+ status: "pending"
109
+ }));
110
+ const logger = new require_pushLog.PushLogger();
111
+ logger.update(dictionariesStatuses.map((s) => ({
112
+ dictionaryKey: s.dictionary.key,
113
+ status: "pending"
114
+ })));
115
+ const successfullyPushedDictionaries = [];
116
+ const processDictionary = async (statusObj) => {
117
+ statusObj.status = "pushing";
118
+ logger.update([{
119
+ dictionaryKey: statusObj.dictionary.key,
120
+ status: "pushing"
121
+ }]);
122
+ try {
123
+ const pushResult = await intlayerAPI.dictionary.pushDictionaries([statusObj.dictionary]);
124
+ const updatedDictionaries = pushResult.data?.updatedDictionaries ?? [];
125
+ const newDictionaries = pushResult.data?.newDictionaries ?? [];
126
+ const allDictionaries = [...updatedDictionaries, ...newDictionaries];
127
+ for (const remoteDictionaryData of allDictionaries) {
128
+ const localDictionary = unmergedDictionariesRecord[remoteDictionaryData.key]?.find((dictionary) => dictionary.localId === remoteDictionaryData.localId);
129
+ if (!localDictionary) continue;
130
+ await (0, _intlayer_chokidar_build.writeContentDeclaration)({
131
+ ...localDictionary,
132
+ id: remoteDictionaryData.id
133
+ }, config);
134
+ }
135
+ if (updatedDictionaries.some((dictionary) => dictionary.key === statusObj.dictionary.key)) {
136
+ statusObj.status = "modified";
137
+ successfullyPushedDictionaries.push(statusObj.dictionary);
138
+ logger.update([{
139
+ dictionaryKey: statusObj.dictionary.key,
140
+ status: "modified"
141
+ }]);
142
+ } else if (newDictionaries.some((dictionary) => dictionary.key === statusObj.dictionary.key)) {
143
+ statusObj.status = "pushed";
144
+ successfullyPushedDictionaries.push(statusObj.dictionary);
145
+ logger.update([{
146
+ dictionaryKey: statusObj.dictionary.key,
147
+ status: "pushed"
148
+ }]);
149
+ } else statusObj.status = "unknown";
150
+ } catch (error) {
151
+ statusObj.status = "error";
152
+ statusObj.error = error;
153
+ statusObj.errorMessage = `Error pushing dictionary ${statusObj.dictionary.key}: ${error}`;
154
+ logger.update([{
155
+ dictionaryKey: statusObj.dictionary.key,
156
+ status: "error"
157
+ }]);
158
+ }
159
+ };
160
+ await (0, _intlayer_chokidar_utils.parallelize)(dictionariesStatuses, processDictionary, 5);
161
+ logger.finish();
162
+ for (const dictionaryStatus of dictionariesStatuses) {
163
+ const { icon, color } = getIconAndColor(dictionaryStatus.status);
164
+ appLogger(` - ${(0, _intlayer_config_logger.colorizeKey)(dictionaryStatus.dictionary.key)} ${_intlayer_config_colors.GREY}[${color}${icon} ${dictionaryStatus.status}${_intlayer_config_colors.GREY}]${_intlayer_config_colors.RESET}`);
165
+ }
166
+ for (const statusObj of dictionariesStatuses) if (statusObj.errorMessage) appLogger(statusObj.errorMessage, { level: "error" });
167
+ const deleteOption = options?.deleteLocaleDictionary;
168
+ const keepOption = options?.keepLocaleDictionary;
169
+ if (deleteOption && keepOption) throw new Error("Cannot specify both --deleteLocaleDictionary and --keepLocaleDictionary options.");
170
+ if (deleteOption) await deleteLocalDictionaries(successfullyPushedDictionaries, options);
171
+ else if (keepOption) {} else {
172
+ const remoteDictionaries = successfullyPushedDictionaries.filter((dictionary) => dictionary.location === "remote");
173
+ const remoteDictionariesKeys = remoteDictionaries.map((dictionary) => dictionary.key);
174
+ if (remoteDictionaries.length > 0) {
175
+ const { confirm, isCancel } = await import("@clack/prompts");
176
+ const shouldDelete = await confirm({
177
+ message: `Do you want to delete the local dictionaries that were successfully pushed? ${(0, _intlayer_config_logger.colorize)("(Dictionaries:", _intlayer_config_colors.GREY, _intlayer_config_colors.RESET)} ${(0, _intlayer_config_logger.colorizeKey)(remoteDictionariesKeys)}${(0, _intlayer_config_logger.colorize)(")", _intlayer_config_colors.GREY, _intlayer_config_colors.RESET)}`,
178
+ initialValue: false
179
+ });
180
+ if (isCancel(shouldDelete)) return;
181
+ if (shouldDelete) await deleteLocalDictionaries(remoteDictionaries, options);
182
+ }
183
+ }
184
+ } catch (error) {
185
+ appLogger(error, { level: "error" });
186
+ }
187
+ };
188
+ const deleteLocalDictionaries = async (dictionariesToDelete, options) => {
189
+ const appLogger = (0, _intlayer_config_logger.getAppLogger)((0, _intlayer_config_node.getConfiguration)(options?.configOptions));
190
+ const filePathsSet = /* @__PURE__ */ new Set();
191
+ for (const dictionary of dictionariesToDelete) {
192
+ const { filePath } = dictionary;
193
+ if (!filePath) {
194
+ appLogger(`Dictionary ${(0, _intlayer_config_logger.colorizeKey)(dictionary.key)} does not have a file path`, { level: "error" });
195
+ continue;
196
+ }
197
+ filePathsSet.add(filePath);
198
+ }
199
+ for (const filePath of filePathsSet) try {
200
+ const stats = await node_fs_promises.lstat(filePath);
201
+ if (stats.isFile()) {
202
+ await node_fs_promises.unlink(filePath);
203
+ appLogger(`Deleted file ${(0, _intlayer_chokidar_utils.formatPath)(filePath)}`, {});
204
+ } else if (stats.isDirectory()) appLogger(`Path is a directory ${(0, _intlayer_chokidar_utils.formatPath)(filePath)}, skipping.`, {});
205
+ else appLogger(`Unknown file type for ${(0, _intlayer_chokidar_utils.formatPath)(filePath)}, skipping.`, {});
206
+ } catch (err) {
207
+ appLogger(`Error deleting ${(0, _intlayer_chokidar_utils.formatPath)(filePath)}: ${err}`, { level: "error" });
208
+ }
209
+ };
210
+
211
+ //#endregion
212
+ exports.push = push;
2
213
  //# sourceMappingURL=push.cjs.map