@mintlify/cli 4.0.1813 → 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.
Files changed (274) hide show
  1. package/dist/assets/export-scripts/README.classic.md +15 -0
  2. package/dist/assets/export-scripts/README.md +14 -0
  3. package/dist/assets/export-scripts/serve.js +114 -0
  4. package/dist/assets/export-scripts/start-docs.bat +10 -0
  5. package/dist/assets/export-scripts/start-docs.sh +9 -0
  6. package/dist/assets/og/Inter-Bold.ttf +0 -0
  7. package/dist/assets/og/Inter-Medium.ttf +0 -0
  8. package/dist/assets/og/Inter-Regular.ttf +0 -0
  9. package/dist/assets/og/Inter-SemiBold.ttf +0 -0
  10. package/dist/assets/og/PaperMono-Regular.ttf +0 -0
  11. package/dist/assets/og/index_bg.wasm +0 -0
  12. package/dist/assets/openChrome.applescript +94 -0
  13. package/dist/assets/socket.io/socket.io.esm.min.js +7 -0
  14. package/dist/assets/socket.io/socket.io.esm.min.js.map +1 -0
  15. package/dist/assets/socket.io/socket.io.js +4907 -0
  16. package/dist/assets/socket.io/socket.io.js.map +1 -0
  17. package/dist/assets/socket.io/socket.io.min.js +7 -0
  18. package/dist/assets/socket.io/socket.io.min.js.map +1 -0
  19. package/dist/assets/socket.io/socket.io.msgpack.min.js +7 -0
  20. package/dist/assets/socket.io/socket.io.msgpack.min.js.map +1 -0
  21. package/dist/assets/xdg-open +1066 -0
  22. package/dist/assets/yargs-locales/be.json +46 -0
  23. package/dist/assets/yargs-locales/cs.json +51 -0
  24. package/dist/assets/yargs-locales/de.json +46 -0
  25. package/dist/assets/yargs-locales/en.json +55 -0
  26. package/dist/assets/yargs-locales/es.json +46 -0
  27. package/dist/assets/yargs-locales/fi.json +49 -0
  28. package/dist/assets/yargs-locales/fr.json +53 -0
  29. package/dist/assets/yargs-locales/hi.json +49 -0
  30. package/dist/assets/yargs-locales/hu.json +46 -0
  31. package/dist/assets/yargs-locales/id.json +50 -0
  32. package/dist/assets/yargs-locales/it.json +46 -0
  33. package/dist/assets/yargs-locales/ja.json +51 -0
  34. package/dist/assets/yargs-locales/ko.json +49 -0
  35. package/dist/assets/yargs-locales/nb.json +44 -0
  36. package/dist/assets/yargs-locales/nl.json +49 -0
  37. package/dist/assets/yargs-locales/nn.json +44 -0
  38. package/dist/assets/yargs-locales/pirate.json +13 -0
  39. package/dist/assets/yargs-locales/pl.json +49 -0
  40. package/dist/assets/yargs-locales/pt.json +45 -0
  41. package/dist/assets/yargs-locales/pt_BR.json +48 -0
  42. package/dist/assets/yargs-locales/ru.json +51 -0
  43. package/dist/assets/yargs-locales/th.json +46 -0
  44. package/dist/assets/yargs-locales/tr.json +48 -0
  45. package/dist/assets/yargs-locales/uk_UA.json +51 -0
  46. package/dist/assets/yargs-locales/uz.json +52 -0
  47. package/dist/assets/yargs-locales/zh_CN.json +48 -0
  48. package/dist/assets/yargs-locales/zh_TW.json +51 -0
  49. package/dist/converter-d8O3xkdU.js +102 -0
  50. package/dist/devtools-CGNZQKFV.js +24 -0
  51. package/dist/index.js +8 -0
  52. package/dist/rolldown-runtime-CEAe2Uac.js +7 -0
  53. package/dist/schemas-CBsmCNpK.js +372 -0
  54. package/dist/start.js +2310 -0
  55. package/package.json +38 -31
  56. package/.oxlintrc.json +0 -5
  57. package/.prettierignore +0 -2
  58. package/.turbo/turbo-build.log +0 -1
  59. package/CONTRIBUTING.md +0 -45
  60. package/__test__/agent-auth.test.ts +0 -114
  61. package/__test__/agent-claim.test.ts +0 -164
  62. package/__test__/agent-credentials.test.ts +0 -149
  63. package/__test__/agent-deployment.test.ts +0 -106
  64. package/__test__/agent-setup-config.test.ts +0 -324
  65. package/__test__/agent-setup.test.ts +0 -207
  66. package/__test__/agent.test.ts +0 -64
  67. package/__test__/analytics/client.test.ts +0 -180
  68. package/__test__/analytics/dates.test.ts +0 -12
  69. package/__test__/analytics/filters.test.ts +0 -116
  70. package/__test__/analytics/format.test.ts +0 -137
  71. package/__test__/authenticatedFetch.test.ts +0 -182
  72. package/__test__/brokenLinks.test.ts +0 -283
  73. package/__test__/checkPort.test.ts +0 -92
  74. package/__test__/deploy-github-actions.test.ts +0 -202
  75. package/__test__/deploy-github-setup.test.ts +0 -240
  76. package/__test__/deploy-instructions.test.ts +0 -155
  77. package/__test__/deploy.test.ts +0 -202
  78. package/__test__/feedback.test.ts +0 -34
  79. package/__test__/foreignSyntax.test.ts +0 -73
  80. package/__test__/format.test.ts +0 -72
  81. package/__test__/helpers.test.ts +0 -52
  82. package/__test__/init.test.ts +0 -119
  83. package/__test__/instructions.test.ts +0 -53
  84. package/__test__/keyring.test.ts +0 -82
  85. package/__test__/mdxAccessibility.test.ts +0 -81
  86. package/__test__/migrate.test.ts +0 -186
  87. package/__test__/openApiCheck.test.ts +0 -185
  88. package/__test__/pathValidation.test.ts +0 -25
  89. package/__test__/resolveFiles.test.ts +0 -70
  90. package/__test__/sessionId.test.ts +0 -46
  91. package/__test__/signup.test.ts +0 -36
  92. package/__test__/update.test.ts +0 -117
  93. package/__test__/utils.ts +0 -25
  94. package/__test__/validateCommand.test.ts +0 -647
  95. package/__test__/validateEngine.test.ts +0 -245
  96. package/__test__/validateRules.test.ts +0 -1275
  97. package/__test__/welcome.test.ts +0 -15
  98. package/__test__/workflows/client.test.ts +0 -126
  99. package/bin/accessibility.js +0 -111
  100. package/bin/accessibilityCheck.js +0 -82
  101. package/bin/addDomain.js +0 -130
  102. package/bin/agent-auth.js +0 -104
  103. package/bin/agent-claim.js +0 -97
  104. package/bin/agent-credentials.js +0 -124
  105. package/bin/agent-deployment.js +0 -96
  106. package/bin/agent-http.js +0 -45
  107. package/bin/agent-setup-config.js +0 -141
  108. package/bin/agent-setup.js +0 -146
  109. package/bin/agent.js +0 -42
  110. package/bin/analytics/client.js +0 -60
  111. package/bin/analytics/dates.js +0 -6
  112. package/bin/analytics/filters.js +0 -27
  113. package/bin/analytics/format.js +0 -13
  114. package/bin/analytics/index.js +0 -496
  115. package/bin/analytics/output.js +0 -75
  116. package/bin/analytics/types.js +0 -1
  117. package/bin/authenticatedFetch.js +0 -46
  118. package/bin/brokenLinks.js +0 -122
  119. package/bin/callbackServer.js +0 -65
  120. package/bin/cli.js +0 -813
  121. package/bin/comingSoon.js +0 -26
  122. package/bin/config.js +0 -78
  123. package/bin/constants.js +0 -16
  124. package/bin/deploy-base.js +0 -20
  125. package/bin/deploy-github-actions.js +0 -102
  126. package/bin/deploy-github-setup.js +0 -165
  127. package/bin/deploy-instructions.js +0 -71
  128. package/bin/deploy.js +0 -123
  129. package/bin/feedback.js +0 -36
  130. package/bin/format.js +0 -121
  131. package/bin/helpers.js +0 -238
  132. package/bin/idToken.js +0 -14
  133. package/bin/index.js +0 -102
  134. package/bin/init.js +0 -182
  135. package/bin/instructions.js +0 -101
  136. package/bin/keyring.js +0 -78
  137. package/bin/login.js +0 -123
  138. package/bin/logout.js +0 -18
  139. package/bin/mdxAccessibility.js +0 -113
  140. package/bin/mdxLinter.js +0 -55
  141. package/bin/middlewares/subdomainMiddleware.js +0 -28
  142. package/bin/middlewares/telemetryMiddleware.js +0 -61
  143. package/bin/migrate.js +0 -54
  144. package/bin/og.js +0 -145
  145. package/bin/openApiCheck.js +0 -99
  146. package/bin/resolveFiles.js +0 -114
  147. package/bin/score/client.js +0 -40
  148. package/bin/score/index.js +0 -211
  149. package/bin/score/types.js +0 -1
  150. package/bin/signup.js +0 -118
  151. package/bin/start.js +0 -36
  152. package/bin/status.js +0 -106
  153. package/bin/telemetry/client.js +0 -53
  154. package/bin/telemetry/distinctId.js +0 -68
  155. package/bin/telemetry/sessionId.js +0 -36
  156. package/bin/telemetry/track.js +0 -149
  157. package/bin/templates.js +0 -127
  158. package/bin/tokenRefresh.js +0 -50
  159. package/bin/tsconfig.build.tsbuildinfo +0 -1
  160. package/bin/update.js +0 -65
  161. package/bin/validate/command.js +0 -127
  162. package/bin/validate/engine.js +0 -154
  163. package/bin/validate/files.js +0 -163
  164. package/bin/validate/mdx.js +0 -238
  165. package/bin/validate/output.js +0 -44
  166. package/bin/validate/report.js +0 -11
  167. package/bin/validate/rules/build.js +0 -102
  168. package/bin/validate/rules/content/duplicateH1.js +0 -57
  169. package/bin/validate/rules/content/foreignSyntax.js +0 -120
  170. package/bin/validate/rules/content/katex.js +0 -34
  171. package/bin/validate/rules/content/missingSnippet.js +0 -34
  172. package/bin/validate/rules/content/undefinedVariable.js +0 -13
  173. package/bin/validate/rules/content/unknownComponent.js +0 -121
  174. package/bin/validate/rules/content/voidTags.js +0 -38
  175. package/bin/validate/rules/index.js +0 -21
  176. package/bin/validate/rules/openapi.js +0 -50
  177. package/bin/validate/rules/parseError.js +0 -7
  178. package/bin/validate/site.js +0 -57
  179. package/bin/validate/types.js +0 -1
  180. package/bin/vendor/converter.js +0 -30882
  181. package/bin/welcome.js +0 -108
  182. package/bin/workflows/client.js +0 -34
  183. package/bin/workflows/index.js +0 -269
  184. package/bin/workflows/types.js +0 -11
  185. package/scripts/bundle-converter.mjs +0 -26
  186. package/scripts/generate-logo.mjs +0 -79
  187. package/src/accessibility.ts +0 -180
  188. package/src/accessibilityCheck.tsx +0 -150
  189. package/src/addDomain.tsx +0 -206
  190. package/src/agent-auth.ts +0 -119
  191. package/src/agent-claim.ts +0 -124
  192. package/src/agent-credentials.ts +0 -104
  193. package/src/agent-deployment.ts +0 -116
  194. package/src/agent-http.ts +0 -34
  195. package/src/agent-setup-config.ts +0 -144
  196. package/src/agent-setup.ts +0 -165
  197. package/src/agent.ts +0 -56
  198. package/src/analytics/client.ts +0 -153
  199. package/src/analytics/dates.ts +0 -6
  200. package/src/analytics/filters.ts +0 -50
  201. package/src/analytics/format.ts +0 -13
  202. package/src/analytics/index.tsx +0 -599
  203. package/src/analytics/output.ts +0 -99
  204. package/src/analytics/types.ts +0 -145
  205. package/src/authenticatedFetch.ts +0 -42
  206. package/src/brokenLinks.tsx +0 -152
  207. package/src/callbackServer.ts +0 -64
  208. package/src/cli.tsx +0 -1105
  209. package/src/comingSoon.tsx +0 -29
  210. package/src/config.ts +0 -75
  211. package/src/constants.ts +0 -28
  212. package/src/deploy-base.ts +0 -18
  213. package/src/deploy-github-actions.ts +0 -139
  214. package/src/deploy-github-setup.ts +0 -189
  215. package/src/deploy-instructions.ts +0 -76
  216. package/src/deploy.ts +0 -165
  217. package/src/feedback.tsx +0 -31
  218. package/src/format.tsx +0 -82
  219. package/src/helpers.tsx +0 -279
  220. package/src/idToken.ts +0 -17
  221. package/src/index.ts +0 -109
  222. package/src/init.tsx +0 -237
  223. package/src/instructions.ts +0 -99
  224. package/src/keyring.ts +0 -65
  225. package/src/login.tsx +0 -166
  226. package/src/logout.tsx +0 -8
  227. package/src/mdxAccessibility.ts +0 -134
  228. package/src/mdxLinter.tsx +0 -88
  229. package/src/middlewares/subdomainMiddleware.ts +0 -20
  230. package/src/middlewares/telemetryMiddleware.ts +0 -55
  231. package/src/migrate.ts +0 -76
  232. package/src/og.tsx +0 -185
  233. package/src/openApiCheck.tsx +0 -125
  234. package/src/resolveFiles.ts +0 -101
  235. package/src/score/client.ts +0 -36
  236. package/src/score/index.tsx +0 -205
  237. package/src/score/types.ts +0 -15
  238. package/src/signup.tsx +0 -172
  239. package/src/start.ts +0 -27
  240. package/src/status.tsx +0 -129
  241. package/src/telemetry/client.ts +0 -46
  242. package/src/telemetry/distinctId.ts +0 -70
  243. package/src/telemetry/sessionId.ts +0 -40
  244. package/src/telemetry/track.ts +0 -163
  245. package/src/templates.tsx +0 -143
  246. package/src/tokenRefresh.ts +0 -53
  247. package/src/update.tsx +0 -89
  248. package/src/validate/command.tsx +0 -135
  249. package/src/validate/engine.ts +0 -210
  250. package/src/validate/files.ts +0 -249
  251. package/src/validate/mdx.ts +0 -290
  252. package/src/validate/output.tsx +0 -76
  253. package/src/validate/report.ts +0 -40
  254. package/src/validate/rules/build.ts +0 -146
  255. package/src/validate/rules/content/duplicateH1.ts +0 -78
  256. package/src/validate/rules/content/foreignSyntax.ts +0 -144
  257. package/src/validate/rules/content/katex.ts +0 -33
  258. package/src/validate/rules/content/missingSnippet.ts +0 -36
  259. package/src/validate/rules/content/undefinedVariable.ts +0 -20
  260. package/src/validate/rules/content/unknownComponent.ts +0 -130
  261. package/src/validate/rules/content/voidTags.ts +0 -43
  262. package/src/validate/rules/index.ts +0 -23
  263. package/src/validate/rules/openapi.ts +0 -59
  264. package/src/validate/rules/parseError.ts +0 -9
  265. package/src/validate/site.ts +0 -53
  266. package/src/validate/types.ts +0 -102
  267. package/src/vendor/converter.ts +0 -1
  268. package/src/welcome.ts +0 -154
  269. package/src/workflows/client.ts +0 -39
  270. package/src/workflows/index.tsx +0 -287
  271. package/src/workflows/types.ts +0 -73
  272. package/tsconfig.build.json +0 -4
  273. package/tsconfig.json +0 -10
  274. package/vitest.config.ts +0 -9
