@mintlify/scraping 4.0.174 → 4.0.176

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintlify/scraping",
3
- "version": "4.0.174",
3
+ "version": "4.0.176",
4
4
  "description": "Scrape documentation frameworks to Mintlify docs",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -38,7 +38,7 @@
38
38
  "format:check": "prettier . --check"
39
39
  },
40
40
  "dependencies": {
41
- "@mintlify/common": "1.0.322",
41
+ "@mintlify/common": "1.0.324",
42
42
  "@mintlify/openapi-parser": "^0.0.7",
43
43
  "fs-extra": "^11.1.1",
44
44
  "hast-util-to-mdast": "^10.1.0",
@@ -78,5 +78,5 @@
78
78
  "typescript": "^5.5.3",
79
79
  "vitest": "^2.0.4"
80
80
  },
81
- "gitHead": "f5c36ee6b12784c48d015dce256024d129a74e24"
81
+ "gitHead": "7c94b810d40ff3c70fbfbf1b280e1c85094da486"
82
82
  }
@@ -57,5 +57,5 @@ export const generateUniqueFilenameWithoutExtension = (
57
57
  filename = `${base}-${extension}`;
58
58
  }
59
59
  }
60
- return filename;
60
+ return filename.toLowerCase();
61
61
  };
@@ -0,0 +1,88 @@
1
+ import {
2
+ AsyncAPIDocumentInterface,
3
+ AsyncAPIChannel,
4
+ validateAsyncApi,
5
+ } from '@mintlify/common/asyncapi';
6
+ import { DecoratedNavigationPage } from '@mintlify/models';
7
+ import { DecoratedGroupsConfig, GroupsConfig } from '@mintlify/validation';
8
+
9
+ import { findNavGroup } from '../apiPages/common.js';
10
+ import { getAsyncApiDefinition } from './getAsyncApiDefinition.js';
11
+ import { processAsyncApiChannel } from './processAsyncApiChannel.js';
12
+
13
+ type GenerateAsyncApiPagesOptions = {
14
+ asyncApiFilePath?: string;
15
+ version?: string;
16
+ writeFiles?: boolean;
17
+ outDir?: string;
18
+ outDirBasePath?: string;
19
+ overwrite?: boolean;
20
+ };
21
+
22
+ type AsyncApiPageGenerationResult = {
23
+ nav: GroupsConfig;
24
+ decoratedNav: DecoratedGroupsConfig;
25
+ spec: AsyncAPIDocumentInterface;
26
+ pagesAcc: Record<string, DecoratedNavigationPage>;
27
+ isUrl: boolean;
28
+ };
29
+
30
+ export async function generateAsyncApiPagesForDocsConfig(
31
+ spec: AsyncAPIDocumentInterface | string | URL,
32
+ opts?: GenerateAsyncApiPagesOptions
33
+ ): Promise<AsyncApiPageGenerationResult> {
34
+ let document: AsyncAPIDocumentInterface | undefined = undefined;
35
+ let isUrl: boolean;
36
+ if (typeof spec === 'string' || spec instanceof URL) {
37
+ const { document: asyncApiDocument, isUrl: isUrlFromDefinition } =
38
+ await getAsyncApiDefinition(spec);
39
+ if (asyncApiDocument) {
40
+ document = asyncApiDocument;
41
+ }
42
+ isUrl = isUrlFromDefinition;
43
+ } else {
44
+ const { valid, errorMessage, document: asyncApiDocument } = await validateAsyncApi(spec);
45
+ if (!valid && errorMessage) {
46
+ throw new Error(errorMessage);
47
+ }
48
+ document = asyncApiDocument;
49
+ isUrl = false;
50
+ }
51
+
52
+ if (!document) {
53
+ throw new Error('No document defined');
54
+ }
55
+
56
+ const channels = document.channels();
57
+
58
+ if (channels.isEmpty()) {
59
+ throw new Error('No channels defined');
60
+ }
61
+
62
+ const nav: GroupsConfig = [];
63
+ const decoratedNav: DecoratedGroupsConfig = [];
64
+ const writePromises: Promise<void>[] = [];
65
+ const pagesAcc: Record<string, DecoratedNavigationPage> = {};
66
+
67
+ channels.all().forEach((channel) => {
68
+ processAsyncApiChannel({
69
+ channel: channel as AsyncAPIChannel,
70
+ nav,
71
+ decoratedNav,
72
+ writePromises,
73
+ pagesAcc,
74
+ opts,
75
+ findNavGroup,
76
+ });
77
+ });
78
+
79
+ await Promise.all(writePromises);
80
+
81
+ return {
82
+ nav,
83
+ decoratedNav,
84
+ spec: document,
85
+ pagesAcc,
86
+ isUrl,
87
+ };
88
+ }
@@ -1,4 +1,4 @@
1
- import { optionallyAddLeadingSlash } from '@mintlify/common';
1
+ import { optionallyAddLeadingSlash, camelToSentenceCase } from '@mintlify/common';
2
2
  import { AsyncAPIChannel } from '@mintlify/common/asyncapi';
