@intlayer/cli 6.1.6-canary.0 → 7.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 (287) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs +187 -239
  2. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  3. package/dist/cjs/_virtual/_utils_asset.cjs +104 -0
  4. package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
  5. package/dist/cjs/build.cjs +23 -42
  6. package/dist/cjs/build.cjs.map +1 -1
  7. package/dist/cjs/cli.cjs +370 -431
  8. package/dist/cjs/cli.cjs.map +1 -1
  9. package/dist/cjs/config.cjs +10 -35
  10. package/dist/cjs/config.cjs.map +1 -1
  11. package/dist/cjs/editor.cjs +51 -66
  12. package/dist/cjs/editor.cjs.map +1 -1
  13. package/dist/cjs/fill/fill.cjs +73 -301
  14. package/dist/cjs/fill/fill.cjs.map +1 -1
  15. package/dist/cjs/fill/formatAutoFillData.cjs +48 -106
  16. package/dist/cjs/fill/formatAutoFillData.cjs.map +1 -1
  17. package/dist/cjs/fill/formatAutoFilledFilePath.cjs +27 -43
  18. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
  19. package/dist/cjs/fill/formatFillData.cjs +50 -0
  20. package/dist/cjs/fill/formatFillData.cjs.map +1 -0
  21. package/dist/cjs/fill/groupLimiter.cjs +42 -0
  22. package/dist/cjs/fill/groupLimiter.cjs.map +1 -0
  23. package/dist/cjs/fill/index.cjs +5 -25
  24. package/dist/cjs/fill/listTranslationsTasks.cjs +77 -0
  25. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -0
  26. package/dist/cjs/fill/test-original-case.cjs +10 -0
  27. package/dist/cjs/fill/test-original-case.cjs.map +1 -0
  28. package/dist/cjs/fill/translateDictionary.cjs +148 -0
  29. package/dist/cjs/fill/translateDictionary.cjs.map +1 -0
  30. package/dist/cjs/fill/writeAutoFill.cjs +48 -0
  31. package/dist/cjs/fill/writeAutoFill.cjs.map +1 -0
  32. package/dist/cjs/fill/writeFill.cjs +50 -0
  33. package/dist/cjs/fill/writeFill.cjs.map +1 -0
  34. package/dist/cjs/getTargetDictionary.cjs +36 -76
  35. package/dist/cjs/getTargetDictionary.cjs.map +1 -1
  36. package/dist/cjs/index.cjs +31 -45
  37. package/dist/cjs/listContentDeclaration.cjs +36 -64
  38. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  39. package/dist/cjs/liveSync.cjs +146 -221
  40. package/dist/cjs/liveSync.cjs.map +1 -1
  41. package/dist/cjs/pull.cjs +132 -195
  42. package/dist/cjs/pull.cjs.map +1 -1
  43. package/dist/cjs/push/pullLog.cjs +101 -144
  44. package/dist/cjs/push/pullLog.cjs.map +1 -1
  45. package/dist/cjs/push/push.cjs +159 -249
  46. package/dist/cjs/push/push.cjs.map +1 -1
  47. package/dist/cjs/pushConfig.cjs +18 -45
  48. package/dist/cjs/pushConfig.cjs.map +1 -1
  49. package/dist/cjs/pushLog.cjs +87 -128
  50. package/dist/cjs/pushLog.cjs.map +1 -1
  51. package/dist/cjs/reviewDoc.cjs +183 -291
  52. package/dist/cjs/reviewDoc.cjs.map +1 -1
  53. package/dist/cjs/test/index.cjs +52 -91
  54. package/dist/cjs/test/index.cjs.map +1 -1
  55. package/dist/cjs/test/listMissingTranslations.cjs +35 -62
  56. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  57. package/dist/cjs/translateDoc.cjs +127 -221
  58. package/dist/cjs/translateDoc.cjs.map +1 -1
  59. package/dist/cjs/utils/calculateChunks.cjs +85 -115
  60. package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
  61. package/dist/cjs/utils/checkAccess.cjs +33 -72
  62. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  63. package/dist/cjs/utils/checkFileModifiedRange.cjs +75 -91
  64. package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
  65. package/dist/cjs/utils/checkLastUpdateTime.cjs +17 -30
  66. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
  67. package/dist/cjs/utils/chunkInference.cjs +28 -47
  68. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  69. package/dist/cjs/utils/fixChunkStartEndChars.cjs +23 -42
  70. package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
  71. package/dist/cjs/utils/formatTimeDiff.cjs +17 -43
  72. package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
  73. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +13 -32
  74. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
  75. package/dist/cjs/utils/getOutputFilePath.cjs +71 -86
  76. package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
  77. package/dist/cjs/utils/getParentPackageJSON.cjs +19 -44
  78. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
  79. package/dist/cjs/utils/listSpecialChars.cjs +49 -73
  80. package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
  81. package/dist/cjs/utils/mapChunksBetweenFiles.cjs +90 -132
  82. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
  83. package/dist/cjs/utils/reorderParagraphs.cjs +86 -118
  84. package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
  85. package/dist/cjs/watch.cjs +21 -39
  86. package/dist/cjs/watch.cjs.map +1 -1
  87. package/dist/esm/IntlayerEventListener.mjs +178 -201
  88. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  89. package/dist/esm/_virtual/_utils_asset.mjs +100 -0
  90. package/dist/esm/_virtual/rolldown_runtime.mjs +8 -0
  91. package/dist/esm/build.mjs +20 -23
  92. package/dist/esm/build.mjs.map +1 -1
  93. package/dist/esm/cli.mjs +349 -380
  94. package/dist/esm/cli.mjs.map +1 -1
  95. package/dist/esm/config.mjs +8 -14
  96. package/dist/esm/config.mjs.map +1 -1
  97. package/dist/esm/editor.mjs +47 -41
  98. package/dist/esm/editor.mjs.map +1 -1
  99. package/dist/esm/fill/fill.mjs +68 -300
  100. package/dist/esm/fill/fill.mjs.map +1 -1
  101. package/dist/esm/fill/formatAutoFillData.mjs +47 -81
  102. package/dist/esm/fill/formatAutoFillData.mjs.map +1 -1
  103. package/dist/esm/fill/formatAutoFilledFilePath.mjs +25 -19
  104. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
  105. package/dist/esm/fill/formatFillData.mjs +50 -0
  106. package/dist/esm/fill/formatFillData.mjs.map +1 -0
  107. package/dist/esm/fill/groupLimiter.mjs +40 -0
  108. package/dist/esm/fill/groupLimiter.mjs.map +1 -0
  109. package/dist/esm/fill/index.mjs +4 -3
  110. package/dist/esm/fill/listTranslationsTasks.mjs +70 -0
  111. package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -0
  112. package/dist/esm/fill/test-original-case.mjs +10 -0
  113. package/dist/esm/fill/test-original-case.mjs.map +1 -0
  114. package/dist/esm/fill/translateDictionary.mjs +141 -0
  115. package/dist/esm/fill/translateDictionary.mjs.map +1 -0
  116. package/dist/esm/fill/writeAutoFill.mjs +44 -0
  117. package/dist/esm/fill/writeAutoFill.mjs.map +1 -0
  118. package/dist/esm/fill/writeFill.mjs +45 -0
  119. package/dist/esm/fill/writeFill.mjs.map +1 -0
  120. package/dist/esm/getTargetDictionary.mjs +27 -48
  121. package/dist/esm/getTargetDictionary.mjs.map +1 -1
  122. package/dist/esm/index.mjs +15 -13
  123. package/dist/esm/listContentDeclaration.mjs +28 -43
  124. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  125. package/dist/esm/liveSync.mjs +135 -187
  126. package/dist/esm/liveSync.mjs.map +1 -1
  127. package/dist/esm/pull.mjs +125 -178
  128. package/dist/esm/pull.mjs.map +1 -1
  129. package/dist/esm/push/pullLog.mjs +99 -125
  130. package/dist/esm/push/pullLog.mjs.map +1 -1
  131. package/dist/esm/push/push.mjs +149 -221
  132. package/dist/esm/push/push.mjs.map +1 -1
  133. package/dist/esm/pushConfig.mjs +14 -23
  134. package/dist/esm/pushConfig.mjs.map +1 -1
  135. package/dist/esm/pushLog.mjs +85 -109
  136. package/dist/esm/pushLog.mjs.map +1 -1
  137. package/dist/esm/reviewDoc.mjs +167 -264
  138. package/dist/esm/reviewDoc.mjs.map +1 -1
  139. package/dist/esm/test/index.mjs +47 -73
  140. package/dist/esm/test/index.mjs.map +1 -1
  141. package/dist/esm/test/listMissingTranslations.mjs +30 -41
  142. package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
  143. package/dist/esm/translateDoc.mjs +114 -193
  144. package/dist/esm/translateDoc.mjs.map +1 -1
  145. package/dist/esm/utils/calculateChunks.mjs +83 -91
  146. package/dist/esm/utils/calculateChunks.mjs.map +1 -1
  147. package/dist/esm/utils/checkAccess.mjs +28 -46
  148. package/dist/esm/utils/checkAccess.mjs.map +1 -1
  149. package/dist/esm/utils/checkFileModifiedRange.mjs +73 -65
  150. package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
  151. package/dist/esm/utils/checkLastUpdateTime.mjs +15 -6
  152. package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
  153. package/dist/esm/utils/chunkInference.mjs +24 -24
  154. package/dist/esm/utils/chunkInference.mjs.map +1 -1
  155. package/dist/esm/utils/fixChunkStartEndChars.mjs +22 -18
  156. package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
  157. package/dist/esm/utils/formatTimeDiff.mjs +16 -19
  158. package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
  159. package/dist/esm/utils/getIsFileUpdatedRecently.mjs +11 -8
  160. package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
  161. package/dist/esm/utils/getOutputFilePath.mjs +70 -62
  162. package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
  163. package/dist/esm/utils/getParentPackageJSON.mjs +16 -20
  164. package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
  165. package/dist/esm/utils/listSpecialChars.mjs +48 -49
  166. package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
  167. package/dist/esm/utils/mapChunksBetweenFiles.mjs +87 -107
  168. package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
  169. package/dist/esm/utils/reorderParagraphs.mjs +85 -93
  170. package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
  171. package/dist/esm/watch.mjs +17 -17
  172. package/dist/esm/watch.mjs.map +1 -1
  173. package/dist/types/IntlayerEventListener.d.ts +63 -59
  174. package/dist/types/IntlayerEventListener.d.ts.map +1 -1
  175. package/dist/types/build.d.ts +10 -7
  176. package/dist/types/build.d.ts.map +1 -1
  177. package/dist/types/cli.d.ts +13 -10
  178. package/dist/types/cli.d.ts.map +1 -1
  179. package/dist/types/config.d.ts +7 -4
  180. package/dist/types/config.d.ts.map +1 -1
  181. package/dist/types/editor.d.ts +6 -4
  182. package/dist/types/editor.d.ts.map +1 -1
  183. package/dist/types/fill/fill.d.ts +20 -14
  184. package/dist/types/fill/fill.d.ts.map +1 -1
  185. package/dist/types/fill/formatAutoFillData.d.ts +10 -7
  186. package/dist/types/fill/formatAutoFillData.d.ts.map +1 -1
  187. package/dist/types/fill/formatAutoFilledFilePath.d.ts +6 -2
  188. package/dist/types/fill/formatAutoFilledFilePath.d.ts.map +1 -1
  189. package/dist/types/fill/formatFillData.d.ts +12 -0
  190. package/dist/types/fill/formatFillData.d.ts.map +1 -0
  191. package/dist/types/fill/groupLimiter.d.ts +15 -0
  192. package/dist/types/fill/groupLimiter.d.ts.map +1 -0
  193. package/dist/types/fill/index.d.ts +3 -3
  194. package/dist/types/fill/listTranslationsTasks.d.ts +15 -0
  195. package/dist/types/fill/listTranslationsTasks.d.ts.map +1 -0
  196. package/dist/types/fill/test-original-case.d.ts +1 -0
  197. package/dist/types/fill/translateDictionary.d.ts +19 -0
  198. package/dist/types/fill/translateDictionary.d.ts.map +1 -0
  199. package/dist/types/fill/writeAutoFill.d.ts +7 -0
  200. package/dist/types/fill/writeAutoFill.d.ts.map +1 -0
  201. package/dist/types/fill/writeFill.d.ts +7 -0
  202. package/dist/types/fill/writeFill.d.ts.map +1 -0
  203. package/dist/types/getTargetDictionary.d.ts +17 -13
  204. package/dist/types/getTargetDictionary.d.ts.map +1 -1
  205. package/dist/types/index.d.ts +15 -14
  206. package/dist/types/listContentDeclaration.d.ts +10 -7
  207. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  208. package/dist/types/liveSync.d.ts +8 -3
  209. package/dist/types/liveSync.d.ts.map +1 -1
  210. package/dist/types/pull.d.ts +9 -6
  211. package/dist/types/pull.d.ts.map +1 -1
  212. package/dist/types/push/pullLog.d.ts +25 -21
  213. package/dist/types/push/pullLog.d.ts.map +1 -1
  214. package/dist/types/push/push.d.ts +13 -9
  215. package/dist/types/push/push.d.ts.map +1 -1
  216. package/dist/types/pushConfig.d.ts +7 -4
  217. package/dist/types/pushConfig.d.ts.map +1 -1
  218. package/dist/types/pushLog.d.ts +23 -20
  219. package/dist/types/pushLog.d.ts.map +1 -1
  220. package/dist/types/reviewDoc.d.ts +34 -17
  221. package/dist/types/reviewDoc.d.ts.map +1 -1
  222. package/dist/types/test/index.d.ts +9 -5
  223. package/dist/types/test/index.d.ts.map +1 -1
  224. package/dist/types/test/listMissingTranslations.d.ts +14 -10
  225. package/dist/types/test/listMissingTranslations.d.ts.map +1 -1
  226. package/dist/types/translateDoc.d.ts +34 -17
  227. package/dist/types/translateDoc.d.ts.map +1 -1
  228. package/dist/types/utils/calculateChunks.d.ts +10 -7
  229. package/dist/types/utils/calculateChunks.d.ts.map +1 -1
  230. package/dist/types/utils/checkAccess.d.ts +8 -4
  231. package/dist/types/utils/checkAccess.d.ts.map +1 -1
  232. package/dist/types/utils/checkFileModifiedRange.d.ts +8 -6
  233. package/dist/types/utils/checkFileModifiedRange.d.ts.map +1 -1
  234. package/dist/types/utils/checkLastUpdateTime.d.ts +4 -1
  235. package/dist/types/utils/checkLastUpdateTime.d.ts.map +1 -1
  236. package/dist/types/utils/chunkInference.d.ts +9 -6
  237. package/dist/types/utils/chunkInference.d.ts.map +1 -1
  238. package/dist/types/utils/fixChunkStartEndChars.d.ts +4 -1
  239. package/dist/types/utils/fixChunkStartEndChars.d.ts.map +1 -1
  240. package/dist/types/utils/formatTimeDiff.d.ts +4 -1
  241. package/dist/types/utils/formatTimeDiff.d.ts.map +1 -1
  242. package/dist/types/utils/getIsFileUpdatedRecently.d.ts +4 -1
  243. package/dist/types/utils/getIsFileUpdatedRecently.d.ts.map +1 -1
  244. package/dist/types/utils/getOutputFilePath.d.ts +7 -2
  245. package/dist/types/utils/getOutputFilePath.d.ts.map +1 -1
  246. package/dist/types/utils/getParentPackageJSON.d.ts +30 -28
  247. package/dist/types/utils/getParentPackageJSON.d.ts.map +1 -1
  248. package/dist/types/utils/listSpecialChars.d.ts +9 -7
  249. package/dist/types/utils/listSpecialChars.d.ts.map +1 -1
  250. package/dist/types/utils/mapChunksBetweenFiles.d.ts +10 -6
  251. package/dist/types/utils/mapChunksBetweenFiles.d.ts.map +1 -1
  252. package/dist/types/utils/reorderParagraphs.d.ts +4 -1
  253. package/dist/types/utils/reorderParagraphs.d.ts.map +1 -1
  254. package/dist/types/watch.d.ts +9 -6
  255. package/dist/types/watch.d.ts.map +1 -1
  256. package/package.json +42 -47
  257. package/LICENSE +0 -202
  258. package/dist/cjs/fill/autoFill.cjs +0 -105
  259. package/dist/cjs/fill/autoFill.cjs.map +0 -1
  260. package/dist/cjs/fill/index.cjs.map +0 -1
  261. package/dist/cjs/index.cjs.map +0 -1
  262. package/dist/cjs/utils/getChunk.cjs +0 -77
  263. package/dist/cjs/utils/getChunk.cjs.map +0 -1
  264. package/dist/cjs/utils/splitTextByLine.cjs +0 -35
  265. package/dist/cjs/utils/splitTextByLine.cjs.map +0 -1
  266. package/dist/esm/fill/autoFill.mjs +0 -92
  267. package/dist/esm/fill/autoFill.mjs.map +0 -1
  268. package/dist/esm/fill/index.mjs.map +0 -1
  269. package/dist/esm/index.mjs.map +0 -1
  270. package/dist/esm/prompts/REVIEW_PROMPT.md +0 -37
  271. package/dist/esm/prompts/TRANSLATE_PROMPT.md +0 -38
  272. package/dist/esm/utils/calculrateChunkTest.md +0 -9
  273. package/dist/esm/utils/getChunk.mjs +0 -53
  274. package/dist/esm/utils/getChunk.mjs.map +0 -1
  275. package/dist/esm/utils/splitTextByLine.mjs +0 -11
  276. package/dist/esm/utils/splitTextByLine.mjs.map +0 -1
  277. package/dist/types/fill/autoFill.d.ts +0 -4
  278. package/dist/types/fill/autoFill.d.ts.map +0 -1
  279. package/dist/types/fill/index.d.ts.map +0 -1
  280. package/dist/types/index.d.ts.map +0 -1
  281. package/dist/types/utils/getChunk.d.ts +0 -9
  282. package/dist/types/utils/getChunk.d.ts.map +0 -1
  283. package/dist/types/utils/splitTextByLine.d.ts +0 -2
  284. package/dist/types/utils/splitTextByLine.d.ts.map +0 -1
  285. /package/dist/{cjs → assets}/prompts/REVIEW_PROMPT.md +0 -0
  286. /package/dist/{cjs → assets}/prompts/TRANSLATE_PROMPT.md +0 -0
  287. /package/dist/{cjs/utils/calculrateChunkTest.md → assets/utils/_calculateChunkTest.md} +0 -0
