@intlayer/chokidar 5.8.1 → 6.0.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/chokidar/watcher.cjs +15 -20
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/fetchDistantDictionaries.cjs +18 -37
- package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/{fetchDistantDictionaryKeys.cjs → fetchDistantDictionaryKeysAndUpdateTimestamp.cjs} +10 -10
- package/dist/cjs/fetchDistantDictionaryKeysAndUpdateTimestamp.cjs.map +1 -0
- package/dist/cjs/filterInvalidDictionaries.cjs +70 -0
- package/dist/cjs/filterInvalidDictionaries.cjs.map +1 -0
- package/dist/cjs/getBuiltFetchDictionariesPath.cjs +52 -0
- package/dist/cjs/getBuiltFetchDictionariesPath.cjs.map +1 -0
- package/dist/cjs/getBuiltRemoteDictionariesPath.cjs +51 -0
- package/dist/cjs/getBuiltRemoteDictionariesPath.cjs.map +1 -0
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/index.cjs +4 -4
- package/dist/cjs/loadDictionaries/index.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +57 -17
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +128 -53
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +101 -0
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -0
- package/dist/cjs/loadDictionaries/log.cjs +144 -0
- package/dist/cjs/loadDictionaries/log.cjs.map +1 -0
- package/dist/cjs/mergeDictionaries.cjs +18 -22
- package/dist/cjs/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/orderDictionaries.cjs +71 -0
- package/dist/cjs/orderDictionaries.cjs.map +1 -0
- package/dist/cjs/prepareContentDeclaration.cjs +4 -1
- package/dist/cjs/prepareContentDeclaration.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +9 -4
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/processPerLocaleDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs +22 -8
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.cjs +44 -42
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.cjs +83 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.cjs +29 -21
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.cjs +52 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.cjs +44 -29
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs +39 -34
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +4 -6
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +17 -16
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -1
- package/dist/cjs/utils/formatter.cjs +50 -0
- package/dist/cjs/utils/formatter.cjs.map +1 -0
- package/dist/cjs/utils/parallelize.cjs +43 -0
- package/dist/cjs/utils/parallelize.cjs.map +1 -0
- package/dist/cjs/utils/runOnce.cjs +2 -1
- package/dist/cjs/utils/runOnce.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/formatCode.cjs +7 -4
- package/dist/cjs/writeContentDeclaration/formatCode.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +5 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +43 -25
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
- package/dist/esm/chokidar/watcher.mjs +16 -21
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/fetchDistantDictionaries.mjs +24 -28
- package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/{fetchDistantDictionaryKeys.mjs → fetchDistantDictionaryKeysAndUpdateTimestamp.mjs} +6 -6
- package/dist/esm/fetchDistantDictionaryKeysAndUpdateTimestamp.mjs.map +1 -0
- package/dist/esm/filterInvalidDictionaries.mjs +40 -0
- package/dist/esm/filterInvalidDictionaries.mjs.map +1 -0
- package/dist/esm/getBuiltFetchDictionariesPath.mjs +18 -0
- package/dist/esm/getBuiltFetchDictionariesPath.mjs.map +1 -0
- package/dist/esm/getBuiltRemoteDictionariesPath.mjs +17 -0
- package/dist/esm/getBuiltRemoteDictionariesPath.mjs.map +1 -0
- package/dist/esm/index.mjs +8 -9
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/loadDictionaries/index.mjs +2 -2
- package/dist/esm/loadDictionaries/index.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +61 -18
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +132 -53
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +66 -0
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -0
- package/dist/esm/loadDictionaries/log.mjs +125 -0
- package/dist/esm/loadDictionaries/log.mjs.map +1 -0
- package/dist/esm/mergeDictionaries.mjs +19 -23
- package/dist/esm/mergeDictionaries.mjs.map +1 -1
- package/dist/esm/orderDictionaries.mjs +37 -0
- package/dist/esm/orderDictionaries.mjs.map +1 -0
- package/dist/esm/prepareContentDeclaration.mjs +4 -1
- package/dist/esm/prepareContentDeclaration.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +9 -4
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/processPerLocaleDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs +25 -9
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs +45 -43
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs +58 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs +29 -21
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs +28 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs +45 -30
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +39 -34
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +4 -6
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +17 -16
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
- package/dist/esm/utils/formatter.mjs +15 -0
- package/dist/esm/utils/formatter.mjs.map +1 -0
- package/dist/esm/utils/parallelize.mjs +9 -0
- package/dist/esm/utils/parallelize.mjs.map +1 -0
- package/dist/esm/utils/runOnce.mjs +2 -1
- package/dist/esm/utils/runOnce.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/formatCode.mjs +8 -5
- package/dist/esm/writeContentDeclaration/formatCode.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +5 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +40 -22
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
- package/dist/types/chokidar/watcher.d.ts.map +1 -1
- package/dist/types/fetchDistantDictionaries.d.ts +2 -1
- package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
- package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts +3 -0
- package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts.map +1 -0
- package/dist/types/filterInvalidDictionaries.d.ts +3 -0
- package/dist/types/filterInvalidDictionaries.d.ts.map +1 -0
- package/dist/types/getBuiltFetchDictionariesPath.d.ts +5 -0
- package/dist/types/getBuiltFetchDictionariesPath.d.ts.map +1 -0
- package/dist/types/getBuiltRemoteDictionariesPath.d.ts +5 -0
- package/dist/types/getBuiltRemoteDictionariesPath.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/loadDictionaries/index.d.ts +2 -2
- package/dist/types/loadDictionaries/index.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +4 -1
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadDictionaries.d.ts +11 -1
- package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +6 -0
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -0
- package/dist/types/loadDictionaries/log.d.ts +19 -0
- package/dist/types/loadDictionaries/log.d.ts.map +1 -0
- package/dist/types/mergeDictionaries.d.ts +1 -1
- package/dist/types/mergeDictionaries.d.ts.map +1 -1
- package/dist/types/orderDictionaries.d.ts +10 -0
- package/dist/types/orderDictionaries.d.ts.map +1 -0
- package/dist/types/prepareContentDeclaration.d.ts.map +1 -1
- package/dist/types/prepareIntlayer.d.ts.map +1 -1
- package/dist/types/processPerLocaleDictionary.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +4 -3
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts +23 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts +19 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts +1 -1
- package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts.map +1 -1
- package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +1 -1
- package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts.map +1 -1
- package/dist/types/transpiler/dictionary_to_type/createType.d.ts +1 -1
- package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +1 -1
- package/dist/types/utils/formatter.d.ts +4 -0
- package/dist/types/utils/formatter.d.ts.map +1 -0
- package/dist/types/utils/parallelize.d.ts +2 -0
- package/dist/types/utils/parallelize.d.ts.map +1 -0
- package/dist/types/utils/runOnce.d.ts +1 -1
- package/dist/types/utils/runOnce.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/formatCode.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +1 -1
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts +1 -1
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -1
- package/package.json +19 -17
- package/dist/cjs/checkDictionaryChanges.cjs +0 -58
- package/dist/cjs/checkDictionaryChanges.cjs.map +0 -1
- package/dist/cjs/fetchDistantDictionaryKeys.cjs.map +0 -1
- package/dist/cjs/getFilteredLocalesContent.cjs +0 -70
- package/dist/cjs/getFilteredLocalesContent.cjs.map +0 -1
- package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs +0 -44
- package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs.map +0 -1
- package/dist/cjs/log.cjs +0 -296
- package/dist/cjs/log.cjs.map +0 -1
- package/dist/esm/checkDictionaryChanges.mjs +0 -37
- package/dist/esm/checkDictionaryChanges.mjs.map +0 -1
- package/dist/esm/fetchDistantDictionaryKeys.mjs.map +0 -1
- package/dist/esm/getFilteredLocalesContent.mjs +0 -49
- package/dist/esm/getFilteredLocalesContent.mjs.map +0 -1
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs +0 -20
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs.map +0 -1
- package/dist/esm/log.mjs +0 -262
- package/dist/esm/log.mjs.map +0 -1
- package/dist/types/checkDictionaryChanges.d.ts +0 -3
- package/dist/types/checkDictionaryChanges.d.ts.map +0 -1
- package/dist/types/fetchDistantDictionaryKeys.d.ts +0 -3
- package/dist/types/fetchDistantDictionaryKeys.d.ts.map +0 -1
- package/dist/types/getFilteredLocalesContent.d.ts +0 -4
- package/dist/types/getFilteredLocalesContent.d.ts.map +0 -1
- package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts +0 -8
- package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts.map +0 -1
- package/dist/types/log.d.ts +0 -45
- package/dist/types/log.d.ts.map +0 -1
|
@@ -1,68 +1,147 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ANSIColors,
|
|
3
|
+
colon,
|
|
4
|
+
colorize,
|
|
5
|
+
colorizeKey,
|
|
2
6
|
ESMxCJSRequire,
|
|
3
7
|
getAppLogger,
|
|
4
8
|
getConfiguration
|
|
5
9
|
} from "@intlayer/config";
|
|
6
10
|
import { relative } from "node:path";
|
|
7
|
-
import { fetchDistantDictionaryKeys } from "../fetchDistantDictionaryKeys.mjs";
|
|
8
|
-
import { logger } from "../log.mjs";
|
|
9
|
-
import { sortAlphabetically } from "../utils/sortAlphabetically.mjs";
|
|
10
11
|
import { loadContentDeclarations } from "./loadContentDeclaration.mjs";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
projectRequire
|
|
12
|
+
import { loadRemoteDictionaries } from "./loadRemoteDictionaries.mjs";
|
|
13
|
+
import { DictionariesLogger } from "./log.mjs";
|
|
14
|
+
let loadDictionariesStatus = [];
|
|
15
|
+
const logger = new DictionariesLogger();
|
|
16
|
+
const setLoadDictionariesStatus = (statuses) => {
|
|
17
|
+
let updated = [...loadDictionariesStatus];
|
|
18
|
+
for (const incoming of statuses) {
|
|
19
|
+
const idx = updated.findIndex(
|
|
20
|
+
(s) => s.dictionaryKey === incoming.dictionaryKey && s.type === incoming.type
|
|
21
21
|
);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
if (idx >= 0) {
|
|
23
|
+
updated[idx] = incoming;
|
|
24
|
+
} else {
|
|
25
|
+
updated.push(incoming);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
loadDictionariesStatus = updated;
|
|
29
|
+
logger.update(statuses);
|
|
30
|
+
return updated;
|
|
31
|
+
};
|
|
32
|
+
const iconFor = (status) => {
|
|
33
|
+
switch (status) {
|
|
34
|
+
case "built":
|
|
35
|
+
case "imported":
|
|
36
|
+
case "fetched":
|
|
37
|
+
return "\u2714";
|
|
38
|
+
case "error":
|
|
39
|
+
return "\u2716";
|
|
40
|
+
default:
|
|
41
|
+
return "\u23F2";
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const colorFor = (status) => {
|
|
45
|
+
switch (status) {
|
|
46
|
+
case "built":
|
|
47
|
+
case "imported":
|
|
48
|
+
case "fetched":
|
|
49
|
+
return ANSIColors.GREEN;
|
|
50
|
+
case "error":
|
|
51
|
+
return ANSIColors.RED;
|
|
52
|
+
default:
|
|
53
|
+
return ANSIColors.BLUE;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const printSummary = (configuration = getConfiguration()) => {
|
|
57
|
+
if (configuration.log.mode !== "verbose") return;
|
|
58
|
+
const appLogger = getAppLogger(configuration);
|
|
59
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
60
|
+
for (const s of loadDictionariesStatus) {
|
|
61
|
+
const rec = byKey.get(s.dictionaryKey) ?? {};
|
|
62
|
+
if (s.type === "local") rec.local = s.status;
|
|
63
|
+
if (s.type === "remote") rec.remote = s.status;
|
|
64
|
+
byKey.set(s.dictionaryKey, rec);
|
|
65
|
+
}
|
|
66
|
+
const keys = Array.from(byKey.keys()).sort((a, b) => a.localeCompare(b));
|
|
67
|
+
for (const key of keys) {
|
|
68
|
+
const rec = byKey.get(key);
|
|
69
|
+
const labels = [];
|
|
70
|
+
if (rec.local) {
|
|
71
|
+
const inner = colorize(
|
|
72
|
+
`${iconFor(rec.local)} ${rec.local}`,
|
|
73
|
+
colorFor(rec.local)
|
|
74
|
+
);
|
|
75
|
+
labels.push(
|
|
76
|
+
`${ANSIColors.GREY}[` + colorize("local: ", ANSIColors.GREY) + inner + `${ANSIColors.GREY}]${ANSIColors.RESET}`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
if (rec.remote) {
|
|
80
|
+
const inner = colorize(
|
|
81
|
+
`${iconFor(rec.remote)} ${rec.remote}`,
|
|
82
|
+
colorFor(rec.remote)
|
|
83
|
+
);
|
|
84
|
+
labels.push(
|
|
85
|
+
`${ANSIColors.GREY}[` + colorize("distant: ", ANSIColors.GREY) + inner + `${ANSIColors.GREY}]${ANSIColors.RESET}`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
appLogger(
|
|
89
|
+
` - ${colon(colorizeKey(key), { colSize: keys })} ${labels.join(" ")}`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const loadDictionaries = async (contentDeclarationsPaths, configuration = getConfiguration(), projectRequire = ESMxCJSRequire) => {
|
|
94
|
+
const appLogger = getAppLogger(configuration);
|
|
95
|
+
appLogger("Dictionaries:", { isVerbose: true });
|
|
96
|
+
const files = Array.isArray(contentDeclarationsPaths) ? contentDeclarationsPaths : [contentDeclarationsPaths];
|
|
97
|
+
const localDictionaries = await loadContentDeclarations(
|
|
98
|
+
files,
|
|
99
|
+
configuration,
|
|
100
|
+
projectRequire,
|
|
101
|
+
setLoadDictionariesStatus
|
|
102
|
+
);
|
|
103
|
+
const filteredLocalDictionaries = localDictionaries.filter((dict) => {
|
|
104
|
+
const hasKey = Boolean(dict.key);
|
|
105
|
+
const hasContent = Boolean(dict.content);
|
|
106
|
+
if (!hasContent) {
|
|
107
|
+
appLogger(
|
|
108
|
+
[
|
|
27
109
|
"Content declaration has no exported content",
|
|
28
110
|
dict.filePath ? relative(configuration.content.baseDir, dict.filePath) : ""
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
logger.init(localDictionaryKeys, []);
|
|
37
|
-
logger.updateStatus(
|
|
38
|
-
filteredLocalDictionaries.map((dict) => ({
|
|
39
|
-
dictionaryKey: dict.key,
|
|
40
|
-
type: "local",
|
|
41
|
-
status: { status: "built" }
|
|
42
|
-
}))
|
|
43
|
-
);
|
|
44
|
-
let distantDictionaries = [];
|
|
45
|
-
let distantDictionaryKeys = [];
|
|
46
|
-
if (editor.clientId && editor.clientSecret) {
|
|
47
|
-
try {
|
|
48
|
-
distantDictionaryKeys = await fetchDistantDictionaryKeys();
|
|
49
|
-
const orderedDistantDictionaryKeys = distantDictionaryKeys.sort(sortAlphabetically);
|
|
50
|
-
logger.addDictionaryKeys("distant", orderedDistantDictionaryKeys);
|
|
51
|
-
distantDictionaries = await loadDistantDictionaries({
|
|
52
|
-
dictionaryKeys: orderedDistantDictionaryKeys
|
|
53
|
-
});
|
|
54
|
-
} catch (_error) {
|
|
55
|
-
appLogger("Error during fetching distant dictionaries", {
|
|
56
|
-
level: "error"
|
|
57
|
-
});
|
|
58
|
-
}
|
|
111
|
+
],
|
|
112
|
+
{ level: "error" }
|
|
113
|
+
);
|
|
114
|
+
} else if (!hasKey) {
|
|
115
|
+
appLogger(["Content declaration has no key", dict.filePath], {
|
|
116
|
+
level: "error"
|
|
117
|
+
});
|
|
59
118
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
119
|
+
return hasKey && hasContent;
|
|
120
|
+
});
|
|
121
|
+
const localDictionariesStatus = filteredLocalDictionaries.map(
|
|
122
|
+
(dict) => ({
|
|
123
|
+
dictionaryKey: dict.key,
|
|
124
|
+
type: "local",
|
|
125
|
+
status: "built"
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
setLoadDictionariesStatus(localDictionariesStatus);
|
|
129
|
+
const hasRemoteDictionaries = Boolean(
|
|
130
|
+
configuration.editor.clientId && configuration.editor.clientSecret
|
|
131
|
+
);
|
|
132
|
+
let remoteDictionaries = [];
|
|
133
|
+
if (hasRemoteDictionaries) {
|
|
134
|
+
remoteDictionaries = await loadRemoteDictionaries(
|
|
135
|
+
configuration,
|
|
136
|
+
setLoadDictionariesStatus
|
|
137
|
+
);
|
|
65
138
|
}
|
|
139
|
+
logger.finish();
|
|
140
|
+
printSummary(configuration);
|
|
141
|
+
return {
|
|
142
|
+
localDictionaries: filteredLocalDictionaries,
|
|
143
|
+
remoteDictionaries
|
|
144
|
+
};
|
|
66
145
|
};
|
|
67
146
|
export {
|
|
68
147
|
loadDictionaries
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n ESMxCJSRequire,\n getAppLogger,\n getConfiguration,\n type IntlayerConfig,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { relative } from 'node:path';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadRemoteDictionaries } from './loadRemoteDictionaries';\nimport { DictionariesLogger } from './log';\n\nexport type DictionariesStatus = {\n dictionaryKey: string;\n type: 'local' | 'remote';\n status:\n | 'pending' // Key found but not fetched yet\n | 'fetching' // If dictionary fetch is in progress\n | 'fetched' // If dictionary fetch succeeded\n | 'error' // If dictionary fetch failed\n | 'imported' // If dictionary already fetched and still up to date\n | 'found' // If dictionary key is found but promise is not resolved yet (ex: fetching distant content)\n | 'building' // If dictionary is being built\n | 'built'; // If dictionary is built;\n error?: string;\n};\n\nlet loadDictionariesStatus: DictionariesStatus[] = [];\nconst logger = new DictionariesLogger();\n\nconst setLoadDictionariesStatus = (statuses: DictionariesStatus[]) => {\n let updated: DictionariesStatus[] = [...loadDictionariesStatus];\n\n for (const incoming of statuses) {\n const idx = updated.findIndex(\n (s) =>\n s.dictionaryKey === incoming.dictionaryKey && s.type === incoming.type\n );\n if (idx >= 0) {\n updated[idx] = incoming;\n } else {\n updated.push(incoming);\n }\n }\n\n loadDictionariesStatus = updated;\n logger.update(statuses);\n\n return updated;\n};\n\ntype StatusRecord = {\n local?: DictionariesStatus['status'];\n remote?: DictionariesStatus['status'];\n};\n\nconst iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'built':\n case 'imported':\n case 'fetched':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n};\n\nconst colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'built':\n case 'imported':\n case 'fetched':\n return ANSIColors.GREEN;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n};\n\nconst printSummary = (configuration: IntlayerConfig = getConfiguration()) => {\n if (configuration.log.mode !== 'verbose') return;\n\n const appLogger = getAppLogger(configuration);\n\n // Aggregate by dictionary key\n const byKey = new Map<string, StatusRecord>();\n for (const s of loadDictionariesStatus) {\n const rec = byKey.get(s.dictionaryKey) ?? {};\n if (s.type === 'local') rec.local = s.status;\n if (s.type === 'remote') rec.remote = s.status;\n byKey.set(s.dictionaryKey, rec);\n }\n\n const keys = Array.from(byKey.keys()).sort((a, b) => a.localeCompare(b));\n\n for (const key of keys) {\n const rec = byKey.get(key)!;\n const labels: string[] = [];\n\n if (rec.local) {\n const inner = colorize(\n `${iconFor(rec.local)} ${rec.local}`,\n colorFor(rec.local)\n );\n labels.push(\n `${ANSIColors.GREY}[` +\n colorize('local: ', ANSIColors.GREY) +\n inner +\n `${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n if (rec.remote) {\n const inner = colorize(\n `${iconFor(rec.remote)} ${rec.remote}`,\n colorFor(rec.remote)\n );\n labels.push(\n `${ANSIColors.GREY}[` +\n colorize('distant: ', ANSIColors.GREY) +\n inner +\n `${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n appLogger(\n ` - ${colon(colorizeKey(key), { colSize: keys })} ${labels.join(' ')}`\n );\n }\n};\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string,\n configuration: IntlayerConfig = getConfiguration(),\n projectRequire = ESMxCJSRequire\n): Promise<{\n localDictionaries: Dictionary[];\n remoteDictionaries: Dictionary[];\n}> => {\n const appLogger = getAppLogger(configuration);\n\n appLogger('Dictionaries:', { isVerbose: true });\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] = await loadContentDeclarations(\n files,\n configuration,\n projectRequire,\n setLoadDictionariesStatus\n );\n\n const filteredLocalDictionaries = localDictionaries.filter((dict) => {\n const hasKey = Boolean(dict.key);\n const hasContent = Boolean(dict.content);\n\n if (!hasContent) {\n appLogger(\n [\n 'Content declaration has no exported content',\n dict.filePath\n ? relative(configuration.content.baseDir, dict.filePath)\n : '',\n ],\n { level: 'error' }\n );\n } else if (!hasKey) {\n appLogger(['Content declaration has no key', dict.filePath], {\n level: 'error',\n });\n }\n\n return hasKey && hasContent;\n });\n\n const localDictionariesStatus = filteredLocalDictionaries.map(\n (dict) =>\n ({\n dictionaryKey: dict.key,\n type: 'local',\n status: 'built',\n }) as const\n );\n\n setLoadDictionariesStatus(localDictionariesStatus);\n\n const hasRemoteDictionaries = Boolean(\n configuration.editor.clientId && configuration.editor.clientSecret\n );\n\n let remoteDictionaries: Dictionary[] = [];\n if (hasRemoteDictionaries) {\n remoteDictionaries = await loadRemoteDictionaries(\n configuration,\n setLoadDictionariesStatus\n );\n }\n\n // Stop spinner and show final progress line(s)\n logger.finish();\n\n printSummary(configuration);\n\n return {\n localDictionaries: filteredLocalDictionaries,\n remoteDictionaries,\n };\n};\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AAiBnC,IAAI,yBAA+C,CAAC;AACpD,MAAM,SAAS,IAAI,mBAAmB;AAEtC,MAAM,4BAA4B,CAAC,aAAmC;AACpE,MAAI,UAAgC,CAAC,GAAG,sBAAsB;AAE9D,aAAW,YAAY,UAAU;AAC/B,UAAM,MAAM,QAAQ;AAAA,MAClB,CAAC,MACC,EAAE,kBAAkB,SAAS,iBAAiB,EAAE,SAAS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QAAQ;AAClB,gBAAU,CAAC,kCAAkC,KAAK,QAAQ,GAAG;AAAA,QAC3D,OAAO;AAAA,MACT,CAAC;AAAA,IACH;AAEA,WAAO,UAAU;AAAA,EACnB,CAAC;AAED,QAAM,0BAA0B,0BAA0B;AAAA,IACxD,CAAC,UACE;AAAA,MACC,eAAe,KAAK;AAAA,MACpB,MAAM;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACJ;AAEA,4BAA0B,uBAAuB;AAEjD,QAAM,wBAAwB;AAAA,IAC5B,cAAc,OAAO,YAAY,cAAc,OAAO;AAAA,EACxD;AAEA,MAAI,qBAAmC,CAAC;AACxC,MAAI,uBAAuB;AACzB,yBAAqB,MAAM;AAAA,MACzB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAGA,SAAO,OAAO;AAEd,eAAa,aAAa;AAE1B,SAAO;AAAA,IACL,mBAAmB;AAAA,IACnB;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { getAppLogger, getConfiguration, x } from "@intlayer/config";
|
|
2
|
+
import remoteDictionariesRecord from "@intlayer/remote-dictionaries-entry";
|
|
3
|
+
import { fetchDistantDictionaries } from "../fetchDistantDictionaries.mjs";
|
|
4
|
+
import { fetchDistantDictionaryKeysAndUpdateTimestamp } from "../fetchDistantDictionaryKeysAndUpdateTimestamp.mjs";
|
|
5
|
+
import { sortAlphabetically } from "../utils/sortAlphabetically.mjs";
|
|
6
|
+
const formatDistantDictionaries = (dictionaries) => dictionaries.map((dict) => ({
|
|
7
|
+
...dict,
|
|
8
|
+
localId: `${dict.key}::remote::${dict.id}`,
|
|
9
|
+
location: "distant"
|
|
10
|
+
}));
|
|
11
|
+
const loadRemoteDictionaries = async (configuration = getConfiguration(), onStatusUpdate) => {
|
|
12
|
+
const appLogger = getAppLogger(configuration);
|
|
13
|
+
const { editor } = configuration;
|
|
14
|
+
const hasRemoteDictionaries = Boolean(editor.clientId && editor.clientSecret);
|
|
15
|
+
if (!hasRemoteDictionaries) return [];
|
|
16
|
+
try {
|
|
17
|
+
const distantDictionaryUpdateTimeStamp = await fetchDistantDictionaryKeysAndUpdateTimestamp(configuration);
|
|
18
|
+
const dictionariesKeysToFetch = Object.entries(
|
|
19
|
+
distantDictionaryUpdateTimeStamp
|
|
20
|
+
).filter(([dictionaryKey, updatedAt]) => {
|
|
21
|
+
if (!updatedAt) return true;
|
|
22
|
+
if (!remoteDictionariesRecord[dictionaryKey]) return true;
|
|
23
|
+
return remoteDictionariesRecord[dictionaryKey] > updatedAt;
|
|
24
|
+
}).map(([dictionaryKey]) => dictionaryKey);
|
|
25
|
+
const cachedDictionaries = Object.values(remoteDictionariesRecord).filter(
|
|
26
|
+
(dictionary) => dictionary?.updatedAt && !dictionariesKeysToFetch.includes(dictionary.key)
|
|
27
|
+
);
|
|
28
|
+
if (cachedDictionaries.length > 0) {
|
|
29
|
+
onStatusUpdate?.(
|
|
30
|
+
cachedDictionaries.map((d) => ({
|
|
31
|
+
dictionaryKey: d.key,
|
|
32
|
+
type: "remote",
|
|
33
|
+
status: "imported"
|
|
34
|
+
}))
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
const orderedDistantDictionaryKeys = dictionariesKeysToFetch.sort(sortAlphabetically);
|
|
38
|
+
if (orderedDistantDictionaryKeys.length > 0) {
|
|
39
|
+
onStatusUpdate?.(
|
|
40
|
+
orderedDistantDictionaryKeys.map((key) => ({
|
|
41
|
+
dictionaryKey: key,
|
|
42
|
+
type: "remote",
|
|
43
|
+
status: "pending"
|
|
44
|
+
}))
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
const distantDictionariesData = await fetchDistantDictionaries(
|
|
48
|
+
{
|
|
49
|
+
dictionaryKeys: orderedDistantDictionaryKeys
|
|
50
|
+
},
|
|
51
|
+
onStatusUpdate
|
|
52
|
+
);
|
|
53
|
+
const distantDictionaries = formatDistantDictionaries(
|
|
54
|
+
distantDictionariesData
|
|
55
|
+
);
|
|
56
|
+
return [...cachedDictionaries, ...distantDictionaries];
|
|
57
|
+
} catch (error) {
|
|
58
|
+
appLogger(`${x} Failed to fetch distant dictionaries`, { level: "error" });
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export {
|
|
63
|
+
formatDistantDictionaries,
|
|
64
|
+
loadRemoteDictionaries
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=loadRemoteDictionaries.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadRemoteDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { getAppLogger, getConfiguration, x } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport remoteDictionariesRecord from '@intlayer/remote-dictionaries-entry';\nimport { fetchDistantDictionaries } from '../fetchDistantDictionaries';\nimport { fetchDistantDictionaryKeysAndUpdateTimestamp } from '../fetchDistantDictionaryKeysAndUpdateTimestamp';\nimport { DictionariesStatus } from '../loadDictionaries/loadDictionaries';\nimport { sortAlphabetically } from '../utils/sortAlphabetically';\n\nexport const formatDistantDictionaries = (\n dictionaries: DictionaryAPI[]\n): Dictionary[] =>\n dictionaries.map((dict) => ({\n ...dict,\n localId: `${dict.key}::remote::${dict.id}`,\n location: 'distant' as const,\n }));\n\nexport const loadRemoteDictionaries = async (\n configuration = getConfiguration(),\n onStatusUpdate?: (status: DictionariesStatus[]) => void\n): Promise<DictionaryAPI[]> => {\n const appLogger = getAppLogger(configuration);\n const { editor } = configuration;\n\n const hasRemoteDictionaries = Boolean(editor.clientId && editor.clientSecret);\n\n if (!hasRemoteDictionaries) return [];\n\n try {\n const distantDictionaryUpdateTimeStamp: Record<string, number> =\n await fetchDistantDictionaryKeysAndUpdateTimestamp(configuration);\n\n const dictionariesKeysToFetch = Object.entries(\n distantDictionaryUpdateTimeStamp\n )\n .filter(([dictionaryKey, updatedAt]) => {\n // If dictionary doesn't have updatedAt, always fetch it\n if (!updatedAt) return true;\n\n // If remote timestamp doesn't exist, fetch it\n if (!remoteDictionariesRecord[dictionaryKey]) return true;\n\n // If remote timestamp is newer than local, fetch it\n return remoteDictionariesRecord[dictionaryKey] > updatedAt;\n })\n .map(([dictionaryKey]) => dictionaryKey);\n\n const cachedDictionaries = Object.values(remoteDictionariesRecord).filter(\n (dictionary) =>\n dictionary?.updatedAt &&\n !dictionariesKeysToFetch.includes(dictionary.key)\n );\n\n // Report cached as already imported\n if (cachedDictionaries.length > 0) {\n onStatusUpdate?.(\n cachedDictionaries.map((d) => ({\n dictionaryKey: d.key,\n type: 'remote',\n status: 'imported',\n }))\n );\n }\n\n const orderedDistantDictionaryKeys =\n dictionariesKeysToFetch.sort(sortAlphabetically);\n\n // Report pending for keys to be fetched so totals are visible immediately\n if (orderedDistantDictionaryKeys.length > 0) {\n onStatusUpdate?.(\n orderedDistantDictionaryKeys.map((key) => ({\n dictionaryKey: key,\n type: 'remote',\n status: 'pending',\n }))\n );\n }\n\n const distantDictionariesData = await fetchDistantDictionaries(\n {\n dictionaryKeys: orderedDistantDictionaryKeys,\n },\n onStatusUpdate\n );\n\n const distantDictionaries: DictionaryAPI[] = formatDistantDictionaries(\n distantDictionariesData\n );\n\n return [...cachedDictionaries, ...distantDictionaries];\n } catch (error) {\n appLogger(`${x} Failed to fetch distant dictionaries`, { level: 'error' });\n return [];\n }\n};\n"],"mappings":"AAEA,SAAS,cAAc,kBAAkB,SAAS;AAElD,OAAO,8BAA8B;AACrC,SAAS,gCAAgC;AACzC,SAAS,oDAAoD;AAE7D,SAAS,0BAA0B;AAE5B,MAAM,4BAA4B,CACvC,iBAEA,aAAa,IAAI,CAAC,UAAU;AAAA,EAC1B,GAAG;AAAA,EACH,SAAS,GAAG,KAAK,GAAG,aAAa,KAAK,EAAE;AAAA,EACxC,UAAU;AACZ,EAAE;AAEG,MAAM,yBAAyB,OACpC,gBAAgB,iBAAiB,GACjC,mBAC6B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AO,QAAQ,CAAC;AACzE,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ANSIColors,
|
|
3
|
+
colorize,
|
|
4
|
+
getConfiguration,
|
|
5
|
+
spinnerFrames
|
|
6
|
+
} from "@intlayer/config";
|
|
7
|
+
class DictionariesLogger {
|
|
8
|
+
statuses = [];
|
|
9
|
+
spinnerTimer = null;
|
|
10
|
+
spinnerIndex = 0;
|
|
11
|
+
renderedLines = 0;
|
|
12
|
+
spinnerFrames = spinnerFrames;
|
|
13
|
+
isFinished = false;
|
|
14
|
+
prefix;
|
|
15
|
+
lastRenderedState = "";
|
|
16
|
+
constructor() {
|
|
17
|
+
const configuration = getConfiguration();
|
|
18
|
+
this.prefix = configuration.log.prefix;
|
|
19
|
+
}
|
|
20
|
+
update(newStatuses) {
|
|
21
|
+
if (this.isFinished) return;
|
|
22
|
+
for (const status of newStatuses) {
|
|
23
|
+
const index = this.statuses.findIndex(
|
|
24
|
+
(s) => s.dictionaryKey === status.dictionaryKey && s.type === status.type
|
|
25
|
+
);
|
|
26
|
+
if (index >= 0) {
|
|
27
|
+
this.statuses[index] = status;
|
|
28
|
+
} else {
|
|
29
|
+
this.statuses.push(status);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
this.startSpinner();
|
|
33
|
+
this.render();
|
|
34
|
+
}
|
|
35
|
+
finish() {
|
|
36
|
+
this.isFinished = true;
|
|
37
|
+
this.stopSpinner();
|
|
38
|
+
this.render();
|
|
39
|
+
}
|
|
40
|
+
startSpinner() {
|
|
41
|
+
if (this.spinnerTimer || this.isFinished) return;
|
|
42
|
+
this.spinnerTimer = setInterval(() => {
|
|
43
|
+
this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;
|
|
44
|
+
this.render();
|
|
45
|
+
}, 100);
|
|
46
|
+
}
|
|
47
|
+
stopSpinner() {
|
|
48
|
+
if (!this.spinnerTimer) return;
|
|
49
|
+
clearInterval(this.spinnerTimer);
|
|
50
|
+
this.spinnerTimer = null;
|
|
51
|
+
}
|
|
52
|
+
render() {
|
|
53
|
+
const { localTotal, localDone, remoteTotal, remoteDone } = this.computeProgress();
|
|
54
|
+
const frame = this.spinnerFrames[this.spinnerIndex];
|
|
55
|
+
const lines = [];
|
|
56
|
+
const isLocalDone = localDone === localTotal;
|
|
57
|
+
const isRemoteDone = remoteDone === remoteTotal;
|
|
58
|
+
if (isLocalDone) {
|
|
59
|
+
lines.push(
|
|
60
|
+
`${this.prefix} ${colorize("\u2714", ANSIColors.GREEN)} local dictionaries: ${localDone}/${localTotal}`
|
|
61
|
+
);
|
|
62
|
+
} else {
|
|
63
|
+
lines.push(
|
|
64
|
+
`${this.prefix} ${colorize(frame, ANSIColors.BLUE)} local dictionaries: ${localDone}/${localTotal}`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
if (remoteTotal > 0) {
|
|
68
|
+
if (isRemoteDone) {
|
|
69
|
+
lines.push(
|
|
70
|
+
`${this.prefix} ${colorize("\u2714", ANSIColors.GREEN)} remote dictionaries: ${remoteDone}/${remoteTotal}`
|
|
71
|
+
);
|
|
72
|
+
} else {
|
|
73
|
+
lines.push(
|
|
74
|
+
`${this.prefix} ${colorize(frame, ANSIColors.BLUE)} remote dictionaries: ${remoteDone}/${remoteTotal}`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const currentState = lines.join("\n");
|
|
79
|
+
if (currentState === this.lastRenderedState) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this.lastRenderedState = currentState;
|
|
83
|
+
if (this.renderedLines > 0) {
|
|
84
|
+
process.stdout.write(`\x1B[${this.renderedLines}F`);
|
|
85
|
+
}
|
|
86
|
+
const totalLinesToClear = Math.max(this.renderedLines, lines.length);
|
|
87
|
+
for (let i = 0; i < totalLinesToClear; i++) {
|
|
88
|
+
process.stdout.write("\x1B[2K");
|
|
89
|
+
const line = lines[i];
|
|
90
|
+
if (line !== void 0) {
|
|
91
|
+
process.stdout.write(line);
|
|
92
|
+
}
|
|
93
|
+
process.stdout.write("\n");
|
|
94
|
+
}
|
|
95
|
+
this.renderedLines = lines.length;
|
|
96
|
+
}
|
|
97
|
+
computeProgress() {
|
|
98
|
+
const localKeys = new Set(
|
|
99
|
+
this.statuses.filter((s) => s.type === "local").map((s) => s.dictionaryKey)
|
|
100
|
+
);
|
|
101
|
+
const localDoneKeys = new Set(
|
|
102
|
+
this.statuses.filter(
|
|
103
|
+
(s) => s.type === "local" && (s.status === "built" || s.status === "error")
|
|
104
|
+
).map((s) => s.dictionaryKey)
|
|
105
|
+
);
|
|
106
|
+
const remoteKeys = new Set(
|
|
107
|
+
this.statuses.filter((s) => s.type === "remote").map((s) => s.dictionaryKey)
|
|
108
|
+
);
|
|
109
|
+
const remoteDoneKeys = new Set(
|
|
110
|
+
this.statuses.filter(
|
|
111
|
+
(s) => s.type === "remote" && (s.status === "fetched" || s.status === "imported" || s.status === "error")
|
|
112
|
+
).map((s) => s.dictionaryKey)
|
|
113
|
+
);
|
|
114
|
+
return {
|
|
115
|
+
localTotal: localKeys.size,
|
|
116
|
+
localDone: localDoneKeys.size,
|
|
117
|
+
remoteTotal: remoteKeys.size,
|
|
118
|
+
remoteDone: remoteDoneKeys.size
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export {
|
|
123
|
+
DictionariesLogger
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=log.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/log.ts"],"sourcesContent":["import {\n ANSIColors,\n colorize,\n getConfiguration,\n spinnerFrames,\n} from '@intlayer/config';\nimport type { DictionariesStatus } from './loadDictionaries';\n\nexport class DictionariesLogger {\n private statuses: DictionariesStatus[] = [];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private spinnerIndex = 0;\n private renderedLines = 0;\n private readonly spinnerFrames = spinnerFrames;\n private isFinished = false;\n private readonly prefix: string;\n private lastRenderedState: string = '';\n\n constructor() {\n const configuration = getConfiguration();\n this.prefix = configuration.log.prefix;\n }\n\n update(newStatuses: DictionariesStatus[]) {\n if (this.isFinished) return;\n for (const status of newStatuses) {\n const index = this.statuses.findIndex(\n (s) =>\n s.dictionaryKey === status.dictionaryKey && s.type === status.type\n );\n if (index >= 0) {\n this.statuses[index] = status;\n } else {\n this.statuses.push(status);\n }\n }\n\n this.startSpinner();\n this.render();\n }\n\n finish() {\n this.isFinished = true;\n this.stopSpinner();\n // Render final state and keep it visible\n this.render();\n }\n\n private startSpinner() {\n if (this.spinnerTimer || this.isFinished) return;\n this.spinnerTimer = setInterval(() => {\n this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;\n this.render();\n }, 100);\n }\n\n private stopSpinner() {\n if (!this.spinnerTimer) return;\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n\n private render() {\n const { localTotal, localDone, remoteTotal, remoteDone } =\n this.computeProgress();\n\n const frame = this.spinnerFrames[this.spinnerIndex];\n const lines: string[] = [];\n\n const isLocalDone = localDone === localTotal;\n const isRemoteDone = remoteDone === remoteTotal;\n\n if (isLocalDone) {\n lines.push(\n `${this.prefix} ${colorize('✔', ANSIColors.GREEN)} local dictionaries: ${localDone}/${localTotal}`\n );\n } else {\n lines.push(\n `${this.prefix} ${colorize(frame, ANSIColors.BLUE)} local dictionaries: ${localDone}/${localTotal}`\n );\n }\n\n if (remoteTotal > 0) {\n if (isRemoteDone) {\n lines.push(\n `${this.prefix} ${colorize('✔', ANSIColors.GREEN)} remote dictionaries: ${remoteDone}/${remoteTotal}`\n );\n } else {\n lines.push(\n `${this.prefix} ${colorize(frame, ANSIColors.BLUE)} remote dictionaries: ${remoteDone}/${remoteTotal}`\n );\n }\n }\n\n // Check if the state has changed to avoid duplicate rendering\n const currentState = lines.join('\\n');\n if (currentState === this.lastRenderedState) {\n return;\n }\n this.lastRenderedState = currentState;\n\n if (this.renderedLines > 0) {\n process.stdout.write(`\\x1b[${this.renderedLines}F`);\n }\n\n const totalLinesToClear = Math.max(this.renderedLines, lines.length);\n for (let i = 0; i < totalLinesToClear; i++) {\n process.stdout.write('\\x1b[2K');\n const line = lines[i];\n if (line !== undefined) {\n process.stdout.write(line);\n }\n process.stdout.write('\\n');\n }\n\n this.renderedLines = lines.length;\n }\n\n private computeProgress() {\n const localKeys = new Set(\n this.statuses\n .filter((s) => s.type === 'local')\n .map((s) => s.dictionaryKey)\n );\n\n const localDoneKeys = new Set(\n this.statuses\n .filter(\n (s) =>\n s.type === 'local' && (s.status === 'built' || s.status === 'error')\n )\n .map((s) => s.dictionaryKey)\n );\n\n const remoteKeys = new Set(\n this.statuses\n .filter((s) => s.type === 'remote')\n .map((s) => s.dictionaryKey)\n );\n\n const remoteDoneKeys = new Set(\n this.statuses\n .filter(\n (s) =>\n s.type === 'remote' &&\n (s.status === 'fetched' ||\n s.status === 'imported' ||\n s.status === 'error')\n )\n .map((s) => s.dictionaryKey)\n );\n\n return {\n localTotal: localKeys.size,\n localDone: localDoneKeys.size,\n remoteTotal: remoteKeys.size,\n remoteDone: remoteDoneKeys.size,\n } as const;\n }\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,MAAM,mBAAmB;AAAA,EACtB,WAAiC,CAAC;AAAA,EAClC,eAAsC;AAAA,EACtC,eAAe;AAAA,EACf,gBAAgB;AAAA,EACP,gBAAgB;AAAA,EACzB,aAAa;AAAA,EACJ;AAAA,EACT,oBAA4B;AAAA,EAEpC,cAAc;AACZ,UAAM,gBAAgB,iBAAiB;AACvC,SAAK,SAAS,cAAc,IAAI;AAAA,EAClC;AAAA,EAEA,OAAO,aAAmC;AACxC,QAAI,KAAK,WAAY;AACrB,eAAW,UAAU,aAAa;AAChC,YAAM,QAAQ,KAAK,SAAS;AAAA,QAC1B,CAAC,MACC,EAA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AAS,aACV,EAAE,WAAW,aACZ,EAAE,WAAW,cACb,EAAE,WAAW;AAAA,MACnB,EACC,IAAI,CAAC,MAAM,EAAE,aAAa;AAAA,IAC/B;AAEA,WAAO;AAAA,MACL,YAAY,UAAU;AAAA,MACtB,WAAW,cAAc;AAAA,MACzB,aAAa,WAAW;AAAA,MACxB,YAAY,eAAe;AAAA,IAC7B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { getAppLogger } from "@intlayer/config";
|
|
1
|
+
import { colorizeKey, getAppLogger } from "@intlayer/config";
|
|
2
2
|
import configuration from "@intlayer/config/built";
|
|
3
3
|
import { getNodeType } from "@intlayer/core";
|
|
4
4
|
import merge from "deepmerge";
|
|
5
|
+
import { orderDictionaries } from "./orderDictionaries.mjs";
|
|
5
6
|
const checkTypesMatch = (obj1, obj2, dictionaryKey, path = []) => {
|
|
6
7
|
const appLogger = getAppLogger(configuration);
|
|
7
8
|
const type1 = getNodeType(obj1);
|
|
8
9
|
const type2 = getNodeType(obj2);
|
|
9
10
|
if (type1 !== type2) {
|
|
10
11
|
appLogger(
|
|
11
|
-
`Error: Dictionary
|
|
12
|
+
`Error: Dictionary ${colorizeKey(dictionaryKey)} has a multiple content files with type mismatch at path "${path.join(".")}": Cannot merge ${type1} with ${type2}`,
|
|
12
13
|
{
|
|
13
14
|
level: "error"
|
|
14
15
|
}
|
|
@@ -77,35 +78,30 @@ const arrayMerge = (destinationArray, sourceArray) => {
|
|
|
77
78
|
return result;
|
|
78
79
|
};
|
|
79
80
|
const mergeDictionaries = (dictionaries) => {
|
|
80
|
-
const
|
|
81
|
-
let
|
|
81
|
+
const orderedDictionaries = orderDictionaries(dictionaries, configuration);
|
|
82
|
+
let mergedContent = orderedDictionaries[0].content;
|
|
82
83
|
const mergeOptions = {
|
|
83
84
|
arrayMerge
|
|
84
85
|
};
|
|
85
|
-
for (let i = 1; i <
|
|
86
|
-
const currentDictionary =
|
|
86
|
+
for (let i = 1; i < orderedDictionaries.length; i++) {
|
|
87
|
+
const currentDictionary = orderedDictionaries[i];
|
|
87
88
|
checkTypesMatch(
|
|
88
|
-
|
|
89
|
-
currentDictionary,
|
|
89
|
+
mergedContent,
|
|
90
|
+
currentDictionary.content,
|
|
90
91
|
currentDictionary.key,
|
|
91
92
|
[]
|
|
92
93
|
);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
mergeOptions
|
|
99
|
-
);
|
|
100
|
-
} else {
|
|
101
|
-
mergedDictionaries = merge(
|
|
102
|
-
currentDictionary,
|
|
103
|
-
mergedDictionaries,
|
|
104
|
-
mergeOptions
|
|
105
|
-
);
|
|
106
|
-
}
|
|
94
|
+
mergedContent = merge(
|
|
95
|
+
currentDictionary.content,
|
|
96
|
+
mergedContent,
|
|
97
|
+
mergeOptions
|
|
98
|
+
);
|
|
107
99
|
}
|
|
108
|
-
return {
|
|
100
|
+
return {
|
|
101
|
+
key: orderedDictionaries[0].key,
|
|
102
|
+
content: mergedContent,
|
|
103
|
+
localIds: dictionaries.filter((dict) => dict.localId).map((dict) => dict.localId)
|
|
104
|
+
};
|
|
109
105
|
};
|
|
110
106
|
export {
|
|
111
107
|
mergeDictionaries
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mergeDictionaries.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport type
|
|
1
|
+
{"version":3,"sources":["../../src/mergeDictionaries.ts"],"sourcesContent":["import { colorizeKey, getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { type Dictionary, getNodeType } from '@intlayer/core';\nimport merge, { Options } from 'deepmerge';\nimport { orderDictionaries } from './orderDictionaries';\n\nconst checkTypesMatch = (\n obj1: any,\n obj2: any,\n dictionaryKey: string,\n path: string[] = []\n): void => {\n const appLogger = getAppLogger(configuration);\n const type1 = getNodeType(obj1);\n const type2 = getNodeType(obj2);\n\n if (type1 !== type2) {\n appLogger(\n `Error: Dictionary ${colorizeKey(dictionaryKey)} has a multiple content files with type mismatch at path \"${path.join('.')}\": Cannot merge ${type1} with ${type2}`,\n {\n level: 'error',\n }\n );\n }\n\n if (type1 === 'object' && obj1 && obj2) {\n const allKeys = new Set([...Object.keys(obj1), ...Object.keys(obj2)]);\n for (const key of allKeys) {\n if (key in obj1 && key in obj2) {\n checkTypesMatch(obj1[key], obj2[key], dictionaryKey, [...path, key]);\n }\n }\n }\n};\n\n// Custom array merge strategy that merges arrays by key when present, otherwise by index\nconst arrayMerge = (destinationArray: any[], sourceArray: any[]): any[] => {\n const isObject = (value: unknown): value is Record<string, any> =>\n !!value && typeof value === 'object' && !Array.isArray(value);\n\n const getKey = (item: any): string | number | undefined => {\n if (!isObject(item)) return undefined;\n const key = (item as any).key;\n if (typeof key === 'string' || typeof key === 'number') return key;\n return undefined;\n };\n\n const result: any[] = [];\n\n // Build a lookup for destination keyed items and track usage of all destination indices\n const destKeyToIndex = new Map<string | number, number>();\n const destUsed: boolean[] = new Array(destinationArray.length).fill(false);\n for (let i = 0; i < destinationArray.length; i++) {\n const k = getKey(destinationArray[i]);\n if (k !== undefined && !destKeyToIndex.has(k)) {\n destKeyToIndex.set(k, i);\n }\n }\n\n // First pass: respect source (already merged) order\n for (let i = 0; i < sourceArray.length; i++) {\n const sourceItem = sourceArray[i];\n const sourceKey = getKey(sourceItem);\n\n if (sourceKey !== undefined && destKeyToIndex.has(sourceKey)) {\n const destIndex = destKeyToIndex.get(sourceKey)!;\n const destItem = destinationArray[destIndex];\n destUsed[destIndex] = true;\n\n if (isObject(destItem) && isObject(sourceItem)) {\n result.push(merge(sourceItem, destItem, { arrayMerge }));\n } else {\n // Prefer destination item (later dictionary) when primitive\n result.push(destItem !== undefined ? destItem : sourceItem);\n }\n continue;\n }\n\n // Fallback to index-based merge when no key match\n const destItem = destinationArray[i];\n if (destItem !== undefined && !destUsed[i]) {\n destUsed[i] = true;\n if (isObject(destItem) && isObject(sourceItem)) {\n result.push(merge(sourceItem, destItem, { arrayMerge }));\n } else if (destItem !== undefined) {\n result.push(destItem);\n } else {\n result.push(sourceItem);\n }\n } else {\n result.push(sourceItem);\n }\n }\n\n // Second pass: append remaining unused destination items (including keyed-only in destination or extra by index)\n for (let i = 0; i < destinationArray.length; i++) {\n if (!destUsed[i]) {\n result.push(destinationArray[i]);\n destUsed[i] = true;\n }\n }\n\n return result;\n};\n\nexport const mergeDictionaries = (dictionaries: Dictionary[]): Dictionary => {\n // Order dictionaries based on priority strategy\n const orderedDictionaries = orderDictionaries(dictionaries, configuration);\n\n let mergedContent: Dictionary['content'] = orderedDictionaries[0].content;\n\n // Configure deepmerge options with custom array merge strategy\n const mergeOptions: Options = {\n arrayMerge,\n };\n\n for (let i = 1; i < orderedDictionaries.length; i++) {\n const currentDictionary = orderedDictionaries[i];\n\n // Check types before merging\n checkTypesMatch(\n mergedContent,\n currentDictionary.content,\n currentDictionary.key,\n []\n );\n\n mergedContent = merge(\n currentDictionary.content,\n mergedContent,\n mergeOptions\n );\n }\n\n return {\n key: orderedDictionaries[0].key,\n content: mergedContent,\n localIds: dictionaries\n .filter((dict) => dict.localId)\n .map((dict) => dict.localId!),\n };\n};\n"],"mappings":"AAAA,SAAS,aAAa,oBAAoB;AAC1C,OAAO,mBAAmB;AAC1B,SAA0B,mBAAmB;AAC7C,OAAO,WAAwB;AAC/B,SAAS,yBAAyB;AAElC,MAAM,kBAAkB,CACtB,MACA,MACA,eACA,OAAiB,CAAC,MACT;AACT,QAAM,YAAY,aAAa,aAAa;AAC5C,QAAM,QAAQ,YAAY,IAAI;AAC9B,QAAM,QAAQ,YAAY,IAAI;AAE9B,MAAI,UAAU,OAAO;AACnB;AAAA,MACE,qBAAqB,YAAY,aAAa,CAAC,6DAA6D,KAAK,KAAK,GAAG,CAAC,mBAAmB,KAAK,SAAS,KAAK;AAAA,MAChK;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AAAA,E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AoB,CAAC,EAAE;AAAA,IAC5B,SAAS;AAAA,IACT,UAAU,aACP,OAAO,CAAC,SAAS,KAAK,OAAO,EAC7B,IAAI,CAAC,SAAS,KAAK,OAAQ;AAAA,EAChC;AACF;","names":["destItem"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import intlayerConfig from "@intlayer/config/built";
|
|
2
|
+
const orderDictionaries = (dictionaries, configuration = intlayerConfig) => {
|
|
3
|
+
const { editor } = configuration;
|
|
4
|
+
const { dictionaryPriorityStrategy } = editor;
|
|
5
|
+
if (dictionaries.length <= 1) {
|
|
6
|
+
return dictionaries;
|
|
7
|
+
}
|
|
8
|
+
const withIndex = dictionaries.map((dict, index) => ({ dict, index }));
|
|
9
|
+
const getPriority = (d) => {
|
|
10
|
+
const p = d.priority ?? 0;
|
|
11
|
+
return Number.isFinite(p) ? p : 0;
|
|
12
|
+
};
|
|
13
|
+
const getLocationWeight = (d) => {
|
|
14
|
+
const location = d.location ?? "distant";
|
|
15
|
+
if (dictionaryPriorityStrategy === "distant_first") {
|
|
16
|
+
return location === "distant" ? 0 : 1;
|
|
17
|
+
}
|
|
18
|
+
return location === "locale" ? 0 : 1;
|
|
19
|
+
};
|
|
20
|
+
withIndex.sort((a, b) => {
|
|
21
|
+
const aAuto = a.dict.autoFilled ? 1 : 0;
|
|
22
|
+
const bAuto = b.dict.autoFilled ? 1 : 0;
|
|
23
|
+
if (aAuto !== bAuto) return aAuto - bAuto;
|
|
24
|
+
const aP = getPriority(a.dict);
|
|
25
|
+
const bP = getPriority(b.dict);
|
|
26
|
+
if (aP !== bP) return bP - aP;
|
|
27
|
+
const aLoc = getLocationWeight(a.dict);
|
|
28
|
+
const bLoc = getLocationWeight(b.dict);
|
|
29
|
+
if (aLoc !== bLoc) return aLoc - bLoc;
|
|
30
|
+
return a.index - b.index;
|
|
31
|
+
});
|
|
32
|
+
return withIndex.map(({ dict }) => dict);
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
orderDictionaries
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=orderDictionaries.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/orderDictionaries.ts"],"sourcesContent":["import intlayerConfig from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/core';\n\n/**\n * Orders dictionaries based on the dictionary priority strategy.\n *\n * @param dictionaries - Array of dictionaries to order\n * @param priorityStrategy - The priority strategy ('local_first' or 'distant_first')\n * @returns Ordered array of dictionaries\n */\nexport const orderDictionaries = (\n dictionaries: Dictionary[],\n configuration = intlayerConfig\n): Dictionary[] => {\n const { editor } = configuration;\n const { dictionaryPriorityStrategy } = editor;\n\n if (dictionaries.length <= 1) {\n return dictionaries;\n }\n\n // Stabilize original indices to preserve relative order for complete ties\n const withIndex = dictionaries.map((dict, index) => ({ dict, index }));\n\n const getPriority = (d: Dictionary): number => {\n const p = d.priority ?? 0;\n\n return Number.isFinite(p) ? p : 0;\n };\n\n const getLocationWeight = (d: Dictionary): number => {\n const location = d.location ?? 'distant';\n\n if (dictionaryPriorityStrategy === 'distant_first') {\n // distant should come first\n return location === 'distant' ? 0 : 1;\n }\n // default: local_first\n return location === 'locale' ? 0 : 1;\n };\n\n withIndex.sort((a, b) => {\n // 1) Non-autoFilled before autoFilled (autoFilled have lower precedence)\n const aAuto = a.dict.autoFilled ? 1 : 0;\n const bAuto = b.dict.autoFilled ? 1 : 0;\n if (aAuto !== bAuto) return aAuto - bAuto; // 0 before 1\n\n // 2) Higher priority first (larger number wins)\n const aP = getPriority(a.dict);\n const bP = getPriority(b.dict);\n if (aP !== bP) return bP - aP; // descending\n\n // 3) Location according to strategy\n const aLoc = getLocationWeight(a.dict);\n const bLoc = getLocationWeight(b.dict);\n if (aLoc !== bLoc) return aLoc - bLoc;\n\n // 4) Stable fallback by original index\n return a.index - b.index;\n });\n\n return withIndex.map(({ dict }) => dict);\n};\n"],"mappings":"AAAA,OAAO,oBAAoB;AAUpB,MAAM,oBAAoB,CAC/B,cACA,gBAAgB,mBACC;AACjB,QAAM,EAAE,OAAO,IAAI;AACnB,QAAM,EAAE,2BAA2B,IAAI;AAEvC,MAAI,aAAa,UAAU,GAAG;AAC5B,WAAO;AAAA,EACT;AAGA,QAAM,YAAY,aAAa,IAAI,CAAC,MAAM,WAAW,EAAE,MAAM,MAAM,EAAE;AAErE,QAAM,cAAc,CAAC,MAA0B;AAC7C,UAAM,IAAI,EAAE,YAAY;AAExB,WAAO,OAAO,SAAS,CAAC,IAAI,IAAI;AAAA,EAClC;AAEA,QAAM,oBAAoB,CAAC,MAA0B;AACnD,UAAM,WAAW,EAAE,YAAY;AAE/B,QAAI,+BAA+B,iBAAiB;AAElD,aAAO,aAAa,YAAY,IAAI;AAAA,IACtC;AAEA,WAAO,aAAa,WAAW,IAAI;AAAA,EACrC;AAEA,YAAU,KAAK,CAAC,GAAG,MAAM;AAEvB,UAAM,QAAQ,EAAE,KAAK,aAAa,IAAI;AACtC,UAAM,QAAQ,EAAE,KAAK,aAAa,IAAI;AACtC,QAAI,UAAU,MAAO,QAAO,QAAQ;AAGpC,UAAM,KAAK,YAAY,EAAE,IAAI;AAC7B,UAAM,KAAK,YAAY,EAAE,IAAI;AAC7B,QAAI,OAAO,GAAI,QAAO,KAAK;AAG3B,UAAM,OAAO,kBAAkB,EAAE,IAAI;AACrC,UAAM,OAAO,kBAAkB,EAAE,IAAI;AACrC,QAAI,SAAS,KAAM,QAAO,OAAO;AAGjC,WAAO,EAAE,QAAQ,EAAE;AAAA,EACrB,CAAC;AAED,SAAO,UAAU,IAAI,CAAC,EAAE,KAAK,MAAM,IAAI;AACzC;","names":[]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { colorizePath, x } from "@intlayer/config";
|
|
1
2
|
import {
|
|
2
3
|
deepTransformNode,
|
|
3
4
|
NodeType
|
|
@@ -27,7 +28,9 @@ const writeFilePlugin = {
|
|
|
27
28
|
}
|
|
28
29
|
writeFileSync(abolsuteFilePath, fileContent);
|
|
29
30
|
} catch (error) {
|
|
30
|
-
throw new Error(
|
|
31
|
+
throw new Error(
|
|
32
|
+
`${x} Error writing file to ${colorizePath(filePath)}: ${error}`
|
|
33
|
+
);
|
|
31
34
|
}
|
|
32
35
|
const transformedFileContent = {
|
|
33
36
|
nodeType: NodeType.File,
|