@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
@@ -1,10 +1,7 @@
1
1
  import { SHA3, enc } from "crypto-js";
2
2
  const getFileHash = (filePath) => {
3
3
  const hash = SHA3(filePath);
4
- return hash
5
- .toString(enc.Base64)
6
- .replace(/[^A-Z\d]/gi, "")
7
- .substring(0, 20);
4
+ return hash.toString(enc.Base64).replace(/[^A-Z\d]/gi, "").substring(0, 20);
8
5
  };
9
6
  const transformToCamelCase = (string) => {
10
7
  const words = string.split(/[\s\-_]+/);
@@ -16,5 +13,8 @@ const transformToCamelCase = (string) => {
16
13
  });
17
14
  return camelCasedWords.join("");
18
15
  };
19
- export { getFileHash, transformToCamelCase };
20
- //# sourceMappingURL=utils.mjs.map
16
+ export {
17
+ getFileHash,
18
+ transformToCamelCase
19
+ };
20
+ //# sourceMappingURL=utils.mjs.map
@@ -1,15 +1,15 @@
1
- import { Compiler } from "webpack";
1
+ import { Compiler } from 'webpack';
2
2
 
3
3
  declare class IntLayerPlugin {
4
- private managedFiles;
5
- private updatedFiles;
6
- private addedFiles;
7
- constructor();
8
- initDictionaries(): Promise<void>;
9
- processFilesChanges(): Promise<void>;
10
- processNewFiles(): Promise<void>;
11
- detectFileAddedOrRemoved(): Promise<void>;
12
- apply(compiler: Compiler): void;
4
+ private managedFiles;
5
+ private updatedFiles;
6
+ private addedFiles;
7
+ constructor();
8
+ initDictionaries(): Promise<void>;
9
+ processFilesChanges(): Promise<void>;
10
+ processNewFiles(): Promise<void>;
11
+ detectFileAddedOrRemoved(): Promise<void>;
12
+ apply(compiler: Compiler): void;
13
13
  }
14
14
 
15
15
  export { IntLayerPlugin };
@@ -2,19 +2,18 @@ import { relative, resolve } from "path";
2
2
  import { getConfiguration } from "@intlayer/config";
3
3
  import { sync } from "glob";
4
4
  import { DynamicEntryPlugin } from "webpack";
