@redocly/portal-plugin-async-api 1.0.116 → 1.0.118
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 +15 -0
- package/lib/.tsbuildinfo +1 -1
- package/lib/plugin.js +30 -16
- package/lib/plugin.js.map +1 -1
- package/package.json +3 -2
- package/src/plugin.ts +34 -19
package/lib/plugin.js
CHANGED
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
import { getAllowedTeamsForRoute } from '@redocly/portal/dist/server/utils/rbac.js';
|
|
12
12
|
import { REDOCLY_TEAMS_RBAC } from '@redocly/portal/dist/shared/constants.js';
|
|
13
13
|
import { withPathPrefix } from '@redocly/portal/dist/shared/urls.js';
|
|
14
|
+
import bundle from '@asyncapi/bundler';
|
|
14
15
|
const ASYNCAPI_TEMPLATE_ID = 'asyncapi-docs';
|
|
15
16
|
const ASYNCAPI_SHARED_DATA_PREFIX = 'asyncapi-docs-';
|
|
16
17
|
export default function asyncAPIDocsPlugin() {
|
|
@@ -22,27 +23,40 @@ export default function asyncAPIDocsPlugin() {
|
|
|
22
23
|
const config = actions.getConfig();
|
|
23
24
|
const globalSettings = ((_a = config.theme) === null || _a === void 0 ? void 0 : _a.asyncapi) || {};
|
|
24
25
|
const definitions = loadDefinitions();
|
|
26
|
+
const currentScriptLocation = process.cwd();
|
|
25
27
|
for (const [relativePath, parsedDefinition] of definitions) {
|
|
26
28
|
const pageSlug = contentProvider.slugFromRelativePath(relativePath);
|
|
27
29
|
const sharedDataKey = `${ASYNCAPI_SHARED_DATA_PREFIX}${relativePath}`;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const isLocatedInRoot = relativePath.lastIndexOf('/') === -1;
|
|
31
|
+
try {
|
|
32
|
+
const fileLocation = relativePath.substring(0, isLocatedInRoot ? undefined : relativePath.lastIndexOf('/'));
|
|
33
|
+
// todo: workaround for $ref resolving until following issue is resolved: https://github.com/asyncapi/bundler/issues/136
|
|
34
|
+
process.chdir(fileLocation);
|
|
35
|
+
const bundledContent = yield bundle([parsedDefinition]);
|
|
36
|
+
yield actions.createSharedData(sharedDataKey, bundledContent.string());
|
|
37
|
+
const route = {
|
|
36
38
|
slug: pageSlug,
|
|
37
39
|
fsPath: relativePath,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
templateId: asyncAPITemplateId,
|
|
41
|
+
getStaticData: buildGetStaticDataFn(globalSettings, pageSlug),
|
|
42
|
+
versions: contentProvider.versions.getPageVersions(relativePath, pageSlug),
|
|
43
|
+
[REDOCLY_TEAMS_RBAC]: getAllowedTeamsForRoute(config.rbac, {
|
|
44
|
+
slug: pageSlug,
|
|
45
|
+
fsPath: relativePath,
|
|
46
|
+
}),
|
|
47
|
+
metadata: {
|
|
48
|
+
type: 'asyncapi',
|
|
49
|
+
title: 'AsyncAPI',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
actions.addRoute(route);
|
|
53
|
+
actions.addRouteSharedData(route.slug, 'AsyncApiDefinition', sharedDataKey);
|
|
54
|
+
process.chdir(currentScriptLocation);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
process.chdir(currentScriptLocation);
|
|
58
|
+
console.error(e);
|
|
59
|
+
}
|
|
46
60
|
}
|
|
47
61
|
function loadDefinitions() {
|
|
48
62
|
var _a;
|
package/lib/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,uDAAuD;;;;;;;;;;AAEvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AACpF,OAAO,EAAE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AAI,GAAG,EAAE,CAAC;oBACpD,KAAK,MAAM,YAAY,IAAI,eAAe,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE;wBAC7D,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE;4BAC5C,SAAS;yBACV;wBAED,IAAI;4BACF,MAAM,aAAa,GAAG,eAAe,CAAC,WAAW,CAAM,YAAY,EAAE,MAAM,CAAC,CAAC;4BAC7E,IAAI,aAAa,CAAC,SAAS,EAAE;gCAC3B,SAAS;6BACV;4BAED,IAAI,CAAC,CAAA,MAAA,aAAa,CAAC,MAAM,0CAAE,QAAQ,CAAA,EAAE;gCACnC,SAAS;6BACV;4BACD,WAAW,CAAC,GAAG,CAAC,YAAY,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;yBACtD;wBAAC,OAAO,KAAK,EAAE;4BACd,SAAS;yBACV;qBACF;oBAED,OAAO,WAAW,CAAC;gBACrB,CAAC;YACH,CAAC,CAAA;SACF,CAAC;QAEF,SAAS,oBAAoB,CAC3B,QAA8B,EAC9B,QAAgB;YAEhB,OAAO,UAAgB,MAAM,EAAE,KAAK,EAAE,QAAQ;;oBAC5C,OAAO;wBACL,KAAK,EAAE;4BACL,QAAQ,kCACH,QAAQ,KACX,WAAW,EAAE,cAAc,CAAC,QAAQ,CAAC,GACtC;yBACF;qBACF,CAAC;gBACJ,CAAC;aAAA,CAAC;QACJ,CAAC;IACH,CAAC;CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/portal-plugin-async-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.118",
|
|
4
4
|
"description": "Async API plugin for @redocly/portal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -26,13 +26,14 @@
|
|
|
26
26
|
"typescript": "^5.2.2"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
+
"@asyncapi/bundler": "^0.3.11",
|
|
29
30
|
"@asyncapi/react-component": "^0.24.23",
|
|
30
31
|
"json-schema-to-ts": "^2.9.1",
|
|
31
32
|
"styled-components": "^5.3.7"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
|
34
35
|
"react": "^17.0.2",
|
|
35
|
-
"@redocly/portal": "0.64.
|
|
36
|
+
"@redocly/portal": "0.64.5"
|
|
36
37
|
},
|
|
37
38
|
"overrides": {
|
|
38
39
|
"react": "^17.0.2"
|
package/src/plugin.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { getAllowedTeamsForRoute } from '@redocly/portal/dist/server/utils/rbac.js';
|
|
4
4
|
import { REDOCLY_TEAMS_RBAC } from '@redocly/portal/dist/shared/constants.js';
|
|
5
5
|
import { withPathPrefix } from '@redocly/portal/dist/shared/urls.js';
|
|
6
|
+
import bundle from '@asyncapi/bundler';
|
|
6
7
|
|
|
7
8
|
import type { PageStaticData } from '@redocly/portal/dist/shared/types';
|
|
8
9
|
import type { AsyncApiDocsSettings } from './config';
|
|
@@ -27,31 +28,46 @@ export default async function asyncAPIDocsPlugin(): Promise<PluginInstance> {
|
|
|
27
28
|
const globalSettings = config.theme?.asyncapi || {};
|
|
28
29
|
|
|
29
30
|
const definitions = loadDefinitions();
|
|
31
|
+
const currentScriptLocation = process.cwd();
|
|
30
32
|
|
|
31
33
|
for (const [relativePath, parsedDefinition] of definitions) {
|
|
32
34
|
const pageSlug = contentProvider.slugFromRelativePath(relativePath);
|
|
33
35
|
|
|
34
36
|
const sharedDataKey = `${ASYNCAPI_SHARED_DATA_PREFIX}${relativePath}`;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
const isLocatedInRoot = relativePath.lastIndexOf('/') === -1;
|
|
38
|
+
try {
|
|
39
|
+
const fileLocation = relativePath.substring(
|
|
40
|
+
0,
|
|
41
|
+
isLocatedInRoot ? undefined : relativePath.lastIndexOf('/'),
|
|
42
|
+
);
|
|
43
|
+
// todo: workaround for $ref resolving until following issue is resolved: https://github.com/asyncapi/bundler/issues/136
|
|
44
|
+
process.chdir(fileLocation);
|
|
45
|
+
const bundledContent = await bundle([parsedDefinition as string]);
|
|
46
|
+
await actions.createSharedData(sharedDataKey, bundledContent.string());
|
|
47
|
+
|
|
48
|
+
const route = {
|
|
44
49
|
slug: pageSlug,
|
|
45
50
|
fsPath: relativePath,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
templateId: asyncAPITemplateId,
|
|
52
|
+
getStaticData: buildGetStaticDataFn(globalSettings, pageSlug),
|
|
53
|
+
versions: contentProvider.versions.getPageVersions(relativePath, pageSlug),
|
|
54
|
+
[REDOCLY_TEAMS_RBAC]: getAllowedTeamsForRoute(config.rbac, {
|
|
55
|
+
slug: pageSlug,
|
|
56
|
+
fsPath: relativePath,
|
|
57
|
+
}),
|
|
58
|
+
metadata: {
|
|
59
|
+
type: 'asyncapi',
|
|
60
|
+
title: 'AsyncAPI',
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
actions.addRoute(route);
|
|
65
|
+
actions.addRouteSharedData(route.slug, 'AsyncApiDefinition', sharedDataKey);
|
|
66
|
+
process.chdir(currentScriptLocation);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
process.chdir(currentScriptLocation);
|
|
69
|
+
console.error(e);
|
|
70
|
+
}
|
|
55
71
|
}
|
|
56
72
|
|
|
57
73
|
function loadDefinitions() {
|
|
@@ -70,7 +86,6 @@ export default async function asyncAPIDocsPlugin(): Promise<PluginInstance> {
|
|
|
70
86
|
if (!contentRecord.parsed?.asyncapi) {
|
|
71
87
|
continue;
|
|
72
88
|
}
|
|
73
|
-
|
|
74
89
|
definitions.set(relativePath, contentRecord.content);
|
|
75
90
|
} catch (error) {
|
|
76
91
|
continue;
|