@intlayer/chokidar 6.0.0-canary.3 → 6.0.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 +4 -4
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/fetchDistantDictionaries.cjs +3 -25
- package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/index.cjs +2 -5
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +1 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +19 -21
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +13 -4
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/log.cjs +47 -12
- package/dist/cjs/loadDictionaries/log.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +52 -9
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs +5 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +3 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
- package/dist/cjs/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/buildIntlayerDictionary.cjs +3 -3
- package/dist/cjs/transpiler/intlayer_dictionary/buildIntlayerDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/index.cjs +3 -3
- package/dist/cjs/transpiler/intlayer_dictionary/index.cjs.map +1 -0
- package/dist/cjs/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/processContentDeclaration.cjs +1 -1
- package/dist/cjs/transpiler/intlayer_dictionary/processContentDeclaration.cjs.map +1 -0
- package/dist/cjs/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeDynamicDictionary.cjs +19 -10
- package/dist/cjs/transpiler/intlayer_dictionary/writeDynamicDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeFetchDictionary.cjs +9 -3
- package/dist/cjs/transpiler/intlayer_dictionary/writeFetchDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeMergedDictionary.cjs +12 -8
- package/dist/cjs/transpiler/intlayer_dictionary/writeMergedDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeRemoteDictionary.cjs +9 -7
- package/dist/cjs/transpiler/intlayer_dictionary/writeRemoteDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeUnmergedDictionary.cjs +12 -8
- package/dist/cjs/transpiler/intlayer_dictionary/writeUnmergedDictionary.cjs.map +1 -0
- package/dist/cjs/writeConfiguration/index.cjs +5 -6
- package/dist/cjs/writeConfiguration/index.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +1 -5
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
- package/dist/cjs/writeFileIfChanged.cjs +46 -0
- package/dist/cjs/writeFileIfChanged.cjs.map +1 -0
- package/dist/cjs/{transpiler/declaration_file_to_dictionary/i18next_dictionary/convertPluralsValues.cjs → writeJsonIfChanged.cjs} +11 -14
- package/dist/cjs/writeJsonIfChanged.cjs.map +1 -0
- package/dist/esm/chokidar/watcher.mjs +1 -1
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/fetchDistantDictionaries.mjs +5 -32
- package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +1 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +19 -21
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +14 -5
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/log.mjs +50 -13
- package/dist/esm/loadDictionaries/log.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +53 -8
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +6 -2
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +4 -2
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
- package/dist/esm/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/buildIntlayerDictionary.mjs +2 -2
- package/dist/esm/transpiler/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/index.mjs +1 -1
- package/dist/esm/transpiler/intlayer_dictionary/index.mjs.map +1 -0
- package/dist/esm/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/processContentDeclaration.mjs +1 -1
- package/dist/esm/transpiler/intlayer_dictionary/processContentDeclaration.mjs.map +1 -0
- package/dist/esm/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeDynamicDictionary.mjs +25 -12
- package/dist/esm/transpiler/intlayer_dictionary/writeDynamicDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeFetchDictionary.mjs +15 -5
- package/dist/esm/transpiler/intlayer_dictionary/writeFetchDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeMergedDictionary.mjs +14 -10
- package/dist/esm/transpiler/intlayer_dictionary/writeMergedDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeRemoteDictionary.mjs +11 -9
- package/dist/esm/transpiler/intlayer_dictionary/writeRemoteDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeUnmergedDictionary.mjs +14 -10
- package/dist/esm/transpiler/intlayer_dictionary/writeUnmergedDictionary.mjs.map +1 -0
- package/dist/esm/writeConfiguration/index.mjs +5 -6
- package/dist/esm/writeConfiguration/index.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +1 -5
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
- package/dist/esm/writeFileIfChanged.mjs +22 -0
- package/dist/esm/writeFileIfChanged.mjs.map +1 -0
- package/dist/esm/writeJsonIfChanged.mjs +10 -0
- package/dist/esm/writeJsonIfChanged.mjs.map +1 -0
- package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadDictionaries.d.ts +4 -0
- package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +5 -1
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -1
- package/dist/types/loadDictionaries/log.d.ts +7 -0
- package/dist/types/loadDictionaries/log.d.ts.map +1 -1
- package/dist/types/prepareIntlayer.d.ts.map +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.map +1 -1
- package/dist/types/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/buildIntlayerDictionary.d.ts +1 -1
- package/dist/types/transpiler/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/index.d.ts +1 -1
- package/dist/types/transpiler/intlayer_dictionary/index.d.ts.map +1 -0
- package/dist/types/transpiler/intlayer_dictionary/processContentDeclaration.d.ts.map +1 -0
- package/dist/types/transpiler/intlayer_dictionary/writeDynamicDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/intlayer_dictionary/writeFetchDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/intlayer_dictionary/writeMergedDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/intlayer_dictionary/writeRemoteDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/intlayer_dictionary/writeUnmergedDictionary.d.ts.map +1 -0
- package/dist/types/writeConfiguration/index.d.ts +1 -1
- package/dist/types/writeConfiguration/index.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
- package/dist/types/writeFileIfChanged.d.ts +4 -0
- package/dist/types/writeFileIfChanged.d.ts.map +1 -0
- package/dist/types/writeJsonIfChanged.d.ts +4 -0
- package/dist/types/writeJsonIfChanged.d.ts.map +1 -0
- package/package.json +15 -15
- package/dist/cjs/fetchDistantDictionaryKeysAndUpdateTimestamp.cjs +0 -45
- package/dist/cjs/fetchDistantDictionaryKeysAndUpdateTimestamp.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.cjs +0 -46
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.cjs +0 -103
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertPluralsValues.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/index.cjs +0 -23
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/index.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.cjs +0 -51
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs +0 -40
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.cjs +0 -30
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.cjs +0 -52
- package/dist/cjs/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.cjs.map +0 -1
- package/dist/esm/fetchDistantDictionaryKeysAndUpdateTimestamp.mjs +0 -21
- package/dist/esm/fetchDistantDictionaryKeysAndUpdateTimestamp.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.mjs +0 -24
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.mjs +0 -81
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertPluralsValues.mjs +0 -13
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertPluralsValues.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/index.mjs +0 -2
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/index.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.mjs +0 -27
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs +0 -16
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.mjs +0 -6
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.mjs +0 -28
- package/dist/esm/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.mjs.map +0 -1
- package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts +0 -3
- package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.d.ts +0 -6
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/buildI18nextDictionary.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.d.ts +0 -7
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertPluralsValues.d.ts +0 -2
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertPluralsValues.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/index.d.ts +0 -2
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/index.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.d.ts +0 -7
- package/dist/types/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +0 -8
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.d.ts +0 -2
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.d.ts +0 -7
- package/dist/types/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.d.ts.map +0 -1
- /package/dist/types/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/processContentDeclaration.d.ts +0 -0
- /package/dist/types/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeDynamicDictionary.d.ts +0 -0
- /package/dist/types/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeFetchDictionary.d.ts +0 -0
- /package/dist/types/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeMergedDictionary.d.ts +0 -0
- /package/dist/types/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeRemoteDictionary.d.ts +0 -0
- /package/dist/types/transpiler/{declaration_file_to_dictionary/intlayer_dictionary → intlayer_dictionary}/writeUnmergedDictionary.d.ts +0 -0
|
@@ -2,7 +2,9 @@ import {
|
|
|
2
2
|
ANSIColors,
|
|
3
3
|
colorize,
|
|
4
4
|
getConfiguration,
|
|
5
|
-
spinnerFrames
|
|
5
|
+
spinnerFrames,
|
|
6
|
+
v,
|
|
7
|
+
x
|
|
6
8
|
} from "@intlayer/config";
|
|
7
9
|
class DictionariesLogger {
|
|
8
10
|
statuses = [];
|
|
@@ -13,10 +15,25 @@ class DictionariesLogger {
|
|
|
13
15
|
isFinished = false;
|
|
14
16
|
prefix;
|
|
15
17
|
lastRenderedState = "";
|
|
18
|
+
remoteCheckInProgress = false;
|
|
19
|
+
expectRemote = false;
|
|
20
|
+
remoteError = false;
|
|
16
21
|
constructor() {
|
|
17
22
|
const configuration = getConfiguration();
|
|
18
23
|
this.prefix = configuration.log.prefix;
|
|
19
24
|
}
|
|
25
|
+
setExpectRemote(expect) {
|
|
26
|
+
this.expectRemote = expect;
|
|
27
|
+
}
|
|
28
|
+
startRemoteCheck() {
|
|
29
|
+
if (this.isFinished) return;
|
|
30
|
+
this.remoteCheckInProgress = true;
|
|
31
|
+
this.startSpinner();
|
|
32
|
+
this.render();
|
|
33
|
+
}
|
|
34
|
+
stopRemoteCheck() {
|
|
35
|
+
this.remoteCheckInProgress = false;
|
|
36
|
+
}
|
|
20
37
|
update(newStatuses) {
|
|
21
38
|
if (this.isFinished) return;
|
|
22
39
|
for (const status of newStatuses) {
|
|
@@ -29,6 +46,10 @@ class DictionariesLogger {
|
|
|
29
46
|
this.statuses.push(status);
|
|
30
47
|
}
|
|
31
48
|
}
|
|
49
|
+
const { remoteTotal } = this.computeProgress();
|
|
50
|
+
if (this.expectRemote && !this.remoteCheckInProgress && remoteTotal === 0) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
32
53
|
this.startSpinner();
|
|
33
54
|
this.render();
|
|
34
55
|
}
|
|
@@ -49,29 +70,45 @@ class DictionariesLogger {
|
|
|
49
70
|
clearInterval(this.spinnerTimer);
|
|
50
71
|
this.spinnerTimer = null;
|
|
51
72
|
}
|
|
73
|
+
setRemoteError = (_error) => {
|
|
74
|
+
this.remoteError = true;
|
|
75
|
+
this.render();
|
|
76
|
+
};
|
|
52
77
|
render() {
|
|
53
78
|
const { localTotal, localDone, remoteTotal, remoteDone } = this.computeProgress();
|
|
54
79
|
const frame = this.spinnerFrames[this.spinnerIndex];
|
|
80
|
+
const clock = colorize(frame, ANSIColors.BLUE);
|
|
55
81
|
const lines = [];
|
|
56
82
|
const isLocalDone = localDone === localTotal;
|
|
57
83
|
const isRemoteDone = remoteDone === remoteTotal;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
84
|
+
const suppressLocalWhileCheckingRemote = this.expectRemote && this.remoteCheckInProgress && remoteTotal === 0;
|
|
85
|
+
if (!suppressLocalWhileCheckingRemote) {
|
|
86
|
+
if (isLocalDone) {
|
|
87
|
+
lines.push(
|
|
88
|
+
`${this.prefix} ${v} Local dictionaries: ${colorize(`${localDone}`, ANSIColors.GREEN)}${colorize(`/${localTotal}`, ANSIColors.GREY)}`
|
|
89
|
+
);
|
|
90
|
+
} else {
|
|
91
|
+
lines.push(
|
|
92
|
+
`${this.prefix} ${clock} Local dictionaries: ${colorize(`${localDone}`, ANSIColors.BLUE)}${colorize(`/${localTotal}`, ANSIColors.GREY)}`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
66
95
|
}
|
|
67
|
-
if (remoteTotal > 0) {
|
|
68
|
-
if (
|
|
96
|
+
if (remoteTotal > 0 || this.remoteCheckInProgress || this.remoteError) {
|
|
97
|
+
if (this.remoteError) {
|
|
98
|
+
lines.push(
|
|
99
|
+
`${this.prefix} ${x} Remote dictionaries: ${colorize("Failed to fetch", ANSIColors.RED)}`
|
|
100
|
+
);
|
|
101
|
+
} else if (remoteTotal === 0) {
|
|
102
|
+
lines.push(
|
|
103
|
+
`${this.prefix} ${clock} Remote dictionaries: ${colorize("Check server", ANSIColors.BLUE)}`
|
|
104
|
+
);
|
|
105
|
+
} else if (isRemoteDone) {
|
|
69
106
|
lines.push(
|
|
70
|
-
`${this.prefix} ${
|
|
107
|
+
`${this.prefix} ${v} Remote dictionaries: ${colorize(`${remoteDone}`, ANSIColors.GREEN)}${colorize(`/${remoteTotal}`, ANSIColors.GREY)}`
|
|
71
108
|
);
|
|
72
109
|
} else {
|
|
73
110
|
lines.push(
|
|
74
|
-
`${this.prefix} ${
|
|
111
|
+
`${this.prefix} ${clock} Remote dictionaries: ${colorize(`${remoteDone}`, ANSIColors.BLUE)}${colorize(`/${remoteTotal}`, ANSIColors.GREY)}`
|
|
75
112
|
);
|
|
76
113
|
}
|
|
77
114
|
}
|
|
@@ -1 +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
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/log.ts"],"sourcesContent":["import {\n ANSIColors,\n colorize,\n getConfiguration,\n spinnerFrames,\n v,\n x,\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 private remoteCheckInProgress = false;\n private expectRemote = false;\n private remoteError = false;\n\n constructor() {\n const configuration = getConfiguration();\n this.prefix = configuration.log.prefix;\n }\n\n setExpectRemote(expect: boolean) {\n this.expectRemote = expect;\n }\n\n startRemoteCheck() {\n if (this.isFinished) return;\n this.remoteCheckInProgress = true;\n this.startSpinner();\n this.render();\n }\n\n stopRemoteCheck() {\n this.remoteCheckInProgress = false;\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 // If we expect remote fetch later, avoid rendering a local-only line first\n const { remoteTotal } = this.computeProgress();\n if (this.expectRemote && !this.remoteCheckInProgress && remoteTotal === 0) {\n // Do not start spinner or render yet; wait until remote check starts\n return;\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 public setRemoteError = (_error?: Error) => {\n this.remoteError = true;\n this.render();\n };\n\n private render() {\n const { localTotal, localDone, remoteTotal, remoteDone } =\n this.computeProgress();\n\n const frame = this.spinnerFrames[this.spinnerIndex];\n const clock = colorize(frame, ANSIColors.BLUE);\n const lines: string[] = [];\n\n const isLocalDone = localDone === localTotal;\n const isRemoteDone = remoteDone === remoteTotal;\n\n const suppressLocalWhileCheckingRemote =\n this.expectRemote && this.remoteCheckInProgress && remoteTotal === 0;\n\n if (!suppressLocalWhileCheckingRemote) {\n if (isLocalDone) {\n lines.push(\n `${this.prefix} ${v} Local dictionaries: ${colorize(`${localDone}`, ANSIColors.GREEN)}${colorize(`/${localTotal}`, ANSIColors.GREY)}`\n );\n } else {\n lines.push(\n `${this.prefix} ${clock} Local dictionaries: ${colorize(`${localDone}`, ANSIColors.BLUE)}${colorize(`/${localTotal}`, ANSIColors.GREY)}`\n );\n }\n }\n\n // Single remote line: show error, check, or progress counts\n if (remoteTotal > 0 || this.remoteCheckInProgress || this.remoteError) {\n if (this.remoteError) {\n lines.push(\n `${this.prefix} ${x} Remote dictionaries: ${colorize('Failed to fetch', ANSIColors.RED)}`\n );\n } else if (remoteTotal === 0) {\n lines.push(\n `${this.prefix} ${clock} Remote dictionaries: ${colorize('Check server', ANSIColors.BLUE)}`\n );\n } else if (isRemoteDone) {\n lines.push(\n `${this.prefix} ${v} Remote dictionaries: ${colorize(`${remoteDone}`, ANSIColors.GREEN)}${colorize(`/${remoteTotal}`, ANSIColors.GREY)}`\n );\n } else {\n lines.push(\n `${this.prefix} ${clock} Remote dictionaries: ${colorize(`${remoteDone}`, ANSIColors.BLUE)}${colorize(`/${remoteTotal}`, ANSIColors.GREY)}`\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,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,EAC5B,wBAAwB;AAAA,EACxB,eAAe;AAAA,EACf,cAAc;AAAA,EAEtB,cAAc;AACZ,UAAM,gBAAgB,iBAAiB;AACvC,SAAK,SAAS,cAAc,IAAI;AAAA,EAClC;AAAA,EAEA,gBAAgB,QAAiB;AAC/B,SAAK,eAAe;AAAA,EACtB;AAAA,EAEA,mBAAmB;AACjB,QAAI,KAAK,WAAY;AACrB,SAAK,wBAAwB;AAC7B,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,kBAAkB;AAChB,SAAK,wBAAwB;AAAA,EAC/B;AAAA,EAEA,OAAO,aAAmC;AACxC,QAAI,KAAK,WAAY;AACrB,eAAW,UAAU,aAAa;AAChC,YAAM,QAAQ,KAAK,SAAS;AAAA,QAC1B,CAAC,MACC,EAAE,kBAAkB,OAAO,iBAAiB,EAAE,SAAS,OAAO;AAAA,MAClE;AACA,UAAI,SAAS,GAAG;AACd,aAAK,SAAS,KAAK,IAAI;AAAA,MACzB,OAAO;AACL,aAAK,SAAS,KAAK,MAAM;AAAA,MAC3B;AAAA,IACF;AAGA,UAAM,EAAE,YAAY,IAAI,KAAK,gBAAgB;AAC7C,QAAI,KAAK,gBAAgB,CAAC,KAAK,yBAAyB,gBAAgB,GAAG;AAEzE;AAAA,IACF;AAEA,SAAK,aAAa;AAClB,SAAK,OAAO;AAA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AAAA,MACpB,KAAK,SACF,OAAO,CAAC,MAAM,EAAE,SAAS,OAAO,EAChC,IAAI,CAAC,MAAM,EAAE,aAAa;AAAA,IAC/B;AAEA,UAAM,gBAAgB,IAAI;AAAA,MACxB,KAAK,SACF;AAAA,QACC,CAAC,MACC,EAAE,SAAS,YAAY,EAAE,WAAW,WAAW,EAAE,WAAW;AAAA,MAChE,EACC,IAAI,CAAC,MAAM,EAAE,aAAa;AAAA,IAC/B;AAEA,UAAM,aAAa,IAAI;AAAA,MACrB,KAAK,SACF,OAAO,CAAC,MAAM,EAAE,SAAS,QAAQ,EACjC,IAAI,CAAC,MAAM,EAAE,aAAa;AAAA,IAC/B;AAEA,UAAM,iBAAiB,IAAI;AAAA,MACzB,KAAK,SACF;AAAA,QACC,CAAC,MACC,EAAE,SAAS,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,21 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ANSIColors,
|
|
2
3
|
ESMxCJSRequire,
|
|
4
|
+
colorize,
|
|
3
5
|
getAppLogger,
|
|
4
6
|
getConfiguration
|
|
5
7
|
} from "@intlayer/config";
|
|
6
8
|
import { cleanOutputDir } from "./cleanOutputDir.mjs";
|
|
7
9
|
import { listDictionaries } from "./listDictionariesPath.mjs";
|
|
8
10
|
import { loadDictionaries } from "./loadDictionaries/loadDictionaries.mjs";
|
|
9
|
-
import { buildDictionary } from "./transpiler/declaration_file_to_dictionary/index.mjs";
|
|
10
|
-
import { writeRemoteDictionary } from "./transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs";
|
|
11
11
|
import { createDictionaryEntryPoint } from "./transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs";
|
|
12
12
|
import {
|
|
13
13
|
createModuleAugmentation,
|
|
14
14
|
createTypes
|
|
15
15
|
} from "./transpiler/dictionary_to_type/index.mjs";
|
|
16
|
+
import { buildDictionary } from "./transpiler/intlayer_dictionary/buildIntlayerDictionary.mjs";
|
|
17
|
+
import { writeRemoteDictionary } from "./transpiler/intlayer_dictionary/writeRemoteDictionary.mjs";
|
|
16
18
|
import { writeConfiguration } from "./writeConfiguration/index.mjs";
|
|
17
19
|
const prepareIntlayer = async (configuration = getConfiguration(), projectRequire = ESMxCJSRequire, clean = false) => {
|
|
18
20
|
const appLogger = getAppLogger(configuration);
|
|
21
|
+
const preparationStartMs = Date.now();
|
|
19
22
|
if (clean) {
|
|
20
23
|
cleanOutputDir(configuration);
|
|
21
24
|
}
|
|
@@ -25,6 +28,16 @@ const prepareIntlayer = async (configuration = getConfiguration(), projectRequir
|
|
|
25
28
|
configuration,
|
|
26
29
|
projectRequire
|
|
27
30
|
);
|
|
31
|
+
const dictionariesLoadedTime = Date.now();
|
|
32
|
+
appLogger([
|
|
33
|
+
"Content loaded",
|
|
34
|
+
colorize(
|
|
35
|
+
[
|
|
36
|
+
dictionaries.remoteDictionaries.length > 0 ? ` (Total: ${dictionariesLoadedTime - preparationStartMs}ms - Local: ${dictionaries.time.localDictionaries}ms - Remote: ${dictionaries.time.remoteDictionaries}ms)` : `(${dictionariesLoadedTime - preparationStartMs}ms)`
|
|
37
|
+
].join(""),
|
|
38
|
+
ANSIColors.GREY_DARK
|
|
39
|
+
)
|
|
40
|
+
]);
|
|
28
41
|
const dictionariesOutput = await buildDictionary(
|
|
29
42
|
[...dictionaries.localDictionaries, ...dictionaries.remoteDictionaries],
|
|
30
43
|
configuration
|
|
@@ -35,13 +48,45 @@ const prepareIntlayer = async (configuration = getConfiguration(), projectRequir
|
|
|
35
48
|
).map((dictionary) => dictionary.dictionaryPath);
|
|
36
49
|
await createTypes(dictionariesPaths);
|
|
37
50
|
await createDictionaryEntryPoint(configuration);
|
|
38
|
-
|
|
51
|
+
const dictionariesBuiltTime = Date.now();
|
|
52
|
+
appLogger([
|
|
53
|
+
"Dictionaries built",
|
|
54
|
+
colorize(
|
|
55
|
+
`(${dictionariesBuiltTime - preparationStartMs}ms)`,
|
|
56
|
+
ANSIColors.GREY_DARK
|
|
57
|
+
)
|
|
58
|
+
]);
|
|
39
59
|
await createModuleAugmentation(configuration);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
const moduleAugmentationBuiltTime = Date.now();
|
|
61
|
+
appLogger(
|
|
62
|
+
[
|
|
63
|
+
"Module augmentation built",
|
|
64
|
+
colorize(
|
|
65
|
+
`(${moduleAugmentationBuiltTime - dictionariesBuiltTime}ms)`,
|
|
66
|
+
ANSIColors.GREY_DARK
|
|
67
|
+
)
|
|
68
|
+
],
|
|
69
|
+
{
|
|
70
|
+
isVerbose: true
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
await writeConfiguration(configuration);
|
|
74
|
+
const configurationWrittenTime = Date.now();
|
|
75
|
+
appLogger(
|
|
76
|
+
[
|
|
77
|
+
"Configuration written",
|
|
78
|
+
colorize(
|
|
79
|
+
`(${configurationWrittenTime - preparationStartMs}ms)`,
|
|
80
|
+
ANSIColors.GREY_DARK
|
|
81
|
+
)
|
|
82
|
+
],
|
|
83
|
+
{
|
|
84
|
+
isVerbose: true
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
const preparationElapsedMs = Date.now() - preparationStartMs;
|
|
88
|
+
appLogger([`Done`, colorize(`${preparationElapsedMs}ms`, ANSIColors.GREEN)], {
|
|
89
|
+
level: "info",
|
|
45
90
|
isVerbose: true
|
|
46
91
|
});
|
|
47
92
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n type IntlayerConfig,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { listDictionaries } from './listDictionariesPath';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n ANSIColors,\n ESMxCJSRequire,\n type IntlayerConfig,\n colorize,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { listDictionaries } from './listDictionariesPath';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createModuleAugmentation,\n createTypes,\n} from './transpiler/dictionary_to_type/index';\nimport { buildDictionary } from './transpiler/intlayer_dictionary/buildIntlayerDictionary';\nimport { writeRemoteDictionary } from './transpiler/intlayer_dictionary/writeRemoteDictionary';\nimport { writeConfiguration } from './writeConfiguration';\n\nexport const prepareIntlayer = async (\n configuration: IntlayerConfig = getConfiguration(),\n projectRequire = ESMxCJSRequire,\n clean = false\n) => {\n const appLogger = getAppLogger(configuration);\n const preparationStartMs = Date.now();\n\n if (clean) {\n cleanOutputDir(configuration);\n }\n\n const files: string[] = listDictionaries(configuration);\n\n const dictionaries = await loadDictionaries(\n files,\n configuration,\n projectRequire\n );\n\n const dictionariesLoadedTime = Date.now();\n\n appLogger([\n 'Content loaded',\n colorize(\n [\n dictionaries.remoteDictionaries.length > 0\n ? ` (Total: ${dictionariesLoadedTime - preparationStartMs}ms - Local: ${dictionaries.time.localDictionaries}ms - Remote: ${dictionaries.time.remoteDictionaries}ms)`\n : `(${dictionariesLoadedTime - preparationStartMs}ms)`,\n ].join(''),\n ANSIColors.GREY_DARK\n ),\n ]);\n\n // Build local dictionaries\n const dictionariesOutput = await buildDictionary(\n [...dictionaries.localDictionaries, ...dictionaries.remoteDictionaries],\n configuration\n );\n\n // Write remote dictionaries\n // Used as cache for next fetch\n await writeRemoteDictionary(dictionaries.remoteDictionaries, configuration);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n await createTypes(dictionariesPaths);\n\n await createDictionaryEntryPoint(configuration);\n\n const dictionariesBuiltTime = Date.now();\n\n appLogger([\n 'Dictionaries built',\n colorize(\n `(${dictionariesBuiltTime - preparationStartMs}ms)`,\n ANSIColors.GREY_DARK\n ),\n ]);\n\n await createModuleAugmentation(configuration);\n\n const moduleAugmentationBuiltTime = Date.now();\n\n appLogger(\n [\n 'Module augmentation built',\n colorize(\n `(${moduleAugmentationBuiltTime - dictionariesBuiltTime}ms)`,\n ANSIColors.GREY_DARK\n ),\n ],\n {\n isVerbose: true,\n }\n );\n\n await writeConfiguration(configuration);\n\n const configurationWrittenTime = Date.now();\n\n appLogger(\n [\n 'Configuration written',\n colorize(\n `(${configurationWrittenTime - preparationStartMs}ms)`,\n ANSIColors.GREY_DARK\n ),\n ],\n {\n isVerbose: true,\n }\n );\n\n const preparationElapsedMs = Date.now() - preparationStartMs;\n appLogger([`Done`, colorize(`${preparationElapsedMs}ms`, ANSIColors.GREEN)], {\n level: 'info',\n isVerbose: true,\n });\n};\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AACjC,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,0BAA0B;AAE5B,MAAM,kBAAkB,OAC7B,gBAAgC,iBAAiB,GACjD,iBAAiB,gBACjB,QAAQ,UACL;AACH,QAAM,YAAY,aAAa,aAAa;AAC5C,QAAM,qBAAqB,KAAK,IAAI;AAEpC,MAAI,OAAO;AACT,mBAAe,aAA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BAAkB;AAAA,QACjD,WAAW;AAAA,MACb;AAAA,IACF;AAAA,IACA;AAAA,MACE,WAAW;AAAA,IACb;AAAA,EACF;AAEA,QAAM,uBAAuB,KAAK,IAAI,IAAI;AAC1C,YAAU,CAAC,QAAQ,SAAS,GAAG,oBAAoB,MAAM,WAAW,KAAK,CAAC,GAAG;AAAA,IAC3E,OAAO;AAAA,IACP,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getConfiguration } from "@intlayer/config";
|
|
2
|
-
import { mkdir
|
|
2
|
+
import { mkdir } from "fs/promises";
|
|
3
3
|
import { resolve } from "path";
|
|
4
4
|
import { getBuiltDictionariesPath } from "../../getBuiltDictionariesPath.mjs";
|
|
5
5
|
import { getBuiltDynamicDictionariesPath } from "../../getBuiltDynamicDictionariesPath.mjs";
|
|
@@ -7,6 +7,7 @@ import { getBuiltFetchDictionariesPath } from "../../getBuiltFetchDictionariesPa
|
|
|
7
7
|
import { getBuiltRemoteDictionariesPath } from "../../getBuiltRemoteDictionariesPath.mjs";
|
|
8
8
|
import { getBuiltUnmergedDictionariesPath } from "../../getBuiltUnmergedDictionariesPath.mjs";
|
|
9
9
|
import { parallelize } from "../../utils/parallelize.mjs";
|
|
10
|
+
import { writeFileIfChanged } from "../../writeFileIfChanged.mjs";
|
|
10
11
|
import { generateDictionaryListContent } from "./generateDictionaryListContent.mjs";
|
|
11
12
|
const filterDictionaries = (paths, keys) => {
|
|
12
13
|
if (!keys) return paths;
|
|
@@ -18,7 +19,10 @@ const writeDictionaryFiles = async (paths, fileName, format, configuration = get
|
|
|
18
19
|
const content = generateDictionaryListContent(paths, format, configuration);
|
|
19
20
|
const extension = format === "cjs" ? "cjs" : "mjs";
|
|
20
21
|
const { mainDir } = configuration.content;
|
|
21
|
-
await
|
|
22
|
+
await writeFileIfChanged(
|
|
23
|
+
resolve(mainDir, `${fileName}.${extension}`),
|
|
24
|
+
content
|
|
25
|
+
);
|
|
22
26
|
};
|
|
23
27
|
const createDictionaryEntryPoint = async (configuration = getConfiguration(), dictionariesKeys, formats = ["cjs", "esm"]) => {
|
|
24
28
|
const { mainDir } = configuration.content;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { mkdir
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { mkdir } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getBuiltDictionariesPath } from '../../getBuiltDictionariesPath';\nimport { getBuiltDynamicDictionariesPath } from '../../getBuiltDynamicDictionariesPath';\nimport { getBuiltFetchDictionariesPath } from '../../getBuiltFetchDictionariesPath';\nimport { getBuiltRemoteDictionariesPath } from '../../getBuiltRemoteDictionariesPath';\nimport { getBuiltUnmergedDictionariesPath } from '../../getBuiltUnmergedDictionariesPath';\nimport { parallelize } from '../../utils/parallelize';\nimport { writeFileIfChanged } from '../../writeFileIfChanged';\nimport { generateDictionaryListContent } from './generateDictionaryListContent';\n\nconst filterDictionaries = (paths: string[], keys?: string[]) => {\n if (!keys) return paths;\n return paths.filter((path) =>\n keys.some((key) => path.endsWith(`${key}.json`))\n );\n};\n\nconst writeDictionaryFiles = async (\n paths: string[],\n fileName: string,\n format: 'cjs' | 'esm',\n configuration = getConfiguration()\n) => {\n const content = generateDictionaryListContent(paths, format, configuration);\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n\n const { mainDir } = configuration.content;\n\n await writeFileIfChanged(\n resolve(mainDir, `${fileName}.${extension}`),\n content\n );\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryEntryPoint = async (\n configuration = getConfiguration(),\n dictionariesKeys?: string[],\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n) => {\n const { mainDir } = configuration.content;\n\n await mkdir(mainDir, { recursive: true });\n\n const remoteDictionariesPath = getBuiltRemoteDictionariesPath(configuration);\n const dictionariesPath = filterDictionaries(\n getBuiltDictionariesPath(configuration),\n dictionariesKeys\n );\n const unmergedDictionariesPath =\n getBuiltUnmergedDictionariesPath(configuration);\n\n const writeOperations = [\n ...formats.map((format) => ({\n paths: remoteDictionariesPath,\n fileName: 'remote_dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: dictionariesPath,\n fileName: 'dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: unmergedDictionariesPath,\n fileName: 'unmerged_dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: getBuiltDynamicDictionariesPath(configuration, format),\n fileName: 'dynamic_dictionaries' as const,\n format,\n })),\n ...formats.map((format) => ({\n paths: getBuiltFetchDictionariesPath(configuration, format),\n fileName: 'fetch_dictionaries' as const,\n format,\n })),\n ];\n\n await parallelize(writeOperations, async ({ paths, fileName, format }) =>\n writeDictionaryFiles(paths, fileName, format, configuration)\n );\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AACjC,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,gCAAgC;AACzC,SAAS,uCAAuC;AAChD,SAAS,qCAAqC;AAC9C,SAAS,sCAAsC;AAC/C,SAAS,wCAAwC;AACjD,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AACnC,SAAS,qCAAqC;AAE9C,MAAM,qBAAqB,CAAC,OAAiB,SAAoB;AAC/D,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,MAAM;AAAA,IAAO,CAAC,SACnB,KAAK,KAAK,CAAC,QAAQ,KAAK,SAAS,GAAG,GAAG,OAAO,CAAC;AAAA,EACjD;AACF;AAEA,MAAM,uBAAuB,OAC3B,OACA,UACA,QACA,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,UAAU,8BAA8B,OAAO,QAAQ,aAAa;AAC1E,QAAM,YAAY,WAAW,QAAQ,QA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import { Locales, getConfiguration, normalizePath } from "@intlayer/config";
|
|
2
2
|
import fg from "fast-glob";
|
|
3
|
-
import { mkdir
|
|
3
|
+
import { mkdir } from "fs/promises";
|
|
4
4
|
import { basename, extname, join, relative } from "path";
|
|
5
5
|
import { getFileHash } from "../../utils/getFileHash.mjs";
|
|
6
6
|
import { kebabCaseToCamelCase } from "../../utils/kebabCaseToCamelCase.mjs";
|
|
7
|
+
import { writeFileIfChanged } from "../../writeFileIfChanged.mjs";
|
|
7
8
|
const getTypeName = (key) => `${kebabCaseToCamelCase(key)}Content`;
|
|
8
9
|
const formatLocales = (locales) => locales.map((locale) => {
|
|
9
10
|
for (const key in Locales) {
|
|
@@ -66,7 +67,8 @@ const createModuleAugmentation = async (configuration = getConfiguration()) => {
|
|
|
66
67
|
}
|
|
67
68
|
);
|
|
68
69
|
const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);
|
|
69
|
-
|
|
70
|
+
const tsFilePath = join(moduleAugmentationDir, "intlayer.d.ts");
|
|
71
|
+
await writeFileIfChanged(tsFilePath, tsContent);
|
|
70
72
|
};
|
|
71
73
|
export {
|
|
72
74
|
createModuleAugmentation,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { Locales, getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { mkdir
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { Locales, getConfiguration, normalizePath } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { mkdir } from 'fs/promises';\nimport { basename, extname, join, relative } from 'path';\nimport { getFileHash } from '../../utils/getFileHash';\nimport { kebabCaseToCamelCase } from '../../utils/kebabCaseToCamelCase';\nimport { writeFileIfChanged } from '../../writeFileIfChanged';\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\nconst formatLocales = (locales: Locales[]): string =>\n locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (\n typeFiles: string[],\n configuration = getConfiguration()\n): string => {\n const { content, internationalization } = configuration;\n const { moduleAugmentationDir } = content;\n const { locales, requiredLocales, strictMode } = internationalization;\n\n let fileContent =\n \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id (without the extension)\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n fileContent += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n });\n\n fileContent += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": typeof ${dictionary.hash};`)\n .join('\\n');\n\n const requiredLocalesValues =\n requiredLocales.length > 0\n ? requiredLocales.filter((locale) =>\n locales.map((locale) => String(locale)).includes(String(locale))\n )\n : locales;\n\n const formattedLocales = formatLocales(locales);\n const formattedRequiredLocales = formatLocales(requiredLocalesValues);\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<DeclaredLocales, Content> {}`\n : strictMode === 'inclusive'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n fileContent += `declare module 'intlayer' {\\n`;\n fileContent += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n fileContent += ` type DeclaredLocales = ${formattedLocales};\\n`;\n fileContent += ` type RequiredLocales = ${formattedRequiredLocales};\\n`;\n fileContent += ` type ExtractedLocales = Extract<Locales, RequiredLocales>;\\n`;\n fileContent += ` type ExcludedLocales = Exclude<Locales, RequiredLocales>;\\n`;\n fileContent += ` ${strictModeRecord}\\n`;\n fileContent += `}`;\n\n return fileContent;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = async (\n configuration = getConfiguration()\n) => {\n const { moduleAugmentationDir, typesDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n await mkdir(moduleAugmentationDir, { recursive: true });\n\n const dictionariesTypesDefinitions: string[] = fg.sync(\n normalizePath(`${typesDir}/*.ts`),\n {\n ignore: ['**/*.d.ts'],\n }\n );\n\n // Create the dictionary list file\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n\n const tsFilePath = join(moduleAugmentationDir, 'intlayer.d.ts');\n\n await writeFileIfChanged(tsFilePath, tsContent);\n};\n"],"mappings":"AAAA,SAAS,SAAS,kBAAkB,qBAAqB;AACzD,OAAO,QAAQ;AACf,SAAS,aAAa;AACtB,SAAS,UAAU,SAAS,MAAM,gBAAgB;AAClD,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AACrC,SAAS,0BAA0B;AAE5B,MAAM,cAAc,CAAC,QAC1B,GAAG,qBAAqB,GAAG,CAAC;AAE9B,MAAM,gB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B,wBAAwB;AAAA;AACnE,iBAAe;AAAA;AACf,iBAAe;AAAA;AACf,iBAAe,KAAK,gBAAgB;AAAA;AACpC,iBAAe;AAEf,SAAO;AACT;AAKO,MAAM,2BAA2B,OACtC,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,EAAE,uBAAuB,SAAS,IAAI,cAAc;AAG1D,QAAM,MAAM,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAEtD,QAAM,+BAAyC,GAAG;AAAA,IAChD,cAAc,GAAG,QAAQ,OAAO;AAAA,IAChC;AAAA,MACE,QAAQ,CAAC,WAAW;AAAA,IACtB;AAAA,EACF;AAGA,QAAM,YAAY,yBAAyB,4BAA4B;AAEvE,QAAM,aAAa,KAAK,uBAAuB,eAAe;AAE9D,QAAM,mBAAmB,YAAY,SAAS;AAChD;","names":["locale"]}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import { writeFetchDictionary } from "./writeFetchDictionary.mjs";
|
|
6
6
|
import { writeMergedDictionaries } from "./writeMergedDictionary.mjs";
|
|
7
7
|
import { writeUnmergedDictionaries } from "./writeUnmergedDictionary.mjs";
|
|
8
|
-
const
|
|
8
|
+
const buildDictionary = async (localDictionariesEntries, configuration = getConfiguration(), formats = ["cjs", "esm"]) => {
|
|
9
9
|
const { importMode } = configuration.build;
|
|
10
10
|
const unmergedDictionaries = await writeUnmergedDictionaries(
|
|
11
11
|
localDictionariesEntries,
|
|
@@ -39,6 +39,6 @@ const buildIntlayerDictionary = async (localDictionariesEntries, configuration =
|
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
41
|
export {
|
|
42
|
-
|
|
42
|
+
buildDictionary
|
|
43
43
|
};
|
|
44
44
|
//# sourceMappingURL=buildIntlayerDictionary.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlayer_dictionary/buildIntlayerDictionary.ts"],"sourcesContent":["// @ts-ignore: @intlayer/backend is not built yet\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport {\n LocalizedDictionaryOutput,\n writeDynamicDictionary,\n} from './writeDynamicDictionary';\nimport { writeFetchDictionary } from './writeFetchDictionary';\nimport { writeMergedDictionaries } from './writeMergedDictionary';\nimport { writeUnmergedDictionaries } from './writeUnmergedDictionary';\n\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const buildDictionary = async (\n localDictionariesEntries: Dictionary[],\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n) => {\n const { importMode } = configuration.build;\n\n const unmergedDictionaries = await writeUnmergedDictionaries(\n localDictionariesEntries,\n configuration\n );\n\n const mergedDictionaries = await writeMergedDictionaries(\n unmergedDictionaries,\n configuration\n );\n\n let dynamicDictionaries: LocalizedDictionaryOutput | null = null;\n\n if (importMode === 'dynamic' || importMode === 'live') {\n dynamicDictionaries = await writeDynamicDictionary(\n mergedDictionaries,\n configuration,\n formats\n );\n }\n\n let fetchDictionaries: LocalizedDictionaryOutput | null = null;\n\n if (importMode === 'live') {\n fetchDictionaries = await writeFetchDictionary(\n dynamicDictionaries!,\n configuration,\n formats\n );\n }\n\n return {\n unmergedDictionaries,\n mergedDictionaries,\n dynamicDictionaries,\n fetchDictionaries,\n };\n};\n"],"mappings":"AACA,SAAS,wBAAwB;AAEjC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AACxC,SAAS,iCAAiC;AAKnC,MAAM,kBAAkB,OAC7B,0BACA,gBAAgB,iBAAiB,GACjC,UAA6B,CAAC,OAAO,KAAK,MACvC;AACH,QAAM,EAAE,WAAW,IAAI,cAAc;AAErC,QAAM,uBAAuB,MAAM;AAAA,IACjC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,qBAAqB,MAAM;AAAA,IAC/B;AAAA,IACA;AAAA,EACF;AAEA,MAAI,sBAAwD;AAE5D,MAAI,eAAe,aAAa,eAAe,QAAQ;AACrD,0BAAsB,MAAM;AAAA,MAC1B;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,oBAAsD;AAE1D,MAAI,eAAe,QAAQ;AACzB,wBAAoB,MAAM;AAAA,MACxB;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlayer_dictionary/index.ts"],"sourcesContent":["export * from './buildIntlayerDictionary';\nexport * from './processContentDeclaration';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from "@intlayer/config/client";
|
|
2
|
-
import { resolveObjectPromises } from "
|
|
2
|
+
import { resolveObjectPromises } from "../../utils/resolveObjectPromises.mjs";
|
|
3
3
|
const processContentDeclaration = async (contentDeclaration) => {
|
|
4
4
|
try {
|
|
5
5
|
const content = await resolveObjectPromises(
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlayer_dictionary/processContentDeclaration.ts"],"sourcesContent":["import { logger } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport { resolveObjectPromises } from '../../utils/resolveObjectPromises';\n\n/**\n * Function to load, process the module and return the Intlayer Dictionary from the module file\n */\nexport const processContentDeclaration = async (\n contentDeclaration: Dictionary\n): Promise<Dictionary | undefined> => {\n try {\n const content = (await resolveObjectPromises(\n contentDeclaration.content\n )) as Dictionary['content'];\n\n return {\n ...contentDeclaration,\n content,\n } as Dictionary;\n } catch (error) {\n logger(error, {\n level: 'error',\n });\n }\n};\n"],"mappings":"AAAA,SAAS,cAAc;AAEvB,SAAS,6BAA6B;AAK/B,MAAM,4BAA4B,OACvC,uBACoC;AACpC,MAAI;AACF,UAAM,UAAW,MAAM;AAAA,MACrB,mBAAmB;AAAA,IACrB;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,WAAO,OAAO;AAAA,MACZ,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
colorizePath,
|
|
3
|
+
getConfiguration,
|
|
4
|
+
normalizePath
|
|
5
|
+
} from "@intlayer/config";
|
|
2
6
|
import { getLocalisedContent } from "@intlayer/core";
|
|
3
|
-
import { mkdir
|
|
7
|
+
import { mkdir } from "fs/promises";
|
|
4
8
|
import { relative, resolve } from "path";
|
|
5
|
-
import { parallelize } from "
|
|
6
|
-
import {
|
|
9
|
+
import { parallelize } from "../../utils/parallelize.mjs";
|
|
10
|
+
import { writeFileIfChanged } from "../../writeFileIfChanged.mjs";
|
|
11
|
+
import { writeJsonIfChanged } from "../../writeJsonIfChanged.mjs";
|
|
7
12
|
const generateDictionaryEntryPoint = (localedDictionariesPathsRecord, format = "esm", configuration = getConfiguration()) => {
|
|
8
13
|
const { dynamicDictionariesDir } = configuration.content;
|
|
9
14
|
let content = "";
|
|
10
15
|
const formattedDictionaryMap = Object.entries(
|
|
11
16
|
localedDictionariesPathsRecord
|
|
12
|
-
).map(([locale, dictionary]) => {
|
|
17
|
+
).filter((entry) => Boolean(entry[1])).sort(([a], [b]) => String(a).localeCompare(String(b))).map(([locale, dictionary]) => {
|
|
13
18
|
const relativePath = normalizePath(
|
|
14
19
|
relative(dynamicDictionariesDir, dictionary.dictionaryPath)
|
|
15
20
|
);
|
|
@@ -34,7 +39,9 @@ const writeDynamicDictionary = async (mergedDictionaries, configuration = getCon
|
|
|
34
39
|
await mkdir(resolve(dynamicDictionariesDir), { recursive: true });
|
|
35
40
|
let resultDictionariesPaths = {};
|
|
36
41
|
await parallelize(
|
|
37
|
-
Object.entries(mergedDictionaries)
|
|
42
|
+
Object.entries(mergedDictionaries).sort(
|
|
43
|
+
([a], [b]) => String(a).localeCompare(String(b))
|
|
44
|
+
),
|
|
38
45
|
async ([key, dictionaryEntry]) => {
|
|
39
46
|
if (key === "undefined") return;
|
|
40
47
|
let localedDictionariesPathsRecord = {};
|
|
@@ -50,12 +57,13 @@ const writeDynamicDictionary = async (mergedDictionaries, configuration = getCon
|
|
|
50
57
|
defaultLocale
|
|
51
58
|
)
|
|
52
59
|
};
|
|
53
|
-
const contentString = formatDictionaryText(localizedDictionary);
|
|
54
60
|
const outputFileName = `${key}.${locale}.json`;
|
|
55
61
|
const resultFilePath = resolve(dynamicDictionariesDir, outputFileName);
|
|
56
|
-
await
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
await writeJsonIfChanged(resultFilePath, localizedDictionary).catch(
|
|
63
|
+
(err) => {
|
|
64
|
+
console.error(`Error creating localized ${outputFileName}:`, err);
|
|
65
|
+
}
|
|
66
|
+
);
|
|
59
67
|
localedDictionariesPathsRecord[locale] = {
|
|
60
68
|
dictionaryPath: resultFilePath,
|
|
61
69
|
dictionary: localizedDictionary
|
|
@@ -69,10 +77,15 @@ const writeDynamicDictionary = async (mergedDictionaries, configuration = getCon
|
|
|
69
77
|
format,
|
|
70
78
|
configuration
|
|
71
79
|
);
|
|
72
|
-
await
|
|
80
|
+
await writeFileIfChanged(
|
|
73
81
|
resolve(dynamicDictionariesDir, `${key}.${extension}`),
|
|
74
82
|
content
|
|
75
|
-
)
|
|
83
|
+
).catch((err) => {
|
|
84
|
+
console.error(
|
|
85
|
+
`Error creating dynamic ${colorizePath(resolve(dynamicDictionariesDir, `${key}.${extension}`))}:`,
|
|
86
|
+
err
|
|
87
|
+
);
|
|
88
|
+
});
|
|
76
89
|
});
|
|
77
90
|
}
|
|
78
91
|
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlayer_dictionary/writeDynamicDictionary.ts"],"sourcesContent":["import {\n colorizePath,\n getConfiguration,\n Locales,\n normalizePath,\n} from '@intlayer/config';\nimport { getLocalisedContent, type Dictionary } from '@intlayer/core';\nimport { mkdir } from 'fs/promises';\nimport { relative, resolve } from 'path';\nimport { parallelize } from '../../utils/parallelize';\nimport { writeFileIfChanged } from '../../writeFileIfChanged';\nimport { writeJsonIfChanged } from '../../writeJsonIfChanged';\nimport { MergedDictionaryOutput } from './writeMergedDictionary';\n\nexport type DictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type LocalizedDictionaryResult = Partial<\n Record<Locales, DictionaryResult>\n>;\n\nexport type LocalizedDictionaryOutput = Record<\n string,\n LocalizedDictionaryResult\n>;\n\n/**\n * This function generates the content of the dictionary list file\n */\nexport const generateDictionaryEntryPoint = (\n localedDictionariesPathsRecord: LocalizedDictionaryResult,\n format: 'cjs' | 'esm' = 'esm',\n configuration = getConfiguration()\n): string => {\n const { dynamicDictionariesDir } = configuration.content;\n\n let content = '';\n\n // Format Dictionary Map - map locales to functions\n const formattedDictionaryMap: string = Object.entries(\n localedDictionariesPathsRecord\n )\n // The following filter/sort preserve determinism of the generated map\n // when files are built in parallel or across different Node versions.\n .filter((entry): entry is [string, DictionaryResult] => Boolean(entry[1]))\n .sort(([a], [b]) => String(a).localeCompare(String(b)))\n .map(([locale, dictionary]) => {\n const relativePath = normalizePath(\n relative(dynamicDictionariesDir, dictionary.dictionaryPath)\n );\n\n if (format === 'esm') {\n return ` '${locale}': () => import('./${relativePath}', { assert: { type: 'json' }}).then(mod => mod.default)`;\n }\n\n return ` '${locale}': () => Promise.resolve(require('./${relativePath}'))`;\n })\n .join(',\\n');\n\n content += `const content = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n if (format === 'esm') content += `export default content;\\n`;\n if (format === 'cjs') content += `module.exports = content;\\n`;\n\n return content;\n};\n\n/**\n * Write the localized dictionaries to the dictionariesDir\n * @param mergedDictionaries - The merged dictionaries\n * @param configuration - The configuration\n * @returns The final dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/dynamic_dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeDynamicDictionary = async (\n mergedDictionaries: MergedDictionaryOutput,\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n): Promise<LocalizedDictionaryOutput> => {\n const { locales, defaultLocale } = configuration.internationalization;\n const { dynamicDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dynamicDictionariesDir), { recursive: true });\n\n let resultDictionariesPaths: LocalizedDictionaryOutput = {};\n\n // Merge dictionaries with the same key and write to dictionariesDir\n await parallelize(\n Object.entries(mergedDictionaries).sort(([a], [b]) =>\n String(a).localeCompare(String(b))\n ),\n async ([key, dictionaryEntry]) => {\n if (key === 'undefined') return;\n\n let localedDictionariesPathsRecord: LocalizedDictionaryResult = {};\n\n await parallelize(locales, async (locale) => {\n const localizedDictionary = {\n ...dictionaryEntry.dictionary,\n locale,\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n content: getLocalisedContent(\n JSON.parse(JSON.stringify(dictionaryEntry.dictionary.content)),\n locale,\n { dictionaryKey: key, keyPath: [] },\n defaultLocale\n ) as any,\n };\n\n const outputFileName = `${key}.${locale}.json`;\n const resultFilePath = resolve(dynamicDictionariesDir, outputFileName);\n\n // Write the localized dictionary\n await writeJsonIfChanged(resultFilePath, localizedDictionary).catch(\n (err) => {\n console.error(`Error creating localized ${outputFileName}:`, err);\n }\n );\n\n localedDictionariesPathsRecord[locale] = {\n dictionaryPath: resultFilePath,\n dictionary: localizedDictionary,\n };\n });\n\n resultDictionariesPaths[key] = localedDictionariesPathsRecord;\n\n await parallelize(formats, async (format) => {\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n const content = generateDictionaryEntryPoint(\n localedDictionariesPathsRecord,\n format,\n configuration\n );\n\n await writeFileIfChanged(\n resolve(dynamicDictionariesDir, `${key}.${extension}`),\n content\n ).catch((err) => {\n console.error(\n `Error creating dynamic ${colorizePath(resolve(dynamicDictionariesDir, `${key}.${extension}`))}:`,\n err\n );\n });\n });\n }\n );\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,2BAA4C;AACrD,SAAS,aAAa;AACtB,SAAS,UAAU,eAAe;AAClC,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AAoB5B,MAAM,+BAA+B,CAC1C,gCACA,SAAwB,OACxB,gBAAgB,iBAAiB,MACtB;AACX,QAAM,EAAE,uBAAuB,IAAI,cAAc;AAEjD,MAAI,UAAU;AAGd,QAAM,yBAAiC,OAAO;AAAA,IAC5C;AAAA,EACF,EAGG,OAAO,CAAC,UAA+C,QAAQ,MAAM,CAAC,CAAC,CAAC,EACxE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,OAAO,CAAC,EAAE,cAAc,OAAO,CAAC,CAAC,CAAC,EACrD,IAAI,CAAC,CAAC,QAAQ,UAAU,MAAM;AAC7B,UAAM,eAAe;AAAA,MACnB,SAAS,wBAAwB,WAAW,cAAc;AAAA,IAC5D;AAEA,QAAI,WAAW,OAAO;AACpB,aAAO,MAAM,MAAM,sBAAsB,YAAY;AAAA,IACvD;AAEA,WAAO,MAAM,MAAM,uCAAuC,YAAY;AAAA,EACxE,CAAC,EACA,KAAK,KAAK;AAEb,aAAW;AAAA,EAAsB,sBAAsB;AAAA;AAAA;AAEvD,MAAI,WAAW,MAAO,YAAW;AAAA;AACjC,MAAI,WAAW,MAAO,YAAW;AAAA;AAEjC,SAAO;AACT;AAkBO,MAAM,yBAAyB,OACpC,oBACA,gBAAgB,iBAAiB,GACjC,UAA6B,CAAC,OAAO,KAAK,MACH;AACvC,QAAM,EAAE,SAAS,cAAc,IAAI,cAAc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AAAA,QACF,EAAE,MAAM,CAAC,QAAQ;AACf,kBAAQ;AAAA,YACN,0BAA0B,aAAa,QAAQ,wBAAwB,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC,CAAC;AAAA,YAC9F;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
colorizePath,
|
|
3
|
+
getConfiguration,
|
|
4
|
+
normalizePath
|
|
5
|
+
} from "@intlayer/config";
|
|
6
|
+
import { mkdir } from "fs/promises";
|
|
3
7
|
import { relative, resolve } from "path";
|
|
4
|
-
import { parallelize } from "
|
|
8
|
+
import { parallelize } from "../../utils/parallelize.mjs";
|
|
9
|
+
import { writeFileIfChanged } from "../../writeFileIfChanged.mjs";
|
|
5
10
|
const generateDictionaryEntryPoint = (localedDictionariesPathsRecord, format = "esm", configuration = getConfiguration()) => {
|
|
6
11
|
const { fetchDictionariesDir } = configuration.content;
|
|
7
12
|
const { liveSyncURL } = configuration.editor;
|
|
@@ -42,10 +47,15 @@ const writeFetchDictionary = async (dynamicDictionaries, configuration = getConf
|
|
|
42
47
|
format,
|
|
43
48
|
configuration
|
|
44
49
|
);
|
|
45
|
-
await
|
|
50
|
+
await writeFileIfChanged(
|
|
46
51
|
resolve(fetchDictionariesDir, `${key}.${extension}`),
|
|
47
52
|
content
|
|
48
|
-
)
|
|
53
|
+
).catch((err) => {
|
|
54
|
+
console.error(
|
|
55
|
+
`Error creating fetch ${colorizePath(resolve(fetchDictionariesDir, `${key}.${extension}`))}:`,
|
|
56
|
+
err
|
|
57
|
+
);
|
|
58
|
+
});
|
|
49
59
|
});
|
|
50
60
|
}
|
|
51
61
|
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlayer_dictionary/writeFetchDictionary.ts"],"sourcesContent":["import {\n colorizePath,\n getConfiguration,\n normalizePath,\n} from '@intlayer/config';\nimport { mkdir } from 'fs/promises';\nimport { relative, resolve } from 'path';\nimport { parallelize } from '../../utils/parallelize';\nimport { writeFileIfChanged } from '../../writeFileIfChanged';\nimport type {\n LocalizedDictionaryOutput,\n LocalizedDictionaryResult,\n} from './writeDynamicDictionary';\n\n/**\n * This function generates the content of the dictionary list file\n */\nexport const generateDictionaryEntryPoint = (\n localedDictionariesPathsRecord: LocalizedDictionaryResult,\n format: 'cjs' | 'esm' = 'esm',\n configuration = getConfiguration()\n): string => {\n const { fetchDictionariesDir } = configuration.content;\n const { liveSyncURL } = configuration.editor;\n\n let content = '';\n\n const formattedDictionaryMap: string = Object.entries(\n localedDictionariesPathsRecord\n )\n .map(([locale, dictionary]) => {\n const relativePath = normalizePath(\n relative(fetchDictionariesDir, dictionary.dictionaryPath)\n );\n\n if (format === 'esm') {\n return ` '${locale}': () => (async () => { try {return await fetch('${liveSyncURL}/dictionaries/${dictionary.dictionary.key}/${locale}').then(res => res.json())} catch (_error) {return await import('./${relativePath}', { assert: { type: 'json' }}).then(mod => mod.default)}})()`;\n }\n\n return ` '${locale}': () => (async () => { try {return await fetch('${liveSyncURL}/dictionaries/${dictionary.dictionary.key}/${locale}').then(res => res.json())} catch (_error) {return Promise.resolve(require('./${relativePath}'))}})()`;\n })\n .join(',\\n');\n\n content += `const content = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n if (format === 'esm') content += `export default content;\\n`;\n if (format === 'cjs') content += `module.exports = content;\\n`;\n\n return content;\n};\n\n/**\n * Write the localized dictionaries to the dictionariesDir\n * @param mergedDictionaries - The merged dictionaries\n * @param configuration - The configuration\n * @returns The final dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/fetch_dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeFetchDictionary = async (\n dynamicDictionaries: LocalizedDictionaryOutput,\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n): Promise<LocalizedDictionaryOutput> => {\n const { fetchDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(fetchDictionariesDir), { recursive: true });\n\n let resultDictionariesPaths: LocalizedDictionaryOutput = {};\n\n // Write entry points for each dictionary in parallel\n await parallelize(\n Object.entries(dynamicDictionaries),\n async ([key, localedDictionariesPathsRecord]) => {\n if (key === 'undefined') return;\n\n await parallelize(formats, async (format) => {\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n const content = generateDictionaryEntryPoint(\n localedDictionariesPathsRecord,\n format,\n configuration\n );\n\n await writeFileIfChanged(\n resolve(fetchDictionariesDir, `${key}.${extension}`),\n content\n ).catch((err) => {\n console.error(\n `Error creating fetch ${colorizePath(resolve(fetchDictionariesDir, `${key}.${extension}`))}:`,\n err\n );\n });\n });\n }\n );\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa;AACtB,SAAS,UAAU,eAAe;AAClC,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AAS5B,MAAM,+BAA+B,CAC1C,gCACA,SAAwB,OACxB,gBAAgB,iBAAiB,MACtB;AACX,QAAM,EAAE,qBAAqB,IAAI,cAAc;AAC/C,QAAM,EAAE,YAAY,IAAI,cAAc;AAEtC,MAAI,UAAU;AAEd,QAAM,yBAAiC,OAAO;AAAA,IAC5C;AAAA,EACF,EACG,IAAI,CAAC,CAAC,QAAQ,UAAU,MAAM;AAC7B,UAAM,eAAe;AAAA,MACnB,SAAS,sBAAsB,WAAW,cAAc;AAAA,IAC1D;AAEA,QAAI,WAAW,OAAO;AACpB,aAAO,MAAM,MAAM,oDAAoD,WAAW,iBAAiB,WAAW,WAAW,GAAG,IAAI,MAAM,sEAAsE,YAAY;AAAA,IAC1N;AAEA,WAAO,MAAM,MAAM,oDAAoD,WAAW,iBAAiB,WAAW,WAAW,GAAG,IAAI,MAAM,iFAAiF,YAAY;AAAA,EACrO,CAAC,EACA,KAAK,KAAK;AAEb,aAAW;AAAA,EAAsB,sBAAsB;AAAA;AAAA;AAEvD,MAAI,WAAW,MAAO,YAAW;AAAA;AACjC,MAAI,WAAW,MAAO,YAAW;AAAA;AAEjC,SAAO;AACT;AAkBO,MAAM,uBAAuB,OAClC,qBACA,gBAAgB,iBAAiB,GACjC,UAA6B,CAAC,OAAO,KAAK,MACH;AACvC,QAAM,EAAE,qBAAqB,IAAI,cAAc;AAG/C,QAAM,MAAM,QAAQ,oBAAoB,GAAG,EAAE,WAAW,KAAK,CAAC;AAE9D,MAAI,0BAAqD,CAAC;AAG1D,QAAM;AAAA,IACJ,OAAO,QAAQ,mBAAmB;AAAA,IAClC,OAAO,CAAC,KAAK,8BAA8B,MAAM;AAC/C,UAAI,QAAQ,YAAa;AAEzB,YAAM,YAAY,SAAS,OAAO,WAAW;AAC3C,cAAM,YAAY,WAAW,QAAQ,QAAQ;AAC7C,cAAM,UAAU;AAAA,UACd;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,cAAM;AAAA,UACJ,QAAQ,sBAAsB,GAAG,GAAG,IAAI,SAAS,EAAE;AAAA,UACnD;AAAA,QACF,EAAE,MAAM,CAAC,QAAQ;AACf,kBAAQ;AAAA,YACN,wBAAwB,aAAa,QAAQ,sBAAsB,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC,CAAC;AAAA,YAC1F;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { getConfiguration } from "@intlayer/config";
|
|
2
|
-
import { mkdir
|
|
1
|
+
import { colorizePath, getConfiguration } from "@intlayer/config";
|
|
2
|
+
import { mkdir } from "fs/promises";
|
|
3
3
|
import { resolve } from "path";
|
|
4
|
-
import { mergeDictionaries } from "
|
|
5
|
-
import { processPerLocaleDictionary } from "
|
|
6
|
-
import { parallelize } from "
|
|
7
|
-
import {
|
|
4
|
+
import { mergeDictionaries } from "../../mergeDictionaries.mjs";
|
|
5
|
+
import { processPerLocaleDictionary } from "../../processPerLocaleDictionary.mjs";
|
|
6
|
+
import { parallelize } from "../../utils/parallelize.mjs";
|
|
7
|
+
import { writeJsonIfChanged } from "../../writeJsonIfChanged.mjs";
|
|
8
8
|
const writeMergedDictionaries = async (groupedDictionaries, configuration = getConfiguration()) => {
|
|
9
9
|
const { dictionariesDir } = configuration.content;
|
|
10
10
|
await mkdir(resolve(dictionariesDir), { recursive: true });
|
|
@@ -18,12 +18,16 @@ const writeMergedDictionaries = async (groupedDictionaries, configuration = getC
|
|
|
18
18
|
(dictionary) => processPerLocaleDictionary(dictionary)
|
|
19
19
|
);
|
|
20
20
|
const mergedDictionary = mergeDictionaries(multiLocaleDictionaries);
|
|
21
|
-
const contentString = formatDictionaryText(mergedDictionary);
|
|
22
21
|
const outputFileName = `${key}.json`;
|
|
23
22
|
const resultFilePath = resolve(dictionariesDir, outputFileName);
|
|
24
|
-
await
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
await writeJsonIfChanged(resultFilePath, mergedDictionary).catch(
|
|
24
|
+
(err) => {
|
|
25
|
+
console.error(
|
|
26
|
+
`Error creating merged ${colorizePath(resultFilePath)}:`,
|
|
27
|
+
err
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
);
|
|
27
31
|
return [
|
|
28
32
|
key,
|
|
29
33
|
{
|