@intlayer/webpack 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/dist/cjs/getEntries.cjs +41 -0
  2. package/dist/cjs/getEntries.cjs.map +1 -0
  3. package/dist/cjs/getEntries.d.ts +5 -0
  4. package/dist/cjs/index.cjs +12 -24
  5. package/dist/cjs/index.cjs.map +1 -1
  6. package/dist/cjs/index.d.ts +4 -0
  7. package/dist/cjs/utils.cjs +32 -31
  8. package/dist/cjs/utils.cjs.map +1 -1
  9. package/dist/cjs/utils.d.ts +7 -0
  10. package/dist/cjs/webpack-plugin.cjs +12 -161
  11. package/dist/cjs/webpack-plugin.cjs.map +1 -1
  12. package/dist/cjs/webpack-plugin.d.ts +5 -0
  13. package/dist/cjs/webpack.config.cjs +53 -63
  14. package/dist/cjs/webpack.config.cjs.map +1 -1
  15. package/dist/cjs/webpack.config.d.ts +7 -0
  16. package/dist/esm/getEntries.d.mts +5 -0
  17. package/dist/esm/getEntries.mjs +17 -0
  18. package/dist/esm/getEntries.mjs.map +1 -0
  19. package/dist/esm/index.d.mts +4 -9
  20. package/dist/esm/index.mjs +4 -8
  21. package/dist/esm/index.mjs.map +1 -1
  22. package/dist/esm/utils.d.mts +5 -2
  23. package/dist/esm/utils.mjs +15 -17
  24. package/dist/esm/utils.mjs.map +1 -1
  25. package/dist/esm/webpack-plugin.d.mts +1 -11
  26. package/dist/esm/webpack-plugin.mjs +8 -142
  27. package/dist/esm/webpack-plugin.mjs.map +1 -1
  28. package/dist/esm/webpack.config.d.mts +2 -2
  29. package/dist/esm/webpack.config.mjs +48 -39
  30. package/dist/esm/webpack.config.mjs.map +1 -1
  31. package/package.json +14 -18
  32. package/src/getEntries.ts +19 -0
  33. package/src/index.ts +2 -12
  34. package/src/utils.ts +19 -19
  35. package/src/webpack-plugin.ts +5 -180
  36. package/src/webpack.config.ts +32 -28
  37. package/dist/cjs/scripts/bundle.cjs +0 -68
  38. package/dist/cjs/scripts/bundle.cjs.map +0 -1
  39. package/dist/cjs/scripts/index.cjs +0 -33
  40. package/dist/cjs/scripts/index.cjs.map +0 -1
  41. package/dist/cjs/scripts/startServer.cjs +0 -44
  42. package/dist/cjs/scripts/startServer.cjs.map +0 -1
  43. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +0 -92
  44. package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +0 -1
  45. package/dist/cjs/transpiler/dictionary_to_main/index.cjs +0 -35
  46. package/dist/cjs/transpiler/dictionary_to_main/index.cjs.map +0 -1
  47. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +0 -83
  48. package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +0 -1
  49. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +0 -122
  50. package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +0 -1
  51. package/dist/cjs/transpiler/dictionary_to_type/index.cjs +0 -41
  52. package/dist/cjs/transpiler/dictionary_to_type/index.cjs.map +0 -1
  53. package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs +0 -50
  54. package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs.map +0 -1
  55. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs +0 -47
  56. package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs.map +0 -1
  57. package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs +0 -70
  58. package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs.map +0 -1
  59. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs +0 -112
  60. package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs.map +0 -1
  61. package/dist/esm/scripts/bundle.d.mts +0 -7
  62. package/dist/esm/scripts/bundle.mjs +0 -35
  63. package/dist/esm/scripts/bundle.mjs.map +0 -1
  64. package/dist/esm/scripts/index.d.mts +0 -3
  65. package/dist/esm/scripts/index.mjs +0 -3
  66. package/dist/esm/scripts/index.mjs.map +0 -1
  67. package/dist/esm/scripts/startServer.d.mts +0 -5
  68. package/dist/esm/scripts/startServer.mjs +0 -10
  69. package/dist/esm/scripts/startServer.mjs.map +0 -1
  70. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.d.mts +0 -6
  71. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +0 -52
  72. package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs.map +0 -1
  73. package/dist/esm/transpiler/dictionary_to_main/index.d.mts +0 -1
  74. package/dist/esm/transpiler/dictionary_to_main/index.mjs +0 -2
  75. package/dist/esm/transpiler/dictionary_to_main/index.mjs.map +0 -1
  76. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.d.mts +0 -7
  77. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +0 -43
  78. package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +0 -1
  79. package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +0 -42
  80. package/dist/esm/transpiler/dictionary_to_type/createType.mjs +0 -84
  81. package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +0 -1
  82. package/dist/esm/transpiler/dictionary_to_type/index.d.mts +0 -10
  83. package/dist/esm/transpiler/dictionary_to_type/index.mjs +0 -3
  84. package/dist/esm/transpiler/dictionary_to_type/index.mjs.map +0 -1
  85. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.mts +0 -44
  86. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs +0 -19
  87. package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs.map +0 -1
  88. package/dist/esm/transpiler/intlater_module_to_dictionary/index.d.mts +0 -4
  89. package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs +0 -4
  90. package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs.map +0 -1
  91. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.d.mts +0 -10
  92. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs +0 -39
  93. package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs.map +0 -1
  94. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.mts +0 -8
  95. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs +0 -70
  96. package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs.map +0 -1
  97. package/src/scripts/bundle.ts +0 -44
  98. package/src/scripts/index.ts +0 -2
  99. package/src/scripts/startServer.ts +0 -14
  100. package/src/transpiler/dictionary_to_main/createDictionaryList.ts +0 -65
  101. package/src/transpiler/dictionary_to_main/index.ts +0 -1
  102. package/src/transpiler/dictionary_to_type/createModuleAugmentation.ts +0 -70
  103. package/src/transpiler/dictionary_to_type/createType.ts +0 -140
  104. package/src/transpiler/dictionary_to_type/index.ts +0 -2
  105. package/src/transpiler/intlater_module_to_dictionary/extractNestedJSON.ts +0 -60
  106. package/src/transpiler/intlater_module_to_dictionary/index.ts +0 -3
  107. package/src/transpiler/intlater_module_to_dictionary/processModule.ts +0 -69
  108. package/src/transpiler/intlater_module_to_dictionary/transpileBundledCode.ts +0 -107
