@intlayer/chokidar 5.5.3 → 5.5.5
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 +12 -3
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/getBuiltDynamicDictionariesPath.cjs +52 -0
- package/dist/cjs/getBuiltDynamicDictionariesPath.cjs.map +1 -0
- package/dist/cjs/{filterDictionaryLocales.cjs → getFilteredLocalesContent.cjs} +25 -13
- package/dist/cjs/getFilteredLocalesContent.cjs.map +1 -0
- package/dist/cjs/index.cjs +3 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +5 -2
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs +19 -8
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.cjs +30 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.cjs +108 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.cjs +59 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.cjs +65 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs +44 -35
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +1 -1
- package/dist/esm/chokidar/watcher.mjs +12 -3
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/getBuiltDynamicDictionariesPath.mjs +18 -0
- package/dist/esm/getBuiltDynamicDictionariesPath.mjs.map +1 -0
- package/dist/esm/{filterDictionaryLocales.mjs → getFilteredLocalesContent.mjs} +21 -9
- package/dist/esm/getFilteredLocalesContent.mjs.map +1 -0
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +5 -2
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs +19 -8
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.mjs +6 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs +83 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs +35 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs +41 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +44 -35
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
- package/dist/types/chokidar/watcher.d.ts.map +1 -1
- package/dist/types/getBuiltDynamicDictionariesPath.d.ts +5 -0
- package/dist/types/getBuiltDynamicDictionariesPath.d.ts.map +1 -0
- package/dist/types/getFilteredLocalesContent.d.ts +4 -0
- package/dist/types/getFilteredLocalesContent.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/prepareIntlayer.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts +5 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/index.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +5 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.d.ts +2 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts +31 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts +25 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.d.ts +28 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.d.ts.map +1 -0
- package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts +1 -1
- package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts.map +1 -1
- package/package.json +13 -13
- package/dist/cjs/filterDictionaryLocales.cjs.map +0 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs +0 -97
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs.map +0 -1
- package/dist/esm/filterDictionaryLocales.mjs.map +0 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs +0 -71
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs.map +0 -1
- package/dist/types/filterDictionaryLocales.d.ts +0 -4
- package/dist/types/filterDictionaryLocales.d.ts.map +0 -1
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts +0 -41
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts.map +0 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getConfiguration } from "@intlayer/config";
|
|
2
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
import { mergeDictionaries } from "../../../mergeDictionaries.mjs";
|
|
5
|
+
import { processPerLocaleDictionary } from "../../../processPerLocaleDictionary.mjs";
|
|
6
|
+
import { formatDictionaryText } from "./formatDictionaryText.mjs";
|
|
7
|
+
const writeMergedDictionaries = async (groupedDictionaries, configuration = getConfiguration()) => {
|
|
8
|
+
const { dictionariesDir } = configuration.content;
|
|
9
|
+
await mkdir(resolve(dictionariesDir), { recursive: true });
|
|
10
|
+
let resultDictionariesPaths = {};
|
|
11
|
+
for await (const [key, dictionariesEntry] of Object.entries(
|
|
12
|
+
groupedDictionaries
|
|
13
|
+
)) {
|
|
14
|
+
if (key === "undefined") continue;
|
|
15
|
+
const multiLocaleDictionaries = dictionariesEntry.dictionaries.map(
|
|
16
|
+
(dictionary) => processPerLocaleDictionary(dictionary)
|
|
17
|
+
);
|
|
18
|
+
const mergedDictionary = mergeDictionaries(multiLocaleDictionaries);
|
|
19
|
+
const contentString = formatDictionaryText(mergedDictionary);
|
|
20
|
+
const outputFileName = `${key}.json`;
|
|
21
|
+
const resultFilePath = resolve(dictionariesDir, outputFileName);
|
|
22
|
+
await writeFile(resultFilePath, contentString, "utf8").catch((err) => {
|
|
23
|
+
console.error(`Error creating merged ${outputFileName}:`, err);
|
|
24
|
+
});
|
|
25
|
+
resultDictionariesPaths[key] = {
|
|
26
|
+
dictionaryPath: resultFilePath,
|
|
27
|
+
dictionary: mergedDictionary
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return resultDictionariesPaths;
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
writeMergedDictionaries
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=writeMergedDictionary.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { mergeDictionaries } from '../../../mergeDictionaries';\nimport { processPerLocaleDictionary } from '../../../processPerLocaleDictionary';\nimport { formatDictionaryText } from './formatDictionaryText';\nimport { UnmergedDictionaryOutput } from './writeUnmergedDictionary';\n\nexport type MergedDictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type MergedDictionaryOutput = Record<string, MergedDictionaryResult>;\n\n/**\n * Write the merged dictionaries to the dictionariesDir\n * @param groupedDictionaries - The grouped dictionaries\n * @param configuration - The configuration\n * @returns The merged dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeMergedDictionaries = async (\n groupedDictionaries: UnmergedDictionaryOutput,\n configuration = getConfiguration()\n): Promise<MergedDictionaryOutput> => {\n const { dictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n let resultDictionariesPaths: MergedDictionaryOutput = {};\n\n // Merge dictionaries with the same key and write to dictionariesDir\n for await (const [key, dictionariesEntry] of Object.entries(\n groupedDictionaries\n )) {\n if (key === 'undefined') continue;\n\n const multiLocaleDictionaries = dictionariesEntry.dictionaries.map(\n (dictionary) => processPerLocaleDictionary(dictionary)\n );\n\n const mergedDictionary = mergeDictionaries(multiLocaleDictionaries);\n\n const contentString = formatDictionaryText(mergedDictionary);\n\n const outputFileName = `${key}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Write the merged dictionary\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating merged ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths[key] = {\n dictionaryPath: resultFilePath,\n dictionary: mergedDictionary,\n };\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AAEjC,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,yBAAyB;AAClC,SAAS,kCAAkC;AAC3C,SAAS,4BAA4B;AA0B9B,MAAM,0BAA0B,OACrC,qBACA,gBAAgB,iBAAiB,MACG;AACpC,QAAM,EAAE,gBAAgB,IAAI,cAAc;AAG1C,QAAM,MAAM,QAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,MAAI,0BAAkD,CAAC;AAGvD,mBAAiB,CAAC,KAAK,iBAAiB,KAAK,OAAO;AAAA,IAClD;AAAA,EACF,GAAG;AACD,QAAI,QAAQ,YAAa;AAEzB,UAAM,0BAA0B,kBAAkB,aAAa;AAAA,MAC7D,CAAC,eAAe,2BAA2B,UAAU;AAAA,IACvD;AAEA,UAAM,mBAAmB,kBAAkB,uBAAuB;AAElE,UAAM,gBAAgB,qBAAqB,gBAAgB;AAE3D,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,iBAAiB,QAAQ,iBAAiB,cAAc;AAG9D,UAAM,UAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,yBAAyB,cAAc,KAAK,GAAG;AAAA,IAC/D,CAAC;AAED,4BAAwB,GAAG,IAAI;AAAA,MAC7B,gBAAgB;AAAA,MAChB,YAAY;AAAA,IACd;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getConfiguration } from "@intlayer/config";
|
|
2
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
import { formatDictionaryText } from "./formatDictionaryText.mjs";
|
|
5
|
+
const groupDictionariesByKey = (dictionaries) => {
|
|
6
|
+
return dictionaries.reduce(
|
|
7
|
+
(acc, dictionary) => {
|
|
8
|
+
const key = dictionary.key;
|
|
9
|
+
if (!acc[key]) {
|
|
10
|
+
acc[key] = [];
|
|
11
|
+
}
|
|
12
|
+
acc[key].push(dictionary);
|
|
13
|
+
return acc;
|
|
14
|
+
},
|
|
15
|
+
{}
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
const writeUnmergedDictionaries = async (dictionaries, configuration = getConfiguration()) => {
|
|
19
|
+
const { unmergedDictionariesDir } = configuration.content;
|
|
20
|
+
await mkdir(resolve(unmergedDictionariesDir), { recursive: true });
|
|
21
|
+
const groupedDictionaries = groupDictionariesByKey(dictionaries);
|
|
22
|
+
let resultDictionariesPaths = {};
|
|
23
|
+
for await (const [key, dictionaries2] of Object.entries(groupedDictionaries)) {
|
|
24
|
+
if (key === "undefined") continue;
|
|
25
|
+
const contentString = formatDictionaryText(dictionaries2);
|
|
26
|
+
const outputFileName = `${key}.json`;
|
|
27
|
+
const unmergedFilePath = resolve(unmergedDictionariesDir, outputFileName);
|
|
28
|
+
await writeFile(unmergedFilePath, contentString, "utf8").catch((err) => {
|
|
29
|
+
console.error(`Error creating unmerged ${outputFileName}:`, err);
|
|
30
|
+
});
|
|
31
|
+
resultDictionariesPaths[key] = {
|
|
32
|
+
dictionaryPath: unmergedFilePath,
|
|
33
|
+
dictionaries: dictionaries2
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return resultDictionariesPaths;
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
writeUnmergedDictionaries
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=writeUnmergedDictionary.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { formatDictionaryText } from './formatDictionaryText';\n\nconst groupDictionariesByKey = (\n dictionaries: Dictionary[]\n): Record<string, Dictionary[]> => {\n return dictionaries.reduce(\n (acc, dictionary) => {\n const key = dictionary.key;\n if (!acc[key]) {\n acc[key] = [];\n }\n acc[key].push(dictionary);\n return acc;\n },\n {} as Record<string, Dictionary[]>\n );\n};\n\nexport type UnmergedDictionaryResult = {\n dictionaryPath: string;\n dictionaries: Dictionary[];\n};\n\nexport type UnmergedDictionaryOutput = Record<string, UnmergedDictionaryResult>;\n\n/**\n * Write the unmerged dictionaries to the unmergedDictionariesDir\n * @param dictionaries - The dictionaries to write\n * @param configuration - The configuration\n * @returns The grouped dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * console.log(unmergedDictionaries);\n *\n * // .intlayer/unmerged_dictionaries/home.json\n * // {\n * // [\n * // { key: 'home', content: { ... } },\n * // { key: 'home', content: { ... } },\n * // ],\n * // }\n * ```\n */\nexport const writeUnmergedDictionaries = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n): Promise<UnmergedDictionaryOutput> => {\n const { unmergedDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(unmergedDictionariesDir), { recursive: true });\n\n // Group dictionaries by key and write to unmergedDictionariesDir\n const groupedDictionaries = groupDictionariesByKey(dictionaries);\n\n let resultDictionariesPaths: UnmergedDictionaryOutput = {};\n\n for await (const [key, dictionaries] of Object.entries(groupedDictionaries)) {\n if (key === 'undefined') continue;\n\n const contentString = formatDictionaryText(dictionaries);\n\n const outputFileName = `${key}.json`;\n const unmergedFilePath = resolve(unmergedDictionariesDir, outputFileName);\n\n // Write the grouped dictionaries\n await writeFile(unmergedFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating unmerged ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths[key] = {\n dictionaryPath: unmergedFilePath,\n dictionaries: dictionaries,\n };\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AAEjC,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,4BAA4B;AAErC,MAAM,yBAAyB,CAC7B,iBACiC;AACjC,SAAO,aAAa;AAAA,IAClB,CAAC,KAAK,eAAe;AACnB,YAAM,MAAM,WAAW;AACvB,UAAI,CAAC,IAAI,GAAG,GAAG;AACb,YAAI,GAAG,IAAI,CAAC;AAAA,MACd;AACA,UAAI,GAAG,EAAE,KAAK,UAAU;AACxB,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;AA6BO,MAAM,4BAA4B,OACvC,cACA,gBAAgB,iBAAiB,MACK;AACtC,QAAM,EAAE,wBAAwB,IAAI,cAAc;AAGlD,QAAM,MAAM,QAAQ,uBAAuB,GAAG,EAAE,WAAW,KAAK,CAAC;AAGjE,QAAM,sBAAsB,uBAAuB,YAAY;AAE/D,MAAI,0BAAoD,CAAC;AAEzD,mBAAiB,CAAC,KAAKA,aAAY,KAAK,OAAO,QAAQ,mBAAmB,GAAG;AAC3E,QAAI,QAAQ,YAAa;AAEzB,UAAM,gBAAgB,qBAAqBA,aAAY;AAEvD,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,mBAAmB,QAAQ,yBAAyB,cAAc;AAGxE,UAAM,UAAU,kBAAkB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACtE,cAAQ,MAAM,2BAA2B,cAAc,KAAK,GAAG;AAAA,IACjE,CAAC;AAED,4BAAwB,GAAG,IAAI;AAAA,MAC7B,gBAAgB;AAAA,MAChB,cAAcA;AAAA,IAChB;AAAA,EACF;AAEA,SAAO;AACT;","names":["dictionaries"]}
|
|
@@ -2,50 +2,59 @@ import { getConfiguration } from "@intlayer/config";
|
|
|
2
2
|
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
3
3
|
import { resolve } from "path";
|
|
4
4
|
import { getBuiltDictionariesPath } from "../../getBuiltDictionariesPath.mjs";
|
|
5
|
+
import { getBuiltDynamicDictionariesPath } from "../../getBuiltDynamicDictionariesPath.mjs";
|
|
5
6
|
import { getBuiltUnmergedDictionariesPath } from "../../getBuiltUnmergedDictionariesPath.mjs";
|
|
6
7
|
import { generateDictionaryListContent } from "./generateDictionaryListContent.mjs";
|
|
7
|
-
const
|
|
8
|
+
const filterDictionaries = (paths, keys) => {
|
|
9
|
+
if (!keys) return paths;
|
|
10
|
+
return paths.filter(
|
|
11
|
+
(path) => keys.some((key) => path.endsWith(`${key}.json`))
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
const writeDictionaryFiles = (paths, fileName, format, configuration = getConfiguration()) => {
|
|
15
|
+
const content = generateDictionaryListContent(paths, format, configuration);
|
|
16
|
+
const extension = format === "cjs" ? "cjs" : "mjs";
|
|
17
|
+
const { mainDir } = configuration.content;
|
|
18
|
+
writeFileSync(resolve(mainDir, `${fileName}.${extension}`), content);
|
|
19
|
+
};
|
|
20
|
+
const createDictionaryEntryPoint = (configuration = getConfiguration(), dictionariesKeys, formats = ["cjs", "esm"]) => {
|
|
8
21
|
const { mainDir } = configuration.content;
|
|
9
22
|
if (!existsSync(mainDir)) {
|
|
10
23
|
mkdirSync(mainDir, { recursive: true });
|
|
11
24
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
const dictionariesPath = filterDictionaries(
|
|
26
|
+
getBuiltDictionariesPath(configuration),
|
|
27
|
+
dictionariesKeys
|
|
28
|
+
);
|
|
29
|
+
for (const format of formats) {
|
|
30
|
+
writeDictionaryFiles(
|
|
31
|
+
dictionariesPath,
|
|
32
|
+
"dictionaries",
|
|
33
|
+
format,
|
|
34
|
+
configuration
|
|
16
35
|
);
|
|
17
36
|
}
|
|
18
|
-
const cjsContent = generateDictionaryListContent(
|
|
19
|
-
dictionariesPath,
|
|
20
|
-
"cjs",
|
|
21
|
-
configuration
|
|
22
|
-
);
|
|
23
|
-
writeFileSync(resolve(mainDir, "dictionaries.cjs"), cjsContent);
|
|
24
|
-
const esmContent = generateDictionaryListContent(
|
|
25
|
-
dictionariesPath,
|
|
26
|
-
"esm",
|
|
27
|
-
configuration
|
|
28
|
-
);
|
|
29
|
-
writeFileSync(resolve(mainDir, "dictionaries.mjs"), esmContent);
|
|
30
37
|
const unmergedDictionariesPath = getBuiltUnmergedDictionariesPath(configuration);
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
for (const format of formats) {
|
|
39
|
+
writeDictionaryFiles(
|
|
40
|
+
unmergedDictionariesPath,
|
|
41
|
+
"unmerged_dictionaries",
|
|
42
|
+
format,
|
|
43
|
+
configuration
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
for (const format of formats) {
|
|
47
|
+
const dynamicDictionariesPathCJS = getBuiltDynamicDictionariesPath(
|
|
48
|
+
configuration,
|
|
49
|
+
format
|
|
50
|
+
);
|
|
51
|
+
writeDictionaryFiles(
|
|
52
|
+
dynamicDictionariesPathCJS,
|
|
53
|
+
"dynamic_dictionaries",
|
|
54
|
+
format,
|
|
55
|
+
configuration
|
|
56
|
+
);
|
|
57
|
+
}
|
|
49
58
|
};
|
|
50
59
|
export {
|
|
51
60
|
createDictionaryEntryPoint
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { getBuiltDictionariesPath } from '../../getBuiltDictionariesPath';\nimport { getBuiltUnmergedDictionariesPath } from '../../getBuiltUnmergedDictionariesPath';\nimport { generateDictionaryListContent } from './generateDictionaryListContent';\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryEntryPoint = (\n configuration = getConfiguration(),\n dictionariesKeys?: string[]\n) => {\n const { 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
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { getBuiltDictionariesPath } from '../../getBuiltDictionariesPath';\nimport { getBuiltDynamicDictionariesPath } from '../../getBuiltDynamicDictionariesPath';\nimport { getBuiltUnmergedDictionariesPath } from '../../getBuiltUnmergedDictionariesPath';\nimport { generateDictionaryListContent } from './generateDictionaryListContent';\n\nconst filterDictionaries = (paths: string[], keys?: string[]) => {\n if (!keys) return paths;\n return paths.filter((path) =>\n keys.some((key) => path.endsWith(`${key}.json`))\n );\n};\n\nconst writeDictionaryFiles = (\n paths: string[],\n fileName: string,\n format: 'cjs' | 'esm',\n configuration = getConfiguration()\n) => {\n const content = generateDictionaryListContent(paths, format, configuration);\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n\n const { mainDir } = configuration.content;\n\n writeFileSync(resolve(mainDir, `${fileName}.${extension}`), content);\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryEntryPoint = (\n configuration = getConfiguration(),\n dictionariesKeys?: string[],\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n) => {\n const { 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 = filterDictionaries(\n getBuiltDictionariesPath(configuration),\n dictionariesKeys\n );\n\n for (const format of formats) {\n writeDictionaryFiles(\n dictionariesPath,\n 'dictionaries',\n format,\n configuration\n );\n }\n\n const unmergedDictionariesPath =\n getBuiltUnmergedDictionariesPath(configuration);\n\n for (const format of formats) {\n writeDictionaryFiles(\n unmergedDictionariesPath,\n 'unmerged_dictionaries',\n format,\n configuration\n );\n }\n\n for (const format of formats) {\n const dynamicDictionariesPathCJS = getBuiltDynamicDictionariesPath(\n configuration,\n format\n );\n\n writeDictionaryFiles(\n dynamicDictionariesPathCJS,\n 'dynamic_dictionaries',\n format,\n configuration\n );\n }\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AACjC,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,eAAe;AACxB,SAAS,gCAAgC;AACzC,SAAS,uCAAuC;AAChD,SAAS,wCAAwC;AACjD,SAAS,qCAAqC;AAE9C,MAAM,qBAAqB,CAAC,OAAiB,SAAoB;AAC/D,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,MAAM;AAAA,IAAO,CAAC,SACnB,KAAK,KAAK,CAAC,QAAQ,KAAK,SAAS,GAAG,GAAG,OAAO,CAAC;AAAA,EACjD;AACF;AAEA,MAAM,uBAAuB,CAC3B,OACA,UACA,QACA,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,UAAU,8BAA8B,OAAO,QAAQ,aAAa;AAC1E,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,gBAAc,QAAQ,SAAS,GAAG,QAAQ,IAAI,SAAS,EAAE,GAAG,OAAO;AACrE;AAKO,MAAM,6BAA6B,CACxC,gBAAgB,iBAAiB,GACjC,kBACA,UAA6B,CAAC,OAAO,KAAK,MACvC;AACH,QAAM,EAAE,QAAQ,IAAI,cAAc;AAGlC,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAAmB;AAAA,IACvB,yBAAyB,aAAa;AAAA,IACtC;AAAA,EACF;AAEA,aAAW,UAAU,SAAS;AAC5B;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,2BACJ,iCAAiC,aAAa;AAEhD,aAAW,UAAU,SAAS;AAC5B;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,aAAW,UAAU,SAAS;AAC5B,UAAM,6BAA6B;AAAA,MACjC;AAAA,MACA;AAAA,IACF;AAEA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../../src/chokidar/watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,KAAK,cAAc,EAGpB,MAAM,kBAAkB,CAAC;AAE1B,2FAA2F;AAC3F,OAAO,EAAE,KAAK,eAAe,EAA0B,MAAM,UAAU,CAAC;AAcxE,eAAO,MAAM,sCAAsC,GACjD,UAAU,MAAM,EAChB,gBAAgB,cAAc,
|
|
1
|
+
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../../src/chokidar/watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,KAAK,cAAc,EAGpB,MAAM,kBAAkB,CAAC;AAE1B,2FAA2F;AAC3F,OAAO,EAAE,KAAK,eAAe,EAA0B,MAAM,UAAU,CAAC;AAcxE,eAAO,MAAM,sCAAsC,GACjD,UAAU,MAAM,EAChB,gBAAgB,cAAc,kBAmC/B,CAAC;AAEF,eAAO,MAAM,mCAAmC,GAC9C,UAAU,MAAM,EAChB,gBAAgB,cAAc,kBAkC/B,CAAC;AAEF,eAAO,MAAM,kCAAkC,GAC7C,UAAU,MAAM,EAChB,gBAAgB,cAAc,kBAqC/B,CAAC;AAEF,KAAK,YAAY,GAAG,eAAe,GAAG;IACpC,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,aAAa,CAAC,EAAE,uBAAuB,CAAC;CACzC,CAAC;AAGF,eAAO,MAAM,KAAK,GAAI,UAAU,YAAY,QA+C3C,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAU,UAAU,YAAY,kBAUjE,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function generates a list of dictionaries in the main directory
|
|
3
|
+
*/
|
|
4
|
+
export declare const getBuiltDynamicDictionariesPath: (configuration?: import("@intlayer/config").IntlayerConfig, format?: "cjs" | "esm") => string[];
|
|
5
|
+
//# sourceMappingURL=getBuiltDynamicDictionariesPath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBuiltDynamicDictionariesPath.d.ts","sourceRoot":"","sources":["../../src/getBuiltDynamicDictionariesPath.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,eAAO,MAAM,+BAA+B,GAC1C,yDAAkC,EAClC,SAAQ,KAAK,GAAG,KAAa,aAgB9B,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LocalesValues } from '@intlayer/config/client';
|
|
2
|
+
import { ContentNode, type NodeProps } from '@intlayer/core';
|
|
3
|
+
export declare const getFilteredLocalesContent: (node: ContentNode, locale: LocalesValues | LocalesValues[], nodeProps: NodeProps, fallback?: LocalesValues) => any;
|
|
4
|
+
//# sourceMappingURL=getFilteredLocalesContent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFilteredLocalesContent.d.ts","sourceRoot":"","sources":["../../src/getFilteredLocalesContent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EACL,WAAW,EAGX,KAAK,SAAS,EAEf,MAAM,gBAAgB,CAAC;AA4CxB,eAAO,MAAM,yBAAyB,GACpC,MAAM,WAAW,EACjB,QAAQ,aAAa,GAAG,aAAa,EAAE,EACvC,WAAW,SAAS,EACpB,WAAW,aAAa,QAWzB,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ export { buildAndWatchIntlayer, handleAdditionalContentDeclarationFile, handleCo
|
|
|
3
3
|
export { cleanOutputDir } from './cleanOutputDir';
|
|
4
4
|
export { fetchDistantDictionaries } from './fetchDistantDictionaries';
|
|
5
5
|
export { fetchDistantDictionaryKeys } from './fetchDistantDictionaryKeys';
|
|
6
|
-
export { filterDictionaryLocales } from './filterDictionaryLocales';
|
|
7
6
|
export { getBuiltDictionariesPath } from './getBuiltDictionariesPath';
|
|
8
7
|
export { getBuiltUnmergedDictionariesPath } from './getBuiltUnmergedDictionariesPath';
|
|
8
|
+
export { getFilteredLocalesContent } from './getFilteredLocalesContent';
|
|
9
9
|
export { listDictionaries } from './listDictionariesPath';
|
|
10
10
|
export { listGitFiles, type DiffMode, type ListGitFilesOptions, } from './listGitFiles';
|
|
11
11
|
export { loadDictionaries, loadDistantDictionaries, loadLocalDictionaries, } from './loadDictionaries/index';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EACL,qBAAqB,EACrB,sCAAsC,EACtC,kCAAkC,EAClC,KAAK,GACN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EACL,qBAAqB,EACrB,sCAAsC,EACtC,kCAAkC,EAClC,KAAK,GACN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AACtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EACL,YAAY,EACZ,KAAK,QAAQ,EACb,KAAK,mBAAmB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,mDAAmD,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,mDAAmD,CAAC;AACpF,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,GAC9B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,0DAA0D,CAAC;AACpG,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,KAAK,gBAAgB,GACtB,MAAM,2BAA2B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareIntlayer.d.ts","sourceRoot":"","sources":["../../src/prepareIntlayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,kBAAkB,CAAC;AAY1B,eAAO,MAAM,eAAe,GAC1B,gBAAe,cAAmC,EAClD,+BAA+B,
|
|
1
|
+
{"version":3,"file":"prepareIntlayer.d.ts","sourceRoot":"","sources":["../../src/prepareIntlayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,kBAAkB,CAAC;AAY1B,eAAO,MAAM,eAAe,GAC1B,gBAAe,cAAmC,EAClD,+BAA+B,kBAsChC,CAAC"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { Dictionary } from '@intlayer/core';
|
|
2
|
-
export declare const buildDictionary: (dictionaries: Dictionary[], configuration?: import("@intlayer/config").IntlayerConfig) => Promise<
|
|
2
|
+
export declare const buildDictionary: (dictionaries: Dictionary[], configuration?: import("@intlayer/config").IntlayerConfig) => Promise<{
|
|
3
|
+
unmergedDictionaries: import("./intlayer_dictionary/writeUnmergedDictionary").UnmergedDictionaryOutput;
|
|
4
|
+
mergedDictionaries: import("./intlayer_dictionary/writeMergedDictionary").MergedDictionaryOutput;
|
|
5
|
+
dynamicDictionaries: import("./intlayer_dictionary/writeDynamicDictionary").LocalizedDictionaryOutput;
|
|
6
|
+
}>;
|
|
3
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transpiler/declaration_file_to_dictionary/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIjD,eAAO,MAAM,eAAe,GAC1B,cAAc,UAAU,EAAE,EAC1B,yDAAkC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transpiler/declaration_file_to_dictionary/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIjD,eAAO,MAAM,eAAe,GAC1B,cAAc,UAAU,EAAE,EAC1B,yDAAkC;;;;EAWnC,CAAC"}
|
|
@@ -3,5 +3,9 @@ import type { Dictionary } from '@intlayer/core';
|
|
|
3
3
|
/**
|
|
4
4
|
* This function transpile the bundled code to to make dictionaries as JSON files
|
|
5
5
|
*/
|
|
6
|
-
export declare const buildIntlayerDictionary: (contentDeclarations: (DictionaryAPI | Dictionary)[], configuration?: import("@intlayer/config").IntlayerConfig) => Promise<
|
|
6
|
+
export declare const buildIntlayerDictionary: (contentDeclarations: (DictionaryAPI | Dictionary)[], configuration?: import("@intlayer/config").IntlayerConfig, formats?: ("cjs" | "esm")[]) => Promise<{
|
|
7
|
+
unmergedDictionaries: import("./writeUnmergedDictionary").UnmergedDictionaryOutput;
|
|
8
|
+
mergedDictionaries: import("./writeMergedDictionary").MergedDictionaryOutput;
|
|
9
|
+
dynamicDictionaries: import("./writeDynamicDictionary").LocalizedDictionaryOutput;
|
|
10
|
+
}>;
|
|
7
11
|
//# sourceMappingURL=buildIntlayerDictionary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildIntlayerDictionary.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildIntlayerDictionary.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAKjD;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAClC,qBAAqB,CAAC,aAAa,GAAG,UAAU,CAAC,EAAE,EACnD,yDAAkC,EAClC,UAAS,CAAC,KAAK,GAAG,KAAK,CAAC,EAAmB;;;;EAuB5C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatDictionaryText.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,GAAI,YAAY,MAAM,WAGvB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Locales } from '@intlayer/config';
|
|
2
|
+
import { type Dictionary } from '@intlayer/core';
|
|
3
|
+
import { MergedDictionaryOutput } from './writeMergedDictionary';
|
|
4
|
+
export type DictionaryResult = {
|
|
5
|
+
dictionaryPath: string;
|
|
6
|
+
dictionary: Dictionary;
|
|
7
|
+
};
|
|
8
|
+
export type LocalizedDictionaryResult = Partial<Record<Locales, DictionaryResult>>;
|
|
9
|
+
export type LocalizedDictionaryOutput = Record<string, LocalizedDictionaryResult>;
|
|
10
|
+
/**
|
|
11
|
+
* This function generates the content of the dictionary list file
|
|
12
|
+
*/
|
|
13
|
+
export declare const generateDictionaryEntryPoint: (localedDictionariesPathsRecord: LocalizedDictionaryResult, format?: "cjs" | "esm", configuration?: import("@intlayer/config").IntlayerConfig) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Write the localized dictionaries to the dictionariesDir
|
|
16
|
+
* @param mergedDictionaries - The merged dictionaries
|
|
17
|
+
* @param configuration - The configuration
|
|
18
|
+
* @returns The final dictionaries
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);
|
|
23
|
+
* const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);
|
|
24
|
+
* console.log(finalDictionaries);
|
|
25
|
+
*
|
|
26
|
+
* // .intlayer/dictionaries/home.json
|
|
27
|
+
* // { key: 'home', content: { ... } },
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const writeDynamicDictionary: (mergedDictionaries: MergedDictionaryOutput, configuration?: import("@intlayer/config").IntlayerConfig, formats?: ("cjs" | "esm")[]) => Promise<LocalizedDictionaryOutput>;
|
|
31
|
+
//# sourceMappingURL=writeDynamicDictionary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeDynamicDictionary.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAKjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAC7C,MAAM,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAClC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,MAAM,CAC5C,MAAM,EACN,yBAAyB,CAC1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,4BAA4B,GACvC,gCAAgC,yBAAyB,EACzD,SAAQ,KAAK,GAAG,KAAa,EAC7B,yDAAkC,KACjC,MA6BF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,GACjC,oBAAoB,sBAAsB,EAC1C,yDAAkC,EAClC,UAAS,CAAC,KAAK,GAAG,KAAK,CAAC,EAAmB,KAC1C,OAAO,CAAC,yBAAyB,CA+DnC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Dictionary } from '@intlayer/core';
|
|
2
|
+
import { UnmergedDictionaryOutput } from './writeUnmergedDictionary';
|
|
3
|
+
export type MergedDictionaryResult = {
|
|
4
|
+
dictionaryPath: string;
|
|
5
|
+
dictionary: Dictionary;
|
|
6
|
+
};
|
|
7
|
+
export type MergedDictionaryOutput = Record<string, MergedDictionaryResult>;
|
|
8
|
+
/**
|
|
9
|
+
* Write the merged dictionaries to the dictionariesDir
|
|
10
|
+
* @param groupedDictionaries - The grouped dictionaries
|
|
11
|
+
* @param configuration - The configuration
|
|
12
|
+
* @returns The merged dictionaries
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);
|
|
17
|
+
* const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);
|
|
18
|
+
* console.log(finalDictionaries);
|
|
19
|
+
*
|
|
20
|
+
* // .intlayer/dictionaries/home.json
|
|
21
|
+
* // { key: 'home', content: { ... } },
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const writeMergedDictionaries: (groupedDictionaries: UnmergedDictionaryOutput, configuration?: import("@intlayer/config").IntlayerConfig) => Promise<MergedDictionaryOutput>;
|
|
25
|
+
//# sourceMappingURL=writeMergedDictionary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeMergedDictionary.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeMergedDictionary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAMjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAErE,MAAM,MAAM,sBAAsB,GAAG;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;AAE5E;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,uBAAuB,GAClC,qBAAqB,wBAAwB,EAC7C,yDAAkC,KACjC,OAAO,CAAC,sBAAsB,CAqChC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Dictionary } from '@intlayer/core';
|
|
2
|
+
export type UnmergedDictionaryResult = {
|
|
3
|
+
dictionaryPath: string;
|
|
4
|
+
dictionaries: Dictionary[];
|
|
5
|
+
};
|
|
6
|
+
export type UnmergedDictionaryOutput = Record<string, UnmergedDictionaryResult>;
|
|
7
|
+
/**
|
|
8
|
+
* Write the unmerged dictionaries to the unmergedDictionariesDir
|
|
9
|
+
* @param dictionaries - The dictionaries to write
|
|
10
|
+
* @param configuration - The configuration
|
|
11
|
+
* @returns The grouped dictionaries
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);
|
|
16
|
+
* console.log(unmergedDictionaries);
|
|
17
|
+
*
|
|
18
|
+
* // .intlayer/unmerged_dictionaries/home.json
|
|
19
|
+
* // {
|
|
20
|
+
* // [
|
|
21
|
+
* // { key: 'home', content: { ... } },
|
|
22
|
+
* // { key: 'home', content: { ... } },
|
|
23
|
+
* // ],
|
|
24
|
+
* // }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const writeUnmergedDictionaries: (dictionaries: Dictionary[], configuration?: import("@intlayer/config").IntlayerConfig) => Promise<UnmergedDictionaryOutput>;
|
|
28
|
+
//# sourceMappingURL=writeUnmergedDictionary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeUnmergedDictionary.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeUnmergedDictionary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAqBjD,MAAM,MAAM,wBAAwB,GAAG;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,UAAU,EAAE,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,yBAAyB,GACpC,cAAc,UAAU,EAAE,EAC1B,yDAAkC,KACjC,OAAO,CAAC,wBAAwB,CA+BlC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This function generates a list of dictionaries in the main directory
|
|
3
3
|
*/
|
|
4
|
-
export declare const createDictionaryEntryPoint: (configuration?: import("@intlayer/config").IntlayerConfig, dictionariesKeys?: string[]) => void;
|
|
4
|
+
export declare const createDictionaryEntryPoint: (configuration?: import("@intlayer/config").IntlayerConfig, dictionariesKeys?: string[], formats?: ("cjs" | "esm")[]) => void;
|
|
5
5
|
//# sourceMappingURL=createDictionaryEntryPoint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDictionaryEntryPoint.d.ts","sourceRoot":"","sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createDictionaryEntryPoint.d.ts","sourceRoot":"","sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"names":[],"mappings":"AA6BA;;GAEG;AACH,eAAO,MAAM,0BAA0B,GACrC,yDAAkC,EAClC,mBAAmB,MAAM,EAAE,EAC3B,UAAS,CAAC,KAAK,GAAG,KAAK,CAAC,EAAmB,SAgD5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/chokidar",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.",
|
|
6
6
|
"keywords": [
|
|
@@ -68,12 +68,12 @@
|
|
|
68
68
|
"fast-glob": "^3.3.3",
|
|
69
69
|
"p-limit": "^3.1.0",
|
|
70
70
|
"simple-git": "^3.27.0",
|
|
71
|
-
"@intlayer/
|
|
72
|
-
"@intlayer/
|
|
73
|
-
"
|
|
74
|
-
"@intlayer/unmerged-dictionaries-entry": "5.5.
|
|
75
|
-
"intlayer": "5.5.
|
|
76
|
-
"@intlayer/
|
|
71
|
+
"@intlayer/core": "5.5.5",
|
|
72
|
+
"@intlayer/config": "5.5.5",
|
|
73
|
+
"intlayer": "5.5.5",
|
|
74
|
+
"@intlayer/unmerged-dictionaries-entry": "5.5.5",
|
|
75
|
+
"@intlayer/dictionaries-entry": "5.5.5",
|
|
76
|
+
"@intlayer/api": "5.5.5"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@changesets/cli": "2.28.1",
|
|
@@ -91,18 +91,18 @@
|
|
|
91
91
|
"tsup": "^8.4.0",
|
|
92
92
|
"typescript": "^5.8.2",
|
|
93
93
|
"@utils/eslint-config": "1.0.4",
|
|
94
|
-
"@intlayer/backend": "5.5.3",
|
|
95
94
|
"@utils/ts-config-types": "1.0.4",
|
|
95
|
+
"@utils/ts-config": "1.0.4",
|
|
96
96
|
"@utils/tsup-config": "1.0.4",
|
|
97
|
-
"@
|
|
97
|
+
"@intlayer/backend": "5.5.5"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
100
|
"fast-glob": "^3.3.3",
|
|
101
101
|
"react": ">=16.0.0",
|
|
102
|
-
"@intlayer/
|
|
103
|
-
"@intlayer/config": "5.5.
|
|
104
|
-
"@intlayer/
|
|
105
|
-
"intlayer": "5.5.
|
|
102
|
+
"@intlayer/api": "5.5.5",
|
|
103
|
+
"@intlayer/config": "5.5.5",
|
|
104
|
+
"@intlayer/core": "5.5.5",
|
|
105
|
+
"intlayer": "5.5.5"
|
|
106
106
|
},
|
|
107
107
|
"engines": {
|
|
108
108
|
"node": ">=14.18"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/filterDictionaryLocales.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n deepTransformNode,\n NodeType,\n type Dictionary,\n type Plugins,\n} from '@intlayer/core';\n\nconst filterTranlationsPlugin = (locales: 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 localesArray = Array.isArray(locales) ? locales : [locales];\n const isSingleLocale = localesArray.length === 1;\n\n const filteredTranslationMap = isSingleLocale\n ? translationMap[localesArray[0] as Locales]\n : 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[] | Locales\n) =>\n deepTransformNode(dictionary, {\n plugins: [filterTranlationsPlugin(locales)],\n dictionaryKey: dictionary.key,\n keyPath: [],\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAKO;AAEP,MAAM,0BAA0B,CAAC,aAA2C;AAAA,EAC1E,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,qBAAS;AAAA,EAC1D,WAAW,CAAC,MAAM,OAAOA,uBAAsB;AAC7C,UAAM,iBAAiB,KAAK;AAE5B,UAAM,eAAe,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAC,OAAO;AAChE,UAAM,iBAAiB,aAAa,WAAW;AAE/C,UAAM,yBAAyB,iBAC3B,eAAe,aAAa,CAAC,CAAY,IACzC,OAAO;AAAA,MACL,OAAO,QAAQ,cAAc,EAAE;AAAA,QAAO,CAAC,CAAC,GAAG,MACzC,QAAQ,SAAS,GAAc;AAAA,MACjC;AAAA,IACF;AAEJ,WAAO;AAAA,MACL,GAAG;AAAA,MACH,aAAaA,mBAAkB,wBAAwB;AAAA,QACrD,GAAG;AAAA,QACH,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,qBAAS,QAAQ,KAAK,qBAAS,YAAY;AAAA,QACrD;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,MAAM,0BAA0B,CACrC,YACA,gBAEA,+BAAkB,YAAY;AAAA,EAC5B,SAAS,CAAC,wBAAwB,OAAO,CAAC;AAAA,EAC1C,eAAe,WAAW;AAAA,EAC1B,SAAS,CAAC;AACZ,CAAC;","names":["deepTransformNode"]}
|
package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var writeDictionary_exports = {};
|
|
20
|
-
__export(writeDictionary_exports, {
|
|
21
|
-
writeDictionary: () => writeDictionary,
|
|
22
|
-
writeFinalDictionaries: () => writeFinalDictionaries,
|
|
23
|
-
writeUnmergedDictionaries: () => writeUnmergedDictionaries
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(writeDictionary_exports);
|
|
26
|
-
var import_config = require("@intlayer/config");
|
|
27
|
-
var import_promises = require("fs/promises");
|
|
28
|
-
var import_path = require("path");
|
|
29
|
-
var import_mergeDictionaries = require('../../../mergeDictionaries.cjs');
|
|
30
|
-
var import_processPerLocaleDictionary = require('../../../processPerLocaleDictionary.cjs');
|
|
31
|
-
const groupDictionariesByKey = (dictionaries) => {
|
|
32
|
-
return dictionaries.reduce(
|
|
33
|
-
(acc, dictionary) => {
|
|
34
|
-
const key = dictionary.key;
|
|
35
|
-
if (!acc[key]) {
|
|
36
|
-
acc[key] = [];
|
|
37
|
-
}
|
|
38
|
-
acc[key].push(dictionary);
|
|
39
|
-
return acc;
|
|
40
|
-
},
|
|
41
|
-
{}
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
|
-
const writeUnmergedDictionaries = async (dictionaries, configuration = (0, import_config.getConfiguration)()) => {
|
|
45
|
-
const { unmergedDictionariesDir } = configuration.content;
|
|
46
|
-
await (0, import_promises.mkdir)(unmergedDictionariesDir, { recursive: true });
|
|
47
|
-
const groupedDictionaries = groupDictionariesByKey(dictionaries);
|
|
48
|
-
for (const [key, dictionaries2] of Object.entries(groupedDictionaries)) {
|
|
49
|
-
if (key === "undefined") continue;
|
|
50
|
-
const isDevelopment = process.env.NODE_ENV === "development";
|
|
51
|
-
const contentString = isDevelopment ? JSON.stringify(dictionaries2, null, 2) : JSON.stringify(dictionaries2);
|
|
52
|
-
const outputFileName = `${key}.json`;
|
|
53
|
-
const unmergedFilePath = (0, import_path.resolve)(unmergedDictionariesDir, outputFileName);
|
|
54
|
-
await (0, import_promises.writeFile)(unmergedFilePath, contentString, "utf8").catch((err) => {
|
|
55
|
-
console.error(`Error creating unmerged ${outputFileName}:`, err);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
return groupedDictionaries;
|
|
59
|
-
};
|
|
60
|
-
const writeFinalDictionaries = async (groupedDictionaries, configuration = (0, import_config.getConfiguration)()) => {
|
|
61
|
-
const { dictionariesDir } = configuration.content;
|
|
62
|
-
const resultDictionariesPaths = [];
|
|
63
|
-
for (const [key, dictionaries] of Object.entries(groupedDictionaries)) {
|
|
64
|
-
if (key === "undefined") continue;
|
|
65
|
-
const multiLocaleDictionaries = dictionaries.map(
|
|
66
|
-
(dictionary) => (0, import_processPerLocaleDictionary.processPerLocaleDictionary)(dictionary)
|
|
67
|
-
);
|
|
68
|
-
const mergedDictionary = (0, import_mergeDictionaries.mergeDictionaries)(multiLocaleDictionaries);
|
|
69
|
-
const isDevelopment = process.env.NODE_ENV === "development";
|
|
70
|
-
const contentString = isDevelopment ? JSON.stringify(mergedDictionary, null, 2) : JSON.stringify(mergedDictionary);
|
|
71
|
-
const outputFileName = `${key}.json`;
|
|
72
|
-
const resultFilePath = (0, import_path.resolve)(dictionariesDir, outputFileName);
|
|
73
|
-
await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
|
|
74
|
-
console.error(`Error creating merged ${outputFileName}:`, err);
|
|
75
|
-
});
|
|
76
|
-
resultDictionariesPaths.push(resultFilePath);
|
|
77
|
-
}
|
|
78
|
-
return resultDictionariesPaths;
|
|
79
|
-
};
|
|
80
|
-
const writeDictionary = async (dictionaries, configuration = (0, import_config.getConfiguration)()) => {
|
|
81
|
-
const unmergedDictionaries = await writeUnmergedDictionaries(
|
|
82
|
-
dictionaries,
|
|
83
|
-
configuration
|
|
84
|
-
);
|
|
85
|
-
const finalDictionaries = await writeFinalDictionaries(
|
|
86
|
-
unmergedDictionaries,
|
|
87
|
-
configuration
|
|
88
|
-
);
|
|
89
|
-
return finalDictionaries;
|
|
90
|
-
};
|
|
91
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
-
0 && (module.exports = {
|
|
93
|
-
writeDictionary,
|
|
94
|
-
writeFinalDictionaries,
|
|
95
|
-
writeUnmergedDictionaries
|
|
96
|
-
});
|
|
97
|
-
//# sourceMappingURL=writeDictionary.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { mergeDictionaries } from '../../../mergeDictionaries';\nimport { processPerLocaleDictionary } from '../../../processPerLocaleDictionary';\n\nconst groupDictionariesByKey = (\n dictionaries: Dictionary[]\n): Record<string, Dictionary[]> => {\n return dictionaries.reduce(\n (acc, dictionary) => {\n const key = dictionary.key;\n if (!acc[key]) {\n acc[key] = [];\n }\n acc[key].push(dictionary);\n return acc;\n },\n {} as Record<string, Dictionary[]>\n );\n};\n\n/**\n * Write the unmerged dictionaries to the unmergedDictionariesDir\n * @param dictionaries - The dictionaries to write\n * @param configuration - The configuration\n * @returns The grouped dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * console.log(unmergedDictionaries);\n *\n * // .intlayer/unmerged_dictionaries/home.json\n * // {\n * // [\n * // { key: 'home', content: { ... } },\n * // { key: 'home', content: { ... } },\n * // ],\n * // }\n * ```\n */\nexport const writeUnmergedDictionaries = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n): Promise<Record<string, Dictionary[]>> => {\n const { unmergedDictionariesDir } = configuration.content;\n\n // Create the merged dictionaries directory\n await mkdir(unmergedDictionariesDir, { recursive: true });\n\n // Group dictionaries by key and write to unmergedDictionariesDir\n const groupedDictionaries = groupDictionariesByKey(dictionaries);\n\n for (const [key, dictionaries] of Object.entries(groupedDictionaries)) {\n if (key === 'undefined') continue;\n\n const isDevelopment = process.env.NODE_ENV === 'development';\n const contentString = isDevelopment\n ? JSON.stringify(dictionaries, null, 2)\n : JSON.stringify(dictionaries);\n\n const outputFileName = `${key}.json`;\n const unmergedFilePath = resolve(unmergedDictionariesDir, outputFileName);\n\n // Write the grouped dictionaries\n await writeFile(unmergedFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating unmerged ${outputFileName}:`, err);\n });\n }\n\n return groupedDictionaries;\n};\n\n/**\n * Write the final dictionaries to the dictionariesDir\n * @param groupedDictionaries - The grouped dictionaries\n * @param configuration - The configuration\n * @returns The final dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeFinalDictionaries = async (\n groupedDictionaries: Record<string, Dictionary[]>,\n configuration = getConfiguration()\n) => {\n const { dictionariesDir } = configuration.content;\n const resultDictionariesPaths: string[] = [];\n\n // Merge dictionaries with the same key and write to dictionariesDir\n for (const [key, dictionaries] of Object.entries(groupedDictionaries)) {\n if (key === 'undefined') continue;\n\n const multiLocaleDictionaries = dictionaries.map((dictionary) =>\n processPerLocaleDictionary(dictionary)\n );\n const mergedDictionary = mergeDictionaries(multiLocaleDictionaries);\n\n const isDevelopment = process.env.NODE_ENV === 'development';\n const contentString = isDevelopment\n ? JSON.stringify(mergedDictionary, null, 2)\n : JSON.stringify(mergedDictionary);\n\n const outputFileName = `${key}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Write the merged dictionary\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating merged ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n\n return resultDictionariesPaths;\n};\n\nexport const writeDictionary = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n) => {\n const unmergedDictionaries = await writeUnmergedDictionaries(\n dictionaries,\n configuration\n );\n\n const finalDictionaries = await writeFinalDictionaries(\n unmergedDictionaries,\n configuration\n );\n\n return finalDictionaries;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,sBAAiC;AACjC,kBAAwB;AACxB,+BAAkC;AAClC,wCAA2C;AAE3C,MAAM,yBAAyB,CAC7B,iBACiC;AACjC,SAAO,aAAa;AAAA,IAClB,CAAC,KAAK,eAAe;AACnB,YAAM,MAAM,WAAW;AACvB,UAAI,CAAC,IAAI,GAAG,GAAG;AACb,YAAI,GAAG,IAAI,CAAC;AAAA,MACd;AACA,UAAI,GAAG,EAAE,KAAK,UAAU;AACxB,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;AAsBO,MAAM,4BAA4B,OACvC,cACA,oBAAgB,gCAAiB,MACS;AAC1C,QAAM,EAAE,wBAAwB,IAAI,cAAc;AAGlD,YAAM,uBAAM,yBAAyB,EAAE,WAAW,KAAK,CAAC;AAGxD,QAAM,sBAAsB,uBAAuB,YAAY;AAE/D,aAAW,CAAC,KAAKA,aAAY,KAAK,OAAO,QAAQ,mBAAmB,GAAG;AACrE,QAAI,QAAQ,YAAa;AAEzB,UAAM,gBAAgB,QAAQ,IAAI,aAAa;AAC/C,UAAM,gBAAgB,gBAClB,KAAK,UAAUA,eAAc,MAAM,CAAC,IACpC,KAAK,UAAUA,aAAY;AAE/B,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,uBAAmB,qBAAQ,yBAAyB,cAAc;AAGxE,cAAM,2BAAU,kBAAkB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACtE,cAAQ,MAAM,2BAA2B,cAAc,KAAK,GAAG;AAAA,IACjE,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAkBO,MAAM,yBAAyB,OACpC,qBACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,gBAAgB,IAAI,cAAc;AAC1C,QAAM,0BAAoC,CAAC;AAG3C,aAAW,CAAC,KAAK,YAAY,KAAK,OAAO,QAAQ,mBAAmB,GAAG;AACrE,QAAI,QAAQ,YAAa;AAEzB,UAAM,0BAA0B,aAAa;AAAA,MAAI,CAAC,mBAChD,8DAA2B,UAAU;AAAA,IACvC;AACA,UAAM,uBAAmB,4CAAkB,uBAAuB;AAElE,UAAM,gBAAgB,QAAQ,IAAI,aAAa;AAC/C,UAAM,gBAAgB,gBAClB,KAAK,UAAU,kBAAkB,MAAM,CAAC,IACxC,KAAK,UAAU,gBAAgB;AAEnC,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,qBAAiB,qBAAQ,iBAAiB,cAAc;AAG9D,cAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,yBAAyB,cAAc,KAAK,GAAG;AAAA,IAC/D,CAAC;AAED,4BAAwB,KAAK,cAAc;AAAA,EAC7C;AAEA,SAAO;AACT;AAEO,MAAM,kBAAkB,OAC7B,cACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,uBAAuB,MAAM;AAAA,IACjC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,oBAAoB,MAAM;AAAA,IAC9B;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;","names":["dictionaries"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/filterDictionaryLocales.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n deepTransformNode,\n NodeType,\n type Dictionary,\n type Plugins,\n} from '@intlayer/core';\n\nconst filterTranlationsPlugin = (locales: 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 localesArray = Array.isArray(locales) ? locales : [locales];\n const isSingleLocale = localesArray.length === 1;\n\n const filteredTranslationMap = isSingleLocale\n ? translationMap[localesArray[0] as Locales]\n : 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[] | Locales\n) =>\n deepTransformNode(dictionary, {\n plugins: [filterTranlationsPlugin(locales)],\n dictionaryKey: dictionary.key,\n keyPath: [],\n });\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,MAAM,0BAA0B,CAAC,aAA2C;AAAA,EAC1E,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,eAAe,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAC,OAAO;AAChE,UAAM,iBAAiB,aAAa,WAAW;AAE/C,UAAM,yBAAyB,iBAC3B,eAAe,aAAa,CAAC,CAAY,IACzC,OAAO;AAAA,MACL,OAAO,QAAQ,cAAc,EAAE;AAAA,QAAO,CAAC,CAAC,GAAG,MACzC,QAAQ,SAAS,GAAc;AAAA,MACjC;AAAA,IACF;AAEJ,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,YAEA,kBAAkB,YAAY;AAAA,EAC5B,SAAS,CAAC,wBAAwB,OAAO,CAAC;AAAA,EAC1C,eAAe,WAAW;AAAA,EAC1B,SAAS,CAAC;AACZ,CAAC;","names":["deepTransformNode"]}
|