@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,65 @@
|
|
|
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 writeUnmergedDictionary_exports = {};
|
|
20
|
+
__export(writeUnmergedDictionary_exports, {
|
|
21
|
+
writeUnmergedDictionaries: () => writeUnmergedDictionaries
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(writeUnmergedDictionary_exports);
|
|
24
|
+
var import_config = require("@intlayer/config");
|
|
25
|
+
var import_promises = require("fs/promises");
|
|
26
|
+
var import_path = require("path");
|
|
27
|
+
var import_formatDictionaryText = require('./formatDictionaryText.cjs');
|
|
28
|
+
const groupDictionariesByKey = (dictionaries) => {
|
|
29
|
+
return dictionaries.reduce(
|
|
30
|
+
(acc, dictionary) => {
|
|
31
|
+
const key = dictionary.key;
|
|
32
|
+
if (!acc[key]) {
|
|
33
|
+
acc[key] = [];
|
|
34
|
+
}
|
|
35
|
+
acc[key].push(dictionary);
|
|
36
|
+
return acc;
|
|
37
|
+
},
|
|
38
|
+
{}
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
const writeUnmergedDictionaries = async (dictionaries, configuration = (0, import_config.getConfiguration)()) => {
|
|
42
|
+
const { unmergedDictionariesDir } = configuration.content;
|
|
43
|
+
await (0, import_promises.mkdir)((0, import_path.resolve)(unmergedDictionariesDir), { recursive: true });
|
|
44
|
+
const groupedDictionaries = groupDictionariesByKey(dictionaries);
|
|
45
|
+
let resultDictionariesPaths = {};
|
|
46
|
+
for await (const [key, dictionaries2] of Object.entries(groupedDictionaries)) {
|
|
47
|
+
if (key === "undefined") continue;
|
|
48
|
+
const contentString = (0, import_formatDictionaryText.formatDictionaryText)(dictionaries2);
|
|
49
|
+
const outputFileName = `${key}.json`;
|
|
50
|
+
const unmergedFilePath = (0, import_path.resolve)(unmergedDictionariesDir, outputFileName);
|
|
51
|
+
await (0, import_promises.writeFile)(unmergedFilePath, contentString, "utf8").catch((err) => {
|
|
52
|
+
console.error(`Error creating unmerged ${outputFileName}:`, err);
|
|
53
|
+
});
|
|
54
|
+
resultDictionariesPaths[key] = {
|
|
55
|
+
dictionaryPath: unmergedFilePath,
|
|
56
|
+
dictionaries: dictionaries2
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return resultDictionariesPaths;
|
|
60
|
+
};
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
writeUnmergedDictionaries
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=writeUnmergedDictionary.cjs.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;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,sBAAiC;AACjC,kBAAwB;AACxB,kCAAqC;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,oBAAgB,gCAAiB,MACK;AACtC,QAAM,EAAE,wBAAwB,IAAI,cAAc;AAGlD,YAAM,2BAAM,qBAAQ,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,oBAAgB,kDAAqBA,aAAY;AAEvD,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;AAED,4BAAwB,GAAG,IAAI;AAAA,MAC7B,gBAAgB;AAAA,MAChB,cAAcA;AAAA,IAChB;AAAA,EACF;AAEA,SAAO;AACT;","names":["dictionaries"]}
|
|
@@ -25,50 +25,59 @@ var import_config = require("@intlayer/config");
|
|
|
25
25
|
var import_fs = require("fs");
|
|
26
26
|
var import_path = require("path");
|
|
27
27
|
var import_getBuiltDictionariesPath = require('../../getBuiltDictionariesPath.cjs');
|
|
28
|
+
var import_getBuiltDynamicDictionariesPath = require('../../getBuiltDynamicDictionariesPath.cjs');
|
|
28
29
|
var import_getBuiltUnmergedDictionariesPath = require('../../getBuiltUnmergedDictionariesPath.cjs');
|
|
29
30
|
var import_generateDictionaryListContent = require('./generateDictionaryListContent.cjs');
|
|
30
|
-
const
|
|
31
|
+
const filterDictionaries = (paths, keys) => {
|
|
32
|
+
if (!keys) return paths;
|
|
33
|
+
return paths.filter(
|
|
34
|
+
(path) => keys.some((key) => path.endsWith(`${key}.json`))
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
const writeDictionaryFiles = (paths, fileName, format, configuration = (0, import_config.getConfiguration)()) => {
|
|
38
|
+
const content = (0, import_generateDictionaryListContent.generateDictionaryListContent)(paths, format, configuration);
|
|
39
|
+
const extension = format === "cjs" ? "cjs" : "mjs";
|
|
40
|
+
const { mainDir } = configuration.content;
|
|
41
|
+
(0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, `${fileName}.${extension}`), content);
|
|
42
|
+
};
|
|
43
|
+
const createDictionaryEntryPoint = (configuration = (0, import_config.getConfiguration)(), dictionariesKeys, formats = ["cjs", "esm"]) => {
|
|
31
44
|
const { mainDir } = configuration.content;
|
|
32
45
|
if (!(0, import_fs.existsSync)(mainDir)) {
|
|
33
46
|
(0, import_fs.mkdirSync)(mainDir, { recursive: true });
|
|
34
47
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
48
|
+
const dictionariesPath = filterDictionaries(
|
|
49
|
+
(0, import_getBuiltDictionariesPath.getBuiltDictionariesPath)(configuration),
|
|
50
|
+
dictionariesKeys
|
|
51
|
+
);
|
|
52
|
+
for (const format of formats) {
|
|
53
|
+
writeDictionaryFiles(
|
|
54
|
+
dictionariesPath,
|
|
55
|
+
"dictionaries",
|
|
56
|
+
format,
|
|
57
|
+
configuration
|
|
39
58
|
);
|
|
40
59
|
}
|
|
41
|
-
const cjsContent = (0, import_generateDictionaryListContent.generateDictionaryListContent)(
|
|
42
|
-
dictionariesPath,
|
|
43
|
-
"cjs",
|
|
44
|
-
configuration
|
|
45
|
-
);
|
|
46
|
-
(0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, "dictionaries.cjs"), cjsContent);
|
|
47
|
-
const esmContent = (0, import_generateDictionaryListContent.generateDictionaryListContent)(
|
|
48
|
-
dictionariesPath,
|
|
49
|
-
"esm",
|
|
50
|
-
configuration
|
|
51
|
-
);
|
|
52
|
-
(0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, "dictionaries.mjs"), esmContent);
|
|
53
60
|
const unmergedDictionariesPath = (0, import_getBuiltUnmergedDictionariesPath.getBuiltUnmergedDictionariesPath)(configuration);
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
for (const format of formats) {
|
|
62
|
+
writeDictionaryFiles(
|
|
63
|
+
unmergedDictionariesPath,
|
|
64
|
+
"unmerged_dictionaries",
|
|
65
|
+
format,
|
|
66
|
+
configuration
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
for (const format of formats) {
|
|
70
|
+
const dynamicDictionariesPathCJS = (0, import_getBuiltDynamicDictionariesPath.getBuiltDynamicDictionariesPath)(
|
|
71
|
+
configuration,
|
|
72
|
+
format
|
|
73
|
+
);
|
|
74
|
+
writeDictionaryFiles(
|
|
75
|
+
dynamicDictionariesPathCJS,
|
|
76
|
+
"dynamic_dictionaries",
|
|
77
|
+
format,
|
|
78
|
+
configuration
|
|
79
|
+
);
|
|
80
|
+
}
|
|
72
81
|
};
|
|
73
82
|
// Annotate the CommonJS export names for ESM import in node:
|
|
74
83
|
0 && (module.exports = {
|
|
@@ -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":";;;;;;;;;;;;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AA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -26,7 +26,10 @@ const handleAdditionalContentDeclarationFile = async (filePath, configuration) =
|
|
|
26
26
|
}
|
|
27
27
|
);
|
|
28
28
|
const localeDictionaries = await loadLocalDictionaries(filePath);
|
|
29
|
-
const
|
|
29
|
+
const dictionariesOutput = await buildDictionary(localeDictionaries);
|
|
30
|
+
const dictionariesPaths = Object.values(
|
|
31
|
+
dictionariesOutput?.mergedDictionaries ?? {}
|
|
32
|
+
).map((dictionary) => dictionary.dictionaryPath);
|
|
30
33
|
createTypes(dictionariesPaths);
|
|
31
34
|
createDictionaryEntryPoint();
|
|
32
35
|
appLogger("Dictionaries built", {
|
|
@@ -46,7 +49,10 @@ const handleUnlikedContentDeclarationFile = async (filePath, configuration) => {
|
|
|
46
49
|
});
|
|
47
50
|
const files = listDictionaries(configuration);
|
|
48
51
|
const localeDictionaries = await loadLocalDictionaries(files);
|
|
49
|
-
const
|
|
52
|
+
const dictionariesOutput = await buildDictionary(localeDictionaries);
|
|
53
|
+
const dictionariesPaths = Object.values(
|
|
54
|
+
dictionariesOutput?.mergedDictionaries ?? {}
|
|
55
|
+
).map((dictionary) => dictionary.dictionaryPath);
|
|
50
56
|
createTypes(dictionariesPaths);
|
|
51
57
|
createDictionaryEntryPoint();
|
|
52
58
|
appLogger("Dictionaries rebuilt", {
|
|
@@ -65,7 +71,10 @@ const handleContentDeclarationFileChange = async (filePath, configuration) => {
|
|
|
65
71
|
isVerbose: true
|
|
66
72
|
});
|
|
67
73
|
const localeDictionaries = await loadLocalDictionaries(filePath);
|
|
68
|
-
const
|
|
74
|
+
const dictionariesOutput = await buildDictionary(localeDictionaries);
|
|
75
|
+
const updatedDictionariesPaths = Object.values(
|
|
76
|
+
dictionariesOutput?.mergedDictionaries ?? {}
|
|
77
|
+
).map((dictionary) => dictionary.dictionaryPath);
|
|
69
78
|
const allDictionariesPaths = getBuiltDictionariesPath();
|
|
70
79
|
createTypes(updatedDictionariesPaths);
|
|
71
80
|
appLogger("TypeScript types built", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import {\n GetConfigurationOptions,\n type IntlayerConfig,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { basename, relative } from 'path';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { getBuiltDictionariesPath } from '../getBuiltDictionariesPath';\nimport { listDictionaries } from '../listDictionariesPath';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { prepareIntlayer } from '../prepareIntlayer';\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';\n\nconst recentlyAddedFiles = new Set<string>();\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const config = configuration ?? getConfiguration();\n const appLogger = getAppLogger(config);\n const { content } = config;\n\n // Process the file with the functionToRun\n appLogger(\n `Additional file detected: ${relative(content.baseDir, filePath)}`,\n {\n isVerbose: true,\n }\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import {\n GetConfigurationOptions,\n type IntlayerConfig,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { basename, relative } from 'path';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { getBuiltDictionariesPath } from '../getBuiltDictionariesPath';\nimport { listDictionaries } from '../listDictionariesPath';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { prepareIntlayer } from '../prepareIntlayer';\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';\n\nconst recentlyAddedFiles = new Set<string>();\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const config = configuration ?? getConfiguration();\n const appLogger = getAppLogger(config);\n const { content } = config;\n\n // Process the file with the functionToRun\n appLogger(\n `Additional file detected: ${relative(content.baseDir, filePath)}`,\n {\n isVerbose: true,\n }\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint();\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleUnlikedContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const config = configuration ?? getConfiguration();\n const appLogger = getAppLogger(config);\n const { content } = config;\n\n // Process the file with the functionToRun\n appLogger(`Unlinked detected: ${relative(content.baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const files: string[] = listDictionaries(configuration);\n\n const localeDictionaries = await loadLocalDictionaries(files);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint();\n\n appLogger('Dictionaries rebuilt', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const config = configuration ?? getConfiguration();\n const appLogger = getAppLogger(config);\n const { content } = config;\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${relative(content.baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries);\n const updatedDictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n const allDictionariesPaths: string[] = getBuiltDictionariesPath();\n\n createTypes(updatedDictionariesPaths);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some(\n (updatedDictionaryPath) =>\n !allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n createDictionaryEntryPoint();\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n }\n};\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n configOptions?: GetConfigurationOptions;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration = options?.configuration ?? getConfiguration();\n const appLogger = getAppLogger(configuration);\n\n const { watch: isWatchMode, watchedFilesPatternWithPath } =\n configuration.content;\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('add', async (filePath) => {\n const fileName = basename(filePath);\n recentlyAddedFiles.add(fileName);\n\n await handleAdditionalContentDeclarationFile(filePath, configuration);\n\n setTimeout(() => recentlyAddedFiles.delete(fileName), 1000); // Allow time for unlink to trigger if it's a move\n })\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('unlink', async (filePath) => {\n setTimeout(async () => {\n const fileName = basename(filePath);\n\n if (recentlyAddedFiles.has(fileName)) {\n // The file was moved, so ignore unlink\n return;\n }\n\n await handleUnlikedContentDeclarationFile(filePath, configuration);\n }, 300); // Allow time for unlink to trigger if it's a move\n })\n .on('error', async (error) => {\n appLogger('Watcher error: ' + error, {\n level: 'error',\n });\n\n appLogger('Restarting watcher');\n\n await prepareIntlayer(configuration);\n });\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n\n await prepareIntlayer(configuration);\n\n if (configuration.content.watch || options.persistent) {\n // Start watching (assuming watch is also async)\n watch({ ...options, configuration });\n }\n};\n"],"mappings":"AAAA;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAU,gBAAgB;AAEnC,SAA+B,SAAS,qBAAqB;AAC7D,SAAS,gCAAgC;AACzC,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,MAAM,qBAAqB,oBAAI,IAAY;AAEpC,MAAM,yCAAyC,OACpD,UACA,kBACG;AACH,QAAM,SAAS,iBAAiB,iBAAiB;AACjD,QAAM,YAAY,aAAa,MAAM;AACrC,QAAM,EAAE,QAAQ,IAAI;AAGpB;AAAA,IACE,6BAA6B,SAAS,QAAQ,SAAS,QAAQ,CAAC;AAAA,IAChE;AAAA,MACE,WAAW;AAAA,IACb;AAAA,EACF;AAEA,QAAM,qBAAqB,MAAM,sBAAsB,QAAQ;AAE/D,QAAM,qBAAqB,MAAM,gBAAgB,kBAAkB;AAEnE,QAAM,oBAAoB,OAAO;AAAA,IAC/B,oBAAoB,sBAAsB,CAAC;AAAA,EAC7C,EAAE,IAAI,CAAC,eAAe,WAAW,cAAc;AAE/C,cAAY,iBAAiB;AAE7B,6BAA2B;AAE3B,YAAU,sBAAsB;AAAA,IAC9B,WAAW;AAAA,EACb,CAAC;AAED,2B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YAAY;AAErD,UAAM,EAAE,GAAG,SAAS,cAAc,CAAC;AAAA,EACrC;AACF;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getConfiguration } from "@intlayer/config";
|
|
2
|
+
import fg from "fast-glob";
|
|
3
|
+
import { existsSync, mkdirSync } from "fs";
|
|
4
|
+
const getBuiltDynamicDictionariesPath = (configuration = getConfiguration(), format = "esm") => {
|
|
5
|
+
const { dynamicDictionariesDir, mainDir } = configuration.content;
|
|
6
|
+
if (!existsSync(mainDir)) {
|
|
7
|
+
mkdirSync(mainDir, { recursive: true });
|
|
8
|
+
}
|
|
9
|
+
const extension = format === "cjs" ? "cjs" : "mjs";
|
|
10
|
+
const dictionariesPath = fg.sync(
|
|
11
|
+
`${dynamicDictionariesDir}/**/*.${extension}`
|
|
12
|
+
);
|
|
13
|
+
return dictionariesPath;
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
getBuiltDynamicDictionariesPath
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=getBuiltDynamicDictionariesPath.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getBuiltDynamicDictionariesPath.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 getBuiltDynamicDictionariesPath = (\n configuration = getConfiguration(),\n format: 'cjs' | 'esm' = 'esm'\n) => {\n const { dynamicDictionariesDir, 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 extension = format === 'cjs' ? 'cjs' : 'mjs';\n\n const dictionariesPath: string[] = fg.sync(\n `${dynamicDictionariesDir}/**/*.${extension}`\n );\n\n return dictionariesPath;\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AACjC,OAAO,QAAQ;AACf,SAAS,YAAY,iBAAiB;AAK/B,MAAM,kCAAkC,CAC7C,gBAAgB,iBAAiB,GACjC,SAAwB,UACrB;AACH,QAAM,EAAE,wBAAwB,QAAQ,IAAI,cAAc;AAG1D,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,YAAY,WAAW,QAAQ,QAAQ;AAE7C,QAAM,mBAA6B,GAAG;AAAA,IACpC,GAAG,sBAAsB,SAAS,SAAS;AAAA,EAC7C;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -2,14 +2,21 @@ import {
|
|
|
2
2
|
deepTransformNode,
|
|
3
3
|
NodeType
|
|
4
4
|
} from "@intlayer/core";
|
|
5
|
-
const filterTranlationsPlugin = (locales) => ({
|
|
5
|
+
const filterTranlationsPlugin = (locales, fallback = void 0) => ({
|
|
6
6
|
id: "filter-translations-plugin",
|
|
7
7
|
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Translation,
|
|
8
8
|
transform: (node, props, deepTransformNode2) => {
|
|
9
9
|
const translationMap = node.translation;
|
|
10
10
|
const localesArray = Array.isArray(locales) ? locales : [locales];
|
|
11
11
|
const isSingleLocale = localesArray.length === 1;
|
|
12
|
-
|
|
12
|
+
if (isSingleLocale) {
|
|
13
|
+
let content = translationMap[localesArray[0]];
|
|
14
|
+
if (typeof content === "undefined" && fallback) {
|
|
15
|
+
content = translationMap[fallback];
|
|
16
|
+
}
|
|
17
|
+
return deepTransformNode2(content, props);
|
|
18
|
+
}
|
|
19
|
+
const filteredTranslationMap = Object.fromEntries(
|
|
13
20
|
Object.entries(translationMap).filter(
|
|
14
21
|
([key]) => locales.includes(key)
|
|
15
22
|
)
|
|
@@ -26,12 +33,17 @@ const filterTranlationsPlugin = (locales) => ({
|
|
|
26
33
|
};
|
|
27
34
|
}
|
|
28
35
|
});
|
|
29
|
-
const
|
|
30
|
-
plugins
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
const getFilteredLocalesContent = (node, locale, nodeProps, fallback) => {
|
|
37
|
+
const plugins = [
|
|
38
|
+
filterTranlationsPlugin(locale, fallback),
|
|
39
|
+
...nodeProps.plugins ?? []
|
|
40
|
+
];
|
|
41
|
+
return deepTransformNode(node, {
|
|
42
|
+
...nodeProps,
|
|
43
|
+
plugins
|
|
44
|
+
});
|
|
45
|
+
};
|
|
34
46
|
export {
|
|
35
|
-
|
|
47
|
+
getFilteredLocalesContent
|
|
36
48
|
};
|
|
37
|
-
//# sourceMappingURL=
|
|
49
|
+
//# sourceMappingURL=getFilteredLocalesContent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getFilteredLocalesContent.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\nimport {\n ContentNode,\n deepTransformNode,\n NodeType,\n type NodeProps,\n type Plugins,\n} from '@intlayer/core';\n\nconst filterTranlationsPlugin = (\n locales: LocalesValues[] | LocalesValues,\n fallback: LocalesValues | undefined = undefined // fallback mean that if field is not translated, it will use the default locale,\n): 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 if (isSingleLocale) {\n let content = translationMap[localesArray[0] as Locales];\n\n if (typeof content === 'undefined' && fallback) {\n content = translationMap[fallback as Locales];\n }\n\n return deepTransformNode(content, props);\n }\n\n const filteredTranslationMap = Object.fromEntries(\n Object.entries(translationMap).filter(([key]) =>\n locales.includes(key as Locales)\n )\n );\n\n return {\n ...node,\n translation: deepTransformNode(filteredTranslationMap, {\n ...props,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key: NodeType.Translation },\n ],\n }),\n };\n },\n});\n\nexport const getFilteredLocalesContent = (\n node: ContentNode,\n locale: LocalesValues | LocalesValues[],\n nodeProps: NodeProps,\n fallback?: LocalesValues // fallback mean that if field is not translated, it will use the default locale,\n) => {\n const plugins: Plugins[] = [\n filterTranlationsPlugin(locale, fallback),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n });\n};\n"],"mappings":"AACA;AAAA,EAEE;AAAA,EACA;AAAA,OAGK;AAEP,MAAM,0BAA0B,CAC9B,SACA,WAAsC,YACzB;AAAA,EACb,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,QAAI,gBAAgB;AAClB,UAAI,UAAU,eAAe,aAAa,CAAC,CAAY;AAEvD,UAAI,OAAO,YAAY,eAAe,UAAU;AAC9C,kBAAU,eAAe,QAAmB;AAAA,MAC9C;AAEA,aAAOA,mBAAkB,SAAS,KAAK;AAAA,IACzC;AAEA,UAAM,yBAAyB,OAAO;AAAA,MACpC,OAAO,QAAQ,cAAc,EAAE;AAAA,QAAO,CAAC,CAAC,GAAG,MACzC,QAAQ,SAAS,GAAc;AAAA,MACjC;AAAA,IACF;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH,aAAaA,mBAAkB,wBAAwB;AAAA,QACrD,GAAG;AAAA,QACH,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,SAAS,QAAQ,KAAK,SAAS,YAAY;AAAA,QACrD;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,MAAM,4BAA4B,CACvC,MACA,QACA,WACA,aACG;AACH,QAAM,UAAqB;AAAA,IACzB,wBAAwB,QAAQ,QAAQ;AAAA,IACxC,GAAI,UAAU,WAAW,CAAC;AAAA,EAC5B;AAEA,SAAO,kBAAkB,MAAM;AAAA,IAC7B,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":["deepTransformNode"]}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
import { cleanOutputDir } from "./cleanOutputDir.mjs";
|
|
9
9
|
import { fetchDistantDictionaries } from "./fetchDistantDictionaries.mjs";
|
|
10
10
|
import { fetchDistantDictionaryKeys } from "./fetchDistantDictionaryKeys.mjs";
|
|
11
|
-
import { filterDictionaryLocales } from "./filterDictionaryLocales.mjs";
|
|
12
11
|
import { getBuiltDictionariesPath } from "./getBuiltDictionariesPath.mjs";
|
|
13
12
|
import { getBuiltUnmergedDictionariesPath } from "./getBuiltUnmergedDictionariesPath.mjs";
|
|
13
|
+
import { getFilteredLocalesContent } from "./getFilteredLocalesContent.mjs";
|
|
14
14
|
import { listDictionaries } from "./listDictionariesPath.mjs";
|
|
15
15
|
import {
|
|
16
16
|
listGitFiles
|
|
@@ -44,11 +44,11 @@ export {
|
|
|
44
44
|
createModuleAugmentation,
|
|
45
45
|
fetchDistantDictionaries,
|
|
46
46
|
fetchDistantDictionaryKeys,
|
|
47
|
-
filterDictionaryLocales,
|
|
48
47
|
generateDictionaryListContent,
|
|
49
48
|
getBuiltDictionariesPath,
|
|
50
49
|
getBuiltUnmergedDictionariesPath,
|
|
51
50
|
getFileHash,
|
|
51
|
+
getFilteredLocalesContent,
|
|
52
52
|
handleAdditionalContentDeclarationFile,
|
|
53
53
|
handleContentDeclarationFileChange,
|
|
54
54
|
listDictionaries,
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 { cleanOutputDir } from './cleanOutputDir';\nexport { fetchDistantDictionaries } from './fetchDistantDictionaries';\nexport { fetchDistantDictionaryKeys } from './fetchDistantDictionaryKeys';\nexport {
|
|
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 { cleanOutputDir } from './cleanOutputDir';\nexport { fetchDistantDictionaries } from './fetchDistantDictionaries';\nexport { fetchDistantDictionaryKeys } from './fetchDistantDictionaryKeys';\nexport { getBuiltDictionariesPath } from './getBuiltDictionariesPath';\nexport { getBuiltUnmergedDictionariesPath } from './getBuiltUnmergedDictionariesPath';\nexport { getFilteredLocalesContent } from './getFilteredLocalesContent';\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 {\n createDictionaryEntryPoint,\n generateDictionaryListContent,\n} from './transpiler/dictionary_to_main';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\nexport { getFileHash } from './utils';\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,sBAAsB;AAC/B,SAAS,gCAAgC;AACzC,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,wCAAwC;AACjD,SAAS,iCAAiC;AAC1C,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;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,gCAAgC;AACzC,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,OAEK;","names":[]}
|
|
@@ -22,8 +22,11 @@ const prepareIntlayer = async (configuration = getConfiguration(), projectRequir
|
|
|
22
22
|
configuration,
|
|
23
23
|
projectRequire
|
|
24
24
|
);
|
|
25
|
-
const
|
|
26
|
-
|
|
25
|
+
const dictionariesOutput = await buildDictionary(dictionaries, configuration);
|
|
26
|
+
const dictionariesPaths = Object.values(
|
|
27
|
+
dictionariesOutput?.mergedDictionaries ?? {}
|
|
28
|
+
).map((dictionary) => dictionary.dictionaryPath);
|
|
29
|
+
createTypes(dictionariesPaths);
|
|
27
30
|
createDictionaryEntryPoint(configuration);
|
|
28
31
|
appLogger("Dictionaries built");
|
|
29
32
|
createModuleAugmentation(configuration);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n type IntlayerConfig,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { listDictionaries } from './listDictionariesPath';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createModuleAugmentation,\n createTypes,\n} from './transpiler/dictionary_to_type/index';\nimport { writeConfiguration } from './writeConfiguration';\n\nexport const prepareIntlayer = async (\n configuration: IntlayerConfig = getConfiguration(),\n projectRequire = ESMxCJSRequire\n) => {\n const appLogger = getAppLogger(configuration);\n\n cleanOutputDir(configuration);\n\n 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
|
|
1
|
+
{"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n ESMxCJSRequire,\n type IntlayerConfig,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { listDictionaries } from './listDictionariesPath';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createModuleAugmentation,\n createTypes,\n} from './transpiler/dictionary_to_type/index';\nimport { writeConfiguration } from './writeConfiguration';\n\nexport const prepareIntlayer = async (\n configuration: IntlayerConfig = getConfiguration(),\n projectRequire = ESMxCJSRequire\n) => {\n const appLogger = getAppLogger(configuration);\n\n cleanOutputDir(configuration);\n\n 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 dictionariesOutput = await buildDictionary(dictionaries, configuration);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint(configuration);\n\n appLogger('Dictionaries built');\n\n createModuleAugmentation(configuration);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n writeConfiguration(configuration);\n\n appLogger('Configuration written', {\n isVerbose: true,\n });\n};\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AAE5B,MAAM,kBAAkB,OAC7B,gBAAgC,iBAAiB,GACjD,iBAAiB,mBACd;AACH,QAAM,YAAY,aAAa,aAAa;AAE5C,iBAAe,aAAa;AAE5B,QAAM,QAAkB,iBAAiB,aAAa;AAEtD,QAAM,eAAe,MAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGA,QAAM,qBAAqB,MAAM,gBAAgB,cAAc,aAAa;AAE5E,QAAM,oBAAoB,OAAO;AAAA,IAC/B,oBAAoB,sBAAsB,CAAC;AAAA,EAC7C,EAAE,IAAI,CAAC,eAAe,WAAW,cAAc;AAE/C,cAAY,iBAAiB;AAE7B,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":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/declaration_file_to_dictionary/index.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { buildI18nDictionary } from './i18next_dictionary/index';\nimport { buildIntlayerDictionary } from './intlayer_dictionary/index';\n\nexport const buildDictionary = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n)
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/declaration_file_to_dictionary/index.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { buildI18nDictionary } from './i18next_dictionary/index';\nimport { buildIntlayerDictionary } from './intlayer_dictionary/index';\n\nexport const buildDictionary = async (\n dictionaries: Dictionary[],\n configuration = getConfiguration()\n) => {\n const { dictionaryOutput } = configuration.content;\n\n if (dictionaryOutput.includes('i18next')) {\n await buildI18nDictionary(dictionaries, configuration);\n }\n\n if (dictionaryOutput.includes('intlayer')) {\n return await buildIntlayerDictionary(dictionaries, configuration);\n }\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AAEjC,SAAS,2BAA2B;AACpC,SAAS,+BAA+B;AAEjC,MAAM,kBAAkB,OAC7B,cACA,gBAAgB,iBAAiB,MAC9B;AACH,QAAM,EAAE,iBAAiB,IAAI,cAAc;AAE3C,MAAI,iBAAiB,SAAS,SAAS,GAAG;AACxC,UAAM,oBAAoB,cAAc,aAAa;AAAA,EACvD;AAEA,MAAI,iBAAiB,SAAS,UAAU,GAAG;AACzC,WAAO,MAAM,wBAAwB,cAAc,aAAa;AAAA,EAClE;AACF;","names":[]}
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import { mkdir } from "fs/promises";
|
|
2
|
-
import { resolve } from "path";
|
|
3
1
|
import { getConfiguration } from "@intlayer/config";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
2
|
+
import { writeDynamicDictionary } from "./writeDynamicDictionary.mjs";
|
|
3
|
+
import { writeMergedDictionaries } from "./writeMergedDictionary.mjs";
|
|
4
|
+
import { writeUnmergedDictionaries } from "./writeUnmergedDictionary.mjs";
|
|
5
|
+
const buildIntlayerDictionary = async (contentDeclarations, configuration = getConfiguration(), formats = ["cjs", "esm"]) => {
|
|
6
|
+
const unmergedDictionaries = await writeUnmergedDictionaries(
|
|
9
7
|
contentDeclarations,
|
|
10
8
|
configuration
|
|
11
9
|
);
|
|
12
|
-
|
|
10
|
+
const mergedDictionaries = await writeMergedDictionaries(
|
|
11
|
+
unmergedDictionaries,
|
|
12
|
+
configuration
|
|
13
|
+
);
|
|
14
|
+
const dynamicDictionaries = await writeDynamicDictionary(
|
|
15
|
+
mergedDictionaries,
|
|
16
|
+
configuration,
|
|
17
|
+
formats
|
|
18
|
+
);
|
|
19
|
+
return {
|
|
20
|
+
unmergedDictionaries,
|
|
21
|
+
mergedDictionaries,
|
|
22
|
+
dynamicDictionaries
|
|
23
|
+
};
|
|
13
24
|
};
|
|
14
25
|
export {
|
|
15
26
|
buildIntlayerDictionary
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts"],"sourcesContent":["// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { writeDynamicDictionary } from './writeDynamicDictionary';\nimport { writeMergedDictionaries } from './writeMergedDictionary';\nimport { writeUnmergedDictionaries } from './writeUnmergedDictionary';\n\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const buildIntlayerDictionary = async (\n contentDeclarations: (DictionaryAPI | Dictionary)[],\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n) => {\n const unmergedDictionaries = await writeUnmergedDictionaries(\n contentDeclarations,\n configuration\n );\n\n const mergedDictionaries = await writeMergedDictionaries(\n unmergedDictionaries,\n configuration\n );\n\n const dynamicDictionaries = await writeDynamicDictionary(\n mergedDictionaries,\n configuration,\n formats\n );\n\n return {\n unmergedDictionaries,\n mergedDictionaries,\n dynamicDictionaries,\n };\n};\n"],"mappings":"AAEA,SAAS,wBAAwB;AAEjC,SAAS,8BAA8B;AACvC,SAAS,+BAA+B;AACxC,SAAS,iCAAiC;AAKnC,MAAM,0BAA0B,OACrC,qBACA,gBAAgB,iBAAiB,GACjC,UAA6B,CAAC,OAAO,KAAK,MACvC;AACH,QAAM,uBAAuB,MAAM;AAAA,IACjC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,qBAAqB,MAAM;AAAA,IAC/B;AAAA,IACA;AAAA,EACF;AAEA,QAAM,sBAAsB,MAAM;AAAA,IAChC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const isDevelopment = process.env.NODE_ENV === "development";
|
|
2
|
+
const formatDictionaryText = (dictionary) => isDevelopment ? JSON.stringify(dictionary, null, 2) : JSON.stringify(dictionary);
|
|
3
|
+
export {
|
|
4
|
+
formatDictionaryText
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=formatDictionaryText.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/formatDictionaryText.ts"],"sourcesContent":["const isDevelopment = process.env.NODE_ENV === 'development';\n\nexport const formatDictionaryText = (dictionary: object) =>\n isDevelopment\n ? JSON.stringify(dictionary, null, 2)\n : JSON.stringify(dictionary);\n"],"mappings":"AAAA,MAAM,gBAAgB,QAAQ,IAAI,aAAa;AAExC,MAAM,uBAAuB,CAAC,eACnC,gBACI,KAAK,UAAU,YAAY,MAAM,CAAC,IAClC,KAAK,UAAU,UAAU;","names":[]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { getConfiguration } from "@intlayer/config";
|
|
2
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
3
|
+
import { relative, resolve } from "path";
|
|
4
|
+
import { getFilteredLocalesContent } from "../../../getFilteredLocalesContent.mjs";
|
|
5
|
+
import { formatDictionaryText } from "./formatDictionaryText.mjs";
|
|
6
|
+
const generateDictionaryEntryPoint = (localedDictionariesPathsRecord, format = "esm", configuration = getConfiguration()) => {
|
|
7
|
+
const { dynamicDictionariesDir } = configuration.content;
|
|
8
|
+
let content = "";
|
|
9
|
+
const formattedDictionaryMap = Object.entries(
|
|
10
|
+
localedDictionariesPathsRecord
|
|
11
|
+
).map(([locale, dictionary]) => {
|
|
12
|
+
const relativePath = relative(
|
|
13
|
+
dynamicDictionariesDir,
|
|
14
|
+
dictionary.dictionaryPath
|
|
15
|
+
);
|
|
16
|
+
if (format === "esm") {
|
|
17
|
+
return ` '${locale}': () => import('./${relativePath}', { assert: { type: 'json' }}).then(mod => mod.default)`;
|
|
18
|
+
}
|
|
19
|
+
return ` '${locale}': () => Promise.resolve(require('./${relativePath}'))`;
|
|
20
|
+
}).join(",\n");
|
|
21
|
+
content += `const content = {
|
|
22
|
+
${formattedDictionaryMap}
|
|
23
|
+
};
|
|
24
|
+
`;
|
|
25
|
+
if (format === "esm") content += `export default content;
|
|
26
|
+
`;
|
|
27
|
+
if (format === "cjs") content += `module.exports = content;
|
|
28
|
+
`;
|
|
29
|
+
return content;
|
|
30
|
+
};
|
|
31
|
+
const writeDynamicDictionary = async (mergedDictionaries, configuration = getConfiguration(), formats = ["cjs", "esm"]) => {
|
|
32
|
+
const { locales, defaultLocale } = configuration.internationalization;
|
|
33
|
+
const { dynamicDictionariesDir } = configuration.content;
|
|
34
|
+
await mkdir(resolve(dynamicDictionariesDir), { recursive: true });
|
|
35
|
+
let resultDictionariesPaths = {};
|
|
36
|
+
for await (const [key, dictionaryEntry] of Object.entries(
|
|
37
|
+
mergedDictionaries
|
|
38
|
+
)) {
|
|
39
|
+
if (key === "undefined") continue;
|
|
40
|
+
let localedDictionariesPathsRecord = {};
|
|
41
|
+
for await (const locale of locales) {
|
|
42
|
+
const localizedDictionary = {
|
|
43
|
+
...dictionaryEntry.dictionary,
|
|
44
|
+
locale,
|
|
45
|
+
content: getFilteredLocalesContent(
|
|
46
|
+
dictionaryEntry.dictionary.content,
|
|
47
|
+
locale,
|
|
48
|
+
{ dictionaryKey: key, keyPath: [] },
|
|
49
|
+
defaultLocale
|
|
50
|
+
)
|
|
51
|
+
};
|
|
52
|
+
const contentString = formatDictionaryText(localizedDictionary);
|
|
53
|
+
const outputFileName = `${key}.${locale}.json`;
|
|
54
|
+
const resultFilePath = resolve(dynamicDictionariesDir, outputFileName);
|
|
55
|
+
await writeFile(resultFilePath, contentString, "utf8").catch((err) => {
|
|
56
|
+
console.error(`Error creating localized ${outputFileName}:`, err);
|
|
57
|
+
});
|
|
58
|
+
localedDictionariesPathsRecord[locale] = {
|
|
59
|
+
dictionaryPath: resultFilePath,
|
|
60
|
+
dictionary: localizedDictionary
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
resultDictionariesPaths[key] = localedDictionariesPathsRecord;
|
|
64
|
+
for await (const format of formats) {
|
|
65
|
+
const extension = format === "cjs" ? "cjs" : "mjs";
|
|
66
|
+
const content = generateDictionaryEntryPoint(
|
|
67
|
+
localedDictionariesPathsRecord,
|
|
68
|
+
format,
|
|
69
|
+
configuration
|
|
70
|
+
);
|
|
71
|
+
await writeFile(
|
|
72
|
+
resolve(dynamicDictionariesDir, `${key}.${extension}`),
|
|
73
|
+
content
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return resultDictionariesPaths;
|
|
78
|
+
};
|
|
79
|
+
export {
|
|
80
|
+
generateDictionaryEntryPoint,
|
|
81
|
+
writeDynamicDictionary
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=writeDynamicDictionary.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDynamicDictionary.ts"],"sourcesContent":["import { getConfiguration, Locales } from '@intlayer/config';\nimport { type Dictionary } from '@intlayer/core';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { relative, resolve } from 'path';\nimport { getFilteredLocalesContent } from '../../../getFilteredLocalesContent';\nimport { formatDictionaryText } from './formatDictionaryText';\nimport { MergedDictionaryOutput } from './writeMergedDictionary';\n\nexport type DictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type LocalizedDictionaryResult = Partial<\n Record<Locales, DictionaryResult>\n>;\n\nexport type LocalizedDictionaryOutput = Record<\n string,\n LocalizedDictionaryResult\n>;\n\n/**\n * This function generates the content of the dictionary list file\n */\nexport const generateDictionaryEntryPoint = (\n localedDictionariesPathsRecord: LocalizedDictionaryResult,\n format: 'cjs' | 'esm' = 'esm',\n configuration = getConfiguration()\n): string => {\n const { dynamicDictionariesDir } = configuration.content;\n\n let content = '';\n\n // Format Dictionary Map - map locales to functions\n const formattedDictionaryMap: string = Object.entries(\n localedDictionariesPathsRecord\n )\n .map(([locale, dictionary]) => {\n const relativePath = relative(\n dynamicDictionariesDir,\n dictionary.dictionaryPath\n );\n\n if (format === 'esm') {\n return ` '${locale}': () => import('./${relativePath}', { assert: { type: 'json' }}).then(mod => mod.default)`;\n }\n\n return ` '${locale}': () => Promise.resolve(require('./${relativePath}'))`;\n })\n .join(',\\n');\n\n content += `const content = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n if (format === 'esm') content += `export default content;\\n`;\n if (format === 'cjs') content += `module.exports = content;\\n`;\n\n return content;\n};\n\n/**\n * Write the localized dictionaries to the dictionariesDir\n * @param mergedDictionaries - The merged 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 writeDynamicDictionary = async (\n mergedDictionaries: MergedDictionaryOutput,\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n): Promise<LocalizedDictionaryOutput> => {\n const { locales, defaultLocale } = configuration.internationalization;\n const { dynamicDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dynamicDictionariesDir), { recursive: true });\n\n let resultDictionariesPaths: LocalizedDictionaryOutput = {};\n\n // Merge dictionaries with the same key and write to dictionariesDir\n for await (const [key, dictionaryEntry] of Object.entries(\n mergedDictionaries\n )) {\n if (key === 'undefined') continue;\n\n let localedDictionariesPathsRecord: LocalizedDictionaryResult = {};\n\n for await (const locale of locales) {\n const localizedDictionary = {\n ...dictionaryEntry.dictionary,\n locale,\n content: getFilteredLocalesContent(\n dictionaryEntry.dictionary.content as any,\n locale,\n { dictionaryKey: key, keyPath: [] },\n defaultLocale\n ),\n };\n\n const contentString = formatDictionaryText(localizedDictionary);\n\n const outputFileName = `${key}.${locale}.json`;\n const resultFilePath = resolve(dynamicDictionariesDir, outputFileName);\n\n // Write the localized dictionary\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating localized ${outputFileName}:`, err);\n });\n\n localedDictionariesPathsRecord[locale] = {\n dictionaryPath: resultFilePath,\n dictionary: localizedDictionary,\n };\n }\n\n resultDictionariesPaths[key] = localedDictionariesPathsRecord;\n\n for await (const format of formats) {\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n const content = generateDictionaryEntryPoint(\n localedDictionariesPathsRecord,\n format,\n configuration\n );\n\n await writeFile(\n resolve(dynamicDictionariesDir, `${key}.${extension}`),\n content\n );\n }\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA,SAAS,wBAAiC;AAE1C,SAAS,OAAO,iBAAiB;AACjC,SAAS,UAAU,eAAe;AAClC,SAAS,iCAAiC;AAC1C,SAAS,4BAA4B;AAoB9B,MAAM,+BAA+B,CAC1C,gCACA,SAAwB,OACxB,gBAAgB,iBAAiB,MACtB;AACX,QAAM,EAAE,uBAAuB,IAAI,cAAc;AAEjD,MAAI,UAAU;AAGd,QAAM,yBAAiC,OAAO;AAAA,IAC5C;AAAA,EACF,EACG,IAAI,CAAC,CAAC,QAAQ,UAAU,MAAM;AAC7B,UAAM,eAAe;AAAA,MACnB;AAAA,MACA,WAAW;AAAA,IACb;AAEA,QAAI,W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