@intlayer/chokidar 5.4.2 → 5.5.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/checkDictionaryChanges.cjs +10 -8
- package/dist/cjs/checkDictionaryChanges.cjs.map +1 -1
- package/dist/cjs/chokidar/watcher.cjs +26 -27
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/cleanOutputDir.cjs +7 -9
- package/dist/cjs/cleanOutputDir.cjs.map +1 -1
- package/dist/cjs/fetchDistantDictionaries.cjs +8 -6
- package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/filterDictionaryLocales.cjs +58 -0
- package/dist/cjs/filterDictionaryLocales.cjs.map +1 -0
- package/dist/cjs/getBuiltUnmergedDictionariesPath.cjs +51 -0
- package/dist/cjs/getBuiltUnmergedDictionariesPath.cjs.map +1 -0
- package/dist/cjs/getContentDeclarationFileTemplate/cjsTemplate.md +9 -0
- package/dist/cjs/getContentDeclarationFileTemplate/esmTemplate.md +9 -0
- package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs +62 -0
- package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs.map +1 -0
- package/dist/cjs/getContentDeclarationFileTemplate/tsTemplate.md +8 -0
- package/dist/cjs/index.cjs +21 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/listGitFiles.cjs +100 -0
- package/dist/cjs/listGitFiles.cjs.map +1 -0
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +4 -25
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs +7 -1
- package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/mergeDictionaries.cjs +44 -23
- package/dist/cjs/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +6 -5
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/processPerLocaleDictionary.cjs +49 -0
- package/dist/cjs/processPerLocaleDictionary.cjs.map +1 -0
- package/dist/cjs/reduceDictionaryContent/applyMask.cjs +50 -0
- package/dist/cjs/reduceDictionaryContent/applyMask.cjs.map +1 -0
- package/dist/cjs/reduceDictionaryContent/buildMask.cjs +49 -0
- package/dist/cjs/reduceDictionaryContent/buildMask.cjs.map +1 -0
- package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs +35 -0
- package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.cjs +4 -4
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs +56 -8
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.cjs +4 -4
- package/dist/cjs/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs +21 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/formatCode.cjs +73 -0
- package/dist/cjs/writeContentDeclaration/formatCode.cjs.map +1 -0
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +36 -37
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +379 -0
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -0
- package/dist/esm/checkDictionaryChanges.mjs +10 -5
- package/dist/esm/checkDictionaryChanges.mjs.map +1 -1
- package/dist/esm/chokidar/watcher.mjs +18 -19
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/cleanOutputDir.mjs +7 -9
- package/dist/esm/cleanOutputDir.mjs.map +1 -1
- package/dist/esm/fetchDistantDictionaries.mjs +8 -6
- package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/filterDictionaryLocales.mjs +37 -0
- package/dist/esm/filterDictionaryLocales.mjs.map +1 -0
- package/dist/esm/getBuiltUnmergedDictionariesPath.mjs +17 -0
- package/dist/esm/getBuiltUnmergedDictionariesPath.mjs.map +1 -0
- package/dist/esm/getContentDeclarationFileTemplate/cjsTemplate.md +9 -0
- package/dist/esm/getContentDeclarationFileTemplate/esmTemplate.md +9 -0
- package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs +37 -0
- package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs.map +1 -0
- package/dist/esm/getContentDeclarationFileTemplate/tsTemplate.md +8 -0
- package/dist/esm/index.mjs +21 -9
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/listGitFiles.mjs +66 -0
- package/dist/esm/listGitFiles.mjs.map +1 -0
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +7 -14
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs +7 -1
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs.map +1 -1
- package/dist/esm/mergeDictionaries.mjs +43 -22
- package/dist/esm/mergeDictionaries.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +5 -4
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/processPerLocaleDictionary.mjs +25 -0
- package/dist/esm/processPerLocaleDictionary.mjs.map +1 -0
- package/dist/esm/reduceDictionaryContent/applyMask.mjs +26 -0
- package/dist/esm/reduceDictionaryContent/applyMask.mjs.map +1 -0
- package/dist/esm/reduceDictionaryContent/buildMask.mjs +24 -0
- package/dist/esm/reduceDictionaryContent/buildMask.mjs.map +1 -0
- package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs +11 -0
- package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.mjs +4 -4
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs +54 -8
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.mjs +4 -4
- package/dist/esm/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +21 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/formatCode.mjs +39 -0
- package/dist/esm/writeContentDeclaration/formatCode.mjs.map +1 -0
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +35 -36
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +347 -0
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -0
- package/dist/types/checkDictionaryChanges.d.ts.map +1 -1
- package/dist/types/chokidar/watcher.d.ts +2 -1
- package/dist/types/chokidar/watcher.d.ts.map +1 -1
- package/dist/types/cleanOutputDir.d.ts.map +1 -1
- package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
- package/dist/types/filterDictionaryLocales.d.ts +4 -0
- package/dist/types/filterDictionaryLocales.d.ts.map +1 -0
- package/dist/types/getBuiltUnmergedDictionariesPath.d.ts +5 -0
- package/dist/types/getBuiltUnmergedDictionariesPath.d.ts.map +1 -0
- package/dist/types/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.d.ts +2 -0
- package/dist/types/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.d.ts.map +1 -0
- package/dist/types/index.d.ts +12 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/listGitFiles.d.ts +9 -0
- package/dist/types/listGitFiles.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts.map +1 -1
- package/dist/types/mergeDictionaries.d.ts +2 -4
- package/dist/types/mergeDictionaries.d.ts.map +1 -1
- package/dist/types/prepareIntlayer.d.ts.map +1 -1
- package/dist/types/processPerLocaleDictionary.d.ts +32 -0
- package/dist/types/processPerLocaleDictionary.d.ts.map +1 -0
- package/dist/types/reduceDictionaryContent/applyMask.d.ts +3 -0
- package/dist/types/reduceDictionaryContent/applyMask.d.ts.map +1 -0
- package/dist/types/reduceDictionaryContent/buildMask.d.ts +5 -0
- package/dist/types/reduceDictionaryContent/buildMask.d.ts.map +1 -0
- package/dist/types/reduceDictionaryContent/reduceDictionaryContent.d.ts +3 -0
- package/dist/types/reduceDictionaryContent/reduceDictionaryContent.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts +38 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/formatCode.d.ts +2 -0
- package/dist/types/writeContentDeclaration/formatCode.d.ts.map +1 -0
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts +9 -0
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -0
- package/package.json +21 -13
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getAuthAPI, getDictionaryAPI } from "@intlayer/api";
|
|
2
|
+
import { getAppLogger, getConfiguration } from "@intlayer/config";
|
|
3
3
|
import pLimit from "p-limit";
|
|
4
4
|
import { logger } from "./log.mjs";
|
|
5
5
|
const fetchDistantDictionaries = async (options) => {
|
|
6
|
+
const config = getConfiguration();
|
|
7
|
+
const appLogger = getAppLogger(config);
|
|
6
8
|
try {
|
|
7
|
-
const config = getConfiguration();
|
|
8
9
|
const { clientId, clientSecret } = config.editor;
|
|
9
|
-
const
|
|
10
|
+
const authAPI = getAuthAPI(void 0, config);
|
|
11
|
+
const dictionaryAPI = getDictionaryAPI(void 0, config);
|
|
10
12
|
if (!clientId || !clientSecret) {
|
|
11
13
|
throw new Error(
|
|
12
14
|
"Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
|
|
13
15
|
);
|
|
14
16
|
}
|
|
15
|
-
const oAuth2TokenResult = await
|
|
17
|
+
const oAuth2TokenResult = await authAPI.getOAuth2AccessToken();
|
|
16
18
|
const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
|
|
17
19
|
const distantDictionariesKeys = options.dictionaryKeys;
|
|
18
20
|
const limit = pLimit(5);
|
|
@@ -25,7 +27,7 @@ const fetchDistantDictionaries = async (options) => {
|
|
|
25
27
|
}
|
|
26
28
|
]);
|
|
27
29
|
try {
|
|
28
|
-
const getDictionaryResult = await
|
|
30
|
+
const getDictionaryResult = await dictionaryAPI.getDictionary(
|
|
29
31
|
dictionaryKey,
|
|
30
32
|
void 0,
|
|
31
33
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fetchDistantDictionaries.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/fetchDistantDictionaries.ts"],"sourcesContent":["import { getAuthAPI, getDictionaryAPI } from '@intlayer/api';\n// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { getAppLogger, getConfiguration } from '@intlayer/config';\nimport pLimit from 'p-limit';\nimport { logger } from './log';\n\ntype FetchDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n logPrefix?: string;\n};\n\n/**\n * Fetch distant dictionaries and update the logger with their statuses.\n */\nexport const fetchDistantDictionaries = async (\n options: FetchDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n const config = getConfiguration();\n const appLogger = getAppLogger(config);\n try {\n const { clientId, clientSecret } = config.editor;\n const authAPI = getAuthAPI(undefined, config);\n const dictionaryAPI = getDictionaryAPI(undefined, config);\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await authAPI.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n const distantDictionariesKeys = options.dictionaryKeys;\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Limit the number of concurrent requests\n\n const processDictionary = async (\n dictionaryKey: string\n ): Promise<DictionaryAPI | undefined> => {\n logger.updateStatus([\n {\n dictionaryKey,\n type: 'distant',\n status: { status: 'fetching' },\n },\n ]);\n\n try {\n // Fetch the dictionary\n const getDictionaryResult = await dictionaryAPI.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n logger.updateStatus([\n { dictionaryKey, type: 'distant', status: { status: 'imported' } },\n ]);\n\n return distantDictionary;\n } catch (error) {\n logger.updateStatus([\n {\n dictionaryKey,\n type: 'distant',\n status: {\n status: 'error',\n error: error as Error,\n errorMessage: `${options?.logPrefix ?? ''}Error fetching dictionary ${dictionaryKey}: ${error}`,\n },\n },\n ]);\n return undefined;\n }\n };\n\n const fetchPromises = distantDictionariesKeys.map((dictionaryKey) =>\n limit(async () => await processDictionary(dictionaryKey))\n );\n\n const result = await Promise.all(fetchPromises);\n\n // Output any error messages\n const statuses = logger.getStatuses();\n for (const statusObj of statuses) {\n const currentState = statusObj.state.find((s) => s.type === 'distant');\n if (currentState && currentState.errorMessage) {\n appLogger(currentState.errorMessage, { level: 'error' });\n }\n }\n\n // Remove undefined values\n const filteredResult = result.filter(\n (dict): dict is DictionaryAPI => dict !== undefined\n );\n\n return filteredResult;\n } catch (error) {\n appLogger(error, { level: 'error' });\n return [];\n }\n};\n"],"mappings":"AAAA,SAAS,YAAY,wBAAwB;AAG7C,SAAS,cAAc,wBAAwB;AAC/C,OAAO,YAAY;AACnB,SAAS,cAAc;AAWhB,MAAM,2BAA2B,OACtC,YAC6B;AAC7B,QAAM,SAAS,iBAAiB;AAChC,QAAM,YAAY,aAAa,MAAM;AACrC,MAAI;AACF,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAC1C,UAAM,UAAU,WAAW,QAAW,MAAM;AAC5C,UAAM,gBAAgB,iBAAiB,QAAW,MAAM;AAExD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,MAAM,QAAQ,qBAAqB;AAE7D,UAAM,oBAAoB,kBAAkB,MAAM;AAElD,UAAM,0BAA0B,QAAQ;AAGxC,UAAM,QAAQ,OAAO,CAAC;AAEtB,UAAM,oBAAoB,OACxB,kBACuC;AACvC,aAAO,aAAa;AAAA,QAClB;AAAA,UACE;AAAA,UACA,MAAM;AAAA,UACN,QAAQ,EAAE,QAAQ,WAAW;AAAA,QAC/B;AAAA,MACF,CAAC;AAED,UAAI;AAEF,cAAM,sBAAsB,MAAM,cAAc;AAAA,UAC9C;AAAA,UACA;AAAA,UACA;AAAA,YACE,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,UAC1D;AAAA,QACF;AAEA,cAAM,oBAAoB,oBAAoB;AAE9C,YAAI,CAAC,mBAAmB;AACtB,gBAAM,IAAI,MAAM,cAAc,aAAa,sBAAsB;AAAA,QACnE;AAEA,eAAO,aAAa;AAAA,UAClB,EAAE,eAAe,MAAM,WAAW,QAAQ,EAAE,QAAQ,WAAW,EAAE;AAAA,QACnE,CAAC;AAED,eAAO;AAAA,MACT,SAAS,OAAO;AACd,eAAO,aAAa;AAAA,UAClB;AAAA,YACE;AAAA,YACA,MAAM;AAAA,YACN,QAAQ;AAAA,cACN,QAAQ;AAAA,cACR;AAAA,cACA,cAAc,GAAG,SAAS,aAAa,EAAE,6BAA6B,aAAa,KAAK,KAAK;AAAA,YAC/F;AAAA,UACF;AAAA,QACF,CAAC;AACD,eAAO;AAAA,MACT;AAAA,IACF;AAEA,UAAM,gBAAgB,wBAAwB;AAAA,MAAI,CAAC,kBACjD,MAAM,YAAY,MAAM,kBAAkB,aAAa,CAAC;AAAA,IAC1D;AAEA,UAAM,SAAS,MAAM,QAAQ,IAAI,aAAa;AAG9C,UAAM,WAAW,OAAO,YAAY;AACpC,eAAW,aAAa,UAAU;AAChC,YAAM,eAAe,UAAU,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,SAAS;AACrE,UAAI,gBAAgB,aAAa,cAAc;AAC7C,kBAAU,aAAa,cAAc,EAAE,OAAO,QAAQ,CAAC;AAAA,MACzD;AAAA,IACF;AAGA,UAAM,iBAAiB,OAAO;AAAA,MAC5B,CAAC,SAAgC,SAAS;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,cAAU,OAAO,EAAE,OAAO,QAAQ,CAAC;AACnC,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deepTransformNode,
|
|
3
|
+
NodeType
|
|
4
|
+
} from "@intlayer/core";
|
|
5
|
+
const filterTranlationsPlugin = (locales) => ({
|
|
6
|
+
id: "filter-translations-plugin",
|
|
7
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Translation,
|
|
8
|
+
transform: (node, props, deepTransformNode2) => {
|
|
9
|
+
const translationMap = node.translation;
|
|
10
|
+
const filteredTranslationMap = Object.fromEntries(
|
|
11
|
+
Object.entries(translationMap).filter(
|
|
12
|
+
([key]) => locales.includes(key)
|
|
13
|
+
)
|
|
14
|
+
);
|
|
15
|
+
return {
|
|
16
|
+
...node,
|
|
17
|
+
translation: deepTransformNode2(filteredTranslationMap, {
|
|
18
|
+
...props,
|
|
19
|
+
keyPath: [
|
|
20
|
+
...props.keyPath,
|
|
21
|
+
{ type: NodeType.Object, key: NodeType.Translation }
|
|
22
|
+
]
|
|
23
|
+
})
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
const filterDictionaryLocales = (dictionary, locales) => {
|
|
28
|
+
return deepTransformNode(dictionary, {
|
|
29
|
+
plugins: [filterTranlationsPlugin(locales)],
|
|
30
|
+
dictionaryKey: dictionary.key,
|
|
31
|
+
keyPath: []
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
filterDictionaryLocales
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=filterDictionaryLocales.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/filterDictionaryLocales.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n deepTransformNode,\n Dictionary,\n NodeType,\n Plugins,\n} from '@intlayer/core';\n\nconst filterTranlationsPlugin = (locales: Locales[]): Plugins => ({\n id: 'filter-translations-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node, props, deepTransformNode) => {\n const translationMap = node.translation as Record<Locales, string>;\n\n const filteredTranslationMap = Object.fromEntries(\n Object.entries(translationMap).filter(([key]) =>\n locales.includes(key as Locales)\n )\n );\n\n return {\n ...node,\n translation: deepTransformNode(filteredTranslationMap, {\n ...props,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key: NodeType.Translation },\n ],\n }),\n };\n },\n});\n\nexport const filterDictionaryLocales = (\n dictionary: Dictionary,\n locales: Locales[]\n) => {\n return deepTransformNode(dictionary, {\n plugins: [filterTranlationsPlugin(locales)],\n dictionaryKey: dictionary.key,\n keyPath: [],\n });\n};\n"],"mappings":"AACA;AAAA,EACE;AAAA,EAEA;AAAA,OAEK;AAEP,MAAM,0BAA0B,CAAC,aAAiC;AAAA,EAChE,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAM,OAAOA,uBAAsB;AAC7C,UAAM,iBAAiB,KAAK;AAE5B,UAAM,yBAAyB,OAAO;AAAA,MACpC,OAAO,QAAQ,cAAc,EAAE;AAAA,QAAO,CAAC,CAAC,GAAG,MACzC,QAAQ,SAAS,GAAc;AAAA,MACjC;AAAA,IACF;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH,aAAaA,mBAAkB,wBAAwB;AAAA,QACrD,GAAG;AAAA,QACH,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,SAAS,QAAQ,KAAK,SAAS,YAAY;AAAA,QACrD;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,MAAM,0BAA0B,CACrC,YACA,YACG;AACH,SAAO,kBAAkB,YAAY;AAAA,IACnC,SAAS,CAAC,wBAAwB,OAAO,CAAC;AAAA,IAC1C,eAAe,WAAW;AAAA,IAC1B,SAAS,CAAC;AAAA,EACZ,CAAC;AACH;","names":["deepTransformNode"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getConfiguration } from "@intlayer/config";
|
|
2
|
+
import fg from "fast-glob";
|
|
3
|
+
import { existsSync, mkdirSync } from "fs";
|
|
4
|
+
const getBuiltUnmergedDictionariesPath = (configuration = getConfiguration()) => {
|
|
5
|
+
const { unmergedDictionariesDir, mainDir } = configuration.content;
|
|
6
|
+
if (!existsSync(mainDir)) {
|
|
7
|
+
mkdirSync(mainDir, { recursive: true });
|
|
8
|
+
}
|
|
9
|
+
const dictionariesPath = fg.sync(
|
|
10
|
+
`${unmergedDictionariesDir}/**/*.json`
|
|
11
|
+
);
|
|
12
|
+
return dictionariesPath;
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
getBuiltUnmergedDictionariesPath
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=getBuiltUnmergedDictionariesPath.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getBuiltUnmergedDictionariesPath.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync } from 'fs';\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const getBuiltUnmergedDictionariesPath = (\n configuration = getConfiguration()\n) => {\n const { unmergedDictionariesDir, mainDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = fg.sync(\n `${unmergedDictionariesDir}/**/*.json`\n );\n\n return dictionariesPath;\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AACjC,OAAO,QAAQ;AACf,SAAS,YAAY,iBAAiB;AAK/B,MAAM,mCAAmC,CAC9C,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,EAAE,yBAAyB,QAAQ,IAAI,cAAc;AAG3D,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,GAAG;AAAA,IACpC,GAAG,uBAAuB;AAAA,EAC5B;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { readFile } from "fs/promises";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import { kebabCaseToCamelCase } from "../utils.mjs";
|
|
5
|
+
const getContentDeclarationFileTemplate = async (key, format, fileParams = {}) => {
|
|
6
|
+
const dirname = __dirname ?? fileURLToPath(import.meta.url);
|
|
7
|
+
let fileTemplate = "./esmTemplate.md";
|
|
8
|
+
if (format === "ts") {
|
|
9
|
+
fileTemplate = "./tsTemplate.md";
|
|
10
|
+
} else if (format === "cjs") {
|
|
11
|
+
fileTemplate = "./cjsTemplate.md";
|
|
12
|
+
}
|
|
13
|
+
const fileContent = await readFile(join(dirname, fileTemplate), "utf-8");
|
|
14
|
+
const camelCaseKey = kebabCaseToCamelCase(key);
|
|
15
|
+
const nonCapitalizedCamelCaseKey = camelCaseKey.charAt(0).toLowerCase() + camelCaseKey.slice(1);
|
|
16
|
+
const fileParmsString = Object.entries(fileParams).filter(([, value]) => value !== void 0).map(([key2, value]) => {
|
|
17
|
+
if (typeof value === "object") {
|
|
18
|
+
return `
|
|
19
|
+
${key2}: ${JSON.stringify(value)},`;
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === "boolean" || typeof value === "number") {
|
|
22
|
+
return `
|
|
23
|
+
${key2}: ${value},`;
|
|
24
|
+
}
|
|
25
|
+
if (typeof value === "string") {
|
|
26
|
+
return `
|
|
27
|
+
${key2}: '${value}',`;
|
|
28
|
+
}
|
|
29
|
+
return `
|
|
30
|
+
${key2}: ${value},`;
|
|
31
|
+
}).join("");
|
|
32
|
+
return fileContent.replace("{{key}}", key).replaceAll("{{name}}", nonCapitalizedCamelCaseKey).replace("{{fileParams}}", fileParmsString);
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
getContentDeclarationFileTemplate
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=getContentDeclarationFileTemplate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.ts"],"sourcesContent":["import { readFile } from 'fs/promises';\nimport { join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { kebabCaseToCamelCase } from '../utils';\n\nexport const getContentDeclarationFileTemplate = async (\n key: string,\n format: 'ts' | 'cjs' | 'esm',\n fileParams: Record<string, any> = {}\n) => {\n const dirname = __dirname ?? fileURLToPath(import.meta.url);\n\n let fileTemplate = './esmTemplate.md';\n\n if (format === 'ts') {\n fileTemplate = './tsTemplate.md';\n } else if (format === 'cjs') {\n fileTemplate = './cjsTemplate.md';\n }\n\n const fileContent = await readFile(join(dirname, fileTemplate), 'utf-8');\n const camelCaseKey = kebabCaseToCamelCase(key);\n const nonCapitalizedCamelCaseKey =\n camelCaseKey.charAt(0).toLowerCase() + camelCaseKey.slice(1);\n\n const fileParmsString = Object.entries(fileParams)\n .filter(([, value]) => value !== undefined)\n .map(([key, value]) => {\n if (typeof value === 'object') {\n return `\\n${key}: ${JSON.stringify(value)},`;\n }\n\n if (typeof value === 'boolean' || typeof value === 'number') {\n return `\\n${key}: ${value},`;\n }\n\n if (typeof value === 'string') {\n return `\\n${key}: '${value}',`;\n }\n\n return `\\n${key}: ${value},`;\n })\n .join('');\n\n return fileContent\n .replace('{{key}}', key)\n .replaceAll('{{name}}', nonCapitalizedCamelCaseKey)\n .replace('{{fileParams}}', fileParmsString);\n};\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,YAAY;AACrB,SAAS,qBAAqB;AAC9B,SAAS,4BAA4B;AAE9B,MAAM,oCAAoC,OAC/C,KACA,QACA,aAAkC,CAAC,MAChC;AACH,QAAM,UAAU,aAAa,cAAc,YAAY,GAAG;AAE1D,MAAI,eAAe;AAEnB,MAAI,WAAW,MAAM;AACnB,mBAAe;AAAA,EACjB,WAAW,WAAW,OAAO;AAC3B,mBAAe;AAAA,EACjB;AAEA,QAAM,cAAc,MAAM,SAAS,KAAK,SAAS,YAAY,GAAG,OAAO;AACvE,QAAM,eAAe,qBAAqB,GAAG;AAC7C,QAAM,6BACJ,aAAa,OAAO,CAAC,EAAE,YAAY,IAAI,aAAa,MAAM,CAAC;AAE7D,QAAM,kBAAkB,OAAO,QAAQ,UAAU,EAC9C,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,UAAU,MAAS,EACzC,IAAI,CAAC,CAACA,MAAK,KAAK,MAAM;AACrB,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO;AAAA,EAAKA,IAAG,KAAK,KAAK,UAAU,KAAK,CAAC;AAAA,IAC3C;AAEA,QAAI,OAAO,UAAU,aAAa,OAAO,UAAU,UAAU;AAC3D,aAAO;AAAA,EAAKA,IAAG,KAAK,KAAK;AAAA,IAC3B;AAEA,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO;AAAA,EAAKA,IAAG,MAAM,KAAK;AAAA,IAC5B;AAEA,WAAO;AAAA,EAAKA,IAAG,KAAK,KAAK;AAAA,EAC3B,CAAC,EACA,KAAK,EAAE;AAEV,SAAO,YACJ,QAAQ,WAAW,GAAG,EACtB,WAAW,YAAY,0BAA0B,EACjD,QAAQ,kBAAkB,eAAe;AAC9C;","names":["key"]}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
|
+
import { checkDictionaryChanges } from "./checkDictionaryChanges.mjs";
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
+
buildAndWatchIntlayer,
|
|
3
4
|
handleAdditionalContentDeclarationFile,
|
|
4
5
|
handleContentDeclarationFileChange,
|
|
5
|
-
|
|
6
|
+
watch
|
|
6
7
|
} from "./chokidar/watcher.mjs";
|
|
7
|
-
import { prepareIntlayer } from "./prepareIntlayer.mjs";
|
|
8
|
-
import { buildDictionary } from "./transpiler/declaration_file_to_dictionary/index.mjs";
|
|
9
|
-
import { createDictionaryEntryPoint } from "./transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs";
|
|
10
|
-
import { createModuleAugmentation } from "./transpiler/dictionary_to_type/createModuleAugmentation.mjs";
|
|
11
8
|
import { fetchDistantDictionaries } from "./fetchDistantDictionaries.mjs";
|
|
12
9
|
import { fetchDistantDictionaryKeys } from "./fetchDistantDictionaryKeys.mjs";
|
|
10
|
+
import { filterDictionaryLocales } from "./filterDictionaryLocales.mjs";
|
|
11
|
+
import { listDictionaries } from "./listDictionariesPath.mjs";
|
|
12
|
+
import {
|
|
13
|
+
listGitFiles
|
|
14
|
+
} from "./listGitFiles.mjs";
|
|
13
15
|
import {
|
|
14
|
-
loadDistantDictionaries,
|
|
15
16
|
loadDictionaries,
|
|
17
|
+
loadDistantDictionaries,
|
|
16
18
|
loadLocalDictionaries
|
|
17
19
|
} from "./loadDictionaries/index.mjs";
|
|
18
|
-
import {
|
|
19
|
-
import { listDictionaries } from "./listDictionariesPath.mjs";
|
|
20
|
+
import { mergeDictionaries } from "./mergeDictionaries.mjs";
|
|
20
21
|
import { prepareContentDeclaration } from "./prepareContentDeclaration.mjs";
|
|
22
|
+
import { prepareIntlayer } from "./prepareIntlayer.mjs";
|
|
23
|
+
import { processPerLocaleDictionary } from "./processPerLocaleDictionary.mjs";
|
|
24
|
+
import { reduceDictionaryContent } from "./reduceDictionaryContent/reduceDictionaryContent.mjs";
|
|
25
|
+
import { buildDictionary } from "./transpiler/declaration_file_to_dictionary/index.mjs";
|
|
26
|
+
import { createDictionaryEntryPoint } from "./transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs";
|
|
27
|
+
import { createModuleAugmentation } from "./transpiler/dictionary_to_type/createModuleAugmentation.mjs";
|
|
21
28
|
import {
|
|
22
29
|
writeContentDeclaration
|
|
23
30
|
} from "./writeContentDeclaration/index.mjs";
|
|
@@ -29,14 +36,19 @@ export {
|
|
|
29
36
|
createModuleAugmentation,
|
|
30
37
|
fetchDistantDictionaries,
|
|
31
38
|
fetchDistantDictionaryKeys,
|
|
39
|
+
filterDictionaryLocales,
|
|
32
40
|
handleAdditionalContentDeclarationFile,
|
|
33
41
|
handleContentDeclarationFileChange,
|
|
34
42
|
listDictionaries,
|
|
43
|
+
listGitFiles,
|
|
35
44
|
loadDictionaries,
|
|
36
45
|
loadDistantDictionaries,
|
|
37
46
|
loadLocalDictionaries,
|
|
47
|
+
mergeDictionaries,
|
|
38
48
|
prepareContentDeclaration,
|
|
39
49
|
prepareIntlayer,
|
|
50
|
+
processPerLocaleDictionary,
|
|
51
|
+
reduceDictionaryContent,
|
|
40
52
|
watch,
|
|
41
53
|
writeContentDeclaration
|
|
42
54
|
};
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { checkDictionaryChanges } from './checkDictionaryChanges';\nexport {\n buildAndWatchIntlayer,\n handleAdditionalContentDeclarationFile,\n handleContentDeclarationFileChange,\n watch,\n} from './chokidar/watcher';\nexport { fetchDistantDictionaries } from './fetchDistantDictionaries';\nexport { fetchDistantDictionaryKeys } from './fetchDistantDictionaryKeys';\nexport { filterDictionaryLocales } from './filterDictionaryLocales';\nexport { listDictionaries } from './listDictionariesPath';\nexport {\n listGitFiles,\n type DiffMode,\n type ListGitFilesOptions,\n} from './listGitFiles';\nexport {\n loadDictionaries,\n loadDistantDictionaries,\n loadLocalDictionaries,\n} from './loadDictionaries/index';\nexport { mergeDictionaries } from './mergeDictionaries';\nexport { prepareContentDeclaration } from './prepareContentDeclaration';\nexport { prepareIntlayer } from './prepareIntlayer';\nexport { processPerLocaleDictionary } from './processPerLocaleDictionary';\nexport { reduceDictionaryContent } from './reduceDictionaryContent/reduceDictionaryContent';\nexport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nexport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\nexport {\n writeContentDeclaration,\n type DictionaryStatus,\n} from './writeContentDeclaration';\n"],"mappings":"AAAA,SAAS,8BAA8B;AACvC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gCAAgC;AACzC,SAAS,kCAAkC;AAC3C,SAAS,+BAA+B;AACxC,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;AAClC,SAAS,iCAAiC;AAC1C,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C,SAAS,+BAA+B;AACxC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC;AAAA,EACE;AAAA,OAEK;","names":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { getAppLogger } from "@intlayer/config";
|
|
2
|
+
import configuration from "@intlayer/config/built";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import simpleGit from "simple-git";
|
|
5
|
+
const getGitRootDir = async () => {
|
|
6
|
+
try {
|
|
7
|
+
const git = simpleGit();
|
|
8
|
+
const rootDir = await git.revparse(["--show-toplevel"]);
|
|
9
|
+
return rootDir.trim();
|
|
10
|
+
} catch (error) {
|
|
11
|
+
const appLogger = getAppLogger(configuration);
|
|
12
|
+
appLogger("Error getting git root directory:" + error, {
|
|
13
|
+
level: "error"
|
|
14
|
+
});
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const listGitFiles = async ({
|
|
19
|
+
mode,
|
|
20
|
+
baseRef = "origin/main",
|
|
21
|
+
currentRef = "HEAD",
|
|
22
|
+
// HEAD points to the current branch's latest commit
|
|
23
|
+
absolute = true
|
|
24
|
+
}) => {
|
|
25
|
+
try {
|
|
26
|
+
const git = simpleGit();
|
|
27
|
+
const diff = /* @__PURE__ */ new Set();
|
|
28
|
+
if (mode.includes("untracked")) {
|
|
29
|
+
const status = await git.status();
|
|
30
|
+
status.not_added.forEach((f) => diff.add(f));
|
|
31
|
+
}
|
|
32
|
+
if (mode.includes("uncommitted")) {
|
|
33
|
+
const uncommittedDiff = await git.diff(["--name-only", "HEAD"]);
|
|
34
|
+
const uncommittedFiles = uncommittedDiff.split("\n").filter(Boolean);
|
|
35
|
+
uncommittedFiles.forEach((file) => diff.add(file));
|
|
36
|
+
}
|
|
37
|
+
if (mode.includes("unpushed")) {
|
|
38
|
+
const unpushedDiff = await git.diff(["--name-only", "@{push}...HEAD"]);
|
|
39
|
+
const unpushedFiles = unpushedDiff.split("\n").filter(Boolean);
|
|
40
|
+
unpushedFiles.forEach((file) => diff.add(file));
|
|
41
|
+
}
|
|
42
|
+
if (mode.includes("gitDiff")) {
|
|
43
|
+
await git.fetch(baseRef);
|
|
44
|
+
const diffBranch = await git.diff([
|
|
45
|
+
"--name-only",
|
|
46
|
+
`${baseRef}...${currentRef}`
|
|
47
|
+
]);
|
|
48
|
+
const gitDiffFiles = diffBranch.split("\n").filter(Boolean);
|
|
49
|
+
gitDiffFiles.forEach((file) => diff.add(file));
|
|
50
|
+
}
|
|
51
|
+
if (absolute) {
|
|
52
|
+
const gitRootDir = await getGitRootDir();
|
|
53
|
+
if (!gitRootDir) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
return Array.from(diff).map((file) => join(gitRootDir, file));
|
|
57
|
+
}
|
|
58
|
+
return Array.from(diff);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.warn("Failed to get changes list:", error);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
export {
|
|
64
|
+
listGitFiles
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=listGitFiles.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/listGitFiles.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { join } from 'path';\nimport simpleGit from 'simple-git';\n\nexport type DiffMode = 'gitDiff' | 'uncommitted' | 'unpushed' | 'untracked';\n\nconst getGitRootDir = async (): Promise<string | null> => {\n try {\n const git = simpleGit();\n const rootDir = await git.revparse(['--show-toplevel']);\n return rootDir.trim();\n } catch (error) {\n const appLogger = getAppLogger(configuration);\n appLogger('Error getting git root directory:' + error, {\n level: 'error',\n });\n return null;\n }\n};\n\nexport type ListGitFilesOptions = {\n mode: DiffMode[];\n baseRef?: string;\n currentRef?: string;\n absolute?: boolean;\n};\n\nexport const listGitFiles = async ({\n mode,\n baseRef = 'origin/main',\n currentRef = 'HEAD', // HEAD points to the current branch's latest commit\n absolute = true,\n}: ListGitFilesOptions) => {\n try {\n const git = simpleGit();\n const diff: Set<string> = new Set();\n\n if (mode.includes('untracked')) {\n const status = await git.status();\n status.not_added.forEach((f) => diff.add(f));\n }\n\n if (mode.includes('uncommitted')) {\n // Get uncommitted changes\n const uncommittedDiff = await git.diff(['--name-only', 'HEAD']);\n\n const uncommittedFiles = uncommittedDiff.split('\\n').filter(Boolean);\n\n uncommittedFiles.forEach((file) => diff.add(file));\n }\n\n if (mode.includes('unpushed')) {\n // Get unpushed commits\n const unpushedDiff = await git.diff(['--name-only', '@{push}...HEAD']);\n\n const unpushedFiles = unpushedDiff.split('\\n').filter(Boolean);\n\n unpushedFiles.forEach((file) => diff.add(file));\n }\n\n if (mode.includes('gitDiff')) {\n // Get the base branch (usually main/master) from CI environment\n\n await git.fetch(baseRef);\n\n const diffBranch = await git.diff([\n '--name-only',\n `${baseRef}...${currentRef}`,\n ]);\n\n const gitDiffFiles = diffBranch.split('\\n').filter(Boolean);\n\n gitDiffFiles.forEach((file) => diff.add(file));\n }\n\n if (absolute) {\n const gitRootDir = await getGitRootDir();\n if (!gitRootDir) {\n return [];\n }\n return Array.from(diff).map((file) => join(gitRootDir, file));\n }\n\n return Array.from(diff);\n } catch (error) {\n console.warn('Failed to get changes list:', error);\n }\n};\n"],"mappings":"AAAA,SAAS,oBAAoB;AAC7B,OAAO,mBAAmB;AAC1B,SAAS,YAAY;AACrB,OAAO,eAAe;AAItB,MAAM,gBAAgB,YAAoC;AACxD,MAAI;AACF,UAAM,MAAM,UAAU;AACtB,UAAM,UAAU,MAAM,IAAI,SAAS,CAAC,iBAAiB,CAAC;AACtD,WAAO,QAAQ,KAAK;AAAA,EACtB,SAAS,OAAO;AACd,UAAM,YAAY,aAAa,aAAa;AAC5C,cAAU,sCAAsC,OAAO;AAAA,MACrD,OAAO;AAAA,IACT,CAAC;AACD,WAAO;AAAA,EACT;AACF;AASO,MAAM,eAAe,OAAO;AAAA,EACjC;AAAA,EACA,UAAU;AAAA,EACV,aAAa;AAAA;AAAA,EACb,WAAW;AACb,MAA2B;AACzB,MAAI;AACF,UAAM,MAAM,UAAU;AACtB,UAAM,OAAoB,oBAAI,IAAI;AAElC,QAAI,KAAK,SAAS,WAAW,GAAG;AAC9B,YAAM,SAAS,MAAM,IAAI,OAAO;AAChC,aAAO,UAAU,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC;AAAA,IAC7C;AAEA,QAAI,KAAK,SAAS,aAAa,GAAG;AAEhC,YAAM,kBAAkB,MAAM,IAAI,KAAK,CAAC,eAAe,MAAM,CAAC;AAE9D,YAAM,mBAAmB,gBAAgB,MAAM,IAAI,EAAE,OAAO,OAAO;AAEnE,uBAAiB,QAAQ,CAAC,SAAS,KAAK,IAAI,IAAI,CAAC;AAAA,IACnD;AAEA,QAAI,KAAK,SAAS,UAAU,GAAG;AAE7B,YAAM,eAAe,MAAM,IAAI,KAAK,CAAC,eAAe,gBAAgB,CAAC;AAErE,YAAM,gBAAgB,aAAa,MAAM,IAAI,EAAE,OAAO,OAAO;AAE7D,oBAAc,QAAQ,CAAC,SAAS,KAAK,IAAI,IAAI,CAAC;AAAA,IAChD;AAEA,QAAI,KAAK,SAAS,SAAS,GAAG;AAG5B,YAAM,IAAI,MAAM,OAAO;AAEvB,YAAM,aAAa,MAAM,IAAI,KAAK;AAAA,QAChC;AAAA,QACA,GAAG,OAAO,MAAM,UAAU;AAAA,MAC5B,CAAC;AAED,YAAM,eAAe,WAAW,MAAM,IAAI,EAAE,OAAO,OAAO;AAE1D,mBAAa,QAAQ,CAAC,SAAS,KAAK,IAAI,IAAI,CAAC;AAAA,IAC/C;AAEA,QAAI,UAAU;AACZ,YAAM,aAAa,MAAM,cAAc;AACvC,UAAI,CAAC,YAAY;AACf,eAAO,CAAC;AAAA,MACV;AACA,aAAO,MAAM,KAAK,IAAI,EAAE,IAAI,CAAC,SAAS,KAAK,YAAY,IAAI,CAAC;AAAA,IAC9D;AAEA,WAAO,MAAM,KAAK,IAAI;AAAA,EACxB,SAAS,OAAO;AACd,YAAQ,KAAK,+BAA+B,KAAK;AAAA,EACnD;AACF;","names":[]}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ESMxCJSRequire,
|
|
3
|
+
getAppLogger,
|
|
4
|
+
getConfiguration
|
|
5
|
+
} from "@intlayer/config";
|
|
3
6
|
import { fetchDistantDictionaryKeys } from "../fetchDistantDictionaryKeys.mjs";
|
|
4
7
|
import { logger } from "../log.mjs";
|
|
5
|
-
import { mergeByKey } from "../mergeDictionaries.mjs";
|
|
6
8
|
import { sortAlphabetically } from "../utils.mjs";
|
|
7
9
|
import { loadContentDeclarations } from "./loadContentDeclaration.mjs";
|
|
8
10
|
import { loadDistantDictionaries } from "./loadDistantDictionaries.mjs";
|
|
9
11
|
const loadDictionaries = async (contentDeclarationsPaths, configuration = getConfiguration(), projectRequire = ESMxCJSRequire) => {
|
|
10
12
|
try {
|
|
13
|
+
const appLogger = getAppLogger(configuration);
|
|
11
14
|
const { editor } = configuration;
|
|
12
15
|
appLogger("Dictionaries:", { isVerbose: true });
|
|
13
16
|
const files = Array.isArray(contentDeclarationsPaths) ? contentDeclarationsPaths : [contentDeclarationsPaths];
|
|
@@ -26,7 +29,6 @@ const loadDictionaries = async (contentDeclarationsPaths, configuration = getCon
|
|
|
26
29
|
);
|
|
27
30
|
let distantDictionaries = [];
|
|
28
31
|
let distantDictionaryKeys = [];
|
|
29
|
-
let mergedDictionaries = localDictionaries;
|
|
30
32
|
if (editor.clientId && editor.clientSecret) {
|
|
31
33
|
try {
|
|
32
34
|
distantDictionaryKeys = await fetchDistantDictionaryKeys();
|
|
@@ -35,15 +37,6 @@ const loadDictionaries = async (contentDeclarationsPaths, configuration = getCon
|
|
|
35
37
|
distantDictionaries = await loadDistantDictionaries({
|
|
36
38
|
dictionaryKeys: orderedDistantDictionaryKeys
|
|
37
39
|
});
|
|
38
|
-
if (editor.dictionaryPriorityStrategy === "distant_first") {
|
|
39
|
-
mergedDictionaries = merge(localDictionaries, distantDictionaries, {
|
|
40
|
-
arrayMerge: mergeByKey("key")
|
|
41
|
-
});
|
|
42
|
-
} else {
|
|
43
|
-
mergedDictionaries = merge(distantDictionaries, localDictionaries, {
|
|
44
|
-
arrayMerge: mergeByKey("key")
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
40
|
} catch (_error) {
|
|
48
41
|
appLogger("Error during fetching distant dictionaries", {
|
|
49
42
|
level: "error"
|
|
@@ -51,7 +44,7 @@ const loadDictionaries = async (contentDeclarationsPaths, configuration = getCon
|
|
|
51
44
|
}
|
|
52
45
|
}
|
|
53
46
|
logger.stop();
|
|
54
|
-
return
|
|
47
|
+
return [...localDictionaries, ...distantDictionaries];
|
|
55
48
|
} catch (error) {
|
|
56
49
|
logger.stop();
|
|
57
50
|
throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport {\n ESMxCJSRequire,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { fetchDistantDictionaryKeys } from '../fetchDistantDictionaryKeys';\nimport { logger } from '../log';\nimport { sortAlphabetically } from '../utils';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadDistantDictionaries } from './loadDistantDictionaries';\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string,\n configuration = getConfiguration(),\n projectRequire = ESMxCJSRequire\n): Promise<Dictionary[]> => {\n try {\n const appLogger = getAppLogger(configuration);\n const { editor } = 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 projectRequire\n );\n const localDictionaryKeys = localDictionaries\n .map((dict) => dict.key)\n .filter(Boolean); // Remove empty or undefined keys\n\n // Initialize the logger with both local and distant dictionaries\n logger.init(localDictionaryKeys, []);\n\n // Update logger statuses for local dictionaries\n logger.updateStatus(\n localDictionaries.map((dict) => ({\n dictionaryKey: dict.key,\n type: 'local',\n status: { status: 'built' },\n }))\n );\n\n let distantDictionaries: DictionaryAPI[] = [];\n let distantDictionaryKeys: string[] = [];\n\n if (editor.clientId && editor.clientSecret) {\n try {\n // Fetch distant dictionary keys\n distantDictionaryKeys = await fetchDistantDictionaryKeys();\n\n const orderedDistantDictionaryKeys =\n distantDictionaryKeys.sort(sortAlphabetically);\n\n // Add distant dictionaries to the logger\n logger.addDictionaryKeys('distant', orderedDistantDictionaryKeys);\n\n // Fetch distant dictionaries\n distantDictionaries = await loadDistantDictionaries({\n dictionaryKeys: orderedDistantDictionaryKeys,\n });\n } catch (_error) {\n appLogger('Error during fetching distant dictionaries', {\n level: 'error',\n });\n }\n }\n\n // Ensure the logger is stopped\n logger.stop();\n\n return [...localDictionaries, ...distantDictionaries];\n } catch (error) {\n // Ensure the logger is stopped\n logger.stop();\n\n throw error; // Re-throw the error after logging\n }\n};\n"],"mappings":"AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,kCAAkC;AAC3C,SAAS,cAAc;AACvB,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AACxC,SAAS,+BAA+B;AAEjC,MAAM,mBAAmB,OAC9B,0BACA,gBAAgB,iBAAiB,GACjC,iBAAiB,mBACS;AAC1B,MAAI;AACF,UAAM,YAAY,aAAa,aAAa;AAC5C,UAAM,EAAE,OAAO,IAAI;AAEnB,cAAU,iBAAiB,EAAE,WAAW,KAAK,CAAC;AAE9C,UAAM,QAAQ,MAAM,QAAQ,wBAAwB,IAChD,2BACA,CAAC,wBAAwB;AAE7B,UAAM,oBAAkC,MAAM;AAAA,MAC5C;AAAA,MACA;AAAA,IACF;AACA,UAAM,sBAAsB,kBACzB,IAAI,CAAC,SAAS,KAAK,GAAG,EACtB,OAAO,OAAO;AAGjB,WAAO,KAAK,qBAAqB,CAAC,CAAC;AAGnC,WAAO;AAAA,MACL,kBAAkB,IAAI,CAAC,UAAU;AAAA,QAC/B,eAAe,KAAK;AAAA,QACpB,MAAM;AAAA,QACN,QAAQ,EAAE,QAAQ,QAAQ;AAAA,MAC5B,EAAE;AAAA,IACJ;AAEA,QAAI,sBAAuC,CAAC;AAC5C,QAAI,wBAAkC,CAAC;AAEvC,QAAI,OAAO,YAAY,OAAO,cAAc;AAC1C,UAAI;AAEF,gCAAwB,MAAM,2BAA2B;AAEzD,cAAM,+BACJ,sBAAsB,KAAK,kBAAkB;AAG/C,eAAO,kBAAkB,WAAW,4BAA4B;AAGhE,8BAAsB,MAAM,wBAAwB;AAAA,UAClD,gBAAgB;AAAA,QAClB,CAAC;AAAA,MACH,SAAS,QAAQ;AACf,kBAAU,8CAA8C;AAAA,UACtD,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAGA,WAAO,KAAK;AAEZ,WAAO,CAAC,GAAG,mBAAmB,GAAG,mBAAmB;AAAA,EACtD,SAAS,OAAO;AAEd,WAAO,KAAK;AAEZ,UAAM;AAAA,EACR;AACF;","names":[]}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { fetchDistantDictionaries } from "../fetchDistantDictionaries.mjs";
|
|
2
|
+
const formatDistantDictionaries = (dictionaries) => {
|
|
3
|
+
return dictionaries.map((dict) => ({
|
|
4
|
+
...dict,
|
|
5
|
+
location: "distant"
|
|
6
|
+
}));
|
|
7
|
+
};
|
|
2
8
|
const loadDistantDictionaries = async (options) => {
|
|
3
9
|
try {
|
|
4
10
|
const distantDictionaries = await fetchDistantDictionaries(options);
|
|
5
|
-
return distantDictionaries;
|
|
11
|
+
return formatDistantDictionaries(distantDictionaries);
|
|
6
12
|
} catch (error) {
|
|
7
13
|
console.error(error);
|
|
8
14
|
return [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loadDictionaries/loadDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { fetchDistantDictionaries } from '../fetchDistantDictionaries';\n\ntype LoadDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n};\n\nexport const loadDistantDictionaries = async (\n options: LoadDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n try {\n const distantDictionaries = await fetchDistantDictionaries(options);\n\n return distantDictionaries;\n } catch (error) {\n console.error(error);\n return [];\n }\n};\n"],"mappings":"AAEA,SAAS,gCAAgC;
|
|
1
|
+
{"version":3,"sources":["../../../src/loadDictionaries/loadDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { fetchDistantDictionaries } from '../fetchDistantDictionaries';\n\ntype LoadDistantDictionariesOptions = {\n dictionaryKeys: string[];\n newDictionariesPath?: string;\n};\n\nconst formatDistantDictionaries = (dictionaries: DictionaryAPI[]) => {\n return dictionaries.map((dict) => ({\n ...dict,\n location: 'distant' as const,\n }));\n};\n\nexport const loadDistantDictionaries = async (\n options: LoadDistantDictionariesOptions\n): Promise<DictionaryAPI[]> => {\n try {\n const distantDictionaries = await fetchDistantDictionaries(options);\n\n return formatDistantDictionaries(distantDictionaries);\n } catch (error) {\n console.error(error);\n return [];\n }\n};\n"],"mappings":"AAEA,SAAS,gCAAgC;AAOzC,MAAM,4BAA4B,CAAC,iBAAkC;AACnE,SAAO,aAAa,IAAI,CAAC,UAAU;AAAA,IACjC,GAAG;AAAA,IACH,UAAU;AAAA,EACZ,EAAE;AACJ;AAEO,MAAM,0BAA0B,OACrC,YAC6B;AAC7B,MAAI;AACF,UAAM,sBAAsB,MAAM,yBAAyB,OAAO;AAElE,WAAO,0BAA0B,mBAAmB;AAAA,EACtD,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
|
@@ -1,28 +1,49 @@
|
|
|
1
|
+
import { getAppLogger } from "@intlayer/config";
|
|
2
|
+
import configuration from "@intlayer/config/built";
|
|
3
|
+
import { getNodeType } from "@intlayer/core";
|
|
1
4
|
import merge from "deepmerge";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (sourceItem) {
|
|
12
|
-
const mergedItem = merge(targetItem, sourceItem, options);
|
|
13
|
-
destination.push(mergedItem);
|
|
14
|
-
sourceMap.delete(targetItem[key]);
|
|
15
|
-
} else {
|
|
16
|
-
destination.push(targetItem);
|
|
5
|
+
const checkTypesMatch = (obj1, obj2, dictionaryKey, path = []) => {
|
|
6
|
+
const appLogger = getAppLogger(configuration);
|
|
7
|
+
const type1 = getNodeType(obj1);
|
|
8
|
+
const type2 = getNodeType(obj2);
|
|
9
|
+
if (type1 !== type2) {
|
|
10
|
+
appLogger(
|
|
11
|
+
`Error: Dictionary ${dictionaryKey} has a multiple content files with type mismatch at path "${path.join(".")}": Cannot merge ${type1} with ${type2}`,
|
|
12
|
+
{
|
|
13
|
+
level: "error"
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
if (type1 === "object" && obj1 && obj2) {
|
|
18
|
+
const allKeys = /* @__PURE__ */ new Set([...Object.keys(obj1), ...Object.keys(obj2)]);
|
|
19
|
+
for (const key of allKeys) {
|
|
20
|
+
if (key in obj1 && key in obj2) {
|
|
21
|
+
checkTypesMatch(obj1[key], obj2[key], dictionaryKey, [...path, key]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const mergeDictionaries = (dictionaries) => {
|
|
27
|
+
const { editor } = configuration;
|
|
28
|
+
let mergedDictionaries = dictionaries[0];
|
|
29
|
+
for (let i = 1; i < dictionaries.length; i++) {
|
|
30
|
+
const currentDictionary = dictionaries[i];
|
|
31
|
+
checkTypesMatch(
|
|
32
|
+
mergedDictionaries,
|
|
33
|
+
currentDictionary,
|
|
34
|
+
currentDictionary.key,
|
|
35
|
+
[]
|
|
36
|
+
);
|
|
37
|
+
const isDistant = currentDictionary.location === "distant";
|
|
38
|
+
if (editor.dictionaryPriorityStrategy === "distant_first" && isDistant) {
|
|
39
|
+
mergedDictionaries = merge(mergedDictionaries, currentDictionary);
|
|
40
|
+
} else {
|
|
41
|
+
mergedDictionaries = merge(currentDictionary, mergedDictionaries);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return { ...mergedDictionaries, filePath: void 0 };
|
|
24
45
|
};
|
|
25
46
|
export {
|
|
26
|
-
|
|
47
|
+
mergeDictionaries
|
|
27
48
|
};
|
|
28
49
|
//# sourceMappingURL=mergeDictionaries.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mergeDictionaries.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/mergeDictionaries.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/core';\nimport { getNodeType } from '@intlayer/core';\nimport merge from 'deepmerge';\n\nconst checkTypesMatch = (\n obj1: any,\n obj2: any,\n dictionaryKey: string,\n path: string[] = []\n): void => {\n const appLogger = getAppLogger(configuration);\n const type1 = getNodeType(obj1);\n const type2 = getNodeType(obj2);\n\n if (type1 !== type2) {\n appLogger(\n `Error: Dictionary ${dictionaryKey} has a multiple content files with type mismatch at path \"${path.join('.')}\": Cannot merge ${type1} with ${type2}`,\n {\n level: 'error',\n }\n );\n }\n\n if (type1 === 'object' && obj1 && obj2) {\n const allKeys = new Set([...Object.keys(obj1), ...Object.keys(obj2)]);\n for (const key of allKeys) {\n if (key in obj1 && key in obj2) {\n checkTypesMatch(obj1[key], obj2[key], dictionaryKey, [...path, key]);\n }\n }\n }\n};\n\nexport const mergeDictionaries = (dictionaries: Dictionary[]): Dictionary => {\n const { editor } = configuration;\n\n let mergedDictionaries: Dictionary = dictionaries[0];\n\n for (let i = 1; i < dictionaries.length; i++) {\n const currentDictionary = dictionaries[i];\n\n // Check types before merging\n checkTypesMatch(\n mergedDictionaries,\n currentDictionary,\n currentDictionary.key,\n []\n );\n\n const isDistant = currentDictionary.location === 'distant';\n\n if (editor.dictionaryPriorityStrategy === 'distant_first' && isDistant) {\n mergedDictionaries = merge(mergedDictionaries, currentDictionary);\n } else {\n mergedDictionaries = merge(currentDictionary, mergedDictionaries);\n }\n }\n\n return { ...mergedDictionaries, filePath: undefined };\n};\n"],"mappings":"AAAA,SAAS,oBAAoB;AAC7B,OAAO,mBAAmB;AAE1B,SAAS,mBAAmB;AAC5B,OAAO,WAAW;AAElB,MAAM,kBAAkB,CACtB,MACA,MACA,eACA,OAAiB,CAAC,MACT;AACT,QAAM,YAAY,aAAa,aAAa;AAC5C,QAAM,QAAQ,YAAY,IAAI;AAC9B,QAAM,QAAQ,YAAY,IAAI;AAE9B,MAAI,UAAU,OAAO;AACnB;AAAA,MACE,qBAAqB,aAAa,6DAA6D,KAAK,KAAK,GAAG,CAAC,mBAAmB,KAAK,SAAS,KAAK;AAAA,MACnJ;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,MAAI,UAAU,YAAY,QAAQ,MAAM;AACtC,UAAM,UAAU,oBAAI,IAAI,CAAC,GAAG,OAAO,KAAK,IAAI,GAAG,GAAG,OAAO,KAAK,IAAI,CAAC,CAAC;AACpE,eAAW,OAAO,SAAS;AACzB,UAAI,OAAO,QAAQ,OAAO,MAAM;AAC9B,wBAAgB,KAAK,GAAG,GAAG,KAAK,GAAG,GAAG,eAAe,CAAC,GAAG,MAAM,GAAG,CAAC;AAAA,MACrE;AAAA,IACF;AAAA,EACF;AACF;AAEO,MAAM,oBAAoB,CAAC,iBAA2C;AAC3E,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI,qBAAiC,aAAa,CAAC;AAEnD,WAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAC5C,UAAM,oBAAoB,aAAa,CAAC;AAGxC;AAAA,MACE;AAAA,MACA;AAAA,MACA,kBAAkB;AAAA,MAClB,CAAC;AAAA,IACH;AAEA,UAAM,YAAY,kBAAkB,aAAa;AAEjD,QAAI,OAAO,+BAA+B,mBAAmB,WAAW;AACtE,2BAAqB,MAAM,oBAAoB,iBAAiB;AAAA,IAClE,OAAO;AACL,2BAAqB,MAAM,mBAAmB,kBAAkB;AAAA,IAClE;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,oBAAoB,UAAU,OAAU;AACtD;","names":[]}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ESMxCJSRequire,
|
|
3
|
-
|
|
3
|
+
getAppLogger,
|
|
4
4
|
getConfiguration
|
|
5
5
|
} from "@intlayer/config";
|
|
6
6
|
import { cleanOutputDir } from "./cleanOutputDir.mjs";
|
|
7
|
+
import { listDictionaries } from "./listDictionariesPath.mjs";
|
|
7
8
|
import { loadDictionaries } from "./loadDictionaries/loadDictionaries.mjs";
|
|
8
9
|
import { buildDictionary } from "./transpiler/declaration_file_to_dictionary/index.mjs";
|
|
9
10
|
import { createDictionaryEntryPoint } from "./transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs";
|
|
10
11
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
createModuleAugmentation,
|
|
13
|
+
createTypes
|
|
13
14
|
} from "./transpiler/dictionary_to_type/index.mjs";
|
|
14
15
|
import { writeConfiguration } from "./writeConfiguration/index.mjs";
|
|
15
|
-
import { listDictionaries } from "./listDictionariesPath.mjs";
|
|
16
16
|
const prepareIntlayer = async (configuration = getConfiguration(), projectRequire = ESMxCJSRequire) => {
|
|
17
|
+
const appLogger = getAppLogger(configuration);
|
|
17
18
|
cleanOutputDir(configuration);
|
|
18
19
|
appLogger("Output directory cleaned", {
|
|
19
20
|
isVerbose: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n type IntlayerConfig,\n
|
|
1
|
+
{"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n type IntlayerConfig,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { listDictionaries } from './listDictionariesPath';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createModuleAugmentation,\n createTypes,\n} from './transpiler/dictionary_to_type/index';\nimport { writeConfiguration } from './writeConfiguration';\n\nexport const prepareIntlayer = async (\n configuration: IntlayerConfig = getConfiguration(),\n projectRequire = ESMxCJSRequire\n) => {\n const appLogger = getAppLogger(configuration);\n\n cleanOutputDir(configuration);\n\n appLogger('Output directory cleaned', {\n isVerbose: true,\n });\n\n const files: string[] = listDictionaries(configuration);\n\n const dictionaries = await loadDictionaries(\n files,\n configuration,\n projectRequire\n );\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries, configuration);\n\n createTypes(dictionariesPaths, configuration);\n\n createDictionaryEntryPoint(configuration);\n\n appLogger('Dictionaries built');\n\n createModuleAugmentation(configuration);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n writeConfiguration(configuration);\n\n appLogger('Configuration written', {\n isVerbose: true,\n });\n};\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AAE5B,MAAM,kBAAkB,OAC7B,gBAAgC,iBAAiB,GACjD,iBAAiB,mBACd;AACH,QAAM,YAAY,aAAa,aAAa;AAE5C,iBAAe,aAAa;AAE5B,YAAU,4BAA4B;AAAA,IACpC,WAAW;AAAA,EACb,CAAC;AAED,QAAM,QAAkB,iBAAiB,aAAa;AAEtD,QAAM,eAAe,MAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGA,QAAM,oBAAoB,MAAM,gBAAgB,cAAc,aAAa;AAE3E,cAAY,mBAAmB,aAAa;AAE5C,6BAA2B,aAAa;AAExC,YAAU,oBAAoB;AAE9B,2BAAyB,aAAa;AAEtC,YAAU,6BAA6B;AAAA,IACrC,WAAW;AAAA,EACb,CAAC;AAED,qBAAmB,aAAa;AAEhC,YAAU,yBAAyB;AAAA,IACjC,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { deepTransformNode, t } from "@intlayer/core";
|
|
2
|
+
const processPerLocaleDictionary = (dictionary) => {
|
|
3
|
+
const isPerLocaleDictionary = typeof dictionary.locale === "string";
|
|
4
|
+
if (!isPerLocaleDictionary) {
|
|
5
|
+
return dictionary;
|
|
6
|
+
}
|
|
7
|
+
const transformStringToTranslationPlugin = {
|
|
8
|
+
id: "transform-string-to-translation-plugin",
|
|
9
|
+
canHandle: (node) => typeof node === "string" || typeof node === "number",
|
|
10
|
+
transform: (node) => t({ [dictionary.locale]: node })
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
...dictionary,
|
|
14
|
+
locale: void 0,
|
|
15
|
+
content: deepTransformNode(dictionary.content, {
|
|
16
|
+
dictionaryKey: dictionary.key,
|
|
17
|
+
keyPath: [],
|
|
18
|
+
plugins: [transformStringToTranslationPlugin]
|
|
19
|
+
})
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
processPerLocaleDictionary
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=processPerLocaleDictionary.mjs.map
|