@mintlify/cli 4.0.626 → 4.0.628

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.626",
3
+ "version": "4.0.628",
4
4
  "description": "The Mintlify CLI",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@mintlify/common": "1.0.453",
43
- "@mintlify/link-rot": "3.0.576",
43
+ "@mintlify/link-rot": "3.0.577",
44
44
  "@mintlify/models": "0.0.207",
45
45
  "@mintlify/prebuild": "1.0.571",
46
46
  "@mintlify/previewing": "4.0.615",
@@ -73,5 +73,5 @@
73
73
  "vitest": "^2.0.4",
74
74
  "vitest-mock-process": "^1.0.4"
75
75
  },
76
- "gitHead": "1ebf8ca521c8d533c648a5bd44a8a3c4b69df832"
76
+ "gitHead": "289495d2fd9b588b475da6c8ca46f7b709cc0be2"
77
77
  }
package/src/cli.tsx CHANGED
@@ -32,11 +32,12 @@ import {
32
32
  } from './helpers.js';
33
33
  import { update } from './update.js';
34
34
 
35
- export const cli = () => {
35
+ export const cli = ({ packageName = 'mint' }: { packageName?: string }) => {
36
36
  render(<Logs />);
37
37
 
38
38
  return (
39
39
  yargs(hideBin(process.argv))
40
+ .scriptName(packageName)
40
41
  .middleware(checkNodeVersion)
41
42
  .middleware(suppressConsoleWarnings)
42
43
  .command(
@@ -71,7 +72,6 @@ export const cli = () => {
71
72
  .example('mintlify dev --no-open', 'run without opening in browser'),
72
73
  async (argv) => {
73
74
  const port = await checkPort(argv);
74
- const packageName = process.argv[1]?.split('/').pop() ?? 'mintlify';
75
75
  const cliVersion = getCliVersion();
76
76
  if (
77
77
  cliVersion &&
@@ -222,7 +222,6 @@ export const cli = () => {
222
222
  'update the CLI to the latest version',
223
223
  () => undefined,
224
224
  async () => {
225
- const packageName = process.argv[1]?.split('/').pop() ?? 'mintlify';
226
225
  await update({ packageName });
227
226
  await terminate(0);
228
227
  }
package/src/index.ts CHANGED
@@ -1,5 +1,106 @@
1
1
  #!/usr/bin/env node
2
- import { cli } from './cli.js';
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 = process.argv[1]?.split('/').pop() ?? 'mint';
10
+
11
+ let cli: ChildProcess | null = null;
12
+ let isShuttingDown = false;
13
+ let hasExited = false;
14
+
15
+ const cleanup = async (): Promise<void> => {
16
+ if (isShuttingDown) return;
17
+ isShuttingDown = true;
18
+
19
+ if (cli && !cli.killed) {
20
+ try {
21
+ cli.kill('SIGTERM');
22
+
23
+ await new Promise<void>((resolve) => {
24
+ const timeout = setTimeout(() => {
25
+ if (cli && !cli.killed) {
26
+ cli.kill('SIGKILL');
27
+ }
28
+ resolve();
29
+ }, 5000);
30
+
31
+ cli!.once('exit', () => {
32
+ clearTimeout(timeout);
33
+ resolve();
34
+ });
35
+ });
36
+ } catch (error) {
37
+ // ignore
38
+ }
39
+ }
40
+ };
41
+
42
+ const exitProcess = (code: number) => {
43
+ if (hasExited) return;
44
+ hasExited = true;
45
+ process.exit(code);
46
+ };
47
+
48
+ const killSignals = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP'];
49
+ killSignals.forEach((signal) => {
50
+ process.on(signal, async () => {
51
+ await cleanup();
52
+ exitProcess(0);
53
+ });
54
+ });
55
+
56
+ process.on('uncaughtException', async () => {
57
+ await cleanup();
58
+ exitProcess(1);
59
+ });
60
+
61
+ process.on('unhandledRejection', async () => {
62
+ await cleanup();
63
+ exitProcess(1);
64
+ });
65
+
66
+ try {
67
+ cli = spawn(
68
+ 'node',
69
+ ['--no-deprecation', path.join(__dirname, '../bin/start.js'), ...process.argv.slice(2)],
70
+ {
71
+ stdio: 'inherit',
72
+ env: {
73
+ ...process.env,
74
+ MINTLIFY_PACKAGE_NAME: packageName,
75
+ },
76
+ shell: process.platform === 'win32',
77
+ windowsHide: process.platform === 'win32',
78
+ detached: false,
79
+ }
80
+ );
81
+
82
+ cli.on('error', async (error) => {
83
+ console.error(`Failed to start ${packageName}: ${error.message}`);
84
+ await cleanup();
85
+ exitProcess(1);
86
+ });
87
+
88
+ cli.on('exit', (code) => {
89
+ exitProcess(code ?? 0);
90
+ });
91
+ } catch (error) {
92
+ console.error(`Failed to start ${packageName}: ${error}`);
93
+ exitProcess(1);
94
+ }
95
+
96
+ process.on('exit', () => {
97
+ if (cli && !cli.killed) {
98
+ try {
99
+ cli.kill('SIGKILL');
100
+ } catch (error) {
101
+ // ignore
102
+ }
103
+ }
104
+ });
3
105
 
4
106
  export { cli };
5
- void cli();
package/src/start.ts ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { cli } from './cli.js';
3
+
4
+ const packageName = process.env.MINTLIFY_PACKAGE_NAME ?? 'mint';
5
+
6
+ void cli({ packageName });