@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintlify/cli",
3
- "version": "4.0.1333",
3
+ "version": "4.0.1335",
4
4
  "description": "The Mintlify CLI",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -45,12 +45,13 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@inquirer/prompts": "7.9.0",
48
- "@mintlify/common": "1.0.1039",
49
- "@mintlify/link-rot": "3.0.1231",
50
- "@mintlify/models": "0.0.342",
51
- "@mintlify/prebuild": "1.0.1187",
52
- "@mintlify/previewing": "4.0.1256",
53
- "@mintlify/validation": "0.1.796",
48
+ "@mintlify/common": "1.0.1040",
49
+ "@mintlify/editor": "0.0.246",
50
+ "@mintlify/link-rot": "3.0.1232",
51
+ "@mintlify/models": "0.0.343",
52
+ "@mintlify/prebuild": "1.0.1188",
53
+ "@mintlify/previewing": "4.0.1257",
54
+ "@mintlify/validation": "0.1.797",
54
55
  "adm-zip": "0.5.16",
55
56
  "chalk": "5.2.0",
56
57
  "color": "4.2.3",
@@ -92,5 +93,5 @@
92
93
  "vitest": "2.1.9",
93
94
  "vitest-mock-process": "1.0.4"
94
95
  },
95
- "gitHead": "48ebadbb106c4c5969cd83c048e660bc39955f3f"
96
+ "gitHead": "60dbc26b00135e7d72e7728a661c64f569352f91"
96
97
  }
package/src/cli.tsx CHANGED
@@ -24,6 +24,7 @@ import { setTelemetryEnabled } from './config.js';
24
24
  import { getConfigValue, setConfigValue, clearConfigValue } from './config.js';
25
25
  import { API_URL } from './constants.js';
26
26
  import { deslopHandler } from './deslop/index.js';
27
+ import { formatHandler } from './format.js';
27
28
  import {
28
29
  CMD_EXEC_PATH,
29
30
  checkPort,
@@ -711,6 +712,7 @@ export const cli = ({ packageName = 'mint' }: { packageName?: string }) => {
711
712
  ),
712
713
  deslopHandler
713
714
  )
715
+ .command('format', false, () => undefined, formatHandler)
714
716
  // Coming soon commands — visible in help, tracked via telemetry to gauge interest.
715
717
  .command(
716
718
  'ai',
package/src/format.tsx ADDED
@@ -0,0 +1,67 @@
1
+ import { isMintIgnored, processMintIgnoreString } from '@mintlify/common';
2
+ import { mdxToPm, pmToMdx } from '@mintlify/editor/converter';
3
+ import { getMintIgnore } from '@mintlify/prebuild';
4
+ import { addLog, ErrorLog, SuccessLog } from '@mintlify/previewing';
5
+ import fs from 'node:fs/promises';
6
+ import path from 'node:path';
7
+
8
+ import { CMD_EXEC_PATH, terminate } from './helpers.js';
9
+
10
+ async function getGitIgnore(): Promise<string[]> {
11
+ try {
12
+ const content = await fs.readFile(path.join(CMD_EXEC_PATH, '.gitignore'), 'utf-8');
13
+ return processMintIgnoreString(content);
14
+ } catch {
15
+ return [];
16
+ }
17
+ }
18
+
19
+ async function* walk(dir: string, ignores: string[]): AsyncGenerator<string> {
20
+ const entries = await fs.readdir(dir, { withFileTypes: true });
21
+ for (const entry of entries) {
22
+ const full = path.join(dir, entry.name);
23
+ const relative = path.relative(CMD_EXEC_PATH, full).split(path.sep).join('/');
24
+ if (entry.isDirectory()) {
25
+ if (isMintIgnored(`${relative}/`, ignores)) continue;
26
+ yield* walk(full, ignores);
27
+ } else if (entry.name.endsWith('.mdx')) {
28
+ if (isMintIgnored(relative, ignores)) continue;
29
+ yield full;
30
+ }
31
+ }
32
+ }
33
+
34
+ export const formatHandler = async (): Promise<void> => {
35
+ const ignores = [...(await getGitIgnore()), ...(await getMintIgnore(CMD_EXEC_PATH))];
36
+ let total = 0;
37
+ let changed = 0;
38
+ let failed = 0;
39
+
40
+ for await (const file of walk(CMD_EXEC_PATH, ignores)) {
41
+ total++;
42
+ const relative = path.relative(CMD_EXEC_PATH, file);
43
+ try {
44
+ const raw = await fs.readFile(file, 'utf-8');
45
+ const { doc, frontmatter } = mdxToPm(raw);
46
+ const formatted = `${pmToMdx(doc, { frontmatter })}\n`;
47
+ if (formatted !== raw) {
48
+ await fs.writeFile(file, formatted);
49
+ changed++;
50
+ }
51
+ } catch (error) {
52
+ failed++;
53
+ addLog(
54
+ <ErrorLog
55
+ message={`${relative}: ${error instanceof Error ? error.message : 'unknown error'}`}
56
+ />
57
+ );
58
+ }
59
+ }
60
+
61
+ addLog(
62
+ <SuccessLog
63
+ message={`formatted ${changed} of ${total} mdx file${total === 1 ? '' : 's'}${failed > 0 ? ` (${failed} failed)` : ''}`}
64
+ />
65
+ );
66
+ await terminate(failed > 0 ? 1 : 0);
67
+ };