@mintlify/cli 4.0.1812 → 4.1.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/dist/assets/export-scripts/README.classic.md +15 -0
- package/dist/assets/export-scripts/README.md +14 -0
- package/dist/assets/export-scripts/serve.js +114 -0
- package/dist/assets/export-scripts/start-docs.bat +10 -0
- package/dist/assets/export-scripts/start-docs.sh +9 -0
- package/dist/assets/og/Inter-Bold.ttf +0 -0
- package/dist/assets/og/Inter-Medium.ttf +0 -0
- package/dist/assets/og/Inter-Regular.ttf +0 -0
- package/dist/assets/og/Inter-SemiBold.ttf +0 -0
- package/dist/assets/og/PaperMono-Regular.ttf +0 -0
- package/dist/assets/og/index_bg.wasm +0 -0
- package/dist/assets/openChrome.applescript +94 -0
- package/dist/assets/socket.io/socket.io.esm.min.js +7 -0
- package/dist/assets/socket.io/socket.io.esm.min.js.map +1 -0
- package/dist/assets/socket.io/socket.io.js +4907 -0
- package/dist/assets/socket.io/socket.io.js.map +1 -0
- package/dist/assets/socket.io/socket.io.min.js +7 -0
- package/dist/assets/socket.io/socket.io.min.js.map +1 -0
- package/dist/assets/socket.io/socket.io.msgpack.min.js +7 -0
- package/dist/assets/socket.io/socket.io.msgpack.min.js.map +1 -0
- package/dist/assets/xdg-open +1066 -0
- package/dist/assets/yargs-locales/be.json +46 -0
- package/dist/assets/yargs-locales/cs.json +51 -0
- package/dist/assets/yargs-locales/de.json +46 -0
- package/dist/assets/yargs-locales/en.json +55 -0
- package/dist/assets/yargs-locales/es.json +46 -0
- package/dist/assets/yargs-locales/fi.json +49 -0
- package/dist/assets/yargs-locales/fr.json +53 -0
- package/dist/assets/yargs-locales/hi.json +49 -0
- package/dist/assets/yargs-locales/hu.json +46 -0
- package/dist/assets/yargs-locales/id.json +50 -0
- package/dist/assets/yargs-locales/it.json +46 -0
- package/dist/assets/yargs-locales/ja.json +51 -0
- package/dist/assets/yargs-locales/ko.json +49 -0
- package/dist/assets/yargs-locales/nb.json +44 -0
- package/dist/assets/yargs-locales/nl.json +49 -0
- package/dist/assets/yargs-locales/nn.json +44 -0
- package/dist/assets/yargs-locales/pirate.json +13 -0
- package/dist/assets/yargs-locales/pl.json +49 -0
- package/dist/assets/yargs-locales/pt.json +45 -0
- package/dist/assets/yargs-locales/pt_BR.json +48 -0
- package/dist/assets/yargs-locales/ru.json +51 -0
- package/dist/assets/yargs-locales/th.json +46 -0
- package/dist/assets/yargs-locales/tr.json +48 -0
- package/dist/assets/yargs-locales/uk_UA.json +51 -0
- package/dist/assets/yargs-locales/uz.json +52 -0
- package/dist/assets/yargs-locales/zh_CN.json +48 -0
- package/dist/assets/yargs-locales/zh_TW.json +51 -0
- package/dist/converter-d8O3xkdU.js +102 -0
- package/dist/devtools-CGNZQKFV.js +24 -0
- package/dist/index.js +8 -0
- package/dist/rolldown-runtime-CEAe2Uac.js +7 -0
- package/dist/schemas-CBsmCNpK.js +372 -0
- package/dist/start.js +2310 -0
- package/package.json +43 -36
- package/.oxlintrc.json +0 -5
- package/.prettierignore +0 -2
- package/.turbo/turbo-build.log +0 -1
- package/CONTRIBUTING.md +0 -45
- package/__test__/agent-auth.test.ts +0 -114
- package/__test__/agent-claim.test.ts +0 -164
- package/__test__/agent-credentials.test.ts +0 -149
- package/__test__/agent-deployment.test.ts +0 -106
- package/__test__/agent-setup-config.test.ts +0 -324
- package/__test__/agent-setup.test.ts +0 -207
- package/__test__/agent.test.ts +0 -64
- package/__test__/analytics/client.test.ts +0 -180
- package/__test__/analytics/dates.test.ts +0 -12
- package/__test__/analytics/filters.test.ts +0 -116
- package/__test__/analytics/format.test.ts +0 -137
- package/__test__/authenticatedFetch.test.ts +0 -182
- package/__test__/brokenLinks.test.ts +0 -283
- package/__test__/checkPort.test.ts +0 -92
- package/__test__/deploy-github-actions.test.ts +0 -202
- package/__test__/deploy-github-setup.test.ts +0 -240
- package/__test__/deploy-instructions.test.ts +0 -155
- package/__test__/deploy.test.ts +0 -202
- package/__test__/feedback.test.ts +0 -34
- package/__test__/foreignSyntax.test.ts +0 -73
- package/__test__/format.test.ts +0 -72
- package/__test__/helpers.test.ts +0 -52
- package/__test__/init.test.ts +0 -119
- package/__test__/instructions.test.ts +0 -53
- package/__test__/keyring.test.ts +0 -82
- package/__test__/mdxAccessibility.test.ts +0 -81
- package/__test__/migrate.test.ts +0 -186
- package/__test__/openApiCheck.test.ts +0 -185
- package/__test__/pathValidation.test.ts +0 -25
- package/__test__/resolveFiles.test.ts +0 -70
- package/__test__/sessionId.test.ts +0 -46
- package/__test__/signup.test.ts +0 -36
- package/__test__/update.test.ts +0 -117
- package/__test__/utils.ts +0 -25
- package/__test__/validateCommand.test.ts +0 -647
- package/__test__/validateEngine.test.ts +0 -245
- package/__test__/validateRules.test.ts +0 -1275
- package/__test__/welcome.test.ts +0 -15
- package/__test__/workflows/client.test.ts +0 -126
- package/bin/accessibility.js +0 -111
- package/bin/accessibilityCheck.js +0 -82
- package/bin/addDomain.js +0 -130
- package/bin/agent-auth.js +0 -104
- package/bin/agent-claim.js +0 -97
- package/bin/agent-credentials.js +0 -124
- package/bin/agent-deployment.js +0 -96
- package/bin/agent-http.js +0 -45
- package/bin/agent-setup-config.js +0 -141
- package/bin/agent-setup.js +0 -146
- package/bin/agent.js +0 -42
- package/bin/analytics/client.js +0 -60
- package/bin/analytics/dates.js +0 -6
- package/bin/analytics/filters.js +0 -27
- package/bin/analytics/format.js +0 -13
- package/bin/analytics/index.js +0 -496
- package/bin/analytics/output.js +0 -75
- package/bin/analytics/types.js +0 -1
- package/bin/authenticatedFetch.js +0 -46
- package/bin/brokenLinks.js +0 -122
- package/bin/callbackServer.js +0 -65
- package/bin/cli.js +0 -813
- package/bin/comingSoon.js +0 -26
- package/bin/config.js +0 -78
- package/bin/constants.js +0 -16
- package/bin/deploy-base.js +0 -20
- package/bin/deploy-github-actions.js +0 -102
- package/bin/deploy-github-setup.js +0 -165
- package/bin/deploy-instructions.js +0 -71
- package/bin/deploy.js +0 -123
- package/bin/feedback.js +0 -36
- package/bin/format.js +0 -121
- package/bin/helpers.js +0 -238
- package/bin/idToken.js +0 -14
- package/bin/index.js +0 -102
- package/bin/init.js +0 -182
- package/bin/instructions.js +0 -101
- package/bin/keyring.js +0 -78
- package/bin/login.js +0 -123
- package/bin/logout.js +0 -18
- package/bin/mdxAccessibility.js +0 -113
- package/bin/mdxLinter.js +0 -55
- package/bin/middlewares/subdomainMiddleware.js +0 -28
- package/bin/middlewares/telemetryMiddleware.js +0 -61
- package/bin/migrate.js +0 -54
- package/bin/og.js +0 -145
- package/bin/openApiCheck.js +0 -99
- package/bin/resolveFiles.js +0 -114
- package/bin/score/client.js +0 -40
- package/bin/score/index.js +0 -211
- package/bin/score/types.js +0 -1
- package/bin/signup.js +0 -118
- package/bin/start.js +0 -36
- package/bin/status.js +0 -106
- package/bin/telemetry/client.js +0 -53
- package/bin/telemetry/distinctId.js +0 -68
- package/bin/telemetry/sessionId.js +0 -36
- package/bin/telemetry/track.js +0 -149
- package/bin/templates.js +0 -127
- package/bin/tokenRefresh.js +0 -50
- package/bin/tsconfig.build.tsbuildinfo +0 -1
- package/bin/update.js +0 -65
- package/bin/validate/command.js +0 -127
- package/bin/validate/engine.js +0 -154
- package/bin/validate/files.js +0 -163
- package/bin/validate/mdx.js +0 -238
- package/bin/validate/output.js +0 -44
- package/bin/validate/report.js +0 -11
- package/bin/validate/rules/build.js +0 -102
- package/bin/validate/rules/content/duplicateH1.js +0 -57
- package/bin/validate/rules/content/foreignSyntax.js +0 -120
- package/bin/validate/rules/content/katex.js +0 -34
- package/bin/validate/rules/content/missingSnippet.js +0 -34
- package/bin/validate/rules/content/undefinedVariable.js +0 -13
- package/bin/validate/rules/content/unknownComponent.js +0 -121
- package/bin/validate/rules/content/voidTags.js +0 -38
- package/bin/validate/rules/index.js +0 -21
- package/bin/validate/rules/openapi.js +0 -50
- package/bin/validate/rules/parseError.js +0 -7
- package/bin/validate/site.js +0 -57
- package/bin/validate/types.js +0 -1
- package/bin/vendor/converter.js +0 -30882
- package/bin/welcome.js +0 -108
- package/bin/workflows/client.js +0 -34
- package/bin/workflows/index.js +0 -269
- package/bin/workflows/types.js +0 -11
- package/scripts/bundle-converter.mjs +0 -26
- package/scripts/generate-logo.mjs +0 -79
- package/src/accessibility.ts +0 -180
- package/src/accessibilityCheck.tsx +0 -150
- package/src/addDomain.tsx +0 -206
- package/src/agent-auth.ts +0 -119
- package/src/agent-claim.ts +0 -124
- package/src/agent-credentials.ts +0 -104
- package/src/agent-deployment.ts +0 -116
- package/src/agent-http.ts +0 -34
- package/src/agent-setup-config.ts +0 -144
- package/src/agent-setup.ts +0 -165
- package/src/agent.ts +0 -56
- package/src/analytics/client.ts +0 -153
- package/src/analytics/dates.ts +0 -6
- package/src/analytics/filters.ts +0 -50
- package/src/analytics/format.ts +0 -13
- package/src/analytics/index.tsx +0 -599
- package/src/analytics/output.ts +0 -99
- package/src/analytics/types.ts +0 -145
- package/src/authenticatedFetch.ts +0 -42
- package/src/brokenLinks.tsx +0 -152
- package/src/callbackServer.ts +0 -64
- package/src/cli.tsx +0 -1105
- package/src/comingSoon.tsx +0 -29
- package/src/config.ts +0 -75
- package/src/constants.ts +0 -28
- package/src/deploy-base.ts +0 -18
- package/src/deploy-github-actions.ts +0 -139
- package/src/deploy-github-setup.ts +0 -189
- package/src/deploy-instructions.ts +0 -76
- package/src/deploy.ts +0 -165
- package/src/feedback.tsx +0 -31
- package/src/format.tsx +0 -82
- package/src/helpers.tsx +0 -279
- package/src/idToken.ts +0 -17
- package/src/index.ts +0 -109
- package/src/init.tsx +0 -237
- package/src/instructions.ts +0 -99
- package/src/keyring.ts +0 -65
- package/src/login.tsx +0 -166
- package/src/logout.tsx +0 -8
- package/src/mdxAccessibility.ts +0 -134
- package/src/mdxLinter.tsx +0 -88
- package/src/middlewares/subdomainMiddleware.ts +0 -20
- package/src/middlewares/telemetryMiddleware.ts +0 -55
- package/src/migrate.ts +0 -76
- package/src/og.tsx +0 -185
- package/src/openApiCheck.tsx +0 -125
- package/src/resolveFiles.ts +0 -101
- package/src/score/client.ts +0 -36
- package/src/score/index.tsx +0 -205
- package/src/score/types.ts +0 -15
- package/src/signup.tsx +0 -172
- package/src/start.ts +0 -27
- package/src/status.tsx +0 -129
- package/src/telemetry/client.ts +0 -46
- package/src/telemetry/distinctId.ts +0 -70
- package/src/telemetry/sessionId.ts +0 -40
- package/src/telemetry/track.ts +0 -163
- package/src/templates.tsx +0 -143
- package/src/tokenRefresh.ts +0 -53
- package/src/update.tsx +0 -89
- package/src/validate/command.tsx +0 -135
- package/src/validate/engine.ts +0 -210
- package/src/validate/files.ts +0 -249
- package/src/validate/mdx.ts +0 -290
- package/src/validate/output.tsx +0 -76
- package/src/validate/report.ts +0 -40
- package/src/validate/rules/build.ts +0 -146
- package/src/validate/rules/content/duplicateH1.ts +0 -78
- package/src/validate/rules/content/foreignSyntax.ts +0 -144
- package/src/validate/rules/content/katex.ts +0 -33
- package/src/validate/rules/content/missingSnippet.ts +0 -36
- package/src/validate/rules/content/undefinedVariable.ts +0 -20
- package/src/validate/rules/content/unknownComponent.ts +0 -130
- package/src/validate/rules/content/voidTags.ts +0 -43
- package/src/validate/rules/index.ts +0 -23
- package/src/validate/rules/openapi.ts +0 -59
- package/src/validate/rules/parseError.ts +0 -9
- package/src/validate/site.ts +0 -53
- package/src/validate/types.ts +0 -102
- package/src/vendor/converter.ts +0 -1
- package/src/welcome.ts +0 -154
- package/src/workflows/client.ts +0 -39
- package/src/workflows/index.tsx +0 -287
- package/src/workflows/types.ts +0 -73
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -10
- package/vitest.config.ts +0 -9
package/src/mdxAccessibility.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { coreRemark } from '@mintlify/common';
|
|
2
|
-
import { categorizeFilePaths, getMintIgnore } from '@mintlify/prebuild';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import type { Root, Text } from 'mdast';
|
|
5
|
-
import type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import type { Node } from 'unist';
|
|
8
|
-
import { visit } from 'unist-util-visit';
|
|
9
|
-
|
|
10
|
-
export interface AccessibilityFixAttribute {
|
|
11
|
-
filePath: string;
|
|
12
|
-
line?: number;
|
|
13
|
-
column?: number;
|
|
14
|
-
element: 'img' | 'video' | 'a';
|
|
15
|
-
tagName: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface MdxAccessibilityResult {
|
|
19
|
-
missingAltAttributes: AccessibilityFixAttribute[];
|
|
20
|
-
totalFiles: number;
|
|
21
|
-
filesWithIssues: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const checkAltAttributes = (filePath: string, content: string): AccessibilityFixAttribute[] => {
|
|
25
|
-
const issues: AccessibilityFixAttribute[] = [];
|
|
26
|
-
|
|
27
|
-
const visitElements = () => {
|
|
28
|
-
return (tree: Root) => {
|
|
29
|
-
visit(tree, (node) => {
|
|
30
|
-
if (node.type === 'image') {
|
|
31
|
-
if (!node.alt || node.alt.trim() === '') {
|
|
32
|
-
issues.push({
|
|
33
|
-
filePath,
|
|
34
|
-
line: node.position?.start.line,
|
|
35
|
-
column: node.position?.start.column,
|
|
36
|
-
element: 'img',
|
|
37
|
-
tagName: 'image (markdown)',
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const mdxJsxElement = node as MdxJsxFlowElement;
|
|
44
|
-
if (mdxJsxElement.name === 'img' || mdxJsxElement.name === 'video') {
|
|
45
|
-
const altAttrIndex = mdxJsxElement.attributes.findIndex(
|
|
46
|
-
(attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'alt'
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
const altAttribute = mdxJsxElement.attributes[altAttrIndex];
|
|
50
|
-
const hasValidAlt =
|
|
51
|
-
altAttribute &&
|
|
52
|
-
typeof altAttribute.value === 'string' &&
|
|
53
|
-
altAttribute.value.trim() !== '';
|
|
54
|
-
|
|
55
|
-
if (!hasValidAlt) {
|
|
56
|
-
issues.push({
|
|
57
|
-
filePath,
|
|
58
|
-
line: node.position?.start.line,
|
|
59
|
-
column: node.position?.start.column,
|
|
60
|
-
element: mdxJsxElement.name,
|
|
61
|
-
tagName: mdxJsxElement.name,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
} else if (mdxJsxElement.name === 'a') {
|
|
65
|
-
const hasTextContent = (children: Node[]): boolean => {
|
|
66
|
-
return children.some((child) => {
|
|
67
|
-
if (child.type === 'text') {
|
|
68
|
-
const textNode = child as Text;
|
|
69
|
-
return textNode.value.trim() !== '';
|
|
70
|
-
}
|
|
71
|
-
if ('children' in child && Array.isArray(child.children)) {
|
|
72
|
-
return hasTextContent(child.children as Node[]);
|
|
73
|
-
}
|
|
74
|
-
return false;
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
if (!hasTextContent(mdxJsxElement.children as Node[])) {
|
|
79
|
-
issues.push({
|
|
80
|
-
filePath,
|
|
81
|
-
line: node.position?.start.line,
|
|
82
|
-
column: node.position?.start.column,
|
|
83
|
-
element: 'a',
|
|
84
|
-
tagName: '<a>',
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
return tree;
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
const stripped = content.replace(/^( {0,3}#{1,6}\s+.+?)\s*\{#[^}]+\}\s*$/gm, '$1');
|
|
95
|
-
coreRemark().use(visitElements).processSync(stripped);
|
|
96
|
-
} catch (error) {
|
|
97
|
-
console.warn(`Warning: Could not parse ${filePath}: ${error}`);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return issues;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export const checkMdxAccessibility = async (
|
|
104
|
-
baseDir: string = process.cwd()
|
|
105
|
-
): Promise<MdxAccessibilityResult> => {
|
|
106
|
-
const mintIgnore = await getMintIgnore(baseDir);
|
|
107
|
-
const { contentFilenames } = await categorizeFilePaths(baseDir, mintIgnore);
|
|
108
|
-
const mdxFiles: string[] = [];
|
|
109
|
-
for (const file of contentFilenames) {
|
|
110
|
-
mdxFiles.push(path.join(baseDir, file));
|
|
111
|
-
}
|
|
112
|
-
const allIssues: AccessibilityFixAttribute[] = [];
|
|
113
|
-
const filesWithIssues = new Set<string>();
|
|
114
|
-
|
|
115
|
-
for (const filePath of mdxFiles) {
|
|
116
|
-
try {
|
|
117
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
118
|
-
const issues = checkAltAttributes(filePath, content);
|
|
119
|
-
|
|
120
|
-
if (issues.length > 0) {
|
|
121
|
-
allIssues.push(...issues);
|
|
122
|
-
filesWithIssues.add(filePath);
|
|
123
|
-
}
|
|
124
|
-
} catch (error) {
|
|
125
|
-
console.warn(`Warning: Could not read file ${filePath}: ${error}`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
missingAltAttributes: allIssues,
|
|
131
|
-
totalFiles: mdxFiles.length,
|
|
132
|
-
filesWithIssues: filesWithIssues.size,
|
|
133
|
-
};
|
|
134
|
-
};
|
package/src/mdxLinter.tsx
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { addLog, ErrorLog, SuccessLog } from '@mintlify/previewing';
|
|
2
|
-
import { Text } from 'ink';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
import { TerminateCode } from './accessibilityCheck.js';
|
|
6
|
-
import { checkMdxAccessibility, type AccessibilityFixAttribute } from './mdxAccessibility.js';
|
|
7
|
-
|
|
8
|
-
export const mdxLinter = async (): Promise<TerminateCode> => {
|
|
9
|
-
try {
|
|
10
|
-
addLog(
|
|
11
|
-
<Text bold color="cyan">
|
|
12
|
-
Checking mdx files for accessibility issues...
|
|
13
|
-
</Text>
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
const results = await checkMdxAccessibility();
|
|
17
|
-
|
|
18
|
-
if (results.missingAltAttributes.length === 0) {
|
|
19
|
-
addLog(<SuccessLog message="no accessibility issues found" />);
|
|
20
|
-
addLog(
|
|
21
|
-
<Text>
|
|
22
|
-
Checked {results.totalFiles} MDX files - all images and videos have alt attributes.
|
|
23
|
-
</Text>
|
|
24
|
-
);
|
|
25
|
-
return 0;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const issuesByFile: Record<string, AccessibilityFixAttribute[]> = {};
|
|
29
|
-
results.missingAltAttributes.forEach((issue) => {
|
|
30
|
-
if (!issuesByFile[issue.filePath]) {
|
|
31
|
-
issuesByFile[issue.filePath] = [];
|
|
32
|
-
}
|
|
33
|
-
issuesByFile[issue.filePath]?.push(issue);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
addLog(
|
|
37
|
-
<Text bold color="red">
|
|
38
|
-
Found {results.missingAltAttributes.length} accessibility issues in{' '}
|
|
39
|
-
{results.filesWithIssues} files:
|
|
40
|
-
</Text>
|
|
41
|
-
);
|
|
42
|
-
addLog(<Text></Text>);
|
|
43
|
-
|
|
44
|
-
for (const [filePath, issues] of Object.entries(issuesByFile)) {
|
|
45
|
-
const relativePath = path.relative(process.cwd(), filePath);
|
|
46
|
-
addLog(<Text bold>{relativePath}:</Text>);
|
|
47
|
-
|
|
48
|
-
for (const issue of issues) {
|
|
49
|
-
const location =
|
|
50
|
-
issue.line && issue.column ? ` (line ${issue.line}, col ${issue.column})` : '';
|
|
51
|
-
if (issue.element === 'a') {
|
|
52
|
-
addLog(
|
|
53
|
-
<Text>
|
|
54
|
-
<Text color="red"> ✗</Text> Missing text attribute <Text bold>{issue.tagName}</Text>{' '}
|
|
55
|
-
element{location}
|
|
56
|
-
</Text>
|
|
57
|
-
);
|
|
58
|
-
} else {
|
|
59
|
-
addLog(
|
|
60
|
-
<Text>
|
|
61
|
-
<Text color="red"> ✗</Text> Missing alt attribute on <Text bold>{issue.tagName}</Text>{' '}
|
|
62
|
-
element{location}
|
|
63
|
-
</Text>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
addLog(<Text></Text>);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
addLog(
|
|
71
|
-
<Text color="yellow">
|
|
72
|
-
<Text bold>Recommendation:</Text> Add alt attributes to all images and videos for better
|
|
73
|
-
accessibility.
|
|
74
|
-
</Text>
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
return 1;
|
|
78
|
-
} catch (error) {
|
|
79
|
-
addLog(
|
|
80
|
-
<ErrorLog
|
|
81
|
-
message={`MDX accessibility check failed: ${
|
|
82
|
-
error instanceof Error ? error.message : 'Unknown error'
|
|
83
|
-
}`}
|
|
84
|
-
/>
|
|
85
|
-
);
|
|
86
|
-
return 1;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ArgumentsCamelCase } from 'yargs';
|
|
2
|
-
|
|
3
|
-
import { getConfigValue } from '../config.js';
|
|
4
|
-
import { getAccessToken } from '../keyring.js';
|
|
5
|
-
import { getCliSubdomains } from '../status.js';
|
|
6
|
-
|
|
7
|
-
type MiddlewareArgs = ArgumentsCamelCase<Record<string, unknown>>;
|
|
8
|
-
|
|
9
|
-
export async function subdomainMiddleware(argv: MiddlewareArgs): Promise<void> {
|
|
10
|
-
if (typeof argv.subdomain === 'string' && argv.subdomain.length > 0) return;
|
|
11
|
-
const fromConfig = getConfigValue('subdomain');
|
|
12
|
-
if (fromConfig) {
|
|
13
|
-
argv.subdomain = fromConfig;
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const accessToken = await getAccessToken();
|
|
17
|
-
if (!accessToken) return;
|
|
18
|
-
const subdomains = await getCliSubdomains(accessToken);
|
|
19
|
-
argv.subdomain = subdomains[0];
|
|
20
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { getConfigValue } from '../config.js';
|
|
2
|
-
import { getVersions } from '../helpers.js';
|
|
3
|
-
import { trackCommand } from '../telemetry/track.js';
|
|
4
|
-
|
|
5
|
-
const SCRAPE_SUBCOMMANDS = new Set(['page', 'site', 'openapi']);
|
|
6
|
-
const ANALYTICS_SUBCOMMANDS = new Set(['stats', 'search', 'feedback', 'conversation']);
|
|
7
|
-
const CONFIG_SUBCOMMANDS = new Set(['set', 'get', 'clear']);
|
|
8
|
-
const CONVERSATION_SUBCOMMANDS = new Set(['list', 'view', 'buckets']);
|
|
9
|
-
const BUCKETS_SUBCOMMANDS = new Set(['list', 'view']);
|
|
10
|
-
|
|
11
|
-
export function getSanitizedCommandForTelemetry(_: (string | number)[]): string {
|
|
12
|
-
const parts = _.filter((p): p is string => typeof p === 'string');
|
|
13
|
-
if (parts.length === 0) return '';
|
|
14
|
-
const first = parts[0]!;
|
|
15
|
-
const second = parts[1];
|
|
16
|
-
const third = parts[2];
|
|
17
|
-
|
|
18
|
-
if (first === 'scrape' && second !== undefined && SCRAPE_SUBCOMMANDS.has(second)) {
|
|
19
|
-
return `scrape ${second}`;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (first === 'config' && second !== undefined && CONFIG_SUBCOMMANDS.has(second)) {
|
|
23
|
-
return `config ${second}`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (first === 'analytics' && second !== undefined && ANALYTICS_SUBCOMMANDS.has(second)) {
|
|
27
|
-
if (second === 'conversation' && third !== undefined) {
|
|
28
|
-
if (CONVERSATION_SUBCOMMANDS.has(third)) {
|
|
29
|
-
const fourth = parts[3];
|
|
30
|
-
if (third === 'buckets' && fourth !== undefined && BUCKETS_SUBCOMMANDS.has(fourth)) {
|
|
31
|
-
return `analytics conversation buckets ${fourth}`;
|
|
32
|
-
}
|
|
33
|
-
return `analytics conversation ${third}`;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return `analytics ${second}`;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return first;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function createTelemetryMiddleware(): (argv: { _: (string | number)[] }) => Promise<void> {
|
|
43
|
-
let tracked = false;
|
|
44
|
-
return async function telemetryMiddleware(argv: { _: (string | number)[] }): Promise<void> {
|
|
45
|
-
const command = argv._[0];
|
|
46
|
-
if (typeof command === 'string') {
|
|
47
|
-
if (tracked) return;
|
|
48
|
-
tracked = true;
|
|
49
|
-
const sanitizedCommand = getSanitizedCommandForTelemetry(argv._);
|
|
50
|
-
const { cli: cliVersion } = getVersions();
|
|
51
|
-
const subdomain = getConfigValue('subdomain');
|
|
52
|
-
void trackCommand({ command: sanitizedCommand, cliVersion, subdomain });
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
package/src/migrate.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { readdirSync, readFileSync } from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
|
|
6
|
-
import { windowsCompatibleSpawnOptions } from './helpers.js';
|
|
7
|
-
|
|
8
|
-
type Section = 'topics' | 'sources';
|
|
9
|
-
|
|
10
|
-
const root = fileURLToPath(new URL('../migrate', import.meta.url));
|
|
11
|
-
|
|
12
|
-
const read = (...segments: string[]) => readFileSync(path.join(root, ...segments), 'utf8');
|
|
13
|
-
|
|
14
|
-
export const listMigrationDocs = (section: Section) =>
|
|
15
|
-
readdirSync(path.join(root, section))
|
|
16
|
-
.filter((file) => file.endsWith('.md'))
|
|
17
|
-
.map((file) => file.slice(0, -3))
|
|
18
|
-
.sort();
|
|
19
|
-
|
|
20
|
-
const overview = () =>
|
|
21
|
-
[
|
|
22
|
-
read('index.md').trimEnd(),
|
|
23
|
-
`Topics: ${listMigrationDocs('topics').join(', ')}. Run \`mint migrate --topic <name>\`.`,
|
|
24
|
-
`Sources: ${listMigrationDocs('sources').join(', ')}. Run \`mint migrate --from <name>\`.`,
|
|
25
|
-
].join('\n\n');
|
|
26
|
-
|
|
27
|
-
export const migrationInstructions = ({ from, topic }: { from?: string; topic?: string }) => {
|
|
28
|
-
if (topic) return read('topics', `${topic}.md`);
|
|
29
|
-
if (from) return `${overview()}\n\n${read('sources', `${from}.md`)}`;
|
|
30
|
-
return `${overview()}\n`;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const prompt = (from?: string) =>
|
|
34
|
-
`Migrate a documentation site to Mintlify in the current directory. Run \`mint migrate${from ? ` --from ${from}` : ''}\` and follow the instructions it prints.`;
|
|
35
|
-
|
|
36
|
-
export const agents = {
|
|
37
|
-
claude: {
|
|
38
|
-
bin: 'claude',
|
|
39
|
-
args: (prompt: string) => [prompt],
|
|
40
|
-
install: 'npm install -g @anthropic-ai/claude-code',
|
|
41
|
-
},
|
|
42
|
-
codex: {
|
|
43
|
-
bin: 'codex',
|
|
44
|
-
args: (prompt: string) => [prompt],
|
|
45
|
-
install: 'npm install -g @openai/codex',
|
|
46
|
-
},
|
|
47
|
-
cursor: {
|
|
48
|
-
bin: 'cursor-agent',
|
|
49
|
-
args: (prompt: string) => [prompt],
|
|
50
|
-
install: 'curl https://cursor.com/install -fsS | bash',
|
|
51
|
-
},
|
|
52
|
-
gemini: {
|
|
53
|
-
bin: 'gemini',
|
|
54
|
-
args: (prompt: string) => ['-i', prompt],
|
|
55
|
-
install: 'npm install -g @google/gemini-cli',
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export type AgentName = keyof typeof agents;
|
|
60
|
-
|
|
61
|
-
export const agentArgs = (name: AgentName, from?: string) => agents[name].args(prompt(from));
|
|
62
|
-
|
|
63
|
-
export const migrateWithAgent = (name: AgentName, from?: string): Promise<number> =>
|
|
64
|
-
new Promise((resolve, reject) => {
|
|
65
|
-
const { bin, install } = agents[name];
|
|
66
|
-
const args = agentArgs(name, from).map((arg) =>
|
|
67
|
-
windowsCompatibleSpawnOptions.shell ? `"${arg}"` : arg
|
|
68
|
-
);
|
|
69
|
-
const child = spawn(bin, args, { stdio: 'inherit', ...windowsCompatibleSpawnOptions });
|
|
70
|
-
child.on('error', (error: NodeJS.ErrnoException) =>
|
|
71
|
-
reject(
|
|
72
|
-
error.code === 'ENOENT' ? new Error(`${bin} not found. Install it with: ${install}`) : error
|
|
73
|
-
)
|
|
74
|
-
);
|
|
75
|
-
child.on('close', (code) => resolve(code ?? 1));
|
|
76
|
-
});
|
package/src/og.tsx
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { parseFrontmatter, slugToTitle } from '@mintlify/common';
|
|
2
|
-
import { renderOgCardPng } from '@mintlify/og';
|
|
3
|
-
import {
|
|
4
|
-
applyCardThemeOverride,
|
|
5
|
-
applyThumbnailOverride,
|
|
6
|
-
buildOgCardInput,
|
|
7
|
-
checkOgCard,
|
|
8
|
-
createLocalAssetLoaders,
|
|
9
|
-
deriveOgThemeParams,
|
|
10
|
-
getOgPageParams,
|
|
11
|
-
MAX_OG_ASSET_BYTES,
|
|
12
|
-
toOgFontAsset,
|
|
13
|
-
toOgImageAsset,
|
|
14
|
-
type OgAssetLoaders,
|
|
15
|
-
} from '@mintlify/og/config';
|
|
16
|
-
import { getConfigObj } from '@mintlify/prebuild';
|
|
17
|
-
import { addLog, ErrorLog, SuccessLog, WarningLog } from '@mintlify/previewing';
|
|
18
|
-
import { validateDocsConfig, type ThumbnailOverride } from '@mintlify/validation';
|
|
19
|
-
import { mkdir, mkdtemp, readFile, writeFile } from 'node:fs/promises';
|
|
20
|
-
import os from 'node:os';
|
|
21
|
-
import path from 'node:path';
|
|
22
|
-
import open from 'open';
|
|
23
|
-
|
|
24
|
-
import { CMD_EXEC_PATH } from './helpers.js';
|
|
25
|
-
|
|
26
|
-
export type OgCommandOptions = Pick<ThumbnailOverride, 'preset' | 'surface' | 'appearance'> & {
|
|
27
|
-
page?: string;
|
|
28
|
-
output?: string;
|
|
29
|
-
open: boolean;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const REMOTE_TIMEOUT_MS = 5_000;
|
|
33
|
-
const PAGE_EXTENSIONS = ['.mdx', '.md'];
|
|
34
|
-
const MAX_REPORTED_ISSUES = 5;
|
|
35
|
-
|
|
36
|
-
const readLimited = async (response: Response): Promise<Uint8Array | null> => {
|
|
37
|
-
const declared = Number(response.headers.get('content-length'));
|
|
38
|
-
if (declared > MAX_OG_ASSET_BYTES || !response.body) return null;
|
|
39
|
-
|
|
40
|
-
const reader = response.body.getReader();
|
|
41
|
-
const chunks: Uint8Array[] = [];
|
|
42
|
-
let size = 0;
|
|
43
|
-
for (let result = await reader.read(); !result.done; result = await reader.read()) {
|
|
44
|
-
size += result.value.byteLength;
|
|
45
|
-
if (size > MAX_OG_ASSET_BYTES) {
|
|
46
|
-
await reader.cancel();
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
chunks.push(result.value);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const bytes = new Uint8Array(size);
|
|
53
|
-
let offset = 0;
|
|
54
|
-
for (const chunk of chunks) {
|
|
55
|
-
bytes.set(chunk, offset);
|
|
56
|
-
offset += chunk.byteLength;
|
|
57
|
-
}
|
|
58
|
-
return bytes;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const fetchAsset = async (src: string) => {
|
|
62
|
-
try {
|
|
63
|
-
const response = await fetch(src, { signal: AbortSignal.timeout(REMOTE_TIMEOUT_MS) });
|
|
64
|
-
if (!response.ok) return null;
|
|
65
|
-
const bytes = await readLimited(response);
|
|
66
|
-
return bytes && { bytes, contentType: response.headers.get('content-type') ?? undefined };
|
|
67
|
-
} catch {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const remoteLoaders: OgAssetLoaders = {
|
|
73
|
-
image: async (src) => {
|
|
74
|
-
const asset = await fetchAsset(src);
|
|
75
|
-
return asset && toOgImageAsset(asset.bytes, asset.contentType);
|
|
76
|
-
},
|
|
77
|
-
font: async (src) => {
|
|
78
|
-
const asset = await fetchAsset(src);
|
|
79
|
-
return asset && toOgFontAsset(asset.bytes);
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const normalizePagePath = (page: string | undefined) =>
|
|
84
|
-
path.posix
|
|
85
|
-
.normalize(`/${(page ?? '').replace(/\\/g, '/')}`)
|
|
86
|
-
.replace(/^\/+|\/+$/g, '')
|
|
87
|
-
.replace(/\.mdx?$/, '') || 'index';
|
|
88
|
-
|
|
89
|
-
const pageHref = (pagePath: string) => pagePath.replace(/(^|\/)index$/, '');
|
|
90
|
-
|
|
91
|
-
const pageCandidates = (pagePath: string) =>
|
|
92
|
-
[pagePath, `${pagePath}/index`].flatMap((base) =>
|
|
93
|
-
PAGE_EXTENSIONS.map((extension) => `${base}${extension}`)
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
const readPage = async (pagePath: string) => {
|
|
97
|
-
const root = path.resolve(CMD_EXEC_PATH);
|
|
98
|
-
for (const candidate of pageCandidates(pagePath)) {
|
|
99
|
-
const filePath = path.resolve(root, candidate);
|
|
100
|
-
if (!filePath.startsWith(`${root}${path.sep}`)) return null;
|
|
101
|
-
try {
|
|
102
|
-
return await readFile(filePath, 'utf-8');
|
|
103
|
-
} catch {
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return null;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const stringAttribute = (attributes: Record<string, unknown>, key: string) => {
|
|
111
|
-
const value = attributes[key];
|
|
112
|
-
return typeof value === 'string' && value ? value : undefined;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const defaultOutputPath = async (pagePath: string) =>
|
|
116
|
-
path.join(
|
|
117
|
-
await mkdtemp(path.join(os.tmpdir(), 'mintlify-og-')),
|
|
118
|
-
`${pagePath.replace(/\//g, '-')}.png`
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
export async function ogCommand(options: OgCommandOptions): Promise<0 | 1> {
|
|
122
|
-
const rawConfig = await getConfigObj(CMD_EXEC_PATH, 'docs');
|
|
123
|
-
if (!rawConfig) {
|
|
124
|
-
addLog(<ErrorLog message="No docs.json found. Run mint og from your docs directory." />);
|
|
125
|
-
return 1;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const validation = validateDocsConfig(rawConfig);
|
|
129
|
-
if (!validation.success) {
|
|
130
|
-
const issues = validation.error.issues
|
|
131
|
-
.slice(0, MAX_REPORTED_ISSUES)
|
|
132
|
-
.map((issue) => `${issue.path.join('.') || 'docs.json'}: ${issue.message}`);
|
|
133
|
-
addLog(<ErrorLog message={`docs.json is invalid:\n${issues.join('\n')}`} />);
|
|
134
|
-
return 1;
|
|
135
|
-
}
|
|
136
|
-
const docsConfig = validation.data;
|
|
137
|
-
|
|
138
|
-
const pagePath = normalizePagePath(options.page);
|
|
139
|
-
const contents = await readPage(pagePath);
|
|
140
|
-
if (contents === null) {
|
|
141
|
-
addLog(
|
|
142
|
-
<ErrorLog message={`Couldn't find a page at ${pageCandidates(pagePath).join(', ')}.`} />
|
|
143
|
-
);
|
|
144
|
-
return 1;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const { attributes } = parseFrontmatter<Record<string, unknown>>(contents);
|
|
148
|
-
const pageParams = getOgPageParams(
|
|
149
|
-
{
|
|
150
|
-
path: pagePath,
|
|
151
|
-
title:
|
|
152
|
-
stringAttribute(attributes, 'title') ??
|
|
153
|
-
stringAttribute(attributes, 'sidebarTitle') ??
|
|
154
|
-
slugToTitle(pageHref(pagePath)),
|
|
155
|
-
description: stringAttribute(attributes, 'description'),
|
|
156
|
-
thumbnail: attributes.thumbnail,
|
|
157
|
-
},
|
|
158
|
-
docsConfig
|
|
159
|
-
);
|
|
160
|
-
const themeParams = applyThumbnailOverride(
|
|
161
|
-
applyCardThemeOverride(deriveOgThemeParams(docsConfig), pageParams.thumbnail),
|
|
162
|
-
options
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
const input = await buildOgCardInput(
|
|
166
|
-
pageParams,
|
|
167
|
-
themeParams,
|
|
168
|
-
createLocalAssetLoaders(CMD_EXEC_PATH, remoteLoaders)
|
|
169
|
-
);
|
|
170
|
-
const png = await renderOgCardPng(input);
|
|
171
|
-
|
|
172
|
-
const outputPath = options.output
|
|
173
|
-
? path.resolve(options.output)
|
|
174
|
-
: await defaultOutputPath(pagePath);
|
|
175
|
-
await mkdir(path.dirname(outputPath), { recursive: true });
|
|
176
|
-
await writeFile(outputPath, new Uint8Array(png));
|
|
177
|
-
|
|
178
|
-
for (const warning of checkOgCard(input, themeParams)) {
|
|
179
|
-
addLog(<WarningLog message={warning} />);
|
|
180
|
-
}
|
|
181
|
-
addLog(<SuccessLog message={`Wrote ${outputPath}`} />);
|
|
182
|
-
|
|
183
|
-
if (options.open && !process.env.CI) await open(outputPath);
|
|
184
|
-
return 0;
|
|
185
|
-
}
|
package/src/openApiCheck.tsx
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
applyOverlays,
|
|
3
|
-
createOverlayRegistry,
|
|
4
|
-
getOpenApiDocumentFromUrl,
|
|
5
|
-
isAllowedLocalSchemaUrl,
|
|
6
|
-
resolveOverlaysForSpec,
|
|
7
|
-
validate,
|
|
8
|
-
type OverlayRegistry,
|
|
9
|
-
} from '@mintlify/common';
|
|
10
|
-
import { discoverOverlayFiles, getMintIgnore, resolveFileRefs } from '@mintlify/prebuild';
|
|
11
|
-
import { addLog, ErrorLog, SuccessLog, WarningLog } from '@mintlify/previewing';
|
|
12
|
-
import {
|
|
13
|
-
collectOpenApiOverlayConfig,
|
|
14
|
-
extractOpenApiEntries,
|
|
15
|
-
type DocsConfig,
|
|
16
|
-
} from '@mintlify/validation';
|
|
17
|
-
import { promises as fs } from 'fs';
|
|
18
|
-
import path from 'path';
|
|
19
|
-
|
|
20
|
-
import { CMD_EXEC_PATH, readLocalOpenApiFile } from './helpers.js';
|
|
21
|
-
|
|
22
|
-
export const getOpenApiFilenamesFromDocsConfig = (config: Pick<DocsConfig, 'api'>): string[] => {
|
|
23
|
-
return extractOpenApiEntries(config.api?.openapi).map((entry) => entry.source);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Builds the overlay registry so checks validate specs with overlays applied.
|
|
28
|
-
* Throws when docs.json configures conflicting overlay lists, matching the build.
|
|
29
|
-
*/
|
|
30
|
-
export const buildOverlayRegistryForCheck = async (
|
|
31
|
-
localSchema?: boolean
|
|
32
|
-
): Promise<OverlayRegistry | undefined> => {
|
|
33
|
-
// Discovery failures propagate and fail the check: silently skipping overlays would
|
|
34
|
-
// validate a different document than the one the build produces.
|
|
35
|
-
const mintIgnore = await getMintIgnore(CMD_EXEC_PATH);
|
|
36
|
-
const discovered = await discoverOverlayFiles(CMD_EXEC_PATH, mintIgnore);
|
|
37
|
-
|
|
38
|
-
let rawConfig: unknown;
|
|
39
|
-
try {
|
|
40
|
-
rawConfig = JSON.parse(await fs.readFile(path.join(CMD_EXEC_PATH, 'docs.json'), 'utf-8'));
|
|
41
|
-
} catch {
|
|
42
|
-
rawConfig = undefined;
|
|
43
|
-
}
|
|
44
|
-
if (rawConfig !== undefined) {
|
|
45
|
-
try {
|
|
46
|
-
rawConfig = (await resolveFileRefs(rawConfig, CMD_EXEC_PATH)).resolved;
|
|
47
|
-
} catch {
|
|
48
|
-
// Broken $refs are reported by regular config validation; collect from the root file.
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const explicit = rawConfig == undefined ? undefined : collectOpenApiOverlayConfig(rawConfig);
|
|
52
|
-
|
|
53
|
-
if (explicit == undefined && discovered.length === 0) return undefined;
|
|
54
|
-
|
|
55
|
-
return createOverlayRegistry({
|
|
56
|
-
explicit,
|
|
57
|
-
discovered,
|
|
58
|
-
localSchema,
|
|
59
|
-
loadLocalDocument: (normalizedPath) => readLocalOpenApiFile(normalizedPath),
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export type OpenApiCheckMessage = { level: 'success' | 'warning' | 'error'; message: string };
|
|
64
|
-
|
|
65
|
-
const logOpenApiMessage = ({ level, message }: OpenApiCheckMessage) => {
|
|
66
|
-
addLog(
|
|
67
|
-
level === 'success' ? (
|
|
68
|
-
<SuccessLog message={message} />
|
|
69
|
-
) : level === 'warning' ? (
|
|
70
|
-
<WarningLog message={message} />
|
|
71
|
-
) : (
|
|
72
|
-
<ErrorLog message={message} />
|
|
73
|
-
)
|
|
74
|
-
);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export const checkOpenApiFile = async (
|
|
78
|
-
filename: string,
|
|
79
|
-
localSchema: boolean,
|
|
80
|
-
overlayRegistry?: OverlayRegistry,
|
|
81
|
-
report: (message: OpenApiCheckMessage) => void = logOpenApiMessage
|
|
82
|
-
): Promise<boolean> => {
|
|
83
|
-
try {
|
|
84
|
-
const overlays = overlayRegistry ? await resolveOverlaysForSpec(overlayRegistry, filename) : [];
|
|
85
|
-
|
|
86
|
-
if (isAllowedLocalSchemaUrl(filename, localSchema)) {
|
|
87
|
-
await getOpenApiDocumentFromUrl(filename, { overlays });
|
|
88
|
-
report({ level: 'success', message: 'OpenAPI definition is valid.' });
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (filename.startsWith('http://') && !localSchema) {
|
|
93
|
-
report({
|
|
94
|
-
level: 'warning',
|
|
95
|
-
message: 'include the --local-schema flag to check locally hosted OpenAPI files',
|
|
96
|
-
});
|
|
97
|
-
report({ level: 'warning', message: 'only https protocol is supported in production' });
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const document = await readLocalOpenApiFile(filename);
|
|
102
|
-
if (!document) {
|
|
103
|
-
throw new Error(
|
|
104
|
-
'failed to parse OpenAPI spec: could not parse file correctly, please check for any syntax errors.'
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
const overlaid: unknown = overlays.length > 0 ? applyOverlays(document, overlays) : document;
|
|
108
|
-
if (overlaid == undefined || typeof overlaid !== 'object') {
|
|
109
|
-
throw new Error('applying overlays produced an invalid OpenAPI document.');
|
|
110
|
-
}
|
|
111
|
-
await validate(overlaid);
|
|
112
|
-
report({ level: 'success', message: 'OpenAPI definition is valid.' });
|
|
113
|
-
return true;
|
|
114
|
-
} catch (err) {
|
|
115
|
-
if (err && typeof err === 'object' && 'code' in err && err.code === 'ENOENT') {
|
|
116
|
-
report({
|
|
117
|
-
level: 'error',
|
|
118
|
-
message: `file not found, please check the path provided: ${filename}`,
|
|
119
|
-
});
|
|
120
|
-
} else {
|
|
121
|
-
report({ level: 'error', message: err instanceof Error ? err.message : 'unknown error' });
|
|
122
|
-
}
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
};
|