@intlayer/webpack 1.0.0 → 1.0.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/index.cjs +16 -21
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/scripts/bundle.cjs +17 -20
- package/dist/cjs/scripts/bundle.d.ts +7 -0
- package/dist/cjs/scripts/index.cjs +11 -19
- package/dist/cjs/scripts/index.d.ts +3 -0
- package/dist/cjs/scripts/startServer.cjs +10 -18
- package/dist/cjs/scripts/startServer.d.ts +5 -0
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +14 -30
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.d.ts +6 -0
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs +9 -21
- package/dist/cjs/transpiler/dictionary_to_main/index.d.ts +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +37 -33
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +7 -0
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +16 -28
- package/dist/cjs/transpiler/dictionary_to_type/createType.d.ts +42 -0
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs +11 -27
- package/dist/cjs/transpiler/dictionary_to_type/index.d.ts +3 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs +8 -13
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.ts +44 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs +13 -33
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.d.ts +4 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs +11 -14
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.d.ts +8 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs +14 -30
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.ts +6 -0
- package/dist/cjs/utils.cjs +10 -18
- package/dist/cjs/utils.d.ts +4 -0
- package/dist/cjs/webpack-plugin.cjs +21 -40
- package/dist/cjs/webpack-plugin.d.ts +15 -0
- package/dist/cjs/webpack.config.cjs +34 -47
- package/dist/cjs/webpack.config.d.ts +7 -0
- package/dist/esm/index.d.mts +6 -9
- package/dist/esm/index.mjs +5 -5
- package/dist/esm/scripts/bundle.d.mts +2 -2
- package/dist/esm/scripts/bundle.mjs +13 -8
- package/dist/esm/scripts/index.d.mts +3 -3
- package/dist/esm/scripts/index.mjs +3 -3
- package/dist/esm/scripts/startServer.d.mts +1 -1
- package/dist/esm/scripts/startServer.mjs +5 -3
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +7 -7
- package/dist/esm/transpiler/dictionary_to_main/index.d.mts +1 -1
- package/dist/esm/transpiler/dictionary_to_main/index.mjs +2 -2
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +31 -12
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +1 -1
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +14 -12
- package/dist/esm/transpiler/dictionary_to_type/index.d.mts +3 -10
- package/dist/esm/transpiler/dictionary_to_type/index.mjs +3 -3
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.mts +1 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs +4 -2
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.d.mts +4 -4
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs +4 -4
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.d.mts +2 -4
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs +7 -3
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.mts +1 -3
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs +6 -4
- package/dist/esm/utils.mjs +6 -6
- package/dist/esm/webpack-plugin.d.mts +10 -10
- package/dist/esm/webpack-plugin.mjs +16 -20
- package/dist/esm/webpack.config.d.mts +2 -2
- package/dist/esm/webpack.config.mjs +29 -23
- package/package.json +7 -7
- package/src/transpiler/dictionary_to_type/createModuleAugmentation.ts +30 -5
|
@@ -8,40 +8,38 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
12
|
for (let key of __getOwnPropNames(from))
|
|
13
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
|
-
});
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
15
|
}
|
|
19
16
|
return to;
|
|
20
17
|
};
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
19
|
var webpack_config_exports = {};
|
|
24
20
|
__export(webpack_config_exports, {
|
|
25
21
|
default: () => webpack_config_default,
|
|
26
22
|
devServerConfig: () => devServerConfig,
|
|
27
|
-
webpackConfig: () => webpackConfig
|
|
23
|
+
webpackConfig: () => webpackConfig
|
|
28
24
|
});
|
|
29
25
|
module.exports = __toCommonJS(webpack_config_exports);
|
|
30
26
|
var import_path = require("path");
|
|
31
27
|
var import_config = require("@intlayer/config");
|
|
32
28
|
var import_glob = require("glob");
|
|
33
|
-
var import_utils = require(
|
|
34
|
-
var import_webpack_plugin = require(
|
|
29
|
+
var import_utils = require('./utils.cjs');
|
|
30
|
+
var import_webpack_plugin = require('./webpack-plugin.cjs');
|
|
35
31
|
const { content } = (0, import_config.getConfiguration)({
|
|
36
|
-
verbose: true
|
|
32
|
+
verbose: true
|
|
37
33
|
});
|
|
38
34
|
const { bundleDir, bundleFileExtension, watchedFilesPatternWithPath } = content;
|
|
39
|
-
const getEntry = () =>
|
|
40
|
-
(
|
|
35
|
+
const getEntry = () => (0, import_glob.sync)(watchedFilesPatternWithPath).reduce(
|
|
36
|
+
(obj, el) => {
|
|
41
37
|
const hash = (0, import_utils.getFileHash)(el);
|
|
42
38
|
obj[hash] = el;
|
|
43
39
|
return obj;
|
|
44
|
-
},
|
|
40
|
+
},
|
|
41
|
+
{}
|
|
42
|
+
);
|
|
45
43
|
const devServerConfig = {
|
|
46
44
|
// Enable hot module replacement
|
|
47
45
|
hot: true,
|
|
@@ -59,12 +57,12 @@ const devServerConfig = {
|
|
|
59
57
|
// watchedFilesPatternWithPath,
|
|
60
58
|
devMiddleware: {
|
|
61
59
|
// Enable write to disk to reuse the output
|
|
62
|
-
writeToDisk: true
|
|
60
|
+
writeToDisk: true
|
|
63
61
|
},
|
|
64
62
|
// Content base
|
|
65
63
|
static: {
|
|
66
|
-
directory: bundleDir
|
|
67
|
-
}
|
|
64
|
+
directory: bundleDir
|
|
65
|
+
}
|
|
68
66
|
};
|
|
69
67
|
const webpackConfig = {
|
|
70
68
|
// Define the environment mode (development or production)
|
|
@@ -80,7 +78,7 @@ const webpackConfig = {
|
|
|
80
78
|
library: "IntlLayerContent",
|
|
81
79
|
libraryTarget: "umd",
|
|
82
80
|
filename: `[name]${bundleFileExtension}`,
|
|
83
|
-
path: bundleDir
|
|
81
|
+
path: bundleDir
|
|
84
82
|
},
|
|
85
83
|
cache: false,
|
|
86
84
|
// devtool: 'source-map',
|
|
@@ -98,12 +96,7 @@ const webpackConfig = {
|
|
|
98
96
|
// In the project node_modules
|
|
99
97
|
(0, import_path.join)(process.cwd(), "node_modules"),
|
|
100
98
|
// In the project node_modules
|
|
101
|
-
(0, import_path.join)(
|
|
102
|
-
process.cwd(),
|
|
103
|
-
"node_modules",
|
|
104
|
-
"intlayer-cli",
|
|
105
|
-
"node_modules"
|
|
106
|
-
),
|
|
99
|
+
(0, import_path.join)(process.cwd(), "node_modules", "intlayer-cli", "node_modules"),
|
|
107
100
|
// Or via another project by importing intlayer
|
|
108
101
|
(0, import_path.join)(
|
|
109
102
|
process.cwd(),
|
|
@@ -112,9 +105,9 @@ const webpackConfig = {
|
|
|
112
105
|
"node_modules",
|
|
113
106
|
"@intlayer/webpack",
|
|
114
107
|
"node_modules"
|
|
115
|
-
)
|
|
108
|
+
)
|
|
116
109
|
// Or via another project by importing intlayer
|
|
117
|
-
]
|
|
110
|
+
]
|
|
118
111
|
},
|
|
119
112
|
resolveLoader: {
|
|
120
113
|
// Configure how Webpack finds `loader` modules.
|
|
@@ -122,12 +115,7 @@ const webpackConfig = {
|
|
|
122
115
|
// To find the loader module
|
|
123
116
|
(0, import_path.join)(process.cwd(), "node_modules"),
|
|
124
117
|
// In the project node_modules
|
|
125
|
-
(0, import_path.join)(
|
|
126
|
-
process.cwd(),
|
|
127
|
-
"node_modules",
|
|
128
|
-
"@intlayer/webpack",
|
|
129
|
-
"node_modules"
|
|
130
|
-
),
|
|
118
|
+
(0, import_path.join)(process.cwd(), "node_modules", "@intlayer/webpack", "node_modules"),
|
|
131
119
|
// Or via another project by importing @intlayer/webpack
|
|
132
120
|
(0, import_path.join)(
|
|
133
121
|
process.cwd(),
|
|
@@ -136,9 +124,9 @@ const webpackConfig = {
|
|
|
136
124
|
"node_modules",
|
|
137
125
|
"@intlayer/webpack",
|
|
138
126
|
"node_modules"
|
|
139
|
-
)
|
|
127
|
+
)
|
|
140
128
|
// Or via another project by importing intlayer
|
|
141
|
-
]
|
|
129
|
+
]
|
|
142
130
|
// roots: [
|
|
143
131
|
// join(process.cwd()), // Project context
|
|
144
132
|
// join(process.cwd(), '@intlayer/webpack'), // Or via CLI in another project
|
|
@@ -149,7 +137,7 @@ const webpackConfig = {
|
|
|
149
137
|
rules: [
|
|
150
138
|
{
|
|
151
139
|
test: /\.node$/,
|
|
152
|
-
loader: "node-loader"
|
|
140
|
+
loader: "node-loader"
|
|
153
141
|
},
|
|
154
142
|
// Use esbuild to compile JavaScript & TypeScript
|
|
155
143
|
{
|
|
@@ -158,23 +146,22 @@ const webpackConfig = {
|
|
|
158
146
|
loader: "esbuild-loader",
|
|
159
147
|
options: {
|
|
160
148
|
// JavaScript version to compile to
|
|
161
|
-
target: "es2015"
|
|
162
|
-
}
|
|
163
|
-
}
|
|
149
|
+
target: "es2015"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
164
152
|
// JSON files are supported natively by Webpack 5, no specific loader required
|
|
165
|
-
]
|
|
153
|
+
]
|
|
166
154
|
},
|
|
167
155
|
devServer: devServerConfig,
|
|
168
156
|
plugins: [
|
|
169
|
-
new import_webpack_plugin.IntLayerPlugin()
|
|
157
|
+
new import_webpack_plugin.IntLayerPlugin()
|
|
170
158
|
// new HotModuleReplacementPlugin()
|
|
171
|
-
]
|
|
159
|
+
]
|
|
172
160
|
};
|
|
173
161
|
var webpack_config_default = webpackConfig;
|
|
174
162
|
// Annotate the CommonJS export names for ESM import in node:
|
|
175
|
-
0 &&
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
//# sourceMappingURL=webpack.config.cjs.map
|
|
163
|
+
0 && (module.exports = {
|
|
164
|
+
devServerConfig,
|
|
165
|
+
webpackConfig
|
|
166
|
+
});
|
|
167
|
+
//# sourceMappingURL=webpack.config.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Configuration as Configuration$1 } from 'webpack';
|
|
2
|
+
import { Configuration } from 'webpack-dev-server';
|
|
3
|
+
|
|
4
|
+
declare const devServerConfig: Configuration;
|
|
5
|
+
declare const webpackConfig: Configuration$1;
|
|
6
|
+
|
|
7
|
+
export { webpackConfig as default, devServerConfig, webpackConfig };
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
export { startServer } from
|
|
2
|
-
export { bundle, watch } from
|
|
3
|
-
export { IntLayerPlugin } from
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "./webpack.config.mjs";
|
|
8
|
-
import "webpack";
|
|
9
|
-
import "webpack-dev-server";
|
|
1
|
+
export { startServer } from './scripts/startServer.mjs';
|
|
2
|
+
export { bundle, watch } from './scripts/bundle.mjs';
|
|
3
|
+
export { IntLayerPlugin } from './webpack-plugin.mjs';
|
|
4
|
+
export { devServerConfig, default as webpackConfig } from './webpack.config.mjs';
|
|
5
|
+
import 'webpack';
|
|
6
|
+
import 'webpack-dev-server';
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { bundle, startServer, watch } from
|
|
2
|
-
import { IntLayerPlugin } from
|
|
3
|
-
import { devServerConfig, webpackConfig } from
|
|
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
4
|
export {
|
|
5
5
|
IntLayerPlugin,
|
|
6
6
|
bundle,
|
|
7
7
|
devServerConfig,
|
|
8
8
|
startServer,
|
|
9
9
|
watch,
|
|
10
|
-
webpackConfig
|
|
10
|
+
webpackConfig
|
|
11
11
|
};
|
|
12
|
-
//# sourceMappingURL=index.mjs.map
|
|
12
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as webpack from
|
|
2
|
-
import { Compiler } from
|
|
1
|
+
import * as webpack from 'webpack';
|
|
2
|
+
import { Compiler } from 'webpack';
|
|
3
3
|
|
|
4
4
|
declare const bundle: (compiler: Compiler) => void;
|
|
5
5
|
declare const watch: (compiler: Compiler) => webpack.Watching;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const bundle = (compiler) =>
|
|
1
|
+
const bundle = (compiler) => (
|
|
2
2
|
// Run the compiler
|
|
3
3
|
compiler.run((err, stats) => {
|
|
4
4
|
if (err) {
|
|
@@ -10,11 +10,12 @@ const bundle = (compiler) =>
|
|
|
10
10
|
console.info(
|
|
11
11
|
stats.toString({
|
|
12
12
|
// Add options here to customize the stats output
|
|
13
|
-
colors: true
|
|
13
|
+
colors: true
|
|
14
14
|
})
|
|
15
15
|
);
|
|
16
|
-
})
|
|
17
|
-
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
const watch = (compiler) => (
|
|
18
19
|
// Run the compiler
|
|
19
20
|
compiler.watch({}, (err, stats) => {
|
|
20
21
|
if (err) {
|
|
@@ -26,10 +27,14 @@ const watch = (compiler) =>
|
|
|
26
27
|
console.info(
|
|
27
28
|
stats.toString({
|
|
28
29
|
// Add options here to customize the stats output
|
|
29
|
-
colors: true
|
|
30
|
+
colors: true
|
|
30
31
|
})
|
|
31
32
|
);
|
|
32
33
|
console.info("Watch IntLayer content...");
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
export {
|
|
37
|
+
bundle,
|
|
38
|
+
watch
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=bundle.mjs.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { startServer } from
|
|
2
|
-
export { bundle, watch } from
|
|
3
|
-
import
|
|
1
|
+
export { startServer } from './startServer.mjs';
|
|
2
|
+
export { bundle, watch } from './bundle.mjs';
|
|
3
|
+
import 'webpack';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export * from './startServer.mjs';
|
|
2
|
+
export * from './bundle.mjs';
|
|
3
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { devServerConfig } from
|
|
1
|
+
import { devServerConfig } from '../webpack.config.mjs';
|
|
2
2
|
const WebpackDevServer = require("webpack-dev-server");
|
|
3
3
|
const startServer = (compiler) => {
|
|
4
4
|
const devServer = new WebpackDevServer(devServerConfig, compiler);
|
|
@@ -6,5 +6,7 @@ const startServer = (compiler) => {
|
|
|
6
6
|
console.info("Webpack Dev Server is running...");
|
|
7
7
|
});
|
|
8
8
|
};
|
|
9
|
-
export {
|
|
10
|
-
|
|
9
|
+
export {
|
|
10
|
+
startServer
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=startServer.mjs.map
|
|
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
|
2
2
|
import { basename, extname, relative, resolve } from "path";
|
|
3
3
|
import { getConfiguration } from "@intlayer/config";
|
|
4
4
|
import { sync } from "glob";
|
|
5
|
-
import { getFileHash } from
|
|
5
|
+
import { getFileHash } from '../../utils.mjs';
|
|
6
6
|
const { content } = getConfiguration();
|
|
7
7
|
const { dictionariesDir, mainDir } = content;
|
|
8
8
|
const generateDictionaryListContent = (dictionaries, format = "esm") => {
|
|
@@ -11,7 +11,7 @@ const generateDictionaryListContent = (dictionaries, format = "esm") => {
|
|
|
11
11
|
relativePath: relative(mainDir, dictionaryPath),
|
|
12
12
|
id: basename(dictionaryPath, extname(dictionaryPath)),
|
|
13
13
|
// Get the base name as the dictionary id
|
|
14
|
-
hash: `_${getFileHash(dictionaryPath)}
|
|
14
|
+
hash: `_${getFileHash(dictionaryPath)}`
|
|
15
15
|
// Get the hash of the dictionary to avoid conflicts
|
|
16
16
|
}));
|
|
17
17
|
dictionariesRef.forEach((dictionary) => {
|
|
@@ -23,9 +23,7 @@ const generateDictionaryListContent = (dictionaries, format = "esm") => {
|
|
|
23
23
|
`;
|
|
24
24
|
});
|
|
25
25
|
content2 += "\n";
|
|
26
|
-
const formattedDictionaryMap = dictionariesRef
|
|
27
|
-
.map((dictionary) => `"${dictionary.id}": ${dictionary.hash}`)
|
|
28
|
-
.join(",\n");
|
|
26
|
+
const formattedDictionaryMap = dictionariesRef.map((dictionary) => `"${dictionary.id}": ${dictionary.hash}`).join(",\n");
|
|
29
27
|
if (format === "esm")
|
|
30
28
|
content2 += `export default {
|
|
31
29
|
${formattedDictionaryMap}
|
|
@@ -48,5 +46,7 @@ const createDictionaryList = () => {
|
|
|
48
46
|
const esmContent = generateDictionaryListContent(dictionaries, "esm");
|
|
49
47
|
writeFileSync(resolve(mainDir, "dictionaries.mjs"), esmContent);
|
|
50
48
|
};
|
|
51
|
-
export {
|
|
52
|
-
|
|
49
|
+
export {
|
|
50
|
+
createDictionaryList
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=createDictionaryList.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createDictionaryList } from
|
|
1
|
+
export { createDictionaryList } from './createDictionaryList.mjs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export * from './createDictionaryList.mjs';
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
2
|
import { basename, join, relative } from "path";
|
|
3
|
-
import { getConfiguration } from "@intlayer/config";
|
|
3
|
+
import { Locales, getConfiguration } from "@intlayer/config";
|
|
4
4
|
import { sync } from "glob";
|
|
5
|
-
import { getFileHash, transformToCamelCase } from
|
|
6
|
-
const { content } = getConfiguration();
|
|
5
|
+
import { getFileHash, transformToCamelCase } from '../../utils.mjs';
|
|
6
|
+
const { content, internationalization } = getConfiguration();
|
|
7
7
|
const { typesDir, moduleAugmentationDir } = content;
|
|
8
|
+
const { locales } = internationalization;
|
|
8
9
|
const getTypeName = (id) => transformToCamelCase(`${id}Content`);
|
|
9
10
|
const generateTypeIndexContent = (typeFiles) => {
|
|
10
|
-
let content2 = "
|
|
11
|
+
let content2 = "/* eslint-disable */\nimport 'intlayer';\nimport { Locales } from '@intlayer/config'\n";
|
|
11
12
|
const dictionariesRef = typeFiles.map((dictionaryPath) => ({
|
|
12
13
|
relativePath: relative(moduleAugmentationDir, dictionaryPath),
|
|
13
14
|
id: basename(dictionaryPath, ".d.ts"),
|
|
14
15
|
// Get the base name as the dictionary id
|
|
15
|
-
hash: `_${getFileHash(dictionaryPath)}
|
|
16
|
+
hash: `_${getFileHash(dictionaryPath)}`
|
|
16
17
|
// Get the hash of the dictionary to avoid conflicts
|
|
17
18
|
}));
|
|
18
19
|
dictionariesRef.forEach((dictionary) => {
|
|
@@ -21,14 +22,29 @@ const generateTypeIndexContent = (typeFiles) => {
|
|
|
21
22
|
`;
|
|
22
23
|
});
|
|
23
24
|
content2 += "\n";
|
|
24
|
-
const formattedDictionaryMap = dictionariesRef
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const formattedDictionaryMap = dictionariesRef.map((dictionary) => ` "${dictionary.id}": ${dictionary.hash};`).join("\n");
|
|
26
|
+
const formatLocales = locales.map((locale) => {
|
|
27
|
+
for (const key in Locales) {
|
|
28
|
+
if (Locales[key] === locale) {
|
|
29
|
+
return ` ${key} = '${locale}'`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}).join(",\n");
|
|
27
33
|
content2 += `declare module 'intlayer' {
|
|
28
|
-
|
|
34
|
+
`;
|
|
35
|
+
content2 += ` interface IntlayerDictionaryTypesConnector {
|
|
29
36
|
${formattedDictionaryMap}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
`;
|
|
40
|
+
content2 += ` enum ConfigLocales {
|
|
41
|
+
${formatLocales}
|
|
30
42
|
};
|
|
31
|
-
|
|
43
|
+
|
|
44
|
+
`;
|
|
45
|
+
content2 += ` interface IConfigLocales<Content> extends Record<ConfigLocales, Content> {}
|
|
46
|
+
`;
|
|
47
|
+
content2 += `};`;
|
|
32
48
|
return content2;
|
|
33
49
|
};
|
|
34
50
|
const createModuleAugmentation = () => {
|
|
@@ -39,5 +55,8 @@ const createModuleAugmentation = () => {
|
|
|
39
55
|
const tsContent = generateTypeIndexContent(dictionaries);
|
|
40
56
|
writeFileSync(join(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
|
|
41
57
|
};
|
|
42
|
-
export {
|
|
43
|
-
|
|
58
|
+
export {
|
|
59
|
+
createModuleAugmentation,
|
|
60
|
+
getTypeName
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=createModuleAugmentation.mjs.map
|
|
@@ -1 +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
|
|
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,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,MAAM,gBAAgB;AACzC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,YAAY;AACrB,SAAS,aAAa,4BAA4B;AAElD,MAAM,EAAE,SAAS,qBAAqB,IAAI,iBAAiB;AAC3D,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAC5C,MAAM,EAAE,QAAQ,IAAI;AAEb,MAAM,cAAc,CAAC,OAC1B,qBAAqB,GAAG,EAAE,SAAS;AAKrC,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WACF;AAEF,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,QAAM,gBAAgB,QACnB,IAAI,CAAC,WAAW;AACf,eAAW,OAAO,SAAS;AACzB,UAAI,QAAQ,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,CAAC,WAAW,qBAAqB,GAAG;AACtC,cAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,eAAyB,KAAK,GAAG,QAAQ,YAAY;AAG3D,QAAM,YAAY,yBAAyB,YAAY;AACvD,gBAAc,KAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
2
|
import { resolve } from "path";
|
|
3
3
|
import { getConfiguration } from "@intlayer/config";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
NodeType
|
|
6
|
+
} from "@intlayer/core";
|
|
7
|
+
import { getTypeName } from './createModuleAugmentation.mjs';
|
|
6
8
|
const { content, internationalization } = getConfiguration();
|
|
7
9
|
const { typesDir } = content;
|
|
8
10
|
const generateTypeScriptType = (obj) => {
|
|
@@ -20,24 +22,21 @@ const generateTypeScriptTypeContent = (obj) => {
|
|
|
20
22
|
const nodeType = value.nodeType;
|
|
21
23
|
if (
|
|
22
24
|
// Check if the value is a typed node
|
|
23
|
-
typeof value === "object" &&
|
|
24
|
-
nodeType === NodeType.Translation
|
|
25
|
+
typeof value === "object" && nodeType === NodeType.Translation
|
|
25
26
|
) {
|
|
26
27
|
const tsType = typeof value[internationalization.defaultLocale];
|
|
27
28
|
typeDefinition += ` ${key}: ${tsType},
|
|
28
29
|
`;
|
|
29
30
|
} else if (
|
|
30
31
|
// Check if the value is a typed node
|
|
31
|
-
typeof value === "object" &&
|
|
32
|
-
nodeType === NodeType.Enumeration
|
|
32
|
+
typeof value === "object" && nodeType === NodeType.Enumeration
|
|
33
33
|
) {
|
|
34
34
|
const tsType = typeof value[internationalization.defaultLocale];
|
|
35
35
|
typeDefinition += ` ${key}: (quantity: number) => ${tsType},
|
|
36
36
|
`;
|
|
37
37
|
} else if (
|
|
38
38
|
// Check if the value is a nested object
|
|
39
|
-
typeof value === "object" &&
|
|
40
|
-
!Array.isArray(value)
|
|
39
|
+
typeof value === "object" && !Array.isArray(value)
|
|
41
40
|
) {
|
|
42
41
|
const nestedType = generateTypeScriptTypeContent(value);
|
|
43
42
|
typeDefinition += ` ${key}: {${nestedType}},
|
|
@@ -51,8 +50,7 @@ const generateTypeScriptTypeContent = (obj) => {
|
|
|
51
50
|
`;
|
|
52
51
|
} else if (
|
|
53
52
|
// Check if the value is an 'id'
|
|
54
|
-
typeof value === "string" &&
|
|
55
|
-
key === "id"
|
|
53
|
+
typeof value === "string" && key === "id"
|
|
56
54
|
) {
|
|
57
55
|
const tsType = `"${value}"`;
|
|
58
56
|
typeDefinition += ` ${key}: ${tsType},
|
|
@@ -80,5 +78,9 @@ const createTypes = (dictionariesPaths) => {
|
|
|
80
78
|
}
|
|
81
79
|
return resultTypesPaths;
|
|
82
80
|
};
|
|
83
|
-
export {
|
|
84
|
-
|
|
81
|
+
export {
|
|
82
|
+
createTypes,
|
|
83
|
+
generateTypeScriptType,
|
|
84
|
+
generateTypeScriptTypeContent
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=createType.mjs.map
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./createModuleAugmentation.mjs";
|
|
5
|
-
export {
|
|
6
|
-
createTypes,
|
|
7
|
-
generateTypeScriptType,
|
|
8
|
-
generateTypeScriptTypeContent,
|
|
9
|
-
} from "./createType.mjs";
|
|
10
|
-
import "@intlayer/core";
|
|
1
|
+
export { createModuleAugmentation, getTypeName } from './createModuleAugmentation.mjs';
|
|
2
|
+
export { createTypes, generateTypeScriptType, generateTypeScriptTypeContent } from './createType.mjs';
|
|
3
|
+
import '@intlayer/core';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export * from './createModuleAugmentation.mjs';
|
|
2
|
+
export * from './createType.mjs';
|
|
3
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -15,5 +15,7 @@ const extractObjectsWithId = (input) => {
|
|
|
15
15
|
search(input, results);
|
|
16
16
|
return results;
|
|
17
17
|
};
|
|
18
|
-
export {
|
|
19
|
-
|
|
18
|
+
export {
|
|
19
|
+
extractObjectsWithId
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=extractNestedJSON.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { extractObjectsWithId } from
|
|
2
|
-
export { processModule } from
|
|
3
|
-
export { transpileBundledCode } from
|
|
4
|
-
import
|
|
1
|
+
export { extractObjectsWithId } from './extractNestedJSON.mjs';
|
|
2
|
+
export { processModule } from './processModule.mjs';
|
|
3
|
+
export { transpileBundledCode } from './transpileBundledCode.mjs';
|
|
4
|
+
import '@intlayer/core';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export * from './extractNestedJSON.mjs';
|
|
2
|
+
export * from './processModule.mjs';
|
|
3
|
+
export * from './transpileBundledCode.mjs';
|
|
4
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { ContentModule } from
|
|
1
|
+
import { ContentModule } from '@intlayer/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Function to load, process the module and return the Intlayer ContentModule from the module file
|
|
5
5
|
*/
|
|
6
|
-
declare const processModule: (
|
|
7
|
-
file: string
|
|
8
|
-
) => Promise<ContentModule | undefined>;
|
|
6
|
+
declare const processModule: (file: string) => Promise<ContentModule | undefined>;
|
|
9
7
|
|
|
10
8
|
export { processModule };
|
|
@@ -9,7 +9,9 @@ const processFunctionResults = async (entry) => {
|
|
|
9
9
|
for (const key of Object.keys(entry)) {
|
|
10
10
|
const field = entry?.[key];
|
|
11
11
|
if (typeof field === "object") {
|
|
12
|
-
result[key] = await processFunctionResults(
|
|
12
|
+
result[key] = await processFunctionResults(
|
|
13
|
+
field
|
|
14
|
+
);
|
|
13
15
|
}
|
|
14
16
|
if (typeof field === "function") {
|
|
15
17
|
const promise = (async () => {
|
|
@@ -35,5 +37,7 @@ const processModule = async (file) => {
|
|
|
35
37
|
console.error("Error processing module:", error);
|
|
36
38
|
}
|
|
37
39
|
};
|
|
38
|
-
export {
|
|
39
|
-
|
|
40
|
+
export {
|
|
41
|
+
processModule
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=processModule.mjs.map
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This function transpile the bundled code to to make dictionaries as JSON files
|
|
3
3
|
*/
|
|
4
|
-
declare const transpileBundledCode: (
|
|
5
|
-
bundledEntriesPaths: string[] | string
|
|
6
|
-
) => Promise<string[]>;
|
|
4
|
+
declare const transpileBundledCode: (bundledEntriesPaths: string[] | string) => Promise<string[]>;
|
|
7
5
|
|
|
8
6
|
export { transpileBundledCode };
|
|
@@ -2,8 +2,8 @@ import { existsSync } from "fs";
|
|
|
2
2
|
import { mkdir, writeFile } from "fs/promises";
|
|
3
3
|
import { resolve } from "path";
|
|
4
4
|
import { getConfiguration } from "@intlayer/config";
|
|
5
|
-
import { extractObjectsWithId } from
|
|
6
|
-
import { processModule } from
|
|
5
|
+
import { extractObjectsWithId } from './extractNestedJSON.mjs';
|
|
6
|
+
import { processModule } from './processModule.mjs';
|
|
7
7
|
const { content } = getConfiguration();
|
|
8
8
|
const { dictionariesDir, bundleFileExtension } = content;
|
|
9
9
|
const loadBundledModule = async (bundledEntryPath) => {
|
|
@@ -66,5 +66,7 @@ const transpileBundledCode = async (bundledEntriesPaths) => {
|
|
|
66
66
|
}
|
|
67
67
|
return resultDictionariesPaths;
|
|
68
68
|
};
|
|
69
|
-
export {
|
|
70
|
-
|
|
69
|
+
export {
|
|
70
|
+
transpileBundledCode
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=transpileBundledCode.mjs.map
|