@intlayer/chokidar 5.8.1 → 6.0.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/chokidar/watcher.cjs +15 -20
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/fetchDistantDictionaries.cjs +18 -37
- package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/{fetchDistantDictionaryKeys.cjs → fetchDistantDictionaryKeysAndUpdateTimestamp.cjs} +10 -10
- package/dist/cjs/fetchDistantDictionaryKeysAndUpdateTimestamp.cjs.map +1 -0
- package/dist/cjs/filterInvalidDictionaries.cjs +70 -0
- package/dist/cjs/filterInvalidDictionaries.cjs.map +1 -0
- package/dist/cjs/getBuiltFetchDictionariesPath.cjs +52 -0
- package/dist/cjs/getBuiltFetchDictionariesPath.cjs.map +1 -0
- package/dist/cjs/getBuiltRemoteDictionariesPath.cjs +51 -0
- package/dist/cjs/getBuiltRemoteDictionariesPath.cjs.map +1 -0
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/index.cjs +4 -4
- package/dist/cjs/loadDictionaries/index.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +57 -17
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +128 -53
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +101 -0
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -0
- package/dist/cjs/loadDictionaries/log.cjs +144 -0
- package/dist/cjs/loadDictionaries/log.cjs.map +1 -0
- package/dist/cjs/mergeDictionaries.cjs +18 -22
- package/dist/cjs/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/orderDictionaries.cjs +71 -0
- package/dist/cjs/orderDictionaries.cjs.map +1 -0
- package/dist/cjs/prepareContentDeclaration.cjs +4 -1
- package/dist/cjs/prepareContentDeclaration.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +9 -4
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/processPerLocaleDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs +22 -8
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.cjs +44 -42
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.cjs +83 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.cjs +29 -21
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.cjs +52 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.cjs +44 -29
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs +39 -34
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +4 -6
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +17 -16
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -1
- package/dist/cjs/utils/formatter.cjs +50 -0
- package/dist/cjs/utils/formatter.cjs.map +1 -0
- package/dist/cjs/utils/parallelize.cjs +43 -0
- package/dist/cjs/utils/parallelize.cjs.map +1 -0
- package/dist/cjs/utils/runOnce.cjs +2 -1
- package/dist/cjs/utils/runOnce.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/formatCode.cjs +7 -4
- package/dist/cjs/writeContentDeclaration/formatCode.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +5 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +43 -25
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
- package/dist/esm/chokidar/watcher.mjs +16 -21
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/fetchDistantDictionaries.mjs +24 -28
- package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/{fetchDistantDictionaryKeys.mjs → fetchDistantDictionaryKeysAndUpdateTimestamp.mjs} +6 -6
- package/dist/esm/fetchDistantDictionaryKeysAndUpdateTimestamp.mjs.map +1 -0
- package/dist/esm/filterInvalidDictionaries.mjs +40 -0
- package/dist/esm/filterInvalidDictionaries.mjs.map +1 -0
- package/dist/esm/getBuiltFetchDictionariesPath.mjs +18 -0
- package/dist/esm/getBuiltFetchDictionariesPath.mjs.map +1 -0
- package/dist/esm/getBuiltRemoteDictionariesPath.mjs +17 -0
- package/dist/esm/getBuiltRemoteDictionariesPath.mjs.map +1 -0
- package/dist/esm/index.mjs +8 -9
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/loadDictionaries/index.mjs +2 -2
- package/dist/esm/loadDictionaries/index.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +61 -18
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +132 -53
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +66 -0
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -0
- package/dist/esm/loadDictionaries/log.mjs +125 -0
- package/dist/esm/loadDictionaries/log.mjs.map +1 -0
- package/dist/esm/mergeDictionaries.mjs +19 -23
- package/dist/esm/mergeDictionaries.mjs.map +1 -1
- package/dist/esm/orderDictionaries.mjs +37 -0
- package/dist/esm/orderDictionaries.mjs.map +1 -0
- package/dist/esm/prepareContentDeclaration.mjs +4 -1
- package/dist/esm/prepareContentDeclaration.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +9 -4
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/processPerLocaleDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs +25 -9
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs +45 -43
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs +58 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs +29 -21
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs +28 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs +45 -30
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +39 -34
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +4 -6
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +17 -16
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
- package/dist/esm/utils/formatter.mjs +15 -0
- package/dist/esm/utils/formatter.mjs.map +1 -0
- package/dist/esm/utils/parallelize.mjs +9 -0
- package/dist/esm/utils/parallelize.mjs.map +1 -0
- package/dist/esm/utils/runOnce.mjs +2 -1
- package/dist/esm/utils/runOnce.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/formatCode.mjs +8 -5
- package/dist/esm/writeContentDeclaration/formatCode.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +5 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +40 -22
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
- package/dist/types/chokidar/watcher.d.ts.map +1 -1
- package/dist/types/fetchDistantDictionaries.d.ts +2 -1
- package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
- package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts +3 -0
- package/dist/types/fetchDistantDictionaryKeysAndUpdateTimestamp.d.ts.map +1 -0
- package/dist/types/filterInvalidDictionaries.d.ts +3 -0
- package/dist/types/filterInvalidDictionaries.d.ts.map +1 -0
- package/dist/types/getBuiltFetchDictionariesPath.d.ts +5 -0
- package/dist/types/getBuiltFetchDictionariesPath.d.ts.map +1 -0
- package/dist/types/getBuiltRemoteDictionariesPath.d.ts +5 -0
- package/dist/types/getBuiltRemoteDictionariesPath.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/loadDictionaries/index.d.ts +2 -2
- package/dist/types/loadDictionaries/index.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +4 -1
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadDictionaries.d.ts +11 -1
- package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +6 -0
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -0
- package/dist/types/loadDictionaries/log.d.ts +19 -0
- package/dist/types/loadDictionaries/log.d.ts.map +1 -0
- package/dist/types/mergeDictionaries.d.ts +1 -1
- package/dist/types/mergeDictionaries.d.ts.map +1 -1
- package/dist/types/orderDictionaries.d.ts +10 -0
- package/dist/types/orderDictionaries.d.ts.map +1 -0
- package/dist/types/prepareContentDeclaration.d.ts.map +1 -1
- package/dist/types/prepareIntlayer.d.ts.map +1 -1
- package/dist/types/processPerLocaleDictionary.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +4 -3
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts +23 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeFetchDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts +19 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeRemoteDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts +1 -1
- package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts.map +1 -1
- package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +1 -1
- package/dist/types/transpiler/dictionary_to_type/createModuleAugmentation.d.ts.map +1 -1
- package/dist/types/transpiler/dictionary_to_type/createType.d.ts +1 -1
- package/dist/types/transpiler/dictionary_to_type/createType.d.ts.map +1 -1
- package/dist/types/utils/formatter.d.ts +4 -0
- package/dist/types/utils/formatter.d.ts.map +1 -0
- package/dist/types/utils/parallelize.d.ts +2 -0
- package/dist/types/utils/parallelize.d.ts.map +1 -0
- package/dist/types/utils/runOnce.d.ts +1 -1
- package/dist/types/utils/runOnce.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/formatCode.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +1 -1
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts +1 -1
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -1
- package/package.json +19 -17
- package/dist/cjs/checkDictionaryChanges.cjs +0 -58
- package/dist/cjs/checkDictionaryChanges.cjs.map +0 -1
- package/dist/cjs/fetchDistantDictionaryKeys.cjs.map +0 -1
- package/dist/cjs/getFilteredLocalesContent.cjs +0 -70
- package/dist/cjs/getFilteredLocalesContent.cjs.map +0 -1
- package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs +0 -44
- package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs.map +0 -1
- package/dist/cjs/log.cjs +0 -296
- package/dist/cjs/log.cjs.map +0 -1
- package/dist/esm/checkDictionaryChanges.mjs +0 -37
- package/dist/esm/checkDictionaryChanges.mjs.map +0 -1
- package/dist/esm/fetchDistantDictionaryKeys.mjs.map +0 -1
- package/dist/esm/getFilteredLocalesContent.mjs +0 -49
- package/dist/esm/getFilteredLocalesContent.mjs.map +0 -1
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs +0 -20
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs.map +0 -1
- package/dist/esm/log.mjs +0 -262
- package/dist/esm/log.mjs.map +0 -1
- package/dist/types/checkDictionaryChanges.d.ts +0 -3
- package/dist/types/checkDictionaryChanges.d.ts.map +0 -1
- package/dist/types/fetchDistantDictionaryKeys.d.ts +0 -3
- package/dist/types/fetchDistantDictionaryKeys.d.ts.map +0 -1
- package/dist/types/getFilteredLocalesContent.d.ts +0 -4
- package/dist/types/getFilteredLocalesContent.d.ts.map +0 -1
- package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts +0 -8
- package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts.map +0 -1
- package/dist/types/log.d.ts +0 -45
- package/dist/types/log.d.ts.map +0 -1
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { getConfiguration } from "@intlayer/config";
|
|
2
|
-
import {
|
|
2
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
3
3
|
import { resolve } from "path";
|
|
4
4
|
import { getBuiltDictionariesPath } from "../../getBuiltDictionariesPath.mjs";
|
|
5
5
|
import { getBuiltDynamicDictionariesPath } from "../../getBuiltDynamicDictionariesPath.mjs";
|
|
6
|
+
import { getBuiltFetchDictionariesPath } from "../../getBuiltFetchDictionariesPath.mjs";
|
|
7
|
+
import { getBuiltRemoteDictionariesPath } from "../../getBuiltRemoteDictionariesPath.mjs";
|
|
6
8
|
import { getBuiltUnmergedDictionariesPath } from "../../getBuiltUnmergedDictionariesPath.mjs";
|
|
9
|
+
import { parallelize } from "../../utils/parallelize.mjs";
|
|
7
10
|
import { generateDictionaryListContent } from "./generateDictionaryListContent.mjs";
|
|
8
11
|
const filterDictionaries = (paths, keys) => {
|
|
9
12
|
if (!keys) return paths;
|
|
@@ -11,50 +14,52 @@ const filterDictionaries = (paths, keys) => {
|
|
|
11
14
|
(path) => keys.some((key) => path.endsWith(`${key}.json`))
|
|
12
15
|
);
|
|
13
16
|
};
|
|
14
|
-
const writeDictionaryFiles = (paths, fileName, format, configuration = getConfiguration()) => {
|
|
17
|
+
const writeDictionaryFiles = async (paths, fileName, format, configuration = getConfiguration()) => {
|
|
15
18
|
const content = generateDictionaryListContent(paths, format, configuration);
|
|
16
19
|
const extension = format === "cjs" ? "cjs" : "mjs";
|
|
17
20
|
const { mainDir } = configuration.content;
|
|
18
|
-
|
|
21
|
+
await writeFile(resolve(mainDir, `${fileName}.${extension}`), content);
|
|
19
22
|
};
|
|
20
|
-
const createDictionaryEntryPoint = (configuration = getConfiguration(), dictionariesKeys, formats = ["cjs", "esm"]) => {
|
|
23
|
+
const createDictionaryEntryPoint = async (configuration = getConfiguration(), dictionariesKeys, formats = ["cjs", "esm"]) => {
|
|
21
24
|
const { mainDir } = configuration.content;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
+
await mkdir(mainDir, { recursive: true });
|
|
26
|
+
const remoteDictionariesPath = getBuiltRemoteDictionariesPath(configuration);
|
|
25
27
|
const dictionariesPath = filterDictionaries(
|
|
26
28
|
getBuiltDictionariesPath(configuration),
|
|
27
29
|
dictionariesKeys
|
|
28
30
|
);
|
|
29
|
-
for (const format of formats) {
|
|
30
|
-
writeDictionaryFiles(
|
|
31
|
-
dictionariesPath,
|
|
32
|
-
"dictionaries",
|
|
33
|
-
format,
|
|
34
|
-
configuration
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
31
|
const unmergedDictionariesPath = getBuiltUnmergedDictionariesPath(configuration);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
format,
|
|
43
|
-
configuration
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
for (const format of formats) {
|
|
47
|
-
const dynamicDictionariesPathCJS = getBuiltDynamicDictionariesPath(
|
|
48
|
-
configuration,
|
|
32
|
+
const writeOperations = [
|
|
33
|
+
...formats.map((format) => ({
|
|
34
|
+
paths: remoteDictionariesPath,
|
|
35
|
+
fileName: "remote_dictionaries",
|
|
49
36
|
format
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
format
|
|
55
|
-
|
|
56
|
-
)
|
|
57
|
-
|
|
37
|
+
})),
|
|
38
|
+
...formats.map((format) => ({
|
|
39
|
+
paths: dictionariesPath,
|
|
40
|
+
fileName: "dictionaries",
|
|
41
|
+
format
|
|
42
|
+
})),
|
|
43
|
+
...formats.map((format) => ({
|
|
44
|
+
paths: unmergedDictionariesPath,
|
|
45
|
+
fileName: "unmerged_dictionaries",
|
|
46
|
+
format
|
|
47
|
+
})),
|
|
48
|
+
...formats.map((format) => ({
|
|
49
|
+
paths: getBuiltDynamicDictionariesPath(configuration, format),
|
|
50
|
+
fileName: "dynamic_dictionaries",
|
|
51
|
+
format
|
|
52
|
+
})),
|
|
53
|
+
...formats.map((format) => ({
|
|
54
|
+
paths: getBuiltFetchDictionariesPath(configuration, format),
|
|
55
|
+
fileName: "fetch_dictionaries",
|
|
56
|
+
format
|
|
57
|
+
}))
|
|
58
|
+
];
|
|
59
|
+
await parallelize(
|
|
60
|
+
writeOperations,
|
|
61
|
+
async ({ paths, fileName, format }) => writeDictionaryFiles(paths, fileName, format, configuration)
|
|
62
|
+
);
|
|
58
63
|
};
|
|
59
64
|
export {
|
|
60
65
|
createDictionaryEntryPoint
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { mkdir, writeFile } 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 { 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 writeFile(resolve(mainDir, `${fileName}.${extension}`), content);\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,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,gCAAgC;AACzC,SAAS,uCAAuC;AAChD,SAAS,qCAAqC;AAC9C,SAAS,sCAAsC;AAC/C,SAAS,wCAAwC;AACjD,SAAS,mBAAmB;AAC5B,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,QAAQ;AAE7C,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,QAAM,UAAU,QAAQ,SAAS,GAAG,QAAQ,IAAI,SAAS,EAAE,GAAG,OAAO;AACvE;AAKO,MAAM,6BAA6B,OACxC,gBAAgB,iBAAiB,GACjC,kBACA,UAA6B,CAAC,OAAO,KAAK,MACvC;AACH,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,QAAM,MAAM,SAAS,EAAE,WAAW,KAAK,CAAC;AAExC,QAAM,yBAAyB,+BAA+B,aAAa;AAC3E,QAAM,mBAAmB;AAAA,IACvB,yBAAyB,aAAa;AAAA,IACtC;AAAA,EACF;AACA,QAAM,2BACJ,iCAAiC,aAAa;AAEhD,QAAM,kBAAkB;AAAA,IACtB,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO;AAAA,MACP,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO,gCAAgC,eAAe,MAAM;AAAA,MAC5D,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,IACF,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC1B,OAAO,8BAA8B,eAAe,MAAM;AAAA,MAC1D,UAAU;AAAA,MACV;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,QAAM;AAAA,IAAY;AAAA,IAAiB,OAAO,EAAE,OAAO,UAAU,OAAO,MAClE,qBAAqB,OAAO,UAAU,QAAQ,aAAa;AAAA,EAC7D;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Locales, getConfiguration, normalizePath } from "@intlayer/config";
|
|
2
2
|
import fg from "fast-glob";
|
|
3
|
-
import {
|
|
3
|
+
import { mkdir, writeFile } 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";
|
|
@@ -56,11 +56,9 @@ ${formattedDictionaryMap}
|
|
|
56
56
|
fileContent += `}`;
|
|
57
57
|
return fileContent;
|
|
58
58
|
};
|
|
59
|
-
const createModuleAugmentation = (configuration = getConfiguration()) => {
|
|
59
|
+
const createModuleAugmentation = async (configuration = getConfiguration()) => {
|
|
60
60
|
const { moduleAugmentationDir, typesDir } = configuration.content;
|
|
61
|
-
|
|
62
|
-
mkdirSync(moduleAugmentationDir, { recursive: true });
|
|
63
|
-
}
|
|
61
|
+
await mkdir(moduleAugmentationDir, { recursive: true });
|
|
64
62
|
const dictionariesTypesDefinitions = fg.sync(
|
|
65
63
|
normalizePath(`${typesDir}/*.ts`),
|
|
66
64
|
{
|
|
@@ -68,7 +66,7 @@ const createModuleAugmentation = (configuration = getConfiguration()) => {
|
|
|
68
66
|
}
|
|
69
67
|
);
|
|
70
68
|
const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);
|
|
71
|
-
|
|
69
|
+
await writeFile(join(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
|
|
72
70
|
};
|
|
73
71
|
export {
|
|
74
72
|
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 {
|
|
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, writeFile } from 'fs/promises';\nimport { basename, extname, join, relative } from 'path';\nimport { getFileHash } from '../../utils/getFileHash';\nimport { kebabCaseToCamelCase } from '../../utils/kebabCaseToCamelCase';\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 // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n await writeFile(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":"AAAA,SAAS,SAAS,kBAAkB,qBAAqB;AACzD,OAAO,QAAQ;AACf,SAAS,OAAO,iBAAiB;AACjC,SAAS,UAAU,SAAS,MAAM,gBAAgB;AAClD,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AAE9B,MAAM,cAAc,CAAC,QAC1B,GAAG,qBAAqB,GAAG,CAAC;AAE9B,MAAM,gBAAgB,CAAC,YACrB,QACG,IAAI,CAAC,WAAW;AACf,aAAW,OAAO,SAAS;AACzB,QAAI,QAAQ,GAA2B,MAAM,QAAQ;AACnD,aAAO,WAAW,GAAG;AAAA,IACvB;AAAA,EACF;AACF,CAAC,EACA,KAAK,KAAK;AAKf,MAAM,2BAA2B,CAC/B,WACA,gBAAgB,iBAAiB,MACtB;AACX,QAAM,EAAE,SAAS,qBAAqB,IAAI;AAC1C,QAAM,EAAE,sBAAsB,IAAI;AAClC,QAAM,EAAE,SAAS,iBAAiB,WAAW,IAAI;AAEjD,MAAI,cACF;AAEF,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,KAAK,SAAS,uBAAuB,cAAc,CAAC;AAAA,IAClE,IAAI,SAAS,gBAAgB,QAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,IAAI,YAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,mBAAe,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AAAA,EAC3E,CAAC;AAED,iBAAe;AAGf,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,aAAa,WAAW,IAAI,GAAG,EACxE,KAAK,IAAI;AAEZ,QAAM,wBACJ,gBAAgB,SAAS,IACrB,gBAAgB;AAAA,IAAO,CAAC,WACtB,QAAQ,IAAI,CAACA,YAAW,OAAOA,OAAM,CAAC,EAAE,SAAS,OAAO,MAAM,CAAC;AAAA,EACjE,IACA;AAEN,QAAM,mBAAmB,cAAc,OAAO;AAC9C,QAAM,2BAA2B,cAAc,qBAAqB;AAEpE,QAAM,mBACJ,eAAe,WACX,kFACA,eAAe,cACb,8HACA;AAsBR,iBAAe;AAAA;AACf,iBAAe;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACxF,iBAAe,4BAA4B,gBAAgB;AAAA;AAC3D,iBAAe,4BAA4B,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;AACvE,QAAM,UAAU,KAAK,uBAAuB,eAAe,GAAG,SAAS;AACzE;","names":["locale"]}
|
|
@@ -2,8 +2,9 @@ import {
|
|
|
2
2
|
ESMxCJSRequire,
|
|
3
3
|
getConfiguration
|
|
4
4
|
} from "@intlayer/config";
|
|
5
|
-
import {
|
|
5
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
6
6
|
import { resolve } from "path";
|
|
7
|
+
import { parallelize } from "../../utils/parallelize.mjs";
|
|
7
8
|
const requireUncached = (module) => {
|
|
8
9
|
delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];
|
|
9
10
|
return ESMxCJSRequire(module);
|
|
@@ -14,23 +15,23 @@ const generateTypeScriptType = (dictionary) => {
|
|
|
14
15
|
export default ${jsonString} as const;
|
|
15
16
|
`;
|
|
16
17
|
};
|
|
17
|
-
const createTypes = (dictionariesPaths, configuration = getConfiguration()) => {
|
|
18
|
+
const createTypes = async (dictionariesPaths, configuration = getConfiguration()) => {
|
|
18
19
|
const { typesDir } = configuration.content;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
await mkdir(typesDir, { recursive: true });
|
|
21
|
+
const results = await parallelize(
|
|
22
|
+
dictionariesPaths,
|
|
23
|
+
async (dictionaryPath) => {
|
|
24
|
+
const dictionary = requireUncached(dictionaryPath);
|
|
25
|
+
if (!dictionary.key) {
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
const typeDefinition = generateTypeScriptType(dictionary);
|
|
29
|
+
const outputPath = resolve(typesDir, `${dictionary.key}.ts`);
|
|
30
|
+
await writeFile(outputPath, typeDefinition);
|
|
31
|
+
return outputPath;
|
|
27
32
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
writeFileSync(outputPath, typeDefinition);
|
|
31
|
-
resultTypesPaths.push(outputPath);
|
|
32
|
-
}
|
|
33
|
-
return resultTypesPaths;
|
|
33
|
+
);
|
|
34
|
+
return results.filter(Boolean);
|
|
34
35
|
};
|
|
35
36
|
export {
|
|
36
37
|
createTypes,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n getConfiguration,\n IntlayerConfig,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n getConfiguration,\n IntlayerConfig,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { parallelize } from '../../utils/parallelize';\n\nconst requireUncached = (module: string) => {\n delete ESMxCJSRequire.cache[ESMxCJSRequire.resolve(module)];\n return ESMxCJSRequire(module);\n};\n\nexport const generateTypeScriptType = (dictionary: Dictionary) => {\n const jsonString = JSON.stringify(dictionary, null, 2);\n\n return `/* eslint-disable */\\nexport default ${jsonString} as const;\\n`;\n};\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = async (\n dictionariesPaths: string[],\n configuration: IntlayerConfig = getConfiguration()\n): Promise<string[]> => {\n const { typesDir } = configuration.content;\n\n // Create type folders if they don't exist\n await mkdir(typesDir, { recursive: true });\n\n const results = await parallelize(\n dictionariesPaths,\n async (dictionaryPath): Promise<string | undefined> => {\n const dictionary: Dictionary = requireUncached(dictionaryPath);\n\n if (!dictionary.key) {\n return undefined;\n }\n\n const typeDefinition: string = generateTypeScriptType(dictionary);\n\n const outputPath: string = resolve(typesDir, `${dictionary.key}.ts`);\n\n await writeFile(outputPath, typeDefinition);\n\n return outputPath;\n }\n );\n\n return results.filter(Boolean) as string[];\n};\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAE5B,MAAM,kBAAkB,CAAC,WAAmB;AAC1C,SAAO,eAAe,MAAM,eAAe,QAAQ,MAAM,CAAC;AAC1D,SAAO,eAAe,MAAM;AAC9B;AAEO,MAAM,yBAAyB,CAAC,eAA2B;AAChE,QAAM,aAAa,KAAK,UAAU,YAAY,MAAM,CAAC;AAErD,SAAO;AAAA,iBAAwC,UAAU;AAAA;AAC3D;AAIO,MAAM,cAAc,OACzB,mBACA,gBAAgC,iBAAiB,MAC3B;AACtB,QAAM,EAAE,SAAS,IAAI,cAAc;AAGnC,QAAM,MAAM,UAAU,EAAE,WAAW,KAAK,CAAC;AAEzC,QAAM,UAAU,MAAM;AAAA,IACpB;AAAA,IACA,OAAO,mBAAgD;AACrD,YAAM,aAAyB,gBAAgB,cAAc;AAE7D,UAAI,CAAC,WAAW,KAAK;AACnB,eAAO;AAAA,MACT;AAEA,YAAM,iBAAyB,uBAAuB,UAAU;AAEhE,YAAM,aAAqB,QAAQ,UAAU,GAAG,WAAW,GAAG,KAAK;AAEnE,YAAM,UAAU,YAAY,cAAc;AAE1C,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO,QAAQ,OAAO,OAAO;AAC/B;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ANSIColors, colorize, colorizePath, Locales } from "@intlayer/config";
|
|
2
|
+
import configuration from "@intlayer/config/built";
|
|
3
|
+
import { getLocaleName } from "@intlayer/core";
|
|
4
|
+
import { relative } from "path";
|
|
5
|
+
const formatPath = (path, color) => [path].flat().map(
|
|
6
|
+
(path2) => path2.startsWith("/") ? relative(configuration.content.baseDir, path2) : path2
|
|
7
|
+
).map(
|
|
8
|
+
(relativePath) => color === false ? relativePath : colorizePath(relativePath, color)
|
|
9
|
+
).join(`, `);
|
|
10
|
+
const formatLocale = (locale, color = ANSIColors.GREEN) => [locale].flat().map((locale2) => `${getLocaleName(locale2, Locales.ENGLISH)} (${locale2})`).map((text) => color === false ? text : colorize(text, color)).join(`, `);
|
|
11
|
+
export {
|
|
12
|
+
formatLocale,
|
|
13
|
+
formatPath
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=formatter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/formatter.ts"],"sourcesContent":["import { ANSIColors, colorize, colorizePath, Locales } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { getLocaleName } from '@intlayer/core';\nimport { relative } from 'path';\n\nexport const formatPath = (\n path: string | string[],\n color?: ANSIColors | false\n) =>\n [path]\n .flat()\n .map((path) =>\n path.startsWith('/')\n ? relative(configuration.content.baseDir, path)\n : path\n )\n .map((relativePath) =>\n color === false ? relativePath : colorizePath(relativePath, color)\n )\n .join(`, `);\n\nexport const formatLocale = (\n locale: Locales | Locales[],\n color: ANSIColors | false = ANSIColors.GREEN\n) =>\n [locale]\n .flat()\n .map((locale) => `${getLocaleName(locale, Locales.ENGLISH)} (${locale})`)\n .map((text) => (color === false ? text : colorize(text, color)))\n .join(`, `);\n"],"mappings":"AAAA,SAAS,YAAY,UAAU,cAAc,eAAe;AAC5D,OAAO,mBAAmB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AAElB,MAAM,aAAa,CACxB,MACA,UAEA,CAAC,IAAI,EACF,KAAK,EACL;AAAA,EAAI,CAACA,UACJA,MAAK,WAAW,GAAG,IACf,SAAS,cAAc,QAAQ,SAASA,KAAI,IAC5CA;AACN,EACC;AAAA,EAAI,CAAC,iBACJ,UAAU,QAAQ,eAAe,aAAa,cAAc,KAAK;AACnE,EACC,KAAK,IAAI;AAEP,MAAM,eAAe,CAC1B,QACA,QAA4B,WAAW,UAEvC,CAAC,MAAM,EACJ,KAAK,EACL,IAAI,CAACC,YAAW,GAAG,cAAcA,SAAQ,QAAQ,OAAO,CAAC,KAAKA,OAAM,GAAG,EACvE,IAAI,CAAC,SAAU,UAAU,QAAQ,OAAO,SAAS,MAAM,KAAK,CAAE,EAC9D,KAAK,IAAI;","names":["path","locale"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import pLimit from "p-limit";
|
|
2
|
+
const parallelize = async (items, callback, parallelLimit = 10) => {
|
|
3
|
+
const limit = pLimit(parallelLimit);
|
|
4
|
+
return Promise.all(items.map((item) => limit(() => callback(item))));
|
|
5
|
+
};
|
|
6
|
+
export {
|
|
7
|
+
parallelize
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=parallelize.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/parallelize.ts"],"sourcesContent":["import pLimit from 'p-limit';\n\nexport const parallelize = async <T, R>(\n items: T[],\n callback: (item: T) => Promise<R>,\n parallelLimit: number = 10\n): Promise<R[]> => {\n const limit = pLimit(parallelLimit);\n return Promise.all(items.map((item) => limit(() => callback(item))));\n};\n"],"mappings":"AAAA,OAAO,YAAY;AAEZ,MAAM,cAAc,OACzB,OACA,UACA,gBAAwB,OACP;AACjB,QAAM,QAAQ,OAAO,aAAa;AAClC,SAAO,QAAQ,IAAI,MAAM,IAAI,CAAC,SAAS,MAAM,MAAM,SAAS,IAAI,CAAC,CAAC,CAAC;AACrE;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mkdir, stat, unlink, writeFile } from "fs/promises";
|
|
2
2
|
import { dirname } from "path";
|
|
3
|
-
const runOnce = async (sentinelFilePath, callback, cacheTimeoutMs = 60 * 1e3) => {
|
|
3
|
+
const runOnce = async (sentinelFilePath, callback, onIsCached, cacheTimeoutMs = 60 * 1e3) => {
|
|
4
4
|
const currentTimestamp = Date.now();
|
|
5
5
|
const timeoutDuration = cacheTimeoutMs;
|
|
6
6
|
try {
|
|
@@ -9,6 +9,7 @@ const runOnce = async (sentinelFilePath, callback, cacheTimeoutMs = 60 * 1e3) =>
|
|
|
9
9
|
if (sentinelAge > timeoutDuration) {
|
|
10
10
|
await unlink(sentinelFilePath);
|
|
11
11
|
} else {
|
|
12
|
+
await onIsCached();
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
15
|
} catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/runOnce.ts"],"sourcesContent":["import { mkdir, stat, unlink, writeFile } from 'fs/promises';\nimport { dirname } from 'path';\n\n/**\n * Ensures a callback function runs only once within a specified time window across multiple processes.\n * Uses a sentinel file to coordinate execution and prevent duplicate work.\n *\n * @param sentinelFilePath - Path to the sentinel file used for coordination\n * @param callback - The function to execute (should be async)\n * @param cacheTimeoutMs - Time window in milliseconds during which the sentinel is considered valid (default: 60000ms = 1 minute)\n *\n * @example\n * ```typescript\n * await runPrepareIntlayerOnce(\n * '/tmp/intlayer-sentinel',\n * async () => {\n * // Your initialization logic here\n * await prepareIntlayer();\n * },\n * 30 * 1000 // 30 seconds cache\n * );\n * ```\n *\n * @throws {Error} When there are unexpected filesystem errors\n */\nexport const runOnce = async (\n sentinelFilePath: string,\n callback: () => void | Promise<void>,\n cacheTimeoutMs: number = 60 * 1000 // 1 minute in milliseconds\n) => {\n const currentTimestamp = Date.now();\n const timeoutDuration = cacheTimeoutMs;\n\n try {\n // Check if sentinel file exists and get its stats\n const sentinelStats = await stat(sentinelFilePath);\n const sentinelAge = currentTimestamp - sentinelStats.mtime.getTime();\n\n // If sentinel is older than the timeout, delete it and rebuild\n if (sentinelAge > timeoutDuration) {\n await unlink(sentinelFilePath);\n // Fall through to create new sentinel and rebuild\n } else {\n // Sentinel is recent, no need to rebuild\n return;\n }\n } catch (err: any) {\n if (err.code === 'ENOENT') {\n // File doesn't exist, continue to create it\n } else {\n throw err; // unexpected FS error\n }\n }\n\n try {\n // Ensure the directory exists before writing the file\n await mkdir(dirname(sentinelFilePath), { recursive: true });\n\n // O_EXCL ensures only the *first* process can create the file\n await writeFile(sentinelFilePath, String(currentTimestamp), { flag: 'wx' });\n } catch (err: any) {\n if (err.code === 'EEXIST') {\n // Another process already created it → we're done\n return;\n }\n throw err; // unexpected FS error\n }\n\n await callback();\n};\n"],"mappings":"AAAA,SAAS,OAAO,MAAM,QAAQ,iBAAiB;AAC/C,SAAS,eAAe;AAwBjB,MAAM,UAAU,OACrB,kBACA,UACA,iBAAyB,KAAK,QAC3B;AACH,QAAM,mBAAmB,KAAK,IAAI;AAClC,QAAM,kBAAkB;AAExB,MAAI;AAEF,UAAM,gBAAgB,MAAM,KAAK,gBAAgB;AACjD,UAAM,cAAc,mBAAmB,cAAc,MAAM,QAAQ;AAGnE,QAAI,cAAc,iBAAiB;AACjC,YAAM,OAAO,gBAAgB;AAAA,IAE/B,OAAO;
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/runOnce.ts"],"sourcesContent":["import { mkdir, stat, unlink, writeFile } from 'fs/promises';\nimport { dirname } from 'path';\n\n/**\n * Ensures a callback function runs only once within a specified time window across multiple processes.\n * Uses a sentinel file to coordinate execution and prevent duplicate work.\n *\n * @param sentinelFilePath - Path to the sentinel file used for coordination\n * @param callback - The function to execute (should be async)\n * @param cacheTimeoutMs - Time window in milliseconds during which the sentinel is considered valid (default: 60000ms = 1 minute)\n *\n * @example\n * ```typescript\n * await runPrepareIntlayerOnce(\n * '/tmp/intlayer-sentinel',\n * async () => {\n * // Your initialization logic here\n * await prepareIntlayer();\n * },\n * 30 * 1000 // 30 seconds cache\n * );\n * ```\n *\n * @throws {Error} When there are unexpected filesystem errors\n */\nexport const runOnce = async (\n sentinelFilePath: string,\n callback: () => void | Promise<void>,\n onIsCached?: () => void | Promise<void>,\n cacheTimeoutMs: number = 60 * 1000 // 1 minute in milliseconds\n) => {\n const currentTimestamp = Date.now();\n const timeoutDuration = cacheTimeoutMs;\n\n try {\n // Check if sentinel file exists and get its stats\n const sentinelStats = await stat(sentinelFilePath);\n const sentinelAge = currentTimestamp - sentinelStats.mtime.getTime();\n\n // If sentinel is older than the timeout, delete it and rebuild\n if (sentinelAge > timeoutDuration) {\n await unlink(sentinelFilePath);\n // Fall through to create new sentinel and rebuild\n } else {\n await onIsCached();\n // Sentinel is recent, no need to rebuild\n return;\n }\n } catch (err: any) {\n if (err.code === 'ENOENT') {\n // File doesn't exist, continue to create it\n } else {\n throw err; // unexpected FS error\n }\n }\n\n try {\n // Ensure the directory exists before writing the file\n await mkdir(dirname(sentinelFilePath), { recursive: true });\n\n // O_EXCL ensures only the *first* process can create the file\n await writeFile(sentinelFilePath, String(currentTimestamp), { flag: 'wx' });\n } catch (err: any) {\n if (err.code === 'EEXIST') {\n // Another process already created it → we're done\n return;\n }\n throw err; // unexpected FS error\n }\n\n await callback();\n};\n"],"mappings":"AAAA,SAAS,OAAO,MAAM,QAAQ,iBAAiB;AAC/C,SAAS,eAAe;AAwBjB,MAAM,UAAU,OACrB,kBACA,UACA,YACA,iBAAyB,KAAK,QAC3B;AACH,QAAM,mBAAmB,KAAK,IAAI;AAClC,QAAM,kBAAkB;AAExB,MAAI;AAEF,UAAM,gBAAgB,MAAM,KAAK,gBAAgB;AACjD,UAAM,cAAc,mBAAmB,cAAc,MAAM,QAAQ;AAGnE,QAAI,cAAc,iBAAiB;AACjC,YAAM,OAAO,gBAAgB;AAAA,IAE/B,OAAO;AACL,YAAM,WAAW;AAEjB;AAAA,IACF;AAAA,EACF,SAAS,KAAU;AACjB,QAAI,IAAI,SAAS,UAAU;AAAA,IAE3B,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF;AAEA,MAAI;AAEF,UAAM,MAAM,QAAQ,gBAAgB,GAAG,EAAE,WAAW,KAAK,CAAC;AAG1D,UAAM,UAAU,kBAAkB,OAAO,gBAAgB,GAAG,EAAE,MAAM,KAAK,CAAC;AAAA,EAC5E,SAAS,KAAU;AACjB,QAAI,IAAI,SAAS,UAAU;AAEzB;AAAA,IACF;AACA,UAAM;AAAA,EACR;AAEA,QAAM,SAAS;AACjB;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAppLogger } from "@intlayer/config";
|
|
1
|
+
import { ANSIColors, getAppLogger } from "@intlayer/config";
|
|
2
2
|
import configuration from "@intlayer/config/built";
|
|
3
3
|
import { relative } from "path";
|
|
4
4
|
const formatCode = async (filePath, code) => {
|
|
@@ -17,10 +17,13 @@ const formatCode = async (filePath, code) => {
|
|
|
17
17
|
// Explicitly provide the filepath so Prettier can infer the parser
|
|
18
18
|
});
|
|
19
19
|
const relativePath = relative(configuration.content.baseDir, filePath);
|
|
20
|
-
appLogger(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
appLogger(
|
|
21
|
+
`Applied Prettier formatting to ${ANSIColors.GREY}${relativePath}${ANSIColors.RESET}`,
|
|
22
|
+
{
|
|
23
|
+
level: "info",
|
|
24
|
+
isVerbose: true
|
|
25
|
+
}
|
|
26
|
+
);
|
|
24
27
|
return formattedCode;
|
|
25
28
|
} catch (error) {
|
|
26
29
|
const err = error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/writeContentDeclaration/formatCode.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { relative } from 'path';\n\nexport const formatCode = async (filePath: string, code: string) => {\n const appLogger = getAppLogger(configuration);\n // Try to import prettier if it exists\n let prettier: any;\n try {\n prettier = require('prettier');\n } catch (error) {\n // Prettier is not installed, continue without it\n }\n\n // Apply Prettier formatting if it's available\n if (prettier) {\n try {\n // Try to find a prettier config file\n const prettierConfig = await prettier.resolveConfig(filePath ?? '');\n\n // Format the code with Prettier\n const formattedCode = await prettier.format(code, {\n ...prettierConfig,\n filepath: filePath, // Explicitly provide the filepath so Prettier can infer the parser\n });\n\n const relativePath = relative(configuration.content.baseDir, filePath);\n\n appLogger(`Applied Prettier formatting to ${relativePath}
|
|
1
|
+
{"version":3,"sources":["../../../src/writeContentDeclaration/formatCode.ts"],"sourcesContent":["import { ANSIColors, getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { relative } from 'path';\n\nexport const formatCode = async (filePath: string, code: string) => {\n const appLogger = getAppLogger(configuration);\n // Try to import prettier if it exists\n let prettier: any;\n try {\n prettier = require('prettier');\n } catch (error) {\n // Prettier is not installed, continue without it\n }\n\n // Apply Prettier formatting if it's available\n if (prettier) {\n try {\n // Try to find a prettier config file\n const prettierConfig = await prettier.resolveConfig(filePath ?? '');\n\n // Format the code with Prettier\n const formattedCode = await prettier.format(code, {\n ...prettierConfig,\n filepath: filePath, // Explicitly provide the filepath so Prettier can infer the parser\n });\n\n const relativePath = relative(configuration.content.baseDir, filePath);\n\n appLogger(\n `Applied Prettier formatting to ${ANSIColors.GREY}${relativePath}${ANSIColors.RESET}`,\n {\n level: 'info',\n isVerbose: true,\n }\n );\n\n return formattedCode;\n } catch (error) {\n const err = error as Error;\n appLogger(\n `Failed to apply Prettier formatting to ${filePath}: ${err.message}`,\n {\n level: 'warn',\n isVerbose: true,\n }\n );\n // Continue with unformatted code on prettier error\n }\n }\n\n return code;\n};\n"],"mappings":"AAAA,SAAS,YAAY,oBAAoB;AACzC,OAAO,mBAAmB;AAC1B,SAAS,gBAAgB;AAElB,MAAM,aAAa,OAAO,UAAkB,SAAiB;AAClE,QAAM,YAAY,aAAa,aAAa;AAE5C,MAAI;AACJ,MAAI;AACF,eAAW,QAAQ,UAAU;AAAA,EAC/B,SAAS,OAAO;AAAA,EAEhB;AAGA,MAAI,UAAU;AACZ,QAAI;AAEF,YAAM,iBAAiB,MAAM,SAAS,cAAc,YAAY,EAAE;AAGlE,YAAM,gBAAgB,MAAM,SAAS,OAAO,MAAM;AAAA,QAChD,GAAG;AAAA,QACH,UAAU;AAAA;AAAA,MACZ,CAAC;AAED,YAAM,eAAe,SAAS,cAAc,QAAQ,SAAS,QAAQ;AAErE;AAAA,QACE,kCAAkC,WAAW,IAAI,GAAG,YAAY,GAAG,WAAW,KAAK;AAAA,QACnF;AAAA,UACE,OAAO;AAAA,UACP,WAAW;AAAA,QACb;AAAA,MACF;AAEA,aAAO;AAAA,IACT,SAAS,OAAO;AACd,YAAM,MAAM;AACZ;AAAA,QACE,0CAA0C,QAAQ,KAAK,IAAI,OAAO;AAAA,QAClE;AAAA,UACE,OAAO;AAAA,UACP,WAAW;AAAA,QACb;AAAA,MACF;AAAA,IAEF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import configuration from "@intlayer/config/built";
|
|
2
|
+
import { colorizePath, x } from "@intlayer/config/client";
|
|
2
3
|
import dictionariesRecord from "@intlayer/unmerged-dictionaries-entry";
|
|
3
4
|
import deepEqual from "deep-equal";
|
|
4
5
|
import { existsSync } from "fs";
|
|
@@ -81,7 +82,10 @@ const writeFileWithDirectories = async (filePath, data) => {
|
|
|
81
82
|
await writeJSFile(filePath, data);
|
|
82
83
|
}
|
|
83
84
|
} catch (error) {
|
|
84
|
-
|
|
85
|
+
console.error(data);
|
|
86
|
+
throw new Error(
|
|
87
|
+
`${x} Error writing file to ${colorizePath(filePath)}: ${error}`
|
|
88
|
+
);
|
|
85
89
|
}
|
|
86
90
|
};
|
|
87
91
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type
|
|
1
|
+
{"version":3,"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { colorizePath, x, type IntlayerConfig } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/unmerged-dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport { existsSync } from 'fs';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { dirname, extname } from 'path';\nimport { prepareContentDeclaration } from '../prepareContentDeclaration';\nimport type { DictionaryStatus } from './dictionaryStatus';\nimport { writeJSFile } from './writeJSFile';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nconst formatContentDeclaration = async (dictionary: Dictionary) => {\n // Clean Markdown, Insertion, File, etc. node metadata\n const preparedContentDeclaration =\n await prepareContentDeclaration(dictionary);\n\n // Remove the filePath from the dictionary and set $schema\n const { filePath, $schema, ...dictionaryWithoutPath } =\n preparedContentDeclaration;\n\n const formattedContentDeclaration = {\n $schema: 'https://intlayer.org/schema.json',\n ...dictionaryWithoutPath,\n };\n\n return formattedContentDeclaration;\n};\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n config: IntlayerConfig = configuration,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const { content } = config;\n const { baseDir } = content;\n\n const newDictionaryRelativeLocationPath =\n newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = (\n dictionariesRecord[dictionary.key] as Dictionary[]\n ).filter((el) => el.filePath === dictionary.filePath);\n\n const filePath = dictionary.filePath;\n const formattedContentDeclaration =\n await formatContentDeclaration(dictionary);\n\n if (existingDictionary) {\n // Compare existing dictionary with distant dictionary\n if (deepEqual(existingDictionary, dictionary)) {\n // Up to date, nothing to do\n return {\n status: 'up-to-date',\n path: filePath!,\n };\n } else {\n if (filePath) {\n await writeFileWithDirectories(filePath, formattedContentDeclaration);\n\n return { status: 'updated', path: filePath };\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration\n );\n\n return {\n status: 'reimported in new location',\n path: contentDeclarationPath,\n };\n }\n }\n } else {\n // No existing dictionary, write to new location\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await mkdir(dir, { recursive: true });\n }\n\n const extention = extname(filePath);\n const acceptedExtensions = configuration.content.fileExtensions.map(\n (extention) => extname(extention)\n );\n\n if (!acceptedExtensions.includes(extention)) {\n throw new Error(\n `Invalid file extension: ${extention}, file: ${filePath}`\n );\n }\n\n if (extention === '.json') {\n const jsonDictionary = JSON.stringify(data, null, 2);\n\n // Write the file\n await writeFile(filePath, jsonDictionary);\n } else {\n await writeJSFile(filePath, data as unknown as Dictionary);\n }\n } catch (error) {\n console.error(data);\n\n throw new Error(\n `${x} Error writing file to ${colorizePath(filePath)}: ${error}`\n );\n }\n};\n"],"mappings":"AAAA,OAAO,mBAAmB;AAC1B,SAAS,cAAc,SAA8B;AAErD,OAAO,wBAAwB;AAC/B,OAAO,eAAe;AACtB,SAAS,kBAAkB;AAC3B,SAAS,OAAO,iBAAiB;AACjC,SAAS,SAAS,eAAe;AACjC,SAAS,iCAAiC;AAE1C,SAAS,mBAAmB;AAE5B,MAAM,8BAA8B;AAEpC,MAAM,2BAA2B,OAAO,eAA2B;AAEjE,QAAM,6BACJ,MAAM,0BAA0B,UAAU;AAG5C,QAAM,EAAE,UAAU,SAAS,GAAG,sBAAsB,IAClD;AAEF,QAAM,8BAA8B;AAAA,IAClC,SAAS;AAAA,IACT,GAAG;AAAA,EACL;AAEA,SAAO;AACT;AAEO,MAAM,0BAA0B,OACrC,YACA,SAAyB,eACzB,wBACwD;AACxD,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,EAAE,QAAQ,IAAI;AAEpB,QAAM,oCACJ,uBAAuB;AACzB,QAAM,4BAA4B,GAAG,OAAO,IAAI,iCAAiC;AAEjF,QAAM,qBACJ,mBAAmB,WAAW,GAAG,EACjC,OAAO,CAAC,OAAO,GAAG,aAAa,WAAW,QAAQ;AAEpD,QAAM,WAAW,WAAW;AAC5B,QAAM,8BACJ,MAAM,yBAAyB,UAAU;AAE3C,MAAI,oBAAoB;AAEtB,QAAI,UAAU,oBAAoB,UAAU,GAAG;AAE7C,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,MACR;AAAA,IACF,OAAO;AACL,UAAI,UAAU;AACZ,cAAM,yBAAyB,UAAU,2BAA2B;AAEpE,eAAO,EAAE,QAAQ,WAAW,MAAM,SAAS;AAAA,MAC7C,OAAO;AAEL,cAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAE7E,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,QACF;AAEA,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAE7E,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,IACF;AAEA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,OAC/B,UACA,SACkB;AAClB,MAAI;AAEF,UAAM,MAAM,QAAQ,QAAQ;AAG5B,UAAM,kBAAkB,WAAW,GAAG;AAEtC,QAAI,CAAC,iBAAiB;AAEpB,YAAM,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACtC;AAEA,UAAM,YAAY,QAAQ,QAAQ;AAClC,UAAM,qBAAqB,cAAc,QAAQ,eAAe;AAAA,MAC9D,CAACA,eAAc,QAAQA,UAAS;AAAA,IAClC;AAEA,QAAI,CAAC,mBAAmB,SAAS,SAAS,GAAG;AAC3C,YAAM,IAAI;AAAA,QACR,2BAA2B,SAAS,WAAW,QAAQ;AAAA,MACzD;AAAA,IACF;AAEA,QAAI,cAAc,SAAS;AACzB,YAAM,iBAAiB,KAAK,UAAU,MAAM,MAAM,CAAC;AAGnD,YAAM,UAAU,UAAU,cAAc;AAAA,IAC1C,OAAO;AACL,YAAM,YAAY,UAAU,IAA6B;AAAA,IAC3D;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,IAAI;AAElB,UAAM,IAAI;AAAA,MACR,GAAG,CAAC,0BAA0B,aAAa,QAAQ,CAAC,KAAK,KAAK;AAAA,IAChE;AAAA,EACF;AACF;","names":["extention"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as generate from "@babel/generator";
|
|
2
2
|
import * as babelParser from "@babel/parser";
|
|
3
|
-
import
|
|
3
|
+
import * as babelTraverse from "@babel/traverse";
|
|
4
4
|
import * as t from "@babel/types";
|
|
5
5
|
import { getAppLogger, logger } from "@intlayer/config";
|
|
6
6
|
import configuration from "@intlayer/config/built";
|
|
@@ -13,6 +13,20 @@ import { extname } from "path";
|
|
|
13
13
|
import { getContentDeclarationFileTemplate } from "../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs";
|
|
14
14
|
import { formatCode } from "./formatCode.mjs";
|
|
15
15
|
const writeJSFile = async (filePath, dictionary) => {
|
|
16
|
+
const normalizeTraverse = (mod) => {
|
|
17
|
+
const candidate = mod;
|
|
18
|
+
if (typeof candidate === "function") return candidate;
|
|
19
|
+
if (candidate?.default) {
|
|
20
|
+
if (typeof candidate.default === "function") return candidate.default;
|
|
21
|
+
if (typeof candidate.default?.default === "function")
|
|
22
|
+
return candidate.default.default;
|
|
23
|
+
if (typeof candidate.default?.traverse === "function")
|
|
24
|
+
return candidate.default.traverse;
|
|
25
|
+
}
|
|
26
|
+
if (typeof candidate?.traverse === "function") return candidate.traverse;
|
|
27
|
+
return candidate;
|
|
28
|
+
};
|
|
29
|
+
const traverse = normalizeTraverse(babelTraverse);
|
|
16
30
|
const appLogger = getAppLogger(configuration);
|
|
17
31
|
const {
|
|
18
32
|
key: dictionaryIdentifierKey,
|
|
@@ -61,15 +75,17 @@ const writeJSFile = async (filePath, dictionary) => {
|
|
|
61
75
|
traverse(ast, {
|
|
62
76
|
ObjectExpression(path) {
|
|
63
77
|
if (dictionaryObjectPath) return;
|
|
64
|
-
const keyProp = path.node.properties.find(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
const keyProp = path.node.properties.find(
|
|
79
|
+
(prop) => {
|
|
80
|
+
if (!t.isObjectProperty(prop)) return false;
|
|
81
|
+
if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))
|
|
82
|
+
return false;
|
|
83
|
+
const keyName = t.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
|
|
84
|
+
if (keyName !== "key" || !t.isStringLiteral(prop.value)) return false;
|
|
85
|
+
const propValue = prop.value.value;
|
|
86
|
+
return propValue === dictionaryIdentifierKey;
|
|
87
|
+
}
|
|
88
|
+
);
|
|
73
89
|
if (keyProp) {
|
|
74
90
|
dictionaryObjectPath = path;
|
|
75
91
|
path.stop();
|
|
@@ -120,17 +136,19 @@ const writeJSFile = async (filePath, dictionary) => {
|
|
|
120
136
|
});
|
|
121
137
|
traverse(ast, {
|
|
122
138
|
ObjectExpression(path) {
|
|
123
|
-
const props = path.node.properties.map(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
139
|
+
const props = path.node.properties.map(
|
|
140
|
+
(prop) => {
|
|
141
|
+
if (!t.isObjectProperty(prop)) return "non-object-property";
|
|
142
|
+
if (!t.isIdentifier(prop.key) && !t.isStringLiteral(prop.key))
|
|
143
|
+
return "complex-key";
|
|
144
|
+
const keyName = t.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
|
|
145
|
+
let valueDesc = "unknown-value";
|
|
146
|
+
if (t.isStringLiteral(prop.value)) {
|
|
147
|
+
valueDesc = `"${prop.value.value}"`;
|
|
148
|
+
}
|
|
149
|
+
return `${keyName}: ${valueDesc}`;
|
|
131
150
|
}
|
|
132
|
-
|
|
133
|
-
}).join(", ");
|
|
151
|
+
).join(", ");
|
|
134
152
|
appLogger(`Object: { ${props} }`);
|
|
135
153
|
}
|
|
136
154
|
});
|
|
@@ -270,7 +288,7 @@ const writeJSFile = async (filePath, dictionary) => {
|
|
|
270
288
|
}
|
|
271
289
|
mergeValueIntoProperty(targetPropertyPath, newEntryData, entryKeyToUpdate);
|
|
272
290
|
}
|
|
273
|
-
const generatedCode =
|
|
291
|
+
const generatedCode = generate.generate(ast, {
|
|
274
292
|
retainLines: true,
|
|
275
293
|
comments: true,
|
|
276
294
|
jsescOption: {
|