@@ -1,304 +1,72 @@
1
- import { getIntlayerAPIProxy } from "@intlayer/api";
2
- import {
3
- formatLocale,
4
- formatPath,
5
- mergeDictionaries,
6
- parallelize,
7
- prepareIntlayer,
8
- processPerLocaleDictionary,
9
- reduceDictionaryContent,
10
- writeContentDeclaration
11
- } from "@intlayer/chokidar";
12
- import {
13
- ANSIColors,
14
- colon,
15
- colorize,
16
- colorizeKey,
17
- colorizePath,
18
- getAppLogger,
19
- getConfiguration
20
- } from "@intlayer/config";
21
- import {
22
- getFilterTranslationsOnlyContent,
23
- getLocalisedContent,
24
- getMissingLocalesContent
25
- } from "@intlayer/core";
26
- import { getDictionaries } from "@intlayer/dictionaries-entry";
27
- import { relative } from "path";
28
- import {
29
- ensureArray,
30
- getTargetUnmergedDictionaries
31
- } from "../getTargetDictionary.mjs";
1
+ import { ensureArray, getTargetUnmergedDictionaries } from "../getTargetDictionary.mjs";
32
2
  import { checkAIAccess } from "../utils/checkAccess.mjs";
33
- import { autoFill } from "./autoFill.mjs";
34
- const NB_CONCURRENT_TRANSLATIONS = 8;
3
+ import { listTranslationsTasks } from "./listTranslationsTasks.mjs";
4
+ import { translateDictionary } from "./translateDictionary.mjs";
5
+ import { writeFill } from "./writeFill.mjs";
6
+ import { formatPath, getGlobalLimiter, getTaskLimiter, prepareIntlayer, writeContentDeclaration } from "@intlayer/chokidar";
7
+ import { ANSIColors, colon, colorize, colorizeKey, colorizePath, getAppLogger, getConfiguration } from "@intlayer/config";
8
+ import { basename, relative } from "node:path";
9
+
10
+ //#region src/fill/fill.ts
11
+ const NB_CONCURRENT_TRANSLATIONS = 7;
12
+ /**
13
+ * Fill translations based on the provided options.
14
+ */
35
15
  const fill = async (options) => {
36
- const configuration = getConfiguration(options.configOptions);
37
- const appLogger = getAppLogger(configuration, {
38
- config: {
39
- prefix: ""
40
- }
41
- });
42
- if (options.build) {
43
- await prepareIntlayer(configuration);
44
- }
45
- const { defaultLocale, locales } = configuration.internationalization;
46
- const mode = options.mode ?? "complete";
47
- const baseLocale = options.sourceLocale ?? defaultLocale;
48
- const outputLocales = (options.outputLocales ? ensureArray(options.outputLocales) : locales).filter((locale) => locale !== baseLocale);
49
- const hasAIAccess = await checkAIAccess(configuration, options.aiOptions);
50
- if (!hasAIAccess) return;
51
- const intlayerAPI = getIntlayerAPIProxy(void 0, configuration);
52
- const targetUnmergedDictionaries = await getTargetUnmergedDictionaries(options);
53
- const affectedDictionaryKeys = /* @__PURE__ */ new Set();
54
- targetUnmergedDictionaries.forEach((dict) => {
55
- affectedDictionaryKeys.add(dict.key);
56
- });
57
- appLogger([
58
- "Affected dictionary keys for processing:",
59
- Array.from(affectedDictionaryKeys).map((key) => colorizeKey(key)).join(", ")
60
- ]);
61
- const maxKeyLength = Math.max(
62
- ...targetUnmergedDictionaries.map((dict) => dict.key.length)
63
- );
64
- const maxLocaleLength = Math.max(
65
- ...locales.map((locale) => formatLocale(locale).length)
66
- );
67
- const dictionariesRecord = getDictionaries(configuration);
68
- const translationTasks = [];
69
- for (const targetUnmergedDictionary of targetUnmergedDictionaries) {
70
- const dictionaryPreset = colon(
71
- [
72
- colorize(" - [", ANSIColors.GREY_DARK),
73
- colorizeKey(targetUnmergedDictionary.key),
74
- colorize("]", ANSIColors.GREY_DARK)
75
- ].join(""),
76
- { colSize: maxKeyLength + 6 }
77
- );
78
- const dictionaryKey = targetUnmergedDictionary.key;
79
- const mainDictionaryToProcess = dictionariesRecord[dictionaryKey];
80
- const sourceLocale = targetUnmergedDictionary.locale ?? baseLocale;
81
- if (!mainDictionaryToProcess) {
82
- appLogger(
83
- `${dictionaryPreset} Dictionary not found in dictionariesRecord. Skipping.`,
84
- {
85
- level: "warn"
86
- }
87
- );
88
- continue;
89
- }
90
- if (!targetUnmergedDictionary.filePath) {
91
- appLogger(`${dictionaryPreset} Dictionary has no file path. Skipping.`, {
92
- level: "warn"
93
- });
94
- continue;
95
- }
96
- const relativePath = relative(
97
- configuration.content.baseDir,
98
- targetUnmergedDictionary.filePath
99
- );
100
- appLogger(
101
- `${dictionaryPreset} Processing content declaration: ${colorizePath(relativePath)}`,
102
- {
103
- level: "info"
104
- }
105
- );
106
- const sourceLocaleContent = getFilterTranslationsOnlyContent(
107
- mainDictionaryToProcess,
108
- sourceLocale,
109
- { dictionaryKey, keyPath: [] }
110
- );
111
- if (Object.keys(sourceLocaleContent).length === 0) {
112
- appLogger(
113
- `${dictionaryPreset} No content found for dictionary in source locale ${formatLocale(sourceLocale)}. Skipping translation for this dictionary.`,
114
- {
115
- level: "warn"
116
- }
117
- );
118
- continue;
119
- }
120
- let outputLocalesList = outputLocales;
121
- if (mode === "complete") {
122
- const missingLocales = getMissingLocalesContent(
123
- mainDictionaryToProcess,
124
- outputLocales,
125
- {
126
- dictionaryKey: mainDictionaryToProcess.key,
127
- keyPath: [],
128
- plugins: []
129
- }
130
- );
131
- outputLocalesList = missingLocales;
132
- }
133
- if (outputLocalesList.length === 0) {
134
- appLogger(
135
- `${dictionaryPreset} No locales to fill - Skipping dictionary`,
136
- {
137
- level: "warn"
138
- }
139
- );
140
- continue;
141
- }
142
- for (const targetLocale of outputLocalesList) {
143
- const localePreset = colon(
144
- [
145
- colorize("[", ANSIColors.GREY_DARK),
146
- formatLocale(targetLocale),
147
- colorize("]", ANSIColors.GREY_DARK)
148
- ].join(""),
149
- { colSize: maxLocaleLength }
150
- );
151
- translationTasks.push({
152
- dictionaryKey,
153
- sourceLocale,
154
- targetLocale,
155
- dictionaryPreset,
156
- localePreset
157
- });
158
- }
159
- }
160
- const translationResults = await parallelize(
161
- translationTasks,
162
- async (task) => {
163
- const mainDictionaryToProcess = dictionariesRecord[task.dictionaryKey];
164
- appLogger(
165
- `${task.dictionaryPreset}${task.localePreset} Preparing translation for dictionary from ${formatLocale(task.sourceLocale)} to ${formatLocale(task.targetLocale)}`,
166
- {
167
- level: "info"
168
- }
169
- );
170
- const sourceLocaleContent = getFilterTranslationsOnlyContent(
171
- mainDictionaryToProcess,
172
- task.sourceLocale,
173
- { dictionaryKey: task.dictionaryKey, keyPath: [] }
174
- );
175
- const presetOutputContent = getLocalisedContent(
176
- mainDictionaryToProcess,
177
- task.targetLocale,
178
- { dictionaryKey: task.dictionaryKey, keyPath: [] }
179
- );
180
- try {
181
- const translationResult = await intlayerAPI.ai.translateJSON({
182
- entryFileContent: sourceLocaleContent.content,
183
- presetOutputContent: presetOutputContent.content,
184
- dictionaryDescription: mainDictionaryToProcess.description ?? "",
185
- entryLocale: task.sourceLocale,
186
- outputLocale: task.targetLocale,
187
- mode,
188
- aiOptions: options.aiOptions
189
- });
190
- if (!translationResult.data?.fileContent) {
191
- appLogger(
192
- `${task.dictionaryPreset}${task.localePreset} No content result`,
193
- {
194
- level: "error"
195
- }
196
- );
197
- return { key: task.dictionaryKey, result: null };
198
- }
199
- const processedPerLocaleDictionary = processPerLocaleDictionary({
200
- ...mainDictionaryToProcess,
201
- content: translationResult.data?.fileContent,
202
- locale: task.targetLocale
203
- });
204
- return {
205
- key: task.dictionaryKey,
206
- result: processedPerLocaleDictionary
207
- };
208
- } catch (error) {
209
- appLogger(
210
- `${task.dictionaryPreset}${task.localePreset} ${colorize("Error filling", ANSIColors.RED)}: ` + error,
211
- {
212
- level: "error"
213
- }
214
- );
215
- return { key: task.dictionaryKey, result: null };
216
- }
217
- },
218
- options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS
219
- );
220
- const resultsByDictionary = /* @__PURE__ */ new Map();
221
- for (const item of translationResults) {
222
- if (item?.result) {
223
- const list = resultsByDictionary.get(item.key) ?? [];
224
- list.push(item.result);
225
- resultsByDictionary.set(item.key, list);
226
- }
227
- }
228
- for (const targetUnmergedDictionary of targetUnmergedDictionaries) {
229
- const dictionaryKey = targetUnmergedDictionary.key;
230
- const mainDictionaryToProcess = dictionariesRecord[dictionaryKey];
231
- const sourceLocale = targetUnmergedDictionary.locale ?? baseLocale;
232
- if (!mainDictionaryToProcess || !targetUnmergedDictionary.filePath) {
233
- continue;
234
- }
235
- let outputLocalesList = outputLocales;
236
- if (mode === "complete") {
237
- const missingLocales = getMissingLocalesContent(
238
- mainDictionaryToProcess,
239
- outputLocales,
240
- {
241
- dictionaryKey: mainDictionaryToProcess.key,
242
- keyPath: [],
243
- plugins: []
244
- }
245
- );
246
- outputLocalesList = missingLocales;
247
- }
248
- if (outputLocalesList.length === 0) {
249
- continue;
250
- }
251
- const perLocaleResults = resultsByDictionary.get(dictionaryKey) ?? [];
252
- const dictionaryToMerge = mode === "review" ? [...perLocaleResults, mainDictionaryToProcess] : [mainDictionaryToProcess, ...perLocaleResults];
253
- const mergedResults = mergeDictionaries(dictionaryToMerge);
254
- let formattedDict = targetUnmergedDictionary;
255
- if (formattedDict.locale) {
256
- const presetOutputContent = getLocalisedContent(
257
- mainDictionaryToProcess,
258
- formattedDict.locale,
259
- { dictionaryKey, keyPath: [] }
260
- );
261
- formattedDict = {
262
- ...formattedDict,
263
- content: presetOutputContent.content
264
- };
265
- }
266
- const reducedResult = reduceDictionaryContent(mergedResults, formattedDict);
267
- if (formattedDict.autoFill || configuration.content.autoFill) {
268
- await autoFill(
269
- mergedResults,
270
- targetUnmergedDictionary,
271
- formattedDict.autoFill ?? configuration.content.autoFill,
272
- outputLocalesList,
273
- [sourceLocale],
274
- configuration
275
- );
276
- } else {
277
- await writeContentDeclaration(
278
- { ...formattedDict, content: reducedResult.content },
279
- configuration,
280
- formattedDict.filePath
281
- );
282
- if (formattedDict.filePath) {
283
- const dictionaryPreset = colon(
284
- [
285
- colorize(" - [", ANSIColors.GREY_DARK),
286
- colorizeKey(targetUnmergedDictionary.key),
287
- colorize("]", ANSIColors.GREY_DARK)
288
- ].join(""),
289
- { colSize: maxKeyLength + 6 }
290
- );
291
- appLogger(
292
- `${dictionaryPreset} Content declaration written to ${formatPath(formattedDict.filePath)}`,
293
- {
294
- level: "info"
295
- }
296
- );
297
- }
298
- }
299
- }
300
- };
301
- export {
302
- fill
16
+ const configuration = getConfiguration(options?.configOptions);
17
+ const appLogger = getAppLogger(configuration);
18
+ if (options?.build === true) await prepareIntlayer(configuration, { forceRun: true });
19
+ else if (typeof options?.build === "undefined") await prepareIntlayer(configuration);
20
+ const { defaultLocale, locales } = configuration.internationalization;
21
+ const mode = options?.mode ?? "complete";
22
+ const baseLocale = options?.sourceLocale ?? defaultLocale;
23
+ const outputLocales = (options?.outputLocales ? ensureArray(options.outputLocales) : locales).filter((locale) => locale !== baseLocale);
24
+ if (!await checkAIAccess(configuration, options?.aiOptions)) return;
25
+ const targetUnmergedDictionaries = await getTargetUnmergedDictionaries(options);
26
+ const affectedDictionaryKeys = /* @__PURE__ */ new Set();
27
+ targetUnmergedDictionaries.forEach((dict) => {
28
+ affectedDictionaryKeys.add(dict.key);
29
+ });
30
+ const keysToProcess = Array.from(affectedDictionaryKeys);
31
+ appLogger(["Affected dictionary keys for processing:", keysToProcess.length > 0 ? keysToProcess.map((key) => colorizeKey(key)).join(", ") : colorize("No keys found", ANSIColors.YELLOW)]);
32
+ if (keysToProcess.length === 0) return;
33
+ /**
34
+ * List the translations tasks
35
+ *
36
+ * Create a list of per-locale dictionaries to translate
37
+ *
38
+ * In 'complete' mode, filter only the missing locales to translate
39
+ */
40
+ const translationTasks = listTranslationsTasks(targetUnmergedDictionaries.map((dict) => dict.localId), outputLocales, mode, baseLocale, configuration);
41
+ const nbConcurrentTranslations = options?.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS;
42
+ const globalLimiter = getGlobalLimiter(nbConcurrentTranslations);
43
+ const taskLimiter = getTaskLimiter(Math.min(options?.nbConcurrentTasks ?? nbConcurrentTranslations, translationTasks.length));
44
+ const runners = translationTasks.map((task) => taskLimiter(async () => {
45
+ const relativePath = relative(configuration?.content?.baseDir ?? process.cwd(), task?.dictionaryFilePath ?? "");
46
+ appLogger(`${task.dictionaryPreset} Processing ${colorizePath(basename(relativePath))}`, { level: "info" });
47
+ const translationTaskResult = await translateDictionary(task, configuration, {
48
+ mode,
49
+ aiOptions: options?.aiOptions,
50
+ fillMetadata: !options?.skipMetadata,
51
+ onHandle: globalLimiter
52
+ });
53
+ if (!translationTaskResult?.dictionaryOutput) return;
54
+ const { dictionaryOutput, sourceLocale } = translationTaskResult;
55
+ if (typeof dictionaryOutput.fill === "string" || typeof dictionaryOutput.fill === "object") await writeFill(dictionaryOutput, outputLocales, [sourceLocale], configuration);
56
+ else {
57
+ await writeContentDeclaration(dictionaryOutput, configuration);
58
+ if (dictionaryOutput.filePath) appLogger(`${colon([
59
+ " - ",
60
+ colorize("[", ANSIColors.GREY_DARK),
61
+ colorizeKey(dictionaryOutput.key),
62
+ colorize("]", ANSIColors.GREY_DARK)
63
+ ].join(""), { colSize: 15 })} Content declaration written to ${formatPath(basename(dictionaryOutput.filePath))}`, { level: "info" });
64
+ }
65
+ }));
66
+ await Promise.all(runners);
67
+ await globalLimiter.onIdle();
303
68
  };
