@intlayer/webpack 1.0.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/LICENSE +21 -0
- package/dist/cjs/index.cjs +46 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/scripts/bundle.cjs +68 -0
- package/dist/cjs/scripts/bundle.cjs.map +1 -0
- package/dist/cjs/scripts/index.cjs +33 -0
- package/dist/cjs/scripts/index.cjs.map +1 -0
- package/dist/cjs/scripts/startServer.cjs +44 -0
- package/dist/cjs/scripts/startServer.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs +92 -0
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryList.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs +35 -0
- package/dist/cjs/transpiler/dictionary_to_main/index.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs +83 -0
- package/dist/cjs/transpiler/dictionary_to_type/createModuleAugmentation.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs +122 -0
- package/dist/cjs/transpiler/dictionary_to_type/createType.cjs.map +1 -0
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs +41 -0
- package/dist/cjs/transpiler/dictionary_to_type/index.cjs.map +1 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs +50 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/extractNestedJSON.cjs.map +1 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs +47 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/index.cjs.map +1 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs +70 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/processModule.cjs.map +1 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs +112 -0
- package/dist/cjs/transpiler/intlater_module_to_dictionary/transpileBundledCode.cjs.map +1 -0
- package/dist/cjs/utils.cjs +53 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/webpack-plugin.cjs +184 -0
- package/dist/cjs/webpack-plugin.cjs.map +1 -0
- package/dist/cjs/webpack.config.cjs +180 -0
- package/dist/cjs/webpack.config.cjs.map +1 -0
- package/dist/esm/index.d.mts +9 -0
- package/dist/esm/index.mjs +12 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/scripts/bundle.d.mts +7 -0
- package/dist/esm/scripts/bundle.mjs +35 -0
- package/dist/esm/scripts/bundle.mjs.map +1 -0
- package/dist/esm/scripts/index.d.mts +3 -0
- package/dist/esm/scripts/index.mjs +3 -0
- package/dist/esm/scripts/index.mjs.map +1 -0
- package/dist/esm/scripts/startServer.d.mts +5 -0
- package/dist/esm/scripts/startServer.mjs +10 -0
- package/dist/esm/scripts/startServer.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.d.mts +6 -0
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs +52 -0
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryList.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_main/index.d.mts +1 -0
- package/dist/esm/transpiler/dictionary_to_main/index.mjs +2 -0
- package/dist/esm/transpiler/dictionary_to_main/index.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.d.mts +7 -0
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs +43 -0
- package/dist/esm/transpiler/dictionary_to_type/createModuleAugmentation.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_type/createType.d.mts +42 -0
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs +84 -0
- package/dist/esm/transpiler/dictionary_to_type/createType.mjs.map +1 -0
- package/dist/esm/transpiler/dictionary_to_type/index.d.mts +10 -0
- package/dist/esm/transpiler/dictionary_to_type/index.mjs +3 -0
- package/dist/esm/transpiler/dictionary_to_type/index.mjs.map +1 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.d.mts +44 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs +19 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/extractNestedJSON.mjs.map +1 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.d.mts +4 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs +4 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/index.mjs.map +1 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.d.mts +10 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs +39 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/processModule.mjs.map +1 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.d.mts +8 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs +70 -0
- package/dist/esm/transpiler/intlater_module_to_dictionary/transpileBundledCode.mjs.map +1 -0
- package/dist/esm/utils.d.mts +4 -0
- package/dist/esm/utils.mjs +20 -0
- package/dist/esm/utils.mjs.map +1 -0
- package/dist/esm/webpack-plugin.d.mts +15 -0
- package/dist/esm/webpack-plugin.mjs +145 -0
- package/dist/esm/webpack-plugin.mjs.map +1 -0
- package/dist/esm/webpack.config.d.mts +7 -0
- package/dist/esm/webpack.config.mjs +136 -0
- package/dist/esm/webpack.config.mjs.map +1 -0
- package/package.json +97 -0
- package/src/index.ts +12 -0
- package/src/scripts/bundle.ts +44 -0
- package/src/scripts/index.ts +2 -0
- package/src/scripts/startServer.ts +14 -0
- package/src/transpiler/dictionary_to_main/createDictionaryList.ts +65 -0
- package/src/transpiler/dictionary_to_main/index.ts +1 -0
- package/src/transpiler/dictionary_to_type/createModuleAugmentation.ts +70 -0
- package/src/transpiler/dictionary_to_type/createType.ts +140 -0
- package/src/transpiler/dictionary_to_type/index.ts +2 -0
- package/src/transpiler/intlater_module_to_dictionary/extractNestedJSON.ts +60 -0
- package/src/transpiler/intlater_module_to_dictionary/index.ts +3 -0
- package/src/transpiler/intlater_module_to_dictionary/processModule.ts +69 -0
- package/src/transpiler/intlater_module_to_dictionary/transpileBundledCode.ts +107 -0
- package/src/utils.ts +26 -0
- package/src/webpack-plugin.ts +185 -0
- package/src/webpack.config.ts +149 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ContentModule } from "@intlayer/core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* This function extracts all nested objects with an 'id' field from the input object and returns them as an array
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
*
|
|
9
|
+
* const input = {
|
|
10
|
+
* id: '1',
|
|
11
|
+
* name: 'John Doe',
|
|
12
|
+
* address: {
|
|
13
|
+
* id: '2',
|
|
14
|
+
* street: '123 Main St',
|
|
15
|
+
* city: 'Springfield',
|
|
16
|
+
* state: 'IL'
|
|
17
|
+
* },
|
|
18
|
+
* };
|
|
19
|
+
* const result = extractObjectsWithId(input);
|
|
20
|
+
* console.log(result);
|
|
21
|
+
*
|
|
22
|
+
* Output:
|
|
23
|
+
*
|
|
24
|
+
* [{
|
|
25
|
+
* id: '1',
|
|
26
|
+
* name: 'John Doe',
|
|
27
|
+
* address: {
|
|
28
|
+
* id: '2',
|
|
29
|
+
* street: '123 Main St',
|
|
30
|
+
* city: 'Springfield',
|
|
31
|
+
* state: 'IL'
|
|
32
|
+
* }
|
|
33
|
+
* },
|
|
34
|
+
* {
|
|
35
|
+
* id: '2',
|
|
36
|
+
* street: '123 Main St',
|
|
37
|
+
* city: 'Springfield',
|
|
38
|
+
* state: 'IL'
|
|
39
|
+
* }]
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
declare const extractObjectsWithId: (input: ContentModule) => ContentModule[];
|
|
43
|
+
|
|
44
|
+
export { extractObjectsWithId };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const extractObjectsWithId = (input) => {
|
|
2
|
+
const search = (obj, results2) => {
|
|
3
|
+
if (obj && typeof obj === "object") {
|
|
4
|
+
if (Object.prototype.hasOwnProperty.call(obj, "id")) {
|
|
5
|
+
results2.push(obj);
|
|
6
|
+
}
|
|
7
|
+
for (const key of Object.keys(obj)) {
|
|
8
|
+
if (typeof obj[key] === "object") {
|
|
9
|
+
search(obj[key], results2);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const results = [];
|
|
15
|
+
search(input, results);
|
|
16
|
+
return results;
|
|
17
|
+
};
|
|
18
|
+
export { extractObjectsWithId };
|
|
19
|
+
//# sourceMappingURL=extractNestedJSON.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/extractNestedJSON.ts"],"sourcesContent":["import type { Content, ContentModule } from '@intlayer/core';\n\n/**\n *\n * This function extracts all nested objects with an 'id' field from the input object and returns them as an array\n *\n * Example:\n *\n * const input = {\n * id: '1',\n * name: 'John Doe',\n * address: {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * state: 'IL'\n * },\n * };\n * const result = extractObjectsWithId(input);\n * console.log(result);\n *\n * Output:\n *\n * [{\n * id: '1',\n * name: 'John Doe',\n * address: {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * state: 'IL'\n * }\n * },\n * {\n * id: '2',\n * street: '123 Main St',\n * city: 'Springfield',\n * state: 'IL'\n * }]\n *\n */\nexport const extractObjectsWithId = (input: ContentModule): ContentModule[] => {\n // Function to recursively search and extract nested objects with an 'id'\n const search = (obj: Content, results: ContentModule[]): void => {\n if (obj && typeof obj === 'object') {\n if (Object.prototype.hasOwnProperty.call(obj, 'id')) {\n results.push(obj as ContentModule);\n }\n for (const key of Object.keys(obj)) {\n if (typeof obj[key] === 'object') {\n search(obj[key] as Content, results);\n }\n }\n }\n };\n\n const results: ContentModule[] = [];\n search(input, results);\n return results;\n};\n"],"mappings":"AAyCO,MAAM,uBAAuB,CAAC,UAA0C;AAE7E,QAAM,SAAS,CAAC,KAAcA,aAAmC;AAC/D,QAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,UAAI,OAAO,UAAU,eAAe,KAAK,KAAK,IAAI,GAAG;AACnD,QAAAA,SAAQ,KAAK,GAAoB;AAAA,MACnC;AACA,iBAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,YAAI,OAAO,IAAI,GAAG,MAAM,UAAU;AAChC,iBAAO,IAAI,GAAG,GAAcA,QAAO;AAAA,QACrC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAA2B,CAAC;AAClC,SAAO,OAAO,OAAO;AACrB,SAAO;AACT;","names":["results"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/index.ts"],"sourcesContent":["export * from './extractNestedJSON';\nexport * from './processModule';\nexport * from './transpileBundledCode';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ContentModule } from "@intlayer/core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Function to load, process the module and return the Intlayer ContentModule from the module file
|
|
5
|
+
*/
|
|
6
|
+
declare const processModule: (
|
|
7
|
+
file: string
|
|
8
|
+
) => Promise<ContentModule | undefined>;
|
|
9
|
+
|
|
10
|
+
export { processModule };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { resolve } from "path";
|
|
2
|
+
const loadModule = async (modulePath) => {
|
|
3
|
+
return (await import(modulePath)).default;
|
|
4
|
+
};
|
|
5
|
+
const processFunctionResults = async (entry) => {
|
|
6
|
+
if (entry && typeof entry === "object") {
|
|
7
|
+
const promises = [];
|
|
8
|
+
const result = {};
|
|
9
|
+
for (const key of Object.keys(entry)) {
|
|
10
|
+
const field = entry?.[key];
|
|
11
|
+
if (typeof field === "object") {
|
|
12
|
+
result[key] = await processFunctionResults(field);
|
|
13
|
+
}
|
|
14
|
+
if (typeof field === "function") {
|
|
15
|
+
const promise = (async () => {
|
|
16
|
+
const value = await field();
|
|
17
|
+
result[key] = value;
|
|
18
|
+
})();
|
|
19
|
+
promises.push(promise);
|
|
20
|
+
} else {
|
|
21
|
+
result[key] = field;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
await Promise.all(promises);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
return entry;
|
|
28
|
+
};
|
|
29
|
+
const processModule = async (file) => {
|
|
30
|
+
try {
|
|
31
|
+
const functionPath = resolve(file);
|
|
32
|
+
const entry = await loadModule(functionPath);
|
|
33
|
+
return await processFunctionResults(entry);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error("Error processing module:", error);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export { processModule };
|
|
39
|
+
//# sourceMappingURL=processModule.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/processModule.ts"],"sourcesContent":["import { resolve } from 'path';\nimport type {\n Content,\n ContentModule,\n FlatContent,\n FlatContentValue,\n} from '@intlayer/core';\n\n/**\n * Function to load the module file in a sandboxed environment\n */\nconst loadModule = async (modulePath: string): Promise<ContentModule> => {\n // @TODO: Sandbox the module to prevent malicious code execution\n\n return (await import(modulePath)).default;\n};\n\n/**\n * Function to replace function and async function fields with their results in the object\n */\nconst processFunctionResults = async (entry: Content): Promise<FlatContent> => {\n if (entry && typeof entry === 'object') {\n const promises: Promise<void>[] = [];\n const result: FlatContent = {};\n\n for (const key of Object.keys(entry)) {\n const field = entry?.[key];\n\n if (typeof field === 'object') {\n result[key] = (await processFunctionResults(\n field as Content\n )) as FlatContentValue;\n }\n\n if (typeof field === 'function') {\n // Wait for the function to resolve if it's an async function\n const promise = (async () => {\n // Execute the function and await the result if it's a Promise\n const value = await field();\n result[key] = value as FlatContentValue;\n })();\n promises.push(promise);\n } else {\n result[key] = field as FlatContentValue;\n }\n }\n\n // Wait for all async operations to complete\n await Promise.all(promises);\n\n return result;\n }\n\n return entry;\n};\n\n/**\n * Function to load, process the module and return the Intlayer ContentModule from the module file\n */\nexport const processModule = async (file: string) => {\n try {\n const functionPath = resolve(file);\n const entry = await loadModule(functionPath);\n\n return (await processFunctionResults(entry)) as ContentModule;\n } catch (error) {\n console.error('Error processing module:', error);\n }\n};\n"],"mappings":"AAAA,SAAS,eAAe;AAWxB,MAAM,aAAa,OAAO,eAA+C;AAGvE,UAAQ,MAAM,OAAO,aAAa;AACpC;AAKA,MAAM,yBAAyB,OAAO,UAAyC;AAC7E,MAAI,SAAS,OAAO,UAAU,UAAU;AACtC,UAAM,WAA4B,CAAC;AACnC,UAAM,SAAsB,CAAC;AAE7B,eAAW,OAAO,OAAO,KAAK,KAAK,GAAG;AACpC,YAAM,QAAQ,QAAQ,GAAG;AAEzB,UAAI,OAAO,UAAU,UAAU;AAC7B,eAAO,GAAG,IAAK,MAAM;AAAA,UACnB;AAAA,QACF;AAAA,MACF;AAEA,UAAI,OAAO,UAAU,YAAY;AAE/B,cAAM,WAAW,YAAY;AAE3B,gBAAM,QAAQ,MAAM,MAAM;AAC1B,iBAAO,GAAG,IAAI;AAAA,QAChB,GAAG;AACH,iBAAS,KAAK,OAAO;AAAA,MACvB,OAAO;AACL,eAAO,GAAG,IAAI;AAAA,MAChB;AAAA,IACF;AAGA,UAAM,QAAQ,IAAI,QAAQ;AAE1B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAKO,MAAM,gBAAgB,OAAO,SAAiB;AACnD,MAAI;AACF,UAAM,eAAe,QAAQ,IAAI;AACjC,UAAM,QAAQ,MAAM,WAAW,YAAY;AAE3C,WAAQ,MAAM,uBAAuB,KAAK;AAAA,EAC5C,SAAS,OAAO;AACd,YAAQ,MAAM,4BAA4B,KAAK;AAAA,EACjD;AACF;","names":[]}
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { extractObjectsWithId } from "./extractNestedJSON.mjs";
|
|
6
|
+
import { processModule } from "./processModule.mjs";
|
|
7
|
+
const { content } = getConfiguration();
|
|
8
|
+
const { dictionariesDir, bundleFileExtension } = content;
|
|
9
|
+
const loadBundledModule = async (bundledEntryPath) => {
|
|
10
|
+
const entryFilePath = resolve(bundledEntryPath);
|
|
11
|
+
const isEntryFilePathExist = existsSync(entryFilePath);
|
|
12
|
+
if (!isEntryFilePathExist) {
|
|
13
|
+
console.error("Entry file not found. " + entryFilePath);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const isEntryPathValid = entryFilePath.endsWith(bundleFileExtension);
|
|
17
|
+
if (!isEntryPathValid) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
delete require.cache[entryFilePath];
|
|
22
|
+
const entry = await import(entryFilePath);
|
|
23
|
+
let result;
|
|
24
|
+
if (entry.default) {
|
|
25
|
+
result = await processModule(entryFilePath);
|
|
26
|
+
} else {
|
|
27
|
+
result = entry;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.error(`Error transpiling ${entryFilePath}:`, err);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const buildDictionary = async (dictionaries) => {
|
|
35
|
+
const resultDictionariesPaths = [];
|
|
36
|
+
for await (const content2 of dictionaries) {
|
|
37
|
+
const contentString = JSON.stringify(content2);
|
|
38
|
+
const id = content2.id;
|
|
39
|
+
const outputFileName = `${id}.json`;
|
|
40
|
+
const resultFilePath = resolve(dictionariesDir, outputFileName);
|
|
41
|
+
await writeFile(resultFilePath, contentString, "utf8").catch((err) => {
|
|
42
|
+
console.error(`Error creating ${outputFileName}:`, err);
|
|
43
|
+
});
|
|
44
|
+
resultDictionariesPaths.push(resultFilePath);
|
|
45
|
+
}
|
|
46
|
+
return resultDictionariesPaths;
|
|
47
|
+
};
|
|
48
|
+
const transpileBundledCode = async (bundledEntriesPaths) => {
|
|
49
|
+
const resultDictionariesPaths = [];
|
|
50
|
+
if (typeof bundledEntriesPaths === "string") {
|
|
51
|
+
bundledEntriesPaths = [bundledEntriesPaths];
|
|
52
|
+
}
|
|
53
|
+
const filteredBundledEntriesPaths = bundledEntriesPaths.filter(
|
|
54
|
+
// Filter js files;
|
|
55
|
+
(bundledEntryPath) => bundledEntryPath.endsWith(bundleFileExtension)
|
|
56
|
+
);
|
|
57
|
+
await mkdir(resolve(dictionariesDir), { recursive: true });
|
|
58
|
+
for await (const bundledEntryPath of filteredBundledEntriesPaths) {
|
|
59
|
+
const result = await loadBundledModule(bundledEntryPath);
|
|
60
|
+
if (!result) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const nestedContent = extractObjectsWithId(result);
|
|
64
|
+
const dictionariesPaths = await buildDictionary(nestedContent);
|
|
65
|
+
resultDictionariesPaths.push(...dictionariesPaths);
|
|
66
|
+
}
|
|
67
|
+
return resultDictionariesPaths;
|
|
68
|
+
};
|
|
69
|
+
export { transpileBundledCode };
|
|
70
|
+
//# sourceMappingURL=transpileBundledCode.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/intlater_module_to_dictionary/transpileBundledCode.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { ContentModule } from '@intlayer/core';\nimport { extractObjectsWithId } from './extractNestedJSON';\nimport { processModule } from './processModule';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir, bundleFileExtension } = content;\n\nconst loadBundledModule = async (bundledEntryPath: string) => {\n const entryFilePath = resolve(bundledEntryPath);\n\n const isEntryFilePathExist = existsSync(entryFilePath);\n\n if (!isEntryFilePathExist) {\n console.error('Entry file not found. ' + entryFilePath);\n return;\n }\n\n const isEntryPathValid = entryFilePath.endsWith(bundleFileExtension);\n\n if (!isEntryPathValid) {\n return;\n }\n\n try {\n // Remove the module from the cache\n delete require.cache[entryFilePath];\n\n // Require the module anew\n const entry = await import(entryFilePath);\n\n let result: ContentModule | undefined;\n\n if (entry.default) {\n // JS or TS file\n result = await processModule(entryFilePath);\n } else {\n // JSON file\n result = entry;\n }\n\n return result;\n } catch (err) {\n console.error(`Error transpiling ${entryFilePath}:`, err);\n }\n};\n\nconst buildDictionary = async (dictionaries: ContentModule[]) => {\n const resultDictionariesPaths: string[] = [];\n\n for await (const content of dictionaries) {\n const contentString = JSON.stringify(content);\n\n const id = content.id;\n const outputFileName = `${id}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n\n return resultDictionariesPaths;\n};\n\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const transpileBundledCode = async (\n bundledEntriesPaths: string[] | string\n) => {\n const resultDictionariesPaths: string[] = [];\n\n if (typeof bundledEntriesPaths === 'string') {\n bundledEntriesPaths = [bundledEntriesPaths];\n }\n\n const filteredBundledEntriesPaths: string[] = bundledEntriesPaths.filter(\n // Filter js files;\n (bundledEntryPath) => bundledEntryPath.endsWith(bundleFileExtension)\n );\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dictionariesDir), { recursive: true });\n\n for await (const bundledEntryPath of filteredBundledEntriesPaths) {\n const result = await loadBundledModule(bundledEntryPath);\n\n if (!result) {\n continue;\n }\n\n const nestedContent: ContentModule[] = extractObjectsWithId(result);\n\n const dictionariesPaths: string[] = await buildDictionary(nestedContent);\n\n resultDictionariesPaths.push(...dictionari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KO,MAAM,uBAAuB,OAClC,wBACG;AACH,QAAM,0BAAoC,CAAC;AAE3C,MAAI,OAAO,wBAAwB,UAAU;AAC3C,0BAAsB,CAAC,mBAAmB;AAAA,EAC5C;AAEA,QAAM,8BAAwC,oBAAoB;AAAA;AAAA,IAEhE,CAAC,qBAAqB,iBAAiB,SAAS,mBAAmB;AAAA,EACrE;AAGA,QAAM,MAAM,QAAQ,eAAe,GAAG,EAAE,WAAW,KAAK,CAAC;AAEzD,mBAAiB,oBAAoB,6BAA6B;AAChE,UAAM,SAAS,MAAM,kBAAkB,gBAAgB;AAEvD,QAAI,CAAC,QAAQ;AACX;AAAA,IACF;AAEA,UAAM,gBAAiC,qBAAqB,MAAM;AAElE,UAAM,oBAA8B,MAAM,gBAAgB,aAAa;AAEvE,4BAAwB,KAAK,GAAG,iBAAiB;AAAA,EACnD;AAEA,SAAO;AACT;","names":["content"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SHA3, enc } from "crypto-js";
|
|
2
|
+
const getFileHash = (filePath) => {
|
|
3
|
+
const hash = SHA3(filePath);
|
|
4
|
+
return hash
|
|
5
|
+
.toString(enc.Base64)
|
|
6
|
+
.replace(/[^A-Z\d]/gi, "")
|
|
7
|
+
.substring(0, 20);
|
|
8
|
+
};
|
|
9
|
+
const transformToCamelCase = (string) => {
|
|
10
|
+
const words = string.split(/[\s\-_]+/);
|
|
11
|
+
const camelCasedWords = words.map((word, index) => {
|
|
12
|
+
if (index === 0) {
|
|
13
|
+
return word[0].toUpperCase() + word.slice(1);
|
|
14
|
+
}
|
|
15
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
16
|
+
});
|
|
17
|
+
return camelCasedWords.join("");
|
|
18
|
+
};
|
|
19
|
+
export { getFileHash, transformToCamelCase };
|
|
20
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import { SHA3, enc } from 'crypto-js';\n\nexport const getFileHash = (filePath: string) => {\n const hash = SHA3(filePath);\n\n return hash\n .toString(enc.Base64)\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n};\n\nexport const transformToCamelCase = (string: string): string => {\n // Split the string into words using a regex that finds spaces, hyphens, and underscores\n const words = string.split(/[\\s\\-_]+/);\n\n // Transform each word except the first to have its first letter uppercase\n const camelCasedWords = words.map((word, index) => {\n if (index === 0) {\n return word[0].toUpperCase() + word.slice(1);\n }\n return word.charAt(0).toUpperCase() + word.slice(1);\n });\n\n // Join the words back together\n return camelCasedWords.join('');\n};\n"],"mappings":"AAAA,SAAS,MAAM,WAAW;AAEnB,MAAM,cAAc,CAAC,aAAqB;AAC/C,QAAM,OAAO,KAAK,QAAQ;AAE1B,SAAO,KACJ,SAAS,IAAI,MAAM,EACnB,QAAQ,cAAc,EAAE,EACxB,UAAU,GAAG,EAAE;AACpB;AAEO,MAAM,uBAAuB,CAAC,WAA2B;AAE9D,QAAM,QAAQ,OAAO,MAAM,UAAU;AAGrC,QAAM,kBAAkB,MAAM,IAAI,CAAC,MAAM,UAAU;AACjD,QAAI,UAAU,GAAG;AACf,aAAO,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,IAC7C;AACA,WAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AAAA,EACpD,CAAC;AAGD,SAAO,gBAAgB,KAAK,EAAE;AAChC;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Compiler } from "webpack";
|
|
2
|
+
|
|
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;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { IntLayerPlugin };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { relative, resolve } from "path";
|
|
2
|
+
import { getConfiguration } from "@intlayer/config";
|
|
3
|
+
import { sync } from "glob";
|
|
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";
|
|
10
|
+
const getRelativePath = (filePath) => relative(baseDir, filePath);
|
|
11
|
+
const getBundledFilePathFromIntlayerModule = (filePath) => {
|
|
12
|
+
const hash = getFileHash(filePath);
|
|
13
|
+
return `${bundleDir}/${hash}${bundleFileExtension}`;
|
|
14
|
+
};
|
|
15
|
+
const { content } = getConfiguration();
|
|
16
|
+
const { bundleDir, baseDir, bundleFileExtension, watchedFilesPatternWithPath } =
|
|
17
|
+
content;
|
|
18
|
+
class IntLayerPlugin {
|
|
19
|
+
managedFiles;
|
|
20
|
+
updatedFiles;
|
|
21
|
+
addedFiles;
|
|
22
|
+
constructor() {
|
|
23
|
+
this.managedFiles = /* @__PURE__ */ new Set();
|
|
24
|
+
this.updatedFiles = /* @__PURE__ */ new Set();
|
|
25
|
+
this.addedFiles = /* @__PURE__ */ new Set();
|
|
26
|
+
}
|
|
27
|
+
// function to initialize the dictionaries
|
|
28
|
+
async initDictionaries() {
|
|
29
|
+
const outputFiles = [...this.managedFiles].map((file) =>
|
|
30
|
+
resolve(bundleDir, file)
|
|
31
|
+
);
|
|
32
|
+
const dictionaries = (await transpileBundledCode(outputFiles)) ?? [];
|
|
33
|
+
console.info(
|
|
34
|
+
`Dictionaries:
|
|
35
|
+
${dictionaries.map(getRelativePath).join("\n")}`
|
|
36
|
+
);
|
|
37
|
+
console.info("Building TypeScript types...");
|
|
38
|
+
createTypes(dictionaries);
|
|
39
|
+
console.info("Building type index...");
|
|
40
|
+
createModuleAugmentation();
|
|
41
|
+
console.info("Building main...");
|
|
42
|
+
createDictionaryList();
|
|
43
|
+
}
|
|
44
|
+
// function to process when intlayer module files content are changed
|
|
45
|
+
async processFilesChanges() {
|
|
46
|
+
const dictionaries =
|
|
47
|
+
(await transpileBundledCode([...this.updatedFiles])) ?? [];
|
|
48
|
+
console.info(
|
|
49
|
+
`Updated dictionaries:
|
|
50
|
+
${dictionaries.map(getRelativePath).join("\n")}`
|
|
51
|
+
);
|
|
52
|
+
console.info("Updating TypeScript types...");
|
|
53
|
+
createTypes(dictionaries);
|
|
54
|
+
this.updatedFiles.clear();
|
|
55
|
+
}
|
|
56
|
+
// function to process when new intlayer module is detected
|
|
57
|
+
async processNewFiles() {
|
|
58
|
+
const dictionaries =
|
|
59
|
+
(await transpileBundledCode([...this.addedFiles])) ?? [];
|
|
60
|
+
console.info(
|
|
61
|
+
`New dictionaries:
|
|
62
|
+
${dictionaries.map(getRelativePath).join("\n")}`
|
|
63
|
+
);
|
|
64
|
+
console.info("Building TypeScript types...");
|
|
65
|
+
createTypes(dictionaries);
|
|
66
|
+
console.info("Building type index...");
|
|
67
|
+
createModuleAugmentation();
|
|
68
|
+
console.info("Building main...");
|
|
69
|
+
createDictionaryList();
|
|
70
|
+
this.managedFiles = /* @__PURE__ */ new Set([
|
|
71
|
+
...this.managedFiles,
|
|
72
|
+
...this.addedFiles,
|
|
73
|
+
]);
|
|
74
|
+
this.addedFiles.clear();
|
|
75
|
+
}
|
|
76
|
+
async detectFileAddedOrRemoved() {
|
|
77
|
+
const filesFound = [];
|
|
78
|
+
for (const pattern of watchedFilesPatternWithPath) {
|
|
79
|
+
sync(pattern).map((file) => filesFound.push(file));
|
|
80
|
+
}
|
|
81
|
+
const newFiles = new Set(
|
|
82
|
+
filesFound.filter((x) => !this.managedFiles.has(x))
|
|
83
|
+
);
|
|
84
|
+
const removedFiles = new Set(
|
|
85
|
+
[...this.managedFiles].filter((x) => !filesFound.includes(x))
|
|
86
|
+
);
|
|
87
|
+
if (
|
|
88
|
+
// Check if there is new files
|
|
89
|
+
newFiles.size > 0
|
|
90
|
+
) {
|
|
91
|
+
console.info("New files:", [...newFiles]);
|
|
92
|
+
this.addedFiles = newFiles;
|
|
93
|
+
await this.processNewFiles();
|
|
94
|
+
}
|
|
95
|
+
if (
|
|
96
|
+
// Check if there is removed files
|
|
97
|
+
removedFiles.size > 0
|
|
98
|
+
) {
|
|
99
|
+
console.info("Removed files:", [...removedFiles]);
|
|
100
|
+
this.managedFiles = new Set(
|
|
101
|
+
[...this.managedFiles].filter((x) => !removedFiles.has(x))
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
if (this.updatedFiles.size > 0) {
|
|
105
|
+
await this.processFilesChanges();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
apply(compiler) {
|
|
109
|
+
compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => {
|
|
110
|
+
if (typeof entry === "function") {
|
|
111
|
+
new DynamicEntryPlugin(context, entry).apply(compiler);
|
|
112
|
+
}
|
|
113
|
+
return true;
|
|
114
|
+
});
|
|
115
|
+
compiler.hooks.afterEmit.tapAsync(
|
|
116
|
+
"IntLayerPlugin - Process dictionaries",
|
|
117
|
+
async (compilation, callback) => {
|
|
118
|
+
const currentEmitFiles = new Set(Object.keys(compilation.assets));
|
|
119
|
+
if (
|
|
120
|
+
// Check if this first load
|
|
121
|
+
!this.managedFiles.size
|
|
122
|
+
) {
|
|
123
|
+
this.managedFiles = currentEmitFiles;
|
|
124
|
+
await this.initDictionaries();
|
|
125
|
+
}
|
|
126
|
+
await this.detectFileAddedOrRemoved();
|
|
127
|
+
callback();
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
compiler.hooks.watchRun.tap(
|
|
131
|
+
"IntLayerPlugin - Change detection",
|
|
132
|
+
(compilation) => {
|
|
133
|
+
if (compilation.modifiedFiles) {
|
|
134
|
+
const updatedFiles = Array.from(compilation.modifiedFiles);
|
|
135
|
+
const outputFileNames = updatedFiles.map(
|
|
136
|
+
getBundledFilePathFromIntlayerModule
|
|
137
|
+
);
|
|
138
|
+
this.updatedFiles = new Set(outputFileNames);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export { IntLayerPlugin };
|
|
145
|
+
//# sourceMappingURL=webpack-plugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/webpack-plugin.ts"],"sourcesContent":["import { relative, resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport { sync } from 'glob';\nimport { DynamicEntryPlugin, type Compiler } from 'webpack';\nimport { createDictionaryList } from './transpiler/dictionary_to_main/createDictionaryList';\nimport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\nimport { createTypes } from './transpiler/dictionary_to_type/createType';\nimport { transpileBundledCode } from './transpiler/intlater_module_to_dictionary/transpileBundledCode';\nimport { getFileHash } from './utils';\n\nconst getRelativePath = (filePath: string) => relative(baseDir, filePath);\n\nconst getBundledFilePathFromIntlayerModule = (filePath: string): string => {\n const hash = getFileHash(filePath);\n\n return `${bundleDir}/${hash}${bundleFileExtension}`;\n};\n\nconst { content } = getConfiguration();\nconst { bundleDir, baseDir, bundleFileExtension, watchedFilesPatternWithPath } =\n content;\n\nexport class IntLayerPlugin {\n private managedFiles: Set<string>;\n private updatedFiles: Set<string>;\n private addedFiles: Set<string>;\n\n constructor() {\n this.managedFiles = new Set();\n this.updatedFiles = new Set();\n this.addedFiles = new Set();\n }\n\n // function to initialize the dictionaries\n public async initDictionaries() {\n const outputFiles = [...this.managedFiles].map((file) =>\n resolve(bundleDir, file)\n );\n\n const dictionaries = (await transpileBundledCode(outputFiles)) ?? [];\n\n console.info(\n `Dictionaries: \\n ${dictionaries.map(getRelativePath).join('\\n')}`\n );\n\n console.info('Building TypeScript types...');\n createTypes(dictionaries);\n\n console.info('Building type index...');\n createModuleAugmentation();\n\n console.info('Building main...');\n createDictionaryList();\n }\n\n // function to process when intlayer module files content are changed\n public async processFilesChanges() {\n const dictionaries =\n (await transpileBundledCode([...this.updatedFiles])) ?? [];\n\n console.info(\n `Updated dictionaries: \\n ${dictionaries.map(getRelativePath).join('\\n')}`\n );\n\n console.info('Updating TypeScript types...');\n createTypes(dictionaries);\n\n this.updatedFiles.clear();\n }\n\n // function to process when new intlayer module is detected\n public async processNewFiles() {\n const dictionaries =\n (await transpileBundledCode([...this.addedFiles])) ?? [];\n\n console.info(\n `New dictionaries: \\n ${dictionaries.map(getRelativePath).join('\\n')}`\n );\n\n console.info('Building TypeScript types...');\n createTypes(dictionaries);\n\n console.info('Building type index...');\n createModuleAugmentation();\n\n console.info('Building main...');\n createDictionaryList();\n\n this.managedFiles = new Set([...this.managedFiles, ...this.addedFiles]);\n this.addedFiles.clear();\n }\n\n public async detectFileAddedOrRemoved() {\n const filesFound: string[] = [];\n\n for (const pattern of watchedFilesPatternWithPath) {\n sync(pattern).map((file) => filesFound.push(file));\n }\n\n // Detect new files by comparing with files emitted in previous compilation\n const newFiles = new Set(\n filesFound.filter((x) => !this.managedFiles.has(x))\n );\n\n const removedFiles = new Set(\n [...this.managedFiles].filter((x) => !filesFound.includes(x))\n );\n\n if (\n // Check if there is new files\n newFiles.size > 0\n ) {\n console.info('New files:', [...newFiles]);\n\n this.addedFiles = newFiles;\n\n await this.processNewFiles();\n }\n\n if (\n // Check if there is removed files\n removedFiles.size > 0\n ) {\n console.info('Removed files:', [...removedFiles]);\n\n this.managedFiles = new Set(\n [...this.managedFiles].filter((x) => !removedFiles.has(x))\n );\n }\n\n // After the compilation, transpile the changed files if any\n if (this.updatedFiles.size > 0) {\n await this.processFilesChanges();\n }\n }\n\n apply(compiler: Compiler): void {\n compiler.hooks.entryOption.tap('EntryOptionPlugin', (context, entry) => {\n if (typeof entry === 'function') {\n // DynamicEntryPlugin is used to add entries at runtime when files are created, updated or deleted\n new DynamicEntryPlugin(context, entry).apply(compiler);\n }\n\n return true;\n });\n\n compiler.hooks.afterEmit.tapAsync(\n 'IntLayerPlugin - Process dictionaries',\n async (compilation, callback) => {\n // Get a set of files that will be emitted in this compilation\n const currentEmitFiles = new Set(Object.keys(compilation.assets));\n\n if (\n // Check if this first load\n !this.managedFiles.size\n ) {\n // Update previousEmitFiles for the next compilation\n this.managedFiles = currentEmitFiles;\n\n await this.initDictionaries();\n }\n\n await this.detectFileAddedOrRemoved();\n\n callback();\n }\n );\n\n // Detect modified files on watch mode\n compiler.hooks.watchRun.tap(\n 'IntLayerPlugin - Change detection',\n (compilation) => {\n if (compilation.modifiedFiles) {\n const updatedFiles = Array.from(compilation.modifiedFiles);\n\n const outputFileNames = updatedFiles.map(\n getBundledFilePathFromIntlayerModule\n );\n\n this.updatedFiles = new Set(outputFileNames);\n }\n }\n );\n }\n}\n"],"mappings":"AAAA,SAAS,UAAU,eAAe;AAClC,SAAS,wBAAwB;AACjC,SAAS,YAAY;AACrB,SAAS,0BAAyC;AAClD,SAAS,4BAA4B;AACrC,SAAS,gCAAgC;AACzC,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAE5B,MAAM,kBAAkB,CAAC,aAAqB,SAAS,SAAS,QAAQ;AAExE,MAAM,uCAAuC,CAAC,aAA6B;AACzE,QAAM,OAAO,YAAY,QAAQ;AAEjC,SAAO,GAAG,SAAS,IAAI,IAAI,GAAG,mBAAmB;AACnD;AAEA,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,WAAW,SAAS,qBAAqB,4BAA4B,IAC3E;AAEK,MAAM,eAAe;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EA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O,KAAK,YAAY,MAAM,CAAC;AAEhE;AAAA;AAAA,UAEE,CAAC,KAAK,aAAa;AAAA,UACnB;AAEA,eAAK,eAAe;AAEpB,gBAAM,KAAK,iBAAiB;AAAA,QAC9B;AAEA,cAAM,KAAK,yBAAyB;AAEpC,iBAAS;AAAA,MACX;AAAA,IACF;AAGA,aAAS,MAAM,SAAS;AAAA,MACtB;AAAA,MACA,CAAC,gBAAgB;AACf,YAAI,YAAY,eAAe;AAC7B,gBAAM,eAAe,MAAM,KAAK,YAAY,aAAa;AAEzD,gBAAM,kBAAkB,aAAa;AAAA,YACnC;AAAA,UACF;AAEA,eAAK,eAAe,IAAI,IAAI,eAAe;AAAA,QAC7C;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -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 };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { getConfiguration } from "@intlayer/config";
|
|
3
|
+
import { sync } from "glob";
|
|
4
|
+
import { getFileHash } from "./utils.mjs";
|
|
5
|
+
import { IntLayerPlugin } from "./webpack-plugin.mjs";
|
|
6
|
+
const { content } = getConfiguration({
|
|
7
|
+
verbose: true,
|
|
8
|
+
});
|
|
9
|
+
const { bundleDir, bundleFileExtension, watchedFilesPatternWithPath } = content;
|
|
10
|
+
const getEntry = () =>
|
|
11
|
+
sync(watchedFilesPatternWithPath).reduce((obj, el) => {
|
|
12
|
+
const hash = getFileHash(el);
|
|
13
|
+
obj[hash] = el;
|
|
14
|
+
return obj;
|
|
15
|
+
}, {});
|
|
16
|
+
const devServerConfig = {
|
|
17
|
+
// Enable hot module replacement
|
|
18
|
+
hot: true,
|
|
19
|
+
// Open the browser
|
|
20
|
+
open: false,
|
|
21
|
+
liveReload: false,
|
|
22
|
+
// Enable compression
|
|
23
|
+
compress: true,
|
|
24
|
+
// History API fallback
|
|
25
|
+
historyApiFallback: false,
|
|
26
|
+
// Host and port
|
|
27
|
+
host: "localhost",
|
|
28
|
+
port: 8080,
|
|
29
|
+
watchFiles: "./src/",
|
|
30
|
+
// watchedFilesPatternWithPath,
|
|
31
|
+
devMiddleware: {
|
|
32
|
+
// Enable write to disk to reuse the output
|
|
33
|
+
writeToDisk: true,
|
|
34
|
+
},
|
|
35
|
+
// Content base
|
|
36
|
+
static: {
|
|
37
|
+
directory: bundleDir,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
const webpackConfig = {
|
|
41
|
+
// Define the environment mode (development or production)
|
|
42
|
+
mode: "production",
|
|
43
|
+
// or 'production'
|
|
44
|
+
// Entry point of the application
|
|
45
|
+
target: "node",
|
|
46
|
+
// Specifies the target environment
|
|
47
|
+
entry: getEntry,
|
|
48
|
+
output: {
|
|
49
|
+
clean: true,
|
|
50
|
+
// Clean the output directory before emit
|
|
51
|
+
library: "IntlLayerContent",
|
|
52
|
+
libraryTarget: "umd",
|
|
53
|
+
filename: `[name]${bundleFileExtension}`,
|
|
54
|
+
path: bundleDir,
|
|
55
|
+
},
|
|
56
|
+
cache: false,
|
|
57
|
+
// devtool: 'source-map',
|
|
58
|
+
// stats: {
|
|
59
|
+
// preset: 'errors-only',
|
|
60
|
+
// warnings: false,
|
|
61
|
+
// },
|
|
62
|
+
ignoreWarnings: [/./],
|
|
63
|
+
resolve: {
|
|
64
|
+
// Resolve TypeScript, JavaScript and JSON files
|
|
65
|
+
extensions: [".ts", ".js", ".json", ".wasm", ".ts", ".tsx", ".mjs", ".cjs"],
|
|
66
|
+
modules: [
|
|
67
|
+
// To find the loader module
|
|
68
|
+
join(__dirname, "..", "node_modules"),
|
|
69
|
+
// In the project node_modules
|
|
70
|
+
join(process.cwd(), "node_modules"),
|
|
71
|
+
// In the project node_modules
|
|
72
|
+
join(process.cwd(), "node_modules", "intlayer-cli", "node_modules"),
|
|
73
|
+
// Or via another project by importing intlayer
|
|
74
|
+
join(
|
|
75
|
+
process.cwd(),
|
|
76
|
+
"node_modules",
|
|
77
|
+
"intlayer-cli",
|
|
78
|
+
"node_modules",
|
|
79
|
+
"@intlayer/webpack",
|
|
80
|
+
"node_modules"
|
|
81
|
+
),
|
|
82
|
+
// Or via another project by importing intlayer
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
resolveLoader: {
|
|
86
|
+
// Configure how Webpack finds `loader` modules.
|
|
87
|
+
modules: [
|
|
88
|
+
// To find the loader module
|
|
89
|
+
join(process.cwd(), "node_modules"),
|
|
90
|
+
// In the project node_modules
|
|
91
|
+
join(process.cwd(), "node_modules", "@intlayer/webpack", "node_modules"),
|
|
92
|
+
// Or via another project by importing @intlayer/webpack
|
|
93
|
+
join(
|
|
94
|
+
process.cwd(),
|
|
95
|
+
"node_modules",
|
|
96
|
+
"intlayer-cli",
|
|
97
|
+
"node_modules",
|
|
98
|
+
"@intlayer/webpack",
|
|
99
|
+
"node_modules"
|
|
100
|
+
),
|
|
101
|
+
// Or via another project by importing intlayer
|
|
102
|
+
],
|
|
103
|
+
// roots: [
|
|
104
|
+
// join(process.cwd()), // Project context
|
|
105
|
+
// join(process.cwd(), '@intlayer/webpack'), // Or via CLI in another project
|
|
106
|
+
// join(process.cwd(), 'intlayer', '@intlayer/webpack'), // Or via CLI in another project
|
|
107
|
+
// ],
|
|
108
|
+
},
|
|
109
|
+
module: {
|
|
110
|
+
rules: [
|
|
111
|
+
{
|
|
112
|
+
test: /\.node$/,
|
|
113
|
+
loader: "node-loader",
|
|
114
|
+
},
|
|
115
|
+
// Use esbuild to compile JavaScript & TypeScript
|
|
116
|
+
{
|
|
117
|
+
// Match `.js`, `.jsx`, `.ts` or `.tsx` files
|
|
118
|
+
test: /\.[jt]sx?$/,
|
|
119
|
+
loader: "esbuild-loader",
|
|
120
|
+
options: {
|
|
121
|
+
// JavaScript version to compile to
|
|
122
|
+
target: "es2015",
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
// JSON files are supported natively by Webpack 5, no specific loader required
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
devServer: devServerConfig,
|
|
129
|
+
plugins: [
|
|
130
|
+
new IntLayerPlugin(),
|
|
131
|
+
// new HotModuleReplacementPlugin()
|
|
132
|
+
],
|
|
133
|
+
};
|
|
134
|
+
var webpack_config_default = webpackConfig;
|
|
135
|
+
export { webpack_config_default as default, devServerConfig, webpackConfig };
|
|
136
|
+
//# sourceMappingURL=webpack.config.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/webpack.config.ts"],"sourcesContent":["import { join } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport { sync } from 'glob';\nimport type { Configuration as WebPackConfiguration } from 'webpack';\nimport type { Configuration as DevServerConfiguration } from 'webpack-dev-server';\nimport { getFileHash } from './utils';\nimport { IntLayerPlugin } from './webpack-plugin';\n\nconst { content } = getConfiguration({\n verbose: true,\n});\nconst { bundleDir, bundleFileExtension, watchedFilesPatternWithPath } = content;\n\nconst getEntry = (): Record<string, string> =>\n sync(watchedFilesPatternWithPath).reduce(\n (obj, el) => {\n const hash = getFileHash(el);\n\n obj[hash] = el;\n return obj;\n },\n {} as Record<string, string>\n );\n\n// For web interface\nexport const devServerConfig: DevServerConfiguration = {\n // Enable hot module replacement\n hot: true,\n // Open the browser\n open: false,\n liveReload: false,\n\n // Enable compression\n compress: true,\n\n // History API fallback\n historyApiFallback: false,\n\n // Host and port\n host: 'localhost',\n port: 8080,\n\n watchFiles: './src/', // watchedFilesPatternWithPath,\n\n devMiddleware: {\n // Enable write to disk to reuse the output\n writeToDisk: true,\n },\n\n // Content base\n static: {\n directory: bundleDir,\n },\n};\n\nexport const webpackConfig: WebPackConfiguration = {\n // Define the environment mode (development or production)\n mode: 'production', // or 'production'\n // Entry point of the application\n target: 'node', // Specifies the target environment\n\n entry: getEntry,\n output: {\n clean: true, // Clean the output directory before emit\n library: 'IntlLayerContent',\n libraryTarget: 'umd',\n filename: `[name]${bundleFileExtension}`,\n path: bundleDir,\n },\n\n cache: false,\n\n // devtool: 'source-map',\n\n // stats: {\n // preset: 'errors-only',\n // warnings: false,\n // },\n ignoreWarnings: [/./],\n resolve: {\n // Resolve TypeScript, JavaScript and JSON files\n extensions: ['.ts', '.js', '.json', '.wasm', '.ts', '.tsx', '.mjs', '.cjs'],\n modules: [\n // To find the loader module\n join(__dirname, '..', 'node_modules'), // In the project node_modules\n join(process.cwd(), 'node_modules'), // In the project node_modules\n join(process.cwd(), 'node_modules', 'intlayer-cli', 'node_modules'), // Or via another project by importing intlayer\n join(\n process.cwd(),\n 'node_modules',\n 'intlayer-cli',\n 'node_modules',\n '@intlayer/webpack',\n 'node_modules'\n ), // Or via another project by importing intlayer\n ],\n },\n\n resolveLoader: {\n // Configure how Webpack finds `loader` modules.\n modules: [\n // To find the loader module\n join(process.cwd(), 'node_modules'), // In the project node_modules\n join(process.cwd(), 'node_modules', '@intlayer/webpack', 'node_modules'), // Or via another project by importing @intlayer/webpack\n join(\n process.cwd(),\n 'node_modules',\n 'intlayer-cli',\n 'node_modules',\n '@intlayer/webpack',\n 'node_modules'\n ), // Or via another project by importing intlayer\n ],\n // roots: [\n // join(process.cwd()), // Project context\n // join(process.cwd(), '@intlayer/webpack'), // Or via CLI in another project\n // join(process.cwd(), 'intlayer', '@intlayer/webpack'), // Or via CLI in another project\n // ],\n },\n\n module: {\n rules: [\n {\n test: /\\.node$/,\n loader: 'node-loader',\n },\n // Use esbuild to compile JavaScript & TypeScript\n {\n // Match `.js`, `.jsx`, `.ts` or `.tsx` files\n test: /\\.[jt]sx?$/,\n loader: 'esbuild-loader',\n options: {\n // JavaScript version to compile to\n target: 'es2015',\n },\n },\n\n // JSON files are supported natively by Webpack 5, no specific loader required\n ],\n },\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