@mintlify/cli 4.0.1333 → 4.0.1335

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/bin/cli.js CHANGED
@@ -21,6 +21,7 @@ import { setTelemetryEnabled } from './config.js';
21
21
  import { getConfigValue, setConfigValue, clearConfigValue } from './config.js';
22
22
  import { API_URL } from './constants.js';
23
23
  import { deslopHandler } from './deslop/index.js';
24
+ import { formatHandler } from './format.js';
24
25
  import { CMD_EXEC_PATH, checkPort, checkNodeVersion, autoUpgradeIfNeeded, getVersions, isAI, suppressConsoleWarnings, terminate, } from './helpers.js';
25
26
  import { init } from './init.js';
26
27
  import { getAccessToken } from './keyring.js';
@@ -522,6 +523,7 @@ export const cli = ({ packageName = 'mint' }) => {
522
523
  .example('mint deslop', 'Check git-changed pages for AI-sounding prose')
523
524
  .example('mint deslop docs/guide.mdx', 'Check a specific page')
524
525
  .example('mint deslop "docs/**/*.mdx" --format json', 'Check pages by glob with agent-friendly JSON output'), deslopHandler)
526
+ .command('format', false, () => undefined, formatHandler)
525
527
  // Coming soon commands — visible in help, tracked via telemetry to gauge interest.
526
528
  .command('ai', '[Coming soon] AI-powered documentation (run mint ai to vote)', () => undefined, comingSoon('ai', packageName))
527
529
  .command('test', '[Coming soon] Test your documentation (run mint test to vote)', () => undefined, comingSoon('test', packageName))
package/bin/format.js ADDED
@@ -0,0 +1,110 @@
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 __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
11
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
12
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
+ var m = o[Symbol.asyncIterator], i;
14
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
+ };
18
+ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
19
+ var i, p;
20
+ return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
21
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
22
+ };
23
+ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
24
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
25
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
26
+ return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
27
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
28
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
29
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
30
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
31
+ function fulfill(value) { resume("next", value); }
32
+ function reject(value) { resume("throw", value); }
33
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
34
+ };
35
+ import { jsx as _jsx } from "react/jsx-runtime";
36
+ import { isMintIgnored, processMintIgnoreString } from '@mintlify/common';
37
+ import { mdxToPm, pmToMdx } from '@mintlify/editor/converter';
38
+ import { getMintIgnore } from '@mintlify/prebuild';
39
+ import { addLog, ErrorLog, SuccessLog } from '@mintlify/previewing';
40
+ import fs from 'node:fs/promises';
41
+ import path from 'node:path';
42
+ import { CMD_EXEC_PATH, terminate } from './helpers.js';
43
+ function getGitIgnore() {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ try {
46
+ const content = yield fs.readFile(path.join(CMD_EXEC_PATH, '.gitignore'), 'utf-8');
47
+ return processMintIgnoreString(content);
48
+ }
49
+ catch (_a) {
50
+ return [];
51
+ }
52
+ });
53
+ }
54
+ function walk(dir, ignores) {
55
+ return __asyncGenerator(this, arguments, function* walk_1() {
56
+ const entries = yield __await(fs.readdir(dir, { withFileTypes: true }));
57
+ for (const entry of entries) {
58
+ const full = path.join(dir, entry.name);
59
+ const relative = path.relative(CMD_EXEC_PATH, full).split(path.sep).join('/');
60
+ if (entry.isDirectory()) {
61
+ if (isMintIgnored(`${relative}/`, ignores))
62
+ continue;
63
+ yield __await(yield* __asyncDelegator(__asyncValues(walk(full, ignores))));
64
+ }
65
+ else if (entry.name.endsWith('.mdx')) {
66
+ if (isMintIgnored(relative, ignores))
67
+ continue;
68
+ yield yield __await(full);
69
+ }
70
+ }
71
+ });
72
+ }
73
+ export const formatHandler = () => __awaiter(void 0, void 0, void 0, function* () {
74
+ var _a, e_1, _b, _c;
75
+ const ignores = [...(yield getGitIgnore()), ...(yield getMintIgnore(CMD_EXEC_PATH))];
76
+ let total = 0;
77
+ let changed = 0;
78
+ let failed = 0;
79
+ try {
80
+ for (var _d = true, _e = __asyncValues(walk(CMD_EXEC_PATH, ignores)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
81
+ _c = _f.value;
82
+ _d = false;
83
+ const file = _c;
84
+ total++;
85
+ const relative = path.relative(CMD_EXEC_PATH, file);
86
+ try {
87
+ const raw = yield fs.readFile(file, 'utf-8');
88
+ const { doc, frontmatter } = mdxToPm(raw);
89
+ const formatted = `${pmToMdx(doc, { frontmatter })}\n`;
90
+ if (formatted !== raw) {
91
+ yield fs.writeFile(file, formatted);
92
+ changed++;
93
+ }
94
+ }
95
+ catch (error) {
96
+ failed++;
97
+ addLog(_jsx(ErrorLog, { message: `${relative}: ${error instanceof Error ? error.message : 'unknown error'}` }));
98
+ }
99
+ }
100
+ }
101
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
102
+ finally {
103
+ try {
104
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
105
+ }
106
+ finally { if (e_1) throw e_1.error; }
107
+ }
108
+ addLog(_jsx(SuccessLog, { message: `formatted ${changed} of ${total} mdx file${total === 1 ? '' : 's'}${failed > 0 ? ` (${failed} failed)` : ''}` }));
109
+ yield terminate(failed > 0 ? 1 : 0);
110
+ });