@eventcatalog/generator-asyncapi 0.0.2
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.md +661 -0
- package/README.md +132 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +292 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +261 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +46 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { Parser } from "@asyncapi/parser";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import utils from "@eventcatalog/sdk";
|
|
5
|
+
import slugify from "slugify";
|
|
6
|
+
|
|
7
|
+
// src/utils/schemas.ts
|
|
8
|
+
var getFileExtentionFromSchemaFormat = (format = "") => {
|
|
9
|
+
if (format.includes("avro")) return "avsc";
|
|
10
|
+
if (format.includes("yml")) return "yml";
|
|
11
|
+
if (format.includes("json")) return "json";
|
|
12
|
+
if (format.includes("openapi")) return "openapi";
|
|
13
|
+
if (format.includes("protobuf")) return "protobuf";
|
|
14
|
+
if (format.includes("yaml")) return "yaml";
|
|
15
|
+
return "json";
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/utils/messages.ts
|
|
19
|
+
var defaultMarkdown = (document, message) => {
|
|
20
|
+
return `
|
|
21
|
+
## Architecture
|
|
22
|
+
<NodeGraph />
|
|
23
|
+
|
|
24
|
+
${messageHasSchema(message) ? `
|
|
25
|
+
## Schema
|
|
26
|
+
<SchemaViewer file="${getSchemaFileName(message)}" title="Message Schema" maxHeight="500" />
|
|
27
|
+
` : ""}
|
|
28
|
+
|
|
29
|
+
${message.externalDocs() ? `
|
|
30
|
+
## External documentation
|
|
31
|
+
- [${message.externalDocs()?.description()}](${message.externalDocs()?.url()})
|
|
32
|
+
` : ""}
|
|
33
|
+
|
|
34
|
+
`;
|
|
35
|
+
};
|
|
36
|
+
var getSummary = (message) => {
|
|
37
|
+
const messageSummary = message.hasSummary() ? message.summary() : "";
|
|
38
|
+
const messageDescription = message.hasDescription() ? message.description() : "";
|
|
39
|
+
let eventCatalogMessageSummary = messageSummary;
|
|
40
|
+
if (!eventCatalogMessageSummary) {
|
|
41
|
+
eventCatalogMessageSummary = messageDescription && messageDescription.length < 150 ? messageDescription : "";
|
|
42
|
+
}
|
|
43
|
+
return eventCatalogMessageSummary;
|
|
44
|
+
};
|
|
45
|
+
var messageHasSchema = (message) => {
|
|
46
|
+
return message.hasPayload() && message.schemaFormat();
|
|
47
|
+
};
|
|
48
|
+
var getSchemaFileName = (message) => {
|
|
49
|
+
const extension = getFileExtentionFromSchemaFormat(message.schemaFormat());
|
|
50
|
+
return `schema.${extension}`;
|
|
51
|
+
};
|
|
52
|
+
var getMessageName = (message) => {
|
|
53
|
+
return message.hasTitle() && message.title() ? message.title() : message.id();
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/utils/services.ts
|
|
57
|
+
var defaultMarkdown2 = (document) => {
|
|
58
|
+
return `
|
|
59
|
+
|
|
60
|
+
${document.info().hasDescription() ? `${document.info().description()}` : ""}
|
|
61
|
+
|
|
62
|
+
## Architecture diagram
|
|
63
|
+
<NodeGraph />
|
|
64
|
+
|
|
65
|
+
${document.info().externalDocs() ? `
|
|
66
|
+
## External documentation
|
|
67
|
+
- [${document.info().externalDocs()?.description()}](${document.info().externalDocs()?.url()})
|
|
68
|
+
` : ""}
|
|
69
|
+
`;
|
|
70
|
+
};
|
|
71
|
+
var getSummary2 = (document) => {
|
|
72
|
+
const summary = document.info().hasDescription() ? document.info().description() : "";
|
|
73
|
+
return summary && summary.length < 150 ? summary : "";
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/utils/domains.ts
|
|
77
|
+
var defaultMarkdown3 = (document) => {
|
|
78
|
+
return `
|
|
79
|
+
|
|
80
|
+
## Architecture diagram
|
|
81
|
+
<NodeGraph />
|
|
82
|
+
|
|
83
|
+
`;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/index.ts
|
|
87
|
+
import chalk from "chalk";
|
|
88
|
+
var parser = new Parser();
|
|
89
|
+
var src_default = async (config, options) => {
|
|
90
|
+
if (!process.env.PROJECT_DIR) {
|
|
91
|
+
throw new Error("Please provide catalog url (env variable PROJECT_DIR)");
|
|
92
|
+
}
|
|
93
|
+
const {
|
|
94
|
+
writeService,
|
|
95
|
+
writeEvent,
|
|
96
|
+
writeCommand,
|
|
97
|
+
getService,
|
|
98
|
+
versionService,
|
|
99
|
+
rmService,
|
|
100
|
+
getDomain,
|
|
101
|
+
writeDomain,
|
|
102
|
+
addServiceToDomain,
|
|
103
|
+
getCommand,
|
|
104
|
+
getEvent,
|
|
105
|
+
rmEventById,
|
|
106
|
+
rmCommandById,
|
|
107
|
+
versionCommand,
|
|
108
|
+
versionEvent,
|
|
109
|
+
addSchemaToCommand,
|
|
110
|
+
addSchemaToEvent,
|
|
111
|
+
addFileToService,
|
|
112
|
+
versionDomain
|
|
113
|
+
} = utils(process.env.PROJECT_DIR);
|
|
114
|
+
const asyncAPIFiles = Array.isArray(options.path) ? options.path : [options.path];
|
|
115
|
+
console.log(chalk.green(`Processing ${asyncAPIFiles.length} AsyncAPI files...`));
|
|
116
|
+
for (const path of asyncAPIFiles) {
|
|
117
|
+
console.log(chalk.gray(`Processing ${path}`));
|
|
118
|
+
const asyncAPIFile = await readFile(path, "utf-8");
|
|
119
|
+
const { document } = await parser.parse(asyncAPIFile);
|
|
120
|
+
if (!document) {
|
|
121
|
+
console.log(chalk.red("Failed to parse AsyncAPI file"));
|
|
122
|
+
if (options.debug) {
|
|
123
|
+
const diagnostics = await parser.validate(asyncAPIFile);
|
|
124
|
+
console.log(diagnostics);
|
|
125
|
+
} else {
|
|
126
|
+
console.log(chalk.red("Run with debug option in the generator to see diagnostics"));
|
|
127
|
+
}
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const operations = document.allOperations();
|
|
131
|
+
const documentTags = document.info().tags().all() || [];
|
|
132
|
+
const serviceId = slugify(document.info().title(), { lower: true, strict: true });
|
|
133
|
+
const version = document.info().version();
|
|
134
|
+
const sends = [];
|
|
135
|
+
const receives = [];
|
|
136
|
+
let serviceMarkdown = defaultMarkdown2(document);
|
|
137
|
+
if (options.domain) {
|
|
138
|
+
const { id: domainId, name: domainName, version: domainVersion } = options.domain;
|
|
139
|
+
const domain = await getDomain(options.domain.id, domainVersion || "latest");
|
|
140
|
+
const currentDomain = await getDomain(options.domain.id, "latest");
|
|
141
|
+
console.log(chalk.blue(`
|
|
142
|
+
Processing domain: ${domainName} (v${domainVersion})`));
|
|
143
|
+
if (currentDomain && currentDomain.version !== domainVersion) {
|
|
144
|
+
await versionDomain(domainId);
|
|
145
|
+
console.log(chalk.cyan(` - Versioned previous domain (v${currentDomain.version})`));
|
|
146
|
+
}
|
|
147
|
+
if (!domain || domain && domain.version !== domainVersion) {
|
|
148
|
+
await writeDomain({
|
|
149
|
+
id: domainId,
|
|
150
|
+
name: domainName,
|
|
151
|
+
version: domainVersion,
|
|
152
|
+
markdown: defaultMarkdown3(document)
|
|
153
|
+
// services: [{ id: serviceId, version: version }],
|
|
154
|
+
});
|
|
155
|
+
console.log(chalk.cyan(` - Domain (v${domainVersion}) created`));
|
|
156
|
+
}
|
|
157
|
+
if (currentDomain && currentDomain.version === domainVersion) {
|
|
158
|
+
console.log(chalk.yellow(` - Domain (v${domainVersion}) already exists, skipped creation...`));
|
|
159
|
+
}
|
|
160
|
+
await addServiceToDomain(domainId, { id: serviceId, version }, domainVersion);
|
|
161
|
+
}
|
|
162
|
+
for (const operation of operations) {
|
|
163
|
+
for (const message of operation.messages()) {
|
|
164
|
+
const eventType = message.extensions().get("x-eventcatalog-message-type")?.value() || "event";
|
|
165
|
+
const messageId = message.id().toLowerCase();
|
|
166
|
+
let messageMarkdown = defaultMarkdown(document, message);
|
|
167
|
+
const writeMessage = eventType === "event" ? writeEvent : writeCommand;
|
|
168
|
+
const versionMessage = eventType === "event" ? versionEvent : versionCommand;
|
|
169
|
+
const getMessage = eventType === "event" ? getEvent : getCommand;
|
|
170
|
+
const rmMessageById = eventType === "event" ? rmEventById : rmCommandById;
|
|
171
|
+
const addSchemaToMessage = eventType === "event" ? addSchemaToEvent : addSchemaToCommand;
|
|
172
|
+
const badges = message.tags().all() || [];
|
|
173
|
+
const catalogedMessage = await getMessage(message.id().toLowerCase(), "latest");
|
|
174
|
+
console.log(chalk.blue(`Processing message: ${getMessageName(message)} (v${version})`));
|
|
175
|
+
if (catalogedMessage) {
|
|
176
|
+
messageMarkdown = catalogedMessage.markdown;
|
|
177
|
+
if (catalogedMessage.version === version) {
|
|
178
|
+
await rmMessageById(messageId, version);
|
|
179
|
+
} else {
|
|
180
|
+
await versionMessage(messageId);
|
|
181
|
+
console.log(chalk.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
await writeMessage(
|
|
185
|
+
{
|
|
186
|
+
id: messageId,
|
|
187
|
+
version,
|
|
188
|
+
name: getMessageName(message),
|
|
189
|
+
summary: getSummary(message),
|
|
190
|
+
markdown: messageMarkdown,
|
|
191
|
+
badges: badges.map((badge) => ({ content: badge.name(), textColor: "blue", backgroundColor: "blue" })),
|
|
192
|
+
schemaPath: messageHasSchema(message) ? getSchemaFileName(message) : void 0
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
path: message.id()
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
console.log(chalk.cyan(` - Message (v${version}) created`));
|
|
199
|
+
if (messageHasSchema(message)) {
|
|
200
|
+
addSchemaToMessage(
|
|
201
|
+
messageId,
|
|
202
|
+
{
|
|
203
|
+
fileName: getSchemaFileName(message),
|
|
204
|
+
schema: JSON.stringify(message.payload()?.json(), null, 4)
|
|
205
|
+
},
|
|
206
|
+
version
|
|
207
|
+
);
|
|
208
|
+
console.log(chalk.cyan(` - Schema added to message (v${version})`));
|
|
209
|
+
}
|
|
210
|
+
if (operation.action() === "send" || operation.action() === "publish") {
|
|
211
|
+
sends.push({ id: messageId, version });
|
|
212
|
+
}
|
|
213
|
+
if (operation.action() === "receive" || operation.action() === "subscribe") {
|
|
214
|
+
receives.push({ id: messageId, version });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const latestServiceInCatalog = await getService(serviceId, "latest");
|
|
219
|
+
console.log(chalk.blue(`Processing service: ${document.info().title()} (v${version})`));
|
|
220
|
+
if (latestServiceInCatalog) {
|
|
221
|
+
serviceMarkdown = latestServiceInCatalog.markdown;
|
|
222
|
+
if (latestServiceInCatalog.version !== version) {
|
|
223
|
+
await versionService(serviceId);
|
|
224
|
+
console.log(chalk.cyan(` - Versioned previous service (v${latestServiceInCatalog.version})`));
|
|
225
|
+
}
|
|
226
|
+
if (latestServiceInCatalog.version === version) {
|
|
227
|
+
serviceMarkdown = latestServiceInCatalog.markdown;
|
|
228
|
+
await rmService(document.info().title());
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
await writeService(
|
|
232
|
+
{
|
|
233
|
+
id: serviceId,
|
|
234
|
+
name: document.info().title(),
|
|
235
|
+
version,
|
|
236
|
+
summary: getSummary2(document),
|
|
237
|
+
badges: documentTags.map((tag) => ({ content: tag.name(), textColor: "blue", backgroundColor: "blue" })),
|
|
238
|
+
markdown: serviceMarkdown,
|
|
239
|
+
sends,
|
|
240
|
+
schemaPath: path.split("/").pop() || "asyncapi.yml",
|
|
241
|
+
receives
|
|
242
|
+
},
|
|
243
|
+
{ path: document.info().title() }
|
|
244
|
+
);
|
|
245
|
+
await addFileToService(
|
|
246
|
+
serviceId,
|
|
247
|
+
{
|
|
248
|
+
fileName: path.split("/").pop() || "asyncapi.yml",
|
|
249
|
+
content: asyncAPIFile
|
|
250
|
+
},
|
|
251
|
+
version
|
|
252
|
+
);
|
|
253
|
+
console.log(chalk.cyan(` - Service (v${version}) created`));
|
|
254
|
+
console.log(chalk.green(`
|
|
255
|
+
Finished generating event catalog for AsyncAPI ${document.info().title()} (v${version})`));
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
export {
|
|
259
|
+
src_default as default
|
|
260
|
+
};
|
|
261
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/utils/schemas.ts","../src/utils/messages.ts","../src/utils/services.ts","../src/utils/domains.ts"],"sourcesContent":["// import utils from '@eventcatalog/sdk';\nimport { Parser } from '@asyncapi/parser';\nconst parser = new Parser();\nimport { readFile } from 'node:fs/promises';\nimport utils from '@eventcatalog/sdk';\nimport slugify from 'slugify';\nimport {\n defaultMarkdown as generateMarkdownForMessage,\n getMessageName,\n getSummary as getMessageSummary,\n getSchemaFileName,\n messageHasSchema,\n} from './utils/messages';\nimport { defaultMarkdown as generateMarkdownForService, getSummary as getServiceSummary } from './utils/services';\nimport { defaultMarkdown as generateMarkdownForDomain } from './utils/domains';\nimport chalk from 'chalk';\n\nlet metrics = { eventsCreated: 0, commandsCreated: 0, servicesCreated: 0, domainsCreated: 0 };\n\ntype Domain = {\n id: string;\n name: string;\n version: string;\n};\n\ntype Props = {\n path: string | string[];\n domain?: Domain;\n debug?: boolean;\n};\n\nexport default async (config: any, options: Props) => {\n if (!process.env.PROJECT_DIR) {\n throw new Error('Please provide catalog url (env variable PROJECT_DIR)');\n }\n\n const {\n writeService,\n writeEvent,\n writeCommand,\n getService,\n versionService,\n rmService,\n getDomain,\n writeDomain,\n addServiceToDomain,\n getCommand,\n getEvent,\n rmEventById,\n rmCommandById,\n versionCommand,\n versionEvent,\n addSchemaToCommand,\n addSchemaToEvent,\n addFileToService,\n versionDomain,\n } = utils(process.env.PROJECT_DIR);\n\n const asyncAPIFiles = Array.isArray(options.path) ? options.path : [options.path];\n\n console.log(chalk.green(`Processing ${asyncAPIFiles.length} AsyncAPI files...`));\n\n for (const path of asyncAPIFiles) {\n console.log(chalk.gray(`Processing ${path}`));\n\n const asyncAPIFile = await readFile(path, 'utf-8');\n const { document } = await parser.parse(asyncAPIFile);\n\n if (!document) {\n console.log(chalk.red('Failed to parse AsyncAPI file'));\n if (options.debug) {\n const diagnostics = await parser.validate(asyncAPIFile);\n console.log(diagnostics);\n } else {\n console.log(chalk.red('Run with debug option in the generator to see diagnostics'));\n }\n continue;\n }\n\n const operations = document.allOperations();\n const documentTags = document.info().tags().all() || [];\n\n const serviceId = slugify(document.info().title(), { lower: true, strict: true });\n const version = document.info().version();\n\n // What messages does this service send and receive\n const sends = [];\n const receives = [];\n\n let serviceMarkdown = generateMarkdownForService(document);\n\n // Manage domain\n if (options.domain) {\n // Try and get the domain\n const { id: domainId, name: domainName, version: domainVersion } = options.domain;\n const domain = await getDomain(options.domain.id, domainVersion || 'latest');\n const currentDomain = await getDomain(options.domain.id, 'latest');\n\n console.log(chalk.blue(`\\nProcessing domain: ${domainName} (v${domainVersion})`));\n\n // Found a domain, but the versions do not match\n if (currentDomain && currentDomain.version !== domainVersion) {\n await versionDomain(domainId);\n console.log(chalk.cyan(` - Versioned previous domain (v${currentDomain.version})`));\n }\n\n // Do we need to create a new domain?\n if (!domain || (domain && domain.version !== domainVersion)) {\n await writeDomain({\n id: domainId,\n name: domainName,\n version: domainVersion,\n markdown: generateMarkdownForDomain(document),\n // services: [{ id: serviceId, version: version }],\n });\n console.log(chalk.cyan(` - Domain (v${domainVersion}) created`));\n }\n\n if (currentDomain && currentDomain.version === domainVersion) {\n console.log(chalk.yellow(` - Domain (v${domainVersion}) already exists, skipped creation...`));\n }\n\n // Add the service to the domain\n await addServiceToDomain(domainId, { id: serviceId, version: version }, domainVersion);\n }\n\n // Find events/commands\n for (const operation of operations) {\n for (const message of operation.messages()) {\n const eventType = message.extensions().get('x-eventcatalog-message-type')?.value() || 'event';\n\n const messageId = message.id().toLowerCase();\n\n let messageMarkdown = generateMarkdownForMessage(document, message);\n const writeMessage = eventType === 'event' ? writeEvent : writeCommand;\n const versionMessage = eventType === 'event' ? versionEvent : versionCommand;\n const getMessage = eventType === 'event' ? getEvent : getCommand;\n const rmMessageById = eventType === 'event' ? rmEventById : rmCommandById;\n const addSchemaToMessage = eventType === 'event' ? addSchemaToEvent : addSchemaToCommand;\n const badges = message.tags().all() || [];\n\n // Check if the message already exists in the catalog\n const catalogedMessage = await getMessage(message.id().toLowerCase(), 'latest');\n\n console.log(chalk.blue(`Processing message: ${getMessageName(message)} (v${version})`));\n\n if (catalogedMessage) {\n messageMarkdown = catalogedMessage.markdown;\n // if the version matches, we can override the message but keep markdown as it was\n if (catalogedMessage.version === version) {\n await rmMessageById(messageId, version);\n } else {\n // if the version does not match, we need to version the message\n await versionMessage(messageId);\n console.log(chalk.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));\n }\n }\n\n // Write the message to the catalog\n await writeMessage(\n {\n id: messageId,\n version: version,\n name: getMessageName(message),\n summary: getMessageSummary(message),\n markdown: messageMarkdown,\n badges: badges.map((badge) => ({ content: badge.name(), textColor: 'blue', backgroundColor: 'blue' })),\n schemaPath: messageHasSchema(message) ? getSchemaFileName(message) : undefined,\n },\n {\n path: message.id(),\n }\n );\n\n console.log(chalk.cyan(` - Message (v${version}) created`));\n\n // Check if the message has a payload, if it does then document in EventCatalog\n if (messageHasSchema(message)) {\n addSchemaToMessage(\n messageId,\n {\n fileName: getSchemaFileName(message),\n schema: JSON.stringify(message.payload()?.json(), null, 4),\n },\n version\n );\n console.log(chalk.cyan(` - Schema added to message (v${version})`));\n }\n\n // Add the message to the correct array\n if (operation.action() === 'send' || operation.action() === 'publish') {\n sends.push({ id: messageId, version: version });\n }\n if (operation.action() === 'receive' || operation.action() === 'subscribe') {\n receives.push({ id: messageId, version: version });\n }\n }\n }\n\n // Check if service is already defined... if the versions do not match then create service.\n const latestServiceInCatalog = await getService(serviceId, 'latest');\n\n console.log(chalk.blue(`Processing service: ${document.info().title()} (v${version})`));\n\n if (latestServiceInCatalog) {\n serviceMarkdown = latestServiceInCatalog.markdown;\n // Found a service, and versions do not match, we need to version the one already there\n if (latestServiceInCatalog.version !== version) {\n await versionService(serviceId);\n console.log(chalk.cyan(` - Versioned previous service (v${latestServiceInCatalog.version})`));\n }\n\n // Match found, override it\n if (latestServiceInCatalog.version === version) {\n serviceMarkdown = latestServiceInCatalog.markdown;\n await rmService(document.info().title());\n }\n }\n\n await writeService(\n {\n id: serviceId,\n name: document.info().title(),\n version: version,\n summary: getServiceSummary(document),\n badges: documentTags.map((tag) => ({ content: tag.name(), textColor: 'blue', backgroundColor: 'blue' })),\n markdown: serviceMarkdown,\n sends,\n schemaPath: path.split('/').pop() || 'asyncapi.yml',\n receives,\n },\n { path: document.info().title() }\n );\n\n await addFileToService(\n serviceId,\n {\n fileName: path.split('/').pop() || 'asyncapi.yml',\n content: asyncAPIFile,\n },\n version\n );\n\n console.log(chalk.cyan(` - Service (v${version}) created`));\n\n console.log(chalk.green(`\\nFinished generating event catalog for AsyncAPI ${document.info().title()} (v${version})`));\n }\n};\n","export const getFileExtentionFromSchemaFormat = (format: string | undefined = '') => {\n if (format.includes('avro')) return 'avsc';\n if (format.includes('yml')) return 'yml';\n if (format.includes('json')) return 'json';\n if (format.includes('openapi')) return 'openapi';\n if (format.includes('protobuf')) return 'protobuf';\n if (format.includes('yaml')) return 'yaml';\n\n return 'json';\n};\n","import { MessageInterface, AsyncAPIDocumentInterface } from '@asyncapi/parser';\nimport { getFileExtentionFromSchemaFormat } from './schemas';\n\nexport const defaultMarkdown = (document: AsyncAPIDocumentInterface, message: MessageInterface) => {\n return `\n## Architecture\n<NodeGraph />\n\n${\n messageHasSchema(message)\n ? `\n## Schema\n<SchemaViewer file=\"${getSchemaFileName(message)}\" title=\"Message Schema\" maxHeight=\"500\" />\n`\n : ''\n}\n\n${\n message.externalDocs()\n ? `\n## External documentation\n- [${message.externalDocs()?.description()}](${message.externalDocs()?.url()})\n`\n : ''\n}\n\n`;\n};\n\nexport const getSummary = (message: MessageInterface) => {\n const messageSummary = message.hasSummary() ? message.summary() : '';\n const messageDescription = message.hasDescription() ? message.description() : '';\n\n let eventCatalogMessageSummary = messageSummary;\n\n if (!eventCatalogMessageSummary) {\n eventCatalogMessageSummary = messageDescription && messageDescription.length < 150 ? messageDescription : '';\n }\n\n return eventCatalogMessageSummary;\n};\n\nexport const messageHasSchema = (message: MessageInterface) => {\n return message.hasPayload() && message.schemaFormat();\n};\n\nexport const getSchemaFileName = (message: MessageInterface) => {\n const extension = getFileExtentionFromSchemaFormat(message.schemaFormat());\n return `schema.${extension}`;\n};\n\nexport const getMessageName = (message: MessageInterface) => {\n return message.hasTitle() && message.title() ? (message.title() as string) : message.id();\n};\n","import { AsyncAPIDocumentInterface } from '@asyncapi/parser';\n\nexport const defaultMarkdown = (document: AsyncAPIDocumentInterface) => {\n return `\n\n${document.info().hasDescription() ? `${document.info().description()}` : ''} \n\n## Architecture diagram\n<NodeGraph />\n\n${\n document.info().externalDocs()\n ? `\n## External documentation\n- [${document.info().externalDocs()?.description()}](${document.info().externalDocs()?.url()})\n`\n : ''\n}\n`;\n};\n\nexport const getSummary = (document: AsyncAPIDocumentInterface) => {\n const summary = document.info().hasDescription() ? document.info().description() : '';\n return summary && summary.length < 150 ? summary : '';\n};\n","import { AsyncAPIDocumentInterface } from '@asyncapi/parser';\n\nexport const defaultMarkdown = (document: AsyncAPIDocumentInterface) => {\n return `\n\n## Architecture diagram\n<NodeGraph />\n\n`;\n};\n"],"mappings":";AACA,SAAS,cAAc;AAEvB,SAAS,gBAAgB;AACzB,OAAO,WAAW;AAClB,OAAO,aAAa;;;ACLb,IAAM,mCAAmC,CAAC,SAA6B,OAAO;AACnF,MAAI,OAAO,SAAS,MAAM,EAAG,QAAO;AACpC,MAAI,OAAO,SAAS,KAAK,EAAG,QAAO;AACnC,MAAI,OAAO,SAAS,MAAM,EAAG,QAAO;AACpC,MAAI,OAAO,SAAS,SAAS,EAAG,QAAO;AACvC,MAAI,OAAO,SAAS,UAAU,EAAG,QAAO;AACxC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AAS,KAAK,EAAE,MAAM;AAAA,QAC5B;AAAA,QACA,SAASC,YAAkB,QAAQ;AAAA,QACnC,QAAQ,aAAa,IAAI,CAAC,SAAS,EAAE,SAAS,IAAI,KAAK,GAAG,WAAW,QAAQ,iBAAiB,OAAO,EAAE;AAAA,QACvG,UAAU;AAAA,QACV;AAAA,QACA,YAAY,KAAK,MAAM,GAAG,EAAE,IAAI,KAAK;AAAA,QACrC;AAAA,MACF;AAAA,MACA,EAAE,MAAM,SAAS,KAAK,EAAE,MAAM,EAAE;AAAA,IAClC;AAEA,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,QACE,UAAU,KAAK,MAAM,GAAG,EAAE,IAAI,KAAK;AAAA,QACnC,SAAS;AAAA,MACX;AAAA,MACA;AAAA,IACF;AAEA,YAAQ,IAAI,MAAM,KAAK,gBAAgB,OAAO,WAAW,CAAC;AAE1D,YAAQ,IAAI,MAAM,MAAM;AAAA,iDAAoD,SAAS,KAAK,EAAE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC;AAAA,EACtH;AACF;","names":["defaultMarkdown","getSummary","defaultMarkdown","defaultMarkdown","getSummary"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eventcatalog/generator-asyncapi",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "AsyncAPI generator for EventCatalog",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsup",
|
|
7
|
+
"test": "vitest",
|
|
8
|
+
"format": "prettier --write .",
|
|
9
|
+
"format:diff": "prettier --list-different .",
|
|
10
|
+
"changeset": "changeset",
|
|
11
|
+
"release": "changeset publish"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"author": "",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/fs-extra": "^11.0.4",
|
|
21
|
+
"@types/lodash": "^4.17.7",
|
|
22
|
+
"@types/node": "^20.16.1",
|
|
23
|
+
"prettier": "^3.3.3",
|
|
24
|
+
"tsup": "^8.1.0",
|
|
25
|
+
"typescript": "^5.5.3",
|
|
26
|
+
"vitest": "^2.0.2"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"package.json"
|
|
31
|
+
],
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"module": "./dist/index.mjs",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@asyncapi/parser": "^3.2.2",
|
|
37
|
+
"@changesets/cli": "^2.27.7",
|
|
38
|
+
"@eventcatalog/sdk": "^0.0.12",
|
|
39
|
+
"chalk": "^4",
|
|
40
|
+
"fs-extra": "^11.2.0",
|
|
41
|
+
"glob": "^11.0.0",
|
|
42
|
+
"gray-matter": "^4.0.3",
|
|
43
|
+
"lodash": "^4.17.21",
|
|
44
|
+
"slugify": "^1.6.6"
|
|
45
|
+
}
|
|
46
|
+
}
|