@intlayer/cli 6.1.6 → 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/cjs/pull.cjs
CHANGED
|
@@ -1,198 +1,135 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
__export(pull_exports, {
|
|
21
|
-
pull: () => pull
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(pull_exports);
|
|
24
|
-
var import_api = require("@intlayer/api");
|
|
25
|
-
var import_chokidar = require("@intlayer/chokidar");
|
|
26
|
-
var import_config = require("@intlayer/config");
|
|
27
|
-
var import_fs = require("fs");
|
|
28
|
-
var import_path = require("path");
|
|
29
|
-
var import_pullLog = require('./push/pullLog.cjs');
|
|
30
|
-
var import_checkAccess = require('./utils/checkAccess.cjs');
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_utils_checkAccess = require('./utils/checkAccess.cjs');
|
|
3
|
+
const require_push_pullLog = require('./push/pullLog.cjs');
|
|
4
|
+
let __intlayer_api = require("@intlayer/api");
|
|
5
|
+
__intlayer_api = require_rolldown_runtime.__toESM(__intlayer_api);
|
|
6
|
+
let __intlayer_chokidar = require("@intlayer/chokidar");
|
|
7
|
+
__intlayer_chokidar = require_rolldown_runtime.__toESM(__intlayer_chokidar);
|
|
8
|
+
let __intlayer_config = require("@intlayer/config");
|
|
9
|
+
__intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
|
|
10
|
+
let node_path = require("node:path");
|
|
11
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
12
|
+
let node_fs = require("node:fs");
|
|
13
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs);
|
|
14
|
+
|
|
15
|
+
//#region src/pull.ts
|
|
16
|
+
/**
|
|
17
|
+
* Fetch distant dictionaries and write them locally,
|
|
18
|
+
* with progress indicators and concurrency control.
|
|
19
|
+
*/
|
|
31
20
|
const pull = async (options) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
logger.finish();
|
|
143
|
-
const iconFor = (status) => {
|
|
144
|
-
switch (status) {
|
|
145
|
-
case "fetched":
|
|
146
|
-
case "imported":
|
|
147
|
-
case "updated":
|
|
148
|
-
case "up-to-date":
|
|
149
|
-
case "reimported in JSON":
|
|
150
|
-
case "new content file":
|
|
151
|
-
return "\u2714";
|
|
152
|
-
case "error":
|
|
153
|
-
return "\u2716";
|
|
154
|
-
default:
|
|
155
|
-
return "\u23F2";
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
const colorFor = (status) => {
|
|
159
|
-
switch (status) {
|
|
160
|
-
case "fetched":
|
|
161
|
-
case "imported":
|
|
162
|
-
case "updated":
|
|
163
|
-
case "up-to-date":
|
|
164
|
-
return import_config.ANSIColors.GREEN;
|
|
165
|
-
case "reimported in JSON":
|
|
166
|
-
case "new content file":
|
|
167
|
-
return import_config.ANSIColors.YELLOW;
|
|
168
|
-
case "error":
|
|
169
|
-
return import_config.ANSIColors.RED;
|
|
170
|
-
default:
|
|
171
|
-
return import_config.ANSIColors.BLUE;
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
for (const s of dictionariesStatuses) {
|
|
175
|
-
const icon = iconFor(s.status);
|
|
176
|
-
const color = colorFor(s.status);
|
|
177
|
-
appLogger(
|
|
178
|
-
` - ${s.dictionaryKey} ${import_config.ANSIColors.GREY}[${color}${icon} ${s.status}${import_config.ANSIColors.GREY}]${import_config.ANSIColors.RESET}`
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
for (const statusObj of dictionariesStatuses) {
|
|
182
|
-
if (statusObj.errorMessage) {
|
|
183
|
-
appLogger(statusObj.errorMessage, {
|
|
184
|
-
level: "error"
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
} catch (error) {
|
|
189
|
-
appLogger(error, {
|
|
190
|
-
level: "error"
|
|
191
|
-
});
|
|
192
|
-
}
|
|
21
|
+
const appLogger = (0, __intlayer_config.getAppLogger)(options?.configOptions?.override);
|
|
22
|
+
try {
|
|
23
|
+
const config = (0, __intlayer_config.getConfiguration)(options?.configOptions);
|
|
24
|
+
if (!await require_utils_checkAccess.checkCMSAuth(config)) return;
|
|
25
|
+
const intlayerAPI = (0, __intlayer_api.getIntlayerAPIProxy)(void 0, config);
|
|
26
|
+
const getDictionariesUpdateTimestampResult = await intlayerAPI.dictionary.getDictionariesUpdateTimestamp();
|
|
27
|
+
if (!getDictionariesUpdateTimestampResult.data) throw new Error("No distant dictionaries found");
|
|
28
|
+
let distantDictionariesUpdateTimeStamp = getDictionariesUpdateTimestampResult.data;
|
|
29
|
+
if (options?.dictionaries) distantDictionariesUpdateTimeStamp = Object.fromEntries(Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) => options.dictionaries?.includes(key)));
|
|
30
|
+
const remoteDictionariesPath = (0, node_path.join)(config.content.mainDir, "remote_dictionaries.cjs");
|
|
31
|
+
const remoteDictionariesRecord = (0, node_fs.existsSync)(remoteDictionariesPath) ? (0, __intlayer_config.ESMxCJSRequire)(remoteDictionariesPath) : {};
|
|
32
|
+
const entries = Object.entries(distantDictionariesUpdateTimeStamp);
|
|
33
|
+
const keysToFetch = entries.filter(([key, remoteUpdatedAt]) => {
|
|
34
|
+
if (!remoteUpdatedAt) return true;
|
|
35
|
+
const local = remoteDictionariesRecord[key];
|
|
36
|
+
if (!local) return true;
|
|
37
|
+
const localUpdatedAtRaw = local?.updatedAt;
|
|
38
|
+
const localUpdatedAt = typeof localUpdatedAtRaw === "number" ? localUpdatedAtRaw : localUpdatedAtRaw ? new Date(localUpdatedAtRaw).getTime() : void 0;
|
|
39
|
+
if (typeof localUpdatedAt !== "number") return true;
|
|
40
|
+
return remoteUpdatedAt > localUpdatedAt;
|
|
41
|
+
}).map(([key]) => key);
|
|
42
|
+
const cachedKeys = entries.filter(([key, remoteUpdatedAt]) => {
|
|
43
|
+
const localUpdatedAtRaw = remoteDictionariesRecord[key]?.updatedAt;
|
|
44
|
+
const localUpdatedAt = typeof localUpdatedAtRaw === "number" ? localUpdatedAtRaw : localUpdatedAtRaw ? new Date(localUpdatedAtRaw).getTime() : void 0;
|
|
45
|
+
return typeof localUpdatedAt === "number" && typeof remoteUpdatedAt === "number" && localUpdatedAt >= remoteUpdatedAt;
|
|
46
|
+
}).map(([key]) => key);
|
|
47
|
+
if (entries.length === 0) {
|
|
48
|
+
appLogger("No dictionaries to fetch", { level: "error" });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
appLogger("Fetching dictionaries:");
|
|
52
|
+
const dictionariesStatuses = [...cachedKeys.map((dictionaryKey) => ({
|
|
53
|
+
dictionaryKey,
|
|
54
|
+
status: "imported"
|
|
55
|
+
})), ...keysToFetch.map((dictionaryKey) => ({
|
|
56
|
+
dictionaryKey,
|
|
57
|
+
status: "pending"
|
|
58
|
+
}))];
|
|
59
|
+
const logger = new require_push_pullLog.PullLogger();
|
|
60
|
+
logger.update(dictionariesStatuses.map((s) => ({
|
|
61
|
+
dictionaryKey: s.dictionaryKey,
|
|
62
|
+
status: s.status
|
|
63
|
+
})));
|
|
64
|
+
const successfullyFetchedDictionaries = [];
|
|
65
|
+
const processDictionary = async (statusObj) => {
|
|
66
|
+
const isCached = statusObj.status === "imported" || statusObj.status === "up-to-date";
|
|
67
|
+
if (!isCached) {
|
|
68
|
+
statusObj.status = "fetching";
|
|
69
|
+
logger.update([{
|
|
70
|
+
dictionaryKey: statusObj.dictionaryKey,
|
|
71
|
+
status: "fetching"
|
|
72
|
+
}]);
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
let sourceDictionary;
|
|
76
|
+
if (isCached) sourceDictionary = remoteDictionariesRecord[statusObj.dictionaryKey];
|
|
77
|
+
if (!sourceDictionary) sourceDictionary = (await intlayerAPI.dictionary.getDictionary(statusObj.dictionaryKey)).data;
|
|
78
|
+
if (!sourceDictionary) throw new Error(`Dictionary ${statusObj.dictionaryKey} not found on remote`);
|
|
79
|
+
const { status } = await (0, __intlayer_chokidar.writeContentDeclaration)(sourceDictionary, config, options);
|
|
80
|
+
statusObj.status = status;
|
|
81
|
+
logger.update([{
|
|
82
|
+
dictionaryKey: statusObj.dictionaryKey,
|
|
83
|
+
status
|
|
84
|
+
}]);
|
|
85
|
+
successfullyFetchedDictionaries.push(sourceDictionary);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
statusObj.status = "error";
|
|
88
|
+
statusObj.error = error;
|
|
89
|
+
statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;
|
|
90
|
+
logger.update([{
|
|
91
|
+
dictionaryKey: statusObj.dictionaryKey,
|
|
92
|
+
status: "error"
|
|
93
|
+
}]);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
await (0, __intlayer_chokidar.parallelize)(dictionariesStatuses, processDictionary, 5);
|
|
97
|
+
logger.finish();
|
|
98
|
+
const iconFor = (status) => {
|
|
99
|
+
switch (status) {
|
|
100
|
+
case "fetched":
|
|
101
|
+
case "imported":
|
|
102
|
+
case "updated":
|
|
103
|
+
case "up-to-date":
|
|
104
|
+
case "reimported in JSON":
|
|
105
|
+
case "new content file": return "✔";
|
|
106
|
+
case "error": return "✖";
|
|
107
|
+
default: return "⏲";
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const colorFor = (status) => {
|
|
111
|
+
switch (status) {
|
|
112
|
+
case "fetched":
|
|
113
|
+
case "imported":
|
|
114
|
+
case "updated":
|
|
115
|
+
case "up-to-date": return __intlayer_config.ANSIColors.GREEN;
|
|
116
|
+
case "reimported in JSON":
|
|
117
|
+
case "new content file": return __intlayer_config.ANSIColors.YELLOW;
|
|
118
|
+
case "error": return __intlayer_config.ANSIColors.RED;
|
|
119
|
+
default: return __intlayer_config.ANSIColors.BLUE;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
for (const s of dictionariesStatuses) {
|
|
123
|
+
const icon = iconFor(s.status);
|
|
124
|
+
const color = colorFor(s.status);
|
|
125
|
+
appLogger(` - ${s.dictionaryKey} ${__intlayer_config.ANSIColors.GREY}[${color}${icon} ${s.status}${__intlayer_config.ANSIColors.GREY}]${__intlayer_config.ANSIColors.RESET}`);
|
|
126
|
+
}
|
|
127
|
+
for (const statusObj of dictionariesStatuses) if (statusObj.errorMessage) appLogger(statusObj.errorMessage, { level: "error" });
|
|
128
|
+
} catch (error) {
|
|
129
|
+
appLogger(error, { level: "error" });
|
|
130
|
+
}
|
|
193
131
|
};
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
});
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
exports.pull = pull;
|
|
198
135
|
//# sourceMappingURL=pull.cjs.map
|
package/dist/cjs/pull.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/pull.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n parallelize,\n writeContentDeclaration,\n type DictionaryStatus,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n ESMxCJSRequire,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { existsSync } from 'fs';\nimport { join } from 'path';\nimport { PullLogger, type PullStatus } from './push/pullLog';\nimport { checkCMSAuth } from './utils/checkAccess';\n\ntype PullOptions = {\n dictionaries?: string[];\n newDictionariesPath?: string;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionaryKey: string;\n status: DictionaryStatus | 'pending' | 'fetching' | 'error';\n error?: Error;\n errorMessage?: string;\n};\n\n/**\n * Fetch distant dictionaries and write them locally,\n * with progress indicators and concurrency control.\n */\nexport const pull = async (options?: PullOptions): Promise<void> => {\n const appLogger = getAppLogger(options?.configOptions?.override, {\n config: {\n prefix: '',\n },\n });\n\n try {\n const config = getConfiguration(options?.configOptions);\n\n const hasCMSAuth = await checkCMSAuth(config);\n\n if (!hasCMSAuth) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n // Get remote update timestamps map\n const getDictionariesUpdateTimestampResult =\n await intlayerAPI.dictionary.getDictionariesUpdateTimestamp();\n\n if (!getDictionariesUpdateTimestampResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n let distantDictionariesUpdateTimeStamp: Record<string, number> =\n getDictionariesUpdateTimestampResult.data;\n\n // Optional filtering by requested dictionaries\n if (options?.dictionaries) {\n distantDictionariesUpdateTimeStamp = Object.fromEntries(\n Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) =>\n options.dictionaries!.includes(key)\n )\n );\n }\n\n // Load local cached remote dictionaries (if any)\n const remoteDictionariesPath = join(\n config.content.mainDir,\n 'remote_dictionaries.cjs'\n );\n const remoteDictionariesRecord: Record<string, any> = existsSync(\n remoteDictionariesPath\n )\n ? (ESMxCJSRequire(remoteDictionariesPath) as any)\n : {};\n\n // Determine which keys need fetching by comparing updatedAt with local cache\n const entries = Object.entries(distantDictionariesUpdateTimeStamp);\n const keysToFetch = entries\n .filter(([key, remoteUpdatedAt]) => {\n if (!remoteUpdatedAt) return true;\n const local = (remoteDictionariesRecord as any)[key];\n if (!local) return true;\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n if (typeof localUpdatedAt !== 'number') return true;\n return remoteUpdatedAt > localUpdatedAt;\n })\n .map(([key]) => key);\n\n const cachedKeys = entries\n .filter(([key, remoteUpdatedAt]) => {\n const local = (remoteDictionariesRecord as any)[key];\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n return (\n typeof localUpdatedAt === 'number' &&\n typeof remoteUpdatedAt === 'number' &&\n localUpdatedAt >= remoteUpdatedAt\n );\n })\n .map(([key]) => key);\n\n // Check if dictionaries list is empty\n if (entries.length === 0) {\n appLogger('No dictionaries to fetch', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Fetching dictionaries:');\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = [\n ...cachedKeys.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'imported' as DictionaryStatus,\n })),\n ...keysToFetch.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'pending' as const,\n })),\n ];\n\n // Initialize aggregated logger\n const logger = new PullLogger();\n logger.update(\n dictionariesStatuses.map<PullStatus>((s) => ({\n dictionaryKey: s.dictionaryKey,\n status: s.status,\n }))\n );\n\n const successfullyFetchedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n const isCached =\n statusObj.status === 'imported' || statusObj.status === 'up-to-date';\n\n if (!isCached) {\n statusObj.status = 'fetching';\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'fetching' },\n ]);\n }\n\n try {\n let sourceDictionary: Dictionary | undefined;\n\n if (isCached) {\n sourceDictionary = remoteDictionariesRecord[\n statusObj.dictionaryKey\n ] as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n // Fetch the dictionary\n const getDictionaryResult =\n await intlayerAPI.dictionary.getDictionary(statusObj.dictionaryKey);\n\n sourceDictionary = getDictionaryResult.data as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n throw new Error(\n `Dictionary ${statusObj.dictionaryKey} not found on remote`\n );\n }\n\n // Now, write the dictionary to local file\n const { status } = await writeContentDeclaration(\n sourceDictionary,\n config,\n options?.newDictionariesPath\n );\n\n statusObj.status = status;\n logger.update([{ dictionaryKey: statusObj.dictionaryKey, status }]);\n\n successfullyFetchedDictionaries.push(sourceDictionary);\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'error' },\n ]);\n }\n };\n\n // Process dictionaries in parallel with concurrency limit\n await parallelize(dictionariesStatuses, processDictionary, 5);\n\n // Stop the logger and render final state\n logger.finish();\n\n // Per-dictionary summary\n const iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n case 'reimported in JSON':\n case 'new content file':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n };\n\n const colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n return ANSIColors.GREEN;\n case 'reimported in JSON':\n case 'new content file':\n return ANSIColors.YELLOW;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n };\n\n for (const s of dictionariesStatuses) {\n const icon = iconFor(s.status);\n const color = colorFor(s.status);\n appLogger(\n ` - ${s.dictionaryKey} ${ANSIColors.GREY}[${color}${icon} ${s.status}${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoC;AACpC,sBAIO;AACP,oBAMO;AAEP,gBAA2B;AAC3B,kBAAqB;AACrB,qBAA4C;AAC5C,yBAA6B;AAmBtB,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MAAM;AAC/B;AAAA,QACE,MAAM,EAAE,aAAa,IAAI,yBAAW,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,EAAE,MAAM,GAAG,yBAAW,IAAI,IAAI,yBAAW,KAAK;AAAA,MAC5G;AAAA,IACF;AAGA,eAAW,aAAa,sBAAsB;AAC5C,UAAI,UAAU,cAAc;AAC1B,kBAAU,UAAU,cAAc;AAAA,UAChC,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,cAAU,OAAO;AAAA,MACf,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
1
|
+
{"version":3,"file":"pull.cjs","names":["checkCMSAuth","distantDictionariesUpdateTimeStamp: Record<string, number>","remoteDictionariesRecord: Record<string, any>","dictionariesStatuses: DictionariesStatus[]","PullLogger","successfullyFetchedDictionaries: Dictionary[]","sourceDictionary: Dictionary | undefined","ANSIColors"],"sources":["../../src/pull.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n type DictionaryStatus,\n parallelize,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n ESMxCJSRequire,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/types';\nimport { PullLogger, type PullStatus } from './push/pullLog';\nimport { checkCMSAuth } from './utils/checkAccess';\n\ntype PullOptions = {\n dictionaries?: string[];\n newDictionariesPath?: string;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionaryKey: string;\n status: DictionaryStatus | 'pending' | 'fetching' | 'error';\n error?: Error;\n errorMessage?: string;\n};\n\n/**\n * Fetch distant dictionaries and write them locally,\n * with progress indicators and concurrency control.\n */\nexport const pull = async (options?: PullOptions): Promise<void> => {\n const appLogger = getAppLogger(options?.configOptions?.override);\n\n try {\n const config = getConfiguration(options?.configOptions);\n\n const hasCMSAuth = await checkCMSAuth(config);\n\n if (!hasCMSAuth) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n // Get remote update timestamps map\n const getDictionariesUpdateTimestampResult =\n await intlayerAPI.dictionary.getDictionariesUpdateTimestamp();\n\n if (!getDictionariesUpdateTimestampResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n let distantDictionariesUpdateTimeStamp: Record<string, number> =\n getDictionariesUpdateTimestampResult.data;\n\n // Optional filtering by requested dictionaries\n if (options?.dictionaries) {\n distantDictionariesUpdateTimeStamp = Object.fromEntries(\n Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) =>\n options.dictionaries?.includes(key)\n )\n );\n }\n\n // Load local cached remote dictionaries (if any)\n const remoteDictionariesPath = join(\n config.content.mainDir,\n 'remote_dictionaries.cjs'\n );\n const remoteDictionariesRecord: Record<string, any> = existsSync(\n remoteDictionariesPath\n )\n ? (ESMxCJSRequire(remoteDictionariesPath) as any)\n : {};\n\n // Determine which keys need fetching by comparing updatedAt with local cache\n const entries = Object.entries(distantDictionariesUpdateTimeStamp);\n const keysToFetch = entries\n .filter(([key, remoteUpdatedAt]) => {\n if (!remoteUpdatedAt) return true;\n const local = (remoteDictionariesRecord as any)[key];\n if (!local) return true;\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n if (typeof localUpdatedAt !== 'number') return true;\n return remoteUpdatedAt > localUpdatedAt;\n })\n .map(([key]) => key);\n\n const cachedKeys = entries\n .filter(([key, remoteUpdatedAt]) => {\n const local = (remoteDictionariesRecord as any)[key];\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n return (\n typeof localUpdatedAt === 'number' &&\n typeof remoteUpdatedAt === 'number' &&\n localUpdatedAt >= remoteUpdatedAt\n );\n })\n .map(([key]) => key);\n\n // Check if dictionaries list is empty\n if (entries.length === 0) {\n appLogger('No dictionaries to fetch', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Fetching dictionaries:');\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = [\n ...cachedKeys.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'imported' as DictionaryStatus,\n })),\n ...keysToFetch.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'pending' as const,\n })),\n ];\n\n // Initialize aggregated logger\n const logger = new PullLogger();\n logger.update(\n dictionariesStatuses.map<PullStatus>((s) => ({\n dictionaryKey: s.dictionaryKey,\n status: s.status,\n }))\n );\n\n const successfullyFetchedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n const isCached =\n statusObj.status === 'imported' || statusObj.status === 'up-to-date';\n\n if (!isCached) {\n statusObj.status = 'fetching';\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'fetching' },\n ]);\n }\n\n try {\n let sourceDictionary: Dictionary | undefined;\n\n if (isCached) {\n sourceDictionary = remoteDictionariesRecord[\n statusObj.dictionaryKey\n ] as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n // Fetch the dictionary\n const getDictionaryResult =\n await intlayerAPI.dictionary.getDictionary(statusObj.dictionaryKey);\n\n sourceDictionary = getDictionaryResult.data as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n throw new Error(\n `Dictionary ${statusObj.dictionaryKey} not found on remote`\n );\n }\n\n // Now, write the dictionary to local file\n const { status } = await writeContentDeclaration(\n sourceDictionary,\n config,\n options\n );\n\n statusObj.status = status;\n logger.update([{ dictionaryKey: statusObj.dictionaryKey, status }]);\n\n successfullyFetchedDictionaries.push(sourceDictionary);\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'error' },\n ]);\n }\n };\n\n // Process dictionaries in parallel with concurrency limit\n await parallelize(dictionariesStatuses, processDictionary, 5);\n\n // Stop the logger and render final state\n logger.finish();\n\n // Per-dictionary summary\n const iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n case 'reimported in JSON':\n case 'new content file':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n };\n\n const colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n return ANSIColors.GREEN;\n case 'reimported in JSON':\n case 'new content file':\n return ANSIColors.YELLOW;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n };\n\n for (const s of dictionariesStatuses) {\n const icon = iconFor(s.status);\n const color = colorFor(s.status);\n appLogger(\n ` - ${s.dictionaryKey} ${ANSIColors.GREY}[${color}${icon} ${s.status}${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoCA,MAAa,OAAO,OAAO,YAAyC;CAClE,MAAM,gDAAyB,SAAS,eAAe,SAAS;AAEhE,KAAI;EACF,MAAM,iDAA0B,SAAS,cAAc;AAIvD,MAAI,CAFe,MAAMA,uCAAa,OAAO,CAE5B;EAEjB,MAAM,sDAAkC,QAAW,OAAO;EAG1D,MAAM,uCACJ,MAAM,YAAY,WAAW,gCAAgC;AAE/D,MAAI,CAAC,q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OA,6BAAW;IACpB,KAAK,QACH,QAAOA,6BAAW;IACpB,QACE,QAAOA,6BAAW;;;AAIxB,OAAK,MAAM,KAAK,sBAAsB;GACpC,MAAM,OAAO,QAAQ,EAAE,OAAO;GAC9B,MAAM,QAAQ,SAAS,EAAE,OAAO;AAChC,aACE,MAAM,EAAE,cAAc,GAAGA,6BAAW,KAAK,GAAG,QAAQ,KAAK,GAAG,EAAE,SAASA,6BAAW,KAAK,GAAGA,6BAAW,QACtG;;AAIH,OAAK,MAAM,aAAa,qBACtB,KAAI,UAAU,aACZ,WAAU,UAAU,cAAc,EAChC,OAAO,SACR,CAAC;UAGC,OAAO;AACd,YAAU,OAAO,EACf,OAAO,SACR,CAAC"}
|
|
@@ -1,146 +1,103 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __intlayer_config = require("@intlayer/config");
|
|
3
|
+
__intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
|
|
4
|
+
|
|
5
|
+
//#region src/push/pullLog.ts
|
|
6
|
+
var PullLogger = class {
|
|
7
|
+
statuses = [];
|
|
8
|
+
spinnerTimer = null;
|
|
9
|
+
spinnerIndex = 0;
|
|
10
|
+
renderedLines = 0;
|
|
11
|
+
spinnerFrames = __intlayer_config.spinnerFrames;
|
|
12
|
+
isFinished = false;
|
|
13
|
+
prefix;
|
|
14
|
+
lastRenderedState = "";
|
|
15
|
+
constructor() {
|
|
16
|
+
this.prefix = (0, __intlayer_config.getConfiguration)().log.prefix;
|
|
17
|
+
}
|
|
18
|
+
update(newStatuses) {
|
|
19
|
+
if (this.isFinished) return;
|
|
20
|
+
for (const status of newStatuses) {
|
|
21
|
+
const index = this.statuses.findIndex((s) => s.dictionaryKey === status.dictionaryKey);
|
|
22
|
+
if (index >= 0) this.statuses[index] = status;
|
|
23
|
+
else this.statuses.push(status);
|
|
24
|
+
}
|
|
25
|
+
this.startSpinner();
|
|
26
|
+
this.render();
|
|
27
|
+
}
|
|
28
|
+
finish() {
|
|
29
|
+
this.isFinished = true;
|
|
30
|
+
this.stopSpinner();
|
|
31
|
+
this.render();
|
|
32
|
+
}
|
|
33
|
+
startSpinner() {
|
|
34
|
+
if (this.spinnerTimer || this.isFinished) return;
|
|
35
|
+
this.spinnerTimer = setInterval(() => {
|
|
36
|
+
this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;
|
|
37
|
+
this.render();
|
|
38
|
+
}, 100);
|
|
39
|
+
}
|
|
40
|
+
stopSpinner() {
|
|
41
|
+
if (!this.spinnerTimer) return;
|
|
42
|
+
clearInterval(this.spinnerTimer);
|
|
43
|
+
this.spinnerTimer = null;
|
|
44
|
+
}
|
|
45
|
+
render() {
|
|
46
|
+
const { total, done, success, errors } = this.computeProgress();
|
|
47
|
+
const frame = this.spinnerFrames[this.spinnerIndex];
|
|
48
|
+
const lines = [];
|
|
49
|
+
const isDone = done === total;
|
|
50
|
+
const progressLabel = `dictionaries: ${done}/${total}`;
|
|
51
|
+
const details = [];
|
|
52
|
+
if (success > 0) details.push(`ok: ${success}`);
|
|
53
|
+
if (errors > 0) details.push((0, __intlayer_config.colorize)(`errors: ${errors}`, __intlayer_config.ANSIColors.RED));
|
|
54
|
+
const suffix = details.length > 0 ? ` (${details.join(", ")})` : "";
|
|
55
|
+
if (isDone) lines.push(`${this.prefix} ${(0, __intlayer_config.colorize)("✔", __intlayer_config.ANSIColors.GREEN)} fetched ${progressLabel}${suffix}`);
|
|
56
|
+
else lines.push(`${this.prefix} ${(0, __intlayer_config.colorize)(frame, __intlayer_config.ANSIColors.BLUE)} fetching ${progressLabel}${suffix}`);
|
|
57
|
+
const currentState = lines.join("\n");
|
|
58
|
+
if (currentState === this.lastRenderedState) return;
|
|
59
|
+
this.lastRenderedState = currentState;
|
|
60
|
+
if (this.renderedLines > 0) process.stdout.write(`\x1b[${this.renderedLines}F`);
|
|
61
|
+
const totalLinesToClear = Math.max(this.renderedLines, lines.length);
|
|
62
|
+
for (let i = 0; i < totalLinesToClear; i++) {
|
|
63
|
+
process.stdout.write("\x1B[2K");
|
|
64
|
+
const line = lines[i];
|
|
65
|
+
if (line !== void 0) process.stdout.write(line);
|
|
66
|
+
process.stdout.write("\n");
|
|
67
|
+
}
|
|
68
|
+
this.renderedLines = lines.length;
|
|
69
|
+
}
|
|
70
|
+
computeProgress() {
|
|
71
|
+
const keys = new Set(this.statuses.map((s) => s.dictionaryKey));
|
|
72
|
+
const doneSet = new Set([
|
|
73
|
+
"fetched",
|
|
74
|
+
"imported",
|
|
75
|
+
"updated",
|
|
76
|
+
"up-to-date",
|
|
77
|
+
"reimported in JSON",
|
|
78
|
+
"new content file",
|
|
79
|
+
"error"
|
|
80
|
+
]);
|
|
81
|
+
const successesSet = new Set([
|
|
82
|
+
"fetched",
|
|
83
|
+
"imported",
|
|
84
|
+
"updated",
|
|
85
|
+
"up-to-date",
|
|
86
|
+
"reimported in JSON",
|
|
87
|
+
"new content file"
|
|
88
|
+
]);
|
|
89
|
+
const done = this.statuses.filter((s) => doneSet.has(s.status)).length;
|
|
90
|
+
const success = this.statuses.filter((s) => successesSet.has(s.status)).length;
|
|
91
|
+
const errors = this.statuses.filter((s) => s.status === "error").length;
|
|
92
|
+
return {
|
|
93
|
+
total: keys.size,
|
|
94
|
+
done,
|
|
95
|
+
success,
|
|
96
|
+
errors
|
|
97
|
+
};
|
|
98
|
+
}
|
|
9
99
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var pullLog_exports = {};
|
|
20
|
-
__export(pullLog_exports, {
|
|
21
|
-
PullLogger: () => PullLogger
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(pullLog_exports);
|
|
24
|
-
var import_config = require("@intlayer/config");
|
|
25
|
-
class PullLogger {
|
|
26
|
-
statuses = [];
|
|
27
|
-
spinnerTimer = null;
|
|
28
|
-
spinnerIndex = 0;
|
|
29
|
-
renderedLines = 0;
|
|
30
|
-
spinnerFrames = import_config.spinnerFrames;
|
|
31
|
-
isFinished = false;
|
|
32
|
-
prefix;
|
|
33
|
-
lastRenderedState = "";
|
|
34
|
-
constructor() {
|
|
35
|
-
const configuration = (0, import_config.getConfiguration)();
|
|
36
|
-
this.prefix = configuration.log.prefix;
|
|
37
|
-
}
|
|
38
|
-
update(newStatuses) {
|
|
39
|
-
if (this.isFinished) return;
|
|
40
|
-
for (const status of newStatuses) {
|
|
41
|
-
const index = this.statuses.findIndex(
|
|
42
|
-
(s) => s.dictionaryKey === status.dictionaryKey
|
|
43
|
-
);
|
|
44
|
-
if (index >= 0) {
|
|
45
|
-
this.statuses[index] = status;
|
|
46
|
-
} else {
|
|
47
|
-
this.statuses.push(status);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
this.startSpinner();
|
|
51
|
-
this.render();
|
|
52
|
-
}
|
|
53
|
-
finish() {
|
|
54
|
-
this.isFinished = true;
|
|
55
|
-
this.stopSpinner();
|
|
56
|
-
this.render();
|
|
57
|
-
}
|
|
58
|
-
startSpinner() {
|
|
59
|
-
if (this.spinnerTimer || this.isFinished) return;
|
|
60
|
-
this.spinnerTimer = setInterval(() => {
|
|
61
|
-
this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;
|
|
62
|
-
this.render();
|
|
63
|
-
}, 100);
|
|
64
|
-
}
|
|
65
|
-
stopSpinner() {
|
|
66
|
-
if (!this.spinnerTimer) return;
|
|
67
|
-
clearInterval(this.spinnerTimer);
|
|
68
|
-
this.spinnerTimer = null;
|
|
69
|
-
}
|
|
70
|
-
render() {
|
|
71
|
-
const { total, done, success, errors } = this.computeProgress();
|
|
72
|
-
const frame = this.spinnerFrames[this.spinnerIndex];
|
|
73
|
-
const lines = [];
|
|
74
|
-
const isDone = done === total;
|
|
75
|
-
const progressLabel = `dictionaries: ${done}/${total}`;
|
|
76
|
-
const details = [];
|
|
77
|
-
if (success > 0) details.push(`ok: ${success}`);
|
|
78
|
-
if (errors > 0) details.push((0, import_config.colorize)(`errors: ${errors}`, import_config.ANSIColors.RED));
|
|
79
|
-
const suffix = details.length > 0 ? ` (${details.join(", ")})` : "";
|
|
80
|
-
if (isDone) {
|
|
81
|
-
lines.push(
|
|
82
|
-
`${this.prefix} ${(0, import_config.colorize)("\u2714", import_config.ANSIColors.GREEN)} fetched ${progressLabel}${suffix}`
|
|
83
|
-
);
|
|
84
|
-
} else {
|
|
85
|
-
lines.push(
|
|
86
|
-
`${this.prefix} ${(0, import_config.colorize)(frame, import_config.ANSIColors.BLUE)} fetching ${progressLabel}${suffix}`
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
const currentState = lines.join("\n");
|
|
90
|
-
if (currentState === this.lastRenderedState) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
this.lastRenderedState = currentState;
|
|
94
|
-
if (this.renderedLines > 0) {
|
|
95
|
-
process.stdout.write(`\x1B[${this.renderedLines}F`);
|
|
96
|
-
}
|
|
97
|
-
const totalLinesToClear = Math.max(this.renderedLines, lines.length);
|
|
98
|
-
for (let i = 0; i < totalLinesToClear; i++) {
|
|
99
|
-
process.stdout.write("\x1B[2K");
|
|
100
|
-
const line = lines[i];
|
|
101
|
-
if (line !== void 0) {
|
|
102
|
-
process.stdout.write(line);
|
|
103
|
-
}
|
|
104
|
-
process.stdout.write("\n");
|
|
105
|
-
}
|
|
106
|
-
this.renderedLines = lines.length;
|
|
107
|
-
}
|
|
108
|
-
computeProgress() {
|
|
109
|
-
const keys = new Set(this.statuses.map((s) => s.dictionaryKey));
|
|
110
|
-
const doneSet = /* @__PURE__ */ new Set([
|
|
111
|
-
"fetched",
|
|
112
|
-
"imported",
|
|
113
|
-
"updated",
|
|
114
|
-
"up-to-date",
|
|
115
|
-
"reimported in JSON",
|
|
116
|
-
"new content file",
|
|
117
|
-
"error"
|
|
118
|
-
]);
|
|
119
|
-
const successesSet = /* @__PURE__ */ new Set([
|
|
120
|
-
"fetched",
|
|
121
|
-
"imported",
|
|
122
|
-
"updated",
|
|
123
|
-
"up-to-date",
|
|
124
|
-
"reimported in JSON",
|
|
125
|
-
"new content file"
|
|
126
|
-
]);
|
|
127
|
-
const done = this.statuses.filter(
|
|
128
|
-
(s) => doneSet.has(s.status)
|
|
129
|
-
).length;
|
|
130
|
-
const success = this.statuses.filter(
|
|
131
|
-
(s) => successesSet.has(s.status)
|
|
132
|
-
).length;
|
|
133
|
-
const errors = this.statuses.filter((s) => s.status === "error").length;
|
|
134
|
-
return {
|
|
135
|
-
total: keys.size,
|
|
136
|
-
done,
|
|
137
|
-
success,
|
|
138
|
-
errors
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
143
|
-
0 && (module.exports = {
|
|
144
|
-
PullLogger
|
|
145
|
-
});
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
exports.PullLogger = PullLogger;
|
|
146
103
|
//# sourceMappingURL=pullLog.cjs.map
|