@intlayer/webpack 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/getEntries.cjs +41 -0
- package/dist/cjs/getEntries.cjs.map +1 -0
- package/dist/cjs/getEntries.d.ts +5 -0
- package/dist/cjs/index.cjs +12 -24
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/utils.cjs +32 -31
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.ts +7 -0
- package/dist/cjs/webpack-plugin.cjs +12 -161
- package/dist/cjs/webpack-plugin.cjs.map +1 -1
- package/dist/cjs/webpack-plugin.d.ts +5 -0
- package/dist/cjs/webpack.config.cjs +53 -63
- package/dist/cjs/webpack.config.cjs.map +1 -1
- package/dist/cjs/webpack.config.d.ts +7 -0
- package/dist/esm/getEntries.d.mts +5 -0
- package/dist/esm/getEntries.mjs +17 -0
- package/dist/esm/getEntries.mjs.map +1 -0
- package/dist/esm/index.d.mts +4 -9
- package/dist/esm/index.mjs +4 -8
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/utils.d.mts +5 -2
- package/dist/esm/utils.mjs +15 -17
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/esm/webpack-plugin.d.mts +1 -11
- package/dist/esm/webpack-plugin.mjs +8 -142
- package/dist/esm/webpack-plugin.mjs.map +1 -1
- package/dist/esm/webpack.config.d.mts +2 -2
- package/dist/esm/webpack.config.mjs +48 -39
- package/dist/esm/webpack.config.mjs.map +1 -1
- package/package.json +14 -18
- package/src/getEntries.ts +19 -0
- package/src/index.ts +2 -12
- package/src/utils.ts +19 -19
- package/src/webpack-plugin.ts +5 -180
- package/src/webpack.config.ts +32 -28
- package/dist/cjs/scripts/bundle.cjs +0 -68
- package/dist/cjs/scripts/bundle.cjs.map +0 -1
- package/dist/cjs/scripts/index.cjs +0 -33
- package/dist/cjs/scripts/index.cjs.map +0 -1
- package/dist/cjs/scripts/startServer.cjs +0 -44
- package/dist/cjs/scripts/startServer.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +0 -92
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs +0 -35
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +0 -83
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +0 -122
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs +0 -41
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs +0 -50
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs +0 -47
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs +0 -70
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs +0 -112
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs.map +0 -1
- package/dist/esm/scripts/bundle.d.mts +0 -7
- package/dist/esm/scripts/bundle.mjs +0 -35
- package/dist/esm/scripts/bundle.mjs.map +0 -1
- package/dist/esm/scripts/index.d.mts +0 -3
- package/dist/esm/scripts/index.mjs +0 -3
- package/dist/esm/scripts/index.mjs.map +0 -1
- package/dist/esm/scripts/startServer.d.mts +0 -5
- package/dist/esm/scripts/startServer.mjs +0 -10
- package/dist/esm/scripts/startServer.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.d.mts +0 -6
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +0 -52
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_main/index.d.mts +0 -1
- package/dist/esm/transpiler/dictionary_to_main/index.mjs +0 -2
- package/dist/esm/transpiler/dictionary_to_main/index.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.d.mts +0 -7
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +0 -43
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +0 -42
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +0 -84
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_type/index.d.mts +0 -10
- package/dist/esm/transpiler/dictionary_to_type/index.mjs +0 -3
- package/dist/esm/transpiler/dictionary_to_type/index.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.mts +0 -44
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs +0 -19
- 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/processModule.d.mts +0 -10
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs +0 -39
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.mts +0 -8
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs +0 -70
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs.map +0 -1
- package/src/scripts/bundle.ts +0 -44
- package/src/scripts/index.ts +0 -2
- package/src/scripts/startServer.ts +0 -14
- package/src/transpiler/dictionary_to_main/createDictionaryList.ts +0 -65
- package/src/transpiler/dictionary_to_main/index.ts +0 -1
- package/src/transpiler/dictionary_to_type/createModuleAugmentation.ts +0 -70
- package/src/transpiler/dictionary_to_type/createType.ts +0 -140
- package/src/transpiler/dictionary_to_type/index.ts +0 -2
- package/src/transpiler/intlater_module_to_dictionary/extractNestedJSON.ts +0 -60
- package/src/transpiler/intlater_module_to_dictionary/index.ts +0 -3
- package/src/transpiler/intlater_module_to_dictionary/processModule.ts +0 -69
- package/src/transpiler/intlater_module_to_dictionary/transpileBundledCode.ts +0 -107
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
15
|
-
get: () => from[key],
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var createDictionaryList_exports = {};
|
|
24
|
-
__export(createDictionaryList_exports, {
|
|
25
|
-
createDictionaryList: () => createDictionaryList,
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(createDictionaryList_exports);
|
|
28
|
-
var import_fs = require("fs");
|
|
29
|
-
var import_path = require("path");
|
|
30
|
-
var import_config = require("@intlayer/config");
|
|
31
|
-
var import_glob = require("glob");
|
|
32
|
-
var import_utils = require("../../utils.cjs");
|
|
33
|
-
const { content } = (0, import_config.getConfiguration)();
|
|
34
|
-
const { dictionariesDir, mainDir } = content;
|
|
35
|
-
const generateDictionaryListContent = (dictionaries, format = "esm") => {
|
|
36
|
-
let content2 = "";
|
|
37
|
-
const dictionariesRef = dictionaries.map((dictionaryPath) => ({
|
|
38
|
-
relativePath: (0, import_path.relative)(mainDir, dictionaryPath),
|
|
39
|
-
id: (0, import_path.basename)(
|
|
40
|
-
dictionaryPath,
|
|
41
|
-
(0, import_path.extname)(dictionaryPath)
|
|
42
|
-
),
|
|
43
|
-
// Get the base name as the dictionary id
|
|
44
|
-
hash: `_${(0, import_utils.getFileHash)(dictionaryPath)}`,
|
|
45
|
-
// Get the hash of the dictionary to avoid conflicts
|
|
46
|
-
}));
|
|
47
|
-
dictionariesRef.forEach((dictionary) => {
|
|
48
|
-
if (format === "esm")
|
|
49
|
-
content2 += `import ${dictionary.hash} from '${dictionary.relativePath}';
|
|
50
|
-
`;
|
|
51
|
-
if (format === "cjs")
|
|
52
|
-
content2 += `const ${dictionary.hash} = require('${dictionary.relativePath}');
|
|
53
|
-
`;
|
|
54
|
-
});
|
|
55
|
-
content2 += "\n";
|
|
56
|
-
const formattedDictionaryMap = dictionariesRef
|
|
57
|
-
.map((dictionary) => `"${dictionary.id}": ${dictionary.hash}`)
|
|
58
|
-
.join(",\n");
|
|
59
|
-
if (format === "esm")
|
|
60
|
-
content2 += `export default {
|
|
61
|
-
${formattedDictionaryMap}
|
|
62
|
-
};
|
|
63
|
-
`;
|
|
64
|
-
if (format === "cjs")
|
|
65
|
-
content2 += `module.exports = {
|
|
66
|
-
${formattedDictionaryMap}
|
|
67
|
-
};
|
|
68
|
-
`;
|
|
69
|
-
return content2;
|
|
70
|
-
};
|
|
71
|
-
const createDictionaryList = () => {
|
|
72
|
-
if (!(0, import_fs.existsSync)(mainDir)) {
|
|
73
|
-
(0, import_fs.mkdirSync)(mainDir, { recursive: true });
|
|
74
|
-
}
|
|
75
|
-
const dictionaries = (0, import_glob.sync)(`${dictionariesDir}/**/*.json`);
|
|
76
|
-
const cjsContent = generateDictionaryListContent(dictionaries, "cjs");
|
|
77
|
-
(0, import_fs.writeFileSync)(
|
|
78
|
-
(0, import_path.resolve)(mainDir, "dictionaries.cjs"),
|
|
79
|
-
cjsContent
|
|
80
|
-
);
|
|
81
|
-
const esmContent = generateDictionaryListContent(dictionaries, "esm");
|
|
82
|
-
(0, import_fs.writeFileSync)(
|
|
83
|
-
(0, import_path.resolve)(mainDir, "dictionaries.mjs"),
|
|
84
|
-
esmContent
|
|
85
|
-
);
|
|
86
|
-
};
|
|
87
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
-
0 &&
|
|
89
|
-
(module.exports = {
|
|
90
|
-
createDictionaryList,
|
|
91
|
-
});
|
|
92
|
-
//# sourceMappingURL=createDictionaryList.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryList.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, relative, resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport { sync } from 'glob';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir, mainDir } = content;\n\n/**\n * This function generates the content of the dictionary list file\n */\nconst generateDictionaryListContent = (\n dictionaries: string[],\n format: 'cjs' | 'esm' = 'esm'\n): string => {\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: relative(mainDir, dictionaryPath),\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => `\"${dictionary.id}\": ${dictionary.hash}`)\n .join(',\\n');\n\n if (format === 'esm')\n content += `export default {\\n${formattedDictionaryMap}\\n};\\n`;\n if (format === 'cjs')\n content += `module.exports = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n return content;\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryList = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionaries: string[] = sync(`${dictionariesDir}/**/*.json`);\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionaries, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionaries, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAqD;AACrD,oBAAiC;AACjC,kBAAqB;AACrB,mBAA4B;AAE5B,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,iBAAiB,QAAQ,IAAI;AAKrC,MAAM,gCAAgC,CACpC,cACA,SAAwB,UACb;AACX,MAAIA,WAAU;AAEd,QAAM,kBAAkB,aAAa,IAAI,CAAC,oBAAoB;AAAA,IAC5D,kBAAc,sBAAS,SAAS,cAAc;AAAA,IAC9C,QAAI,sBAAS,oBAAgB,qBAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,QAAI,0BAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,QAAI,WAAW;AACb,MAAAA,YAAW,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AACvE,QAAI,WAAW;AACb,MAAAA,YAAW,SAAS,WAAW,IAAI,eAAe,WAAW,YAAY;AAAA;AAAA,EAC7E,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,IAAI,WAAW,EAAE,MAAM,WAAW,IAAI,EAAE,EAC5D,KAAK,KAAK;AAEb,MAAI,WAAW;AACb,IAAAA,YAAW;AAAA,EAAqB,sBAAsB;AAAA;AAAA;AACxD,MAAI,WAAW;AACb,IAAAA,YAAW;AAAA,EAAuB,sBAAsB;AAAA;AAAA;AAE1D,SAAOA;AACT;AAKO,MAAM,uBAAuB,MAAM;AAExC,MAAI,KAAC,sBAAW,OAAO,GAAG;AACxB,6BAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAAyB,kBAAK,GAAG,eAAe,YAAY;AAGlE,QAAM,aAAa,8BAA8B,cAAc,KAAK;AACpE,mCAAc,qBAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa,8BAA8B,cAAc,KAAK;AACpE,mCAAc,qBAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __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, {
|
|
11
|
-
get: () => from[key],
|
|
12
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __reExport = (target, mod, secondTarget) => (
|
|
18
|
-
__copyProps(target, mod, "default"),
|
|
19
|
-
secondTarget && __copyProps(secondTarget, mod, "default")
|
|
20
|
-
);
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var dictionary_to_main_exports = {};
|
|
24
|
-
module.exports = __toCommonJS(dictionary_to_main_exports);
|
|
25
|
-
__reExport(
|
|
26
|
-
dictionary_to_main_exports,
|
|
27
|
-
require("./createDictionaryList.cjs"),
|
|
28
|
-
module.exports
|
|
29
|
-
);
|
|
30
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
-
0 &&
|
|
32
|
-
(module.exports = {
|
|
33
|
-
...require("./createDictionaryList.cjs"),
|
|
34
|
-
});
|
|
35
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/index.ts"],"sourcesContent":["export * from './createDictionaryList';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uCAAc,mCAAd;","names":[]}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
15
|
-
get: () => from[key],
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var createModuleAugmentation_exports = {};
|
|
24
|
-
__export(createModuleAugmentation_exports, {
|
|
25
|
-
createModuleAugmentation: () => createModuleAugmentation,
|
|
26
|
-
getTypeName: () => getTypeName,
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(createModuleAugmentation_exports);
|
|
29
|
-
var import_fs = require("fs");
|
|
30
|
-
var import_path = require("path");
|
|
31
|
-
var import_config = require("@intlayer/config");
|
|
32
|
-
var import_glob = require("glob");
|
|
33
|
-
var import_utils = require("../../utils.cjs");
|
|
34
|
-
const { content } = (0, import_config.getConfiguration)();
|
|
35
|
-
const { typesDir, moduleAugmentationDir } = content;
|
|
36
|
-
const getTypeName = (id) =>
|
|
37
|
-
(0, import_utils.transformToCamelCase)(`${id}Content`);
|
|
38
|
-
const generateTypeIndexContent = (typeFiles) => {
|
|
39
|
-
let content2 = "import 'intlayer';\n\n";
|
|
40
|
-
const dictionariesRef = typeFiles.map((dictionaryPath) => ({
|
|
41
|
-
relativePath: (0, import_path.relative)(
|
|
42
|
-
moduleAugmentationDir,
|
|
43
|
-
dictionaryPath
|
|
44
|
-
),
|
|
45
|
-
id: (0, import_path.basename)(dictionaryPath, ".d.ts"),
|
|
46
|
-
// Get the base name as the dictionary id
|
|
47
|
-
hash: `_${(0, import_utils.getFileHash)(dictionaryPath)}`,
|
|
48
|
-
// Get the hash of the dictionary to avoid conflicts
|
|
49
|
-
}));
|
|
50
|
-
dictionariesRef.forEach((dictionary) => {
|
|
51
|
-
const typeName = getTypeName(dictionary.id);
|
|
52
|
-
content2 += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';
|
|
53
|
-
`;
|
|
54
|
-
});
|
|
55
|
-
content2 += "\n";
|
|
56
|
-
const formattedDictionaryMap = dictionariesRef
|
|
57
|
-
.map((dictionary) => ` "${dictionary.id}": ${dictionary.hash};`)
|
|
58
|
-
.join("\n");
|
|
59
|
-
content2 += `declare module 'intlayer' {
|
|
60
|
-
interface IntlayerDictionaryTypesConnector {
|
|
61
|
-
${formattedDictionaryMap}
|
|
62
|
-
};
|
|
63
|
-
};`;
|
|
64
|
-
return content2;
|
|
65
|
-
};
|
|
66
|
-
const createModuleAugmentation = () => {
|
|
67
|
-
if (!(0, import_fs.existsSync)(moduleAugmentationDir)) {
|
|
68
|
-
(0, import_fs.mkdirSync)(moduleAugmentationDir, { recursive: true });
|
|
69
|
-
}
|
|
70
|
-
const dictionaries = (0, import_glob.sync)(`${typesDir}/**/*.d.ts`);
|
|
71
|
-
const tsContent = generateTypeIndexContent(dictionaries);
|
|
72
|
-
(0, import_fs.writeFileSync)(
|
|
73
|
-
(0, import_path.join)(moduleAugmentationDir, "intlayer.d.ts"),
|
|
74
|
-
tsContent
|
|
75
|
-
);
|
|
76
|
-
};
|
|
77
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
-
0 &&
|
|
79
|
-
(module.exports = {
|
|
80
|
-
createModuleAugmentation,
|
|
81
|
-
getTypeName,
|
|
82
|
-
});
|
|
83
|
-
//# sourceMappingURL=createModuleAugmentation.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, join, relative } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport { sync } from 'glob';\nimport { getFileHash, transformToCamelCase } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { typesDir, moduleAugmentationDir } = content;\n\nexport const getTypeName = (id: string): string =>\n transformToCamelCase(`${id}Content`);\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"import 'intlayer';\\n\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: relative(moduleAugmentationDir, dictionaryPath),\n id: basename(dictionaryPath, '.d.ts'), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n const typeName = getTypeName(dictionary.id);\n content += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash};`)\n .join('\\n');\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n };\\n};`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionaries: string[] = sync(`${typesDir}/**/*.d.ts`);\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionaries);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAyC;AACzC,oBAAiC;AACjC,kBAAqB;AACrB,mBAAkD;AAElD,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAErC,MAAM,cAAc,CAAC,WAC1B,mCAAqB,GAAG,EAAE,SAAS;AAKrC,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WAAU;AAEd,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,kBAAc,sBAAS,uBAAuB,cAAc;AAAA,IAC5D,QAAI,sBAAS,gBAAgB,OAAO;AAAA;AAAA,IACpC,MAAM,QAAI,0BAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,UAAM,WAAW,YAAY,WAAW,EAAE;AAC1C,IAAAA,YAAW,iBAAiB,QAAQ,OAAO,WAAW,IAAI,YAAY,WAAW,YAAY;AAAA;AAAA,EAC/F,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,MAAM,WAAW,IAAI,GAAG,EACjE,KAAK,IAAI;AAeZ,EAAAA,YAAW;AAAA;AAAA,EAAgF,sBAAsB;AAAA;AAAA;AAEjH,SAAOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,KAAC,sBAAW,qBAAqB,GAAG;AACtC,6BAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,mBAAyB,kBAAK,GAAG,QAAQ,YAAY;AAG3D,QAAM,YAAY,yBAAyB,YAAY;AACvD,mCAAc,kBAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content"]}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
15
|
-
get: () => from[key],
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var createType_exports = {};
|
|
24
|
-
__export(createType_exports, {
|
|
25
|
-
createTypes: () => createTypes,
|
|
26
|
-
generateTypeScriptType: () => generateTypeScriptType,
|
|
27
|
-
generateTypeScriptTypeContent: () => generateTypeScriptTypeContent,
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(createType_exports);
|
|
30
|
-
var import_fs = require("fs");
|
|
31
|
-
var import_path = require("path");
|
|
32
|
-
var import_config = require("@intlayer/config");
|
|
33
|
-
var import_core = require("@intlayer/core");
|
|
34
|
-
var import_createModuleAugmentation = require("./createModuleAugmentation.cjs");
|
|
35
|
-
const { content, internationalization } = (0, import_config.getConfiguration)();
|
|
36
|
-
const { typesDir } = content;
|
|
37
|
-
const generateTypeScriptType = (obj) => {
|
|
38
|
-
let typeDefinition = ``;
|
|
39
|
-
const typeName = (0, import_createModuleAugmentation.getTypeName)(obj.id);
|
|
40
|
-
typeDefinition += `export type ${typeName} = {
|
|
41
|
-
`;
|
|
42
|
-
typeDefinition += generateTypeScriptTypeContent(obj);
|
|
43
|
-
typeDefinition += "};\n\n";
|
|
44
|
-
return typeDefinition;
|
|
45
|
-
};
|
|
46
|
-
const generateTypeScriptTypeContent = (obj) => {
|
|
47
|
-
let typeDefinition = ``;
|
|
48
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
49
|
-
const nodeType = value.nodeType;
|
|
50
|
-
if (
|
|
51
|
-
// Check if the value is a typed node
|
|
52
|
-
typeof value === "object" &&
|
|
53
|
-
nodeType === import_core.NodeType.Translation
|
|
54
|
-
) {
|
|
55
|
-
const tsType = typeof value[internationalization.defaultLocale];
|
|
56
|
-
typeDefinition += ` ${key}: ${tsType},
|
|
57
|
-
`;
|
|
58
|
-
} else if (
|
|
59
|
-
// Check if the value is a typed node
|
|
60
|
-
typeof value === "object" &&
|
|
61
|
-
nodeType === import_core.NodeType.Enumeration
|
|
62
|
-
) {
|
|
63
|
-
const tsType = typeof value[internationalization.defaultLocale];
|
|
64
|
-
typeDefinition += ` ${key}: (quantity: number) => ${tsType},
|
|
65
|
-
`;
|
|
66
|
-
} else if (
|
|
67
|
-
// Check if the value is a nested object
|
|
68
|
-
typeof value === "object" &&
|
|
69
|
-
!Array.isArray(value)
|
|
70
|
-
) {
|
|
71
|
-
const nestedType = generateTypeScriptTypeContent(value);
|
|
72
|
-
typeDefinition += ` ${key}: {${nestedType}},
|
|
73
|
-
`;
|
|
74
|
-
} else if (
|
|
75
|
-
// Check if the value is an array
|
|
76
|
-
Array.isArray(value)
|
|
77
|
-
) {
|
|
78
|
-
const arrayType = typeof value[0];
|
|
79
|
-
typeDefinition += ` ${key}: ${arrayType}[],
|
|
80
|
-
`;
|
|
81
|
-
} else if (
|
|
82
|
-
// Check if the value is an 'id'
|
|
83
|
-
typeof value === "string" &&
|
|
84
|
-
key === "id"
|
|
85
|
-
) {
|
|
86
|
-
const tsType = `"${value}"`;
|
|
87
|
-
typeDefinition += ` ${key}: ${tsType},
|
|
88
|
-
`;
|
|
89
|
-
} else {
|
|
90
|
-
const tsType = typeof value;
|
|
91
|
-
typeDefinition += ` ${key}: ${tsType},
|
|
92
|
-
`;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return typeDefinition;
|
|
96
|
-
};
|
|
97
|
-
const createTypes = (dictionariesPaths) => {
|
|
98
|
-
const resultTypesPaths = [];
|
|
99
|
-
if (!(0, import_fs.existsSync)(typesDir)) {
|
|
100
|
-
(0, import_fs.mkdirSync)(typesDir, { recursive: true });
|
|
101
|
-
}
|
|
102
|
-
for (const dictionaryPath of dictionariesPaths) {
|
|
103
|
-
const contentModule = require(dictionaryPath);
|
|
104
|
-
const dictionaryName = contentModule.id;
|
|
105
|
-
const typeDefinition = generateTypeScriptType(contentModule);
|
|
106
|
-
const outputPath = (0, import_path.resolve)(
|
|
107
|
-
typesDir,
|
|
108
|
-
`${dictionaryName}.d.ts`
|
|
109
|
-
);
|
|
110
|
-
(0, import_fs.writeFileSync)(outputPath, typeDefinition);
|
|
111
|
-
resultTypesPaths.push(outputPath);
|
|
112
|
-
}
|
|
113
|
-
return resultTypesPaths;
|
|
114
|
-
};
|
|
115
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
-
0 &&
|
|
117
|
-
(module.exports = {
|
|
118
|
-
createTypes,
|
|
119
|
-
generateTypeScriptType,
|
|
120
|
-
generateTypeScriptTypeContent,
|
|
121
|
-
});
|
|
122
|
-
//# sourceMappingURL=createType.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport {\n NodeType,\n type Content,\n type ContentModule,\n type TypedNode,\n} from '@intlayer/core';\nimport { getTypeName } from './createModuleAugmentation';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir } = content;\n\n/**\n *\n * This function generates a TypeScript type definition from a JSON object\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 * }\n * };\n *\n * const result = generateTypeScriptType(input, 'RootObject');\n * console.log(result);\n *\n * Output:\n *\n * type RootObject = {\n * id: '1',\n * name: string,\n * address: {\n * id: '2',\n * street: string,\n * city: string,\n * },\n * };\n *\n */\nexport const generateTypeScriptType = (obj: ContentModule): string => {\n let typeDefinition = ``;\n\n const typeName = getTypeName(obj.id);\n\n typeDefinition += `export type ${typeName} = {\\n`;\n typeDefinition += generateTypeScriptTypeContent(obj);\n typeDefinition += '};\\n\\n';\n\n return typeDefinition;\n};\n\nexport const generateTypeScriptTypeContent = (obj: Content): string => {\n let typeDefinition = ``;\n\n for (const [key, value] of Object.entries(obj)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nodeType: NodeType | undefined = (value as TypedNode).nodeType;\n\n if (\n // Check if the value is a typed node\n typeof value === 'object' &&\n nodeType === NodeType.Translation\n ) {\n const tsType =\n typeof value[internationalization.defaultLocale as keyof typeof value];\n typeDefinition += ` ${key}: ${tsType},\\n`;\n } else if (\n // Check if the value is a typed node\n typeof value === 'object' &&\n nodeType === NodeType.Enumeration\n ) {\n const tsType =\n typeof value[internationalization.defaultLocale as keyof typeof value];\n\n typeDefinition += ` ${key}: (quantity: number) => ${tsType},\\n`;\n } else if (\n // Check if the value is a nested object\n typeof value === 'object' &&\n !Array.isArray(value)\n ) {\n // Nested object, recurse\n const nestedType = generateTypeScriptTypeContent(value as Content);\n typeDefinition += ` ${key}: {${nestedType}},\\n`;\n } else if (\n // Check if the value is an array\n Array.isArray(value)\n ) {\n // Array handling (simplified, assumes non-empty arrays with uniform type)\n const arrayType = typeof value[0];\n typeDefinition += ` ${key}: ${arrayType}[],\\n`;\n } else if (\n // Check if the value is an 'id'\n typeof value === 'string' &&\n key === 'id'\n ) {\n // Special handling for 'id' field\n const tsType = `\"${value}\"`;\n typeDefinition += ` ${key}: ${tsType},\\n`;\n } else {\n // Primitive type\n const tsType = typeof value;\n typeDefinition += ` ${key}: ${tsType},\\n`;\n }\n }\n\n return typeDefinition;\n};\n\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = (dictionariesPaths: string[]): string[] => {\n const resultTypesPaths: string[] = [];\n\n // Create type folders if they don't exist\n if (!existsSync(typesDir)) {\n mkdirSync(typesDir, { recursive: true });\n }\n\n for (const dictionaryPath of dictionariesPaths) {\n const contentModule: ContentModule = require(dictionaryPath);\n const dictionaryName: string = contentModule.id;\n const typeDefinition: string = generateTypeScriptType(contentModule);\n\n const outputPath = resolve(typesDir, `${dictionaryName}.d.ts`);\n\n writeFileSync(outputPath, typeDefinition);\n\n resultTypesPaths.push(outputPath);\n }\n\n return resultTypesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAwB;AACxB,oBAAiC;AACjC,kBAKO;AACP,sCAA4B;AAE5B,MAAM,EAAE,SAAS,qBAAqB,QAAI,gCAAiB;AAC3D,MAAM,EAAE,SAAS,IAAI;AAkCd,MAAM,yBAAyB,CAAC,QAA+B;AACpE,MAAI,iBAAiB;AAErB,QAAM,eAAW,6CAAY,IAAI,EAAE;AAEnC,oBAAkB,eAAe,QAAQ;AAAA;AACzC,oBAAkB,8BAA8B,GAAG;AACnD,oBAAkB;AAElB,SAAO;AACT;AAEO,MAAM,gCAAgC,CAAC,QAAyB;AACrE,MAAI,iBAAiB;AAErB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAE9C,UAAM,WAAkC,MAAoB;AAE5D;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,aAAa,qBAAS;AAAA,MACtB;AACA,YAAM,SACJ,OAAO,MAAM,qBAAqB,aAAmC;AACvE,wBAAkB,KAAK,GAAG,KAAK,MAAM;AAAA;AAAA,IACvC;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,aAAa,qBAAS;AAAA,MACtB;AACA,YAAM,SACJ,OAAO,MAAM,qBAAqB,aAAmC;AAEvE,wBAAkB,KAAK,GAAG,2BAA2B,MAAM;AAAA;AAAA,IAC7D;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,CAAC,MAAM,QAAQ,KAAK;AAAA,MACpB;AAEA,YAAM,aAAa,8BAA8B,KAAgB;AACjE,wBAAkB,KAAK,GAAG,MAAM,UAAU;AAAA;AAAA,IAC5C;AAAA;AAAA,MAEE,MAAM,QAAQ,KAAK;AAAA,MACnB;AAEA,YAAM,YAAY,OAAO,MAAM,CAAC;AAChC,wBAAkB,KAAK,GAAG,KAAK,SAAS;AAAA;AAAA,IAC1C;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,QAAQ;AAAA,MACR;AAEA,YAAM,SAAS,IAAI,KAAK;AACxB,wBAAkB,KAAK,GAAG,KAAK,MAAM;AAAA;AAAA,IACvC,OAAO;AAEL,YAAM,SAAS,OAAO;AACtB,wBAAkB,KAAK,GAAG,KAAK,MAAM;AAAA;AAAA,IACvC;AAAA,EACF;AAEA,SAAO;AACT;AAKO,MAAM,cAAc,CAAC,sBAA0C;AACpE,QAAM,mBAA6B,CAAC;AAGpC,MAAI,KAAC,sBAAW,QAAQ,GAAG;AACzB,6BAAU,UAAU,EAAE,WAAW,KAAK,CAAC;AAAA,EACzC;AAEA,aAAW,kBAAkB,mBAAmB;AAC9C,UAAM,gBAA+B,QAAQ,cAAc;AAC3D,UAAM,iBAAyB,cAAc;AAC7C,UAAM,iBAAyB,uBAAuB,aAAa;AAEnE,UAAM,iBAAa,qBAAQ,UAAU,GAAG,cAAc,OAAO;AAE7D,iCAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __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, {
|
|
11
|
-
get: () => from[key],
|
|
12
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __reExport = (target, mod, secondTarget) => (
|
|
18
|
-
__copyProps(target, mod, "default"),
|
|
19
|
-
secondTarget && __copyProps(secondTarget, mod, "default")
|
|
20
|
-
);
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var dictionary_to_type_exports = {};
|
|
24
|
-
module.exports = __toCommonJS(dictionary_to_type_exports);
|
|
25
|
-
__reExport(
|
|
26
|
-
dictionary_to_type_exports,
|
|
27
|
-
require("./createModuleAugmentation.cjs"),
|
|
28
|
-
module.exports
|
|
29
|
-
);
|
|
30
|
-
__reExport(
|
|
31
|
-
dictionary_to_type_exports,
|
|
32
|
-
require("./createType.cjs"),
|
|
33
|
-
module.exports
|
|
34
|
-
);
|
|
35
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
-
0 &&
|
|
37
|
-
(module.exports = {
|
|
38
|
-
...require("./createModuleAugmentation.cjs"),
|
|
39
|
-
...require("./createType.cjs"),
|
|
40
|
-
});
|
|
41
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/index.ts"],"sourcesContent":["export * from './createModuleAugmentation';\nexport * from './createType';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uCAAc,uCAAd;AACA,uCAAc,yBADd;","names":[]}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
15
|
-
get: () => from[key],
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var extractNestedJSON_exports = {};
|
|
24
|
-
__export(extractNestedJSON_exports, {
|
|
25
|
-
extractObjectsWithId: () => extractObjectsWithId,
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(extractNestedJSON_exports);
|
|
28
|
-
const extractObjectsWithId = (input) => {
|
|
29
|
-
const search = (obj, results2) => {
|
|
30
|
-
if (obj && typeof obj === "object") {
|
|
31
|
-
if (Object.prototype.hasOwnProperty.call(obj, "id")) {
|
|
32
|
-
results2.push(obj);
|
|
33
|
-
}
|
|
34
|
-
for (const key of Object.keys(obj)) {
|
|
35
|
-
if (typeof obj[key] === "object") {
|
|
36
|
-
search(obj[key], results2);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const results = [];
|
|
42
|
-
search(input, results);
|
|
43
|
-
return results;
|
|
44
|
-
};
|
|
45
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
-
0 &&
|
|
47
|
-
(module.exports = {
|
|
48
|
-
extractObjectsWithId,
|
|
49
|
-
});
|
|
50
|
-
//# sourceMappingURL=extractNestedJSON.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/intlater_module_to_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.prototype.hasOwnProperty.call(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,UAAU,eAAe,KAAK,KAAK,IAAI,GAAG;AACnD,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"]}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __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, {
|
|
11
|
-
get: () => from[key],
|
|
12
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __reExport = (target, mod, secondTarget) => (
|
|
18
|
-
__copyProps(target, mod, "default"),
|
|
19
|
-
secondTarget && __copyProps(secondTarget, mod, "default")
|
|
20
|
-
);
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var intlater_module_to_dictionary_exports = {};
|
|
24
|
-
module.exports = __toCommonJS(intlater_module_to_dictionary_exports);
|
|
25
|
-
__reExport(
|
|
26
|
-
intlater_module_to_dictionary_exports,
|
|
27
|
-
require("./extractNestedJSON.cjs"),
|
|
28
|
-
module.exports
|
|
29
|
-
);
|
|
30
|
-
__reExport(
|
|
31
|
-
intlater_module_to_dictionary_exports,
|
|
32
|
-
require("./processModule.cjs"),
|
|
33
|
-
module.exports
|
|
34
|
-
);
|
|
35
|
-
__reExport(
|
|
36
|
-
intlater_module_to_dictionary_exports,
|
|
37
|
-
require("./transpileBundledCode.cjs"),
|
|
38
|
-
module.exports
|
|
39
|
-
);
|
|
40
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
-
0 &&
|
|
42
|
-
(module.exports = {
|
|
43
|
-
...require("./extractNestedJSON.cjs"),
|
|
44
|
-
...require("./processModule.cjs"),
|
|
45
|
-
...require("./transpileBundledCode.cjs"),
|
|
46
|
-
});
|
|
47
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/index.ts"],"sourcesContent":["export * from './extractNestedJSON';\nexport * from './processModule';\nexport * from './transpileBundledCode';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,kDAAc,gCAAd;AACA,kDAAc,4BADd;AAEA,kDAAc,mCAFd;","names":[]}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
15
|
-
get: () => from[key],
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var processModule_exports = {};
|
|
24
|
-
__export(processModule_exports, {
|
|
25
|
-
processModule: () => processModule,
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(processModule_exports);
|
|
28
|
-
var import_path = require("path");
|
|
29
|
-
const loadModule = async (modulePath) => {
|
|
30
|
-
return (await import(modulePath)).default;
|
|
31
|
-
};
|
|
32
|
-
const processFunctionResults = async (entry) => {
|
|
33
|
-
if (entry && typeof entry === "object") {
|
|
34
|
-
const promises = [];
|
|
35
|
-
const result = {};
|
|
36
|
-
for (const key of Object.keys(entry)) {
|
|
37
|
-
const field = entry?.[key];
|
|
38
|
-
if (typeof field === "object") {
|
|
39
|
-
result[key] = await processFunctionResults(field);
|
|
40
|
-
}
|
|
41
|
-
if (typeof field === "function") {
|
|
42
|
-
const promise = (async () => {
|
|
43
|
-
const value = await field();
|
|
44
|
-
result[key] = value;
|
|
45
|
-
})();
|
|
46
|
-
promises.push(promise);
|
|
47
|
-
} else {
|
|
48
|
-
result[key] = field;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
await Promise.all(promises);
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
return entry;
|
|
55
|
-
};
|
|
56
|
-
const processModule = async (file) => {
|
|
57
|
-
try {
|
|
58
|
-
const functionPath = (0, import_path.resolve)(file);
|
|
59
|
-
const entry = await loadModule(functionPath);
|
|
60
|
-
return await processFunctionResults(entry);
|
|
61
|
-
} catch (error) {
|
|
62
|
-
console.error("Error processing module:", error);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
-
0 &&
|
|
67
|
-
(module.exports = {
|
|
68
|
-
processModule,
|
|
69
|
-
});
|
|
70
|
-
//# sourceMappingURL=processModule.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/processModule.ts"],"sourcesContent":["import { resolve } from 'path';\nimport type {\n Content,\n ContentModule,\n FlatContent,\n FlatContentValue,\n} from '@intlayer/core';\n\n/**\n * Function to load the module file in a sandboxed environment\n */\nconst loadModule = async (modulePath: string): Promise<ContentModule> => {\n // @TODO: Sandbox the module to prevent malicious code execution\n\n return (await import(modulePath)).default;\n};\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 }\n\n 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 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 processModule = async (file: string) => {\n try {\n const functionPath = resolve(file);\n const entry = await loadModule(functionPath);\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;AAWxB,MAAM,aAAa,OAAO,eAA+C;AAGvE,UAAQ,MAAM,OAAO,aAAa;AACpC;AAKA,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;AAEA,UAAI,OAAO,UAAU,YAAY;AAE/B,cAAM,WAAW,YAAY;AAE3B,gBAAM,QAAQ,MAAM,MAAM;AAC1B,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,gBAAgB,OAAO,SAAiB;AACnD,MAAI;AACF,UAAM,mBAAe,qBAAQ,IAAI;AACjC,UAAM,QAAQ,MAAM,WAAW,YAAY;AAE3C,WAAQ,MAAM,uBAAuB,KAAK;AAAA,EAC5C,SAAS,OAAO;AACd,YAAQ,MAAM,4BAA4B,KAAK;AAAA,EACjD;AACF;","names":[]}
|