@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,112 +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 transpileBundledCode_exports = {};
|
|
24
|
-
__export(transpileBundledCode_exports, {
|
|
25
|
-
transpileBundledCode: () => transpileBundledCode,
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(transpileBundledCode_exports);
|
|
28
|
-
var import_fs = require("fs");
|
|
29
|
-
var import_promises = require("fs/promises");
|
|
30
|
-
var import_path = require("path");
|
|
31
|
-
var import_config = require("@intlayer/config");
|
|
32
|
-
var import_extractNestedJSON = require("./extractNestedJSON.cjs");
|
|
33
|
-
var import_processModule = require("./processModule.cjs");
|
|
34
|
-
const { content } = (0, import_config.getConfiguration)();
|
|
35
|
-
const { dictionariesDir, bundleFileExtension } = content;
|
|
36
|
-
const loadBundledModule = async (bundledEntryPath) => {
|
|
37
|
-
const entryFilePath = (0, import_path.resolve)(bundledEntryPath);
|
|
38
|
-
const isEntryFilePathExist = (0, import_fs.existsSync)(entryFilePath);
|
|
39
|
-
if (!isEntryFilePathExist) {
|
|
40
|
-
console.error("Entry file not found. " + entryFilePath);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const isEntryPathValid = entryFilePath.endsWith(bundleFileExtension);
|
|
44
|
-
if (!isEntryPathValid) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
try {
|
|
48
|
-
delete require.cache[entryFilePath];
|
|
49
|
-
const entry = await import(entryFilePath);
|
|
50
|
-
let result;
|
|
51
|
-
if (entry.default) {
|
|
52
|
-
result = await (0, import_processModule.processModule)(entryFilePath);
|
|
53
|
-
} else {
|
|
54
|
-
result = entry;
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
} catch (err) {
|
|
58
|
-
console.error(`Error transpiling ${entryFilePath}:`, err);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const buildDictionary = async (dictionaries) => {
|
|
62
|
-
const resultDictionariesPaths = [];
|
|
63
|
-
for await (const content2 of dictionaries) {
|
|
64
|
-
const contentString = JSON.stringify(content2);
|
|
65
|
-
const id = content2.id;
|
|
66
|
-
const outputFileName = `${id}.json`;
|
|
67
|
-
const resultFilePath = (0, import_path.resolve)(
|
|
68
|
-
dictionariesDir,
|
|
69
|
-
outputFileName
|
|
70
|
-
);
|
|
71
|
-
await (0, import_promises.writeFile)(
|
|
72
|
-
resultFilePath,
|
|
73
|
-
contentString,
|
|
74
|
-
"utf8"
|
|
75
|
-
).catch((err) => {
|
|
76
|
-
console.error(`Error creating ${outputFileName}:`, err);
|
|
77
|
-
});
|
|
78
|
-
resultDictionariesPaths.push(resultFilePath);
|
|
79
|
-
}
|
|
80
|
-
return resultDictionariesPaths;
|
|
81
|
-
};
|
|
82
|
-
const transpileBundledCode = async (bundledEntriesPaths) => {
|
|
83
|
-
const resultDictionariesPaths = [];
|
|
84
|
-
if (typeof bundledEntriesPaths === "string") {
|
|
85
|
-
bundledEntriesPaths = [bundledEntriesPaths];
|
|
86
|
-
}
|
|
87
|
-
const filteredBundledEntriesPaths = bundledEntriesPaths.filter(
|
|
88
|
-
// Filter js files;
|
|
89
|
-
(bundledEntryPath) => bundledEntryPath.endsWith(bundleFileExtension)
|
|
90
|
-
);
|
|
91
|
-
await (0, import_promises.mkdir)((0, import_path.resolve)(dictionariesDir), {
|
|
92
|
-
recursive: true,
|
|
93
|
-
});
|
|
94
|
-
for await (const bundledEntryPath of filteredBundledEntriesPaths) {
|
|
95
|
-
const result = await loadBundledModule(bundledEntryPath);
|
|
96
|
-
if (!result) {
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
const nestedContent = (0, import_extractNestedJSON.extractObjectsWithId)(
|
|
100
|
-
result
|
|
101
|
-
);
|
|
102
|
-
const dictionariesPaths = await buildDictionary(nestedContent);
|
|
103
|
-
resultDictionariesPaths.push(...dictionariesPaths);
|
|
104
|
-
}
|
|
105
|
-
return resultDictionariesPaths;
|
|
106
|
-
};
|
|
107
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
-
0 &&
|
|
109
|
-
(module.exports = {
|
|
110
|
-
transpileBundledCode,
|
|
111
|
-
});
|
|
112
|
-
//# sourceMappingURL=transpileBundledCode.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/transpileBundledCode.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport { 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 { processModule } from './processModule';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir, bundleFileExtension } = content;\n\nconst loadBundledModule = async (bundledEntryPath: string) => {\n const entryFilePath = resolve(bundledEntryPath);\n\n const isEntryFilePathExist = existsSync(entryFilePath);\n\n if (!isEntryFilePathExist) {\n console.error('Entry file not found. ' + entryFilePath);\n return;\n }\n\n const isEntryPathValid = entryFilePath.endsWith(bundleFileExtension);\n\n if (!isEntryPathValid) {\n return;\n }\n\n try {\n // Remove the module from the cache\n delete require.cache[entryFilePath];\n\n // Require the module anew\n const entry = await import(entryFilePath);\n\n let result: ContentModule | undefined;\n\n if (entry.default) {\n // JS or TS file\n result = await processModule(entryFilePath);\n } else {\n // JSON file\n result = entry;\n }\n\n return result;\n } catch (err) {\n console.error(`Error transpiling ${entryFilePath}:`, err);\n }\n};\n\nconst buildDictionary = 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 transpileBundledCode = async (\n bundledEntriesPaths: string[] | string\n) => {\n const resultDictionariesPaths: string[] = [];\n\n if (typeof bundledEntriesPaths === 'string') {\n bundledEntriesPaths = [bundledEntriesPaths];\n }\n\n const filteredBundledEntriesPaths: string[] = bundledEntriesPaths.filter(\n // Filter js files;\n (bundledEntryPath) => bundledEntryPath.endsWith(bundleFileExtension)\n );\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n for await (const bundledEntryPath of filteredBundledEntriesPaths) {\n const result = await loadBundledModule(bundledEntryPath);\n\n if (!result) {\n continue;\n }\n\n const nestedContent: ContentModule[] = extractObjectsWithId(result);\n\n const dictionariesPaths: string[] = await buildDictionary(nestedContent);\n\n resultDictionariesPaths.push(...dictionariesPaths);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA2B;AAC3B,sBAAiC;AACjC,kBAAwB;AACxB,oBAAiC;AAEjC,+BAAqC;AACrC,2BAA8B;AAE9B,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,iBAAiB,oBAAoB,IAAI;AAEjD,MAAM,oBAAoB,OAAO,qBAA6B;AAC5D,QAAM,oBAAgB,qBAAQ,gBAAgB;AAE9C,QAAM,2BAAuB,sBAAW,aAAa;AAErD,MAAI,CAAC,sBAAsB;AACzB,YAAQ,MAAM,2BAA2B,aAAa;AACtD;AAAA,EACF;AAEA,QAAM,mBAAmB,cAAc,SAAS,mBAAmB;AAEnE,MAAI,CAAC,kBAAkB;AACrB;AAAA,EACF;AAEA,MAAI;AAEF,WAAO,QAAQ,MAAM,aAAa;AAGlC,UAAM,QAAQ,MAAM,OAAO;AAE3B,QAAI;AAEJ,QAAI,MAAM,SAAS;AAEjB,eAAS,UAAM,oCAAc,aAAa;AAAA,IAC5C,OAAO;AAEL,eAAS;AAAA,IACX;AAEA,WAAO;AAAA,EACT,SAAS,KAAK;AACZ,YAAQ,MAAM,qBAAqB,aAAa,KAAK,GAAG;AAAA,EAC1D;AACF;AAEA,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,uBAAuB,OAClC,wBACG;AACH,QAAM,0BAAoC,CAAC;AAE3C,MAAI,OAAO,wBAAwB,UAAU;AAC3C,0BAAsB,CAAC,mBAAmB;AAAA,EAC5C;AAEA,QAAM,8BAAwC,oBAAoB;AAAA;AAAA,IAEhE,CAAC,qBAAqB,iBAAiB,SAAS,mBAAmB;AAAA,EACrE;AAGA,YAAM,2BAAM,qBAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,mBAAiB,oBAAoB,6BAA6B;AAChE,UAAM,SAAS,MAAM,kBAAkB,gBAAgB;AAEvD,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"]}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const bundle = (compiler) =>
|
|
2
|
-
// Run the compiler
|
|
3
|
-
compiler.run((err, stats) => {
|
|
4
|
-
if (err) {
|
|
5
|
-
console.error("Webpack compilation error:", err);
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
console.info("Webpack compilation successful.");
|
|
9
|
-
if (stats)
|
|
10
|
-
console.info(
|
|
11
|
-
stats.toString({
|
|
12
|
-
// Add options here to customize the stats output
|
|
13
|
-
colors: true,
|
|
14
|
-
})
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
const watch = (compiler) =>
|
|
18
|
-
// Run the compiler
|
|
19
|
-
compiler.watch({}, (err, stats) => {
|
|
20
|
-
if (err) {
|
|
21
|
-
console.error("Webpack compilation error:", err);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
console.info("Webpack compilation successful.");
|
|
25
|
-
if (stats)
|
|
26
|
-
console.info(
|
|
27
|
-
stats.toString({
|
|
28
|
-
// Add options here to customize the stats output
|
|
29
|
-
colors: true,
|
|
30
|
-
})
|
|
31
|
-
);
|
|
32
|
-
console.info("Watch IntLayer content...");
|
|
33
|
-
});
|
|
34
|
-
export { bundle, watch };
|
|
35
|
-
//# sourceMappingURL=bundle.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/scripts/bundle.ts"],"sourcesContent":["import type { Compiler } from 'webpack';\n\nexport const bundle = (compiler: Compiler) =>\n // Run the compiler\n compiler.run((err, stats) => {\n // Handle errors and webpack compilation stats\n if (err) {\n console.error('Webpack compilation error:', err);\n return;\n }\n\n console.info('Webpack compilation successful.');\n\n if (stats)\n console.info(\n stats.toString({\n // Add options here to customize the stats output\n colors: true,\n })\n );\n });\n\nexport const watch = (compiler: Compiler) =>\n // Run the compiler\n compiler.watch({}, (err, stats) => {\n // Handle errors and webpack compilation stats\n if (err) {\n console.error('Webpack compilation error:', err);\n return;\n }\n\n console.info('Webpack compilation successful.');\n\n if (stats)\n console.info(\n stats.toString({\n // Add options here to customize the stats output\n colors: true,\n })\n );\n\n // After successful compilation, start the server\n console.info('Watch IntLayer content...');\n });\n"],"mappings":"AAEO,MAAM,SAAS,CAAC;AAAA;AAAA,EAErB,SAAS,IAAI,CAAC,KAAK,UAAU;AAE3B,QAAI,KAAK;AACP,cAAQ,MAAM,8BAA8B,GAAG;AAC/C;AAAA,IACF;AAEA,YAAQ,KAAK,iCAAiC;AAE9C,QAAI;AACF,cAAQ;AAAA,QACN,MAAM,SAAS;AAAA;AAAA,UAEb,QAAQ;AAAA,QACV,CAAC;AAAA,MACH;AAAA,EACJ,CAAC;AAAA;AAEI,MAAM,QAAQ,CAAC;AAAA;AAAA,EAEpB,SAAS,MAAM,CAAC,GAAG,CAAC,KAAK,UAAU;AAEjC,QAAI,KAAK;AACP,cAAQ,MAAM,8BAA8B,GAAG;AAC/C;AAAA,IACF;AAEA,YAAQ,KAAK,iCAAiC;AAE9C,QAAI;AACF,cAAQ;AAAA,QACN,MAAM,SAAS;AAAA;AAAA,UAEb,QAAQ;AAAA,QACV,CAAC;AAAA,MACH;AAGF,YAAQ,KAAK,2BAA2B;AAAA,EAC1C,CAAC;AAAA;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/scripts/index.ts"],"sourcesContent":["export * from './startServer';\nexport * from './bundle';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { devServerConfig } from "../webpack.config.mjs";
|
|
2
|
-
const WebpackDevServer = require("webpack-dev-server");
|
|
3
|
-
const startServer = (compiler) => {
|
|
4
|
-
const devServer = new WebpackDevServer(devServerConfig, compiler);
|
|
5
|
-
devServer.startCallback(() => {
|
|
6
|
-
console.info("Webpack Dev Server is running...");
|
|
7
|
-
});
|
|
8
|
-
};
|
|
9
|
-
export { startServer };
|
|
10
|
-
//# sourceMappingURL=startServer.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/scripts/startServer.ts"],"sourcesContent":["import type { Compiler } from 'webpack';\nimport { devServerConfig } from '../webpack.config';\n\nconst WebpackDevServer = require('webpack-dev-server');\n\nexport const startServer = (compiler: Compiler) => {\n // Create a new instance of webpack-dev-server\n const devServer = new WebpackDevServer(devServerConfig, compiler);\n\n // Start the server\n devServer.startCallback(() => {\n console.info('Webpack Dev Server is running...');\n });\n};\n"],"mappings":"AACA,SAAS,uBAAuB;AAEhC,MAAM,mBAAmB,QAAQ,oBAAoB;AAE9C,MAAM,cAAc,CAAC,aAAuB;AAEjD,QAAM,YAAY,IAAI,iBAAiB,iBAAiB,QAAQ;AAGhE,YAAU,cAAc,MAAM;AAC5B,YAAQ,KAAK,kCAAkC;AAAA,EACjD,CAAC;AACH;","names":[]}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
|
-
import { basename, extname, relative, resolve } from "path";
|
|
3
|
-
import { getConfiguration } from "@intlayer/config";
|
|
4
|
-
import { sync } from "glob";
|
|
5
|
-
import { getFileHash } from "../../utils.mjs";
|
|
6
|
-
const { content } = getConfiguration();
|
|
7
|
-
const { dictionariesDir, mainDir } = content;
|
|
8
|
-
const generateDictionaryListContent = (dictionaries, format = "esm") => {
|
|
9
|
-
let content2 = "";
|
|
10
|
-
const dictionariesRef = dictionaries.map((dictionaryPath) => ({
|
|
11
|
-
relativePath: relative(mainDir, dictionaryPath),
|
|
12
|
-
id: basename(dictionaryPath, extname(dictionaryPath)),
|
|
13
|
-
// Get the base name as the dictionary id
|
|
14
|
-
hash: `_${getFileHash(dictionaryPath)}`,
|
|
15
|
-
// Get the hash of the dictionary to avoid conflicts
|
|
16
|
-
}));
|
|
17
|
-
dictionariesRef.forEach((dictionary) => {
|
|
18
|
-
if (format === "esm")
|
|
19
|
-
content2 += `import ${dictionary.hash} from '${dictionary.relativePath}';
|
|
20
|
-
`;
|
|
21
|
-
if (format === "cjs")
|
|
22
|
-
content2 += `const ${dictionary.hash} = require('${dictionary.relativePath}');
|
|
23
|
-
`;
|
|
24
|
-
});
|
|
25
|
-
content2 += "\n";
|
|
26
|
-
const formattedDictionaryMap = dictionariesRef
|
|
27
|
-
.map((dictionary) => `"${dictionary.id}": ${dictionary.hash}`)
|
|
28
|
-
.join(",\n");
|
|
29
|
-
if (format === "esm")
|
|
30
|
-
content2 += `export default {
|
|
31
|
-
${formattedDictionaryMap}
|
|
32
|
-
};
|
|
33
|
-
`;
|
|
34
|
-
if (format === "cjs")
|
|
35
|
-
content2 += `module.exports = {
|
|
36
|
-
${formattedDictionaryMap}
|
|
37
|
-
};
|
|
38
|
-
`;
|
|
39
|
-
return content2;
|
|
40
|
-
};
|
|
41
|
-
const createDictionaryList = () => {
|
|
42
|
-
if (!existsSync(mainDir)) {
|
|
43
|
-
mkdirSync(mainDir, { recursive: true });
|
|
44
|
-
}
|
|
45
|
-
const dictionaries = sync(`${dictionariesDir}/**/*.json`);
|
|
46
|
-
const cjsContent = generateDictionaryListContent(dictionaries, "cjs");
|
|
47
|
-
writeFileSync(resolve(mainDir, "dictionaries.cjs"), cjsContent);
|
|
48
|
-
const esmContent = generateDictionaryListContent(dictionaries, "esm");
|
|
49
|
-
writeFileSync(resolve(mainDir, "dictionaries.mjs"), esmContent);
|
|
50
|
-
};
|
|
51
|
-
export { createDictionaryList };
|
|
52
|
-
//# sourceMappingURL=createDictionaryList.mjs.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,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,SAAS,UAAU,eAAe;AACrD,SAAS,wBAAwB;AACjC,SAAS,YAAY;AACrB,SAAS,mBAAmB;AAE5B,MAAM,EAAE,QAAQ,IAAI,iBAAiB;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,cAAc,SAAS,SAAS,cAAc;AAAA,IAC9C,IAAI,SAAS,gBAAgB,QAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,IAAI,YAAY,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,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,eAAyB,KAAK,GAAG,eAAe,YAAY;AAGlE,QAAM,aAAa,8BAA8B,cAAc,KAAK;AACpE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa,8BAA8B,cAAc,KAAK;AACpE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createDictionaryList } from "./createDictionaryList.mjs";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/index.ts"],"sourcesContent":["export * from './createDictionaryList';\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
|
-
import { basename, join, relative } from "path";
|
|
3
|
-
import { getConfiguration } from "@intlayer/config";
|
|
4
|
-
import { sync } from "glob";
|
|
5
|
-
import { getFileHash, transformToCamelCase } from "../../utils.mjs";
|
|
6
|
-
const { content } = getConfiguration();
|
|
7
|
-
const { typesDir, moduleAugmentationDir } = content;
|
|
8
|
-
const getTypeName = (id) => transformToCamelCase(`${id}Content`);
|
|
9
|
-
const generateTypeIndexContent = (typeFiles) => {
|
|
10
|
-
let content2 = "import 'intlayer';\n\n";
|
|
11
|
-
const dictionariesRef = typeFiles.map((dictionaryPath) => ({
|
|
12
|
-
relativePath: relative(moduleAugmentationDir, dictionaryPath),
|
|
13
|
-
id: basename(dictionaryPath, ".d.ts"),
|
|
14
|
-
// Get the base name as the dictionary id
|
|
15
|
-
hash: `_${getFileHash(dictionaryPath)}`,
|
|
16
|
-
// Get the hash of the dictionary to avoid conflicts
|
|
17
|
-
}));
|
|
18
|
-
dictionariesRef.forEach((dictionary) => {
|
|
19
|
-
const typeName = getTypeName(dictionary.id);
|
|
20
|
-
content2 += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';
|
|
21
|
-
`;
|
|
22
|
-
});
|
|
23
|
-
content2 += "\n";
|
|
24
|
-
const formattedDictionaryMap = dictionariesRef
|
|
25
|
-
.map((dictionary) => ` "${dictionary.id}": ${dictionary.hash};`)
|
|
26
|
-
.join("\n");
|
|
27
|
-
content2 += `declare module 'intlayer' {
|
|
28
|
-
interface IntlayerDictionaryTypesConnector {
|
|
29
|
-
${formattedDictionaryMap}
|
|
30
|
-
};
|
|
31
|
-
};`;
|
|
32
|
-
return content2;
|
|
33
|
-
};
|
|
34
|
-
const createModuleAugmentation = () => {
|
|
35
|
-
if (!existsSync(moduleAugmentationDir)) {
|
|
36
|
-
mkdirSync(moduleAugmentationDir, { recursive: true });
|
|
37
|
-
}
|
|
38
|
-
const dictionaries = sync(`${typesDir}/**/*.d.ts`);
|
|
39
|
-
const tsContent = generateTypeIndexContent(dictionaries);
|
|
40
|
-
writeFileSync(join(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
|
|
41
|
-
};
|
|
42
|
-
export { createModuleAugmentation, getTypeName };
|
|
43
|
-
//# sourceMappingURL=createModuleAugmentation.mjs.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,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,MAAM,gBAAgB;AACzC,SAAS,wBAAwB;AACjC,SAAS,YAAY;AACrB,SAAS,aAAa,4BAA4B;AAElD,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAErC,MAAM,cAAc,CAAC,OAC1B,qBAAqB,GAAG,EAAE,SAAS;AAKrC,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WAAU;AAEd,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,SAAS,uBAAuB,cAAc;AAAA,IAC5D,IAAI,SAAS,gBAAgB,OAAO;AAAA;AAAA,IACpC,MAAM,IAAI,YAAY,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,CAAC,WAAW,qBAAqB,GAAG;AACtC,cAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,eAAyB,KAAK,GAAG,QAAQ,YAAY;AAG3D,QAAM,YAAY,yBAAyB,YAAY;AACvD,gBAAc,KAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content"]}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { ContentModule, Content } from "@intlayer/core";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* This function generates a TypeScript type definition from a JSON object
|
|
6
|
-
*
|
|
7
|
-
* Example:
|
|
8
|
-
*
|
|
9
|
-
* const input = {
|
|
10
|
-
* id: '1',
|
|
11
|
-
* name: 'John Doe',
|
|
12
|
-
* address: {
|
|
13
|
-
* id: '2',
|
|
14
|
-
* street: '123 Main St',
|
|
15
|
-
* city: 'Springfield',
|
|
16
|
-
* }
|
|
17
|
-
* };
|
|
18
|
-
*
|
|
19
|
-
* const result = generateTypeScriptType(input, 'RootObject');
|
|
20
|
-
* console.log(result);
|
|
21
|
-
*
|
|
22
|
-
* Output:
|
|
23
|
-
*
|
|
24
|
-
* type RootObject = {
|
|
25
|
-
* id: '1',
|
|
26
|
-
* name: string,
|
|
27
|
-
* address: {
|
|
28
|
-
* id: '2',
|
|
29
|
-
* street: string,
|
|
30
|
-
* city: string,
|
|
31
|
-
* },
|
|
32
|
-
* };
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
declare const generateTypeScriptType: (obj: ContentModule) => string;
|
|
36
|
-
declare const generateTypeScriptTypeContent: (obj: Content) => string;
|
|
37
|
-
/**
|
|
38
|
-
* This function generates a TypeScript type definition from a JSON object
|
|
39
|
-
*/
|
|
40
|
-
declare const createTypes: (dictionariesPaths: string[]) => string[];
|
|
41
|
-
|
|
42
|
-
export { createTypes, generateTypeScriptType, generateTypeScriptTypeContent };
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import { getConfiguration } from "@intlayer/config";
|
|
4
|
-
import { NodeType } from "@intlayer/core";
|
|
5
|
-
import { getTypeName } from "./createModuleAugmentation.mjs";
|
|
6
|
-
const { content, internationalization } = getConfiguration();
|
|
7
|
-
const { typesDir } = content;
|
|
8
|
-
const generateTypeScriptType = (obj) => {
|
|
9
|
-
let typeDefinition = ``;
|
|
10
|
-
const typeName = getTypeName(obj.id);
|
|
11
|
-
typeDefinition += `export type ${typeName} = {
|
|
12
|
-
`;
|
|
13
|
-
typeDefinition += generateTypeScriptTypeContent(obj);
|
|
14
|
-
typeDefinition += "};\n\n";
|
|
15
|
-
return typeDefinition;
|
|
16
|
-
};
|
|
17
|
-
const generateTypeScriptTypeContent = (obj) => {
|
|
18
|
-
let typeDefinition = ``;
|
|
19
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
20
|
-
const nodeType = value.nodeType;
|
|
21
|
-
if (
|
|
22
|
-
// Check if the value is a typed node
|
|
23
|
-
typeof value === "object" &&
|
|
24
|
-
nodeType === NodeType.Translation
|
|
25
|
-
) {
|
|
26
|
-
const tsType = typeof value[internationalization.defaultLocale];
|
|
27
|
-
typeDefinition += ` ${key}: ${tsType},
|
|
28
|
-
`;
|
|
29
|
-
} else if (
|
|
30
|
-
// Check if the value is a typed node
|
|
31
|
-
typeof value === "object" &&
|
|
32
|
-
nodeType === NodeType.Enumeration
|
|
33
|
-
) {
|
|
34
|
-
const tsType = typeof value[internationalization.defaultLocale];
|
|
35
|
-
typeDefinition += ` ${key}: (quantity: number) => ${tsType},
|
|
36
|
-
`;
|
|
37
|
-
} else if (
|
|
38
|
-
// Check if the value is a nested object
|
|
39
|
-
typeof value === "object" &&
|
|
40
|
-
!Array.isArray(value)
|
|
41
|
-
) {
|
|
42
|
-
const nestedType = generateTypeScriptTypeContent(value);
|
|
43
|
-
typeDefinition += ` ${key}: {${nestedType}},
|
|
44
|
-
`;
|
|
45
|
-
} else if (
|
|
46
|
-
// Check if the value is an array
|
|
47
|
-
Array.isArray(value)
|
|
48
|
-
) {
|
|
49
|
-
const arrayType = typeof value[0];
|
|
50
|
-
typeDefinition += ` ${key}: ${arrayType}[],
|
|
51
|
-
`;
|
|
52
|
-
} else if (
|
|
53
|
-
// Check if the value is an 'id'
|
|
54
|
-
typeof value === "string" &&
|
|
55
|
-
key === "id"
|
|
56
|
-
) {
|
|
57
|
-
const tsType = `"${value}"`;
|
|
58
|
-
typeDefinition += ` ${key}: ${tsType},
|
|
59
|
-
`;
|
|
60
|
-
} else {
|
|
61
|
-
const tsType = typeof value;
|
|
62
|
-
typeDefinition += ` ${key}: ${tsType},
|
|
63
|
-
`;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return typeDefinition;
|
|
67
|
-
};
|
|
68
|
-
const createTypes = (dictionariesPaths) => {
|
|
69
|
-
const resultTypesPaths = [];
|
|
70
|
-
if (!existsSync(typesDir)) {
|
|
71
|
-
mkdirSync(typesDir, { recursive: true });
|
|
72
|
-
}
|
|
73
|
-
for (const dictionaryPath of dictionariesPaths) {
|
|
74
|
-
const contentModule = require(dictionaryPath);
|
|
75
|
-
const dictionaryName = contentModule.id;
|
|
76
|
-
const typeDefinition = generateTypeScriptType(contentModule);
|
|
77
|
-
const outputPath = resolve(typesDir, `${dictionaryName}.d.ts`);
|
|
78
|
-
writeFileSync(outputPath, typeDefinition);
|
|
79
|
-
resultTypesPaths.push(outputPath);
|
|
80
|
-
}
|
|
81
|
-
return resultTypesPaths;
|
|
82
|
-
};
|
|
83
|
-
export { createTypes, generateTypeScriptType, generateTypeScriptTypeContent };
|
|
84
|
-
//# sourceMappingURL=createType.mjs.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,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,eAAe;AACxB,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,OAIK;AACP,SAAS,mBAAmB;AAE5B,MAAM,EAAE,SAAS,qBAAqB,IAAI,iBAAiB;AAC3D,MAAM,EAAE,SAAS,IAAI;AAkCd,MAAM,yBAAyB,CAAC,QAA+B;AACpE,MAAI,iBAAiB;AAErB,QAAM,WAAW,YAAY,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,SAAS;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,SAAS;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,CAAC,WAAW,QAAQ,GAAG;AACzB,cAAU,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,aAAa,QAAQ,UAAU,GAAG,cAAc,OAAO;AAE7D,kBAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/index.ts"],"sourcesContent":["export * from './createModuleAugmentation';\nexport * from './createType';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ContentModule } from "@intlayer/core";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* This function extracts all nested objects with an 'id' field from the input object and returns them as an array
|
|
6
|
-
*
|
|
7
|
-
* Example:
|
|
8
|
-
*
|
|
9
|
-
* const input = {
|
|
10
|
-
* id: '1',
|
|
11
|
-
* name: 'John Doe',
|
|
12
|
-
* address: {
|
|
13
|
-
* id: '2',
|
|
14
|
-
* street: '123 Main St',
|
|
15
|
-
* city: 'Springfield',
|
|
16
|
-
* state: 'IL'
|
|
17
|
-
* },
|
|
18
|
-
* };
|
|
19
|
-
* const result = extractObjectsWithId(input);
|
|
20
|
-
* console.log(result);
|
|
21
|
-
*
|
|
22
|
-
* Output:
|
|
23
|
-
*
|
|
24
|
-
* [{
|
|
25
|
-
* id: '1',
|
|
26
|
-
* name: 'John Doe',
|
|
27
|
-
* address: {
|
|
28
|
-
* id: '2',
|
|
29
|
-
* street: '123 Main St',
|
|
30
|
-
* city: 'Springfield',
|
|
31
|
-
* state: 'IL'
|
|
32
|
-
* }
|
|
33
|
-
* },
|
|
34
|
-
* {
|
|
35
|
-
* id: '2',
|
|
36
|
-
* street: '123 Main St',
|
|
37
|
-
* city: 'Springfield',
|
|
38
|
-
* state: 'IL'
|
|
39
|
-
* }]
|
|
40
|
-
*
|
|
41
|
-
*/
|
|
42
|
-
declare const extractObjectsWithId: (input: ContentModule) => ContentModule[];
|
|
43
|
-
|
|
44
|
-
export { extractObjectsWithId };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const extractObjectsWithId = (input) => {
|
|
2
|
-
const search = (obj, results2) => {
|
|
3
|
-
if (obj && typeof obj === "object") {
|
|
4
|
-
if (Object.prototype.hasOwnProperty.call(obj, "id")) {
|
|
5
|
-
results2.push(obj);
|
|
6
|
-
}
|
|
7
|
-
for (const key of Object.keys(obj)) {
|
|
8
|
-
if (typeof obj[key] === "object") {
|
|
9
|
-
search(obj[key], results2);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
const results = [];
|
|
15
|
-
search(input, results);
|
|
16
|
-
return results;
|
|
17
|
-
};
|
|
18
|
-
export { extractObjectsWithId };
|
|
19
|
-
//# sourceMappingURL=extractNestedJSON.mjs.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":"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 +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,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ContentModule } from "@intlayer/core";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Function to load, process the module and return the Intlayer ContentModule from the module file
|
|
5
|
-
*/
|
|
6
|
-
declare const processModule: (
|
|
7
|
-
file: string
|
|
8
|
-
) => Promise<ContentModule | undefined>;
|
|
9
|
-
|
|
10
|
-
export { processModule };
|