69
+
70
+ //#endregion
71
+ export { fill };
304
72
  //# sourceMappingURL=fill.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fill/fill.ts"],"sourcesContent":["import { AIOptions, getIntlayerAPIProxy } from '@intlayer/api'; // Importing only getAiAPI for now\nimport {\n formatLocale,\n formatPath,\n ListGitFilesOptions,\n mergeDictionaries,\n parallelize,\n prepareIntlayer,\n processPerLocaleDictionary,\n reduceDictionaryContent,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizePath,\n getAppLogger,\n getConfiguration,\n Locales,\n} from '@intlayer/config';\nimport {\n type ContentNode,\n type Dictionary,\n getFilterTranslationsOnlyContent,\n getLocalisedContent,\n getMissingLocalesContent,\n} from '@intlayer/core';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { relative } from 'path';\nimport {\n ensureArray,\n GetTargetDictionaryOptions,\n getTargetUnmergedDictionaries,\n} from '../getTargetDictionary';\nimport { checkAIAccess } from '../utils/checkAccess';\nimport { autoFill } from './autoFill';\n\nconst NB_CONCURRENT_TRANSLATIONS = 8;\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locales;\n outputLocales?: Locales | Locales[];\n mode?: 'complete' | 'review';\n gitOptions?: ListGitFilesOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n nbConcurrentTranslations?: number;\n build?: boolean;\n} & GetTargetDictionaryOptions;\n\n/**\n * Fill translations based on the provided options.\n */\nexport const fill = async (options: FillOptions): Promise<void> => {\n const configuration = getConfiguration(options.configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n if (options.build) {\n await prepareIntlayer(configuration);\n }\n\n const { defaultLocale, locales } = configuration.internationalization;\n const mode = options.mode ?? 'complete';\n const baseLocale = options.sourceLocale ?? defaultLocale;\n const outputLocales = (\n options.outputLocales ? ensureArray(options.outputLocales) : locales\n ).filter((locale) => locale !== baseLocale);\n\n const hasAIAccess = await checkAIAccess(configuration, options.aiOptions);\n\n if (!hasAIAccess) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n const targetUnmergedDictionaries =\n await getTargetUnmergedDictionaries(options);\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n appLogger([\n 'Affected dictionary keys for processing:',\n Array.from(affectedDictionaryKeys)\n .map((key) => colorizeKey(key))\n .join(', '),\n ]);\n\n const maxKeyLength = Math.max(\n ...targetUnmergedDictionaries.map((dict) => dict.key.length)\n );\n const maxLocaleLength = Math.max(\n ...locales.map((locale) => formatLocale(locale).length)\n );\n const dictionariesRecord = getDictionaries(configuration);\n\n type TranslationTask = {\n dictionaryKey: string;\n sourceLocale: Locales;\n targetLocale: Locales;\n dictionaryPreset: string;\n localePreset: string;\n };\n\n const translationTasks: TranslationTask[] = [];\n\n for (const targetUnmergedDictionary of targetUnmergedDictionaries) {\n const dictionaryPreset = colon(\n [\n colorize(' - [', ANSIColors.GREY_DARK),\n colorizeKey(targetUnmergedDictionary.key),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: maxKeyLength + 6 }\n );\n\n const dictionaryKey = targetUnmergedDictionary.key;\n const mainDictionaryToProcess: Dictionary =\n dictionariesRecord[dictionaryKey];\n\n const sourceLocale: Locales =\n (targetUnmergedDictionary.locale as Locales) ?? baseLocale;\n\n if (!mainDictionaryToProcess) {\n appLogger(\n `${dictionaryPreset} Dictionary not found in dictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n if (!targetUnmergedDictionary.filePath) {\n appLogger(`${dictionaryPreset} Dictionary has no file path. Skipping.`, {\n level: 'warn',\n });\n continue;\n }\n\n const relativePath = relative(\n configuration.content.baseDir,\n targetUnmergedDictionary.filePath\n );\n\n appLogger(\n `${dictionaryPreset} Processing content declaration: ${colorizePath(relativePath)}`,\n {\n level: 'info',\n }\n );\n\n const sourceLocaleContent = getFilterTranslationsOnlyContent(\n mainDictionaryToProcess as unknown as ContentNode,\n sourceLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n if (Object.keys(sourceLocaleContent).length === 0) {\n appLogger(\n `${dictionaryPreset} No content found for dictionary in source locale ${formatLocale(sourceLocale)}. Skipping translation for this dictionary.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n let outputLocalesList: Locales[] = outputLocales;\n\n if (mode === 'complete') {\n const missingLocales = getMissingLocalesContent(\n mainDictionaryToProcess as unknown as ContentNode,\n outputLocales,\n {\n dictionaryKey: mainDictionaryToProcess.key,\n keyPath: [],\n plugins: [],\n }\n );\n\n outputLocalesList = missingLocales;\n }\n\n if (outputLocalesList.length === 0) {\n appLogger(\n `${dictionaryPreset} No locales to fill - Skipping dictionary`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n for (const targetLocale of outputLocalesList) {\n const localePreset = colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n formatLocale(targetLocale),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: maxLocaleLength }\n );\n\n translationTasks.push({\n dictionaryKey,\n sourceLocale,\n targetLocale,\n dictionaryPreset,\n localePreset,\n });\n }\n }\n\n const translationResults = await parallelize(\n translationTasks,\n async (task) => {\n const mainDictionaryToProcess: Dictionary =\n dictionariesRecord[task.dictionaryKey];\n\n appLogger(\n `${task.dictionaryPreset}${task.localePreset} Preparing translation for dictionary from ${formatLocale(task.sourceLocale)} to ${formatLocale(task.targetLocale)}`,\n {\n level: 'info',\n }\n );\n\n const sourceLocaleContent = getFilterTranslationsOnlyContent(\n mainDictionaryToProcess as unknown as ContentNode,\n task.sourceLocale,\n { dictionaryKey: task.dictionaryKey, keyPath: [] }\n );\n\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n task.targetLocale,\n { dictionaryKey: task.dictionaryKey, keyPath: [] }\n );\n\n try {\n const translationResult = await intlayerAPI.ai.translateJSON({\n entryFileContent: sourceLocaleContent.content,\n presetOutputContent: presetOutputContent.content,\n dictionaryDescription: mainDictionaryToProcess.description ?? '',\n entryLocale: task.sourceLocale,\n outputLocale: task.targetLocale,\n mode,\n aiOptions: options.aiOptions,\n });\n\n if (!translationResult.data?.fileContent) {\n appLogger(\n `${task.dictionaryPreset}${task.localePreset} No content result`,\n {\n level: 'error',\n }\n );\n return { key: task.dictionaryKey, result: null } as const;\n }\n\n const processedPerLocaleDictionary = processPerLocaleDictionary({\n ...mainDictionaryToProcess,\n content: translationResult.data?.fileContent,\n locale: task.targetLocale,\n });\n\n return {\n key: task.dictionaryKey,\n result: processedPerLocaleDictionary,\n } as const;\n } catch (error) {\n appLogger(\n `${task.dictionaryPreset}${task.localePreset} ${colorize('Error filling', ANSIColors.RED)}: ` +\n error,\n {\n level: 'error',\n }\n );\n return { key: task.dictionaryKey, result: null } as const;\n }\n },\n options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS\n );\n\n const resultsByDictionary = new Map<string, Dictionary[]>();\n for (const item of translationResults) {\n if (item?.result) {\n const list = resultsByDictionary.get(item.key) ?? [];\n list.push(item.result);\n resultsByDictionary.set(item.key, list);\n }\n }\n\n for (const targetUnmergedDictionary of targetUnmergedDictionaries) {\n const dictionaryKey = targetUnmergedDictionary.key;\n const mainDictionaryToProcess: Dictionary =\n dictionariesRecord[dictionaryKey];\n\n const sourceLocale: Locales =\n (targetUnmergedDictionary.locale as Locales) ?? baseLocale;\n\n if (!mainDictionaryToProcess || !targetUnmergedDictionary.filePath) {\n continue;\n }\n\n let outputLocalesList: Locales[] = outputLocales;\n\n if (mode === 'complete') {\n const missingLocales = getMissingLocalesContent(\n mainDictionaryToProcess as unknown as ContentNode,\n outputLocales,\n {\n dictionaryKey: mainDictionaryToProcess.key,\n keyPath: [],\n plugins: [],\n }\n );\n\n outputLocalesList = missingLocales;\n }\n\n if (outputLocalesList.length === 0) {\n continue;\n }\n\n const perLocaleResults = resultsByDictionary.get(dictionaryKey) ?? [];\n\n const dictionaryToMerge =\n mode === 'review'\n ? [...perLocaleResults, mainDictionaryToProcess]\n : [mainDictionaryToProcess, ...perLocaleResults];\n\n const mergedResults = mergeDictionaries(dictionaryToMerge);\n\n let formattedDict = targetUnmergedDictionary;\n\n if (formattedDict.locale) {\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n formattedDict.locale,\n { dictionaryKey, keyPath: [] }\n );\n\n formattedDict = {\n ...formattedDict,\n content: presetOutputContent.content,\n };\n }\n\n const reducedResult = reduceDictionaryContent(mergedResults, formattedDict);\n\n if (formattedDict.autoFill || configuration.content.autoFill) {\n await autoFill(\n mergedResults,\n targetUnmergedDictionary,\n formattedDict.autoFill ?? configuration.content.autoFill,\n outputLocalesList,\n [sourceLocale],\n configuration\n );\n } else {\n await writeContentDeclaration(\n { ...formattedDict, content: reducedResult.content },\n configuration,\n formattedDict.filePath\n );\n\n if (formattedDict.filePath) {\n const dictionaryPreset = colon(\n [\n colorize(' - [', ANSIColors.GREY_DARK),\n colorizeKey(targetUnmergedDictionary.key),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: maxKeyLength + 6 }\n );\n appLogger(\n `${dictionaryPreset} Content declaration written to ${formatPath(formattedDict.filePath)}`,\n {\n level: 'info',\n }\n );\n }\n }\n }\n};\n"],"mappings":"AAAA,SAAoB,2BAA2B;AAC/C;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,qB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AAA,EACF;AACF;","names":[]}
