@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/__test__/utils.ts CHANGED
@@ -7,7 +7,7 @@ import { cli } from '../src/cli.js';
7
7
  */
8
8
  export async function runCommand(...args: string[]) {
9
9
  process.argv = ['node', 'cli.js', ...args];
10
- return cli();
10
+ return cli({ packageName: 'mint' });
11
11
  }
12
12
 
13
13
  export const mockValidOpenApiDocument = {
package/bin/cli.js CHANGED
@@ -19,9 +19,10 @@ import { hideBin } from 'yargs/helpers';
19
19
  import { LOCAL_LINKED_VERSION, MINIMUM_CLI_VERSION } from './constants.js';
20
20
  import { checkPort, checkForMintJson, checkNodeVersion, upgradeConfig, checkForDocsJson, getCliVersion, getVersions, suppressConsoleWarnings, terminate, readLocalOpenApiFile, } from './helpers.js';
21
21
  import { update } from './update.js';
22
- export const cli = () => {
22
+ export const cli = ({ packageName = 'mint' }) => {
23
23
  render(_jsx(Logs, {}));
24
24
  return (yargs(hideBin(process.argv))
25
+ .scriptName(packageName)
25
26
  .middleware(checkNodeVersion)
26
27
  .middleware(suppressConsoleWarnings)
27
28
  .command('dev', 'initialize a local preview environment', (yargs) => yargs
@@ -49,9 +50,7 @@ export const cli = () => {
49
50
  .usage('usage: mintlify dev [options]')
50
51
  .example('mintlify dev', 'run with default settings (opens in browser)')
51
52
  .example('mintlify dev --no-open', 'run without opening in browser'), (argv) => __awaiter(void 0, void 0, void 0, function* () {
52
- var _a, _b;
53
53
  const port = yield checkPort(argv);
54
- const packageName = (_b = (_a = process.argv[1]) === null || _a === void 0 ? void 0 : _a.split('/').pop()) !== null && _b !== void 0 ? _b : 'mintlify';
55
54
  const cliVersion = getCliVersion();
56
55
  if (cliVersion &&
57
56
  cliVersion !== LOCAL_LINKED_VERSION &&
@@ -164,8 +163,6 @@ export const cli = () => {
164
163
  yield terminate(0);
165
164
  }))
166
165
  .command('update', 'update the CLI to the latest version', () => undefined, () => __awaiter(void 0, void 0, void 0, function* () {
167
- var _a, _b;
168
- const packageName = (_b = (_a = process.argv[1]) === null || _a === void 0 ? void 0 : _a.split('/').pop()) !== null && _b !== void 0 ? _b : 'mintlify';
169
166
  yield update({ packageName });
170
167
  yield terminate(0);
171
168
  }))
package/bin/index.js CHANGED
@@ -1,4 +1,98 @@
1
1
  #!/usr/bin/env node
2
- import { cli } from './cli.js';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var _a, _b;
12
+ import { spawn } from 'child_process';
13
+ import path from 'path';
14
+ import { fileURLToPath } from 'url';
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = path.dirname(__filename);
17
+ const packageName = (_b = (_a = process.argv[1]) === null || _a === void 0 ? void 0 : _a.split('/').pop()) !== null && _b !== void 0 ? _b : 'mint';
18
+ let cli = null;
19
+ let isShuttingDown = false;
20
+ let hasExited = false;
21
+ const cleanup = () => __awaiter(void 0, void 0, void 0, function* () {
22
+ if (isShuttingDown)
23
+ return;
24
+ isShuttingDown = true;
25
+ if (cli && !cli.killed) {
26
+ try {
27
+ cli.kill('SIGTERM');
28
+ yield new Promise((resolve) => {
29
+ const timeout = setTimeout(() => {
30
+ if (cli && !cli.killed) {
31
+ cli.kill('SIGKILL');
32
+ }
33
+ resolve();
34
+ }, 5000);
35
+ cli.once('exit', () => {
36
+ clearTimeout(timeout);
37
+ resolve();
38
+ });
39
+ });
40
+ }
41
+ catch (error) {
42
+ // ignore
43
+ }
44
+ }
45
+ });
46
+ const exitProcess = (code) => {
47
+ if (hasExited)
48
+ return;
49
+ hasExited = true;
50
+ process.exit(code);
51
+ };
52
+ const killSignals = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP'];
53
+ killSignals.forEach((signal) => {
54
+ process.on(signal, () => __awaiter(void 0, void 0, void 0, function* () {
55
+ yield cleanup();
56
+ exitProcess(0);
57
+ }));
58
+ });
59
+ process.on('uncaughtException', () => __awaiter(void 0, void 0, void 0, function* () {
60
+ yield cleanup();
61
+ exitProcess(1);
62
+ }));
63
+ process.on('unhandledRejection', () => __awaiter(void 0, void 0, void 0, function* () {
64
+ yield cleanup();
65
+ exitProcess(1);
66
+ }));
67
+ try {
68
+ cli = spawn('node', ['--no-deprecation', path.join(__dirname, '../bin/start.js'), ...process.argv.slice(2)], {
69
+ stdio: 'inherit',
70
+ env: Object.assign(Object.assign({}, process.env), { MINTLIFY_PACKAGE_NAME: packageName }),
71
+ shell: process.platform === 'win32',
72
+ windowsHide: process.platform === 'win32',
73
+ detached: false,
74
+ });
75
+ cli.on('error', (error) => __awaiter(void 0, void 0, void 0, function* () {
76
+ console.error(`Failed to start ${packageName}: ${error.message}`);
77
+ yield cleanup();
78
+ exitProcess(1);
79
+ }));
80
+ cli.on('exit', (code) => {
81
+ exitProcess(code !== null && code !== void 0 ? code : 0);
82
+ });
83
+ }
84
+ catch (error) {
85
+ console.error(`Failed to start ${packageName}: ${error}`);
86
+ exitProcess(1);
87
+ }
88
+ process.on('exit', () => {
89
+ if (cli && !cli.killed) {
90
+ try {
91
+ cli.kill('SIGKILL');
92
+ }
93
+ catch (error) {
94
+ // ignore
95
+ }
96
+ }
97
+ });
3
98
  export { cli };
4
- void cli();
package/bin/start.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ var _a;
3
+ import { cli } from './cli.js';
4
+ const packageName = (_a = process.env.MINTLIFY_PACKAGE_NAME) !== null && _a !== void 0 ? _a : 'mint';
5
+ void cli({ packageName });