@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.
- package/dist/cjs/IntlayerEventListener.cjs +187 -239
- package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
- package/dist/cjs/_virtual/_utils_asset.cjs +104 -0
- package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/cjs/build.cjs +23 -42
- package/dist/cjs/build.cjs.map +1 -1
- package/dist/cjs/cli.cjs +370 -431
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/config.cjs +10 -35
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/editor.cjs +51 -66
- package/dist/cjs/editor.cjs.map +1 -1
- package/dist/cjs/fill/fill.cjs +73 -301
- package/dist/cjs/fill/fill.cjs.map +1 -1
- package/dist/cjs/fill/formatAutoFillData.cjs +48 -106
- package/dist/cjs/fill/formatAutoFillData.cjs.map +1 -1
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs +27 -43
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
- package/dist/cjs/fill/formatFillData.cjs +50 -0
- package/dist/cjs/fill/formatFillData.cjs.map +1 -0
- package/dist/cjs/fill/groupLimiter.cjs +42 -0
- package/dist/cjs/fill/groupLimiter.cjs.map +1 -0
- package/dist/cjs/fill/index.cjs +5 -25
- package/dist/cjs/fill/listTranslationsTasks.cjs +77 -0
- package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -0
- package/dist/cjs/fill/test-original-case.cjs +10 -0
- package/dist/cjs/fill/test-original-case.cjs.map +1 -0
- package/dist/cjs/fill/translateDictionary.cjs +148 -0
- package/dist/cjs/fill/translateDictionary.cjs.map +1 -0
- package/dist/cjs/fill/writeAutoFill.cjs +48 -0
- package/dist/cjs/fill/writeAutoFill.cjs.map +1 -0
- package/dist/cjs/fill/writeFill.cjs +50 -0
- package/dist/cjs/fill/writeFill.cjs.map +1 -0
- package/dist/cjs/getTargetDictionary.cjs +36 -76
- package/dist/cjs/getTargetDictionary.cjs.map +1 -1
- package/dist/cjs/index.cjs +31 -45
- package/dist/cjs/listContentDeclaration.cjs +36 -64
- package/dist/cjs/listContentDeclaration.cjs.map +1 -1
- package/dist/cjs/liveSync.cjs +146 -221
- package/dist/cjs/liveSync.cjs.map +1 -1
- package/dist/cjs/pull.cjs +132 -195
- package/dist/cjs/pull.cjs.map +1 -1
- package/dist/cjs/push/pullLog.cjs +101 -144
- package/dist/cjs/push/pullLog.cjs.map +1 -1
- package/dist/cjs/push/push.cjs +159 -249
- package/dist/cjs/push/push.cjs.map +1 -1
- package/dist/cjs/pushConfig.cjs +18 -45
- package/dist/cjs/pushConfig.cjs.map +1 -1
- package/dist/cjs/pushLog.cjs +87 -128
- package/dist/cjs/pushLog.cjs.map +1 -1
- package/dist/cjs/reviewDoc.cjs +183 -291
- package/dist/cjs/reviewDoc.cjs.map +1 -1
- package/dist/cjs/test/index.cjs +52 -91
- package/dist/cjs/test/index.cjs.map +1 -1
- package/dist/cjs/test/listMissingTranslations.cjs +35 -62
- package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
- package/dist/cjs/translateDoc.cjs +127 -221
- package/dist/cjs/translateDoc.cjs.map +1 -1
- package/dist/cjs/utils/calculateChunks.cjs +85 -115
- package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
- package/dist/cjs/utils/checkAccess.cjs +33 -72
- package/dist/cjs/utils/checkAccess.cjs.map +1 -1
- package/dist/cjs/utils/checkFileModifiedRange.cjs +75 -91
- package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
- package/dist/cjs/utils/checkLastUpdateTime.cjs +17 -30
- package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
- package/dist/cjs/utils/chunkInference.cjs +28 -47
- package/dist/cjs/utils/chunkInference.cjs.map +1 -1
- package/dist/cjs/utils/fixChunkStartEndChars.cjs +23 -42
- package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
- package/dist/cjs/utils/formatTimeDiff.cjs +17 -43
- package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
- package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +13 -32
- package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
- package/dist/cjs/utils/getOutputFilePath.cjs +71 -86
- package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
- package/dist/cjs/utils/getParentPackageJSON.cjs +19 -44
- package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
- package/dist/cjs/utils/listSpecialChars.cjs +49 -73
- package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs +90 -132
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
- package/dist/cjs/utils/reorderParagraphs.cjs +86 -118
- package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
- package/dist/cjs/watch.cjs +21 -39
- package/dist/cjs/watch.cjs.map +1 -1
- package/dist/esm/IntlayerEventListener.mjs +178 -201
- package/dist/esm/IntlayerEventListener.mjs.map +1 -1
- package/dist/esm/_virtual/_utils_asset.mjs +100 -0
- package/dist/esm/_virtual/rolldown_runtime.mjs +8 -0
- package/dist/esm/build.mjs +20 -23
- package/dist/esm/build.mjs.map +1 -1
- package/dist/esm/cli.mjs +349 -380
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/config.mjs +8 -14
- package/dist/esm/config.mjs.map +1 -1
- package/dist/esm/editor.mjs +47 -41
- package/dist/esm/editor.mjs.map +1 -1
- package/dist/esm/fill/fill.mjs +68 -300
- package/dist/esm/fill/fill.mjs.map +1 -1
- package/dist/esm/fill/formatAutoFillData.mjs +47 -81
- package/dist/esm/fill/formatAutoFillData.mjs.map +1 -1
- package/dist/esm/fill/formatAutoFilledFilePath.mjs +25 -19
- package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
- package/dist/esm/fill/formatFillData.mjs +50 -0
- package/dist/esm/fill/formatFillData.mjs.map +1 -0
- package/dist/esm/fill/groupLimiter.mjs +40 -0
- package/dist/esm/fill/groupLimiter.mjs.map +1 -0
- package/dist/esm/fill/index.mjs +4 -3
- package/dist/esm/fill/listTranslationsTasks.mjs +70 -0
- package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -0
- package/dist/esm/fill/test-original-case.mjs +10 -0
- package/dist/esm/fill/test-original-case.mjs.map +1 -0
- package/dist/esm/fill/translateDictionary.mjs +141 -0
- package/dist/esm/fill/translateDictionary.mjs.map +1 -0
- package/dist/esm/fill/writeAutoFill.mjs +44 -0
- package/dist/esm/fill/writeAutoFill.mjs.map +1 -0
- package/dist/esm/fill/writeFill.mjs +45 -0
- package/dist/esm/fill/writeFill.mjs.map +1 -0
- package/dist/esm/getTargetDictionary.mjs +27 -48
- package/dist/esm/getTargetDictionary.mjs.map +1 -1
- package/dist/esm/index.mjs +15 -13
- package/dist/esm/listContentDeclaration.mjs +28 -43
- package/dist/esm/listContentDeclaration.mjs.map +1 -1
- package/dist/esm/liveSync.mjs +135 -187
- package/dist/esm/liveSync.mjs.map +1 -1
- package/dist/esm/pull.mjs +125 -178
- package/dist/esm/pull.mjs.map +1 -1
- package/dist/esm/push/pullLog.mjs +99 -125
- package/dist/esm/push/pullLog.mjs.map +1 -1
- package/dist/esm/push/push.mjs +149 -221
- package/dist/esm/push/push.mjs.map +1 -1
- package/dist/esm/pushConfig.mjs +14 -23
- package/dist/esm/pushConfig.mjs.map +1 -1
- package/dist/esm/pushLog.mjs +85 -109
- package/dist/esm/pushLog.mjs.map +1 -1
- package/dist/esm/reviewDoc.mjs +167 -264
- package/dist/esm/reviewDoc.mjs.map +1 -1
- package/dist/esm/test/index.mjs +47 -73
- package/dist/esm/test/index.mjs.map +1 -1
- package/dist/esm/test/listMissingTranslations.mjs +30 -41
- package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
- package/dist/esm/translateDoc.mjs +114 -193
- package/dist/esm/translateDoc.mjs.map +1 -1
- package/dist/esm/utils/calculateChunks.mjs +83 -91
- package/dist/esm/utils/calculateChunks.mjs.map +1 -1
- package/dist/esm/utils/checkAccess.mjs +28 -46
- package/dist/esm/utils/checkAccess.mjs.map +1 -1
- package/dist/esm/utils/checkFileModifiedRange.mjs +73 -65
- package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
- package/dist/esm/utils/checkLastUpdateTime.mjs +15 -6
- package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
- package/dist/esm/utils/chunkInference.mjs +24 -24
- package/dist/esm/utils/chunkInference.mjs.map +1 -1
- package/dist/esm/utils/fixChunkStartEndChars.mjs +22 -18
- package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
- package/dist/esm/utils/formatTimeDiff.mjs +16 -19
- package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
- package/dist/esm/utils/getIsFileUpdatedRecently.mjs +11 -8
- package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
- package/dist/esm/utils/getOutputFilePath.mjs +70 -62
- package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
- package/dist/esm/utils/getParentPackageJSON.mjs +16 -20
- package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
- package/dist/esm/utils/listSpecialChars.mjs +48 -49
- package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
- package/dist/esm/utils/mapChunksBetweenFiles.mjs +87 -107
- package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
- package/dist/esm/utils/reorderParagraphs.mjs +85 -93
- package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
- package/dist/esm/watch.mjs +17 -17
- package/dist/esm/watch.mjs.map +1 -1
- package/dist/types/IntlayerEventListener.d.ts +63 -59
- package/dist/types/IntlayerEventListener.d.ts.map +1 -1
- package/dist/types/build.d.ts +10 -7
- package/dist/types/build.d.ts.map +1 -1
- package/dist/types/cli.d.ts +13 -10
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/types/config.d.ts +7 -4
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/editor.d.ts +6 -4
- package/dist/types/editor.d.ts.map +1 -1
- package/dist/types/fill/fill.d.ts +20 -14
- package/dist/types/fill/fill.d.ts.map +1 -1
- package/dist/types/fill/formatAutoFillData.d.ts +10 -7
- package/dist/types/fill/formatAutoFillData.d.ts.map +1 -1
- package/dist/types/fill/formatAutoFilledFilePath.d.ts +6 -2
- package/dist/types/fill/formatAutoFilledFilePath.d.ts.map +1 -1
- package/dist/types/fill/formatFillData.d.ts +12 -0
- package/dist/types/fill/formatFillData.d.ts.map +1 -0
- package/dist/types/fill/groupLimiter.d.ts +15 -0
- package/dist/types/fill/groupLimiter.d.ts.map +1 -0
- package/dist/types/fill/index.d.ts +3 -3
- package/dist/types/fill/listTranslationsTasks.d.ts +15 -0
- package/dist/types/fill/listTranslationsTasks.d.ts.map +1 -0
- package/dist/types/fill/test-original-case.d.ts +1 -0
- package/dist/types/fill/translateDictionary.d.ts +19 -0
- package/dist/types/fill/translateDictionary.d.ts.map +1 -0
- package/dist/types/fill/writeAutoFill.d.ts +7 -0
- package/dist/types/fill/writeAutoFill.d.ts.map +1 -0
- package/dist/types/fill/writeFill.d.ts +7 -0
- package/dist/types/fill/writeFill.d.ts.map +1 -0
- package/dist/types/getTargetDictionary.d.ts +17 -13
- package/dist/types/getTargetDictionary.d.ts.map +1 -1
- package/dist/types/index.d.ts +15 -14
- package/dist/types/listContentDeclaration.d.ts +10 -7
- package/dist/types/listContentDeclaration.d.ts.map +1 -1
- package/dist/types/liveSync.d.ts +8 -3
- package/dist/types/liveSync.d.ts.map +1 -1
- package/dist/types/pull.d.ts +9 -6
- package/dist/types/pull.d.ts.map +1 -1
- package/dist/types/push/pullLog.d.ts +25 -21
- package/dist/types/push/pullLog.d.ts.map +1 -1
- package/dist/types/push/push.d.ts +13 -9
- package/dist/types/push/push.d.ts.map +1 -1
- package/dist/types/pushConfig.d.ts +7 -4
- package/dist/types/pushConfig.d.ts.map +1 -1
- package/dist/types/pushLog.d.ts +23 -20
- package/dist/types/pushLog.d.ts.map +1 -1
- package/dist/types/reviewDoc.d.ts +34 -17
- package/dist/types/reviewDoc.d.ts.map +1 -1
- package/dist/types/test/index.d.ts +9 -5
- package/dist/types/test/index.d.ts.map +1 -1
- package/dist/types/test/listMissingTranslations.d.ts +14 -10
- package/dist/types/test/listMissingTranslations.d.ts.map +1 -1
- package/dist/types/translateDoc.d.ts +34 -17
- package/dist/types/translateDoc.d.ts.map +1 -1
- package/dist/types/utils/calculateChunks.d.ts +10 -7
- package/dist/types/utils/calculateChunks.d.ts.map +1 -1
- package/dist/types/utils/checkAccess.d.ts +8 -4
- package/dist/types/utils/checkAccess.d.ts.map +1 -1
- package/dist/types/utils/checkFileModifiedRange.d.ts +8 -6
- package/dist/types/utils/checkFileModifiedRange.d.ts.map +1 -1
- package/dist/types/utils/checkLastUpdateTime.d.ts +4 -1
- package/dist/types/utils/checkLastUpdateTime.d.ts.map +1 -1
- package/dist/types/utils/chunkInference.d.ts +9 -6
- package/dist/types/utils/chunkInference.d.ts.map +1 -1
- package/dist/types/utils/fixChunkStartEndChars.d.ts +4 -1
- package/dist/types/utils/fixChunkStartEndChars.d.ts.map +1 -1
- package/dist/types/utils/formatTimeDiff.d.ts +4 -1
- package/dist/types/utils/formatTimeDiff.d.ts.map +1 -1
- package/dist/types/utils/getIsFileUpdatedRecently.d.ts +4 -1
- package/dist/types/utils/getIsFileUpdatedRecently.d.ts.map +1 -1
- package/dist/types/utils/getOutputFilePath.d.ts +7 -2
- package/dist/types/utils/getOutputFilePath.d.ts.map +1 -1
- package/dist/types/utils/getParentPackageJSON.d.ts +30 -28
- package/dist/types/utils/getParentPackageJSON.d.ts.map +1 -1
- package/dist/types/utils/listSpecialChars.d.ts +9 -7
- package/dist/types/utils/listSpecialChars.d.ts.map +1 -1
- package/dist/types/utils/mapChunksBetweenFiles.d.ts +10 -6
- package/dist/types/utils/mapChunksBetweenFiles.d.ts.map +1 -1
- package/dist/types/utils/reorderParagraphs.d.ts +4 -1
- package/dist/types/utils/reorderParagraphs.d.ts.map +1 -1
- package/dist/types/watch.d.ts +9 -6
- package/dist/types/watch.d.ts.map +1 -1
- package/package.json +42 -47
- package/LICENSE +0 -202
- package/dist/cjs/fill/autoFill.cjs +0 -105
- package/dist/cjs/fill/autoFill.cjs.map +0 -1
- package/dist/cjs/fill/index.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/utils/getChunk.cjs +0 -77
- package/dist/cjs/utils/getChunk.cjs.map +0 -1
- package/dist/cjs/utils/splitTextByLine.cjs +0 -35
- package/dist/cjs/utils/splitTextByLine.cjs.map +0 -1
- package/dist/esm/fill/autoFill.mjs +0 -92
- package/dist/esm/fill/autoFill.mjs.map +0 -1
- package/dist/esm/fill/index.mjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/prompts/REVIEW_PROMPT.md +0 -37
- package/dist/esm/prompts/TRANSLATE_PROMPT.md +0 -38
- package/dist/esm/utils/calculrateChunkTest.md +0 -9
- package/dist/esm/utils/getChunk.mjs +0 -53
- package/dist/esm/utils/getChunk.mjs.map +0 -1
- package/dist/esm/utils/splitTextByLine.mjs +0 -11
- package/dist/esm/utils/splitTextByLine.mjs.map +0 -1
- package/dist/types/fill/autoFill.d.ts +0 -4
- package/dist/types/fill/autoFill.d.ts.map +0 -1
- package/dist/types/fill/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/utils/getChunk.d.ts +0 -9
- package/dist/types/utils/getChunk.d.ts.map +0 -1
- package/dist/types/utils/splitTextByLine.d.ts +0 -2
- package/dist/types/utils/splitTextByLine.d.ts.map +0 -1
- /package/dist/{cjs → assets}/prompts/REVIEW_PROMPT.md +0 -0
- /package/dist/{cjs → assets}/prompts/TRANSLATE_PROMPT.md +0 -0
- /package/dist/{cjs/utils/calculrateChunkTest.md → assets/utils/_calculateChunkTest.md} +0 -0
package/dist/esm/fill/fill.mjs
CHANGED
|
@@ -1,304 +1,72 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
34
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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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AA,UACT;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,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;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AS,iBAAiB,SAAS,CAAC,IACrG,EAAE,OAAO,QAAQ,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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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 {
|
|
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,
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
|
|
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
|