@@ -1,107 +0,0 @@
1
- import { existsSync } from 'fs';
2
- import { mkdir, writeFile } from 'fs/promises';
3
- import { resolve } from 'path';
4
- import { getConfiguration } from '@intlayer/config';
5
- import type { ContentModule } from '@intlayer/core';
6
- import { extractObjectsWithId } from './extractNestedJSON';
7
- import { processModule } from './processModule';
8
-
9
- const { content } = getConfiguration();
10
- const { dictionariesDir, bundleFileExtension } = content;
11
-
12
- const loadBundledModule = async (bundledEntryPath: string) => {
13
- const entryFilePath = resolve(bundledEntryPath);
14
-
15
- const isEntryFilePathExist = existsSync(entryFilePath);
16
-
17
- if (!isEntryFilePathExist) {
18
- console.error('Entry file not found. ' + entryFilePath);
19
- return;
20
- }
21
-
22
- const isEntryPathValid = entryFilePath.endsWith(bundleFileExtension);
23
-
24
- if (!isEntryPathValid) {
25
- return;
26
- }
27
-
28
- try {
29
- // Remove the module from the cache
30
- delete require.cache[entryFilePath];
31
-
32
- // Require the module anew
33
- const entry = await import(entryFilePath);
34
-
35
- let result: ContentModule | undefined;
36
-
37
- if (entry.default) {
38
- // JS or TS file
39
- result = await processModule(entryFilePath);
40
- } else {
41
- // JSON file
42
- result = entry;
43
- }
44
-
45
- return result;
46
- } catch (err) {
47
- console.error(`Error transpiling ${entryFilePath}:`, err);
48
- }
49
- };
50
-
51
- const buildDictionary = async (dictionaries: ContentModule[]) => {
52
- const resultDictionariesPaths: string[] = [];
53
-
54
- for await (const content of dictionaries) {
55
- const contentString = JSON.stringify(content);
56
-
57
- const id = content.id;
58
- const outputFileName = `${id}.json`;
59
- const resultFilePath = resolve(dictionariesDir, outputFileName);
60
-
61
- // Create the json file
62
- await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {
63
- console.error(`Error creating ${outputFileName}:`, err);
64
- });
65
-
66
- resultDictionariesPaths.push(resultFilePath);
67
- }
68
-
69
- return resultDictionariesPaths;
70
- };
71
-
72
- /**
73
- * This function transpile the bundled code to to make dictionaries as JSON files
74
- */
75
- export const transpileBundledCode = async (
76
- bundledEntriesPaths: string[] | string
77
- ) => {
78
- const resultDictionariesPaths: string[] = [];
79
-
80
- if (typeof bundledEntriesPaths === 'string') {
81
- bundledEntriesPaths = [bundledEntriesPaths];
82
- }
83
-
84
- const filteredBundledEntriesPaths: string[] = bundledEntriesPaths.filter(
85
- // Filter js files;
86
- (bundledEntryPath) => bundledEntryPath.endsWith(bundleFileExtension)
87
- );
88
-
89
- // Create the dictionaries folder if it doesn't exist
90
- await mkdir(resolve(dictionariesDir), { recursive: true });
91
-
92
- for await (const bundledEntryPath of filteredBundledEntriesPaths) {
93
- const result = await loadBundledModule(bundledEntryPath);
94
-
95
- if (!result) {
96
- continue;
97
- }
98
-
99
- const nestedContent: ContentModule[] = extractObjectsWithId(result);
100
-
101
- const dictionariesPaths: string[] = await buildDictionary(nestedContent);
102
-
103
- resultDictionariesPaths.push(...dictionariesPaths);
104
- }
105
-
106
- return resultDictionariesPaths;
107
- };