5
- import { createDictionaryList } from "./transpiler/dictionary_to_main/createDictionaryList.mjs";
6
- import { createModuleAugmentation } from "./transpiler/dictionary_to_type/createModuleAugmentation.mjs";
7
- import { createTypes } from "./transpiler/dictionary_to_type/createType.mjs";
8
- import { transpileBundledCode } from "./transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs";
9
- import { getFileHash } from "./utils.mjs";
5
+ import { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList.mjs';
6
+ import { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation.mjs';
7
+ import { createTypes } from './transpiler/dictionary_to_type/createType.mjs';
8
+ import { transpileBundledCode } from './transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs';
9
+ import { getFileHash } from './utils.mjs';
10
10
  const getRelativePath = (filePath) => relative(baseDir, filePath);
11
11
  const getBundledFilePathFromIntlayerModule = (filePath) => {
12
12
  const hash = getFileHash(filePath);
13
13
  return `${bundleDir}/${hash}${bundleFileExtension}`;
14
14
  };
15
15
  const { content } = getConfiguration();
16
- const { bundleDir, baseDir, bundleFileExtension, watchedFilesPatternWithPath } =
17
- content;
16
+ const { bundleDir, baseDir, bundleFileExtension, watchedFilesPatternWithPath } = content;
18
17
  class IntLayerPlugin {
19
18
  managedFiles;
20
19
  updatedFiles;
@@ -26,10 +25,10 @@ class IntLayerPlugin {
26
25
  }
27
26
  // function to initialize the dictionaries
28
27
  async initDictionaries() {
29
- const outputFiles = [...this.managedFiles].map((file) =>
30
- resolve(bundleDir, file)
28
+ const outputFiles = [...this.managedFiles].map(
29
+ (file) => resolve(bundleDir, file)
31
30
  );
32
- const dictionaries = (await transpileBundledCode(outputFiles)) ?? [];
31
+ const dictionaries = await transpileBundledCode(outputFiles) ?? [];
33
32
  console.info(
34
33
  `Dictionaries:
35
34
  ${dictionaries.map(getRelativePath).join("\n")}`
@@ -43,8 +42,7 @@ class IntLayerPlugin {
43
42
  }
44
43
  // function to process when intlayer module files content are changed
45
44
  async processFilesChanges() {
46
- const dictionaries =
47
- (await transpileBundledCode([...this.updatedFiles])) ?? [];
45
+ const dictionaries = await transpileBundledCode([...this.updatedFiles]) ?? [];
48
46
  console.info(
49
47
  `Updated dictionaries:
50
48
  ${dictionaries.map(getRelativePath).join("\n")}`
@@ -55,8 +53,7 @@ class IntLayerPlugin {
55
53
  }
56
54
  // function to process when new intlayer module is detected
57
55
  async processNewFiles() {
58
- const dictionaries =
59
- (await transpileBundledCode([...this.addedFiles])) ?? [];
56
+ const dictionaries = await transpileBundledCode([...this.addedFiles]) ?? [];
60
57
  console.info(
61
58
  `New dictionaries:
62
59
  ${dictionaries.map(getRelativePath).join("\n")}`
@@ -67,10 +64,7 @@ class IntLayerPlugin {
67
64
  createModuleAugmentation();
68
65
  console.info("Building main...");
69
66
  createDictionaryList();
70
- this.managedFiles = /* @__PURE__ */ new Set([
71
- ...this.managedFiles,
72
- ...this.addedFiles,
73
- ]);
67
+ this.managedFiles = /* @__PURE__ */ new Set([...this.managedFiles, ...this.addedFiles]);
74
68
  this.addedFiles.clear();
75
69
  }
76
70
  async detectFileAddedOrRemoved() {
@@ -141,5 +135,7 @@ class IntLayerPlugin {
141
135
  );
142
136
  }
143
137
  }
144
- export { IntLayerPlugin };
145
- //# sourceMappingURL=webpack-plugin.mjs.map
138
+ export {
139
+ IntLayerPlugin
140
+ };
141
+ //# sourceMappingURL=webpack-plugin.mjs.map
@@ -1,5 +1,5 @@
1
- import { Configuration as Configuration$1 } from "webpack";
2
- import { Configuration } from "webpack-dev-server";
1
+ import { Configuration as Configuration$1 } from 'webpack';
2
+ import { Configuration } from 'webpack-dev-server';
3
3
 
4
4
  declare const devServerConfig: Configuration;
5
5
  declare const webpackConfig: Configuration$1;
@@ -1,18 +1,20 @@
1
1
  import { join } from "path";
2
2
  import { getConfiguration } from "@intlayer/config";
3
3
  import { sync } from "glob";
4
- import { getFileHash } from "./utils.mjs";
5
- import { IntLayerPlugin } from "./webpack-plugin.mjs";
4
+ import { getFileHash } from './utils.mjs';
5
+ import { IntLayerPlugin } from './webpack-plugin.mjs';
6
6
  const { content } = getConfiguration({
7
- verbose: true,
7
+ verbose: true
8
8
  });
9
9
  const { bundleDir, bundleFileExtension, watchedFilesPatternWithPath } = content;
10
- const getEntry = () =>
11
- sync(watchedFilesPatternWithPath).reduce((obj, el) => {
10
+ const getEntry = () => sync(watchedFilesPatternWithPath).reduce(
11
+ (obj, el) => {
12
12
  const hash = getFileHash(el);
13
13
  obj[hash] = el;
14
14
  return obj;
15
- }, {});
15
+ },
16
+ {}
17
+ );
16
18
  const devServerConfig = {
17
19
  // Enable hot module replacement
18
20
  hot: true,
@@ -30,12 +32,12 @@ const devServerConfig = {
30
32
  // watchedFilesPatternWithPath,
31
33
  devMiddleware: {
32
34
  // Enable write to disk to reuse the output
33
- writeToDisk: true,
35
+ writeToDisk: true
34
36
  },
35
37
  // Content base
36
38
  static: {
37
- directory: bundleDir,
38
- },
39
+ directory: bundleDir
40
+ }
39
41
  };
40
42
  const webpackConfig = {
41
43
  // Define the environment mode (development or production)
@@ -51,7 +53,7 @@ const webpackConfig = {
51
53
  library: "IntlLayerContent",
52
54
  libraryTarget: "umd",
53
55
  filename: `[name]${bundleFileExtension}`,
54
- path: bundleDir,
56
+ path: bundleDir
55
57
  },
56
58
  cache: false,
57
59
  // devtool: 'source-map',
@@ -78,9 +80,9 @@ const webpackConfig = {
78
80
  "node_modules",
79
81
  "@intlayer/webpack",
80
82
  "node_modules"
81
- ),
83
+ )
82
84
  // Or via another project by importing intlayer
83
- ],
85
+ ]
84
86
  },
85
87
  resolveLoader: {
86
88
  // Configure how Webpack finds `loader` modules.
@@ -97,9 +99,9 @@ const webpackConfig = {
97
99
  "node_modules",
98
100
  "@intlayer/webpack",
99
101
  "node_modules"
100
- ),
102
+ )
101
103
  // Or via another project by importing intlayer
102
- ],
104
+ ]
103
105
  // roots: [
104
106
  // join(process.cwd()), // Project context
105
107
  // join(process.cwd(), '@intlayer/webpack'), // Or via CLI in another project
@@ -110,7 +112,7 @@ const webpackConfig = {
110
112
  rules: [
111
113
  {
112
114
  test: /\.node$/,
113
- loader: "node-loader",
115
+ loader: "node-loader"
114
116
  },
115
117
  // Use esbuild to compile JavaScript & TypeScript
116
118
  {
@@ -119,18 +121,22 @@ const webpackConfig = {
119
121
  loader: "esbuild-loader",
120
122
  options: {
121
123
  // JavaScript version to compile to
122
- target: "es2015",
123
- },
124
- },
124
+ target: "es2015"
125
+ }
126
+ }
125
127
  // JSON files are supported natively by Webpack 5, no specific loader required
126
- ],
128
+ ]
127
129
  },
128
130
  devServer: devServerConfig,
129
131
  plugins: [
130
- new IntLayerPlugin(),
132
+ new IntLayerPlugin()
131
133
  // new HotModuleReplacementPlugin()
132
- ],
134
+ ]
133
135
  };
