@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.
Files changed (65) hide show
  1. package/dist/cjs/index.cjs +16 -21
  2. package/dist/cjs/index.d.ts +6 -0
  3. package/dist/cjs/scripts/bundle.cjs +17 -20
  4. package/dist/cjs/scripts/bundle.d.ts +7 -0
  5. package/dist/cjs/scripts/index.cjs +11 -19
  6. package/dist/cjs/scripts/index.d.ts +3 -0
  7. package/dist/cjs/scripts/startServer.cjs +10 -18
  8. package/dist/cjs/scripts/startServer.d.ts +5 -0
  9. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +14 -30
  10. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.d.ts +6 -0
  11. package/dist/cjs/transpiler/dictionary_to_main/index.cjs +9 -21
  12. package/dist/cjs/transpiler/dictionary_to_main/index.d.ts +1 -0
  13. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +37 -33
  14. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -1
  15. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.d.ts +7 -0
  16. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +16 -28
  17. package/dist/cjs/transpiler/dictionary_to_type/createType.d.ts +42 -0
  18. package/dist/cjs/transpiler/dictionary_to_type/index.cjs +11 -27
  19. package/dist/cjs/transpiler/dictionary_to_type/index.d.ts +3 -0
  20. package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs +8 -13
  21. package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.ts +44 -0
  22. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs +13 -33
  23. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.d.ts +4 -0
  24. package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs +11 -14
  25. package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.d.ts +8 -0
  26. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs +14 -30
  27. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.ts +6 -0
  28. package/dist/cjs/utils.cjs +10 -18
  29. package/dist/cjs/utils.d.ts +4 -0
  30. package/dist/cjs/webpack-plugin.cjs +21 -40
  31. package/dist/cjs/webpack-plugin.d.ts +15 -0
  32. package/dist/cjs/webpack.config.cjs +34 -47
  33. package/dist/cjs/webpack.config.d.ts +7 -0
  34. package/dist/esm/index.d.mts +6 -9
  35. package/dist/esm/index.mjs +5 -5
  36. package/dist/esm/scripts/bundle.d.mts +2 -2
  37. package/dist/esm/scripts/bundle.mjs +13 -8
  38. package/dist/esm/scripts/index.d.mts +3 -3
  39. package/dist/esm/scripts/index.mjs +3 -3
  40. package/dist/esm/scripts/startServer.d.mts +1 -1
  41. package/dist/esm/scripts/startServer.mjs +5 -3
  42. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +7 -7
  43. package/dist/esm/transpiler/dictionary_to_main/index.d.mts +1 -1
  44. package/dist/esm/transpiler/dictionary_to_main/index.mjs +2 -2
  45. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +31 -12
  46. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -1
  47. package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +1 -1
  48. package/dist/esm/transpiler/dictionary_to_type/createType.mjs +14 -12
  49. package/dist/esm/transpiler/dictionary_to_type/index.d.mts +3 -10
  50. package/dist/esm/transpiler/dictionary_to_type/index.mjs +3 -3
  51. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.mts +1 -1
  52. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs +4 -2
  53. package/dist/esm/transpiler/intlater_module_to_dictionary/index.d.mts +4 -4
  54. package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs +4 -4
  55. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.d.mts +2 -4
  56. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs +7 -3
  57. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.mts +1 -3
  58. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs +6 -4
  59. package/dist/esm/utils.mjs +6 -6
  60. package/dist/esm/webpack-plugin.d.mts +10 -10
  61. package/dist/esm/webpack-plugin.mjs +16 -20
  62. package/dist/esm/webpack.config.d.mts +2 -2
  63. package/dist/esm/webpack.config.mjs +29 -23
  64. package/package.json +7 -7
  65. package/src/transpiler/dictionary_to_type/createModuleAugmentation.ts +30 -5
