@intlayer/webpack 1.0.1 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{scripts/startServer.cjs → getEntries.cjs} +19 -14
- package/dist/cjs/getEntries.cjs.map +1 -0
- package/dist/cjs/getEntries.d.ts +5 -0
- package/dist/cjs/index.cjs +0 -7
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +0 -2
- package/dist/cjs/utils.cjs +26 -17
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.ts +5 -2
- package/dist/cjs/webpack-plugin.cjs +4 -134
- package/dist/cjs/webpack-plugin.cjs.map +1 -1
- package/dist/cjs/webpack-plugin.d.ts +1 -11
- package/dist/cjs/webpack.config.cjs +28 -25
- package/dist/cjs/webpack.config.cjs.map +1 -1
- 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 +0 -2
- package/dist/esm/index.mjs +0 -4
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/utils.d.mts +5 -2
- package/dist/esm/utils.mjs +13 -15
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/esm/webpack-plugin.d.mts +1 -11
- package/dist/esm/webpack-plugin.mjs +4 -134
- package/dist/esm/webpack-plugin.mjs.map +1 -1
- package/dist/esm/webpack.config.mjs +29 -26
- package/dist/esm/webpack.config.mjs.map +1 -1
- package/package.json +11 -15
- 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 -65
- package/dist/cjs/scripts/bundle.cjs.map +0 -1
- package/dist/cjs/scripts/bundle.d.ts +0 -7
- package/dist/cjs/scripts/index.cjs +0 -25
- package/dist/cjs/scripts/index.cjs.map +0 -1
- package/dist/cjs/scripts/index.d.ts +0 -3
- package/dist/cjs/scripts/startServer.cjs.map +0 -1
- package/dist/cjs/scripts/startServer.d.ts +0 -5
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +0 -76
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.d.ts +0 -6
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs +0 -23
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_main/index.d.ts +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +0 -87
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +0 -7
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +0 -110
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/createType.d.ts +0 -42
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs +0 -25
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/index.d.ts +0 -3
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs +0 -45
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.ts +0 -44
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs +0 -27
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.d.ts +0 -4
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs +0 -67
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.d.ts +0 -8
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs +0 -96
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.ts +0 -6
- package/dist/esm/scripts/bundle.d.mts +0 -7
- package/dist/esm/scripts/bundle.mjs +0 -40
- 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 -12
- 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 -62
- 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 -86
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_type/index.d.mts +0 -3
- 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 -21
- 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 -8
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs +0 -43
- 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 -6
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs +0 -72
- 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 -95
- 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
package/src/webpack.config.ts
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { getConfiguration } from '@intlayer/config';
|
|
3
|
-
import { sync } from 'glob';
|
|
4
3
|
import type { Configuration as WebPackConfiguration } from 'webpack';
|
|
5
4
|
import type { Configuration as DevServerConfiguration } from 'webpack-dev-server';
|
|
6
|
-
import {
|
|
5
|
+
import { getEntries } from './getEntries';
|
|
6
|
+
import { defineDirname } from './utils';
|
|
7
7
|
import { IntLayerPlugin } from './webpack-plugin';
|
|
8
8
|
|
|
9
9
|
const { content } = getConfiguration({
|
|
10
|
-
verbose:
|
|
10
|
+
verbose: false,
|
|
11
11
|
});
|
|
12
|
-
const {
|
|
12
|
+
const { fileExtensions } = content;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
obj[hash] = el;
|
|
20
|
-
return obj;
|
|
21
|
-
},
|
|
22
|
-
{} as Record<string, string>
|
|
23
|
-
);
|
|
14
|
+
/**
|
|
15
|
+
* Set the __dirname global variable to make the config work in both ESM and CJS environments
|
|
16
|
+
*/
|
|
17
|
+
defineDirname();
|
|
24
18
|
|
|
25
19
|
// For web interface
|
|
26
20
|
export const devServerConfig: DevServerConfiguration = {
|
|
@@ -48,9 +42,7 @@ export const devServerConfig: DevServerConfiguration = {
|
|
|
48
42
|
},
|
|
49
43
|
|
|
50
44
|
// Content base
|
|
51
|
-
static: {
|
|
52
|
-
directory: bundleDir,
|
|
53
|
-
},
|
|
45
|
+
static: {},
|
|
54
46
|
};
|
|
55
47
|
|
|
56
48
|
export const webpackConfig: WebPackConfiguration = {
|
|
@@ -59,18 +51,17 @@ export const webpackConfig: WebPackConfiguration = {
|
|
|
59
51
|
// Entry point of the application
|
|
60
52
|
target: 'node', // Specifies the target environment
|
|
61
53
|
|
|
62
|
-
entry:
|
|
54
|
+
entry: getEntries,
|
|
63
55
|
output: {
|
|
64
56
|
clean: true, // Clean the output directory before emit
|
|
65
57
|
library: 'IntlLayerContent',
|
|
66
58
|
libraryTarget: 'umd',
|
|
67
|
-
filename: `[name]
|
|
68
|
-
path: bundleDir,
|
|
59
|
+
filename: `[name].bundle.js`,
|
|
69
60
|
},
|
|
70
61
|
|
|
71
62
|
cache: false,
|
|
72
63
|
|
|
73
|
-
|
|
64
|
+
devtool: 'source-map',
|
|
74
65
|
|
|
75
66
|
// stats: {
|
|
76
67
|
// preset: 'errors-only',
|
|
@@ -82,7 +73,7 @@ export const webpackConfig: WebPackConfiguration = {
|
|
|
82
73
|
extensions: ['.ts', '.js', '.json', '.wasm', '.ts', '.tsx', '.mjs', '.cjs'],
|
|
83
74
|
modules: [
|
|
84
75
|
// To find the loader module
|
|
85
|
-
join(__dirname, '..', 'node_modules'), // In the project node_modules
|
|
76
|
+
join(globalThis.__dirname, '..', 'node_modules'), // In the project node_modules
|
|
86
77
|
join(process.cwd(), 'node_modules'), // In the project node_modules
|
|
87
78
|
join(process.cwd(), 'node_modules', 'intlayer-cli', 'node_modules'), // Or via another project by importing intlayer
|
|
88
79
|
join(
|
|
@@ -111,15 +102,28 @@ export const webpackConfig: WebPackConfiguration = {
|
|
|
111
102
|
'node_modules'
|
|
112
103
|
), // Or via another project by importing intlayer
|
|
113
104
|
],
|
|
114
|
-
// roots: [
|
|
115
|
-
// join(process.cwd()), // Project context
|
|
116
|
-
// join(process.cwd(), '@intlayer/webpack'), // Or via CLI in another project
|
|
117
|
-
// join(process.cwd(), 'intlayer', '@intlayer/webpack'), // Or via CLI in another project
|
|
118
|
-
// ],
|
|
119
105
|
},
|
|
120
106
|
|
|
121
107
|
module: {
|
|
122
108
|
rules: [
|
|
109
|
+
{
|
|
110
|
+
// Rule for .content.ts files
|
|
111
|
+
test: new RegExp(`(${fileExtensions.join('|')})$`),
|
|
112
|
+
use: [
|
|
113
|
+
{
|
|
114
|
+
// Transpile with esbuild-loader
|
|
115
|
+
loader: 'esbuild-loader',
|
|
116
|
+
options: {
|
|
117
|
+
// JavaScript version to compile to
|
|
118
|
+
target: 'es2015',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
// {
|
|
122
|
+
// // Custom loader to process the transpiled code
|
|
123
|
+
// loader: resolve('./intlayer-loader'),
|
|
124
|
+
// },
|
|
125
|
+
],
|
|
126
|
+
},
|
|
123
127
|
{
|
|
124
128
|
test: /\.node$/,
|
|
125
129
|
loader: 'node-loader',
|
|
@@ -127,7 +131,7 @@ export const webpackConfig: WebPackConfiguration = {
|
|
|
127
131
|
// Use esbuild to compile JavaScript & TypeScript
|
|
128
132
|
{
|
|
129
133
|
// Match `.js`, `.jsx`, `.ts` or `.tsx` files
|
|
130
|
-
test: /\.
|
|
134
|
+
test: /\.(jsx|js|ts|tsx|mjs|cjs)?$/,
|
|
131
135
|
loader: 'esbuild-loader',
|
|
132
136
|
options: {
|
|
133
137
|
// JavaScript version to compile to
|
|
@@ -1,65 +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, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var bundle_exports = {};
|
|
20
|
-
__export(bundle_exports, {
|
|
21
|
-
bundle: () => bundle,
|
|
22
|
-
watch: () => watch
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(bundle_exports);
|
|
25
|
-
const bundle = (compiler) => (
|
|
26
|
-
// Run the compiler
|
|
27
|
-
compiler.run((err, stats) => {
|
|
28
|
-
if (err) {
|
|
29
|
-
console.error("Webpack compilation error:", err);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
console.info("Webpack compilation successful.");
|
|
33
|
-
if (stats)
|
|
34
|
-
console.info(
|
|
35
|
-
stats.toString({
|
|
36
|
-
// Add options here to customize the stats output
|
|
37
|
-
colors: true
|
|
38
|
-
})
|
|
39
|
-
);
|
|
40
|
-
})
|
|
41
|
-
);
|
|
42
|
-
const watch = (compiler) => (
|
|
43
|
-
// Run the compiler
|
|
44
|
-
compiler.watch({}, (err, stats) => {
|
|
45
|
-
if (err) {
|
|
46
|
-
console.error("Webpack compilation error:", err);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
console.info("Webpack compilation successful.");
|
|
50
|
-
if (stats)
|
|
51
|
-
console.info(
|
|
52
|
-
stats.toString({
|
|
53
|
-
// Add options here to customize the stats output
|
|
54
|
-
colors: true
|
|
55
|
-
})
|
|
56
|
-
);
|
|
57
|
-
console.info("Watch IntLayer content...");
|
|
58
|
-
})
|
|
59
|
-
);
|
|
60
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
-
0 && (module.exports = {
|
|
62
|
-
bundle,
|
|
63
|
-
watch
|
|
64
|
-
});
|
|
65
|
-
//# sourceMappingURL=bundle.cjs.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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var scripts_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(scripts_exports);
|
|
18
|
-
__reExport(scripts_exports, require('./startServer.cjs'), module.exports);
|
|
19
|
-
__reExport(scripts_exports, require('./bundle.cjs'), module.exports);
|
|
20
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
-
0 && (module.exports = {
|
|
22
|
-
...require('./startServer.cjs'),
|
|
23
|
-
...require('./bundle.cjs')
|
|
24
|
-
});
|
|
25
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/scripts/index.ts"],"sourcesContent":["export * from './startServer';\nexport * from './bundle';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,4BAAc,0BAAd;AACA,4BAAc,qBADd;","names":[]}
|
|
@@ -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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAgC;AAEhC,MAAM,mBAAmB,QAAQ,oBAAoB;AAE9C,MAAM,cAAc,CAAC,aAAuB;AAEjD,QAAM,YAAY,IAAI,iBAAiB,gCAAiB,QAAQ;AAGhE,YAAU,cAAc,MAAM;AAC5B,YAAQ,KAAK,kCAAkC;AAAA,EACjD,CAAC;AACH;","names":[]}
|
|
@@ -1,76 +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, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var createDictionaryList_exports = {};
|
|
20
|
-
__export(createDictionaryList_exports, {
|
|
21
|
-
createDictionaryList: () => createDictionaryList
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(createDictionaryList_exports);
|
|
24
|
-
var import_fs = require("fs");
|
|
25
|
-
var import_path = require("path");
|
|
26
|
-
var import_config = require("@intlayer/config");
|
|
27
|
-
var import_glob = require("glob");
|
|
28
|
-
var import_utils = require('../../utils.cjs');
|
|
29
|
-
const { content } = (0, import_config.getConfiguration)();
|
|
30
|
-
const { dictionariesDir, mainDir } = content;
|
|
31
|
-
const generateDictionaryListContent = (dictionaries, format = "esm") => {
|
|
32
|
-
let content2 = "";
|
|
33
|
-
const dictionariesRef = dictionaries.map((dictionaryPath) => ({
|
|
34
|
-
relativePath: (0, import_path.relative)(mainDir, dictionaryPath),
|
|
35
|
-
id: (0, import_path.basename)(dictionaryPath, (0, import_path.extname)(dictionaryPath)),
|
|
36
|
-
// Get the base name as the dictionary id
|
|
37
|
-
hash: `_${(0, import_utils.getFileHash)(dictionaryPath)}`
|
|
38
|
-
// Get the hash of the dictionary to avoid conflicts
|
|
39
|
-
}));
|
|
40
|
-
dictionariesRef.forEach((dictionary) => {
|
|
41
|
-
if (format === "esm")
|
|
42
|
-
content2 += `import ${dictionary.hash} from '${dictionary.relativePath}';
|
|
43
|
-
`;
|
|
44
|
-
if (format === "cjs")
|
|
45
|
-
content2 += `const ${dictionary.hash} = require('${dictionary.relativePath}');
|
|
46
|
-
`;
|
|
47
|
-
});
|
|
48
|
-
content2 += "\n";
|
|
49
|
-
const formattedDictionaryMap = dictionariesRef.map((dictionary) => `"${dictionary.id}": ${dictionary.hash}`).join(",\n");
|
|
50
|
-
if (format === "esm")
|
|
51
|
-
content2 += `export default {
|
|
52
|
-
${formattedDictionaryMap}
|
|
53
|
-
};
|
|
54
|
-
`;
|
|
55
|
-
if (format === "cjs")
|
|
56
|
-
content2 += `module.exports = {
|
|
57
|
-
${formattedDictionaryMap}
|
|
58
|
-
};
|
|
59
|
-
`;
|
|
60
|
-
return content2;
|
|
61
|
-
};
|
|
62
|
-
const createDictionaryList = () => {
|
|
63
|
-
if (!(0, import_fs.existsSync)(mainDir)) {
|
|
64
|
-
(0, import_fs.mkdirSync)(mainDir, { recursive: true });
|
|
65
|
-
}
|
|
66
|
-
const dictionaries = (0, import_glob.sync)(`${dictionariesDir}/**/*.json`);
|
|
67
|
-
const cjsContent = generateDictionaryListContent(dictionaries, "cjs");
|
|
68
|
-
(0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, "dictionaries.cjs"), cjsContent);
|
|
69
|
-
const esmContent = generateDictionaryListContent(dictionaries, "esm");
|
|
70
|
-
(0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, "dictionaries.mjs"), esmContent);
|
|
71
|
-
};
|
|
72
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
-
0 && (module.exports = {
|
|
74
|
-
createDictionaryList
|
|
75
|
-
});
|
|
76
|
-
//# sourceMappingURL=createDictionaryList.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryList.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, relative, resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport { sync } from 'glob';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir, mainDir } = content;\n\n/**\n * This function generates the content of the dictionary list file\n */\nconst generateDictionaryListContent = (\n dictionaries: string[],\n format: 'cjs' | 'esm' = 'esm'\n): string => {\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: relative(mainDir, dictionaryPath),\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => `\"${dictionary.id}\": ${dictionary.hash}`)\n .join(',\\n');\n\n if (format === 'esm')\n content += `export default {\\n${formattedDictionaryMap}\\n};\\n`;\n if (format === 'cjs')\n content += `module.exports = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n return content;\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryList = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionaries: string[] = sync(`${dictionariesDir}/**/*.json`);\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionaries, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionaries, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAqD;AACrD,oBAAiC;AACjC,kBAAqB;AACrB,mBAA4B;AAE5B,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,iBAAiB,QAAQ,IAAI;AAKrC,MAAM,gCAAgC,CACpC,cACA,SAAwB,UACb;AACX,MAAIA,WAAU;AAEd,QAAM,kBAAkB,aAAa,IAAI,CAAC,oBAAoB;AAAA,IAC5D,kBAAc,sBAAS,SAAS,cAAc;AAAA,IAC9C,QAAI,sBAAS,oBAAgB,qBAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,QAAI,0BAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,QAAI,WAAW;AACb,MAAAA,YAAW,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AACvE,QAAI,WAAW;AACb,MAAAA,YAAW,SAAS,WAAW,IAAI,eAAe,WAAW,YAAY;AAAA;AAAA,EAC7E,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,IAAI,WAAW,EAAE,MAAM,WAAW,IAAI,EAAE,EAC5D,KAAK,KAAK;AAEb,MAAI,WAAW;AACb,IAAAA,YAAW;AAAA,EAAqB,sBAAsB;AAAA;AAAA;AACxD,MAAI,WAAW;AACb,IAAAA,YAAW;AAAA,EAAuB,sBAAsB;AAAA;AAAA;AAE1D,SAAOA;AACT;AAKO,MAAM,uBAAuB,MAAM;AAExC,MAAI,KAAC,sBAAW,OAAO,GAAG;AACxB,6BAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAAyB,kBAAK,GAAG,eAAe,YAAY;AAGlE,QAAM,aAAa,8BAA8B,cAAc,KAAK;AACpE,mCAAc,qBAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa,8BAA8B,cAAc,KAAK;AACpE,mCAAc,qBAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var dictionary_to_main_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(dictionary_to_main_exports);
|
|
18
|
-
__reExport(dictionary_to_main_exports, require('./createDictionaryList.cjs'), module.exports);
|
|
19
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
-
0 && (module.exports = {
|
|
21
|
-
...require('./createDictionaryList.cjs')
|
|
22
|
-
});
|
|
23
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/index.ts"],"sourcesContent":["export * from './createDictionaryList';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uCAAc,mCAAd;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createDictionaryList } from './createDictionaryList.js';
|
|
@@ -1,87 +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, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var createModuleAugmentation_exports = {};
|
|
20
|
-
__export(createModuleAugmentation_exports, {
|
|
21
|
-
createModuleAugmentation: () => createModuleAugmentation,
|
|
22
|
-
getTypeName: () => getTypeName
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(createModuleAugmentation_exports);
|
|
25
|
-
var import_fs = require("fs");
|
|
26
|
-
var import_path = require("path");
|
|
27
|
-
var import_config = require("@intlayer/config");
|
|
28
|
-
var import_glob = require("glob");
|
|
29
|
-
var import_utils = require('../../utils.cjs');
|
|
30
|
-
const { content, internationalization } = (0, import_config.getConfiguration)();
|
|
31
|
-
const { typesDir, moduleAugmentationDir } = content;
|
|
32
|
-
const { locales } = internationalization;
|
|
33
|
-
const getTypeName = (id) => (0, import_utils.transformToCamelCase)(`${id}Content`);
|
|
34
|
-
const generateTypeIndexContent = (typeFiles) => {
|
|
35
|
-
let content2 = "/* eslint-disable */\nimport 'intlayer';\nimport { Locales } from '@intlayer/config'\n";
|
|
36
|
-
const dictionariesRef = typeFiles.map((dictionaryPath) => ({
|
|
37
|
-
relativePath: (0, import_path.relative)(moduleAugmentationDir, dictionaryPath),
|
|
38
|
-
id: (0, import_path.basename)(dictionaryPath, ".d.ts"),
|
|
39
|
-
// Get the base name as the dictionary id
|
|
40
|
-
hash: `_${(0, import_utils.getFileHash)(dictionaryPath)}`
|
|
41
|
-
// Get the hash of the dictionary to avoid conflicts
|
|
42
|
-
}));
|
|
43
|
-
dictionariesRef.forEach((dictionary) => {
|
|
44
|
-
const typeName = getTypeName(dictionary.id);
|
|
45
|
-
content2 += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';
|
|
46
|
-
`;
|
|
47
|
-
});
|
|
48
|
-
content2 += "\n";
|
|
49
|
-
const formattedDictionaryMap = dictionariesRef.map((dictionary) => ` "${dictionary.id}": ${dictionary.hash};`).join("\n");
|
|
50
|
-
const formatLocales = locales.map((locale) => {
|
|
51
|
-
for (const key in import_config.Locales) {
|
|
52
|
-
if (import_config.Locales[key] === locale) {
|
|
53
|
-
return ` ${key} = '${locale}'`;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}).join(",\n");
|
|
57
|
-
content2 += `declare module 'intlayer' {
|
|
58
|
-
`;
|
|
59
|
-
content2 += ` interface IntlayerDictionaryTypesConnector {
|
|
60
|
-
${formattedDictionaryMap}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
`;
|
|
64
|
-
content2 += ` enum ConfigLocales {
|
|
65
|
-
${formatLocales}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
`;
|
|
69
|
-
content2 += ` interface IConfigLocales<Content> extends Record<ConfigLocales, Content> {}
|
|
70
|
-
`;
|
|
71
|
-
content2 += `};`;
|
|
72
|
-
return content2;
|
|
73
|
-
};
|
|
74
|
-
const createModuleAugmentation = () => {
|
|
75
|
-
if (!(0, import_fs.existsSync)(moduleAugmentationDir)) {
|
|
76
|
-
(0, import_fs.mkdirSync)(moduleAugmentationDir, { recursive: true });
|
|
77
|
-
}
|
|
78
|
-
const dictionaries = (0, import_glob.sync)(`${typesDir}/**/*.d.ts`);
|
|
79
|
-
const tsContent = generateTypeIndexContent(dictionaries);
|
|
80
|
-
(0, import_fs.writeFileSync)((0, import_path.join)(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
|
|
81
|
-
};
|
|
82
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
-
0 && (module.exports = {
|
|
84
|
-
createModuleAugmentation,
|
|
85
|
-
getTypeName
|
|
86
|
-
});
|
|
87
|
-
//# sourceMappingURL=createModuleAugmentation.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport { sync } from 'glob';\nimport { getFileHash, transformToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir, moduleAugmentationDir } = content;\nconst { locales } = internationalization;\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 =\n \"/* eslint-disable */\\nimport 'intlayer';\\nimport { Locales } from '@intlayer/config'\\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 const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return ` ${key} = '${locale}'`;\n }\n }\n })\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 * enum ConfigLocales {\n * ENGLISH = 'en',\n * FRENCH = 'fr',\n * SPANISH = 'es',\n * }\n *\n * interface IConfigLocales<Content> extends Record<ConfigLocales, Content> {}\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` enum ConfigLocales {\\n${formatLocales}\\n };\\n\\n`;\n content += ` interface IConfigLocales<Content> extends Record<ConfigLocales, Content> {}\\n`;\n content += `};`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionaries: string[] = sync(`${typesDir}/**/*.d.ts`);\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionaries);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAyC;AACzC,oBAA0C;AAC1C,kBAAqB;AACrB,mBAAkD;AAElD,MAAM,EAAE,SAAS,qBAAqB,QAAI,gCAAiB;AAC3D,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAC5C,MAAM,EAAE,QAAQ,IAAI;AAEb,MAAM,cAAc,CAAC,WAC1B,mCAAqB,GAAG,EAAE,SAAS;AAKrC,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WACF;AAEF,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,kBAAc,sBAAS,uBAAuB,cAAc;AAAA,IAC5D,QAAI,sBAAS,gBAAgB,OAAO;AAAA;AAAA,IACpC,MAAM,QAAI,0BAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,UAAM,WAAW,YAAY,WAAW,EAAE;AAC1C,IAAAA,YAAW,iBAAiB,QAAQ,OAAO,WAAW,IAAI,YAAY,WAAW,YAAY;AAAA;AAAA,EAC/F,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,MAAM,WAAW,IAAI,GAAG,EACjE,KAAK,IAAI;AAEZ,QAAM,gBAAgB,QACnB,IAAI,CAAC,WAAW;AACf,eAAW,OAAO,uBAAS;AACzB,UAAI,sBAAQ,GAA2B,MAAM,QAAQ;AACnD,eAAO,OAAO,GAAG,OAAO,MAAM;AAAA,MAChC;AAAA,IACF;AAAA,EACF,CAAC,EACA,KAAK,KAAK;AAwBb,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACpF,EAAAA,YAAW;AAAA,EAA2B,aAAa;AAAA;AAAA;AAAA;AACnD,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAEX,SAAOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,KAAC,sBAAW,qBAAqB,GAAG;AACtC,6BAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,mBAAyB,kBAAK,GAAG,QAAQ,YAAY;AAG3D,QAAM,YAAY,yBAAyB,YAAY;AACvD,mCAAc,kBAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content"]}
|
|
@@ -1,110 +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, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var createType_exports = {};
|
|
20
|
-
__export(createType_exports, {
|
|
21
|
-
createTypes: () => createTypes,
|
|
22
|
-
generateTypeScriptType: () => generateTypeScriptType,
|
|
23
|
-
generateTypeScriptTypeContent: () => generateTypeScriptTypeContent
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(createType_exports);
|
|
26
|
-
var import_fs = require("fs");
|
|
27
|
-
var import_path = require("path");
|
|
28
|
-
var import_config = require("@intlayer/config");
|
|
29
|
-
var import_core = require("@intlayer/core");
|
|
30
|
-
var import_createModuleAugmentation = require('./createModuleAugmentation.cjs');
|
|
31
|
-
const { content, internationalization } = (0, import_config.getConfiguration)();
|
|
32
|
-
const { typesDir } = content;
|
|
33
|
-
const generateTypeScriptType = (obj) => {
|
|
34
|
-
let typeDefinition = ``;
|
|
35
|
-
const typeName = (0, import_createModuleAugmentation.getTypeName)(obj.id);
|
|
36
|
-
typeDefinition += `export type ${typeName} = {
|
|
37
|
-
`;
|
|
38
|
-
typeDefinition += generateTypeScriptTypeContent(obj);
|
|
39
|
-
typeDefinition += "};\n\n";
|
|
40
|
-
return typeDefinition;
|
|
41
|
-
};
|
|
42
|
-
const generateTypeScriptTypeContent = (obj) => {
|
|
43
|
-
let typeDefinition = ``;
|
|
44
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
45
|
-
const nodeType = value.nodeType;
|
|
46
|
-
if (
|
|
47
|
-
// Check if the value is a typed node
|
|
48
|
-
typeof value === "object" && nodeType === import_core.NodeType.Translation
|
|
49
|
-
) {
|
|
50
|
-
const tsType = typeof value[internationalization.defaultLocale];
|
|
51
|
-
typeDefinition += ` ${key}: ${tsType},
|
|
52
|
-
`;
|
|
53
|
-
} else if (
|
|
54
|
-
// Check if the value is a typed node
|
|
55
|
-
typeof value === "object" && nodeType === import_core.NodeType.Enumeration
|
|
56
|
-
) {
|
|
57
|
-
const tsType = typeof value[internationalization.defaultLocale];
|
|
58
|
-
typeDefinition += ` ${key}: (quantity: number) => ${tsType},
|
|
59
|
-
`;
|
|
60
|
-
} else if (
|
|
61
|
-
// Check if the value is a nested object
|
|
62
|
-
typeof value === "object" && !Array.isArray(value)
|
|
63
|
-
) {
|
|
64
|
-
const nestedType = generateTypeScriptTypeContent(value);
|
|
65
|
-
typeDefinition += ` ${key}: {${nestedType}},
|
|
66
|
-
`;
|
|
67
|
-
} else if (
|
|
68
|
-
// Check if the value is an array
|
|
69
|
-
Array.isArray(value)
|
|
70
|
-
) {
|
|
71
|
-
const arrayType = typeof value[0];
|
|
72
|
-
typeDefinition += ` ${key}: ${arrayType}[],
|
|
73
|
-
`;
|
|
74
|
-
} else if (
|
|
75
|
-
// Check if the value is an 'id'
|
|
76
|
-
typeof value === "string" && key === "id"
|
|
77
|
-
) {
|
|
78
|
-
const tsType = `"${value}"`;
|
|
79
|
-
typeDefinition += ` ${key}: ${tsType},
|
|
80
|
-
`;
|
|
81
|
-
} else {
|
|
82
|
-
const tsType = typeof value;
|
|
83
|
-
typeDefinition += ` ${key}: ${tsType},
|
|
84
|
-
`;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return typeDefinition;
|
|
88
|
-
};
|
|
89
|
-
const createTypes = (dictionariesPaths) => {
|
|
90
|
-
const resultTypesPaths = [];
|
|
91
|
-
if (!(0, import_fs.existsSync)(typesDir)) {
|
|
92
|
-
(0, import_fs.mkdirSync)(typesDir, { recursive: true });
|
|
93
|
-
}
|
|
94
|
-
for (const dictionaryPath of dictionariesPaths) {
|
|
95
|
-
const contentModule = require(dictionaryPath);
|
|
96
|
-
const dictionaryName = contentModule.id;
|
|
97
|
-
const typeDefinition = generateTypeScriptType(contentModule);
|
|
98
|
-
const outputPath = (0, import_path.resolve)(typesDir, `${dictionaryName}.d.ts`);
|
|
99
|
-
(0, import_fs.writeFileSync)(outputPath, typeDefinition);
|
|
100
|
-
resultTypesPaths.push(outputPath);
|
|
101
|
-
}
|
|
102
|
-
return resultTypesPaths;
|
|
103
|
-
};
|
|
104
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
-
0 && (module.exports = {
|
|
106
|
-
createTypes,
|
|
107
|
-
generateTypeScriptType,
|
|
108
|
-
generateTypeScriptTypeContent
|
|
109
|
-
});
|
|
110
|
-
//# sourceMappingURL=createType.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createType.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport {\n NodeType,\n type Content,\n type ContentModule,\n type TypedNode,\n} from '@intlayer/core';\nimport { getTypeName } from './createModuleAugmentation';\n\nconst { content, internationalization } = getConfiguration();\nconst { typesDir } = content;\n\n/**\n *\n * This function generates a TypeScript type definition from a JSON object\n *\n * Example:\n *\n * const input = {\n * id: '1',\n * name: 'John Doe',\n * address: {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * }\n * };\n *\n * const result = generateTypeScriptType(input, 'RootObject');\n * console.log(result);\n *\n * Output:\n *\n * type RootObject = {\n * id: '1',\n * name: string,\n * address: {\n * id: '2',\n * street: string,\n * city: string,\n * },\n * };\n *\n */\nexport const generateTypeScriptType = (obj: ContentModule): string => {\n let typeDefinition = ``;\n\n const typeName = getTypeName(obj.id);\n\n typeDefinition += `export type ${typeName} = {\\n`;\n typeDefinition += generateTypeScriptTypeContent(obj);\n typeDefinition += '};\\n\\n';\n\n return typeDefinition;\n};\n\nexport const generateTypeScriptTypeContent = (obj: Content): string => {\n let typeDefinition = ``;\n\n for (const [key, value] of Object.entries(obj)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nodeType: NodeType | undefined = (value as TypedNode).nodeType;\n\n if (\n // Check if the value is a typed node\n typeof value === 'object' &&\n nodeType === NodeType.Translation\n ) {\n const tsType =\n typeof value[internationalization.defaultLocale as keyof typeof value];\n typeDefinition += ` ${key}: ${tsType},\\n`;\n } else if (\n // Check if the value is a typed node\n typeof value === 'object' &&\n nodeType === NodeType.Enumeration\n ) {\n const tsType =\n typeof value[internationalization.defaultLocale as keyof typeof value];\n\n typeDefinition += ` ${key}: (quantity: number) => ${tsType},\\n`;\n } else if (\n // Check if the value is a nested object\n typeof value === 'object' &&\n !Array.isArray(value)\n ) {\n // Nested object, recurse\n const nestedType = generateTypeScriptTypeContent(value as Content);\n typeDefinition += ` ${key}: {${nestedType}},\\n`;\n } else if (\n // Check if the value is an array\n Array.isArray(value)\n ) {\n // Array handling (simplified, assumes non-empty arrays with uniform type)\n const arrayType = typeof value[0];\n typeDefinition += ` ${key}: ${arrayType}[],\\n`;\n } else if (\n // Check if the value is an 'id'\n typeof value === 'string' &&\n key === 'id'\n ) {\n // Special handling for 'id' field\n const tsType = `\"${value}\"`;\n typeDefinition += ` ${key}: ${tsType},\\n`;\n } else {\n // Primitive type\n const tsType = typeof value;\n typeDefinition += ` ${key}: ${tsType},\\n`;\n }\n }\n\n return typeDefinition;\n};\n\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = (dictionariesPaths: string[]): string[] => {\n const resultTypesPaths: string[] = [];\n\n // Create type folders if they don't exist\n if (!existsSync(typesDir)) {\n mkdirSync(typesDir, { recursive: true });\n }\n\n for (const dictionaryPath of dictionariesPaths) {\n const contentModule: ContentModule = require(dictionaryPath);\n const dictionaryName: string = contentModule.id;\n const typeDefinition: string = generateTypeScriptType(contentModule);\n\n const outputPath = resolve(typesDir, `${dictionaryName}.d.ts`);\n\n writeFileSync(outputPath, typeDefinition);\n\n resultTypesPaths.push(outputPath);\n }\n\n return resultTypesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAwB;AACxB,oBAAiC;AACjC,kBAKO;AACP,sCAA4B;AAE5B,MAAM,EAAE,SAAS,qBAAqB,QAAI,gCAAiB;AAC3D,MAAM,EAAE,SAAS,IAAI;AAkCd,MAAM,yBAAyB,CAAC,QAA+B;AACpE,MAAI,iBAAiB;AAErB,QAAM,eAAW,6CAAY,IAAI,EAAE;AAEnC,oBAAkB,eAAe,QAAQ;AAAA;AACzC,oBAAkB,8BAA8B,GAAG;AACnD,oBAAkB;AAElB,SAAO;AACT;AAEO,MAAM,gCAAgC,CAAC,QAAyB;AACrE,MAAI,iBAAiB;AAErB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAE9C,UAAM,WAAkC,MAAoB;AAE5D;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,aAAa,qBAAS;AAAA,MACtB;AACA,YAAM,SACJ,OAAO,MAAM,qBAAqB,aAAmC;AACvE,wBAAkB,KAAK,GAAG,KAAK,MAAM;AAAA;AAAA,IACvC;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,aAAa,qBAAS;AAAA,MACtB;AACA,YAAM,SACJ,OAAO,MAAM,qBAAqB,aAAmC;AAEvE,wBAAkB,KAAK,GAAG,2BAA2B,MAAM;AAAA;AAAA,IAC7D;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,CAAC,MAAM,QAAQ,KAAK;AAAA,MACpB;AAEA,YAAM,aAAa,8BAA8B,KAAgB;AACjE,wBAAkB,KAAK,GAAG,MAAM,UAAU;AAAA;AAAA,IAC5C;AAAA;AAAA,MAEE,MAAM,QAAQ,KAAK;AAAA,MACnB;AAEA,YAAM,YAAY,OAAO,MAAM,CAAC;AAChC,wBAAkB,KAAK,GAAG,KAAK,SAAS;AAAA;AAAA,IAC1C;AAAA;AAAA,MAEE,OAAO,UAAU,YACjB,QAAQ;AAAA,MACR;AAEA,YAAM,SAAS,IAAI,KAAK;AACxB,wBAAkB,KAAK,GAAG,KAAK,MAAM;AAAA;AAAA,IACvC,OAAO;AAEL,YAAM,SAAS,OAAO;AACtB,wBAAkB,KAAK,GAAG,KAAK,MAAM;AAAA;AAAA,IACvC;AAAA,EACF;AAEA,SAAO;AACT;AAKO,MAAM,cAAc,CAAC,sBAA0C;AACpE,QAAM,mBAA6B,CAAC;AAGpC,MAAI,KAAC,sBAAW,QAAQ,GAAG;AACzB,6BAAU,UAAU,EAAE,WAAW,KAAK,CAAC;AAAA,EACzC;AAEA,aAAW,kBAAkB,mBAAmB;AAC9C,UAAM,gBAA+B,QAAQ,cAAc;AAC3D,UAAM,iBAAyB,cAAc;AAC7C,UAAM,iBAAyB,uBAAuB,aAAa;AAEnE,UAAM,iBAAa,qBAAQ,UAAU,GAAG,cAAc,OAAO;AAE7D,iCAAc,YAAY,cAAc;AAExC,qBAAiB,KAAK,UAAU;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,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 };
|