@eventcatalog/core 2.13.4 → 2.14.1
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/.github/workflows/test-e2e.yml +19 -21
- package/CHANGELOG.md +12 -0
- package/bin/dist/eventcatalog.cjs +478 -26
- package/bin/dist/eventcatalog.js +478 -26
- package/package.json +4 -6
- package/scripts/analytics/analytics.js +2 -16
- package/scripts/analytics/log-build.js +8 -4
- package/scripts/build-ci.js +14 -7
- package/scripts/catalog-to-astro-content-directory.js +13 -10
- package/scripts/constants.ts +3 -0
- package/scripts/generate.js +1 -4
- package/scripts/start-catalog-locally.js +19 -11
- package/scripts/watcher.js +0 -17
- package/src/utils/node-graphs/services-node-graph.ts +4 -8
- /package/{scripts/default-files-for-collections → default-files-for-collections}/changelogs.md +0 -0
- /package/{scripts/default-files-for-collections → default-files-for-collections}/channels.md +0 -0
- /package/{scripts/default-files-for-collections → default-files-for-collections}/commands.md +0 -0
- /package/{scripts/default-files-for-collections → default-files-for-collections}/domains.md +0 -0
- /package/{scripts/default-files-for-collections → default-files-for-collections}/events.md +0 -0
- /package/{scripts/default-files-for-collections → default-files-for-collections}/flows.md +0 -0
- /package/{scripts/default-files-for-collections → default-files-for-collections}/pages.md +0 -0
- /package/{scripts/default-files-for-collections → default-files-for-collections}/queries.md +0 -0
- /package/{scripts/default-files-for-collections → default-files-for-collections}/services.md +0 -0
- /package/{scripts/default-files-for-collections → default-files-for-collections}/teams.md +0 -0
- /package/{scripts/default-files-for-collections → default-files-for-collections}/users.md +0 -0
package/bin/dist/eventcatalog.js
CHANGED
|
@@ -3,24 +3,462 @@
|
|
|
3
3
|
// bin/eventcatalog.ts
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import { execSync } from "node:child_process";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import
|
|
6
|
+
import { join as join2 } from "node:path";
|
|
7
|
+
import fs3 from "fs";
|
|
8
|
+
import path5 from "node:path";
|
|
9
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
10
|
+
import concurrently from "concurrently";
|
|
11
|
+
|
|
12
|
+
// scripts/generate.js
|
|
13
|
+
import path2 from "node:path";
|
|
14
|
+
|
|
15
|
+
// scripts/eventcatalog-config-file-utils.js
|
|
16
|
+
import { readFile, writeFile, rm } from "node:fs/promises";
|
|
17
|
+
import { existsSync } from "node:fs";
|
|
18
|
+
import { copyFile } from "node:fs/promises";
|
|
8
19
|
import path from "node:path";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
import { v4 as uuidV4 } from "uuid";
|
|
21
|
+
import { pathToFileURL } from "url";
|
|
22
|
+
import matter from "gray-matter";
|
|
23
|
+
async function cleanup(projectDirectory) {
|
|
24
|
+
const filePath = path.join(projectDirectory, "eventcatalog.config.mjs");
|
|
25
|
+
if (existsSync(filePath)) {
|
|
26
|
+
await rm(filePath);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
var getEventCatalogConfigFile = async (projectDirectory) => {
|
|
30
|
+
try {
|
|
31
|
+
let configFilePath = path.join(projectDirectory, "eventcatalog.config.js");
|
|
32
|
+
const filePath = path.join(projectDirectory, "package.json");
|
|
33
|
+
const packageJson = JSON.parse(await readFile(filePath, "utf-8"));
|
|
34
|
+
if (packageJson?.type !== "module") {
|
|
35
|
+
await copyFile(configFilePath, path.join(projectDirectory, "eventcatalog.config.mjs"));
|
|
36
|
+
configFilePath = path.join(projectDirectory, "eventcatalog.config.mjs");
|
|
37
|
+
}
|
|
38
|
+
const configFileURL = pathToFileURL(configFilePath).href;
|
|
39
|
+
const config = await import(
|
|
40
|
+
/* @vite-ignore */
|
|
41
|
+
configFileURL
|
|
42
|
+
);
|
|
43
|
+
return config.default;
|
|
44
|
+
} finally {
|
|
45
|
+
await cleanup(projectDirectory);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var writeEventCatalogConfigFile = async (projectDirectory, newConfig) => {
|
|
49
|
+
try {
|
|
50
|
+
const configFilePath = path.join(projectDirectory, "eventcatalog.config.js");
|
|
51
|
+
let content = await readFile(configFilePath, "utf8");
|
|
52
|
+
const startIndex = content.indexOf("export default {");
|
|
53
|
+
if (startIndex === -1) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
Object.entries(newConfig).forEach(([key, value]) => {
|
|
57
|
+
const valueString = JSON.stringify(value, null, 2).replace(/"/g, "'").replace(/\n/g, "\n ");
|
|
58
|
+
const keyRegex = new RegExp(`(${key}\\s*:)([^,}]+)`, "g");
|
|
59
|
+
if (content.match(keyRegex)) {
|
|
60
|
+
content = content.replace(keyRegex, `$1 ${valueString}`);
|
|
61
|
+
} else {
|
|
62
|
+
const insertPosition = content.indexOf("{", startIndex) + 1;
|
|
63
|
+
content = content.slice(0, insertPosition) + `
|
|
64
|
+
${key}: ${valueString},` + content.slice(insertPosition);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
await writeFile(configFilePath, content);
|
|
68
|
+
} finally {
|
|
69
|
+
await cleanup(projectDirectory);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var verifyRequiredFieldsAreInCatalogConfigFile = async (projectDirectory) => {
|
|
73
|
+
try {
|
|
74
|
+
const config = await getEventCatalogConfigFile(projectDirectory);
|
|
75
|
+
if (!config.cId) {
|
|
76
|
+
await writeEventCatalogConfigFile(projectDirectory, { cId: uuidV4() });
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
function addPropertyToFrontMatter(input, newProperty, newValue) {
|
|
82
|
+
const file = matter(input);
|
|
83
|
+
return matter.stringify(file.content, { ...file.data, [newProperty]: newValue });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// scripts/generate.js
|
|
87
|
+
function getDefaultExport(importedModule) {
|
|
88
|
+
if (importedModule === null || typeof importedModule !== "object") {
|
|
89
|
+
throw new Error("Invalid module");
|
|
90
|
+
}
|
|
91
|
+
if (typeof importedModule.default === "object" && importedModule.default !== null) {
|
|
92
|
+
return importedModule.default.default || importedModule.default;
|
|
93
|
+
}
|
|
94
|
+
if (typeof importedModule.default !== "undefined") {
|
|
95
|
+
return importedModule.default;
|
|
96
|
+
}
|
|
97
|
+
return importedModule;
|
|
98
|
+
}
|
|
99
|
+
var generate = async (PROJECT_DIRECTORY) => {
|
|
100
|
+
try {
|
|
101
|
+
const config = await getEventCatalogConfigFile(PROJECT_DIRECTORY);
|
|
102
|
+
const { generators = [] } = config;
|
|
103
|
+
if (!generators.length) {
|
|
104
|
+
console.log("No configured generators found, skipping generation");
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
for (const generator of generators) {
|
|
108
|
+
let plugin = generator[0];
|
|
109
|
+
const pluginConfig = generator[1];
|
|
110
|
+
if (plugin.startsWith("./")) {
|
|
111
|
+
plugin = path2.join(PROJECT_DIRECTORY, plugin);
|
|
112
|
+
}
|
|
113
|
+
if (plugin.includes("<rootDir>")) {
|
|
114
|
+
plugin = plugin.replace("<rootDir>", PROJECT_DIRECTORY);
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const importedGenerator = await import(plugin);
|
|
118
|
+
const generator2 = getDefaultExport(importedGenerator);
|
|
119
|
+
await generator2({ eventCatalogConfig: {} }, pluginConfig);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error("Error loading plugin:", error);
|
|
122
|
+
await cleanup(PROJECT_DIRECTORY);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
await cleanup(PROJECT_DIRECTORY);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error(error);
|
|
129
|
+
await cleanup(PROJECT_DIRECTORY);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// scripts/analytics/analytics.js
|
|
134
|
+
import axios from "axios";
|
|
135
|
+
import os from "os";
|
|
136
|
+
|
|
137
|
+
// package.json
|
|
138
|
+
var version = "2.14.1";
|
|
139
|
+
|
|
140
|
+
// scripts/constants.ts
|
|
141
|
+
var VERSION = version;
|
|
142
|
+
|
|
143
|
+
// scripts/analytics/analytics.js
|
|
144
|
+
async function raiseEvent(eventData) {
|
|
145
|
+
const url = "https://queue.simpleanalyticscdn.com/events";
|
|
146
|
+
const userAgent = `@eventcatalog/eventcatalog@${VERSION} (${os.platform()}; ${os.arch()}; Node/${process.version})`;
|
|
147
|
+
const headers = {
|
|
148
|
+
"Content-Type": "application/json"
|
|
149
|
+
};
|
|
150
|
+
const payload = {
|
|
151
|
+
type: "event",
|
|
152
|
+
hostname: "eventcatalog.dev",
|
|
153
|
+
event: "@eventcatalog/eventcatalog",
|
|
154
|
+
metadata: {
|
|
155
|
+
...eventData,
|
|
156
|
+
t: `t;${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
157
|
+
ua: userAgent
|
|
158
|
+
},
|
|
159
|
+
ua: userAgent
|
|
160
|
+
};
|
|
161
|
+
try {
|
|
162
|
+
await axios.post(url, payload, { headers });
|
|
163
|
+
} catch (error) {
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// scripts/analytics/log-build.js
|
|
168
|
+
var main = async (projectDir) => {
|
|
169
|
+
if (process.env.NODE_ENV === "CI") return;
|
|
170
|
+
try {
|
|
171
|
+
await verifyRequiredFieldsAreInCatalogConfigFile(projectDir);
|
|
172
|
+
const configFile = await getEventCatalogConfigFile(projectDir);
|
|
173
|
+
const { cId, organizationName, generators = [] } = configFile;
|
|
174
|
+
const generatorNames = generators.length > 0 ? generators.map((generator) => generator[0]) : ["none"];
|
|
175
|
+
await raiseEvent({
|
|
176
|
+
command: "build",
|
|
177
|
+
org: organizationName,
|
|
178
|
+
cId,
|
|
179
|
+
generators: generatorNames.toString()
|
|
180
|
+
});
|
|
181
|
+
} catch (error) {
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
var log_build_default = main;
|
|
185
|
+
|
|
186
|
+
// scripts/watcher.js
|
|
187
|
+
import watcher from "@parcel/watcher";
|
|
188
|
+
import fs from "node:fs";
|
|
189
|
+
|
|
190
|
+
// scripts/map-catalog-to-astro.js
|
|
191
|
+
import path3 from "node:path";
|
|
192
|
+
var COLLECTION_KEYS = [
|
|
193
|
+
"events",
|
|
194
|
+
"commands",
|
|
195
|
+
"services",
|
|
196
|
+
"users",
|
|
197
|
+
"teams",
|
|
198
|
+
"domains",
|
|
199
|
+
"flows",
|
|
200
|
+
"pages",
|
|
201
|
+
"changelogs",
|
|
202
|
+
"queries",
|
|
203
|
+
"channels"
|
|
204
|
+
];
|
|
205
|
+
function mapCatalogToAstro({ filePath, astroDir, projectDir }) {
|
|
206
|
+
const relativeFilePath = removeBasePath(filePath, projectDir);
|
|
207
|
+
if (!isCatalogRelated(relativeFilePath)) {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
const baseTargetPaths = getBaseTargetPaths(relativeFilePath);
|
|
211
|
+
const relativeTargetPath = getRelativeTargetPath(relativeFilePath);
|
|
212
|
+
return baseTargetPaths.map(
|
|
213
|
+
(base) => path3.join(astroDir, base, relativeTargetPath.replace("index.md", "index.mdx").replace("changelog.md", "changelog.mdx"))
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
function removeBasePath(fullPath, basePath) {
|
|
217
|
+
const relativePath = path3.relative(basePath, fullPath);
|
|
218
|
+
return relativePath.startsWith("..") ? fullPath : relativePath;
|
|
219
|
+
}
|
|
220
|
+
function isCollectionKey(key) {
|
|
221
|
+
return COLLECTION_KEYS.includes(key);
|
|
222
|
+
}
|
|
223
|
+
function isCatalogRelated(filePath) {
|
|
224
|
+
const filePathArr = filePath.split(path3.sep).filter(Boolean);
|
|
225
|
+
if ([
|
|
226
|
+
"eventcatalog.config.js",
|
|
227
|
+
// config file at root
|
|
228
|
+
"eventcatalog.styles.css",
|
|
229
|
+
// custom styles file at root
|
|
230
|
+
"components",
|
|
231
|
+
// custom components
|
|
232
|
+
"public",
|
|
233
|
+
// public assets
|
|
234
|
+
...COLLECTION_KEYS
|
|
235
|
+
].includes(filePathArr[0])) {
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
function getBaseTargetPaths(filePath) {
|
|
241
|
+
const filePathArr = filePath.split(path3.sep).filter(Boolean);
|
|
242
|
+
if (isCollectionKey(filePathArr[0])) {
|
|
243
|
+
if (filePathArr[filePathArr.length - 1] == "changelog.md") {
|
|
244
|
+
return [path3.join("src", "content", "changelogs")];
|
|
245
|
+
}
|
|
246
|
+
if (filePathArr[filePathArr.length - 1].match(/\.md$/)) {
|
|
247
|
+
return [path3.join("src", "content")];
|
|
248
|
+
}
|
|
249
|
+
const hasExtension = (str) => /\.[a-zA-Z0-9]{2,}$/.test(str);
|
|
250
|
+
if (hasExtension(filePath)) {
|
|
251
|
+
return [path3.join("public", "generated"), path3.join("src", "catalog-files")];
|
|
252
|
+
}
|
|
253
|
+
return [path3.join("public", "generated"), path3.join("src", "catalog-files"), path3.join("src", "content")];
|
|
254
|
+
}
|
|
255
|
+
if (filePathArr[0] == "components") {
|
|
256
|
+
return [path3.join("src", "custom-defined-components")];
|
|
257
|
+
}
|
|
258
|
+
if (filePathArr[0] == "public") {
|
|
259
|
+
return [path3.join("public")];
|
|
260
|
+
}
|
|
261
|
+
return [path3.join("/")];
|
|
262
|
+
}
|
|
263
|
+
function getRelativeTargetPath(filePath) {
|
|
264
|
+
const filePathArr = filePath.split(path3.sep).filter(Boolean);
|
|
265
|
+
if (filePathArr[0] == "public" || filePathArr[0] == "components") {
|
|
266
|
+
filePathArr.shift();
|
|
267
|
+
}
|
|
268
|
+
const relativePath = [];
|
|
269
|
+
for (let i = filePathArr.length - 1; i >= 0; i--) {
|
|
270
|
+
relativePath.unshift(filePathArr[i]);
|
|
271
|
+
if (isCollectionKey(filePathArr[i])) break;
|
|
272
|
+
}
|
|
273
|
+
return path3.join(...relativePath);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// scripts/watcher.js
|
|
277
|
+
import { rimrafSync } from "rimraf";
|
|
278
|
+
async function watch(projectDirectory, catalogDirectory, callback = void 0) {
|
|
279
|
+
const subscription = await watcher.subscribe(
|
|
280
|
+
projectDirectory,
|
|
281
|
+
compose(
|
|
282
|
+
/**
|
|
283
|
+
* @param {Error|null} err
|
|
284
|
+
* @param {Event[]} events
|
|
285
|
+
* @returns {unknown}
|
|
286
|
+
*/
|
|
287
|
+
(err, events) => {
|
|
288
|
+
if (err) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
for (let event of events) {
|
|
292
|
+
const { path: filePath, type } = event;
|
|
293
|
+
const astroPaths = mapCatalogToAstro({
|
|
294
|
+
filePath,
|
|
295
|
+
astroDir: catalogDirectory,
|
|
296
|
+
projectDir: projectDirectory
|
|
297
|
+
});
|
|
298
|
+
for (const astroPath of astroPaths) {
|
|
299
|
+
switch (type) {
|
|
300
|
+
case "create":
|
|
301
|
+
case "update":
|
|
302
|
+
try {
|
|
303
|
+
if (astroPath.endsWith(".mdx")) {
|
|
304
|
+
const content = fs.readFileSync(astroPath, "utf-8");
|
|
305
|
+
const frontmatter = addPropertyToFrontMatter(content, "pathToFile", filePath);
|
|
306
|
+
fs.writeFileSync(astroPath, frontmatter);
|
|
307
|
+
}
|
|
308
|
+
} catch (error) {
|
|
309
|
+
}
|
|
310
|
+
if (fs.statSync(filePath).isDirectory()) fs.mkdirSync(astroPath, { recursive: true });
|
|
311
|
+
else retryEPERM(fs.cpSync)(filePath, astroPath);
|
|
312
|
+
break;
|
|
313
|
+
case "delete":
|
|
314
|
+
retryEPERM(rimrafSync)(astroPath);
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
callback
|
|
321
|
+
),
|
|
322
|
+
{
|
|
323
|
+
ignore: [`**/${catalogDirectory}/!(${projectDirectory})**`]
|
|
324
|
+
}
|
|
325
|
+
);
|
|
326
|
+
return () => subscription.unsubscribe();
|
|
327
|
+
}
|
|
328
|
+
function compose(...fns) {
|
|
329
|
+
return function(err, events) {
|
|
330
|
+
fns.filter(Boolean).forEach((fn, i) => {
|
|
331
|
+
try {
|
|
332
|
+
fn(err, events);
|
|
333
|
+
} catch (error) {
|
|
334
|
+
console.error({ error });
|
|
335
|
+
throw error;
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
var MAX_RETRIES = 5;
|
|
341
|
+
var DELAY_MS = 100;
|
|
342
|
+
function retryEPERM(fn) {
|
|
343
|
+
return (...args) => {
|
|
344
|
+
let retries = 0;
|
|
345
|
+
while (retries < MAX_RETRIES) {
|
|
346
|
+
try {
|
|
347
|
+
return fn(...args);
|
|
348
|
+
} catch (err) {
|
|
349
|
+
if (err.code !== "EPERM") throw err;
|
|
350
|
+
setTimeout(() => {
|
|
351
|
+
}, DELAY_MS);
|
|
352
|
+
retries += 1;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// scripts/catalog-to-astro-content-directory.js
|
|
359
|
+
import { glob } from "glob";
|
|
360
|
+
import * as path4 from "node:path";
|
|
361
|
+
import fs2 from "fs";
|
|
362
|
+
import { fileURLToPath } from "url";
|
|
363
|
+
import os2 from "node:os";
|
|
364
|
+
var __filename2 = fileURLToPath(import.meta.url);
|
|
365
|
+
var rootPkg = path4.resolve(
|
|
366
|
+
path4.dirname(__filename2),
|
|
367
|
+
/**
|
|
368
|
+
* TODO: fix me =0
|
|
369
|
+
*
|
|
370
|
+
* The following is a workaround until organize the structure to have the correct path
|
|
371
|
+
* for any value of NODE_ENV
|
|
372
|
+
*
|
|
373
|
+
* @author carlosallexandre
|
|
374
|
+
*/
|
|
375
|
+
process.env.NODE_ENV === "test" ? "../" : "../../"
|
|
376
|
+
);
|
|
377
|
+
var copyFiles = async (source, target) => {
|
|
378
|
+
const files = await glob(path4.join(source, "**"), {
|
|
379
|
+
nodir: true,
|
|
380
|
+
windowsPathsNoEscape: os2.platform() == "win32"
|
|
381
|
+
});
|
|
382
|
+
for (const file of files) {
|
|
383
|
+
mapCatalogToAstro({
|
|
384
|
+
filePath: file,
|
|
385
|
+
astroDir: target,
|
|
386
|
+
projectDir: source
|
|
387
|
+
}).map((astroPath) => {
|
|
388
|
+
fs2.cpSync(file, astroPath);
|
|
389
|
+
return { oldPath: file, newPath: astroPath };
|
|
390
|
+
}).map(({ oldPath, newPath }) => {
|
|
391
|
+
if (!oldPath.endsWith(".md") && !oldPath.endsWith(".mdx")) return;
|
|
392
|
+
try {
|
|
393
|
+
const content = fs2.readFileSync(newPath, "utf-8");
|
|
394
|
+
const frontmatter = addPropertyToFrontMatter(content, "pathToFile", oldPath);
|
|
395
|
+
fs2.writeFileSync(newPath, frontmatter);
|
|
396
|
+
} catch (error) {
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
var ensureAstroCollectionNotEmpty = async (astroDir) => {
|
|
402
|
+
const COLLECTIONS = [
|
|
403
|
+
"events",
|
|
404
|
+
"commands",
|
|
405
|
+
"services",
|
|
406
|
+
"users",
|
|
407
|
+
"teams",
|
|
408
|
+
"domains",
|
|
409
|
+
"flows",
|
|
410
|
+
"pages",
|
|
411
|
+
"changelogs",
|
|
412
|
+
"queries",
|
|
413
|
+
"channels"
|
|
414
|
+
];
|
|
415
|
+
const emptyCollections = [];
|
|
416
|
+
for (const collection of COLLECTIONS) {
|
|
417
|
+
const markdownFiles = await glob(path4.join(astroDir, "src/content/", collection, "**"), {
|
|
418
|
+
nodir: true,
|
|
419
|
+
windowsPathsNoEscape: os2.platform() == "win32"
|
|
420
|
+
});
|
|
421
|
+
if (markdownFiles.length === 0) emptyCollections.push(collection);
|
|
422
|
+
}
|
|
423
|
+
const defaultCollectionFilesDir = path4.join(rootPkg, "default-files-for-collections");
|
|
424
|
+
for (const collection of emptyCollections) {
|
|
425
|
+
const defaultFile = path4.join(defaultCollectionFilesDir, `${collection}.md`);
|
|
426
|
+
const targetDir = path4.join(astroDir, "src/content/", collection);
|
|
427
|
+
if (!fs2.existsSync(targetDir)) {
|
|
428
|
+
fs2.mkdirSync(targetDir, { recursive: true });
|
|
429
|
+
}
|
|
430
|
+
fs2.cpSync(defaultFile, path4.join(targetDir, `${collection}.md`));
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
var catalogToAstro = async (source, astroDir) => {
|
|
434
|
+
const astroContentDir = path4.join(astroDir, "src/content/");
|
|
435
|
+
const astroConfigFile = fs2.readFileSync(path4.join(astroContentDir, "config.ts"));
|
|
436
|
+
fs2.rmSync(astroContentDir, { recursive: true });
|
|
437
|
+
fs2.mkdirSync(astroContentDir);
|
|
438
|
+
fs2.writeFileSync(path4.join(astroContentDir, "config.ts"), astroConfigFile);
|
|
439
|
+
await verifyRequiredFieldsAreInCatalogConfigFile(source);
|
|
440
|
+
await copyFiles(source, astroDir);
|
|
441
|
+
await ensureAstroCollectionNotEmpty(astroDir);
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
// bin/eventcatalog.ts
|
|
445
|
+
var currentDir = path5.dirname(fileURLToPath2(import.meta.url));
|
|
446
|
+
var program = new Command().version(VERSION);
|
|
447
|
+
var dir = path5.resolve(process.env.PROJECT_DIR || process.cwd());
|
|
448
|
+
var core = path5.resolve(process.env.CATALOG_DIR || join2(dir, ".eventcatalog-core"));
|
|
449
|
+
var eventCatalogDir = path5.resolve(join2(currentDir, "../../"));
|
|
15
450
|
program.name("eventcatalog").description("Documentation tool for event-driven architectures");
|
|
16
451
|
var ensureDir = (dir2) => {
|
|
17
|
-
if (!
|
|
18
|
-
|
|
452
|
+
if (!fs3.existsSync(dir2)) {
|
|
453
|
+
fs3.mkdirSync(dir2);
|
|
19
454
|
}
|
|
20
455
|
};
|
|
21
456
|
var copyCore = () => {
|
|
22
457
|
ensureDir(core);
|
|
23
|
-
|
|
458
|
+
if (eventCatalogDir === core) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
fs3.cpSync(eventCatalogDir, core, {
|
|
24
462
|
recursive: true,
|
|
25
463
|
filter: (src) => {
|
|
26
464
|
return true;
|
|
@@ -28,9 +466,9 @@ var copyCore = () => {
|
|
|
28
466
|
});
|
|
29
467
|
};
|
|
30
468
|
var clearCore = () => {
|
|
31
|
-
if (
|
|
469
|
+
if (fs3.existsSync(core)) fs3.rmSync(core, { recursive: true });
|
|
32
470
|
};
|
|
33
|
-
program.command("dev").description("Run development server of EventCatalog").option("-d, --debug", "Output EventCatalog application information into your terminal").option("--force-recreate", "Recreate the eventcatalog-core directory", false).action((options) => {
|
|
471
|
+
program.command("dev").description("Run development server of EventCatalog").option("-d, --debug", "Output EventCatalog application information into your terminal").option("--force-recreate", "Recreate the eventcatalog-core directory", false).action(async (options) => {
|
|
34
472
|
console.log("Setting up EventCatalog....");
|
|
35
473
|
if (options.debug) {
|
|
36
474
|
console.log("Debug mode enabled");
|
|
@@ -40,15 +478,33 @@ program.command("dev").description("Run development server of EventCatalog").opt
|
|
|
40
478
|
if (options.forceRecreate) clearCore();
|
|
41
479
|
copyCore();
|
|
42
480
|
console.log("EventCatalog is starting at http://localhost:3000/docs");
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
481
|
+
await catalogToAstro(dir, core);
|
|
482
|
+
let watchUnsub;
|
|
483
|
+
try {
|
|
484
|
+
watchUnsub = await watch(dir, core);
|
|
485
|
+
const { result } = concurrently([
|
|
486
|
+
{
|
|
487
|
+
name: "astro",
|
|
488
|
+
command: "npm run dev",
|
|
489
|
+
cwd: core,
|
|
490
|
+
env: {
|
|
491
|
+
PROJECT_DIR: dir,
|
|
492
|
+
CATALOG_DIR: core
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
]);
|
|
496
|
+
await result;
|
|
497
|
+
} catch (err) {
|
|
498
|
+
console.error(err);
|
|
499
|
+
} finally {
|
|
500
|
+
await watchUnsub?.();
|
|
501
|
+
}
|
|
48
502
|
});
|
|
49
|
-
program.command("build").description("Run build of EventCatalog").action((options) => {
|
|
503
|
+
program.command("build").description("Run build of EventCatalog").action(async (options) => {
|
|
50
504
|
console.log("Building EventCatalog...");
|
|
51
505
|
copyCore();
|
|
506
|
+
await log_build_default(dir);
|
|
507
|
+
await catalogToAstro(dir, core);
|
|
52
508
|
execSync(`cross-env PROJECT_DIR='${dir}' CATALOG_DIR='${core}' npm run build`, {
|
|
53
509
|
cwd: core,
|
|
54
510
|
stdio: "inherit"
|
|
@@ -69,11 +525,7 @@ program.command("start").description("Serves the contents of your eventcatalog b
|
|
|
69
525
|
console.log("Starting preview of your build...");
|
|
70
526
|
previewCatalog();
|
|
71
527
|
});
|
|
72
|
-
program.command("generate [siteDir]").description("Start the generator scripts.").action(() => {
|
|
73
|
-
|
|
74
|
-
execSync(`cross-env PROJECT_DIR='${dir}' npm run generate`, {
|
|
75
|
-
cwd: core,
|
|
76
|
-
stdio: "inherit"
|
|
77
|
-
});
|
|
528
|
+
program.command("generate [siteDir]").description("Start the generator scripts.").action(async () => {
|
|
529
|
+
await generate(dir);
|
|
78
530
|
});
|
|
79
|
-
program.
|
|
531
|
+
program.parseAsync();
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"url": "https://github.com/event-catalog/eventcatalog.git"
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
|
-
"version": "2.
|
|
9
|
+
"version": "2.14.1",
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
@@ -14,23 +14,21 @@
|
|
|
14
14
|
"eventcatalog": "bin/dist/eventcatalog.cjs"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
-
"dev": "
|
|
18
|
-
"dev:local": "concurrently \"node scripts/watcher.js\" \"astro dev\"",
|
|
17
|
+
"dev": "astro dev",
|
|
19
18
|
"build:bin": "tsup",
|
|
20
19
|
"prepublishOnly": "npm run build:bin",
|
|
21
20
|
"test": "vitest --config vitest.config.ts",
|
|
22
21
|
"test:ci": "node scripts/ci/test.js",
|
|
23
22
|
"test:e2e": "playwright test",
|
|
24
23
|
"start": "astro dev",
|
|
25
|
-
"build": "
|
|
24
|
+
"build": "astro build",
|
|
26
25
|
"build:cd": "node scripts/build-ci.js",
|
|
27
26
|
"preview": "astro preview",
|
|
28
27
|
"astro": "astro",
|
|
29
|
-
"scripts:hydrate-content": "node scripts/catalog-to-astro-content-directory.js",
|
|
30
28
|
"start:catalog": "node scripts/start-catalog-locally.js",
|
|
31
29
|
"verify-build:catalog": "rimraf dist && npm run build:cd",
|
|
32
30
|
"changeset": "changeset",
|
|
33
|
-
"generate": "
|
|
31
|
+
"generate": "npm run build:bin && npx . generate",
|
|
34
32
|
"release": "changeset publish",
|
|
35
33
|
"format": "prettier --config .prettierrc --write \"**/*.{js,jsx,ts,tsx,json,astro}\"",
|
|
36
34
|
"format:diff": "prettier --config .prettierrc --list-different \"**/*.{js,jsx,ts,tsx,json,astro}\""
|
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import os from 'os';
|
|
3
|
-
import
|
|
4
|
-
import path from 'path';
|
|
5
|
-
|
|
6
|
-
async function getVersion() {
|
|
7
|
-
try {
|
|
8
|
-
const pkg = await fs.readFileSync(path.join(process.env.CATALOG_DIR, 'package.json'));
|
|
9
|
-
const parsed = JSON.parse(pkg);
|
|
10
|
-
return parsed.version;
|
|
11
|
-
} catch (error) {
|
|
12
|
-
console.log(error);
|
|
13
|
-
return 'unknown';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
3
|
+
import { VERSION } from '../constants';
|
|
16
4
|
|
|
17
5
|
async function raiseEvent(eventData) {
|
|
18
|
-
const version = await getVersion();
|
|
19
|
-
|
|
20
6
|
const url = 'https://queue.simpleanalyticscdn.com/events';
|
|
21
|
-
const userAgent = `@eventcatalog/eventcatalog@${
|
|
7
|
+
const userAgent = `@eventcatalog/eventcatalog@${VERSION} (${os.platform()}; ${os.arch()}; Node/${process.version})`;
|
|
22
8
|
const headers = {
|
|
23
9
|
'Content-Type': 'application/json',
|
|
24
10
|
};
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { getEventCatalogConfigFile, verifyRequiredFieldsAreInCatalogConfigFile } from '../eventcatalog-config-file-utils.js';
|
|
2
2
|
import { raiseEvent } from './analytics.js';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {string} projectDir
|
|
7
|
+
*/
|
|
8
|
+
const main = async (projectDir) => {
|
|
5
9
|
if (process.env.NODE_ENV === 'CI') return;
|
|
6
10
|
try {
|
|
7
|
-
await verifyRequiredFieldsAreInCatalogConfigFile(
|
|
8
|
-
const configFile = await getEventCatalogConfigFile(
|
|
11
|
+
await verifyRequiredFieldsAreInCatalogConfigFile(projectDir);
|
|
12
|
+
const configFile = await getEventCatalogConfigFile(projectDir);
|
|
9
13
|
const { cId, organizationName, generators = [] } = configFile;
|
|
10
14
|
const generatorNames = generators.length > 0 ? generators.map((generator) => generator[0]) : ['none'];
|
|
11
15
|
await raiseEvent({
|
|
@@ -19,4 +23,4 @@ const main = async () => {
|
|
|
19
23
|
}
|
|
20
24
|
};
|
|
21
25
|
|
|
22
|
-
main
|
|
26
|
+
export default main;
|
package/scripts/build-ci.js
CHANGED
|
@@ -11,10 +11,17 @@ const catalog = args[0] || 'default';
|
|
|
11
11
|
const catalogDir = join(__dirname, '../');
|
|
12
12
|
const projectDIR = join(__dirname, `../examples/${catalog}`);
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
// Build cli
|
|
15
|
+
execSync('npm run build:bin', { stdio: 'inherit' });
|
|
16
|
+
|
|
17
|
+
// Build catalog
|
|
18
|
+
execSync(`cross-env NODE_ENV=CI PROJECT_DIR=${projectDIR} CATALOG_DIR=${catalogDir} npx . build`, {
|
|
19
|
+
cwd: catalogDir,
|
|
20
|
+
stdio: 'inherit',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Type check
|
|
24
|
+
execSync('npx astro check --minimumSeverity error', {
|
|
25
|
+
cwd: catalogDir,
|
|
26
|
+
stdio: 'inherit',
|
|
27
|
+
});
|