@mintlify/cli 4.0.627 → 4.0.629

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/helpers.js CHANGED
@@ -151,3 +151,17 @@ export const terminate = (code) => __awaiter(void 0, void 0, void 0, function* (
151
151
  process.exit(code);
152
152
  });
153
153
  export const execAsync = promisify(exec);
154
+ export const detectPackageManager = (_a) => __awaiter(void 0, [_a], void 0, function* ({ packageName }) {
155
+ try {
156
+ const { stdout: packagePath } = yield execAsync(`which ${packageName}`);
157
+ if (packagePath.includes('pnpm')) {
158
+ return 'pnpm';
159
+ }
160
+ else {
161
+ return 'npm';
162
+ }
163
+ }
164
+ catch (error) {
165
+ return 'npm';
166
+ }
167
+ });
package/bin/index.js CHANGED
@@ -1,4 +1,100 @@
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, _c;
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 = ((_a = process.argv[1]) === null || _a === void 0 ? void 0 : _a.split('/').pop()) === 'index.js'
18
+ ? 'mint'
19
+ : (_c = (_b = process.argv[1]) === null || _b === void 0 ? void 0 : _b.split('/').pop()) !== null && _c !== void 0 ? _c : 'mint';
20
+ let cli = null;
21
+ let isShuttingDown = false;
22
+ let hasExited = false;
23
+ const cleanup = () => __awaiter(void 0, void 0, void 0, function* () {
24
+ if (isShuttingDown)
25
+ return;
26
+ isShuttingDown = true;
27
+ if (cli && !cli.killed) {
28
+ try {
29
+ cli.kill('SIGTERM');
30
+ yield new Promise((resolve) => {
31
+ const timeout = setTimeout(() => {
32
+ if (cli && !cli.killed) {
33
+ cli.kill('SIGKILL');
34
+ }
35
+ resolve();
36
+ }, 5000);
37
+ cli.once('exit', () => {
38
+ clearTimeout(timeout);
39
+ resolve();
40
+ });
41
+ });
42
+ }
43
+ catch (error) {
44
+ // ignore
45
+ }
46
+ }
47
+ });
48
+ const exitProcess = (code) => {
49
+ if (hasExited)
50
+ return;
51
+ hasExited = true;
52
+ process.exit(code);
53
+ };
54
+ const killSignals = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP'];
55
+ killSignals.forEach((signal) => {
56
+ process.on(signal, () => __awaiter(void 0, void 0, void 0, function* () {
57
+ yield cleanup();
58
+ exitProcess(0);
59
+ }));
60
+ });
61
+ process.on('uncaughtException', () => __awaiter(void 0, void 0, void 0, function* () {
62
+ yield cleanup();
63
+ exitProcess(1);
64
+ }));
65
+ process.on('unhandledRejection', () => __awaiter(void 0, void 0, void 0, function* () {
66
+ yield cleanup();
67
+ exitProcess(1);
68
+ }));
69
+ try {
70
+ cli = spawn('node', ['--no-deprecation', path.join(__dirname, '../bin/start.js'), ...process.argv.slice(2)], {
71
+ stdio: 'inherit',
72
+ env: Object.assign(Object.assign({}, process.env), { MINTLIFY_PACKAGE_NAME: packageName }),
73
+ shell: process.platform === 'win32',
74
+ windowsHide: process.platform === 'win32',
75
+ detached: false,
76
+ });
77
+ cli.on('error', (error) => __awaiter(void 0, void 0, void 0, function* () {
78
+ console.error(`Failed to start ${packageName}: ${error.message}`);
79
+ yield cleanup();
80
+ exitProcess(1);
81
+ }));
82
+ cli.on('exit', (code) => {
83
+ exitProcess(code !== null && code !== void 0 ? code : 0);
84
+ });
85
+ }
86
+ catch (error) {
87
+ console.error(`Failed to start ${packageName}: ${error}`);
88
+ exitProcess(1);
89
+ }
90
+ process.on('exit', () => {
91
+ if (cli && !cli.killed) {
92
+ try {
93
+ cli.kill('SIGKILL');
94
+ }
95
+ catch (error) {
96
+ // ignore
97
+ }
98
+ }
99
+ });
3
100
  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 });