@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.
- package/dist/cjs/getEntries.cjs +41 -0
- package/dist/cjs/getEntries.cjs.map +1 -0
- package/dist/cjs/getEntries.d.ts +5 -0
- package/dist/cjs/index.cjs +12 -24
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/utils.cjs +32 -31
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.ts +7 -0
- package/dist/cjs/webpack-plugin.cjs +12 -161
- package/dist/cjs/webpack-plugin.cjs.map +1 -1
- package/dist/cjs/webpack-plugin.d.ts +5 -0
- package/dist/cjs/webpack.config.cjs +53 -63
- package/dist/cjs/webpack.config.cjs.map +1 -1
- package/dist/cjs/webpack.config.d.ts +7 -0
- package/dist/esm/getEntries.d.mts +5 -0
- package/dist/esm/getEntries.mjs +17 -0
- package/dist/esm/getEntries.mjs.map +1 -0
- package/dist/esm/index.d.mts +4 -9
- package/dist/esm/index.mjs +4 -8
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/utils.d.mts +5 -2
- package/dist/esm/utils.mjs +15 -17
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/esm/webpack-plugin.d.mts +1 -11
- package/dist/esm/webpack-plugin.mjs +8 -142
- package/dist/esm/webpack-plugin.mjs.map +1 -1
- package/dist/esm/webpack.config.d.mts +2 -2
- package/dist/esm/webpack.config.mjs +48 -39
- package/dist/esm/webpack.config.mjs.map +1 -1
- package/package.json +14 -18
- package/src/getEntries.ts +19 -0
- package/src/index.ts +2 -12
- package/src/utils.ts +19 -19
- package/src/webpack-plugin.ts +5 -180
- package/src/webpack.config.ts +32 -28
- package/dist/cjs/scripts/bundle.cjs +0 -68
- package/dist/cjs/scripts/bundle.cjs.map +0 -1
- package/dist/cjs/scripts/index.cjs +0 -33
- package/dist/cjs/scripts/index.cjs.map +0 -1
- package/dist/cjs/scripts/startServer.cjs +0 -44
- package/dist/cjs/scripts/startServer.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +0 -92
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs +0 -35
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +0 -83
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +0 -122
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +0 -1
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs +0 -41
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs +0 -50
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs +0 -47
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs +0 -70
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs.map +0 -1
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs +0 -112
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs.map +0 -1
- package/dist/esm/scripts/bundle.d.mts +0 -7
- package/dist/esm/scripts/bundle.mjs +0 -35
- package/dist/esm/scripts/bundle.mjs.map +0 -1
- package/dist/esm/scripts/index.d.mts +0 -3
- package/dist/esm/scripts/index.mjs +0 -3
- package/dist/esm/scripts/index.mjs.map +0 -1
- package/dist/esm/scripts/startServer.d.mts +0 -5
- package/dist/esm/scripts/startServer.mjs +0 -10
- package/dist/esm/scripts/startServer.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.d.mts +0 -6
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +0 -52
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_main/index.d.mts +0 -1
- package/dist/esm/transpiler/dictionary_to_main/index.mjs +0 -2
- package/dist/esm/transpiler/dictionary_to_main/index.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.d.mts +0 -7
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +0 -43
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +0 -42
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +0 -84
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +0 -1
- package/dist/esm/transpiler/dictionary_to_type/index.d.mts +0 -10
- package/dist/esm/transpiler/dictionary_to_type/index.mjs +0 -3
- package/dist/esm/transpiler/dictionary_to_type/index.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.mts +0 -44
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs +0 -19
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.d.mts +0 -4
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs +0 -4
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.d.mts +0 -10
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs +0 -39
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs.map +0 -1
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.mts +0 -8
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs +0 -70
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs.map +0 -1
- package/src/scripts/bundle.ts +0 -44
- package/src/scripts/index.ts +0 -2
- package/src/scripts/startServer.ts +0 -14
- package/src/transpiler/dictionary_to_main/createDictionaryList.ts +0 -65
- package/src/transpiler/dictionary_to_main/index.ts +0 -1
- package/src/transpiler/dictionary_to_type/createModuleAugmentation.ts +0 -70
- package/src/transpiler/dictionary_to_type/createType.ts +0 -140
- package/src/transpiler/dictionary_to_type/index.ts +0 -2
- package/src/transpiler/intlater_module_to_dictionary/extractNestedJSON.ts +0 -60
- package/src/transpiler/intlater_module_to_dictionary/index.ts +0 -3
- package/src/transpiler/intlater_module_to_dictionary/processModule.ts +0 -69
- package/src/transpiler/intlater_module_to_dictionary/transpileBundledCode.ts +0 -107
|
@@ -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
|
-
};
|