134
136
  var webpack_config_default = webpackConfig;
135
- export { webpack_config_default as default, devServerConfig, webpackConfig };
136
- //# sourceMappingURL=webpack.config.mjs.map
137
+ export {
138
+ webpack_config_default as default,
139
+ devServerConfig,
140
+ webpackConfig
141
+ };
142
+ //# sourceMappingURL=webpack.config.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/webpack",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "private": false,
5
5
  "description": "Webpack application for IntLayer - Webpack process to transpile TypeScript files to JavaScript files into IntLayer dictionaries.",
6
6
  "keywords": [
@@ -16,7 +16,7 @@
16
16
  "homepage": "https://github.com/aypineau/intlayer",
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "https://github.com/aypineau/intlayer"
19
+ "url": "git+https://github.com/aypineau/intlayer.git"
20
20
  },
21
21
  "license": "MIT",
22
22
  "author": {
@@ -57,9 +57,9 @@
57
57
  "webpack-cli": "^5.1.4",
58
58
  "webpack-dev-server": "^5.0.4",
59
59
  "yargs": "^17.7.2",
60
- "@intlayer/cli": "^1.0.0",
61
- "@intlayer/config": "^1.0.0",
62
- "@intlayer/core": "^1.0.0"
60
+ "@intlayer/cli": "^1.0.1",
61
+ "@intlayer/config": "^1.0.1",
62
+ "@intlayer/core": "^1.0.1"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@changesets/changelog-github": "0.5.0",
@@ -73,8 +73,8 @@
73
73
  "tsup": "^8.0.2",
74
74
  "typescript": "^5.3.3",
75
75
  "webpack-watch-files-plugin": "^1.2.1",
76
- "@utils/eslint-config": "^1.0.0",
77
- "@utils/ts-config": "^1.0.0"
76
+ "@utils/eslint-config": "^1.0.1",
77
+ "@utils/ts-config": "^1.0.1"
78
78
  },