@@ -8,18 +8,14 @@ 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 ((from && typeof from === "object") || typeof from === "function") {
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 src_exports = {};
24
20
  __export(src_exports, {
25
21
  IntLayerPlugin: () => import_webpack_plugin.IntLayerPlugin,
@@ -27,20 +23,19 @@ __export(src_exports, {
27
23
  devServerConfig: () => import_webpack.devServerConfig,
28
24
  startServer: () => import_scripts.startServer,
29
25
  watch: () => import_scripts.watch,
30
- webpackConfig: () => import_webpack.webpackConfig,
26
+ webpackConfig: () => import_webpack.webpackConfig
31
27
  });
32
28
  module.exports = __toCommonJS(src_exports);
33
- var import_scripts = require("./scripts/index.cjs");
34
- var import_webpack_plugin = require("./webpack-plugin.cjs");
35
- var import_webpack = require("./webpack.config.cjs");
29
+ var import_scripts = require('./scripts/index.cjs');
30
+ var import_webpack_plugin = require('./webpack-plugin.cjs');
31
+ var import_webpack = require('./webpack.config.cjs');
36
32
  // Annotate the CommonJS export names for ESM import in node:
37
- 0 &&
38
- (module.exports = {
39
- IntLayerPlugin,
40
- bundle,
41
- devServerConfig,
42
- startServer,
43
- watch,
44
- webpackConfig,
45
- });
46
- //# sourceMappingURL=index.cjs.map
33
+ 0 && (module.exports = {
34
+ IntLayerPlugin,
35
+ bundle,
36
+ devServerConfig,
37
+ startServer,
38
+ watch,
39
+ webpackConfig
40
+ });
41
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,6 @@
1
+ export { startServer } from './scripts/startServer.js';
2
+ export { bundle, watch } from './scripts/bundle.js';
3
+ export { IntLayerPlugin } from './webpack-plugin.js';
4
+ export { devServerConfig, default as webpackConfig } from './webpack.config.js';
5
+ import 'webpack';
6
+ import 'webpack-dev-server';
@@ -8,25 +8,21 @@ 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 ((from && typeof from === "object") || typeof from === "function") {
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 bundle_exports = {};
24
20
  __export(bundle_exports, {
25
21
  bundle: () => bundle,
26
- watch: () => watch,
22
+ watch: () => watch
27
23
  });
28
24
  module.exports = __toCommonJS(bundle_exports);
29
- const bundle = (compiler) =>
25
+ const bundle = (compiler) => (
30
26
  // Run the compiler
31
27
  compiler.run((err, stats) => {
32
28
  if (err) {
@@ -38,11 +34,12 @@ const bundle = (compiler) =>
38
34
  console.info(
39
35
  stats.toString({
40
36
  // Add options here to customize the stats output
41
- colors: true,
37
+ colors: true
42
38
  })
43
39
  );
44
- });
45
- const watch = (compiler) =>
40
+ })
41
+ );
42
+ const watch = (compiler) => (
46
43
  // Run the compiler
47
44
  compiler.watch({}, (err, stats) => {
48
45
  if (err) {
@@ -54,15 +51,15 @@ const watch = (compiler) =>
54
51
  console.info(
55
52
  stats.toString({
56
53
  // Add options here to customize the stats output
57
- colors: true,
54
+ colors: true
58
55
  })
59
56
  );
60
57
  console.info("Watch IntLayer content...");
61
- });
58
+ })
59
+ );
62
60
  // Annotate the CommonJS export names for ESM import in node:
63
- 0 &&
64
- (module.exports = {
65
- bundle,
66
- watch,
67
- });
68
- //# sourceMappingURL=bundle.cjs.map
61
+ 0 && (module.exports = {
62
+ bundle,
63
+ watch
64
+ });
65
+ //# sourceMappingURL=bundle.cjs.map
@@ -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 };
@@ -4,30 +4,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __copyProps = (to, from, except, desc) => {
7
- if ((from && typeof from === "object") || typeof from === "function") {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
8
  for (let key of __getOwnPropNames(from))
9
9
  if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, {
11
- get: () => from[key],
12
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
13
- });
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
11
  }
15
12
  return to;
16
13
  };
17
- var __reExport = (target, mod, secondTarget) => (
18
- __copyProps(target, mod, "default"),
19
- secondTarget && __copyProps(secondTarget, mod, "default")
20
- );
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
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);
23
16
  var scripts_exports = {};
24
17
  module.exports = __toCommonJS(scripts_exports);
25
- __reExport(scripts_exports, require("./startServer.cjs"), module.exports);
26
- __reExport(scripts_exports, require("./bundle.cjs"), module.exports);
18
+ __reExport(scripts_exports, require('./startServer.cjs'), module.exports);
19
+ __reExport(scripts_exports, require('./bundle.cjs'), module.exports);
27
20
  // Annotate the CommonJS export names for ESM import in node:
28
- 0 &&
29
- (module.exports = {
30
- ...require("./startServer.cjs"),
31
- ...require("./bundle.cjs"),
32
- });
33
- //# sourceMappingURL=index.cjs.map
21
+ 0 && (module.exports = {
22
+ ...require('./startServer.cjs'),
23
+ ...require('./bundle.cjs')
24
+ });
25
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,3 @@
1
+ export { startServer } from './startServer.js';
2
+ export { bundle, watch } from './bundle.js';
3
+ import 'webpack';
@@ -8,37 +8,29 @@ 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 ((from && typeof from === "object") || typeof from === "function") {
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 startServer_exports = {};
24
20
  __export(startServer_exports, {
25
- startServer: () => startServer,
21
+ startServer: () => startServer
26
22
  });
27
23
  module.exports = __toCommonJS(startServer_exports);
28
- var import_webpack = require("../webpack.config.cjs");
24
+ var import_webpack = require('../webpack.config.cjs');
29
25
  const WebpackDevServer = require("webpack-dev-server");
30
26
  const startServer = (compiler) => {
31
- const devServer = new WebpackDevServer(
32
- import_webpack.devServerConfig,
33
- compiler
34
- );
27
+ const devServer = new WebpackDevServer(import_webpack.devServerConfig, compiler);
35
28
  devServer.startCallback(() => {
36
29
  console.info("Webpack Dev Server is running...");
37
30
  });
38
31
  };
39
32
  // Annotate the CommonJS export names for ESM import in node:
40
- 0 &&
41
- (module.exports = {
42
- startServer,
43
- });
44
- //# sourceMappingURL=startServer.cjs.map
33
+ 0 && (module.exports = {
34
+ startServer
35
+ });
36
+ //# sourceMappingURL=startServer.cjs.map
@@ -0,0 +1,5 @@
1
+ import { Compiler } from 'webpack';
2
+
3
+ declare const startServer: (compiler: Compiler) => void;
4
+
5
+ export { startServer };
@@ -8,40 +8,33 @@ 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 ((from && typeof from === "object") || typeof from === "function") {
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 createDictionaryList_exports = {};
24
20
  __export(createDictionaryList_exports, {
25
- createDictionaryList: () => createDictionaryList,
21
+ createDictionaryList: () => createDictionaryList
26
22
  });
27
23
  module.exports = __toCommonJS(createDictionaryList_exports);
28
24
  var import_fs = require("fs");
29
25
  var import_path = require("path");
30
26
  var import_config = require("@intlayer/config");
31
27
  var import_glob = require("glob");
32
- var import_utils = require("../../utils.cjs");
28
+ var import_utils = require('../../utils.cjs');
33
29
  const { content } = (0, import_config.getConfiguration)();
34
30
  const { dictionariesDir, mainDir } = content;
35
31
  const generateDictionaryListContent = (dictionaries, format = "esm") => {
36
32
  let content2 = "";
37
33
  const dictionariesRef = dictionaries.map((dictionaryPath) => ({
38
34
  relativePath: (0, import_path.relative)(mainDir, dictionaryPath),
39
- id: (0, import_path.basename)(
40
- dictionaryPath,
41
- (0, import_path.extname)(dictionaryPath)
42
- ),
35
+ id: (0, import_path.basename)(dictionaryPath, (0, import_path.extname)(dictionaryPath)),
43
36
  // Get the base name as the dictionary id
44
- hash: `_${(0, import_utils.getFileHash)(dictionaryPath)}`,
37
+ hash: `_${(0, import_utils.getFileHash)(dictionaryPath)}`
45
38
  // Get the hash of the dictionary to avoid conflicts
46
39
  }));
47
40
  dictionariesRef.forEach((dictionary) => {
@@ -53,9 +46,7 @@ const generateDictionaryListContent = (dictionaries, format = "esm") => {
53
46
  `;
54
47
  });
55
48
  content2 += "\n";
56
- const formattedDictionaryMap = dictionariesRef
57
- .map((dictionary) => `"${dictionary.id}": ${dictionary.hash}`)
58
- .join(",\n");
49
+ const formattedDictionaryMap = dictionariesRef.map((dictionary) => `"${dictionary.id}": ${dictionary.hash}`).join(",\n");
59
50
  if (format === "esm")
60
51
  content2 += `export default {
61
52
  ${formattedDictionaryMap}
@@ -74,19 +65,12 @@ const createDictionaryList = () => {
74
65
  }
75
66
  const dictionaries = (0, import_glob.sync)(`${dictionariesDir}/**/*.json`);
76
67
  const cjsContent = generateDictionaryListContent(dictionaries, "cjs");
77
- (0, import_fs.writeFileSync)(
78
- (0, import_path.resolve)(mainDir, "dictionaries.cjs"),
79
- cjsContent
80
- );
68
+ (0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, "dictionaries.cjs"), cjsContent);
81
69
  const esmContent = generateDictionaryListContent(dictionaries, "esm");
82
- (0, import_fs.writeFileSync)(
83
- (0, import_path.resolve)(mainDir, "dictionaries.mjs"),
84
- esmContent
85
- );
70
+ (0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, "dictionaries.mjs"), esmContent);
86
71
  };
87
72
  // Annotate the CommonJS export names for ESM import in node:
88
- 0 &&
89
- (module.exports = {
90
- createDictionaryList,
91
- });
92
- //# sourceMappingURL=createDictionaryList.cjs.map
73
+ 0 && (module.exports = {
74
+ createDictionaryList
75
+ });
76
+ //# sourceMappingURL=createDictionaryList.cjs.map
@@ -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 };
@@ -4,32 +4,20 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __copyProps = (to, from, except, desc) => {
7
- if ((from && typeof from === "object") || typeof from === "function") {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
8
  for (let key of __getOwnPropNames(from))
9
9
  if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, {
11
- get: () => from[key],
12
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
13
- });
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
11
  }
15
12
  return to;
16
13
  };
17
- var __reExport = (target, mod, secondTarget) => (
18
- __copyProps(target, mod, "default"),
19
- secondTarget && __copyProps(secondTarget, mod, "default")
20
- );
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
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);
23
16
  var dictionary_to_main_exports = {};
24
17
  module.exports = __toCommonJS(dictionary_to_main_exports);
25
- __reExport(
26
- dictionary_to_main_exports,
27
- require("./createDictionaryList.cjs"),
28
- module.exports
29
- );
18
+ __reExport(dictionary_to_main_exports, require('./createDictionaryList.cjs'), module.exports);
30
19
  // Annotate the CommonJS export names for ESM import in node:
31
- 0 &&
32
- (module.exports = {
33
- ...require("./createDictionaryList.cjs"),
34
- });
35
- //# sourceMappingURL=index.cjs.map
20
+ 0 && (module.exports = {
21
+ ...require('./createDictionaryList.cjs')
22
+ });
23
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ export { createDictionaryList } from './createDictionaryList.js';
@@ -8,43 +8,36 @@ 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 ((from && typeof from === "object") || typeof from === "function") {
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 createModuleAugmentation_exports = {};
24
20
  __export(createModuleAugmentation_exports, {
25
21
  createModuleAugmentation: () => createModuleAugmentation,
26
- getTypeName: () => getTypeName,
22
+ getTypeName: () => getTypeName
27
23
  });
28
24
  module.exports = __toCommonJS(createModuleAugmentation_exports);
29
25
  var import_fs = require("fs");
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("../../utils.cjs");
34
- const { content } = (0, import_config.getConfiguration)();
29
+ var import_utils = require('../../utils.cjs');
30
+ const { content, internationalization } = (0, import_config.getConfiguration)();
35
31
  const { typesDir, moduleAugmentationDir } = content;
36
- const getTypeName = (id) =>
37
- (0, import_utils.transformToCamelCase)(`${id}Content`);
32
+ const { locales } = internationalization;
33
+ const getTypeName = (id) => (0, import_utils.transformToCamelCase)(`${id}Content`);
38
34
  const generateTypeIndexContent = (typeFiles) => {
39
- let content2 = "import 'intlayer';\n\n";
35
+ let content2 = "/* eslint-disable */\nimport 'intlayer';\nimport { Locales } from '@intlayer/config'\n";
40
36
  const dictionariesRef = typeFiles.map((dictionaryPath) => ({
41
- relativePath: (0, import_path.relative)(
42
- moduleAugmentationDir,
43
- dictionaryPath
44
- ),
37
+ relativePath: (0, import_path.relative)(moduleAugmentationDir, dictionaryPath),
45
38
  id: (0, import_path.basename)(dictionaryPath, ".d.ts"),
46
39
  // Get the base name as the dictionary id
47
- hash: `_${(0, import_utils.getFileHash)(dictionaryPath)}`,
40
+ hash: `_${(0, import_utils.getFileHash)(dictionaryPath)}`
48
41
  // Get the hash of the dictionary to avoid conflicts
49
42
  }));
50
43
  dictionariesRef.forEach((dictionary) => {
@@ -53,14 +46,29 @@ const generateTypeIndexContent = (typeFiles) => {
53
46
  `;
54
47
  });
55
48
  content2 += "\n";
56
- const formattedDictionaryMap = dictionariesRef
57
- .map((dictionary) => ` "${dictionary.id}": ${dictionary.hash};`)
58
- .join("\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");
59
57
  content2 += `declare module 'intlayer' {
60
- interface IntlayerDictionaryTypesConnector {
58
+ `;
59
+ content2 += ` interface IntlayerDictionaryTypesConnector {
61
60
  ${formattedDictionaryMap}
61
+ }
62
+
63
+ `;
64
+ content2 += ` enum ConfigLocales {
65
+ ${formatLocales}
62
66
  };
63
- };`;
67
+
68
+ `;
69
+ content2 += ` interface IConfigLocales<Content> extends Record<ConfigLocales, Content> {}
70
+ `;
71
+ content2 += `};`;
64
72
  return content2;
65
73
  };
66
74
  const createModuleAugmentation = () => {
@@ -69,15 +77,11 @@ const createModuleAugmentation = () => {
69
77
  }
70
78
  const dictionaries = (0, import_glob.sync)(`${typesDir}/**/*.d.ts`);
71
79
  const tsContent = generateTypeIndexContent(dictionaries);
72
- (0, import_fs.writeFileSync)(
73
- (0, import_path.join)(moduleAugmentationDir, "intlayer.d.ts"),
74
- tsContent
75
- );
80
+ (0, import_fs.writeFileSync)((0, import_path.join)(moduleAugmentationDir, "intlayer.d.ts"), tsContent);
76
81
  };
77
82
  // Annotate the CommonJS export names for ESM import in node:
78
- 0 &&
79
- (module.exports = {
80
- createModuleAugmentation,
81
- getTypeName,
82
- });
83
- //# sourceMappingURL=createModuleAugmentation.cjs.map
83
+ 0 && (module.exports = {
84
+ createModuleAugmentation,
85
+ getTypeName
86
+ });
87
+ //# sourceMappingURL=createModuleAugmentation.cjs.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 = \"import 'intlayer';\\n\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: relative(moduleAugmentationDir, dictionaryPath),\n id: basename(dictionaryPath, '.d.ts'), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n const typeName = getTypeName(dictionary.id);\n content += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash};`)\n .join('\\n');\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n };\\n};`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionaries: string[] = sync(`${typesDir}/**/*.d.ts`);\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionaries);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAyC;AACzC,oBAAiC;AACjC,kBAAqB;AACrB,mBAAkD;AAElD,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,UAAU,sBAAsB,IAAI;AAErC,MAAM,cAAc,CAAC,WAC1B,mCAAqB,GAAG,EAAE,SAAS;AAKrC,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WAAU;AAEd,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,kBAAc,sBAAS,uBAAuB,cAAc;AAAA,IAC5D,QAAI,sBAAS,gBAAgB,OAAO;AAAA;AAAA,IACpC,MAAM,QAAI,0BAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,UAAM,WAAW,YAAY,WAAW,EAAE;AAC1C,IAAAA,YAAW,iBAAiB,QAAQ,OAAO,WAAW,IAAI,YAAY,WAAW,YAAY;AAAA;AAAA,EAC/F,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,MAAM,WAAW,IAAI,GAAG,EACjE,KAAK,IAAI;AAeZ,EAAAA,YAAW;AAAA;AAAA,EAAgF,sBAAsB;AAAA;AAAA;AAEjH,SAAOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,KAAC,sBAAW,qBAAqB,GAAG;AACtC,6BAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,mBAAyB,kBAAK,GAAG,QAAQ,YAAY;AAG3D,QAAM,YAAY,yBAAyB,YAAY;AACvD,mCAAc,kBAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content"]}
1
+ {"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"]}
@@ -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 };
@@ -8,30 +8,26 @@ 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 ((from && typeof from === "object") || typeof from === "function") {
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 createType_exports = {};
24
20
  __export(createType_exports, {
25
21
  createTypes: () => createTypes,
26
22
  generateTypeScriptType: () => generateTypeScriptType,
27
- generateTypeScriptTypeContent: () => generateTypeScriptTypeContent,
23
+ generateTypeScriptTypeContent: () => generateTypeScriptTypeContent
28
24
  });
29
25
  module.exports = __toCommonJS(createType_exports);
30
26
  var import_fs = require("fs");
31
27
  var import_path = require("path");
32
28
  var import_config = require("@intlayer/config");
33
29
  var import_core = require("@intlayer/core");
34
- var import_createModuleAugmentation = require("./createModuleAugmentation.cjs");
30
+ var import_createModuleAugmentation = require('./createModuleAugmentation.cjs');
35
31
  const { content, internationalization } = (0, import_config.getConfiguration)();
36
32
  const { typesDir } = content;
37
33
  const generateTypeScriptType = (obj) => {
@@ -49,24 +45,21 @@ const generateTypeScriptTypeContent = (obj) => {
49
45
  const nodeType = value.nodeType;
50
46
  if (
51
47
  // Check if the value is a typed node
52
- typeof value === "object" &&
53
- nodeType === import_core.NodeType.Translation
48
+ typeof value === "object" && nodeType === import_core.NodeType.Translation
54
49
  ) {
55
50
  const tsType = typeof value[internationalization.defaultLocale];
56
51
  typeDefinition += ` ${key}: ${tsType},
57
52
  `;
58
53
  } else if (
59
54
  // Check if the value is a typed node
60
- typeof value === "object" &&
61
- nodeType === import_core.NodeType.Enumeration
55
+ typeof value === "object" && nodeType === import_core.NodeType.Enumeration
62
56
  ) {
63
57
  const tsType = typeof value[internationalization.defaultLocale];
64
58
  typeDefinition += ` ${key}: (quantity: number) => ${tsType},
65
59
  `;
66
60
  } else if (
67
61
  // Check if the value is a nested object
68
- typeof value === "object" &&
69
- !Array.isArray(value)
62
+ typeof value === "object" && !Array.isArray(value)
70
63
  ) {
71
64
  const nestedType = generateTypeScriptTypeContent(value);
72
65
  typeDefinition += ` ${key}: {${nestedType}},
@@ -80,8 +73,7 @@ const generateTypeScriptTypeContent = (obj) => {
80
73
  `;
81
74
  } else if (
82
75
  // Check if the value is an 'id'
83
- typeof value === "string" &&
84
- key === "id"
76
+ typeof value === "string" && key === "id"
85
77
  ) {
86
78
  const tsType = `"${value}"`;
87
79
  typeDefinition += ` ${key}: ${tsType},
@@ -103,20 +95,16 @@ const createTypes = (dictionariesPaths) => {
103
95
  const contentModule = require(dictionaryPath);
104
96
  const dictionaryName = contentModule.id;
105
97
  const typeDefinition = generateTypeScriptType(contentModule);
106
- const outputPath = (0, import_path.resolve)(
107
- typesDir,
108
- `${dictionaryName}.d.ts`
109
- );
98
+ const outputPath = (0, import_path.resolve)(typesDir, `${dictionaryName}.d.ts`);
110
99
  (0, import_fs.writeFileSync)(outputPath, typeDefinition);
111
100
  resultTypesPaths.push(outputPath);
112
101
  }
113
102
  return resultTypesPaths;
114
103
  };
115
104
  // Annotate the CommonJS export names for ESM import in node:
116
- 0 &&
117
- (module.exports = {
118
- createTypes,
119
- generateTypeScriptType,
120
- generateTypeScriptTypeContent,
121
- });
122
- //# sourceMappingURL=createType.cjs.map
105
+ 0 && (module.exports = {
106
+ createTypes,
107
+ generateTypeScriptType,
108
+ generateTypeScriptTypeContent
109
+ });
110
+ //# sourceMappingURL=createType.cjs.map