1
+ {"version":3,"file":"fill.mjs","names":["translationTasks: TranslationTask[]"],"sources":["../../../src/fill/fill.ts"],"sourcesContent":["import { basename, relative } from 'node:path';\nimport type { AIOptions } from '@intlayer/api';\nimport {\n formatPath,\n getGlobalLimiter,\n getTaskLimiter,\n type ListGitFilesOptions,\n prepareIntlayer,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizePath,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { Locale } from '@intlayer/types';\nimport {\n ensureArray,\n type GetTargetDictionaryOptions,\n getTargetUnmergedDictionaries,\n} from '../getTargetDictionary';\nimport { checkAIAccess } from '../utils/checkAccess';\nimport {\n listTranslationsTasks,\n type TranslationTask,\n} from './listTranslationsTasks';\nimport { translateDictionary } from './translateDictionary';\nimport { writeFill } from './writeFill';\n\nconst NB_CONCURRENT_TRANSLATIONS = 7;\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locale;\n outputLocales?: Locale | Locale[];\n mode?: 'complete' | 'review';\n gitOptions?: ListGitFilesOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n nbConcurrentTranslations?: number;\n nbConcurrentTasks?: number; // NEW: number of tasks that may run at once\n build?: boolean;\n skipMetadata?: boolean;\n} & GetTargetDictionaryOptions;\n\n/**\n * Fill translations based on the provided options.\n */\nexport const fill = async (options?: FillOptions): Promise<void> => {\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n if (options?.build === true) {\n await prepareIntlayer(configuration, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(configuration);\n }\n\n const { defaultLocale, locales } = configuration.internationalization;\n const mode = options?.mode ?? 'complete';\n const baseLocale = options?.sourceLocale ?? defaultLocale;\n const outputLocales = (\n options?.outputLocales ? ensureArray(options.outputLocales) : locales\n ).filter((locale) => locale !== baseLocale);\n\n const hasAIAccess = await checkAIAccess(configuration, options?.aiOptions);\n\n if (!hasAIAccess) return;\n\n const targetUnmergedDictionaries =\n await getTargetUnmergedDictionaries(options);\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n const keysToProcess = Array.from(affectedDictionaryKeys);\n\n appLogger([\n 'Affected dictionary keys for processing:',\n keysToProcess.length > 0\n ? keysToProcess.map((key) => colorizeKey(key)).join(', ')\n : colorize('No keys found', ANSIColors.YELLOW),\n ]);\n\n if (keysToProcess.length === 0) return;\n\n /**\n * List the translations tasks\n *\n * Create a list of per-locale dictionaries to translate\n *\n * In 'complete' mode, filter only the missing locales to translate\n */\n const translationTasks: TranslationTask[] = listTranslationsTasks(\n targetUnmergedDictionaries.map((dict) => dict.localId!),\n outputLocales,\n mode,\n baseLocale,\n configuration\n );\n\n // AI calls in flight at once (translateJSON + metadata audit)\n const nbConcurrentTranslations =\n options?.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS;\n const globalLimiter = getGlobalLimiter(nbConcurrentTranslations);\n\n // NEW: number of *tasks* that may run at once (start/prepare/log/write)\n const nbConcurrentTasks = Math.min(\n options?.nbConcurrentTasks ?? nbConcurrentTranslations,\n translationTasks.length\n );\n const taskLimiter = getTaskLimiter(nbConcurrentTasks);\n\n const runners = translationTasks.map((task) =>\n taskLimiter(async () => {\n const relativePath = relative(\n configuration?.content?.baseDir ?? process.cwd(),\n task?.dictionaryFilePath ?? ''\n );\n\n // log AFTER acquiring a task slot\n appLogger(\n `${task.dictionaryPreset} Processing ${colorizePath(basename(relativePath))}`,\n { level: 'info' }\n );\n\n const translationTaskResult = await translateDictionary(\n task,\n configuration,\n {\n mode,\n aiOptions: options?.aiOptions,\n fillMetadata: !options?.skipMetadata,\n onHandle: globalLimiter, // <= AI calls go through here\n }\n );\n\n if (!translationTaskResult?.dictionaryOutput) return;\n\n const { dictionaryOutput, sourceLocale } = translationTaskResult;\n\n // fix impossible && condition\n const isFillOtherFile =\n typeof dictionaryOutput.fill === 'string' ||\n typeof dictionaryOutput.fill === 'object';\n\n if (isFillOtherFile) {\n await writeFill(\n dictionaryOutput,\n outputLocales,\n [sourceLocale],\n configuration\n );\n } else {\n await writeContentDeclaration(dictionaryOutput, configuration);\n\n if (dictionaryOutput.filePath) {\n const dictionaryPreset = colon(\n [\n ' - ',\n colorize('[', ANSIColors.GREY_DARK),\n colorizeKey(dictionaryOutput.key),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 15 }\n );\n appLogger(\n `${dictionaryPreset} Content declaration written to ${formatPath(basename(dictionaryOutput.filePath))}`,\n { level: 'info' }\n );\n }\n }\n })\n );\n\n await Promise.all(runners);\n await (globalLimiter as any).onIdle();\n};\n"],"mappings":";;;;;;;;;;AAiCA,MAAM,6BAA6B;;;;AAmBnC,MAAa,OAAO,OAAO,YAAyC;CAClE,MAAM,gBAAgB,iBAAiB,SAAS,cAAc;CAC9D,MAAM,YAAY,aAAa,cAAc;AAE7C,KAAI,SAAS,UAAU,KACrB,OAAM,gBAAgB,eAAe,EAAE,UAAU,MAAM,CAAC;UAC/C,OAAO,SAAS,UAAU,YACnC,OAAM,gBAAgB,cAAc;CAGtC,MAAM,EAAE,eAAe,YAAY,cAAc;CACjD,MAAM,OAAO,SAAS,QAAQ;CAC9B,MAAM,aAAa,SAAS,gBAAgB;CAC5C,MAAM,iBACJ,SAAS,gBAAgB,YAAY,QAAQ,cAAc,GAAG,SAC9D,QAAQ,WAAW,WAAW,WAAW;AAI3C,KAAI,CAFgB,MAAM,cAAc,eAAe,SAAS,UAAU,CAExD;CAElB,MAAM,6BACJ,MAAM,8BAA8B,QAAQ;CAE9C,MAAM,yCAAyB,IAAI,KAAa;AAChD,4BAA2B,SAAS,SAAS;AAC3C,yBAAuB,IAAI,KAAK,IAAI;GACpC;CAEF,MAAM,gBAAgB,MAAM,KAAK,uBAAuB;AAExD,WA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CAClB;;GAGL,CACH;AAED,OAAM,QAAQ,IAAI,QAAQ;AAC1B,OAAO,cAAsB,QAAQ"}
@@ -1,84 +1,50 @@
1
- import { extname } from "path";
2
1
  import { formatAutoFilledFilePath } from "./formatAutoFilledFilePath.mjs";
