@intlayer/chokidar 5.8.1 → 6.0.0-canary.1
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} +11 -19
- 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 +13 -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 +108 -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/dictionaryStatus.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 +6 -2
- 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/fetchDistantDictionaryKeysAndUpdateTimestamp.mjs +21 -0
- 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 +10 -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 +73 -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 +6 -2
- 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 +4 -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/dictionaryStatus.d.ts +1 -1
- package/dist/types/writeContentDeclaration/dictionaryStatus.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 +17 -15
- 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 +0 -29
- 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,26 +1,69 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ESMxCJSRequire,
|
|
3
|
+
getConfiguration,
|
|
4
|
+
loadExternalFile
|
|
5
|
+
} from "@intlayer/config";
|
|
6
|
+
import { relative } from "path";
|
|
7
|
+
import { filterInvalidDictionaries } from "../filterInvalidDictionaries.mjs";
|
|
2
8
|
import { processContentDeclaration } from "../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
import { parallelize } from "../utils/parallelize.mjs";
|
|
10
|
+
const formatLocalDictionaries = (dictionariesRecord) => Object.entries(dictionariesRecord).map(([relativePath, dict]) => ({
|
|
11
|
+
...dict,
|
|
12
|
+
localId: `${dict.key}::local::${relativePath}`,
|
|
13
|
+
location: "locale",
|
|
14
|
+
filePath: relativePath
|
|
15
|
+
}));
|
|
16
|
+
const loadContentDeclarations = async (contentDeclarationFilePath, configuration = getConfiguration(), projectRequire = ESMxCJSRequire, onStatusUpdate) => {
|
|
17
|
+
const dictionariesRecord = contentDeclarationFilePath.reduce(
|
|
18
|
+
(acc, path) => {
|
|
19
|
+
const relativePath = relative(configuration.content.baseDir, path);
|
|
20
|
+
return {
|
|
21
|
+
...acc,
|
|
22
|
+
[relativePath]: loadExternalFile(path, void 0, projectRequire)
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
{}
|
|
26
|
+
);
|
|
27
|
+
const contentDeclarations = formatLocalDictionaries(dictionariesRecord);
|
|
28
|
+
const listFoundDictionaries = contentDeclarations.map((declaration) => ({
|
|
29
|
+
dictionaryKey: declaration.key,
|
|
30
|
+
type: "local",
|
|
31
|
+
status: "found"
|
|
7
32
|
}));
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
33
|
+
onStatusUpdate?.(listFoundDictionaries);
|
|
34
|
+
const processedDictionaries = await parallelize(
|
|
35
|
+
contentDeclarations,
|
|
36
|
+
async (contentDeclaration) => {
|
|
37
|
+
if (!contentDeclaration) {
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
onStatusUpdate?.([
|
|
41
|
+
{
|
|
42
|
+
dictionaryKey: contentDeclaration.key,
|
|
43
|
+
type: "local",
|
|
44
|
+
status: "building"
|
|
45
|
+
}
|
|
46
|
+
]);
|
|
47
|
+
const processedContentDeclaration = await processContentDeclaration(
|
|
48
|
+
contentDeclaration
|
|
49
|
+
);
|
|
50
|
+
if (!processedContentDeclaration) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
onStatusUpdate?.([
|
|
54
|
+
{
|
|
55
|
+
dictionaryKey: processedContentDeclaration.key,
|
|
56
|
+
type: "local",
|
|
57
|
+
status: "built"
|
|
58
|
+
}
|
|
59
|
+
]);
|
|
60
|
+
return processedContentDeclaration;
|
|
12
61
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
);
|
|
16
|
-
if (!processedContentDeclaration) {
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
resultDictionariesPaths.push(processedContentDeclaration);
|
|
20
|
-
}
|
|
21
|
-
return resultDictionariesPaths;
|
|
62
|
+
);
|
|
63
|
+
return filterInvalidDictionaries(processedDictionaries);
|
|
22
64
|
};
|
|
23
65
|
export {
|
|
66
|
+
formatLocalDictionaries,
|
|
24
67
|
loadContentDeclarations
|
|
25
68
|
};
|
|
26
69
|
//# sourceMappingURL=loadContentDeclaration.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadContentDeclaration.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n getConfiguration,\n IntlayerConfig,\n loadExternalFile,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { relative } from 'path';\nimport { filterInvalidDictionaries } from '../filterInvalidDictionaries';\nimport { processContentDeclaration } from '../transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration';\nimport { parallelize } from '../utils/parallelize';\nimport { DictionariesStatus } from './loadDictionaries';\n\nexport const formatLocalDictionaries = (\n dictionariesRecord: Record<string, Dictionary>\n): Dictionary[] =>\n Object.entries(dictionariesRecord).map(([relativePath, dict]) => ({\n ...dict,\n localId: `${dict.key}::local::${relativePath}`,\n location: 'locale' as const,\n filePath: relativePath,\n }));\n\nexport const loadContentDeclarations = async (\n contentDeclarationFilePath: string[],\n configuration: IntlayerConfig = getConfiguration(),\n projectRequire = ESMxCJSRequire,\n onStatusUpdate?: (status: DictionariesStatus[]) => void\n): Promise<Dictionary[]> => {\n const dictionariesRecord = contentDeclarationFilePath.reduce(\n (acc, path) => {\n const relativePath = relative(configuration.content.baseDir, path);\n return {\n ...acc,\n [relativePath]: loadExternalFile(path, undefined, projectRequire),\n };\n },\n {} as Record<string, Dictionary>\n );\n const contentDeclarations: Dictionary[] =\n formatLocalDictionaries(dictionariesRecord);\n\n const listFoundDictionaries = contentDeclarations.map((declaration) => ({\n dictionaryKey: declaration.key,\n type: 'local' as const,\n status: 'found' as const,\n }));\n\n onStatusUpdate?.(listFoundDictionaries);\n\n const processedDictionaries = await parallelize(\n contentDeclarations,\n async (contentDeclaration): Promise<Dictionary | undefined> => {\n if (!contentDeclaration) {\n return undefined;\n }\n\n onStatusUpdate?.([\n {\n dictionaryKey: contentDeclaration.key,\n type: 'local',\n status: 'building',\n },\n ]);\n\n const processedContentDeclaration = await processContentDeclaration(\n contentDeclaration as Dictionary\n );\n\n if (!processedContentDeclaration) {\n return undefined;\n }\n\n onStatusUpdate?.([\n {\n dictionaryKey: processedContentDeclaration.key,\n type: 'local',\n status: 'built',\n },\n ]);\n\n return processedContentDeclaration;\n }\n );\n\n return filterInvalidDictionaries(processedDictionaries);\n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eAAe,4BAA4B;AAAA,UAC3C,MAAM;AAAA,UACN,QAAQ;AAAA,QACV;AAAA,MACF,CAAC;AAED,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO,0BAA0B,qBAAqB;AACxD;","names":[]}
|
|
@@ -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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M,SAAS,QAAQ,KAAK,GAAG;AAC/B,UAAM,aAAa,QAAQ,KAAK,OAAO;AAEvC,QAAI,CAAC,YAAY;AACf;AAAA,QACE;AAAA,UACE;AAAA,UACA,KAAK,WACD,SAAS,cAAc,QAAQ,SAAS,KAAK,QAAQ,IACrD;AAAA,QACN;AAAA,QACA,EAAE,OAAO,QAAQ;AAAA,MACnB;AAAA,IACF,WAAW,CAAC,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,73 @@
|
|
|
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, remoteUpdatedAt]) => {
|
|
21
|
+
if (!remoteUpdatedAt) return true;
|
|
22
|
+
const local = remoteDictionariesRecord[dictionaryKey];
|
|
23
|
+
if (!local) return true;
|
|
24
|
+
const localUpdatedAtRaw = local?.updatedAt;
|
|
25
|
+
const localUpdatedAt = typeof localUpdatedAtRaw === "number" ? localUpdatedAtRaw : localUpdatedAtRaw ? new Date(localUpdatedAtRaw).getTime() : void 0;
|
|
26
|
+
if (typeof localUpdatedAt !== "number") return true;
|
|
27
|
+
return remoteUpdatedAt > localUpdatedAt;
|
|
28
|
+
}).map(([dictionaryKey]) => dictionaryKey);
|
|
29
|
+
const cachedDictionaries = Object.entries(remoteDictionariesRecord).filter(([key, dictionary]) => {
|
|
30
|
+
const remoteUpdatedAt = distantDictionaryUpdateTimeStamp[key];
|
|
31
|
+
const localUpdatedAtRaw = dictionary?.updatedAt;
|
|
32
|
+
const localUpdatedAt = typeof localUpdatedAtRaw === "number" ? localUpdatedAtRaw : localUpdatedAtRaw ? new Date(localUpdatedAtRaw).getTime() : void 0;
|
|
33
|
+
return typeof localUpdatedAt === "number" && typeof remoteUpdatedAt === "number" && localUpdatedAt >= remoteUpdatedAt;
|
|
34
|
+
}).map(([, dictionary]) => dictionary);
|
|
35
|
+
if (cachedDictionaries.length > 0) {
|
|
36
|
+
onStatusUpdate?.(
|
|
37
|
+
cachedDictionaries.map((d) => ({
|
|
38
|
+
dictionaryKey: d.key,
|
|
39
|
+
type: "remote",
|
|
40
|
+
status: "imported"
|
|
41
|
+
}))
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
const orderedDistantDictionaryKeys = dictionariesKeysToFetch.sort(sortAlphabetically);
|
|
45
|
+
if (orderedDistantDictionaryKeys.length > 0) {
|
|
46
|
+
onStatusUpdate?.(
|
|
47
|
+
orderedDistantDictionaryKeys.map((key) => ({
|
|
48
|
+
dictionaryKey: key,
|
|
49
|
+
type: "remote",
|
|
50
|
+
status: "pending"
|
|
51
|
+
}))
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const distantDictionariesData = await fetchDistantDictionaries(
|
|
55
|
+
{
|
|
56
|
+
dictionaryKeys: orderedDistantDictionaryKeys
|
|
57
|
+
},
|
|
58
|
+
onStatusUpdate
|
|
59
|
+
);
|
|
60
|
+
const distantDictionaries = formatDistantDictionaries(
|
|
61
|
+
distantDictionariesData
|
|
62
|
+
);
|
|
63
|
+
return [...cachedDictionaries, ...distantDictionaries];
|
|
64
|
+
} catch (error) {
|
|
65
|
+
appLogger(`${x} Failed to fetch distant dictionaries`, { level: "error" });
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
export {
|
|
70
|
+
formatDistantDictionaries,
|
|
71
|
+
loadRemoteDictionaries
|
|
72
|
+
};
|
|
73
|
+
//# 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, remoteUpdatedAt]) => {\n // If remote doesn't provide updatedAt, fetch to be safe\n if (!remoteUpdatedAt) return true;\n\n // If no local cache exists, fetch\n const local = (remoteDictionariesRecord as any)[dictionaryKey];\n if (!local) return true;\n\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n\n // If local timestamp missing or older than remote, fetch\n if (typeof localUpdatedAt !== 'number') return true;\n return remoteUpdatedAt > localUpdatedAt;\n })\n .map(([dictionaryKey]) => dictionaryKey);\n\n const cachedDictionaries = Object.entries(remoteDictionariesRecord)\n .filter(([key, dictionary]) => {\n const remoteUpdatedAt = distantDictionaryUpdateTimeStamp[key];\n const localUpdatedAtRaw = (dictionary as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n // Consider as cached/imported when local exists and is up-to-date or newer\n return (\n typeof localUpdatedAt === 'number' &&\n typeof remoteUpdatedAt === 'number' &&\n localUpdatedAt >= remoteUpdatedAt\n );\n })\n .map(([, dictionary]) => dictionary as any);\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,mBAC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;AAGjD,QAAI,6BAA6B,SAAS,GAAG;AAC3C;AAAA,QACE,6BAA6B,IAAI,CAAC,SAAS;AAAA,UACzC,eAAe;AAAA,UACf,MAAM;AAAA,UACN,QAAQ;AAAA,QACV,EAAE;AAAA,MACJ;AAAA,IACF;AAEA,UAAM,0BAA0B,MAAM;AAAA,MACpC;AAAA,QACE,gBAAgB;AAAA,MAClB;AAAA,MACA;AAAA,IACF;AAEA,UAAM,sBAAuC;AAAA,MAC3C;AAAA,IACF;AAEA,WAAO,CAAC,GAAG,oBAAoB,GAAG,mBAAmB;AAAA,EACvD,SAAS,OAAO;AACd,cAAU,GAAG,CAAC,yCAAyC,EAAE,OAAO,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,E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