@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,39 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|
|
@@ -1,70 +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 { 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
|
|
@@ -1 +0,0 @@
|
|
|
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(...dictionariesPaths);\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;AACxB,SAAS,wBAAwB;AAEjC,SAAS,4BAA4B;AACrC,SAAS,qBAAqB;AAE9B,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,iBAAiB,oBAAoB,IAAI;AAEjD,MAAM,oBAAoB,OAAO,qBAA6B;AAC5D,QAAM,gBAAgB,QAAQ,gBAAgB;AAE9C,QAAM,uBAAuB,WAAW,aAAa;AAErD,MAAI,CAAC,sBAAsB;AACzB,YAAQ,MAAM,2BAA2B,aAAa;AACtD;AAAA,EACF;AAEA,QAAM,mBAAmB,cAAc,SAAS,mBAAmB;AAEnE,MAAI,CAAC,kBAAkB;AACrB;AAAA,EACF;AAEA,MAAI;AAEF,WAAO,QAAQ,MAAM,aAAa;AAGlC,UAAM,QAAQ,MAAM,OAAO;AAE3B,QAAI;AAEJ,QAAI,MAAM,SAAS;AAEjB,eAAS,MAAM,cAAc,aAAa;AAAA,IAC5C,OAAO;AAEL,eAAS;AAAA,IACX;AAEA,WAAO;AAAA,EACT,SAAS,KAAK;AACZ,YAAQ,MAAM,qBAAqB,aAAa,KAAK,GAAG;AAAA,EAC1D;AACF;AAEA,MAAM,kBAAkB,OAAO,iBAAkC;AAC/D,QAAM,0BAAoC,CAAC;AAE3C,mBAAiBA,YAAW,cAAc;AACxC,UAAM,gBAAgB,KAAK,UAAUA,QAAO;AAE5C,UAAM,KAAKA,SAAQ;AACnB,UAAM,iBAAiB,GAAG,EAAE;AAC5B,UAAM,iBAAiB,QAAQ,iBAAiB,cAAc;AAG9D,UAAM,UAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,IACxD,CAAC;AAED,4BAAwB,KAAK,cAAc;AAAA,EAC7C;AAEA,SAAO;AACT;AAKO,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"]}
|
package/src/scripts/bundle.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { Compiler } from 'webpack';
|
|
2
|
-
|
|
3
|
-
export const bundle = (compiler: Compiler) =>
|
|
4
|
-
// Run the compiler
|
|
5
|
-
compiler.run((err, stats) => {
|
|
6
|
-
// Handle errors and webpack compilation stats
|
|
7
|
-
if (err) {
|
|
8
|
-
console.error('Webpack compilation error:', err);
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
console.info('Webpack compilation successful.');
|
|
13
|
-
|
|
14
|
-
if (stats)
|
|
15
|
-
console.info(
|
|
16
|
-
stats.toString({
|
|
17
|
-
// Add options here to customize the stats output
|
|
18
|
-
colors: true,
|
|
19
|
-
})
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export const watch = (compiler: Compiler) =>
|
|
24
|
-
// Run the compiler
|
|
25
|
-
compiler.watch({}, (err, stats) => {
|
|
26
|
-
// Handle errors and webpack compilation stats
|
|
27
|
-
if (err) {
|
|
28
|
-
console.error('Webpack compilation error:', err);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
console.info('Webpack compilation successful.');
|
|
33
|
-
|
|
34
|
-
if (stats)
|
|
35
|
-
console.info(
|
|
36
|
-
stats.toString({
|
|
37
|
-
// Add options here to customize the stats output
|
|
38
|
-
colors: true,
|
|
39
|
-
})
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
// After successful compilation, start the server
|
|
43
|
-
console.info('Watch IntLayer content...');
|
|
44
|
-
});
|
package/src/scripts/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Compiler } from 'webpack';
|
|
2
|
-
import { devServerConfig } from '../webpack.config';
|
|
3
|
-
|
|
4
|
-
const WebpackDevServer = require('webpack-dev-server');
|
|
5
|
-
|
|
6
|
-
export const startServer = (compiler: Compiler) => {
|
|
7
|
-
// Create a new instance of webpack-dev-server
|
|
8
|
-
const devServer = new WebpackDevServer(devServerConfig, compiler);
|
|
9
|
-
|
|
10
|
-
// Start the server
|
|
11
|
-
devServer.startCallback(() => {
|
|
12
|
-
console.info('Webpack Dev Server is running...');
|
|
13
|
-
});
|
|
14
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
2
|
-
import { basename, extname, relative, resolve } from 'path';
|
|
3
|
-
import { getConfiguration } from '@intlayer/config';
|
|
4
|
-
import { sync } from 'glob';
|
|
5
|
-
import { getFileHash } from '../../utils';
|
|
6
|
-
|
|
7
|
-
const { content } = getConfiguration();
|
|
8
|
-
const { dictionariesDir, mainDir } = content;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* This function generates the content of the dictionary list file
|
|
12
|
-
*/
|
|
13
|
-
const generateDictionaryListContent = (
|
|
14
|
-
dictionaries: string[],
|
|
15
|
-
format: 'cjs' | 'esm' = 'esm'
|
|
16
|
-
): string => {
|
|
17
|
-
let content = '';
|
|
18
|
-
|
|
19
|
-
const dictionariesRef = dictionaries.map((dictionaryPath) => ({
|
|
20
|
-
relativePath: relative(mainDir, dictionaryPath),
|
|
21
|
-
id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id
|
|
22
|
-
hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
// Import all dictionaries
|
|
26
|
-
dictionariesRef.forEach((dictionary) => {
|
|
27
|
-
if (format === 'esm')
|
|
28
|
-
content += `import ${dictionary.hash} from '${dictionary.relativePath}';\n`;
|
|
29
|
-
if (format === 'cjs')
|
|
30
|
-
content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\n`;
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
content += '\n';
|
|
34
|
-
|
|
35
|
-
// Format Dictionary Map
|
|
36
|
-
const formattedDictionaryMap: string = dictionariesRef
|
|
37
|
-
.map((dictionary) => `"${dictionary.id}": ${dictionary.hash}`)
|
|
38
|
-
.join(',\n');
|
|
39
|
-
|
|
40
|
-
if (format === 'esm')
|
|
41
|
-
content += `export default {\n${formattedDictionaryMap}\n};\n`;
|
|
42
|
-
if (format === 'cjs')
|
|
43
|
-
content += `module.exports = {\n${formattedDictionaryMap}\n};\n`;
|
|
44
|
-
|
|
45
|
-
return content;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* This function generates a list of dictionaries in the main directory
|
|
50
|
-
*/
|
|
51
|
-
export const createDictionaryList = () => {
|
|
52
|
-
// Create main directory if it doesn't exist
|
|
53
|
-
if (!existsSync(mainDir)) {
|
|
54
|
-
mkdirSync(mainDir, { recursive: true });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const dictionaries: string[] = sync(`${dictionariesDir}/**/*.json`);
|
|
58
|
-
|
|
59
|
-
// Create the dictionary list file
|
|
60
|
-
const cjsContent = generateDictionaryListContent(dictionaries, 'cjs');
|
|
61
|
-
writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);
|
|
62
|
-
|
|
63
|
-
const esmContent = generateDictionaryListContent(dictionaries, 'esm');
|
|
64
|
-
writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);
|
|
65
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './createDictionaryList';
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
2
|
-
import { basename, join, relative } from 'path';
|
|
3
|
-
import { getConfiguration } from '@intlayer/config';
|
|
4
|
-
import { sync } from 'glob';
|
|
5
|
-
import { getFileHash, transformToCamelCase } from '../../utils';
|
|
6
|
-
|
|
7
|
-
const { content } = getConfiguration();
|
|
8
|
-
const { typesDir, moduleAugmentationDir } = content;
|
|
9
|
-
|
|
10
|
-
export const getTypeName = (id: string): string =>
|
|
11
|
-
transformToCamelCase(`${id}Content`);
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* This function generates the content of the module augmentation file
|
|
15
|
-
*/
|
|
16
|
-
const generateTypeIndexContent = (typeFiles: string[]): string => {
|
|
17
|
-
let content = "import 'intlayer';\n\n";
|
|
18
|
-
|
|
19
|
-
const dictionariesRef = typeFiles.map((dictionaryPath) => ({
|
|
20
|
-
relativePath: relative(moduleAugmentationDir, dictionaryPath),
|
|
21
|
-
id: basename(dictionaryPath, '.d.ts'), // Get the base name as the dictionary id
|
|
22
|
-
hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
// Import all dictionaries
|
|
26
|
-
dictionariesRef.forEach((dictionary) => {
|
|
27
|
-
const typeName = getTypeName(dictionary.id);
|
|
28
|
-
content += `import type { ${typeName} as ${dictionary.hash} } from '${dictionary.relativePath}';\n`;
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
content += '\n';
|
|
32
|
-
|
|
33
|
-
// Format Dictionary Map
|
|
34
|
-
const formattedDictionaryMap: string = dictionariesRef
|
|
35
|
-
.map((dictionary) => ` "${dictionary.id}": ${dictionary.hash};`)
|
|
36
|
-
.join('\n');
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Write the module augmentation to extend the intlayer module with the dictionaries types
|
|
40
|
-
* Will suggest the type resulting of the dictionaries
|
|
41
|
-
*
|
|
42
|
-
* declare module 'intlayer' {
|
|
43
|
-
* interface IntlayerDictionaryTypesConnector = {
|
|
44
|
-
* dictionaries: {
|
|
45
|
-
* id: DictionaryType;
|
|
46
|
-
* }
|
|
47
|
-
* }
|
|
48
|
-
*
|
|
49
|
-
* See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
50
|
-
*/
|
|
51
|
-
content += `declare module 'intlayer' {\n interface IntlayerDictionaryTypesConnector {\n${formattedDictionaryMap}\n };\n};`;
|
|
52
|
-
|
|
53
|
-
return content;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* This function generates a index file merging all the types
|
|
58
|
-
*/
|
|
59
|
-
export const createModuleAugmentation = () => {
|
|
60
|
-
// Create main directory if it doesn't exist
|
|
61
|
-
if (!existsSync(moduleAugmentationDir)) {
|
|
62
|
-
mkdirSync(moduleAugmentationDir, { recursive: true });
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const dictionaries: string[] = sync(`${typesDir}/**/*.d.ts`);
|
|
66
|
-
// Create the dictionary list file
|
|
67
|
-
|
|
68
|
-
const tsContent = generateTypeIndexContent(dictionaries);
|
|
69
|
-
writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);
|
|
70
|
-
};
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
2
|
-
import { resolve } from 'path';
|
|
3
|
-
import { getConfiguration } from '@intlayer/config';
|
|
4
|
-
import {
|
|
5
|
-
NodeType,
|
|
6
|
-
type Content,
|
|
7
|
-
type ContentModule,
|
|
8
|
-
type TypedNode,
|
|
9
|
-
} from '@intlayer/core';
|
|
10
|
-
import { getTypeName } from './createModuleAugmentation';
|
|
11
|
-
|
|
12
|
-
const { content, internationalization } = getConfiguration();
|
|
13
|
-
const { typesDir } = content;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* This function generates a TypeScript type definition from a JSON object
|
|
18
|
-
*
|
|
19
|
-
* Example:
|
|
20
|
-
*
|
|
21
|
-
* const input = {
|
|
22
|
-
* id: '1',
|
|
23
|
-
* name: 'John Doe',
|
|
24
|
-
* address: {
|
|
25
|
-
* id: '2',
|
|
26
|
-
* street: '123 Main St',
|
|
27
|
-
* city: 'Springfield',
|
|
28
|
-
* }
|
|
29
|
-
* };
|
|
30
|
-
*
|
|
31
|
-
* const result = generateTypeScriptType(input, 'RootObject');
|
|
32
|
-
* console.log(result);
|
|
33
|
-
*
|
|
34
|
-
* Output:
|
|
35
|
-
*
|
|
36
|
-
* type RootObject = {
|
|
37
|
-
* id: '1',
|
|
38
|
-
* name: string,
|
|
39
|
-
* address: {
|
|
40
|
-
* id: '2',
|
|
41
|
-
* street: string,
|
|
42
|
-
* city: string,
|
|
43
|
-
* },
|
|
44
|
-
* };
|
|
45
|
-
*
|
|
46
|
-
*/
|
|
47
|
-
export const generateTypeScriptType = (obj: ContentModule): string => {
|
|
48
|
-
let typeDefinition = ``;
|
|
49
|
-
|
|
50
|
-
const typeName = getTypeName(obj.id);
|
|
51
|
-
|
|
52
|
-
typeDefinition += `export type ${typeName} = {\n`;
|
|
53
|
-
typeDefinition += generateTypeScriptTypeContent(obj);
|
|
54
|
-
typeDefinition += '};\n\n';
|
|
55
|
-
|
|
56
|
-
return typeDefinition;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const generateTypeScriptTypeContent = (obj: Content): string => {
|
|
60
|
-
let typeDefinition = ``;
|
|
61
|
-
|
|
62
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
|
-
const nodeType: NodeType | undefined = (value as TypedNode).nodeType;
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
// Check if the value is a typed node
|
|
68
|
-
typeof value === 'object' &&
|
|
69
|
-
nodeType === NodeType.Translation
|
|
70
|
-
) {
|
|
71
|
-
const tsType =
|
|
72
|
-
typeof value[internationalization.defaultLocale as keyof typeof value];
|
|
73
|
-
typeDefinition += ` ${key}: ${tsType},\n`;
|
|
74
|
-
} else if (
|
|
75
|
-
// Check if the value is a typed node
|
|
76
|
-
typeof value === 'object' &&
|
|
77
|
-
nodeType === NodeType.Enumeration
|
|
78
|
-
) {
|
|
79
|
-
const tsType =
|
|
80
|
-
typeof value[internationalization.defaultLocale as keyof typeof value];
|
|
81
|
-
|
|
82
|
-
typeDefinition += ` ${key}: (quantity: number) => ${tsType},\n`;
|
|
83
|
-
} else if (
|
|
84
|
-
// Check if the value is a nested object
|
|
85
|
-
typeof value === 'object' &&
|
|
86
|
-
!Array.isArray(value)
|
|
87
|
-
) {
|
|
88
|
-
// Nested object, recurse
|
|
89
|
-
const nestedType = generateTypeScriptTypeContent(value as Content);
|
|
90
|
-
typeDefinition += ` ${key}: {${nestedType}},\n`;
|
|
91
|
-
} else if (
|
|
92
|
-
// Check if the value is an array
|
|
93
|
-
Array.isArray(value)
|
|
94
|
-
) {
|
|
95
|
-
// Array handling (simplified, assumes non-empty arrays with uniform type)
|
|
96
|
-
const arrayType = typeof value[0];
|
|
97
|
-
typeDefinition += ` ${key}: ${arrayType}[],\n`;
|
|
98
|
-
} else if (
|
|
99
|
-
// Check if the value is an 'id'
|
|
100
|
-
typeof value === 'string' &&
|
|
101
|
-
key === 'id'
|
|
102
|
-
) {
|
|
103
|
-
// Special handling for 'id' field
|
|
104
|
-
const tsType = `"${value}"`;
|
|
105
|
-
typeDefinition += ` ${key}: ${tsType},\n`;
|
|
106
|
-
} else {
|
|
107
|
-
// Primitive type
|
|
108
|
-
const tsType = typeof value;
|
|
109
|
-
typeDefinition += ` ${key}: ${tsType},\n`;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return typeDefinition;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* This function generates a TypeScript type definition from a JSON object
|
|
118
|
-
*/
|
|
119
|
-
export const createTypes = (dictionariesPaths: string[]): string[] => {
|
|
120
|
-
const resultTypesPaths: string[] = [];
|
|
121
|
-
|
|
122
|
-
// Create type folders if they don't exist
|
|
123
|
-
if (!existsSync(typesDir)) {
|
|
124
|
-
mkdirSync(typesDir, { recursive: true });
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
for (const dictionaryPath of dictionariesPaths) {
|
|
128
|
-
const contentModule: ContentModule = require(dictionaryPath);
|
|
129
|
-
const dictionaryName: string = contentModule.id;
|
|
130
|
-
const typeDefinition: string = generateTypeScriptType(contentModule);
|
|
131
|
-
|
|
132
|
-
const outputPath = resolve(typesDir, `${dictionaryName}.d.ts`);
|
|
133
|
-
|
|
134
|
-
writeFileSync(outputPath, typeDefinition);
|
|
135
|
-
|
|
136
|
-
resultTypesPaths.push(outputPath);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return resultTypesPaths;
|
|
140
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { Content, 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
|
-
export const extractObjectsWithId = (input: ContentModule): ContentModule[] => {
|
|
43
|
-
// Function to recursively search and extract nested objects with an 'id'
|
|
44
|
-
const search = (obj: Content, results: ContentModule[]): void => {
|
|
45
|
-
if (obj && typeof obj === 'object') {
|
|
46
|
-
if (Object.prototype.hasOwnProperty.call(obj, 'id')) {
|
|
47
|
-
results.push(obj as ContentModule);
|
|
48
|
-
}
|
|
49
|
-
for (const key of Object.keys(obj)) {
|
|
50
|
-
if (typeof obj[key] === 'object') {
|
|
51
|
-
search(obj[key] as Content, results);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const results: ContentModule[] = [];
|
|
58
|
-
search(input, results);
|
|
59
|
-
return results;
|
|
60
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'path';
|
|
2
|
-
import type {
|
|
3
|
-
Content,
|
|
4
|
-
ContentModule,
|
|
5
|
-
FlatContent,
|
|
6
|
-
FlatContentValue,
|
|
7
|
-
} from '@intlayer/core';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Function to load the module file in a sandboxed environment
|
|
11
|
-
*/
|
|
12
|
-
const loadModule = async (modulePath: string): Promise<ContentModule> => {
|
|
13
|
-
// @TODO: Sandbox the module to prevent malicious code execution
|
|
14
|
-
|
|
15
|
-
return (await import(modulePath)).default;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Function to replace function and async function fields with their results in the object
|
|
20
|
-
*/
|
|
21
|
-
const processFunctionResults = async (entry: Content): Promise<FlatContent> => {
|
|
22
|
-
if (entry && typeof entry === 'object') {
|
|
23
|
-
const promises: Promise<void>[] = [];
|
|
24
|
-
const result: FlatContent = {};
|
|
25
|
-
|
|
26
|
-
for (const key of Object.keys(entry)) {
|
|
27
|
-
const field = entry?.[key];
|
|
28
|
-
|
|
29
|
-
if (typeof field === 'object') {
|
|
30
|
-
result[key] = (await processFunctionResults(
|
|
31
|
-
field as Content
|
|
32
|
-
)) as FlatContentValue;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (typeof field === 'function') {
|
|
36
|
-
// Wait for the function to resolve if it's an async function
|
|
37
|
-
const promise = (async () => {
|
|
38
|
-
// Execute the function and await the result if it's a Promise
|
|
39
|
-
const value = await field();
|
|
40
|
-
result[key] = value as FlatContentValue;
|
|
41
|
-
})();
|
|
42
|
-
promises.push(promise);
|
|
43
|
-
} else {
|
|
44
|
-
result[key] = field as FlatContentValue;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Wait for all async operations to complete
|
|
49
|
-
await Promise.all(promises);
|
|
50
|
-
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return entry;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Function to load, process the module and return the Intlayer ContentModule from the module file
|
|
59
|
-
*/
|
|
60
|
-
export const processModule = async (file: string) => {
|
|
61
|
-
try {
|
|
62
|
-
const functionPath = resolve(file);
|
|
63
|
-
const entry = await loadModule(functionPath);
|
|
64
|
-
|
|
65
|
-
return (await processFunctionResults(entry)) as ContentModule;
|
|
66
|
-
} catch (error) {
|
|
67
|
-
console.error('Error processing module:', error);
|
|
68
|
-
}
|
|
69
|
-
};
|