@intlayer/webpack 1.0.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.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/index.cjs +46 -0
  3. package/dist/cjs/index.cjs.map +1 -0
  4. package/dist/cjs/scripts/bundle.cjs +68 -0
  5. package/dist/cjs/scripts/bundle.cjs.map +1 -0
  6. package/dist/cjs/scripts/index.cjs +33 -0
  7. package/dist/cjs/scripts/index.cjs.map +1 -0
  8. package/dist/cjs/scripts/startServer.cjs +44 -0
  9. package/dist/cjs/scripts/startServer.cjs.map +1 -0
  10. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +92 -0
  11. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +1 -0
  12. package/dist/cjs/transpiler/dictionary_to_main/index.cjs +35 -0
  13. package/dist/cjs/transpiler/dictionary_to_main/index.cjs.map +1 -0
  14. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +83 -0
  15. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -0
  16. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +122 -0
  17. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -0
  18. package/dist/cjs/transpiler/dictionary_to_type/index.cjs +41 -0
  19. package/dist/cjs/transpiler/dictionary_to_type/index.cjs.map +1 -0
  20. package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs +50 -0
  21. package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs.map +1 -0
  22. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs +47 -0
  23. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs.map +1 -0
  24. package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs +70 -0
  25. package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs.map +1 -0
  26. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs +112 -0
  27. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs.map +1 -0
  28. package/dist/cjs/utils.cjs +53 -0
  29. package/dist/cjs/utils.cjs.map +1 -0
  30. package/dist/cjs/webpack-plugin.cjs +184 -0
  31. package/dist/cjs/webpack-plugin.cjs.map +1 -0
  32. package/dist/cjs/webpack.config.cjs +180 -0
  33. package/dist/cjs/webpack.config.cjs.map +1 -0
  34. package/dist/esm/index.d.mts +9 -0
  35. package/dist/esm/index.mjs +12 -0
  36. package/dist/esm/index.mjs.map +1 -0
  37. package/dist/esm/scripts/bundle.d.mts +7 -0
  38. package/dist/esm/scripts/bundle.mjs +35 -0
  39. package/dist/esm/scripts/bundle.mjs.map +1 -0
  40. package/dist/esm/scripts/index.d.mts +3 -0
  41. package/dist/esm/scripts/index.mjs +3 -0
  42. package/dist/esm/scripts/index.mjs.map +1 -0
  43. package/dist/esm/scripts/startServer.d.mts +5 -0
  44. package/dist/esm/scripts/startServer.mjs +10 -0
  45. package/dist/esm/scripts/startServer.mjs.map +1 -0
  46. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.d.mts +6 -0
  47. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +52 -0
  48. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs.map +1 -0
  49. package/dist/esm/transpiler/dictionary_to_main/index.d.mts +1 -0
  50. package/dist/esm/transpiler/dictionary_to_main/index.mjs +2 -0
  51. package/dist/esm/transpiler/dictionary_to_main/index.mjs.map +1 -0
  52. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.d.mts +7 -0
  53. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +43 -0
  54. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -0
  55. package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +42 -0
  56. package/dist/esm/transpiler/dictionary_to_type/createType.mjs +84 -0
  57. package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -0
  58. package/dist/esm/transpiler/dictionary_to_type/index.d.mts +10 -0
  59. package/dist/esm/transpiler/dictionary_to_type/index.mjs +3 -0
  60. package/dist/esm/transpiler/dictionary_to_type/index.mjs.map +1 -0
  61. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.mts +44 -0
  62. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs +19 -0
  63. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs.map +1 -0
  64. package/dist/esm/transpiler/intlater_module_to_dictionary/index.d.mts +4 -0
  65. package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs +4 -0
  66. package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs.map +1 -0
  67. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.d.mts +10 -0
  68. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs +39 -0
  69. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs.map +1 -0
  70. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.mts +8 -0
  71. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs +70 -0
  72. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs.map +1 -0
  73. package/dist/esm/utils.d.mts +4 -0
  74. package/dist/esm/utils.mjs +20 -0
  75. package/dist/esm/utils.mjs.map +1 -0
  76. package/dist/esm/webpack-plugin.d.mts +15 -0
  77. package/dist/esm/webpack-plugin.mjs +145 -0
  78. package/dist/esm/webpack-plugin.mjs.map +1 -0
  79. package/dist/esm/webpack.config.d.mts +7 -0
  80. package/dist/esm/webpack.config.mjs +136 -0
  81. package/dist/esm/webpack.config.mjs.map +1 -0
  82. package/package.json +97 -0
  83. package/src/index.ts +12 -0
  84. package/src/scripts/bundle.ts +44 -0
  85. package/src/scripts/index.ts +2 -0
  86. package/src/scripts/startServer.ts +14 -0
  87. package/src/transpiler/dictionary_to_main/createDictionaryList.ts +65 -0
  88. package/src/transpiler/dictionary_to_main/index.ts +1 -0
  89. package/src/transpiler/dictionary_to_type/createModuleAugmentation.ts +70 -0
  90. package/src/transpiler/dictionary_to_type/createType.ts +140 -0
  91. package/src/transpiler/dictionary_to_type/index.ts +2 -0
  92. package/src/transpiler/intlater_module_to_dictionary/extractNestedJSON.ts +60 -0
  93. package/src/transpiler/intlater_module_to_dictionary/index.ts +3 -0
  94. package/src/transpiler/intlater_module_to_dictionary/processModule.ts +69 -0
  95. package/src/transpiler/intlater_module_to_dictionary/transpileBundledCode.ts +107 -0
  96. package/src/utils.ts +26 -0
  97. package/src/webpack-plugin.ts +185 -0
  98. package/src/webpack.config.ts +149 -0
