@eventcatalog/core 2.5.2 → 2.5.3
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/CHANGELOG.md +6 -0
- package/README.md +2 -2
- package/package.json +1 -1
- package/scripts/generate.js +88 -32
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
[![MIT License][license-badge]][license]
|
|
6
6
|
[![PRs Welcome][prs-badge]][prs]
|
|
7
7
|
<img src="https://img.shields.io/github/actions/workflow/status/event-catalog/eventcatalog/verify-build.yml"/>
|
|
8
|
-
[](https://discord.gg/3rjaZMmrAm) [<img src="https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white" height="20px" />](https://www.linkedin.com/in/david-boyne/) [](https://eda-visuals.boyney.io/?utm_source=event-catalog-gihub)
|
|
9
|
+
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
|
|
@@ -233,7 +234,6 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
233
234
|
|
|
234
235
|
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
|
235
236
|
|
|
236
|
-
|
|
237
237
|
# License
|
|
238
238
|
|
|
239
239
|
MIT.
|
package/package.json
CHANGED
package/scripts/generate.js
CHANGED
|
@@ -1,53 +1,109 @@
|
|
|
1
|
-
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { createRequire } from 'module';
|
|
1
|
+
import { readFile, writeFile, rm } from 'node:fs/promises';
|
|
3
2
|
import path from 'node:path';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Very strange behaviour when importing ESM files from catalogs into core.
|
|
6
|
+
* Core (node) does not know how to handle ESM files, so we have to try and convert them.
|
|
7
|
+
*
|
|
8
|
+
* This needs sorting out! Sorry if you are reading this, but it unblocked me for now!
|
|
9
|
+
* @param {*} content
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
function convertESMtoCJS(content) {
|
|
13
|
+
// Replace import statements with require
|
|
14
|
+
content = content.replace(/import\s+([a-zA-Z0-9{},\s*]+)\s+from\s+['"]([^'"]+)['"];/g, (match, imports, modulePath) => {
|
|
15
|
+
return `const ${imports.trim()} = require('${modulePath}');`;
|
|
16
|
+
});
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
// Replace export default with module.exports
|
|
19
|
+
content = content.replace(/export\s+default\s+/g, 'module.exports = ');
|
|
10
20
|
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
// Replace named exports with module.exports
|
|
22
|
+
content = content.replace(/export\s+{([^}]+)}/g, (match, exports) => {
|
|
23
|
+
return `module.exports = {${exports.trim()}};`;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Remove declarations of __filename and __dirname
|
|
27
|
+
content = content.replace(/^\s*(const|let|var)\s+__(filename|dirname)\s+=\s+.*;?\s*$/gm, '');
|
|
16
28
|
|
|
17
|
-
|
|
29
|
+
return content;
|
|
30
|
+
}
|
|
18
31
|
|
|
19
|
-
|
|
32
|
+
// TODO: Do we actually need this? Can we clean this up
|
|
33
|
+
function getDefaultExport(importedModule) {
|
|
34
|
+
if (importedModule === null || typeof importedModule !== 'object') {
|
|
35
|
+
throw new Error('Invalid module');
|
|
36
|
+
}
|
|
20
37
|
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
return;
|
|
38
|
+
if (typeof importedModule.default === 'object' && importedModule.default !== null) {
|
|
39
|
+
return importedModule.default.default || importedModule.default;
|
|
24
40
|
}
|
|
25
41
|
|
|
26
|
-
|
|
42
|
+
if (typeof importedModule.default !== 'undefined') {
|
|
43
|
+
return importedModule.default;
|
|
44
|
+
}
|
|
27
45
|
|
|
28
|
-
|
|
29
|
-
|
|
46
|
+
return importedModule;
|
|
47
|
+
}
|
|
30
48
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
async function cleanup() {
|
|
50
|
+
await rm(path.join(process.env.PROJECT_DIR, 'eventcatalog.config.cjs'));
|
|
51
|
+
}
|
|
34
52
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
53
|
+
const generate = async () => {
|
|
54
|
+
try {
|
|
55
|
+
// Fix for the file
|
|
56
|
+
const rawFile = await readFile(path.join(process.env.PROJECT_DIR, 'eventcatalog.config.js'), 'utf8');
|
|
57
|
+
|
|
58
|
+
// Have to conver the ESM to CJS...
|
|
59
|
+
const configAsCommonJS = convertESMtoCJS(rawFile);
|
|
60
|
+
await writeFile(path.join(process.env.PROJECT_DIR, 'eventcatalog.config.cjs'), configAsCommonJS);
|
|
38
61
|
|
|
39
|
-
|
|
40
|
-
|
|
62
|
+
const configAsCJS = await import(path.join(process.env.PROJECT_DIR, 'eventcatalog.config.cjs'));
|
|
63
|
+
const config = configAsCJS.default;
|
|
64
|
+
|
|
65
|
+
const { generators = [] } = config;
|
|
66
|
+
|
|
67
|
+
if (!generators.length) {
|
|
68
|
+
console.log('No configured generators found, skipping generation');
|
|
69
|
+
return;
|
|
41
70
|
}
|
|
42
71
|
|
|
43
|
-
|
|
72
|
+
// Tidy up
|
|
73
|
+
await writeFile(path.join(process.env.PROJECT_DIR, 'eventcatalog.config.js'), rawFile);
|
|
44
74
|
|
|
45
|
-
|
|
75
|
+
for (const generator of generators) {
|
|
76
|
+
let plugin = generator[0];
|
|
77
|
+
const pluginConfig = generator[1];
|
|
46
78
|
|
|
47
|
-
|
|
48
|
-
|
|
79
|
+
if (plugin.startsWith('./')) {
|
|
80
|
+
plugin = path.join(process.env.PROJECT_DIR, plugin);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (plugin.includes('<rootDir>')) {
|
|
84
|
+
plugin = plugin.replace('<rootDir>', process.env.PROJECT_DIR);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const importedGenerator = await import(plugin);
|
|
49
89
|
|
|
50
|
-
|
|
90
|
+
// TODO: Fix this...
|
|
91
|
+
const generator = getDefaultExport(importedGenerator);
|
|
92
|
+
|
|
93
|
+
await generator({ eventCatalogConfig: {} }, pluginConfig);
|
|
94
|
+
|
|
95
|
+
// Use importedGenerator here
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error('Error loading plugin:', error);
|
|
98
|
+
await cleanup();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
// Failed to generate clean up...
|
|
104
|
+
console.error(error);
|
|
105
|
+
await cleanup();
|
|
106
|
+
}
|
|
51
107
|
};
|
|
52
108
|
|
|
53
109
|
generate();
|