3
3
  import { DecoratedNavigationPage } from '@mintlify/models';
4
4
  import {
@@ -49,18 +49,20 @@ export const processAsyncApiChannel = ({
49
49
  findNavGroup,
50
50
  }: ProcessAsyncApiChannelArgs) => {
51
51
  const asyncApiFilePathFromRoot = opts?.asyncApiFilePath
52
- ? optionallyAddLeadingSlash(opts.asyncApiFilePath)
52
+ ? opts.asyncApiFilePath.startsWith('https://')
53
+ ? opts.asyncApiFilePath
54
+ : optionallyAddLeadingSlash(opts.asyncApiFilePath)
53
55
  : undefined;
54
56
 
55
- const operation = 'websocket';
56
57
  const tags = channel.tags().all();
57
58
  const groupName = tags[0]?.name() ?? DEFAULT_WEBSOCKETS_GROUP_NAME;
58
59
  const channelId = channel.id();
59
60
  const title = channel.title() ?? channelId;
61
+ const filename = prepareStringToBeValidFilename(title) ?? '';
60
62
  const description = channel.description() ?? channel.summary() ?? '';
61
63
 
62
64
  const folder = prepareStringToBeValidFilename(groupName) ?? '';
63
- const base = join(opts?.outDir ?? '', folder, title);
65
+ const base = join(opts?.outDir ?? '', folder, filename);
64
66
 
65
67
  const navGroup = findNavGroup(nav, groupName);
66
68
  const decoratedNavGroup = findNavGroup(decoratedNav, groupName);
@@ -69,14 +71,14 @@ export const processAsyncApiChannel = ({
69
71
 
70
72
  const asyncApiMetaTag = `${
71
73
  asyncApiFilePathFromRoot ? `${asyncApiFilePathFromRoot} ` : ''
72
- }${operation} ${channelId}`;
74
+ }${channelId}`;
73
75
 
74
76
  navGroup.push(filenameWithoutExtension);
75
77
 
76
78
  const page: DecoratedNavigationPage = {
77
79
  asyncapi: asyncApiMetaTag,
78
80
  href: resolve('/', filenameWithoutExtension),
79
- title: title,
81
+ title: title === channelId ? camelToSentenceCase(title) : title,
80
82
  description,
81
83
  version: opts?.version,
82
84
  };
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { generateOpenApiPages } from './openapi/generateOpenApiPages.js';
2
2
  export { generateOpenApiPagesForDocsConfig } from './openapi/generateOpenApiPagesForDocsConfig.js';
3
3
  export * from './utils/log.js';
4
+ export { generateAsyncApiPagesForDocsConfig } from './asyncapi/generateAsyncApiPagesForDocsConfig.js';