@@ -0,0 +1,180 @@
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 webpack_config_exports = {};
24
+ __export(webpack_config_exports, {
25
+ default: () => webpack_config_default,
26
+ devServerConfig: () => devServerConfig,
27
+ webpackConfig: () => webpackConfig,
28
+ });
29
+ module.exports = __toCommonJS(webpack_config_exports);
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
+ var import_webpack_plugin = require("./webpack-plugin.cjs");
35
+ const { content } = (0, import_config.getConfiguration)({
36
+ verbose: true,
37
+ });
38
+ const { bundleDir, bundleFileExtension, watchedFilesPatternWithPath } = content;
39
+ const getEntry = () =>
40
+ (0, import_glob.sync)(watchedFilesPatternWithPath).reduce((obj, el) => {
41
+ const hash = (0, import_utils.getFileHash)(el);
42
+ obj[hash] = el;
43
+ return obj;
44
+ }, {});
45
+ const devServerConfig = {
46
+ // Enable hot module replacement
47
+ hot: true,
48
+ // Open the browser
49
+ open: false,
50
+ liveReload: false,
51
+ // Enable compression
52
+ compress: true,
53
+ // History API fallback
54
+ historyApiFallback: false,
55
+ // Host and port
56
+ host: "localhost",
57
+ port: 8080,
58
+ watchFiles: "./src/",
59
+ // watchedFilesPatternWithPath,
60
+ devMiddleware: {
61
+ // Enable write to disk to reuse the output
62
+ writeToDisk: true,
63
+ },
64
+ // Content base
65
+ static: {
66
+ directory: bundleDir,
67
+ },
68
+ };
69
+ const webpackConfig = {
70
+ // Define the environment mode (development or production)
71
+ mode: "production",
72
+ // or 'production'
73
+ // Entry point of the application
74
+ target: "node",
75
+ // Specifies the target environment
76
+ entry: getEntry,
77
+ output: {
78
+ clean: true,
79
+ // Clean the output directory before emit
80
+ library: "IntlLayerContent",
81
+ libraryTarget: "umd",
82
+ filename: `[name]${bundleFileExtension}`,
83
+ path: bundleDir,
84
+ },
85
+ cache: false,
86
+ // devtool: 'source-map',
87
+ // stats: {
88
+ // preset: 'errors-only',
89
+ // warnings: false,
90
+ // },
91
+ ignoreWarnings: [/./],
92
+ resolve: {
93
+ // Resolve TypeScript, JavaScript and JSON files
94
+ extensions: [".ts", ".js", ".json", ".wasm", ".ts", ".tsx", ".mjs", ".cjs"],
95
+ modules: [
96
+ // To find the loader module
97
+ (0, import_path.join)(__dirname, "..", "node_modules"),
98
+ // In the project node_modules
99
+ (0, import_path.join)(process.cwd(), "node_modules"),
100
+ // In the project node_modules
101
+ (0, import_path.join)(
102
+ process.cwd(),
103
+ "node_modules",
104
+ "intlayer-cli",
105
+ "node_modules"
106
+ ),
107
+ // Or via another project by importing intlayer
108
+ (0, import_path.join)(
109
+ process.cwd(),
110
+ "node_modules",
111
+ "intlayer-cli",
112
+ "node_modules",
113
+ "@intlayer/webpack",
114
+ "node_modules"
115
+ ),
116
+ // Or via another project by importing intlayer
117
+ ],
118
+ },
119
+ resolveLoader: {
120
+ // Configure how Webpack finds `loader` modules.
121
+ modules: [
122
+ // To find the loader module
123
+ (0, import_path.join)(process.cwd(), "node_modules"),
124
+ // In the project node_modules
125
+ (0, import_path.join)(
126
+ process.cwd(),
127
+ "node_modules",
128
+ "@intlayer/webpack",
129
+ "node_modules"
130
+ ),
131
+ // Or via another project by importing @intlayer/webpack
132
+ (0, import_path.join)(
133
+ process.cwd(),
134
+ "node_modules",
135
+ "intlayer-cli",
136
+ "node_modules",
137
+ "@intlayer/webpack",
138
+ "node_modules"
139
+ ),
140
+ // Or via another project by importing intlayer
141
+ ],
142
+ // roots: [
143
+ // join(process.cwd()), // Project context
144
+ // join(process.cwd(), '@intlayer/webpack'), // Or via CLI in another project
145
+ // join(process.cwd(), 'intlayer', '@intlayer/webpack'), // Or via CLI in another project
146
+ // ],
147
+ },
148
+ module: {
149
+ rules: [
150
+ {
151
+ test: /\.node$/,
152
+ loader: "node-loader",
153
+ },
154
+ // Use esbuild to compile JavaScript & TypeScript
155
+ {
156
+ // Match `.js`, `.jsx`, `.ts` or `.tsx` files
157
+ test: /\.[jt]sx?$/,
158
+ loader: "esbuild-loader",
159
+ options: {
160
+ // JavaScript version to compile to
161
+ target: "es2015",
162
+ },
163
+ },
164
+ // JSON files are supported natively by Webpack 5, no specific loader required
165
+ ],
166
+ },
167
+ devServer: devServerConfig,
168
+ plugins: [
169
+ new import_webpack_plugin.IntLayerPlugin(),
170
+ // new HotModuleReplacementPlugin()
171
+ ],
172
+ };
173
+ var webpack_config_default = webpackConfig;
174
+ // Annotate the CommonJS export names for ESM import in node:
175
+ 0 &&
176
+ (module.exports = {
177
+ devServerConfig,
178
+ webpackConfig,
179
+ });
180
+ //# sourceMappingURL=webpack.config.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/webpack.config.ts"],"sourcesContent":["import { join } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport { sync } from 'glob';\nimport type { Configuration as WebPackConfiguration } from 'webpack';\nimport type { Configuration as DevServerConfiguration } from 'webpack-dev-server';\nimport { getFileHash } from './utils';\nimport { IntLayerPlugin } from './webpack-plugin';\n\nconst { content } = getConfiguration({\n verbose: true,\n});\nconst { bundleDir, bundleFileExtension, watchedFilesPatternWithPath } = content;\n\nconst getEntry = (): Record<string, string> =>\n sync(watchedFilesPatternWithPath).reduce(\n (obj, el) => {\n const hash = getFileHash(el);\n\n obj[hash] = el;\n return obj;\n },\n {} as Record<string, string>\n );\n\n// For web interface\nexport const devServerConfig: DevServerConfiguration = {\n // Enable hot module replacement\n hot: true,\n // Open the browser\n open: false,\n liveReload: false,\n\n // Enable compression\n compress: true,\n\n // History API fallback\n historyApiFallback: false,\n\n // Host and port\n host: 'localhost',\n port: 8080,\n\n watchFiles: './src/', // watchedFilesPatternWithPath,\n\n devMiddleware: {\n // Enable write to disk to reuse the output\n writeToDisk: true,\n },\n\n // Content base\n static: {\n directory: bundleDir,\n },\n};\n\nexport const webpackConfig: WebPackConfiguration = {\n // Define the environment mode (development or production)\n mode: 'production', // or 'production'\n // Entry point of the application\n target: 'node', // Specifies the target environment\n\n entry: getEntry,\n output: {\n clean: true, // Clean the output directory before emit\n library: 'IntlLayerContent',\n libraryTarget: 'umd',\n filename: `[name]${bundleFileExtension}`,\n path: bundleDir,\n },\n\n cache: false,\n\n // devtool: 'source-map',\n\n // stats: {\n // preset: 'errors-only',\n // warnings: false,\n // },\n ignoreWarnings: [/./],\n resolve: {\n // Resolve TypeScript, JavaScript and JSON files\n extensions: ['.ts', '.js', '.json', '.wasm', '.ts', '.tsx', '.mjs', '.cjs'],\n modules: [\n // To find the loader module\n join(__dirname, '..', 'node_modules'), // In the project node_modules\n join(process.cwd(), 'node_modules'), // In the project node_modules\n join(process.cwd(), 'node_modules', 'intlayer-cli', 'node_modules'), // Or via another project by importing intlayer\n join(\n process.cwd(),\n 'node_modules',\n 'intlayer-cli',\n 'node_modules',\n '@intlayer/webpack',\n 'node_modules'\n ), // Or via another project by importing intlayer\n ],\n },\n\n resolveLoader: {\n // Configure how Webpack finds `loader` modules.\n modules: [\n // To find the loader module\n join(process.cwd(), 'node_modules'), // In the project node_modules\n join(process.cwd(), 'node_modules', '@intlayer/webpack', 'node_modules'), // Or via another project by importing @intlayer/webpack\n join(\n process.cwd(),\n 'node_modules',\n 'intlayer-cli',\n 'node_modules',\n '@intlayer/webpack',\n 'node_modules'\n ), // Or via another project by importing intlayer\n ],\n // roots: [\n // join(process.cwd()), // Project context\n // join(process.cwd(), '@intlayer/webpack'), // Or via CLI in another project\n // join(process.cwd(), 'intlayer', '@intlayer/webpack'), // Or via CLI in another project\n // ],\n },\n\n module: {\n rules: [\n {\n test: /\\.node$/,\n loader: 'node-loader',\n },\n // Use esbuild to compile JavaScript & TypeScript\n {\n // Match `.js`, `.jsx`, `.ts` or `.tsx` files\n test: /\\.[jt]sx?$/,\n loader: 'esbuild-loader',\n options: {\n // JavaScript version to compile to\n target: 'es2015',\n },\n },\n\n // JSON files are supported natively by Webpack 5, no specific loader required\n ],\n },\n devServer: devServerConfig,\n\n plugins: [\n new IntLayerPlugin(),\n // new HotModuleReplacementPlugin()\n ],\n};\n\nexport default webpackConfig;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AACrB,oBAAiC;AACjC,kBAAqB;AAGrB,mBAA4B;AAC5B,4BAA+B;AAE/B,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AAAA,EACnC,SAAS;AACX,CAAC;AACD,MAAM,EAAE,WAAW,qBAAqB,4BAA4B,IAAI;AAExE,MAAM,WAAW,UACf,kBAAK,2BAA2B,EAAE;AAAA,EAChC,CAAC,KAAK,OAAO;AACX,UAAM,WAAO,0BAAY,EAAE;AAE3B,QAAI,IAAI,IAAI;AACZ,WAAO;AAAA,EACT;AAAA,EACA,CAAC;AACH;AAGK,MAAM,kBAA0C;AAAA;AAAA,EAErD,KAAK;AAAA;AAAA,EAEL,MAAM;AAAA,EACN,YAAY;AAAA;AAAA,EAGZ,UAAU;AAAA;AAAA,EAGV,oBAAoB;AAAA;AAAA,EAGpB,MAAM;AAAA,EACN,MAAM;AAAA,EAEN,YAAY;AAAA;AAAA,EAEZ,eAAe;AAAA;AAAA,IAEb,aAAa;AAAA,EACf;AAAA;AAAA,EAGA,QAAQ;AAAA,IACN,WAAW;AAAA,EACb;AACF;AAEO,MAAM,gBAAsC;AAAA;AAAA,EAEjD,MAAM;AAAA;AAAA;AAAA,EAEN,QAAQ;AAAA;AAAA,EAER,OAAO;AAAA,EACP,QAAQ;AAAA,IACN,OAAO;AAAA;AAAA,IACP,SAAS;AAAA,IACT,eAAe;AAAA,IACf,UAAU,SAAS,mBAAmB;AAAA,IACtC,MAAM;AAAA,EACR;AAAA,EAEA,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP,gBAAgB,CAAC,GAAG;AAAA,EACpB,SAAS;AAAA;AAAA,IAEP,YAAY,CAAC,OAAO,OAAO,SAAS,SAAS,OAAO,QAAQ,QAAQ,MAAM;AAAA,IAC1E,SAAS;AAAA;AAAA,UAEP,kBAAK,WAAW,MAAM,cAAc;AAAA;AAAA,UACpC,kBAAK,QAAQ,IAAI,GAAG,cAAc;AAAA;AAAA,UAClC,kBAAK,QAAQ,IAAI,GAAG,gBAAgB,gBAAgB,cAAc;AAAA;AAAA,UAClE;AAAA,QACE,QAAQ,IAAI;AAAA,QACZ;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA;AAAA,IACF;AAAA,EACF;AAAA,EAEA,eAAe;AAAA;AAAA,IAEb,SAAS;AAAA;AAAA,UAEP,kBAAK,QAAQ,IAAI,GAAG,cAAc;AAAA;AAAA,UAClC,kBAAK,QAAQ,IAAI,GAAG,gBAAgB,qBAAqB,cAAc;AAAA;AAAA,UACvE;AAAA,QACE,QAAQ,IAAI;AAAA,QACZ;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMF;AAAA,EAEA,QAAQ;AAAA,IACN,OAAO;AAAA,MACL;AAAA,QACE,MAAM;AAAA,QACN,QAAQ;AAAA,MACV;AAAA;AAAA,MAEA;AAAA;AAAA,QAEE,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,SAAS;AAAA;AAAA,UAEP,QAAQ;AAAA,QACV;AAAA,MACF;AAAA;AAAA,IAGF;AAAA,EACF;AAAA,EACA,WAAW;AAAA,EAEX,SAAS;AAAA,IACP,IAAI,qCAAe;AAAA;AAAA,EAErB;AACF;AAEA,IAAO,yBAAQ;","names":[]}
@@ -0,0 +1,9 @@
1
+ export { startServer } from "./scripts/startServer.mjs";
2
+ export { bundle, watch } from "./scripts/bundle.mjs";
3
+ export { IntLayerPlugin } from "./webpack-plugin.mjs";
4
+ export {
5
+ devServerConfig,
6
+ default as webpackConfig,
7
+ } from "./webpack.config.mjs";
8
+ import "webpack";
9
+ import "webpack-dev-server";
@@ -0,0 +1,12 @@
1
+ import { bundle, startServer, watch } from "./scripts/index.mjs";
2
+ import { IntLayerPlugin } from "./webpack-plugin.mjs";
3
+ import { devServerConfig, webpackConfig } from "./webpack.config.mjs";
4
+ export {
5
+ IntLayerPlugin,
6
+ bundle,
7
+ devServerConfig,
8
+ startServer,
9
+ watch,
10
+ webpackConfig,
11
+ };
12
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { bundle, startServer, watch } from './scripts/index';\nimport { IntLayerPlugin } from './webpack-plugin';\nimport { devServerConfig, webpackConfig } from './webpack.config';\n\nexport {\n bundle,\n watch,\n startServer,\n devServerConfig,\n webpackConfig,\n IntLayerPlugin,\n};\n"],"mappings":"AAAA,SAAS,QAAQ,aAAa,aAAa;AAC3C,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB,qBAAqB;","names":[]}
@@ -0,0 +1,7 @@
1
+ import * as webpack from "webpack";
2
+ import { Compiler } from "webpack";
3
+
4
+ declare const bundle: (compiler: Compiler) => void;
5
+ declare const watch: (compiler: Compiler) => webpack.Watching;
6
+
7
+ export { bundle, watch };
@@ -0,0 +1,35 @@
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
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,3 @@
1
+ export { startServer } from "./startServer.mjs";
2
+ export { bundle, watch } from "./bundle.mjs";
3
+ import "webpack";
@@ -0,0 +1,3 @@
1
+ export * from "./startServer.mjs";
2
+ export * from "./bundle.mjs";
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/scripts/index.ts"],"sourcesContent":["export * from './startServer';\nexport * from './bundle';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,5 @@
1
+ import { Compiler } from "webpack";
2
+
3
+ declare const startServer: (compiler: Compiler) => void;
4
+
5
+ export { startServer };
@@ -0,0 +1,10 @@
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
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This function generates a list of dictionaries in the main directory
3
+ */
4
+ declare const createDictionaryList: () => void;
5
+
6
+ export { createDictionaryList };
@@ -0,0 +1,52 @@
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
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1 @@
1
+ export { createDictionaryList } from "./createDictionaryList.mjs";
@@ -0,0 +1,2 @@
1
+ export * from "./createDictionaryList.mjs";
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/index.ts"],"sourcesContent":["export * from './createDictionaryList';\n"],"mappings":"AAAA,cAAc;","names":[]}
@@ -0,0 +1,7 @@
1
+ declare const getTypeName: (id: string) => string;
2
+ /**
3
+ * This function generates a index file merging all the types
4
+ */
5
+ declare const createModuleAugmentation: () => void;
6
+
7
+ export { createModuleAugmentation, getTypeName };
@@ -0,0 +1,43 @@
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
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,42 @@
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 };
@@ -0,0 +1,84 @@
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
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,10 @@
1
+ export {
2
+ createModuleAugmentation,
3
+ getTypeName,
4
+ } from "./createModuleAugmentation.mjs";
5
+ export {
6
+ createTypes,
7
+ generateTypeScriptType,
8
+ generateTypeScriptTypeContent,
9
+ } from "./createType.mjs";
10
+ import "@intlayer/core";
@@ -0,0 +1,3 @@
1
+ export * from "./createModuleAugmentation.mjs";
2
+ export * from "./createType.mjs";
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
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":[]}