@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.
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 +43 -36
  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/bin/update.js DELETED
@@ -1,65 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { jsx as _jsx } from "react/jsx-runtime";
11
- import { SpinnerLog, SuccessLog, ErrorLog, addLog, addErrorLog, clearLogs, getLatestClientVersion, downloadTargetMint, getClientVersion, } from '@mintlify/previewing';
12
- import { assertValidPackageName, execFileAsync, getLatestCliVersion, getVersions, detectPackageManager, windowsCompatibleSpawnOptions, } from './helpers.js';
13
- export const update = (_a) => __awaiter(void 0, [_a], void 0, function* ({ packageName }) {
14
- assertValidPackageName(packageName);
15
- addLog(_jsx(SpinnerLog, { message: "updating..." }));
16
- const { cli: existingCliVersion } = getVersions(packageName);
17
- const latestCliVersion = getLatestCliVersion(packageName);
18
- const isUpToDate = existingCliVersion && latestCliVersion && latestCliVersion.trim() === existingCliVersion.trim();
19
- if (!isUpToDate && existingCliVersion && latestCliVersion.trim() !== existingCliVersion.trim()) {
20
- const packageManager = yield detectPackageManager({ packageName });
21
- try {
22
- clearLogs();
23
- addLog(_jsx(SpinnerLog, { message: `updating ${packageName} package...` }));
24
- if (packageManager === 'pnpm') {
25
- yield execFileAsync('pnpm', ['install', '-g', `${packageName}@latest`, '--silent'], windowsCompatibleSpawnOptions);
26
- }
27
- else {
28
- yield execFileAsync('npm', ['install', '-g', `${packageName}@latest`, '--silent'], windowsCompatibleSpawnOptions);
29
- }
30
- }
31
- catch (err) {
32
- const errorMessage = err instanceof Error ? err.message : String(err);
33
- addErrorLog(_jsx(ErrorLog, { message: `Failed to update ${packageName}@${latestCliVersion} using ${packageManager}: ${errorMessage}` }));
34
- return;
35
- }
36
- }
37
- clearLogs();
38
- addLog(_jsx(SpinnerLog, { message: "updating client..." }));
39
- let clientUpdated = false;
40
- const latestClientVersion = yield getLatestClientVersion();
41
- if (latestClientVersion) {
42
- const existingClientVersion = getClientVersion().trim();
43
- if (existingClientVersion !== latestClientVersion.trim()) {
44
- try {
45
- yield downloadTargetMint({
46
- targetVersion: latestClientVersion,
47
- existingVersion: existingClientVersion === 'none' ? null : existingClientVersion,
48
- });
49
- clientUpdated = true;
50
- }
51
- catch (err) {
52
- const errorMessage = err instanceof Error ? err.message : String(err);
53
- addErrorLog(_jsx(ErrorLog, { message: `Failed to update client: ${errorMessage}` }));
54
- return;
55
- }
56
- }
57
- }
58
- clearLogs();
59
- if (isUpToDate && !clientUpdated) {
60
- addLog(_jsx(SuccessLog, { message: "already up to date" }));
61
- }
62
- else {
63
- addLog(_jsx(SuccessLog, { message: `updated ${packageName} to the latest version: ${latestCliVersion}` }));
64
- }
65
- });
@@ -1,127 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __rest = (this && this.__rest) || function (s, e) {
11
- var t = {};
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
- t[p] = s[p];
14
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
- t[p[i]] = s[p[i]];
18
- }
19
- return t;
20
- };
21
- import { jsx as _jsx } from "react/jsx-runtime";
22
- import { addLog, checkBuild, clearLogs, ErrorLog, SpinnerLog } from '@mintlify/previewing';
23
- import path from 'node:path';
24
- import { format } from 'node:util';
25
- import { CMD_EXEC_PATH, errorMessage, getVersions, terminate } from '../helpers.js';
26
- import { resolveExplicitFiles } from '../resolveFiles.js';
27
- import { sendPublishPrompt } from '../signup.js';
28
- import { checkSite, runBuildChecks, selectRules } from './engine.js';
29
- import { logReport } from './output.js';
30
- import { toReport } from './report.js';
31
- export const EXIT = { passed: 0, failed: 1, crashed: 2 };
32
- export const splitList = (values) => values.flatMap((value) => value
33
- .split(',')
34
- .map((item) => item.trim())
35
- .filter(Boolean));
36
- const write = (text) => new Promise((resolve) => {
37
- process.stdout.write(text, () => resolve());
38
- });
39
- /**
40
- * Writes console output straight to stderr, so --format json leaves stdout to the report. Ink
41
- * patches console and redraws on stdout, so redirecting to console.error isn't enough.
42
- */
43
- const consoleToStderr = () => {
44
- const original = {
45
- log: console.log,
46
- info: console.info,
47
- warn: console.warn,
48
- error: console.error,
49
- };
50
- const toStderr = (...args) => {
51
- process.stderr.write(`${format(...args)}\n`);
52
- };
53
- console.log = console.info = console.warn = console.error = toStderr;
54
- return () => Object.assign(console, original);
55
- };
56
- const resolveSelection = (baseDir, values) => __awaiter(void 0, void 0, void 0, function* () {
57
- const args = (values !== null && values !== void 0 ? values : []).map(String).filter(Boolean);
58
- if (args.length === 0)
59
- return undefined;
60
- const files = yield resolveExplicitFiles(CMD_EXEC_PATH, args);
61
- return new Set(files.map((file) => path.relative(baseDir, path.resolve(CMD_EXEC_PATH, file)).split(path.sep).join('/')));
62
- });
63
- /** mint validate: one pass over every selected rule, then the strict build when nothing failed. */
64
- export const validateHandler = (argv_1, packageName_1, ...args_1) => __awaiter(void 0, [argv_1, packageName_1, ...args_1], void 0, function* (argv, packageName, baseDir = CMD_EXEC_PATH) {
65
- var _a;
66
- const json = argv.format === 'json';
67
- const restoreConsole = json ? consoleToStderr() : undefined;
68
- try {
69
- const rules = selectRules({
70
- enable: argv.enable,
71
- disable: (_a = argv.disable) !== null && _a !== void 0 ? _a : [],
72
- });
73
- const selected = yield resolveSelection(baseDir, argv.files);
74
- if (!json)
75
- addLog(_jsx(SpinnerLog, { message: "validating..." }));
76
- const _b = yield checkSite(baseDir, rules, {
77
- selected,
78
- localSchema: argv['local-schema'],
79
- fix: argv.fix,
80
- }), { site, fixed } = _b, checked = __rest(_b, ["site", "fixed"]);
81
- let { diagnostics } = checked;
82
- const buildRules = rules.some(({ needsBuild }) => needsBuild);
83
- let build;
84
- if (!argv.build) {
85
- build = { ran: false, reason: 'disabled' };
86
- }
87
- else if (!buildRules) {
88
- build = { ran: false, reason: 'no build rules' };
89
- }
90
- else if (diagnostics.some(({ severity }) => severity === 'error')) {
91
- build = { ran: false, reason: 'errors found' };
92
- }
93
- else {
94
- if (!json)
95
- addLog(_jsx(SpinnerLog, { message: "building..." }));
96
- const { cli: cliVersion } = getVersions(packageName);
97
- site.build = yield checkBuild(Object.assign(Object.assign({}, argv), { _: [], $0: packageName, packageName,
98
- cliVersion, disableOpenapi: !rules.some(({ group }) => group === 'openapi') }));
99
- diagnostics = yield runBuildChecks(site, rules, diagnostics);
100
- build = { ran: true, passed: site.build.passed };
101
- }
102
- const report = toReport(diagnostics, build, argv.fix ? fixed : undefined);
103
- if (json) {
104
- restoreConsole === null || restoreConsole === void 0 ? void 0 : restoreConsole();
105
- yield write(`${JSON.stringify(report)}\n`);
106
- }
107
- else {
108
- clearLogs();
109
- logReport(report);
110
- if (report.passed && build.ran && build.passed)
111
- yield sendPublishPrompt();
112
- }
113
- yield terminate(report.passed ? EXIT.passed : EXIT.failed);
114
- }
115
- catch (error) {
116
- // Bad arguments and crashes alike mean validate could not run
117
- if (json) {
118
- restoreConsole === null || restoreConsole === void 0 ? void 0 : restoreConsole();
119
- process.stderr.write(`Error: ${errorMessage(error)}\n`);
120
- }
121
- else {
122
- clearLogs();
123
- addLog(_jsx(ErrorLog, { message: errorMessage(error) }));
124
- }
125
- yield terminate(EXIT.crashed);
126
- }
127
- });
@@ -1,154 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { replaceVariables } from '@mintlify/common';
11
- import fs from 'node:fs/promises';
12
- import path from 'node:path';
13
- import { checkFiles, parseFile } from './files.js';
14
- import { applyEdits, selectEdits, toPosition } from './mdx.js';
15
- import { buildFindings } from './rules/build.js';
16
- import { RULES } from './rules/index.js';
17
- import { PARSE_ERROR } from './rules/parseError.js';
18
- import { loadSite } from './site.js';
19
- import { GROUPS, } from './types.js';
20
- export class UsageError extends Error {
21
- }
22
- const ruleList = () => RULES.map(({ id }) => id).join(', ');
23
- const matchToken = (token) => {
24
- if (token === 'all')
25
- return RULES;
26
- const rule = RULES.find(({ id }) => id === token);
27
- if (rule)
28
- return [rule];
29
- if (GROUPS.includes(token)) {
30
- return RULES.filter(({ group }) => group === token);
31
- }
32
- throw new UsageError(`unknown rule or group "${token}". Groups: all, ${GROUPS.join(', ')}. Rules: ${ruleList()}`);
33
- };
34
- /** Every rule, minus --disable, plus --enable. parse-error is the engine's own, not selectable. */
35
- export const selectRules = ({ enable = [], disable = [], }) => {
36
- if ([...disable, ...enable].includes(PARSE_ERROR.id)) {
37
- throw new UsageError(`${PARSE_ERROR.id} always runs and can't be disabled`);
38
- }
39
- const selected = new Set(RULES);
40
- for (const token of disable)
41
- for (const rule of matchToken(token))
42
- selected.delete(rule);
43
- for (const token of enable)
44
- for (const rule of matchToken(token))
45
- selected.add(rule);
46
- return RULES.filter((rule) => selected.has(rule));
47
- };
48
- const toDiagnostic = (source, finding) => {
49
- var _a;
50
- return (Object.assign(Object.assign({}, finding), { rule: source.id, group: source.group, severity: (_a = finding.severity) !== null && _a !== void 0 ? _a : source.severity }));
51
- };
52
- const RULE_ORDER = new Map(RULES.map(({ id }, index) => [id, index]));
53
- const sortDiagnostics = (diagnostics) => diagnostics.sort((a, b) => {
54
- var _a, _b, _c, _d, _e, _f;
55
- return (a.file < b.file ? -1 : a.file > b.file ? 1 : 0) ||
56
- ((_a = a.line) !== null && _a !== void 0 ? _a : 0) - ((_b = b.line) !== null && _b !== void 0 ? _b : 0) ||
57
- ((_c = a.column) !== null && _c !== void 0 ? _c : 0) - ((_d = b.column) !== null && _d !== void 0 ? _d : 0) ||
58
- ((_e = RULE_ORDER.get(a.rule)) !== null && _e !== void 0 ? _e : 0) - ((_f = RULE_ORDER.get(b.rule)) !== null && _f !== void 0 ? _f : 0);
59
- });
60
- /** Adds findings for a rule unless a diagnostic of that rule already has the same key. */
61
- const merge = (diagnostics, source, extra, key) => {
62
- const reported = new Set(diagnostics.filter((item) => item.rule === source.id).map(key));
63
- for (const finding of extra) {
64
- if (reported.has(key(finding)))
65
- continue;
66
- reported.add(key(finding));
67
- diagnostics.push(toDiagnostic(source, finding));
68
- }
69
- };
70
- const addParseErrors = (site, diagnostics, extra) => merge(diagnostics, PARSE_ERROR, extra.filter(({ file }) => !site.selected || site.selected.has(file)), ({ file }) => file);
71
- const fileRulesOf = (rules) => rules.filter((rule) => rule.scope === 'file');
72
- const runSiteRules = (site, rules, needsBuild, diagnostics) => __awaiter(void 0, void 0, void 0, function* () {
73
- for (const rule of rules) {
74
- if (rule.scope !== 'site' || Boolean(rule.needsBuild) !== needsBuild)
75
- continue;
76
- for (const finding of yield rule.check(site))
77
- diagnostics.push(toDiagnostic(rule, finding));
78
- }
79
- });
80
- /** Runs every selected rule that doesn't need the build. */
81
- export const runChecks = (site, rules) => __awaiter(void 0, void 0, void 0, function* () {
82
- const diagnostics = yield checkFiles(site, fileRulesOf(rules));
83
- yield runSiteRules(site, rules, false, diagnostics);
84
- return sortDiagnostics(diagnostics);
85
- });
86
- /** Adds the build's findings to a site whose build has run. */
87
- export const runBuildChecks = (site, rules, diagnostics) => __awaiter(void 0, void 0, void 0, function* () {
88
- yield runSiteRules(site, rules, true, diagnostics);
89
- // The file pass already reported files it couldn't parse; the build adds the rest
90
- addParseErrors(site, diagnostics, buildFindings(site, 'parse-error'));
91
- return sortDiagnostics(diagnostics);
92
- });
93
- const parseLevel = (file, content, baseDir) => {
94
- const parsed = parseFile(file, content, baseDir);
95
- return 'error' in parsed ? 0 : parsed.approximate ? 1 : 2;
96
- };
97
- /** Applies every fix that doesn't overlap an earlier fix in the same file, writing each Markdown file only when its fixed content parses at least as well as before. */
98
- export const applyFixes = (site, diagnostics) => __awaiter(void 0, void 0, void 0, function* () {
99
- var _a;
100
- const read = (file) => { var _a; return (_a = site.read(file)) !== null && _a !== void 0 ? _a : ''; };
101
- const chosen = new Map();
102
- const overlaps = ({ file, start, end }) => { var _a; return ((_a = chosen.get(file)) !== null && _a !== void 0 ? _a : []).some(({ fix }) => start < fix.end && fix.start < end); };
103
- for (const { rule, fix } of diagnostics) {
104
- if (!fix || overlaps(fix))
105
- continue;
106
- const content = read(fix.file);
107
- const change = Object.assign(Object.assign({ rule, file: fix.file }, toPosition(content, fix.start)), { before: content.slice(fix.start, fix.end), after: fix.text });
108
- chosen.set(fix.file, [...((_a = chosen.get(fix.file)) !== null && _a !== void 0 ? _a : []), { fix, change }]);
109
- }
110
- const snippets = new Set(site.files.filter(({ kind }) => kind === 'snippet').map(({ file }) => file));
111
- const level = (file, content) => parseLevel(file, snippets.has(file) ? replaceVariables(content, site.variables) : content, site.baseDir);
112
- const applied = [];
113
- for (const [file, picks] of chosen) {
114
- const content = read(file);
115
- const updated = applyEdits(content, selectEdits(picks.map(({ fix }) => fix)));
116
- if (/\.mdx?$/.test(file) && level(file, updated) < level(file, content)) {
117
- continue;
118
- }
119
- yield fs.writeFile(path.join(site.baseDir, file), updated);
120
- applied.push(...picks.map(({ change }) => change));
121
- }
122
- return applied;
123
- });
124
- // Fixes can unlock others (a self-closed <br> lets a page parse), so --fix runs a few passes
125
- const MAX_FIX_PASSES = 5;
126
- /**
127
- * Loads the site and runs the selected rules. With fix, applies the fixes, rechecks only the
128
- * files that changed for further fixes, then runs every rule once more for the final report.
129
- */
130
- export const checkSite = (baseDir, rules, options) => __awaiter(void 0, void 0, void 0, function* () {
131
- const fixed = [];
132
- let site = yield loadSite(baseDir, options);
133
- const { selected } = options;
134
- if (selected && !site.files.some(({ file }) => selected.has(file))) {
135
- throw new UsageError(`none of the given files are pages or snippets of this site: ${[...selected].join(', ')}`);
136
- }
137
- const diagnostics = yield runChecks(site, rules);
138
- if (!options.fix)
139
- return { site, diagnostics, fixed };
140
- // Only file rules offer fixes, so passes after the first recheck just the files that changed
141
- let pending = diagnostics;
142
- for (let pass = 0; pass < MAX_FIX_PASSES; pass++) {
143
- const changes = yield applyFixes(site, pending);
144
- if (changes.length === 0)
145
- break;
146
- fixed.push(...changes);
147
- site = yield loadSite(baseDir, options);
148
- const changed = new Set(changes.map(({ file }) => file));
149
- pending = sortDiagnostics(yield checkFiles(Object.assign(Object.assign({}, site), { selected: changed }), fileRulesOf(rules)));
150
- }
151
- if (fixed.length === 0)
152
- return { site, diagnostics, fixed };
153
- return { site, diagnostics: yield runChecks(site, rules), fixed };
154
- });
@@ -1,163 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __rest = (this && this.__rest) || function (s, e) {
11
- var t = {};
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
- t[p] = s[p];
14
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
- t[p[i]] = s[p[i]];
18
- }
19
- return t;
20
- };
21
- import { getAST, getFileCategory, parseFrontmatter, replaceVariables } from '@mintlify/common';
22
- import { categorizeMdxFiles, getErrorPosition, getMintIgnore, listContentFiles, } from '@mintlify/prebuild';
23
- import { applyEdits, collectAnchorLinks, parseContent, relocate, selectEdits, toOffset, unmapEdit, } from './mdx.js';
24
- import { PARSE_ERROR } from './rules/parseError.js';
25
- const CHECKED_CATEGORIES = new Set(['page', 'snippet', 'snippet-v2']);
26
- export const readSiteFiles = (baseDir) => __awaiter(void 0, void 0, void 0, function* () {
27
- const { mdxCandidates: candidates } = yield listContentFiles(baseDir, yield getMintIgnore(baseDir));
28
- const { snippets, snippetsV2 } = yield categorizeMdxFiles(baseDir, candidates);
29
- const snippetFiles = new Set([...snippets, ...snippetsV2]);
30
- return candidates
31
- .filter((name) => /\.mdx?$/.test(name) && CHECKED_CATEGORIES.has(getFileCategory(name)))
32
- .map((name) => ({
33
- file: name.replace(/^\//, ''),
34
- kind: (snippetFiles.has(name) ? 'snippet' : 'page'),
35
- }));
36
- });
37
- const readFrontmatter = (content) => {
38
- try {
39
- const { attributes } = parseFrontmatter(content);
40
- return attributes && typeof attributes === 'object' ? Object.assign({}, attributes) : {};
41
- }
42
- catch (_a) {
43
- return {};
44
- }
45
- };
46
- const REASON_POSITION = /\s*\(\d+:\d+(?:-\d+:\d+)?\)$/;
47
- const TAG_NAME_RULES = new Set(['unexpected-character', 'unexpected-eof']);
48
- const ESCAPE_HINT = "; if this < isn't a tag, escape it as \\<";
49
- const isStrayLessThan = (error, content, position) => {
50
- const { source, ruleId } = (error !== null && error !== void 0 ? error : {});
51
- return (source === 'micromark-extension-mdx-jsx' &&
52
- typeof ruleId === 'string' &&
53
- TAG_NAME_RULES.has(ruleId) &&
54
- (position === null || position === void 0 ? void 0 : position.line) != null &&
55
- position.column != null &&
56
- content[toOffset(content, position.line, position.column) - 1] === '<');
57
- };
58
- export const toParseError = (error, content = '') => {
59
- const reason = error === null || error === void 0 ? void 0 : error.reason;
60
- const fallback = error instanceof Error ? error.message : 'could not parse this file';
61
- const text = typeof reason === 'string' ? reason : fallback;
62
- const position = error && typeof error === 'object' ? getErrorPosition(error) : null;
63
- const hint = isStrayLessThan(error, content, position) ? ESCAPE_HINT : '';
64
- return Object.assign(Object.assign(Object.assign({}, ((position === null || position === void 0 ? void 0 : position.line) != null && { line: position.line })), ((position === null || position === void 0 ? void 0 : position.column) != null && { column: position.column })), { message: text.replace(REASON_POSITION, '') + hint });
65
- };
66
- const parseErrorDiagnostic = (file, error) => (Object.assign(Object.assign({}, error), { rule: PARSE_ERROR.id, group: PARSE_ERROR.group, severity: PARSE_ERROR.severity, file, message: `${error.message} (other checks were skipped for this file)` }));
67
- const tryParseContent = (content) => {
68
- try {
69
- return parseContent(content);
70
- }
71
- catch (_a) {
72
- return undefined;
73
- }
74
- };
75
- export const parseFile = (file, content, baseDir, extras = {}) => {
76
- const context = Object.assign({ file, content, baseDir, frontmatter: readFrontmatter(content) }, extras);
77
- const tree = tryParseContent(content);
78
- if (tree)
79
- return { context: Object.assign(Object.assign({}, context), { tree }), approximate: false };
80
- try {
81
- return { context: Object.assign(Object.assign({}, context), { tree: getAST(content, file) }), approximate: true };
82
- }
83
- catch (error) {
84
- return { error: toParseError(error, content) };
85
- }
86
- };
87
- const EMPTY_TREE = { type: 'root', children: [] };
88
- const SOURCE_STAGE = 1;
89
- const AFTER_RAW_STAGE = 2;
90
- const VARIABLE = /\{\{\s*([\w.\-]+)\s*\}\}/g;
91
- const variableEdits = (content, variables = {}) => [...content.matchAll(VARIABLE)]
92
- .filter((match) => match[1] !== undefined && variables[match[1]] !== undefined)
93
- .map((match) => ({
94
- start: match.index,
95
- end: match.index + match[0].length,
96
- text: replaceVariables(match[0], variables),
97
- }));
98
- const toDiagnostic = (rule, file, _a, stages, stage) => {
99
- var { edit } = _a, finding = __rest(_a, ["edit"]);
100
- const original = edit && unmapEdit(stages, stage, edit);
101
- return Object.assign(Object.assign(Object.assign(Object.assign({}, finding), relocate(stages, stage, finding)), { rule: rule.id, group: rule.group, severity: rule.severity, file }), (original && { fix: Object.assign({ file }, original) }));
102
- };
103
- const checkFile = (allRules, { file, kind }, content, baseDir, extras, variables) => {
104
- const rules = kind === 'snippet' ? allRules.filter((rule) => !rule.pagesOnly) : allRules;
105
- const raw = rules.filter((rule) => rule.raw);
106
- const treeRules = rules.filter((rule) => !rule.raw);
107
- const varEdits = kind === 'snippet' ? variableEdits(content, variables) : [];
108
- const source = applyEdits(content, varEdits);
109
- const rawContext = {
110
- file,
111
- content: source,
112
- baseDir,
113
- frontmatter: {},
114
- tree: EMPTY_TREE,
115
- variables,
116
- };
117
- const rawFound = raw.flatMap((rule) => rule.check(rawContext).map((finding) => ({ rule, finding })));
118
- const rawEdits = selectEdits(rawFound.flatMap(({ finding }) => (finding.edit ? [finding.edit] : [])));
119
- const afterRaw = applyEdits(source, rawEdits);
120
- const stages = [
121
- { content, edits: varEdits },
122
- { content: source, edits: rawEdits },
123
- { content: afterRaw, edits: [] },
124
- ];
125
- const diagnostics = rawFound.map(({ rule, finding }) => toDiagnostic(rule, file, finding, stages, SOURCE_STAGE));
126
- const parsed = parseFile(file, afterRaw, baseDir, Object.assign(Object.assign({}, extras), { variables }));
127
- if ('error' in parsed) {
128
- diagnostics.unshift(parseErrorDiagnostic(file, Object.assign(Object.assign({}, parsed.error), relocate(stages, AFTER_RAW_STAGE, parsed.error))));
129
- return diagnostics;
130
- }
131
- for (const rule of treeRules) {
132
- for (const finding of rule.check(parsed.context)) {
133
- const found = parsed.approximate ? Object.assign(Object.assign({}, finding), { edit: undefined }) : finding;
134
- diagnostics.push(toDiagnostic(rule, file, found, stages, AFTER_RAW_STAGE));
135
- }
136
- }
137
- return diagnostics;
138
- };
139
- const collectSiteAnchorLinks = (site) => __awaiter(void 0, void 0, void 0, function* () {
140
- const pages = yield Promise.all(site.files.map(({ file }) => { var _a; return collectAnchorLinks(file, (_a = site.read(file)) !== null && _a !== void 0 ? _a : ''); }));
141
- return new Set(pages.flat());
142
- });
143
- export const checkFiles = (site, rules) => __awaiter(void 0, void 0, void 0, function* () {
144
- const anchorRules = new Set(rules.filter((rule) => rule.needsAnchorLinks).map(({ id }) => id));
145
- const targets = site.files.filter(({ file }) => !site.selected || site.selected.has(file));
146
- const checkTarget = (entry, extras) => {
147
- const content = site.read(entry.file);
148
- if (content === undefined) {
149
- return [parseErrorDiagnostic(entry.file, { message: 'could not read this file' })];
150
- }
151
- return checkFile(rules, entry, content, site.baseDir, extras, site.variables);
152
- };
153
- const needsLinks = (diagnostics) => diagnostics.some(({ rule }) => anchorRules.has(rule));
154
- const checked = targets.map((entry) => checkTarget(entry, { readFile: site.read }));
155
- if (!checked.some(needsLinks))
156
- return checked.flat();
157
- const extras = { readFile: site.read, anchorLinks: yield collectSiteAnchorLinks(site) };
158
- return targets.flatMap((entry, index) => {
159
- var _a;
160
- const diagnostics = (_a = checked[index]) !== null && _a !== void 0 ? _a : [];
161
- return needsLinks(diagnostics) ? checkTarget(entry, extras) : diagnostics;
162
- });
163
- });