@intlayer/chokidar 5.4.1 → 5.5.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 +3 -3
- 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 +4 -3
- 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 +98 -0
- package/dist/cjs/listGitFiles.cjs.map +1 -0
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +1 -23
- 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 +43 -23
- package/dist/cjs/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +1 -1
- 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 +61 -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 +377 -0
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -0
- package/dist/esm/chokidar/watcher.mjs +5 -5
- 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 +5 -4
- 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 +64 -0
- package/dist/esm/listGitFiles.mjs.map +1 -0
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +1 -13
- 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 +42 -22
- package/dist/esm/mergeDictionaries.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +3 -3
- 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 +37 -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 +345 -0
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -0
- 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/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
|
@@ -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,64 @@
|
|
|
1
|
+
import { appLogger } from "@intlayer/config";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import simpleGit from "simple-git";
|
|
4
|
+
const getGitRootDir = async () => {
|
|
5
|
+
try {
|
|
6
|
+
const git = simpleGit();
|
|
7
|
+
const rootDir = await git.revparse(["--show-toplevel"]);
|
|
8
|
+
return rootDir.trim();
|
|
9
|
+
} catch (error) {
|
|
10
|
+
appLogger("Error getting git root directory:" + error, {
|
|
11
|
+
level: "error"
|
|
12
|
+
});
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const listGitFiles = async ({
|
|
17
|
+
mode,
|
|
18
|
+
baseRef = "origin/main",
|
|
19
|
+
currentRef = "HEAD",
|
|
20
|
+
// HEAD points to the current branch's latest commit
|
|
21
|
+
absolute = true
|
|
22
|
+
}) => {
|
|
23
|
+
try {
|
|
24
|
+
const git = simpleGit();
|
|
25
|
+
const diff = /* @__PURE__ */ new Set();
|
|
26
|
+
if (mode.includes("untracked")) {
|
|
27
|
+
const status = await git.status();
|
|
28
|
+
status.not_added.forEach((f) => diff.add(f));
|
|
29
|
+
}
|
|
30
|
+
if (mode.includes("uncommitted")) {
|
|
31
|
+
const uncommittedDiff = await git.diff(["--name-only", "HEAD"]);
|
|
32
|
+
const uncommittedFiles = uncommittedDiff.split("\n").filter(Boolean);
|
|
33
|
+
uncommittedFiles.forEach((file) => diff.add(file));
|
|
34
|
+
}
|
|
35
|
+
if (mode.includes("unpushed")) {
|
|
36
|
+
const unpushedDiff = await git.diff(["--name-only", "@{push}...HEAD"]);
|
|
37
|
+
const unpushedFiles = unpushedDiff.split("\n").filter(Boolean);
|
|
38
|
+
unpushedFiles.forEach((file) => diff.add(file));
|
|
39
|
+
}
|
|
40
|
+
if (mode.includes("gitDiff")) {
|
|
41
|
+
await git.fetch(baseRef);
|
|
42
|
+
const diffBranch = await git.diff([
|
|
43
|
+
"--name-only",
|
|
44
|
+
`${baseRef}...${currentRef}`
|
|
45
|
+
]);
|
|
46
|
+
const gitDiffFiles = diffBranch.split("\n").filter(Boolean);
|
|
47
|
+
gitDiffFiles.forEach((file) => diff.add(file));
|
|
48
|
+
}
|
|
49
|
+
if (absolute) {
|
|
50
|
+
const gitRootDir = await getGitRootDir();
|
|
51
|
+
if (!gitRootDir) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
return Array.from(diff).map((file) => join(gitRootDir, file));
|
|
55
|
+
}
|
|
56
|
+
return Array.from(diff);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.warn("Failed to get changes list:", error);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export {
|
|
62
|
+
listGitFiles
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=listGitFiles.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/listGitFiles.ts"],"sourcesContent":["import { appLogger } from '@intlayer/config';\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 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,iBAAiB;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,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,8 +1,6 @@
|
|
|
1
1
|
import { appLogger, ESMxCJSRequire, getConfiguration } from "@intlayer/config";
|
|
2
|
-
import merge from "deepmerge";
|
|
3
2
|
import { fetchDistantDictionaryKeys } from "../fetchDistantDictionaryKeys.mjs";
|
|
4
3
|
import { logger } from "../log.mjs";
|
|
5
|
-
import { mergeByKey } from "../mergeDictionaries.mjs";
|
|
6
4
|
import { sortAlphabetically } from "../utils.mjs";
|
|
7
5
|
import { loadContentDeclarations } from "./loadContentDeclaration.mjs";
|
|
8
6
|
import { loadDistantDictionaries } from "./loadDistantDictionaries.mjs";
|
|
@@ -26,7 +24,6 @@ const loadDictionaries = async (contentDeclarationsPaths, configuration = getCon
|
|
|
26
24
|
);
|
|
27
25
|
let distantDictionaries = [];
|
|
28
26
|
let distantDictionaryKeys = [];
|
|
29
|
-
let mergedDictionaries = localDictionaries;
|
|
30
27
|
if (editor.clientId && editor.clientSecret) {
|
|
31
28
|
try {
|
|
32
29
|
distantDictionaryKeys = await fetchDistantDictionaryKeys();
|
|
@@ -35,15 +32,6 @@ const loadDictionaries = async (contentDeclarationsPaths, configuration = getCon
|
|
|
35
32
|
distantDictionaries = await loadDistantDictionaries({
|
|
36
33
|
dictionaryKeys: orderedDistantDictionaryKeys
|
|
37
34
|
});
|
|
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
35
|
} catch (_error) {
|
|
48
36
|
appLogger("Error during fetching distant dictionaries", {
|
|
49
37
|
level: "error"
|
|
@@ -51,7 +39,7 @@ const loadDictionaries = async (contentDeclarationsPaths, configuration = getCon
|
|
|
51
39
|
}
|
|
52
40
|
}
|
|
53
41
|
logger.stop();
|
|
54
|
-
return
|
|
42
|
+
return [...localDictionaries, ...distantDictionaries];
|
|
55
43
|
} catch (error) {
|
|
56
44
|
logger.stop();
|
|
57
45
|
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 { appLogger, ESMxCJSRequire, getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\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 { appLogger, ESMxCJSRequire, getConfiguration } 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 { 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,SAAS,WAAW,gBAAgB,wBAAwB;AAE5D,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,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,48 @@
|
|
|
1
|
+
import { appLogger } 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
|
-
const sourceItem = sourceMap.get(targetItem[key]);
|
|
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 type1 = getNodeType(obj1);
|
|
7
|
+
const type2 = getNodeType(obj2);
|
|
8
|
+
if (type1 !== type2) {
|
|
9
|
+
appLogger(
|
|
10
|
+
`Error: Dictionary ${dictionaryKey} has a multiple content files with type mismatch at path "${path.join(".")}": Cannot merge ${type1} with ${type2}`,
|
|
11
|
+
{
|
|
12
|
+
level: "error"
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
if (type1 === "object" && obj1 && obj2) {
|
|
17
|
+
const allKeys = /* @__PURE__ */ new Set([...Object.keys(obj1), ...Object.keys(obj2)]);
|
|
18
|
+
for (const key of allKeys) {
|
|
19
|
+
if (key in obj1 && key in obj2) {
|
|
20
|
+
checkTypesMatch(obj1[key], obj2[key], dictionaryKey, [...path, key]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const mergeDictionaries = (dictionaries) => {
|
|
26
|
+
const { editor } = configuration;
|
|
27
|
+
let mergedDictionaries = dictionaries[0];
|
|
28
|
+
for (let i = 1; i < dictionaries.length; i++) {
|
|
29
|
+
const currentDictionary = dictionaries[i];
|
|
30
|
+
checkTypesMatch(
|
|
31
|
+
mergedDictionaries,
|
|
32
|
+
currentDictionary,
|
|
33
|
+
currentDictionary.key,
|
|
34
|
+
[]
|
|
35
|
+
);
|
|
36
|
+
const isDistant = currentDictionary.location === "distant";
|
|
37
|
+
if (editor.dictionaryPriorityStrategy === "distant_first" && isDistant) {
|
|
38
|
+
mergedDictionaries = merge(mergedDictionaries, currentDictionary);
|
|
39
|
+
} else {
|
|
40
|
+
mergedDictionaries = merge(currentDictionary, mergedDictionaries);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { ...mergedDictionaries, filePath: void 0 };
|
|
24
44
|
};
|
|
25
45
|
export {
|
|
26
|
-
|
|
46
|
+
mergeDictionaries
|
|
27
47
|
};
|
|
28
48
|
//# sourceMappingURL=mergeDictionaries.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mergeDictionaries.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/mergeDictionaries.ts"],"sourcesContent":["import { appLogger } 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 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,iBAAiB;AAC1B,OAAO,mBAAmB;AAE1B,SAAS,mBAAmB;AAC5B,OAAO,WAAW;AAElB,MAAM,kBAAkB,CACtB,MACA,MACA,eACA,OAAiB,CAAC,MACT;AACT,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":[]}
|
|
@@ -4,15 +4,15 @@ import {
|
|
|
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
17
|
cleanOutputDir(configuration);
|
|
18
18
|
appLogger("Output directory cleaned", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n type IntlayerConfig,\n appLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n
|
|
1
|
+
{"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n type IntlayerConfig,\n appLogger,\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 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,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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/processPerLocaleDictionary.ts"],"sourcesContent":["import { deepTransformNode, Plugins, t, type Dictionary } from '@intlayer/core';\n\n/**\n *\n * Should transform per locale dictionaries to multi-locale dictionaries\n *\n * Example:\n *\n * ```json5\n * // .intlayer/dictionaries/home.fr.json\n * { 'key': 'home', 'locale': 'fr', 'content': { 'example': \"value\", ... } },\n * ```\n *\n * Result:\n *\n * ```json5\n * // .intlayer/dictionaries/home.json\n * {\n * 'key': 'home',\n * 'content': {\n * 'example': {\n * 'nodeType': 'translation',\n * 'translation': {\n * 'fr': 'valeur',\n * }\n * }, ... } },\n * ```\n *\n * @param dictionary\n * @returns\n */\nexport const processPerLocaleDictionary = (dictionary: Dictionary) => {\n const isPerLocaleDictionary = typeof dictionary.locale === 'string';\n\n if (!isPerLocaleDictionary) {\n return dictionary;\n }\n\n const transformStringToTranslationPlugin: Plugins = {\n id: 'transform-string-to-translation-plugin',\n canHandle: (node) => typeof node === 'string' || typeof node === 'number',\n transform: (node: string | number) =>\n t({ [dictionary.locale as string]: node }),\n };\n\n return {\n ...dictionary,\n locale: undefined,\n content: deepTransformNode(dictionary.content, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [transformStringToTranslationPlugin],\n }),\n };\n};\n"],"mappings":"AAAA,SAAS,mBAA4B,SAA0B;AA+BxD,MAAM,6BAA6B,CAAC,eAA2B;AACpE,QAAM,wBAAwB,OAAO,WAAW,WAAW;AAE3D,MAAI,CAAC,uBAAuB;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,qCAA8C;AAAA,IAClD,IAAI;AAAA,IACJ,WAAW,CAAC,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS;AAAA,IACjE,WAAW,CAAC,SACV,EAAE,EAAE,CAAC,WAAW,MAAgB,GAAG,KAAK,CAAC;AAAA,EAC7C;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ;AAAA,IACR,SAAS,kBAAkB,WAAW,SAAS;AAAA,MAC7C,eAAe,WAAW;AAAA,MAC1B,SAAS,CAAC;AAAA,MACV,SAAS,CAAC,kCAAkC;AAAA,IAC9C,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const applyMask = (full, mask) => {
|
|
2
|
+
if (mask === true) {
|
|
3
|
+
return full;
|
|
4
|
+
}
|
|
5
|
+
if (Array.isArray(mask) && Array.isArray(full)) {
|
|
6
|
+
return mask.map((m, i) => applyMask(full[i], m));
|
|
7
|
+
}
|
|
8
|
+
if (full && typeof full === "object" && "nodeType" in full) {
|
|
9
|
+
if (mask && typeof mask === "object") {
|
|
10
|
+
return full;
|
|
11
|
+
}
|
|
12
|
+
return full;
|
|
13
|
+
}
|
|
14
|
+
if (mask && typeof mask === "object" && full && typeof full === "object") {
|
|
15
|
+
const out = {};
|
|
16
|
+
for (const [k, m] of Object.entries(mask)) {
|
|
17
|
+
out[k] = applyMask(full[k], m);
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
return full;
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
applyMask
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=applyMask.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/reduceDictionaryContent/applyMask.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/core';\n\nexport const applyMask = (full: Dictionary, mask: any): Dictionary => {\n // the mask \"true\" → we don't filter\n if (mask === true) {\n return full;\n }\n\n // arrays\n if (Array.isArray(mask) && Array.isArray(full)) {\n return mask.map((m, i) => applyMask(full[i], m)) as any;\n }\n\n // handle node with nodeType property\n if (full && typeof full === 'object' && 'nodeType' in full) {\n if (mask && typeof mask === 'object') {\n return full; // Keep the full object with nodeType intact\n }\n return full;\n }\n\n // generic object\n if (mask && typeof mask === 'object' && full && typeof full === 'object') {\n const out: any = {};\n for (const [k, m] of Object.entries(mask)) {\n out[k] = applyMask((full as any)[k], m);\n }\n return out;\n }\n\n // unexpected case: we return the original value\n return full;\n};\n"],"mappings":"AAEO,MAAM,YAAY,CAAC,MAAkB,SAA0B;AAEpE,MAAI,SAAS,MAAM;AACjB,WAAO;AAAA,EACT;AAGA,MAAI,MAAM,QAAQ,IAAI,KAAK,MAAM,QAAQ,IAAI,GAAG;AAC9C,WAAO,KAAK,IAAI,CAAC,GAAG,MAAM,UAAU,KAAK,CAAC,GAAG,CAAC,CAAC;AAAA,EACjD;AAGA,MAAI,QAAQ,OAAO,SAAS,YAAY,cAAc,MAAM;AAC1D,QAAI,QAAQ,OAAO,SAAS,UAAU;AACpC,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAGA,MAAI,QAAQ,OAAO,SAAS,YAAY,QAAQ,OAAO,SAAS,UAAU;AACxE,UAAM,MAAW,CAAC;AAClB,eAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,IAAI,GAAG;AACzC,UAAI,CAAC,IAAI,UAAW,KAAa,CAAC,GAAG,CAAC;AAAA,IACxC;AACA,WAAO;AAAA,EACT;AAGA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { deepTransformNode } from "@intlayer/core";
|
|
2
|
+
const passTypedNodePlugin = {
|
|
3
|
+
id: "pass-typed-node-plugin",
|
|
4
|
+
canHandle: (node) => typeof node === "object" && typeof node?.nodeType === "string",
|
|
5
|
+
transform: (node, props, deepTransformNode2) => deepTransformNode2(node[node.nodeType], props)
|
|
6
|
+
};
|
|
7
|
+
const buildMaskPlugin = {
|
|
8
|
+
id: "build-mask-plugin",
|
|
9
|
+
canHandle: (node) => typeof node === "string" || typeof node === "number",
|
|
10
|
+
transform: () => true
|
|
11
|
+
};
|
|
12
|
+
const buildMask = (source) => ({
|
|
13
|
+
...source,
|
|
14
|
+
content: deepTransformNode(source.content, {
|
|
15
|
+
dictionaryKey: source.key,
|
|
16
|
+
keyPath: [],
|
|
17
|
+
plugins: [passTypedNodePlugin, buildMaskPlugin]
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
export {
|
|
21
|
+
buildMask,
|
|
22
|
+
buildMaskPlugin
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=buildMask.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/reduceDictionaryContent/buildMask.ts"],"sourcesContent":["import { deepTransformNode, Dictionary, type Plugins } from '@intlayer/core';\n\nconst passTypedNodePlugin: Plugins = {\n id: 'pass-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node, props, deepTransformNode) =>\n deepTransformNode(node[node.nodeType], props),\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const buildMaskPlugin: Plugins = {\n id: 'build-mask-plugin',\n canHandle: (node) => typeof node === 'string' || typeof node === 'number',\n transform: () => true,\n};\n\nexport const buildMask = (source: Dictionary): any => ({\n ...source,\n content: deepTransformNode(source.content, {\n dictionaryKey: source.key,\n keyPath: [],\n plugins: [passTypedNodePlugin, buildMaskPlugin],\n }),\n});\n"],"mappings":"AAAA,SAAS,yBAAmD;AAE5D,MAAM,sBAA+B;AAAA,EACnC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,OAAO,MAAM,aAAa;AAAA,EACxD,WAAW,CAAC,MAAM,OAAOA,uBACvBA,mBAAkB,KAAK,KAAK,QAAQ,GAAG,KAAK;AAChD;AAGO,MAAM,kBAA2B;AAAA,EACtC,IAAI;AAAA,EACJ,WAAW,CAAC,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS;AAAA,EACjE,WAAW,MAAM;AACnB;AAEO,MAAM,YAAY,CAAC,YAA6B;AAAA,EACrD,GAAG;AAAA,EACH,SAAS,kBAAkB,OAAO,SAAS;AAAA,IACzC,eAAe,OAAO;AAAA,IACtB,SAAS,CAAC;AAAA,IACV,SAAS,CAAC,qBAAqB,eAAe;AAAA,EAChD,CAAC;AACH;","names":["deepTransformNode"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { applyMask } from "./applyMask.mjs";
|
|
2
|
+
import { buildMask } from "./buildMask.mjs";
|
|
3
|
+
const reduceDictionaryContent = (fullDictionary, partialDictionary) => {
|
|
4
|
+
const mask = buildMask(partialDictionary);
|
|
5
|
+
const result = applyMask(fullDictionary, mask);
|
|
6
|
+
return result;
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
reduceDictionaryContent
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=reduceDictionaryContent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/reduceDictionaryContent/reduceDictionaryContent.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/core';\nimport { applyMask } from './applyMask';\nimport { buildMask } from './buildMask';\n\nexport const reduceDictionaryContent = (\n fullDictionary: Dictionary,\n partialDictionary: Dictionary\n) => {\n const mask = buildMask(partialDictionary);\n const result = applyMask(fullDictionary, mask);\n\n return result;\n};\n"],"mappings":"AACA,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAEnB,MAAM,0BAA0B,CACrC,gBACA,sBACG;AACH,QAAM,OAAO,UAAU,iBAAiB;AACxC,QAAM,SAAS,UAAU,gBAAgB,IAAI;AAE7C,SAAO;AACT;","names":[]}
|
package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { getConfiguration } from "@intlayer/config";
|
|
1
2
|
import { mkdir, writeFile } from "fs/promises";
|
|
2
3
|
import { resolve } from "path";
|
|
3
|
-
import { getConfiguration } from "@intlayer/config";
|
|
4
4
|
const writeDictionary = async (dictionariesDeclaration, configuration = getConfiguration()) => {
|
|
5
5
|
const { i18nextResourcesDir } = configuration.content;
|
|
6
6
|
const resultDictionariesPaths = [];
|
|
@@ -10,9 +10,9 @@ const writeDictionary = async (dictionariesDeclaration, configuration = getConfi
|
|
|
10
10
|
for await (const [locale, content] of Object.entries(localContent)) {
|
|
11
11
|
const contentString = JSON.stringify(content);
|
|
12
12
|
const outputFileName = `${nameSpace}.json`;
|
|
13
|
-
const
|
|
14
|
-
const resultFilePath = resolve(
|
|
15
|
-
await mkdir(
|
|
13
|
+
const dictionariesDirPath = resolve(i18nextResourcesDir, locale);
|
|
14
|
+
const resultFilePath = resolve(dictionariesDirPath, outputFileName);
|
|
15
|
+
await mkdir(dictionariesDirPath, { recursive: true });
|
|
16
16
|
await writeFile(resultFilePath, contentString, "utf8").catch((err) => {
|
|
17
17
|
console.error(`Error creating ${outputFileName}:`, err);
|
|
18
18
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport type { I18nextDictionariesOutput } from './convertContentDeclarationInto18nDictionaries';\n\nexport type DictionariesDeclaration = Record<string, I18nextDictionariesOutput>;\n\n/**\n * This function writes the dictionaries to the file system\n */\nexport const writeDictionary = async (\n dictionariesDeclaration: DictionariesDeclaration,\n configuration = getConfiguration()\n) => {\n const { i18nextResourcesDir } = configuration.content;\n\n const resultDictionariesPaths: string[] = [];\n\n for (const [nameSpace, localContent] of Object.entries(\n dictionariesDeclaration\n )) {\n for await (const [locale, content] of Object.entries(localContent)) {\n const contentString = JSON.stringify(content);\n\n const outputFileName = `${nameSpace}.json`;\n const dictionariesDirPath = resolve(i18nextResourcesDir, locale);\n const resultFilePath = resolve(dictionariesDirPath, outputFileName);\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(dictionariesDirPath, { recursive: true });\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AACjC,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AAQjB,MAAM,kBAAkB,OAC7B,yBACA,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,EAAE,oBAAoB,IAAI,cAAc;AAE9C,QAAM,0BAAoC,CAAC;AAE3C,aAAW,CAAC,WAAW,YAAY,KAAK,OAAO;AAAA,IAC7C;AAAA,EACF,GAAG;AACD,qBAAiB,CAAC,QAAQ,OAAO,KAAK,OAAO,QAAQ,YAAY,GAAG;AAClE,YAAM,gBAAgB,KAAK,UAAU,OAAO;AAE5C,YAAM,iBAAiB,GAAG,SAAS;AACnC,YAAM,sBAAsB,QAAQ,qBAAqB,MAAM;AAC/D,YAAM,iBAAiB,QAAQ,qBAAqB,cAAc;AAGlE,YAAM,MAAM,qBAAqB,EAAE,WAAW,KAAK,CAAC;AAGpD,YAAM,UAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,gBAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,MACxD,CAAC;AAED,8BAAwB,KAAK,cAAc;AAAA,IAC7C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|