package/src/deploy.ts DELETED
@@ -1,165 +0,0 @@
1
- import path from 'node:path';
2
-
3
- import {
4
- discoverAgentAuth,
5
- exchangeAgentToken,
6
- getAgentIdentity,
7
- registerAgent,
8
- } from './agent-auth.js';
9
- import {
10
- loadAgentCredentials,
11
- saveAgentCredentials,
12
- type AgentCredentials,
13
- } from './agent-credentials.js';
14
- import {
15
- getAgentWriteToken,
16
- provisionAgentSite,
17
- type AgentProjectType,
18
- type AgentSite,
19
- type AgentWriteToken,
20
- } from './agent-deployment.js';
21
- import { getAgentSiteMetadata, setAgentSiteMetadata } from './config.js';
22
- import { DASHBOARD_URL } from './constants.js';
23
- import { trackEvent } from './telemetry/track.js';
24
-
25
- export type DeployOptions = {
26
- apiUrl: string;
27
- directory: string;
28
- subdomain?: string;
29
- orgName?: string;
30
- newSite?: boolean;
31
- base?: boolean;
32
- };
33
-
34
- export type DeployResult =
35
- | { status: 'claimed' }
36
- | {
37
- status: 'ready';
38
- projectType: AgentProjectType;
39
- site: AgentSite;
40
- write: AgentWriteToken;
41
- created: boolean;
42
- credentials: AgentCredentials;
43
- };
44
-
45
- export async function prepareAgentDeployment(
46
- options: DeployOptions,
47
- warn: (message: string) => void,
48
- progress: (message: string) => void = () => {}
49
- ): Promise<DeployResult> {
50
- const { apiUrl } = options;
51
- const directory = path.resolve(options.directory);
52
- const metadataKey = JSON.stringify([new URL(apiUrl).origin, directory]);
53
- const previous = getAgentSiteMetadata(metadataKey);
54
- progress('Authenticating agent...');
55
- let saved = options.newSite
56
- ? null
57
- : await loadAgentCredentials(apiUrl, directory).catch(() => {
58
- if (previous)
59
- throw new Error(
60
- 'Could not read this site’s saved credentials. Unlock your keyring or use --new for another site.'
61
- );
62
- warn('Could not read the keyring. Continuing with a new registration for this run.');
63
- return null;
64
- });
65
- const subdomain = options.subdomain ?? (options.newSite ? undefined : previous?.subdomain);
66
- if (!subdomain) throw new Error('Choose a site name with --subdomain <name>.');
67
- const discovery = await discoverAgentAuth(apiUrl);
68
- const projectType: AgentProjectType = options.base ? 'workspace' : 'site';
69
-
70
- const save = (credentials: AgentCredentials) =>
71
- saveAgentCredentials(apiUrl, directory, credentials);
72
-
73
- for (let attempt = 0; attempt < 2; attempt++) {
74
- const credentials = saved ?? (await registerAgent(discovery));
75
- void trackEvent('agent_signup.discovered', { registration_id: credentials.registrationId });
76
- if (!saved)
77
- void trackEvent('agent_signup.registered', { registration_id: credentials.registrationId });
78
- await save(credentials);
79
- const authenticated = await exchangeAgentToken(discovery, credentials);
80
- await save(authenticated);
81
- const identity = await getAgentIdentity(apiUrl, authenticated.accessToken);
82
- if (identity.registrationId !== credentials.registrationId)
83
- throw new Error('Agent identity does not match the saved registration.');
84
- if (identity.identityType === 'user_bound') return { status: 'claimed' };
85
- progress(`Provisioning the ${options.base ? 'base' : 'site'} and repository...`);
86
- const site = await provisionAgentSite(apiUrl, authenticated.accessToken, {
87
- subdomain,
88
- orgName: options.orgName,
89
- ...(options.base && { projectType }),
90
- });
91
- if (site.status === 'expired') {
92
- warn('The previous anonymous site expired. Creating a new registration and site.');
93
- saved = null;
94
- continue;
95
- }
96
- void trackEvent('cli.deploy.provisioned', {
97
- registration_id: credentials.registrationId,
98
- deployment_id: site.deploymentId,
99
- subdomain: site.subdomain,
100
- created: site.created,
101
- });
102
- await setAgentSiteMetadata(metadataKey, {
103
- registrationId: credentials.registrationId,
104
- subdomain: site.subdomain,
105
- }).catch(() =>
106
- warn('Could not save the site name locally. Provide --subdomain on your next invocation.')
107
- );
108
- progress('Getting repository write access...');
109
- const write = await getAgentWriteToken(apiUrl, authenticated.accessToken);
110
- if (write.remote !== site.remote)
111
- throw new Error('Repository credentials do not match the provisioned site.');
112
- return {
113
- status: 'ready',
114
- projectType,
115
- site,
116
- write,
117
- created: site.created,
118
- credentials: authenticated,
119
- };
120
- }
121
- throw new Error('The new anonymous site is already expired. Please retry later.');
122
- }
123
-
124
- export function agentSiteUrl(apiUrl: string, subdomain: string): string {
125
- const domain =
126
- new URL(apiUrl).hostname === 'leaves-dev.mintlify.com'
127
- ? 'mint-dev.mintlify.me'
128
- : 'mintlify.site';
129
- return new URL(`https://${subdomain}.${domain}`).toString();
130
- }
131
-
132
- export function agentEditorUrl(site: Pick<AgentSite, 'subdomain' | 'orgSlug'>): string {
133
- return site.orgSlug
134
- ? new URL(`/${site.orgSlug}/${site.subdomain}/editor`, DASHBOARD_URL).toString()
135
- : new URL(DASHBOARD_URL).toString();
136
- }
137
-
138
- export function formatDeployment(result: DeployResult, apiUrl: string): string {
139
- if (result.status === 'claimed')
140
- return 'This site has been claimed. Manage it in the Mintlify dashboard. Use mint deploy --new --subdomain <name> to create another site.';
141
- const { site, write } = result;
142
- const access = [
143
- `Repository: ${site.remote}`,
144
- `Branch: ${site.branch}`,
145
- `Write token: ${write.token}`,
146
- `Write token expires: ${write.tokenExpiresAt}`,
147
- ];
148
- if (result.projectType === 'workspace')
149
- return [
150
- result.created ? 'Base provisioned.' : 'Using the existing anonymous base.',
151
- `Editor: ${agentEditorUrl(site)}`,
152
- `Expires: ${site.expiresAt}. Claim it before then or it is deleted.`,
153
- ].join('\n');
154
- const siteUrl = agentSiteUrl(apiUrl, site.subdomain);
155
- return [
156
- result.created
157
- ? 'Repository provisioned; push required to build the site.'
158
- : 'Using the existing anonymous repository; push any changes to build the site.',
159
- `Site: ${siteUrl}`,
160
- `Expires: ${site.expiresAt}`,
161
- ...access,
162
- 'Commit and push your documentation to this repository to start the build.',
163
- 'The site link becomes available after the push and build complete.',
164
- ].join('\n');
165
- }
package/src/feedback.tsx DELETED
@@ -1,31 +0,0 @@
1
- import { addLog, ErrorLog, SuccessLog } from '@mintlify/previewing';
2
-
3
- import { API_URL } from './constants.js';
4
-
5
- export const FEEDBACK_CATEGORIES = ['bug', 'docs', 'idea'] as const;
6
-
7
- export type FeedbackInput = {
8
- message: string;
9
- clientId: string;
10
- category: (typeof FEEDBACK_CATEGORIES)[number];
11
- };
12
-
13
- export async function sendFeedback(input: FeedbackInput): Promise<string | undefined> {
14
- let res: Response;
15
- try {
16
- res = await fetch(`${API_URL}/api/cli/feedback`, {
17
- method: 'POST',
18
- headers: { 'Content-Type': 'application/json' },
19
- body: JSON.stringify({ ...input, source: 'cli' }),
20
- });
21
- } catch {
22
- return 'could not reach the server';
23
- }
24
- return res.ok ? undefined : `could not send feedback (HTTP ${res.status})`;
25
- }
26
-
27
- export async function feedback(input: FeedbackInput): Promise<boolean> {
28
- const error = await sendFeedback(input);
29
- addLog(error ? <ErrorLog message={error} /> : <SuccessLog message="feedback sent" />);
30
- return !error;
31
- }
package/src/format.tsx DELETED
@@ -1,82 +0,0 @@
1
- import {
2
- createMintIgnoreMatcher,
3
- isMintIgnoredBy,
4
- processMintIgnoreString,
5
- type MintIgnoreMatcher,
6
- } from '@mintlify/common';
7
- import { getMintIgnore } from '@mintlify/prebuild';
8
- import { addLog, ErrorLog, SuccessLog } from '@mintlify/previewing';
9
- import fs from 'node:fs/promises';
10
- import path from 'node:path';
11
-
12
- import { CMD_EXEC_PATH, terminate } from './helpers.js';
13
-
14
- async function getGitIgnore(): Promise<string[]> {
15
- try {
16
- const content = await fs.readFile(path.join(CMD_EXEC_PATH, '.gitignore'), 'utf-8');
17
- return processMintIgnoreString(content);
18
- } catch {
19
- return [];
20
- }
21
- }
22
-
23
- async function* walk(dir: string, matcher: MintIgnoreMatcher): AsyncGenerator<string> {
24
- const entries = await fs.readdir(dir, { withFileTypes: true });
25
- for (const entry of entries) {
26
- const full = path.join(dir, entry.name);
27
- const relative = path.relative(CMD_EXEC_PATH, full).split(path.sep).join('/');
28
- if (isMintIgnoredBy(relative, matcher, entry.isDirectory())) continue;
29
- if (entry.isDirectory()) {
30
- yield* walk(full, matcher);
31
- } else if (entry.name.endsWith('.mdx')) {
32
- yield full;
33
- }
34
- }
35
- }
36
-
37
- export const formatHandler = async (): Promise<void> => {
38
- const { mdxToPm, pmToMdx, canonicalPmToMdxOptions } = await import('./vendor/converter.js');
39
- const ignores = [...(await getGitIgnore()), ...(await getMintIgnore(CMD_EXEC_PATH))];
40
- const matcher = createMintIgnoreMatcher(ignores);
41
- let total = 0;
42
- let changed = 0;
43
- let failed = 0;
44
-
45
- for await (const file of walk(CMD_EXEC_PATH, matcher)) {
46
- total++;
47
- const relative = path.relative(CMD_EXEC_PATH, file);
48
- try {
49
- const raw = await fs.readFile(file, 'utf-8');
50
- let formatted = raw;
51
- let originalFrontmatterKeys = 0;
52
- for (let pass = 0; pass < 3; pass++) {
53
- const { doc, frontmatter } = mdxToPm(formatted);
54
- if (pass === 0) originalFrontmatterKeys = Object.keys(frontmatter).length;
55
- const next = `${pmToMdx(doc, { frontmatter, ...canonicalPmToMdxOptions })}\n`;
56
- if (next === formatted) break;
57
- formatted = next;
58
- }
59
- if (originalFrontmatterKeys > 0 && !formatted.startsWith('---')) {
60
- throw new Error('formatting would remove frontmatter; file left untouched');
61
- }
62
- if (formatted !== raw) {
63
- await fs.writeFile(file, formatted);
64
- changed++;
65
- }
66
- } catch (error) {
67
- failed++;
68
- addLog(
69
- <ErrorLog
70
- message={`${relative}: ${error instanceof Error ? error.message : 'unknown error'}`}
71
- />
72
- );
73
- }
74
- }
75
-
76
- addLog(
77
- <SuccessLog
78
- message={`formatted ${changed} of ${total} mdx file${total === 1 ? '' : 's'}${failed > 0 ? ` (${failed} failed)` : ''}`}
79
- />
80
- );
81
- await terminate(failed > 0 ? 1 : 0);
82
- };
package/src/helpers.tsx DELETED
@@ -1,279 +0,0 @@
1
- import { getConfigPath } from '@mintlify/prebuild';
2
- import { MintConfigUpdater } from '@mintlify/prebuild';
3
- import {
4
- addLog,
5
- ErrorLog,
6
- getClientVersion,
7
- SuccessLog,
8
- InfoLog,
9
- SpinnerLog,
10
- removeLastLog,
11
- LOCAL_LINKED_CLI_VERSION,
12
- WarningLog,
13
- } from '@mintlify/previewing';
14
- import { upgradeToDocsConfig, validatePathWithinCwd } from '@mintlify/validation';
15
- import detect from 'detect-port';
16
- import fse from 'fs-extra';
17
- import inquirer from 'inquirer';
18
- import yaml from 'js-yaml';
19
- import { execFile, execFileSync } from 'node:child_process';
20
- import { readFileSync } from 'node:fs';
21
- import fs from 'node:fs/promises';
22
- import { createRequire } from 'node:module';
23
- import { fileURLToPath } from 'node:url';
24
- import { promisify } from 'node:util';
25
- import path from 'path';
26
- import type { ArgumentsCamelCase } from 'yargs';
27
-
28
- import { detectAgent } from './agent.js';
29
- import { shutdownPostHog } from './telemetry/client.js';
30
-
31
- export const CMD_EXEC_PATH = process.cwd();
32
-
33
- export const checkPort = async (argv: ArgumentsCamelCase): Promise<number | undefined> => {
34
- const initialPort = typeof argv.port === 'number' ? argv.port : 3000;
35
- if (initialPort === (await detect(initialPort))) return initialPort;
36
-
37
- for (let port = initialPort + 1; port < initialPort + 10; port++) {
38
- addLog(<InfoLog message={`port ${port - 1} is already in use. trying ${port} instead`} />);
39
- if (port === (await detect(port))) return port;
40
- }
41
- };
42
-
43
- export const checkNodeVersion = async () => {
44
- let nodeVersionString = process.version;
45
- if (nodeVersionString.charAt(0) === 'v') {
46
- nodeVersionString = nodeVersionString.slice(1);
47
- }
48
- const versionArr = nodeVersionString.split('.');
49
- const majorVersion = parseInt(versionArr[0]!, 10);
50
- const minorVersion = parseInt(versionArr[1]!, 10);
51
-
52
- if (majorVersion === 25) {
53
- addLog(
54
- <ErrorLog
55
- message={`mintlify is not supported on node 25 (current version ${nodeVersionString}). Please switch to an LTS node version.`}
56
- />
57
- );
58
- await terminate(1);
59
- }
60
-
61
- if (majorVersion < 20 || (majorVersion === 20 && minorVersion < 17)) {
62
- addLog(
63
- <ErrorLog message="mintlify requires node 20.17 or higher. Please upgrade to an LTS node version." />
64
- );
65
- await terminate(1);
66
- }
67
- };
68
-
69
- export const checkForMintJson = async () => {
70
- return !!(await getConfigPath(CMD_EXEC_PATH, 'mint'));
71
- };
72
-
73
- export const findDocsRoot = async (startDir: string): Promise<string> => {
74
- const start = path.resolve(startDir);
75
- const { root } = path.parse(start);
76
-
77
- let dir = start;
78
- while (dir !== root) {
79
- if ((await getConfigPath(dir, 'docs')) || (await getConfigPath(dir, 'mint'))) return dir;
80
- dir = path.dirname(dir);
81
- }
82
- return start;
83
- };
84
-
85
- export const checkForDocsJson = async () => {
86
- const docsJsonPath = path.join(CMD_EXEC_PATH, 'docs.json');
87
- if (!(await fse.pathExists(docsJsonPath))) {
88
- addLog(<InfoLog message="new docs.json file is available" />);
89
- const promptResult = await inquirer.prompt([
90
- {
91
- type: 'list',
92
- name: 'action',
93
- message: 'would you like to upgrade your mint.json to docs.json?',
94
- choices: [
95
- { name: 'upgrade (migrate from mint.json to docs.json)', value: 'upgrade' },
96
- { name: 'continue (use existing mint.json)', value: 'continue' },
97
- ],
98
- },
99
- ]);
100
-
101
- const { action } = promptResult;
102
-
103
- if (action === 'continue') {
104
- addLog(<InfoLog message="proceeding with the existing mint.json..." />);
105
- }
106
-
107
- if (action === 'upgrade') {
108
- addLog(<SpinnerLog message="upgrading docs.json..." />);
109
- await upgradeConfig();
110
- }
111
- }
112
- };
113
-
114
- export const autoUpgradeIfNeeded = async () => {
115
- const hasMintJson = await checkForMintJson();
116
- if (!hasMintJson) return;
117
-
118
- const docsJsonPath = path.join(CMD_EXEC_PATH, 'docs.json');
119
- const hasDocsJson = await fse.pathExists(docsJsonPath);
120
- if (!hasDocsJson) {
121
- addLog(<WarningLog message="Legacy mint.json detected, auto-upgrading to docs.json" />);
122
- addLog(<SpinnerLog message="upgrading mint.json to docs.json..." />);
123
- await upgradeConfig();
124
- }
125
- };
126
-
127
- export const upgradeConfig = async () => {
128
- try {
129
- const mintJsonPath = path.join(CMD_EXEC_PATH, 'mint.json');
130
- const docsJsonPath = path.join(CMD_EXEC_PATH, 'docs.json');
131
- const mintJsonFileContent = await fs.readFile(mintJsonPath, 'utf8');
132
- const validationResult = await MintConfigUpdater.validateConfigJsonString(mintJsonFileContent);
133
- const mintConfig = validationResult.data;
134
- const upgradedDocsConfig = upgradeToDocsConfig(mintConfig, {
135
- shouldUpgradeTheme: true,
136
- });
137
- await fs.writeFile(docsJsonPath, JSON.stringify(upgradedDocsConfig, null, 2));
138
- removeLastLog();
139
- addLog(<SuccessLog message="mint.json file has been upgraded to docs.json." />);
140
- } catch (err) {
141
- removeLastLog();
142
- addLog(<ErrorLog message={err instanceof Error ? err.message : 'an unknown error occurred'} />);
143
- }
144
- };
145
-
146
- const require = createRequire(import.meta.url);
147
-
148
- const isRunningFromLinkedBuild = (): boolean => {
149
- try {
150
- const thisFile = fileURLToPath(import.meta.url);
151
- return !thisFile.split(path.sep).includes('node_modules');
152
- } catch {
153
- return false;
154
- }
155
- };
156
-
157
- const readPackageVersion = (packageName: string): string | undefined => {
158
- try {
159
- const pkgPath = require.resolve(`${packageName}/package.json`);
160
- const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as { version?: string };
161
- return typeof pkg.version === 'string' ? pkg.version : undefined;
162
- } catch {
163
- return undefined;
164
- }
165
- };
166
-
167
- export const getCliVersion = (
168
- packageName: string = process.env.MINTLIFY_PACKAGE_NAME ?? 'mint'
169
- ): string | undefined => {
170
- if (process.env.CLI_TEST_MODE === 'true') {
171
- return 'test-cli';
172
- }
173
- if (isRunningFromLinkedBuild()) {
174
- return LOCAL_LINKED_CLI_VERSION;
175
- }
176
- return readPackageVersion(packageName);
177
- };
178
-
179
- export const getVersions = (
180
- packageName: string = process.env.MINTLIFY_PACKAGE_NAME ?? 'mint'
181
- ): {
182
- cli: string | undefined;
183
- client: string | undefined;
184
- } => {
185
- const cli = getCliVersion(packageName);
186
- const client = getClientVersion().trim();
187
- return { cli, client };
188
- };
189
-
190
- // On Windows, npm/pnpm entrypoints are .cmd shims that Node refuses to spawn
191
- // without a shell (EINVAL since the CVE-2024-27980 fix). Everywhere else we
192
- // keep the shell disabled so arguments can't be interpreted as shell syntax.
193
- export const windowsCompatibleSpawnOptions = {
194
- shell: process.platform === 'win32',
195
- };
196
-
197
- // npm package name grammar (optionally scoped). Rejecting anything else before
198
- // it reaches a package-manager spawn keeps the win32 shell path (above) safe
199
- // from shell metacharacters.
200
- const VALID_PACKAGE_NAME_PATTERN = /^(@[a-z0-9~-][a-z0-9._~-]*\/)?[a-z0-9~-][a-z0-9._~-]*$/;
201
-
202
- export const assertValidPackageName = (packageName: string): void => {
203
- if (!VALID_PACKAGE_NAME_PATTERN.test(packageName)) {
204
- throw new Error(`Invalid package name: ${packageName}`);
205
- }
206
- };
207
-
208
- export const getLatestCliVersion = (packageName: string) => {
209
- assertValidPackageName(packageName);
210
- return execFileSync('npm', ['view', packageName, 'version', '--silent'], {
211
- encoding: 'utf-8',
212
- stdio: ['pipe', 'pipe', 'pipe'],
213
- ...windowsCompatibleSpawnOptions,
214
- }).trim();
215
- };
216
-
217
- export const suppressConsoleWarnings = (): void => {
218
- // Ignore tailwind warnings and punycode deprecation warning
219
- const ignoredMessages = [
220
- 'No utility classes were detected',
221
- 'https://tailwindcss.com/docs/content-configuration',
222
- 'DeprecationWarning',
223
- ];
224
- const originalConsoleError = console.error;
225
- console.error = (...args) => {
226
- const message = args.join(' ');
227
- if (ignoredMessages.some((ignoredMessage) => message.includes(ignoredMessage))) {
228
- return;
229
- }
230
- originalConsoleError.apply(console, args);
231
- };
232
- const originalConsoleWarn = console.warn;
233
- console.warn = (...args) => {
234
- const message = args.join(' ');
235
- if (ignoredMessages.some((ignoredMessage) => message.includes(ignoredMessage))) {
236
- return;
237
- }
238
- originalConsoleWarn.apply(console, args);
239
- };
240
- };
241
-
242
- export const readLocalOpenApiFile = async (
243
- filename: string
244
- ): Promise<Record<string, unknown> | undefined> => {
245
- const { resolvedPath } = validatePathWithinCwd(filename, CMD_EXEC_PATH);
246
- const file = await fs.readFile(resolvedPath, 'utf-8');
247
- const document = yaml.load(file) as Record<string, unknown> | undefined;
248
- return document;
249
- };
250
-
251
- export const errorMessage = (error: unknown) =>
252
- error instanceof Error ? error.message : String(error);
253
-
254
- export const terminate = async (code: number) => {
255
- // Wait for the logs to be fully rendered before exiting
256
- await new Promise((resolve) => setTimeout(resolve, 50));
257
- await shutdownPostHog();
258
- process.exit(code);
259
- };
260
-
261
- export const execFileAsync = promisify(execFile);
262
-
263
- export function isAI(): boolean {
264
- return !process.stdin.isTTY || detectAgent() !== undefined;
265
- }
266
-
267
- export const detectPackageManager = async ({ packageName }: { packageName: string }) => {
268
- assertValidPackageName(packageName);
269
- try {
270
- const { stdout: packagePath } = await execFileAsync('which', [packageName]);
271
- if (packagePath.includes('pnpm')) {
272
- return 'pnpm';
273
- } else {
274
- return 'npm';
275
- }
276
- } catch (error) {
277
- return 'npm';
278
- }
279
- };
package/src/idToken.ts DELETED
@@ -1,17 +0,0 @@
1
- interface IdTokenClaims {
2
- email?: unknown;
3
- }
4
-
5
- export function getEmailFromIdToken(idToken: string | undefined): string | undefined {
6
- if (!idToken) return undefined;
7
-
8
- try {
9
- const payload = idToken.split('.')[1];
10
- if (!payload) return undefined;
11
-
12
- const claims = JSON.parse(Buffer.from(payload, 'base64url').toString('utf8')) as IdTokenClaims;
13
- return typeof claims.email === 'string' && claims.email.length > 0 ? claims.email : undefined;
14
- } catch {
15
- return undefined;
16
- }
17
- }
package/src/index.ts DELETED
@@ -1,109 +0,0 @@
1
- #!/usr/bin/env node
2
- import { spawn, type ChildProcess } from 'child_process';
3
- import path from 'path';
4
- import { fileURLToPath } from 'url';
5
-
6
- const __filename = fileURLToPath(import.meta.url);
7
- const __dirname = path.dirname(__filename);
8
-
9
- const packageName =
10
- path.basename(process.argv[1] ?? '') === 'index.js'
11
- ? 'mint'
12
- : path.basename(process.argv[1] ?? '') || 'mint';
13
-
14
- let cli: ChildProcess | null = null;
15
- let isShuttingDown = false;
16
- let hasExited = false;
17
-
18
- const cleanup = async (): Promise<void> => {
19
- if (isShuttingDown) return;
20
- isShuttingDown = true;
21
-
22
- if (cli && !cli.killed) {
23
- try {
24
- cli.kill('SIGTERM');
25
-
26
- await new Promise<void>((resolve) => {
27
- const timeout = setTimeout(() => {
28
- if (cli && !cli.killed) {
29
- cli.kill('SIGKILL');
30
- }
31
- resolve();
32
- }, 5000);
33
-
34
- cli!.once('exit', () => {
35
- clearTimeout(timeout);
36
- resolve();
37
- });
38
- });
39
- } catch (error) {
40
- // ignore
41
- }
42
- }
43
- };
44
-
45
- const exitProcess = (code: number) => {
46
- if (hasExited) return;
47
- hasExited = true;
48
- process.exit(code);
49
- };
50
-
51
- const killSignals = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP'];
52
- killSignals.forEach((signal) => {
53
- process.on(signal, async () => {
54
- await cleanup();
55
- exitProcess(0);
56
- });
57
- });
58
-
59
- process.on('uncaughtException', async () => {
60
- await cleanup();
61
- exitProcess(1);
62
- });
63
-
64
- process.on('unhandledRejection', async () => {
65
- await cleanup();
66
- exitProcess(1);
67
- });
68
-
69
- // Arguments are passed as array elements to spawn() without shell: true,
70
- // so shell metacharacters are not interpreted and command injection is prevented.
71
- const userArgs = process.argv.slice(2);
72
-
73
- try {
74
- cli = spawn('node', ['--no-deprecation', path.join(__dirname, '../bin/start.js'), ...userArgs], {
75
- stdio: 'inherit',
76
- env: {
77
- ...process.env,
78
- MINTLIFY_PACKAGE_NAME: packageName,
79
- CLI_TEST_MODE: process.env.CLI_TEST_MODE ?? 'false',
80
- },
81
- windowsHide: process.platform === 'win32',
82
- detached: false,
83
- });
84
-
85
- cli.on('error', async (error) => {
86
- console.error(`Failed to start ${packageName}: ${error.message}`);
87
- await cleanup();
88
- exitProcess(1);
89
- });
90
-
91
- cli.on('exit', (code) => {
92
- exitProcess(code ?? 0);
93
- });
94
- } catch (error) {
95
- console.error(`Failed to start ${packageName}: ${error}`);
96
- exitProcess(1);
97
- }
98
-
99
- process.on('exit', () => {
100
- if (cli && !cli.killed) {
101
- try {
102
- cli.kill('SIGKILL');
103
- } catch (error) {
104
- // ignore
105
- }
106
- }
107
- });
108
-
109
- export { cli };