3
- const formatAutoFillData = (autoFillField, localeList, filePath, dictionaryKey, configuration) => {
4
- const outputContentDeclarationFile = [];
5
- const baseDir = configuration.content.baseDir;
6
- if (!Boolean(autoFillField)) return outputContentDeclarationFile;
7
- if (autoFillField === true) {
8
- let jsonFilePath = filePath.replace(extname(filePath), ".json");
9
- if (filePath === jsonFilePath) {
10
- jsonFilePath = jsonFilePath.replace(extname(jsonFilePath), ".fill.json");
11
- }
12
- outputContentDeclarationFile.push({
13
- localeList,
14
- filePath: jsonFilePath,
15
- isPerLocale: false
16
- });
17
- }
18
- if (typeof autoFillField === "string") {
19
- if (autoFillField.includes("{{locale}}")) {
20
- const output = localeList.map((locale) => {
21
- const formattedFilePath = formatAutoFilledFilePath(
22
- autoFillField,
23
- dictionaryKey,
24
- filePath,
25
- baseDir,
26
- locale
27
- );
28
- return {
29
- localeList: [locale],
30
- filePath: formattedFilePath,
31
- isPerLocale: true
32
- };
33
- });
34
- outputContentDeclarationFile.push(...output);
35
- } else {
36
- const formattedFilePath = formatAutoFilledFilePath(
37
- autoFillField,
38
- dictionaryKey,
39
- filePath,
40
- baseDir
41
- );
42
- outputContentDeclarationFile.push({
43
- localeList,
44
- filePath: formattedFilePath,
45
- isPerLocale: false
46
- });
47
- }
48
- return outputContentDeclarationFile;
49
- }
50
- if (typeof autoFillField === "object") {
51
- const localeList2 = Object.keys(autoFillField).filter(
52
- (locale) => typeof autoFillField[locale] === "string"
53
- );
54
- const output = localeList2.filter((locale) => Boolean(autoFillField[locale])).map((locale) => {
55
- const formattedFilePath = formatAutoFilledFilePath(
56
- autoFillField[locale],
57
- dictionaryKey,
58
- filePath,
59
- baseDir,
60
- locale
61
- );
62
- return {
63
- localeList: [locale],
64
- filePath: formattedFilePath,
65
- isPerLocale: true
66
- };
67
- });
68
- const groupedByFilePath = output.reduce((acc, curr) => {
69
- const existing = acc.find((item) => item.filePath === curr.filePath);
70
- if (existing) {
71
- existing.localeList.push(...curr.localeList);
72
- } else {
73
- acc.push(curr);
74
- }
75
- return acc;
76
- }, []);
77
- outputContentDeclarationFile.push(...groupedByFilePath);
78
- }
79
- return outputContentDeclarationFile;
80
- };
81
- export {
82
- formatAutoFillData
2
+
3
+ //#region src/fill/formatAutoFillData.ts
4
+ const formatFillData = (autoFillField, localeList, filePath, dictionaryKey, configuration) => {
5
+ const outputContentDeclarationFile = [];
6
+ const baseDir = configuration.content.baseDir;
7
+ if (!autoFillField) return outputContentDeclarationFile;
8
+ if (typeof autoFillField === "string") {
9
+ if (autoFillField.includes("{{locale}}")) {
10
+ const output = localeList.map((locale) => {
11
+ const formattedFilePath = formatAutoFilledFilePath(autoFillField, dictionaryKey, filePath, baseDir, locale);
12
+ return {
13
+ localeList: [locale],
14
+ filePath: formattedFilePath,
15
+ isPerLocale: true
16
+ };
17
+ });
18
+ outputContentDeclarationFile.push(...output);
19
+ } else {
20
+ const formattedFilePath = formatAutoFilledFilePath(autoFillField, dictionaryKey, filePath, baseDir);
21
+ outputContentDeclarationFile.push({
22
+ localeList,
23
+ filePath: formattedFilePath,
24
+ isPerLocale: false
25
+ });
26
+ }
27
+ return outputContentDeclarationFile;
28
+ }
29
+ if (typeof autoFillField === "object") {
30
+ const groupedByFilePath = Object.keys(autoFillField).filter((locale) => typeof autoFillField[locale] === "string").filter((locale) => Boolean(autoFillField[locale])).map((locale) => {
31
+ const formattedFilePath = formatAutoFilledFilePath(autoFillField[locale], dictionaryKey, filePath, baseDir, locale);
32
+ return {
33
+ localeList: [locale],
34
+ filePath: formattedFilePath,
35
+ isPerLocale: true
36
+ };
37
+ }).reduce((acc, curr) => {
38
+ const existing = acc.find((item) => item.filePath === curr.filePath);
39
+ if (existing) existing.localeList.push(...curr.localeList);
40
+ else acc.push(curr);
41
+ return acc;
42
+ }, []);
43
+ outputContentDeclarationFile.push(...groupedByFilePath);
44
+ }
45
+ return outputContentDeclarationFile;
83
46
  };
47
+
48
+ //#endregion
49
+ export { formatFillData };
84
50
  //# sourceMappingURL=formatAutoFillData.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fill/formatAutoFillData.ts"],"sourcesContent":["import { type IntlayerConfig, Locales } from '@intlayer/config';\nimport { type AutoFill } from '@intlayer/core';\nimport { extname } from 'path';\nimport { formatAutoFilledFilePath } from './formatAutoFilledFilePath';\n\nexport type AutoFillData = {\n localeList: Locales[];\n filePath: string;\n isPerLocale: boolean;\n};\n\nexport const formatAutoFillData = (\n autoFillField: AutoFill,\n localeList: Locales[],\n filePath: string,\n dictionaryKey: string,\n configuration: IntlayerConfig\n): AutoFillData[] => {\n const outputContentDeclarationFile: AutoFillData[] = [];\n\n const baseDir = configuration.content.baseDir;\n\n if (!Boolean(autoFillField)) return outputContentDeclarationFile;\n\n if (autoFillField === true) {\n // wanted jsonFilePath: /..../src/components/home/index.content.json\n // replace file extension in json\n let jsonFilePath = filePath.replace(extname(filePath), '.json');\n\n // if both filePath jsonFilePath are same path, change it as : /..../src/components/home/index.fill.content.json\n if (filePath === jsonFilePath) {\n jsonFilePath = jsonFilePath.replace(extname(jsonFilePath), '.fill.json');\n }\n\n outputContentDeclarationFile.push({\n localeList,\n filePath: jsonFilePath,\n isPerLocale: false,\n });\n }\n\n if (typeof autoFillField === 'string') {\n if (autoFillField.includes('{{locale}}')) {\n const output = localeList.map((locale) => {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField,\n dictionaryKey,\n filePath,\n baseDir,\n locale\n );\n\n return {\n localeList: [locale],\n filePath: formattedFilePath,\n isPerLocale: true,\n };\n });\n\n outputContentDeclarationFile.push(...output);\n } else {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField,\n dictionaryKey,\n filePath,\n baseDir\n );\n\n outputContentDeclarationFile.push({\n localeList,\n filePath: formattedFilePath,\n isPerLocale: false,\n });\n }\n\n return outputContentDeclarationFile;\n }\n\n if (typeof autoFillField === 'object') {\n const localeList = Object.keys(autoFillField).filter(\n (locale) => typeof autoFillField[locale] === 'string'\n ) as Locales[];\n\n const output: AutoFillData[] = localeList\n .filter((locale) => Boolean(autoFillField[locale]))\n .map((locale) => {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField[locale],\n dictionaryKey,\n filePath,\n baseDir,\n locale\n );\n\n return {\n localeList: [locale],\n filePath: formattedFilePath,\n isPerLocale: true,\n };\n });\n\n // Group by filePath and merge localeList\n const groupedByFilePath = output.reduce((acc, curr) => {\n const existing = acc.find((item) => item.filePath === curr.filePath);\n if (existing) {\n existing.localeList.push(...curr.localeList);\n } else {\n acc.push(curr);\n }\n return acc;\n }, [] as AutoFillData[]);\n\n outputContentDeclarationFile.push(...groupedByFilePath);\n }\n\n return outputContentDeclarationFile;\n};\n"],"mappings":"AAEA,SAAS,eAAe;AACxB,SAAS,gCAAgC;AAQlC,MAAM,qBAAqB,CAChC,eACA,YACA,UACA,eACA,kBACmB;AACnB,QAAM,+BAA+C,CAAC;AAEtD,QAAM,UAAU,cAAc,QAAQ;AAEtC,MAAI,CAAC,QAAQ,aAAa,EAAG,QAAO;AAEpC,MAAI,kBAAkB,MAAM;AAG1B,QAAI,eAAe,SAAS,QAAQ,QAAQ,QAAQ,GAAG,OAAO;AAG9D,QAAI,aAAa,cAAc;AAC7B,qBAAe,aAAa,QAAQ,QAAQ,YAAY,GAAG,YAAY;AAAA,IACzE;AAEA,iCAA6B,KAAK;AAAA,MAChC;AAAA,MACA,UAAU;AAAA,MACV,aAAa;AAAA,IACf,CAAC;AAAA,EACH;AAEA,MAAI,OAAO,kBAAkB,UAAU;AACrC,QAAI,cAAc,SAAS,YAAY,GAAG;AACxC,YAAM,SAAS,WAAW,IAAI,CAAC,WAAW;AACxC,cAAM,oBAAoB;AAAA,UACxB;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,eAAO;AAAA,UACL,YAAY,CAAC,MAAM;AAAA,UACnB,UAAU;AAAA,UACV,aAAa;AAAA,QACf;AAAA,MACF,CAAC;AAED,mCAA6B,KAAK,GAAG,MAAM;AAAA,IAC7C,OAAO;AACL,YAAM,oBAAoB;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAEA,mCAA6B,KAAK;AAAA,QAChC;AAAA,QACA,UAAU;AAAA,QACV,aAAa;AAAA,MACf,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,kBAAkB,UAAU;AACrC,UAAMA,cAAa,OAAO,KAAK,aAAa,EAAE;AAAA,MAC5C,CAAC,WAAW,OAAO,cAAc,MAAM,MAAM;AAAA,IAC/C;AAEA,UAAM,SAAyBA,YAC5B,OAAO,CAAC,WAAW,QAAQ,cAAc,MAAM,CAAC,CAAC,EACjD,IAAI,CAAC,WAAW;AACf,YAAM,oBAAoB;AAAA,QACxB,cAAc,MAAM;AAAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAEA,aAAO;AAAA,QACL,YAAY,CAAC,MAAM;AAAA,QACnB,UAAU;AAAA,QACV,aAAa;AAAA,MACf;AAAA,IACF,CAAC;AAGH,UAAM,oBAAoB,OAAO,OAAO,CAAC,KAAK,SAAS;AACrD,YAAM,WAAW,IAAI,KAAK,CAAC,SAAS,KAAK,aAAa,KAAK,QAAQ;AACnE,UAAI,UAAU;AACZ,iBAAS,WAAW,KAAK,GAAG,KAAK,UAAU;AAAA,MAC7C,OAAO;AACL,YAAI,KAAK,IAAI;AAAA,MACf;AACA,aAAO;AAAA,IACT,GAAG,CAAC,CAAmB;AAEvB,iCAA6B,KAAK,GAAG,iBAAiB;AAAA,EACxD;AAEA,SAAO;AACT;","names":["localeList"]}
1
+ {"version":3,"file":"formatAutoFillData.mjs","names":["outputContentDeclarationFile: FillData[]"],"sources":["../../../src/fill/formatAutoFillData.ts"],"sourcesContent":["import { extname } from 'node:path';\nimport type { Fill, IntlayerConfig, LocalesValues } from '@intlayer/types';\nimport { formatAutoFilledFilePath } from './formatAutoFilledFilePath';\n\nexport type FillData = {\n localeList: LocalesValues[];\n filePath: string;\n isPerLocale: boolean;\n};\n\nexport const formatFillData = (\n autoFillField: Fill,\n localeList: LocalesValues[],\n filePath: string,\n dictionaryKey: string,\n configuration: IntlayerConfig\n): FillData[] => {\n const outputContentDeclarationFile: FillData[] = [];\n\n const baseDir = configuration.content.baseDir;\n\n if (!autoFillField) return outputContentDeclarationFile;\n\n if (typeof autoFillField === 'string') {\n if (autoFillField.includes('{{locale}}')) {\n const output = localeList.map((locale) => {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField,\n dictionaryKey,\n filePath,\n baseDir,\n locale\n );\n\n return {\n localeList: [locale],\n filePath: formattedFilePath,\n isPerLocale: true,\n };\n });\n\n outputContentDeclarationFile.push(...output);\n } else {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField,\n dictionaryKey,\n filePath,\n baseDir\n );\n\n outputContentDeclarationFile.push({\n localeList,\n filePath: formattedFilePath,\n isPerLocale: false,\n });\n }\n\n return outputContentDeclarationFile;\n }\n\n if (typeof autoFillField === 'object') {\n const localeList = Object.keys(autoFillField).filter(\n (locale) =>\n typeof autoFillField[locale as keyof typeof autoFillField] === 'string'\n ) as LocalesValues[];\n\n const output: FillData[] = localeList\n .filter((locale) =>\n Boolean(autoFillField[locale as keyof typeof autoFillField])\n )\n .map((locale) => {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField[locale as keyof typeof autoFillField] as string,\n dictionaryKey,\n filePath,\n baseDir,\n locale\n );\n\n return {\n localeList: [locale],\n filePath: formattedFilePath,\n isPerLocale: true,\n };\n });\n\n // Group by filePath and merge localeList\n const groupedByFilePath = output.reduce((acc, curr) => {\n const existing = acc.find((item) => item.filePath === curr.filePath);\n if (existing) {\n existing.localeList.push(...curr.localeList);\n } else {\n acc.push(curr);\n }\n return acc;\n }, [] as FillData[]);\n\n outputContentDeclarationFile.push(...groupedByFilePath);\n }\n\n return outputContentDeclarationFile;\n};\n"],"mappings":";;;AAUA,MAAa,kBACX,eACA,YACA,UACA,eACA,kBACe;CACf,MAAMA,+BAA2C,EAAE;CAEnD,MAAM,UAAU,cAAc,QAAQ;AAEtC,KAAI,CAAC,cAAe,QAAO;AAE3B,KAAI,OAAO,kBAAkB,UAAU;AACrC,MAAI,cAAc,SAAS,aAAa,EAAE;GACxC,MAAM,SAAS,WAAW,KAAK,WAAW;IACxC,MAAM,oBAAoB,yBACxB,eACA,eACA,UACA,SACA,OACD;AAED,WAAO;KACL,YAAY,CAAC,OAAO;KACpB,UAAU;KACV,aAAa;KACd;KACD;AAEF,gCAA6B,KAAK,GAAG,OAAO;SACvC;GACL,MAAM,oBAAoB,yBACxB,eACA,eACA,UACA,QACD;AAED,gCAA6B,KAAK;IAChC;IACA,UAAU;IACV,aAAa;IACd,CAAC;;AAGJ,SAAO;;AAGT,KAAI,OAAO,kBAAkB,UAAU;EA2BrC,MAAM,oBA1Ba,OAAO,KAAK,cAAc,CAAC,QAC3C,WACC,OAAO,cAAc,YAA0C,SAClE,CAGE,QAAQ,WACP,QAAQ,cAAc,QAAsC,CAC7D,CACA,KAAK,WAAW;GACf,MAAM,oBAAoB,yBACxB,cAAc,SACd,eACA,UACA,SACA,OACD;AAED,UAAO;IACL,YAAY,CAAC,OAAO;IACpB,UAAU;IACV,aAAa;IACd;IACD,CAG6B,QAAQ,KAAK,SAAS;GACrD,MAAM,WAAW,IAAI,MAAM,SAAS,KAAK,aAAa,KAAK,SAAS;AACpE,OAAI,SACF,UAAS,WAAW,KAAK,GAAG,KAAK,WAAW;OAE5C,KAAI,KAAK,KAAK;AAEhB,UAAO;KACN,EAAE,CAAe;AAEpB,+BAA6B,KAAK,GAAG,kBAAkB;;AAGzD,QAAO"}
@@ -1,22 +1,28 @@
1
- import { basename, dirname, join } from "path";
2
- const transformUriToAbsolutePath = (uri, filePath, baseDir) => {
3
- if (uri.startsWith("/")) {
4
- return join(baseDir, uri);
5
- }
6
- if (uri.startsWith("./")) {
7
- return join(dirname(filePath), uri);
8
- }
9
- return filePath;
10
- };
1
+ import { basename, dirname, isAbsolute, normalize, resolve } from "node:path";
2
+
3
+ //#region src/fill/formatAutoFilledFilePath.ts
11
4
  const formatAutoFilledFilePath = (autoFillField, dictionaryKey, dictionaryFilePath, baseDir, locale) => {
12
- const fileName = basename(dictionaryFilePath).split(".").slice(0, -2).join(".");
13
- let result = autoFillField.replace("{{key}}", dictionaryKey).replace("{{fileName}}", fileName);
14
- if (locale) {
15
- result = result.replace("{{locale}}", locale);
16
- }
17
- return transformUriToAbsolutePath(result, dictionaryFilePath, baseDir);
18
- };
19
- export {
20
- formatAutoFilledFilePath
5
+ if (!autoFillField || typeof autoFillField !== "string") throw new Error("autoFillField must be a non-empty string");
6
+ if (!dictionaryKey || typeof dictionaryKey !== "string") throw new Error("dictionaryKey must be a non-empty string");
7
+ if (!dictionaryFilePath || typeof dictionaryFilePath !== "string") throw new Error("dictionaryFilePath must be a non-empty string");
8
+ if (!baseDir || typeof baseDir !== "string") throw new Error("baseDir must be a non-empty string");
9
+ const originalFileName = basename(dictionaryFilePath).split(".").slice(0, -2).join(".");
10
+ let result = autoFillField.replace(/\{\{key\}\}/g, originalFileName).replace(/\{\{fileName\}\}/g, originalFileName);
11
+ if (locale) result = result.replace(/\{\{locale\}\}/g, locale);
12
+ const absoluteDictionaryPath = isAbsolute(dictionaryFilePath) ? dictionaryFilePath : resolve(baseDir, dictionaryFilePath);
13
+ if (result.startsWith("./") || result.startsWith("../")) return resolve(dirname(absoluteDictionaryPath), result);
14
+ if (isAbsolute(result)) {
15
+ const normalizedResult = normalize(result);
16
+ const normalizedBaseDir = normalize(baseDir);
17
+ if (result.startsWith("/") && !normalizedResult.startsWith(normalizedBaseDir)) {
18
+ const relativeToBase = resolve(baseDir, result.substring(1));
19
+ if (!result.startsWith("/usr/") && !result.startsWith("/etc/") && !result.startsWith("/var/") && !result.startsWith("/home/") && !result.startsWith("/Users/")) return relativeToBase;
20
+ }
21
+ return normalizedResult;
22
+ }
23
+ return normalize(result);
21
24
  };
25
+
26
+ //#endregion
27
+ export { formatAutoFilledFilePath };
22
28
  //# sourceMappingURL=formatAutoFilledFilePath.mjs.map