79
79
  "engines": {
80
80
  "node": ">=14.18"
@@ -1,11 +1,12 @@
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
5
  import { getFileHash, transformToCamelCase } from '../../utils';
6
6
 
7
- const { content } = getConfiguration();
7
+ const { content, internationalization } = getConfiguration();
8
8
  const { typesDir, moduleAugmentationDir } = content;
9
+ const { locales } = internationalization;
9
10
 
10
11
  export const getTypeName = (id: string): string =>
11
12
  transformToCamelCase(`${id}Content`);
@@ -14,7 +15,8 @@ export const getTypeName = (id: string): string =>
14
15
  * This function generates the content of the module augmentation file
15
16
  */
16
17
  const generateTypeIndexContent = (typeFiles: string[]): string => {
17
- let content = "import 'intlayer';\n\n";
18
+ let content =
19
+ "/* eslint-disable */\nimport 'intlayer';\nimport { Locales } from '@intlayer/config'\n";
18
20
 
19
21
  const dictionariesRef = typeFiles.map((dictionaryPath) => ({
20
22
  relativePath: relative(moduleAugmentationDir, dictionaryPath),
@@ -35,6 +37,16 @@ const generateTypeIndexContent = (typeFiles: string[]): string => {
35
37
  .map((dictionary) => ` "${dictionary.id}": ${dictionary.hash};`)
36
38
  .join('\n');
37
39
 
40
+ const formatLocales = locales
41
+ .map((locale) => {
42
+ for (const key in Locales) {
43
+ if (Locales[key as keyof typeof Locales] === locale) {
44
+ return ` ${key} = '${locale}'`;
45
+ }
46
+ }
47
+ })
48
+ .join(',\n');
49
+
38
50
  /**
39
51
  * Write the module augmentation to extend the intlayer module with the dictionaries types
40
52
  * Will suggest the type resulting of the dictionaries
@@ -44,11 +56,24 @@ const generateTypeIndexContent = (typeFiles: string[]): string => {
44
56
  * dictionaries: {
45
57
  * id: DictionaryType;
46
58
  * }
47
- * }
59
+ * }
60
+ *
61
+ * enum ConfigLocales {
62
+ * ENGLISH = 'en',
63
+ * FRENCH = 'fr',
64
+ * SPANISH = 'es',
65
+ * }
48
66
  *
67
+ * interface IConfigLocales<Content> extends Record<ConfigLocales, Content> {}
68
+ *
69
+ * }
49
70
  * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
50
71
  */
51
- content += `declare module 'intlayer' {\n interface IntlayerDictionaryTypesConnector {\n${formattedDictionaryMap}\n };\n};`;
72
+ content += `declare module 'intlayer' {\n`;
73
+ content += ` interface IntlayerDictionaryTypesConnector {\n${formattedDictionaryMap}\n }\n\n`;
74
+ content += ` enum ConfigLocales {\n${formatLocales}\n };\n\n`;
75
+ content += ` interface IConfigLocales<Content> extends Record<ConfigLocales, Content> {}\n`;
76
+ content += `};`;
52
77
 
53
78
  return content;
54
79
  };