@intlayer/chokidar 1.2.0 → 1.2.1
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 +4 -4
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.cjs +80 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.ts +6 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.cjs +86 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.ts +8 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.cjs +50 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.ts +3 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.cjs +23 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.ts +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs +43 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/index.d.ts +3 -0
- package/dist/cjs/transpiler/{intlater_module_to_dictionary/transpileContentDeclaration.cjs → declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs} +11 -11
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.ts +6 -0
- package/dist/cjs/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/extractNestedJSON.cjs +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.cjs.map +1 -0
- package/dist/cjs/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/index.cjs +7 -7
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.ts +4 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.cjs.map +1 -0
- package/dist/cjs/transpiler/{intlater_module_to_dictionary/processModule.cjs → declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs} +5 -6
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +24 -12
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -1
- package/dist/esm/chokidar/watcher.mjs +4 -4
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.d.mts +6 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.mjs +61 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.d.mts +8 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.mjs +64 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.d.mts +3 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.mjs +26 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.d.mts +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.mjs +2 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.d.mts +3 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs +19 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/index.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.d.mts +6 -0
- package/dist/esm/transpiler/{intlater_module_to_dictionary/transpileContentDeclaration.mjs → declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs} +6 -6
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.mjs.map +1 -0
- package/dist/esm/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/extractNestedJSON.mjs +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.d.mts +4 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.mjs +4 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.mjs.map +1 -0
- package/dist/esm/transpiler/{intlater_module_to_dictionary/processModule.mjs → declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs} +2 -3
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +24 -12
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -1
- package/package.json +4 -4
- package/src/chokidar/watcher.ts +5 -14
- package/src/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.ts +95 -0
- package/src/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.ts +91 -0
- package/src/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.ts +22 -0
- package/src/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.ts +1 -0
- package/src/transpiler/declaration_file_to_dictionary/index.ts +21 -0
- package/src/transpiler/{intlater_module_to_dictionary/transpileContentDeclaration.ts → declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts} +4 -4
- package/src/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/extractNestedJSON.ts +1 -1
- package/src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.ts +3 -0
- package/src/transpiler/{intlater_module_to_dictionary/processModule.ts → declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.ts} +2 -3
- package/src/transpiler/dictionary_to_type/createType.ts +36 -19
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.d.ts +0 -4
- package/dist/cjs/transpiler/intlater_module_to_dictionary/loadContentDeclaration.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.d.ts +0 -6
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.d.mts +0 -4
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs +0 -4
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/loadContentDeclaration.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.d.mts +0 -6
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileContentDeclaration.mjs.map +0 -1
- package/src/transpiler/intlater_module_to_dictionary/index.ts +0 -3
- /package/dist/cjs/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/extractNestedJSON.d.ts +0 -0
- /package/dist/cjs/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/loadContentDeclaration.cjs +0 -0
- /package/dist/cjs/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/loadContentDeclaration.d.ts +0 -0
- /package/dist/cjs/transpiler/{intlater_module_to_dictionary/processModule.d.ts → declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.ts} +0 -0
- /package/dist/esm/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/extractNestedJSON.d.mts +0 -0
- /package/dist/esm/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/loadContentDeclaration.d.mts +0 -0
- /package/dist/esm/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/loadContentDeclaration.mjs +0 -0
- /package/dist/esm/transpiler/{intlater_module_to_dictionary/processModule.d.mts → declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.d.mts} +0 -0
- /package/src/transpiler/{intlater_module_to_dictionary → declaration_file_to_dictionary/intlayer_dictionary}/loadContentDeclaration.ts +0 -0
|
@@ -35,9 +35,9 @@ var import_path = require("path");
|
|
|
35
35
|
var import_config = require("@intlayer/config");
|
|
36
36
|
var import_chokidar = __toESM(require("chokidar"));
|
|
37
37
|
var import_glob = require("glob");
|
|
38
|
+
var import_declaration_file_to_dictionary = require('../transpiler/declaration_file_to_dictionary/index.cjs');
|
|
38
39
|
var import_createDictionaryList = require('../transpiler/dictionary_to_main/createDictionaryList.cjs');
|
|
39
40
|
var import_dictionary_to_type = require('../transpiler/dictionary_to_type/index.cjs');
|
|
40
|
-
var import_transpileContentDeclaration = require('../transpiler/intlater_module_to_dictionary/transpileContentDeclaration.cjs');
|
|
41
41
|
const watch = (options) => {
|
|
42
42
|
const { content } = (0, import_config.getConfiguration)({
|
|
43
43
|
verbose: true
|
|
@@ -51,7 +51,7 @@ const watch = (options) => {
|
|
|
51
51
|
// Process existing files
|
|
52
52
|
...options
|
|
53
53
|
}).on("ready", async () => {
|
|
54
|
-
const dictionariesPaths = await (0,
|
|
54
|
+
const dictionariesPaths = await (0, import_declaration_file_to_dictionary.buildDictionary)(files);
|
|
55
55
|
console.info("Building Intlayer types...");
|
|
56
56
|
(0, import_dictionary_to_type.createTypes)(dictionariesPaths);
|
|
57
57
|
console.info("Building Intlayer module augmentation...");
|
|
@@ -66,7 +66,7 @@ const watch = (options) => {
|
|
|
66
66
|
console.info("Removed file detected: ", (0, import_path.relative)(baseDir, filePath));
|
|
67
67
|
}).on("add", async (filePath) => {
|
|
68
68
|
console.info("Additional file detected: ", (0, import_path.relative)(baseDir, filePath));
|
|
69
|
-
const dictionaries = await (0,
|
|
69
|
+
const dictionaries = await (0, import_declaration_file_to_dictionary.buildDictionary)(filePath);
|
|
70
70
|
console.info("Building TypeScript types...");
|
|
71
71
|
(0, import_dictionary_to_type.createTypes)(dictionaries);
|
|
72
72
|
console.info("Building type index...");
|
|
@@ -75,7 +75,7 @@ const watch = (options) => {
|
|
|
75
75
|
(0, import_createDictionaryList.createDictionaryList)();
|
|
76
76
|
}).on("change", async (filePath) => {
|
|
77
77
|
console.info("Change detected: ", (0, import_path.relative)(baseDir, filePath));
|
|
78
|
-
const dictionaries = await (0,
|
|
78
|
+
const dictionaries = await (0, import_declaration_file_to_dictionary.buildDictionary)(filePath);
|
|
79
79
|
console.info("Building TypeScript types...");
|
|
80
80
|
(0, import_dictionary_to_type.createTypes)(dictionaries);
|
|
81
81
|
}).on("error", (error) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport chokidar, { type WatchOptions } from 'chokidar';\nimport { sync } from 'glob';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\
|
|
1
|
+
{"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport chokidar, { type WatchOptions } from 'chokidar';\nimport { sync } from 'glob';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryList } from '../transpiler/dictionary_to_main/createDictionaryList';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const { content } = getConfiguration({\n verbose: true,\n });\n\n const { watchedFilesPatternWithPath, baseDir } = content;\n\n const files: string[] = sync(watchedFilesPatternWithPath);\n\n return chokidar\n .watch(watchedFilesPatternWithPath, {\n persistent: true, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('ready', async () => {\n const dictionariesPaths = await buildDictionary(files);\n\n console.info('Building Intlayer types...');\n createTypes(dictionariesPaths);\n\n console.info('Building Intlayer module augmentation...');\n createModuleAugmentation();\n\n console.info('Building Intlayer dictionary list...');\n createDictionaryList();\n\n const relativeDictionariesPath = dictionariesPaths.map((dictionary) =>\n relative(baseDir, dictionary)\n );\n\n console.info('Dictionaries:', relativeDictionariesPath);\n })\n .on('unlink', (filePath) => {\n // Process the file with the functionToRun\n console.info('Removed file detected: ', relative(baseDir, filePath));\n })\n .on('add', async (filePath) => {\n // Process the file with the functionToRun\n console.info('Additional file detected: ', relative(baseDir, filePath));\n const dictionaries = await buildDictionary(filePath);\n\n console.info('Building TypeScript types...');\n createTypes(dictionaries);\n\n console.info('Building type index...');\n createModuleAugmentation();\n\n console.info('Building main...');\n createDictionaryList();\n })\n .on('change', async (filePath) => {\n // Process the file with the functionToRun\n console.info('Change detected: ', relative(baseDir, filePath));\n const dictionaries = await buildDictionary(filePath);\n\n console.info('Building TypeScript types...');\n createTypes(dictionaries);\n })\n .on('error', (error) => {\n console.error('Watcher error:', error);\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyB;AACzB,oBAAiC;AACjC,sBAA4C;AAC5C,kBAAqB;AACrB,4CAAgC;AAChC,kCAAqC;AACrC,gCAGO;AAGA,MAAM,QAAQ,CAAC,YAA2B;AAC/C,QAAM,EAAE,QAAQ,QAAI,gCAAiB;AAAA,IACnC,SAAS;AAAA,EACX,CAAC;AAED,QAAM,EAAE,6BAA6B,QAAQ,IAAI;AAEjD,QAAM,YAAkB,kBAAK,2BAA2B;AAExD,SAAO,gBAAAA,QACJ,MAAM,6BAA6B;AAAA,IAClC,YAAY;AAAA;AAAA,IACZ,eAAe;AAAA;AAAA,IACf,GAAG;AAAA,EACL,CAAC,EACA,GAAG,SAAS,YAAY;AACvB,UAAM,oBAAoB,UAAM,uDAAgB,KAAK;AAErD,YAAQ,KAAK,4BAA4B;AACzC,+CAAY,iBAAiB;AAE7B,YAAQ,KAAK,0CAA0C;AACvD,4DAAyB;AAEzB,YAAQ,KAAK,sCAAsC;AACnD,0DAAqB;AAErB,UAAM,2BAA2B,kBAAkB;AAAA,MAAI,CAAC,mBACtD,sBAAS,SAAS,UAAU;AAAA,IAC9B;AAEA,YAAQ,KAAK,iBAAiB,wBAAwB;AAAA,EACxD,CAAC,EACA,GAAG,UAAU,CAAC,aAAa;AAE1B,YAAQ,KAAK,+BAA2B,sBAAS,SAAS,QAAQ,CAAC;AAAA,EACrE,CAAC,EACA,GAAG,OAAO,OAAO,aAAa;AAE7B,YAAQ,KAAK,kCAA8B,sBAAS,SAAS,QAAQ,CAAC;AACtE,UAAM,eAAe,UAAM,uDAAgB,QAAQ;AAEnD,YAAQ,KAAK,8BAA8B;AAC3C,+CAAY,YAAY;AAExB,YAAQ,KAAK,wBAAwB;AACrC,4DAAyB;AAEzB,YAAQ,KAAK,kBAAkB;AAC/B,0DAAqB;AAAA,EACvB,CAAC,EACA,GAAG,UAAU,OAAO,aAAa;AAEhC,YAAQ,KAAK,yBAAqB,sBAAS,SAAS,QAAQ,CAAC;AAC7D,UAAM,eAAe,UAAM,uDAAgB,QAAQ;AAEnD,YAAQ,KAAK,8BAA8B;AAC3C,+CAAY,YAAY;AAAA,EAC1B,CAAC,EACA,GAAG,SAAS,CAAC,UAAU;AACtB,YAAQ,MAAM,kBAAkB,KAAK;AAAA,EACvC,CAAC;AACL;","names":["chokidar"]}
|
package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.cjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
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 buildI18nDictionary_exports = {};
|
|
20
|
+
__export(buildI18nDictionary_exports, {
|
|
21
|
+
buildI18nDictionary: () => buildI18nDictionary
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(buildI18nDictionary_exports);
|
|
24
|
+
var import_promises = require("fs/promises");
|
|
25
|
+
var import_path = require("path");
|
|
26
|
+
var import_config = require("@intlayer/config");
|
|
27
|
+
var import_intlayer_dictionary = require('../intlayer_dictionary/index.cjs');
|
|
28
|
+
var import_convertContentDeclarationInto18nDictionaries = require('./convertContentDeclarationInto18nDictionaries.cjs');
|
|
29
|
+
const { content } = (0, import_config.getConfiguration)();
|
|
30
|
+
const { i18nDictionariesDir } = content;
|
|
31
|
+
const writeDictionary = async (dictionariesDeclaration) => {
|
|
32
|
+
const resultDictionariesPaths = [];
|
|
33
|
+
for (const [nameSpace, localContent] of Object.entries(
|
|
34
|
+
dictionariesDeclaration
|
|
35
|
+
)) {
|
|
36
|
+
for await (const [locale, content2] of Object.entries(localContent)) {
|
|
37
|
+
const contentString = JSON.stringify(content2);
|
|
38
|
+
const outputFileName = `${nameSpace}.json`;
|
|
39
|
+
const resultDirPath = (0, import_path.resolve)(i18nDictionariesDir, locale);
|
|
40
|
+
const resultFilePath = (0, import_path.resolve)(resultDirPath, outputFileName);
|
|
41
|
+
await (0, import_promises.mkdir)(resultDirPath, { recursive: true });
|
|
42
|
+
await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
|
|
43
|
+
console.error(`Error creating ${outputFileName}:`, err);
|
|
44
|
+
});
|
|
45
|
+
resultDictionariesPaths.push(resultFilePath);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return resultDictionariesPaths;
|
|
49
|
+
};
|
|
50
|
+
const buildI18nDictionary = async (contentDeclarationsPaths) => {
|
|
51
|
+
const resultDictionariesPaths = [];
|
|
52
|
+
if (typeof contentDeclarationsPaths === "string") {
|
|
53
|
+
contentDeclarationsPaths = [contentDeclarationsPaths];
|
|
54
|
+
}
|
|
55
|
+
for await (const contentDeclarationPath of contentDeclarationsPaths) {
|
|
56
|
+
const result = await (0, import_intlayer_dictionary.processContentDeclaration)(contentDeclarationPath);
|
|
57
|
+
if (!result) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const nestedContent = (0, import_intlayer_dictionary.extractObjectsWithId)(result);
|
|
61
|
+
const dictionariesDeclaration = nestedContent.reduce((acc, content2) => {
|
|
62
|
+
const id = content2.id;
|
|
63
|
+
const i18Content = (0, import_convertContentDeclarationInto18nDictionaries.createI18nDictionaries)(content2);
|
|
64
|
+
return {
|
|
65
|
+
...acc,
|
|
66
|
+
[id]: i18Content
|
|
67
|
+
};
|
|
68
|
+
}, {});
|
|
69
|
+
const dictionariesPaths = await writeDictionary(
|
|
70
|
+
dictionariesDeclaration
|
|
71
|
+
);
|
|
72
|
+
resultDictionariesPaths.push(...dictionariesPaths);
|
|
73
|
+
}
|
|
74
|
+
return resultDictionariesPaths;
|
|
75
|
+
};
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
buildI18nDictionary
|
|
79
|
+
});
|
|
80
|
+
//# sourceMappingURL=buildI18nDictionary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/buildI18nDictionary.ts"],"sourcesContent":["import { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { ContentModule } from '@intlayer/core';\nimport {\n processContentDeclaration,\n extractObjectsWithId,\n} from '../intlayer_dictionary/index';\nimport {\n type I18nDictionariesOutput,\n createI18nDictionaries,\n} from './convertContentDeclarationInto18nDictionaries';\n\nconst { content } = getConfiguration();\nconst { i18nDictionariesDir } = content;\n\ntype DictionariesDeclaration = Record<string, I18nDictionariesOutput>;\n\n/**\n * This function writes the dictionaries to the file system\n */\nconst writeDictionary = async (\n dictionariesDeclaration: DictionariesDeclaration\n) => {\n const resultDictionariesPaths: string[] = [];\n\n for (const [nameSpace, localContent] of Object.entries(\n dictionariesDeclaration\n )) {\n for await (const [locale, content] of Object.entries(localContent)) {\n const contentString = JSON.stringify(content);\n\n const outputFileName = `${nameSpace}.json`;\n const resultDirPath = resolve(i18nDictionariesDir, locale);\n const resultFilePath = resolve(resultDirPath, outputFileName);\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resultDirPath, { recursive: true });\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n }\n\n return resultDictionariesPaths;\n};\n\n/**\n * This function transpile content declaration to i18n dictionaries\n */\nexport const buildI18nDictionary = async (\n contentDeclarationsPaths: string[] | string\n) => {\n const resultDictionariesPaths: string[] = [];\n\n if (typeof contentDeclarationsPaths === 'string') {\n contentDeclarationsPaths = [contentDeclarationsPaths];\n }\n\n for await (const contentDeclarationPath of contentDeclarationsPaths) {\n const result = await processContentDeclaration(contentDeclarationPath);\n\n if (!result) {\n continue;\n }\n\n const nestedContent: ContentModule[] = extractObjectsWithId(result);\n\n // Create dictionaries for each nested content and format them\n const dictionariesDeclaration: DictionariesDeclaration =\n nestedContent.reduce((acc, content) => {\n const id = content.id;\n const i18Content = createI18nDictionaries(content);\n\n return {\n ...acc,\n [id]: i18Content,\n };\n }, {});\n\n // Write the dictionaries to the file system\n const dictionariesPaths: string[] = await writeDictionary(\n dictionariesDeclaration\n );\n\n // Add the paths to the result\n resultDictionariesPaths.push(...dictionariesPaths);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAiC;AACjC,kBAAwB;AACxB,oBAAiC;AAEjC,iCAGO;AACP,0DAGO;AAEP,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,oBAAoB,IAAI;AAOhC,MAAM,kBAAkB,OACtB,4BACG;AACH,QAAM,0BAAoC,CAAC;AAE3C,aAAW,CAAC,WAAW,YAAY,KAAK,OAAO;AAAA,IAC7C;AAAA,EACF,GAAG;AACD,qBAAiB,CAAC,QAAQA,QAAO,KAAK,OAAO,QAAQ,YAAY,GAAG;AAClE,YAAM,gBAAgB,KAAK,UAAUA,QAAO;AAE5C,YAAM,iBAAiB,GAAG,SAAS;AACnC,YAAM,oBAAgB,qBAAQ,qBAAqB,MAAM;AACzD,YAAM,qBAAiB,qBAAQ,eAAe,cAAc;AAG5D,gBAAM,uBAAM,eAAe,EAAE,WAAW,KAAK,CAAC;AAG9C,gBAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,gBAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,MACxD,CAAC;AAED,8BAAwB,KAAK,cAAc;AAAA,IAC7C;AAAA,EACF;AAEA,SAAO;AACT;AAKO,MAAM,sBAAsB,OACjC,6BACG;AACH,QAAM,0BAAoC,CAAC;AAE3C,MAAI,OAAO,6BAA6B,UAAU;AAChD,+BAA2B,CAAC,wBAAwB;AAAA,EACtD;AAEA,mBAAiB,0BAA0B,0BAA0B;AACnE,UAAM,SAAS,UAAM,sDAA0B,sBAAsB;AAErE,QAAI,CAAC,QAAQ;AACX;AAAA,IACF;AAEA,UAAM,oBAAiC,iDAAqB,MAAM;AAGlE,UAAM,0BACJ,cAAc,OAAO,CAAC,KAAKA,aAAY;AACrC,YAAM,KAAKA,SAAQ;AACnB,YAAM,iBAAa,4EAAuBA,QAAO;AAEjD,aAAO;AAAA,QACL,GAAG;AAAA,QACH,CAAC,EAAE,GAAG;AAAA,MACR;AAAA,IACF,GAAG,CAAC,CAAC;AAGP,UAAM,oBAA8B,MAAM;AAAA,MACxC;AAAA,IACF;AAGA,4BAAwB,KAAK,GAAG,iBAAiB;AAAA,EACnD;AAEA,SAAO;AACT;","names":["content"]}
|
|
@@ -0,0 +1,86 @@
|
|
|
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 convertContentDeclarationInto18nDictionaries_exports = {};
|
|
20
|
+
__export(convertContentDeclarationInto18nDictionaries_exports, {
|
|
21
|
+
createI18nDictionaries: () => createI18nDictionaries
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(convertContentDeclarationInto18nDictionaries_exports);
|
|
24
|
+
var import_config = require("@intlayer/config");
|
|
25
|
+
var import_core = require("@intlayer/core");
|
|
26
|
+
var import_convertPluralsValues = require('./convertPluralsValues.cjs');
|
|
27
|
+
const {
|
|
28
|
+
internationalization: { locales }
|
|
29
|
+
} = (0, import_config.getConfiguration)();
|
|
30
|
+
const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined" && typeof node?.type !== "undefined";
|
|
31
|
+
const buildDictionary = (content, locale) => {
|
|
32
|
+
if (
|
|
33
|
+
// Translation node
|
|
34
|
+
content && content.nodeType === import_core.NodeType.Translation
|
|
35
|
+
) {
|
|
36
|
+
const result = content[locale];
|
|
37
|
+
return buildDictionary(result, locale);
|
|
38
|
+
} else if (
|
|
39
|
+
// Translation node
|
|
40
|
+
content && content.nodeType === import_core.NodeType.Enumeration
|
|
41
|
+
) {
|
|
42
|
+
const plurals = {};
|
|
43
|
+
Object.keys(content).forEach((quantity) => {
|
|
44
|
+
const letterNumber = (0, import_convertPluralsValues.convertPluralsValues)(quantity);
|
|
45
|
+
const value = content[quantity];
|
|
46
|
+
plurals[`${letterNumber}_${letterNumber}`] = buildDictionary(
|
|
47
|
+
value,
|
|
48
|
+
locale
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
return plurals;
|
|
52
|
+
} else if (
|
|
53
|
+
// React element node
|
|
54
|
+
isReactNode(content)
|
|
55
|
+
) {
|
|
56
|
+
return JSON.stringify(content);
|
|
57
|
+
} else if (
|
|
58
|
+
// Nested object
|
|
59
|
+
typeof content === "object"
|
|
60
|
+
) {
|
|
61
|
+
const result = {};
|
|
62
|
+
Object.keys(content).forEach((dictionaryValue) => {
|
|
63
|
+
result[dictionaryValue] = buildDictionary(
|
|
64
|
+
content[dictionaryValue],
|
|
65
|
+
locale
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
return content;
|
|
71
|
+
};
|
|
72
|
+
const createI18nDictionaries = (content) => {
|
|
73
|
+
const result = locales.reduce(
|
|
74
|
+
(acc, locale) => ({
|
|
75
|
+
...acc,
|
|
76
|
+
[locale]: buildDictionary(content, locale)
|
|
77
|
+
}),
|
|
78
|
+
{}
|
|
79
|
+
);
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
createI18nDictionaries
|
|
85
|
+
});
|
|
86
|
+
//# sourceMappingURL=convertContentDeclarationInto18nDictionaries.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config';\nimport {\n NodeType,\n type TranslationContent,\n type Content,\n type TypedNode,\n type EnumerationContent,\n} from '@intlayer/core';\nimport { convertPluralsValues } from './convertPluralsValues';\n\ntype Dictionary = Record<string, unknown>;\nexport type I18nDictionariesOutput = Partial<Record<Locales, Dictionary>>;\n\nconst {\n internationalization: { locales },\n} = getConfiguration();\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' &&\n typeof node?.props !== 'undefined' &&\n typeof node?.type !== 'undefined';\n\n// Build dictionary for a specific locale\nconst buildDictionary = (content: Dictionary, locale: Locales): unknown => {\n if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Translation\n ) {\n const result = (content as TranslationContent<unknown>)[locale];\n\n return buildDictionary(result as Dictionary, locale);\n } else if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Enumeration\n ) {\n const plurals: Record<string, unknown> = {};\n\n Object.keys(content).forEach((quantity) => {\n const letterNumber = convertPluralsValues(quantity);\n\n const value = (content as EnumerationContent<unknown>)[\n quantity as keyof EnumerationContent<unknown>\n ];\n\n plurals[`${letterNumber}_${letterNumber}`] = buildDictionary(\n value as Dictionary,\n locale\n );\n });\n\n return plurals;\n } else if (\n // React element node\n isReactNode(content as Record<string, unknown>)\n ) {\n return JSON.stringify(content);\n } else if (\n // Nested object\n typeof content === 'object'\n ) {\n const result: Record<string, unknown> = {};\n\n Object.keys(content).forEach((dictionaryValue) => {\n result[dictionaryValue] = buildDictionary(\n content[dictionaryValue] as Dictionary,\n locale\n );\n });\n\n return result;\n }\n\n return content;\n};\n\nexport const createI18nDictionaries = (\n content: Content\n): I18nDictionariesOutput => {\n // Map dictionaries for each locale\n const result: I18nDictionariesOutput = locales.reduce(\n (acc, locale) => ({\n ...acc,\n [locale]: buildDictionary(content, locale),\n }),\n {}\n );\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,kBAMO;AACP,kCAAqC;AAKrC,MAAM;AAAA,EACJ,sBAAsB,EAAE,QAAQ;AAClC,QAAI,gCAAiB;AAErB,MAAM,cAAc,CAAC,SACnB,OAAO,MAAM,QAAQ,eACrB,OAAO,MAAM,UAAU,eACvB,OAAO,MAAM,SAAS;AAGxB,MAAM,kBAAkB,CAAC,SAAqB,WAA6B;AACzE;AAAA;AAAA,IAEE,WACC,QAAsB,aAAa,qBAAS;AAAA,IAC7C;AACA,UAAM,SAAU,QAAwC,MAAM;AAE9D,WAAO,gBAAgB,QAAsB,MAAM;AAAA,EACrD;AAAA;AAAA,IAEE,WACC,QAAsB,aAAa,qBAAS;AAAA,IAC7C;AACA,UAAM,UAAmC,CAAC;AAE1C,WAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,aAAa;AACzC,YAAM,mBAAe,kDAAqB,QAAQ;AAElD,YAAM,QAAS,QACb,QACF;AAEA,cAAQ,GAAG,YAAY,IAAI,YAAY,EAAE,IAAI;AAAA,QAC3C;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAAA;AAAA,IAEE,YAAY,OAAkC;AAAA,IAC9C;AACA,WAAO,KAAK,UAAU,OAAO;AAAA,EAC/B;AAAA;AAAA,IAEE,OAAO,YAAY;AAAA,IACnB;AACA,UAAM,SAAkC,CAAC;AAEzC,WAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,oBAAoB;AAChD,aAAO,eAAe,IAAI;AAAA,QACxB,QAAQ,eAAe;AAAA,QACvB;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,yBAAyB,CACpC,YAC2B;AAE3B,QAAM,SAAiC,QAAQ;AAAA,IAC7C,CAAC,KAAK,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,CAAC,MAAM,GAAG,gBAAgB,SAAS,MAAM;AAAA,IAC3C;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Locales } from '@intlayer/config';
|
|
2
|
+
import { Content } from '@intlayer/core';
|
|
3
|
+
|
|
4
|
+
type Dictionary = Record<string, unknown>;
|
|
5
|
+
type I18nDictionariesOutput = Partial<Record<Locales, Dictionary>>;
|
|
6
|
+
declare const createI18nDictionaries: (content: Content) => I18nDictionariesOutput;
|
|
7
|
+
|
|
8
|
+
export { type I18nDictionariesOutput, createI18nDictionaries };
|
package/dist/cjs/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.cjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
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 convertPluralsValues_exports = {};
|
|
20
|
+
__export(convertPluralsValues_exports, {
|
|
21
|
+
convertPluralsValues: () => convertPluralsValues
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(convertPluralsValues_exports);
|
|
24
|
+
const convertPluralsValues = (number) => {
|
|
25
|
+
switch (number) {
|
|
26
|
+
case "1":
|
|
27
|
+
return "one";
|
|
28
|
+
case "2":
|
|
29
|
+
return "two";
|
|
30
|
+
case "3":
|
|
31
|
+
return "three";
|
|
32
|
+
case "4":
|
|
33
|
+
return "four";
|
|
34
|
+
case "5":
|
|
35
|
+
return "five";
|
|
36
|
+
case "6":
|
|
37
|
+
return "six";
|
|
38
|
+
case "7":
|
|
39
|
+
return "seven";
|
|
40
|
+
case "8":
|
|
41
|
+
return "eight";
|
|
42
|
+
default:
|
|
43
|
+
return number.toString();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
convertPluralsValues
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=convertPluralsValues.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/convertPluralsValues.ts"],"sourcesContent":["export const convertPluralsValues = (number: string): string => {\n switch (number) {\n case '1':\n return 'one';\n case '2':\n return 'two';\n case '3':\n return 'three';\n case '4':\n return 'four';\n case '5':\n return 'five';\n case '6':\n return 'six';\n case '7':\n return 'seven';\n case '8':\n return 'eight';\n default:\n return number.toString();\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,uBAAuB,CAAC,WAA2B;AAC9D,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO,OAAO,SAAS;AAAA,EAC3B;AACF;","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var i18n_dictionary_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(i18n_dictionary_exports);
|
|
18
|
+
__reExport(i18n_dictionary_exports, require('./buildI18nDictionary.cjs'), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require('./buildI18nDictionary.cjs')
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18n_dictionary/index.ts"],"sourcesContent":["export * from './buildI18nDictionary';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,oCAAc,kCAAd;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { buildI18nDictionary } from './buildI18nDictionary.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
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 declaration_file_to_dictionary_exports = {};
|
|
20
|
+
__export(declaration_file_to_dictionary_exports, {
|
|
21
|
+
buildDictionary: () => buildDictionary
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(declaration_file_to_dictionary_exports);
|
|
24
|
+
var import_config = require("@intlayer/config");
|
|
25
|
+
var import_i18n_dictionary = require('./i18n_dictionary/index.cjs');
|
|
26
|
+
var import_intlayer_dictionary = require('./intlayer_dictionary/index.cjs');
|
|
27
|
+
const {
|
|
28
|
+
content: { dictionaryOutput }
|
|
29
|
+
} = (0, import_config.getConfiguration)();
|
|
30
|
+
const buildDictionary = async (contentDeclarationsPaths) => {
|
|
31
|
+
if (dictionaryOutput.includes("i18next")) {
|
|
32
|
+
return await (0, import_i18n_dictionary.buildI18nDictionary)(contentDeclarationsPaths);
|
|
33
|
+
}
|
|
34
|
+
if (dictionaryOutput.includes("intlayer")) {
|
|
35
|
+
return await (0, import_intlayer_dictionary.buildIntlayerDictionary)(contentDeclarationsPaths);
|
|
36
|
+
}
|
|
37
|
+
return [];
|
|
38
|
+
};
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
buildDictionary
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/declaration_file_to_dictionary/index.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { buildI18nDictionary } from './i18n_dictionary/index';\nimport { buildIntlayerDictionary } from './intlayer_dictionary/index';\n\nconst {\n content: { dictionaryOutput },\n} = getConfiguration();\n\nexport const buildDictionary = async (\n contentDeclarationsPaths: string | string[]\n): Promise<string[]> => {\n if (dictionaryOutput.includes('i18next')) {\n return await buildI18nDictionary(contentDeclarationsPaths);\n }\n\n if (dictionaryOutput.includes('intlayer')) {\n return await buildIntlayerDictionary(contentDeclarationsPaths);\n }\n\n return [];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AACjC,6BAAoC;AACpC,iCAAwC;AAExC,MAAM;AAAA,EACJ,SAAS,EAAE,iBAAiB;AAC9B,QAAI,gCAAiB;AAEd,MAAM,kBAAkB,OAC7B,6BACsB;AACtB,MAAI,iBAAiB,SAAS,SAAS,GAAG;AACxC,WAAO,UAAM,4CAAoB,wBAAwB;AAAA,EAC3D;AAEA,MAAI,iBAAiB,SAAS,UAAU,GAAG;AACzC,WAAO,UAAM,oDAAwB,wBAAwB;AAAA,EAC/D;AAEA,SAAO,CAAC;AACV;","names":[]}
|
|
@@ -16,19 +16,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var buildIntlayerDictionary_exports = {};
|
|
20
|
+
__export(buildIntlayerDictionary_exports, {
|
|
21
|
+
buildIntlayerDictionary: () => buildIntlayerDictionary
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(buildIntlayerDictionary_exports);
|
|
24
24
|
var import_promises = require("fs/promises");
|
|
25
25
|
var import_path = require("path");
|
|
26
26
|
var import_config = require("@intlayer/config");
|
|
27
27
|
var import_extractNestedJSON = require('./extractNestedJSON.cjs');
|
|
28
|
-
var
|
|
28
|
+
var import_processContentDeclaration = require('./processContentDeclaration.cjs');
|
|
29
29
|
const { content } = (0, import_config.getConfiguration)();
|
|
30
30
|
const { dictionariesDir } = content;
|
|
31
|
-
const
|
|
31
|
+
const writeDictionary = async (dictionaries) => {
|
|
32
32
|
const resultDictionariesPaths = [];
|
|
33
33
|
for await (const content2 of dictionaries) {
|
|
34
34
|
const contentString = JSON.stringify(content2);
|
|
@@ -42,25 +42,25 @@ const buildDictionary = async (dictionaries) => {
|
|
|
42
42
|
}
|
|
43
43
|
return resultDictionariesPaths;
|
|
44
44
|
};
|
|
45
|
-
const
|
|
45
|
+
const buildIntlayerDictionary = async (contentDeclarationsPaths) => {
|
|
46
46
|
const resultDictionariesPaths = [];
|
|
47
47
|
if (typeof contentDeclarationsPaths === "string") {
|
|
48
48
|
contentDeclarationsPaths = [contentDeclarationsPaths];
|
|
49
49
|
}
|
|
50
50
|
await (0, import_promises.mkdir)((0, import_path.resolve)(dictionariesDir), { recursive: true });
|
|
51
51
|
for await (const contentDeclarationPath of contentDeclarationsPaths) {
|
|
52
|
-
const result = await (0,
|
|
52
|
+
const result = await (0, import_processContentDeclaration.processContentDeclaration)(contentDeclarationPath);
|
|
53
53
|
if (!result) {
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
56
56
|
const nestedContent = (0, import_extractNestedJSON.extractObjectsWithId)(result);
|
|
57
|
-
const dictionariesPaths = await
|
|
57
|
+
const dictionariesPaths = await writeDictionary(nestedContent);
|
|
58
58
|
resultDictionariesPaths.push(...dictionariesPaths);
|
|
59
59
|
}
|
|
60
60
|
return resultDictionariesPaths;
|
|
61
61
|
};
|
|
62
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
63
63
|
0 && (module.exports = {
|
|
64
|
-
|
|
64
|
+
buildIntlayerDictionary
|
|
65
65
|
});
|
|
66
|
-
//# sourceMappingURL=
|
|
66
|
+
//# sourceMappingURL=buildIntlayerDictionary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/buildIntlayerDictionary.ts"],"sourcesContent":["import { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { ContentModule } from '@intlayer/core';\nimport { extractObjectsWithId } from './extractNestedJSON';\nimport { processContentDeclaration } from './processContentDeclaration';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir } = content;\n\nconst writeDictionary = async (dictionaries: ContentModule[]) => {\n const resultDictionariesPaths: string[] = [];\n\n for await (const content of dictionaries) {\n const contentString = JSON.stringify(content);\n\n const id = content.id;\n const outputFileName = `${id}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n\n return resultDictionariesPaths;\n};\n\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const buildIntlayerDictionary = async (\n contentDeclarationsPaths: string[] | string\n) => {\n const resultDictionariesPaths: string[] = [];\n\n if (typeof contentDeclarationsPaths === 'string') {\n contentDeclarationsPaths = [contentDeclarationsPaths];\n }\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n for await (const contentDeclarationPath of contentDeclarationsPaths) {\n const result = await processContentDeclaration(contentDeclarationPath);\n\n if (!result) {\n continue;\n }\n\n const nestedContent: ContentModule[] = extractObjectsWithId(result);\n\n const dictionariesPaths: string[] = await writeDictionary(nestedContent);\n\n resultDictionariesPaths.push(...dictionariesPaths);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAiC;AACjC,kBAAwB;AACxB,oBAAiC;AAEjC,+BAAqC;AACrC,uCAA0C;AAE1C,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,gBAAgB,IAAI;AAE5B,MAAM,kBAAkB,OAAO,iBAAkC;AAC/D,QAAM,0BAAoC,CAAC;AAE3C,mBAAiBA,YAAW,cAAc;AACxC,UAAM,gBAAgB,KAAK,UAAUA,QAAO;AAE5C,UAAM,KAAKA,SAAQ;AACnB,UAAM,iBAAiB,GAAG,EAAE;AAC5B,UAAM,qBAAiB,qBAAQ,iBAAiB,cAAc;AAG9D,cAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,IACxD,CAAC;AAED,4BAAwB,KAAK,cAAc;AAAA,EAC7C;AAEA,SAAO;AACT;AAKO,MAAM,0BAA0B,OACrC,6BACG;AACH,QAAM,0BAAoC,CAAC;AAE3C,MAAI,OAAO,6BAA6B,UAAU;AAChD,+BAA2B,CAAC,wBAAwB;AAAA,EACtD;AAGA,YAAM,2BAAM,qBAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,mBAAiB,0BAA0B,0BAA0B;AACnE,UAAM,SAAS,UAAM,4DAA0B,sBAAsB;AAErE,QAAI,CAAC,QAAQ;AACX;AAAA,IACF;AAEA,UAAM,oBAAiC,+CAAqB,MAAM;AAElE,UAAM,oBAA8B,MAAM,gBAAgB,aAAa;AAEvE,4BAAwB,KAAK,GAAG,iBAAiB;AAAA,EACnD;AAEA,SAAO;AACT;","names":["content"]}
|
|
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(extractNestedJSON_exports);
|
|
|
24
24
|
const extractObjectsWithId = (input) => {
|
|
25
25
|
const search = (obj, results2) => {
|
|
26
26
|
if (obj && typeof obj === "object") {
|
|
27
|
-
if (Object.
|
|
27
|
+
if (Object.hasOwn(obj, "id")) {
|
|
28
28
|
results2.push(obj);
|
|
29
29
|
}
|
|
30
30
|
for (const key of Object.keys(obj)) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/extractNestedJSON.ts"],"sourcesContent":["import type { Content, ContentModule } from '@intlayer/core';\n\n/**\n *\n * This function extracts all nested objects with an 'id' field from the input object and returns them as an array\n *\n * Example:\n *\n * const input = {\n * id: '1',\n * name: 'John Doe',\n * address: {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * state: 'IL'\n * },\n * };\n * const result = extractObjectsWithId(input);\n * console.log(result);\n *\n * Output:\n *\n * [{\n * id: '1',\n * name: 'John Doe',\n * address: {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * state: 'IL'\n * }\n * },\n * {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * state: 'IL'\n * }]\n *\n */\nexport const extractObjectsWithId = (input: ContentModule): ContentModule[] => {\n // Function to recursively search and extract nested objects with an 'id'\n const search = (obj: Content, results: ContentModule[]): void => {\n if (obj && typeof obj === 'object') {\n if (Object.hasOwn(obj, 'id')) {\n results.push(obj as ContentModule);\n }\n for (const key of Object.keys(obj)) {\n if (typeof obj[key] === 'object') {\n search(obj[key] as Content, results);\n }\n }\n }\n };\n\n const results: ContentModule[] = [];\n search(input, results);\n return results;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCO,MAAM,uBAAuB,CAAC,UAA0C;AAE7E,QAAM,SAAS,CAAC,KAAcA,aAAmC;AAC/D,QAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,UAAI,OAAO,OAAO,KAAK,IAAI,GAAG;AAC5B,QAAAA,SAAQ,KAAK,GAAoB;AAAA,MACnC;AACA,iBAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,YAAI,OAAO,IAAI,GAAG,MAAM,UAAU;AAChC,iBAAO,IAAI,GAAG,GAAcA,QAAO;AAAA,QACrC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAA2B,CAAC;AAClC,SAAO,OAAO,OAAO;AACrB,SAAO;AACT;","names":["results"]}
|
|
@@ -13,15 +13,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
13
13
|
};
|
|
14
14
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var
|
|
17
|
-
module.exports = __toCommonJS(
|
|
18
|
-
__reExport(
|
|
19
|
-
__reExport(
|
|
20
|
-
__reExport(
|
|
16
|
+
var intlayer_dictionary_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(intlayer_dictionary_exports);
|
|
18
|
+
__reExport(intlayer_dictionary_exports, require('./extractNestedJSON.cjs'), module.exports);
|
|
19
|
+
__reExport(intlayer_dictionary_exports, require('./processContentDeclaration.cjs'), module.exports);
|
|
20
|
+
__reExport(intlayer_dictionary_exports, require('./buildIntlayerDictionary.cjs'), module.exports);
|
|
21
21
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22
22
|
0 && (module.exports = {
|
|
23
23
|
...require('./extractNestedJSON.cjs'),
|
|
24
|
-
...require('./
|
|
25
|
-
...require('./
|
|
24
|
+
...require('./processContentDeclaration.cjs'),
|
|
25
|
+
...require('./buildIntlayerDictionary.cjs')
|
|
26
26
|
});
|
|
27
27
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/index.ts"],"sourcesContent":["export * from './extractNestedJSON';\nexport * from './processContentDeclaration';\nexport * from './buildIntlayerDictionary';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wCAAc,gCAAd;AACA,wCAAc,wCADd;AAEA,wCAAc,sCAFd;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/loadContentDeclaration.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { createRequire } from 'module';\nimport { type Context, runInNewContext } from 'vm';\nimport type { ContentModule } from '@intlayer/core';\nimport { type BuildOptions, buildSync, type BuildResult } from 'esbuild';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst sandboxContext: Context = {\n exports: {\n default: {},\n },\n module: {\n exports: {},\n },\n console,\n require: isESModule ? createRequire(import.meta.url) : require,\n};\n\nconst transformationOption: BuildOptions = {\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n },\n format: 'cjs', // Output format as commonjs\n target: 'es2017',\n packages: 'external',\n write: false,\n bundle: true,\n};\n\nconst filterValidContentDeclaration = (\n contentDeclaration: ContentModule\n): ContentModule => {\n // @TODO Implement filtering of valid content declaration\n return contentDeclaration;\n};\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadContentDeclaration = (\n contentDeclarationFilePath: string\n): ContentModule | undefined => {\n let contentDeclaration: ContentModule | undefined = undefined;\n\n const fileExtension = contentDeclarationFilePath.split('.').pop() ?? '';\n\n try {\n if (fileExtension === 'json') {\n // Assume JSON\n return require(contentDeclarationFilePath);\n }\n\n // Rest is JS, MJS or TS\n\n const moduleResult: BuildResult = buildSync({\n entryPoints: [contentDeclarationFilePath],\n\n ...transformationOption,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n if (!moduleResultString) {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n runInNewContext(moduleResultString, sandboxContext);\n\n if (\n sandboxContext.exports.default &&\n Object.keys(sandboxContext.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.exports.default;\n } else if (\n sandboxContext.module.exports.defaults &&\n Object.keys(sandboxContext.module.exports.defaults).length > 0\n ) {\n // CommonJS\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports.default &&\n Object.keys(sandboxContext.module.exports.default).length > 0\n ) {\n // ES Module\n contentDeclaration = sandboxContext.module.exports.default;\n } else if (\n sandboxContext.module.exports &&\n Object.keys(sandboxContext.module.exports).length > 0\n ) {\n // Other\n contentDeclaration = sandboxContext.module.exports;\n }\n\n if (typeof contentDeclaration === 'undefined') {\n console.error('Configuration file could not be loaded.');\n return undefined;\n }\n\n return filterValidContentDeclaration(contentDeclaration);\n } catch (error) {\n console.error('Error:', error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA8B;AAC9B,gBAA8C;AAE9C,qBAA+D;AAJ/D;AAMA,MAAM,aAAa,OAAO,YAAY,QAAQ;AAE9C,MAAM,iBAA0B;AAAA,EAC9B,SAAS;AAAA,IACP,SAAS,CAAC;AAAA,EACZ;AAAA,EACA,QAAQ;AAAA,IACN,SAAS,CAAC;AAAA,EACZ;AAAA,EACA;AAAA,EACA,SAAS,iBAAa,6BAAc,YAAY,GAAG,IAAI;AACzD;AAEA,MAAM,uBAAqC;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AAAA,EACA,QAAQ;AAAA;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AACV;AAEA,MAAM,gCAAgC,CACpC,uBACkB;AAElB,SAAO;AACT;AAOO,MAAM,yBAAyB,CACpC,+BAC8B;AAC9B,MAAI,qBAAgD;AAEpD,QAAM,gBAAgB,2BAA2B,MAAM,GAAG,EAAE,IAAI,KAAK;AAErE,MAAI;AACF,QAAI,kBAAkB,QAAQ;AAE5B,aAAO,QAAQ,0BAA0B;AAAA,IAC3C;AAIA,UAAM,mBAA4B,0BAAU;AAAA,MAC1C,aAAa,CAAC,0BAA0B;AAAA,MAExC,GAAG;AAAA,IACL,CAAC;AAED,UAAM,qBAAqB,aAAa,cAAc,CAAC,EAAE;AAEzD,QAAI,CAAC,oBAAoB;AACvB,cAAQ,MAAM,yCAAyC;AACvD,aAAO;AAAA,IACT;AAEA,mCAAgB,oBAAoB,cAAc;AAElD,QACE,eAAe,QAAQ,WACvB,OAAO,KAAK,eAAe,QAAQ,OAAO,EAAE,SAAS,GACrD;AAEA,2BAAqB,eAAe,QAAQ;AAAA,IAC9C,WACE,eAAe,OAAO,QAAQ,YAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,QAAQ,EAAE,SAAS,GAC7D;AAEA,2BAAqB,eAAe,OAAO,QAAQ;AAAA,IACrD,WACE,eAAe,OAAO,QAAQ,WAC9B,OAAO,KAAK,eAAe,OAAO,QAAQ,OAAO,EAAE,SAAS,GAC5D;AAEA,2BAAqB,eAAe,OAAO,QAAQ;AAAA,IACrD,WACE,eAAe,OAAO,WACtB,OAAO,KAAK,eAAe,OAAO,OAAO,EAAE,SAAS,GACpD;AAEA,2BAAqB,eAAe,OAAO;AAAA,IAC7C;AAEA,QAAI,OAAO,uBAAuB,aAAa;AAC7C,cAAQ,MAAM,yCAAyC;AACvD,aAAO;AAAA,IACT;AAEA,WAAO,8BAA8B,kBAAkB;AAAA,EACzD,SAAS,OAAO;AACd,YAAQ,MAAM,UAAU,KAAK;AAAA,EAC/B;AACF;","names":[]}
|
|
@@ -16,11 +16,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var processContentDeclaration_exports = {};
|
|
20
|
+
__export(processContentDeclaration_exports, {
|
|
21
21
|
processContentDeclaration: () => processContentDeclaration
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(processContentDeclaration_exports);
|
|
24
24
|
var import_path = require("path");
|
|
25
25
|
var import_loadContentDeclaration = require('./loadContentDeclaration.cjs');
|
|
26
26
|
const processFunctionResults = async (entry) => {
|
|
@@ -33,8 +33,7 @@ const processFunctionResults = async (entry) => {
|
|
|
33
33
|
result[key] = await processFunctionResults(
|
|
34
34
|
field
|
|
35
35
|
);
|
|
36
|
-
}
|
|
37
|
-
if (typeof field === "function") {
|
|
36
|
+
} else if (typeof field === "function") {
|
|
38
37
|
const promise = (async () => {
|
|
39
38
|
const value = await field();
|
|
40
39
|
result[key] = value;
|
|
@@ -66,4 +65,4 @@ const processContentDeclaration = async (file) => {
|
|
|
66
65
|
0 && (module.exports = {
|
|
67
66
|
processContentDeclaration
|
|
68
67
|
});
|
|
69
|
-
//# sourceMappingURL=
|
|
68
|
+
//# sourceMappingURL=processContentDeclaration.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/processContentDeclaration.ts"],"sourcesContent":["import { resolve } from 'path';\nimport type {\n Content,\n ContentModule,\n FlatContent,\n FlatContentValue,\n} from '@intlayer/core';\nimport { loadContentDeclaration } from './loadContentDeclaration';\n\n/**\n * Function to replace function and async function fields with their results in the object\n */\nconst processFunctionResults = async (entry: Content): Promise<FlatContent> => {\n if (entry && typeof entry === 'object') {\n const promises: Promise<void>[] = [];\n const result: FlatContent = {};\n\n for (const key of Object.keys(entry)) {\n const field = entry?.[key];\n\n if (typeof field === 'object') {\n result[key] = (await processFunctionResults(\n field as Content\n )) as FlatContentValue;\n } else if (typeof field === 'function') {\n // Wait for the function to resolve if it's an async function\n const promise = (async () => {\n // Execute the function and await the result if it's a Promise\n const value = await field();\n\n result[key] = value as FlatContentValue;\n })();\n promises.push(promise);\n } else {\n result[key] = field as FlatContentValue;\n }\n }\n\n // Wait for all async operations to complete\n await Promise.all(promises);\n\n return result;\n }\n\n return entry;\n};\n\n/**\n * Function to load, process the module and return the Intlayer ContentModule from the module file\n */\nexport const processContentDeclaration = async (file: string) => {\n try {\n const functionPath = resolve(file);\n const entry = loadContentDeclaration(functionPath);\n\n if (!entry) {\n console.error('No entry found in module:', functionPath);\n return;\n }\n\n return (await processFunctionResults(entry)) as ContentModule;\n } catch (error) {\n console.error('Error processing module:', error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwB;AAOxB,oCAAuC;AAKvC,MAAM,yBAAyB,OAAO,UAAyC;AAC7E,MAAI,SAAS,OAAO,UAAU,UAAU;AACtC,UAAM,WAA4B,CAAC;AACnC,UAAM,SAAsB,CAAC;AAE7B,eAAW,OAAO,OAAO,KAAK,KAAK,GAAG;AACpC,YAAM,QAAQ,QAAQ,GAAG;AAEzB,UAAI,OAAO,UAAU,UAAU;AAC7B,eAAO,GAAG,IAAK,MAAM;AAAA,UACnB;AAAA,QACF;AAAA,MACF,WAAW,OAAO,UAAU,YAAY;AAEtC,cAAM,WAAW,YAAY;AAE3B,gBAAM,QAAQ,MAAM,MAAM;AAE1B,iBAAO,GAAG,IAAI;AAAA,QAChB,GAAG;AACH,iBAAS,KAAK,OAAO;AAAA,MACvB,OAAO;AACL,eAAO,GAAG,IAAI;AAAA,MAChB;AAAA,IACF;AAGA,UAAM,QAAQ,IAAI,QAAQ;AAE1B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAKO,MAAM,4BAA4B,OAAO,SAAiB;AAC/D,MAAI;AACF,UAAM,mBAAe,qBAAQ,IAAI;AACjC,UAAM,YAAQ,sDAAuB,YAAY;AAEjD,QAAI,CAAC,OAAO;AACV,cAAQ,MAAM,6BAA6B,YAAY;AACvD;AAAA,IACF;AAEA,WAAQ,MAAM,uBAAuB,KAAK;AAAA,EAC5C,SAAS,OAAO;AACd,YAAQ,MAAM,4BAA4B,KAAK;AAAA,EACjD;AACF;","names":[]}
|