@mintlify/cli 4.0.781 → 4.0.783
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/CONTRIBUTING.md +2 -2
- package/bin/cli.js +15 -0
- package/bin/init.js +85 -0
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +10 -7
- package/src/cli.tsx +22 -0
- package/src/init.tsx +93 -0
package/CONTRIBUTING.md
CHANGED
|
@@ -4,13 +4,13 @@ Note: contributing requires `yarn` and it's recommended you install it as a glob
|
|
|
4
4
|
|
|
5
5
|
Run `yarn` or `yarn install` to install dependencies. Then, run `npm link` once to link to your local version of the CLI in the npm global namespace (`npm list -g`). Make sure you are working in `packages/cli` and not its alias package, `packages/mintlify`.
|
|
6
6
|
|
|
7
|
-
If you already have a non-local version of the CLI, you will need to uninstall it (`npm uninstall -g
|
|
7
|
+
If you already have a non-local version of the CLI, you will need to uninstall it (`npm uninstall -g mint`) or force overwrite the executable file. Otherwise, you will get an `EEXIST` error on the mintlify binary. You can overwrite the file using the `--force` flag (`npm link --force`), but always double check the file(s) you are overwriting.
|
|
8
8
|
|
|
9
9
|
Make sure to build the CLI using `yarn build` or `yarn watch` to see your local changes reflected. Tip: keep `yarn watch` running in a separate terminal for changes to be quickly and continuously reflected while developing.
|
|
10
10
|
|
|
11
11
|
To uninstall locally, run `npm uninstall -g @mintlify/cli`.
|
|
12
12
|
|
|
13
|
-
If you wish to continue using the production version of the CLI, you will need to reinstall it (`npm install -g
|
|
13
|
+
If you wish to continue using the production version of the CLI, you will need to reinstall it (`npm install -g mint`). If you do not uninstall `@mintlify/cli`, then you will need to force overwrite the executable file (`npm install -g mint --force`) for the same reasons as mentioned above. As a best practice, we recommend always uninstalling `@mintlify/cli` first.
|
|
14
14
|
|
|
15
15
|
## Updating Version of Mint Client
|
|
16
16
|
|
package/bin/cli.js
CHANGED
|
@@ -17,6 +17,7 @@ import yargs from 'yargs';
|
|
|
17
17
|
import { hideBin } from 'yargs/helpers';
|
|
18
18
|
import { accessibilityCheck } from './accessibilityCheck.js';
|
|
19
19
|
import { checkPort, checkForMintJson, checkNodeVersion, upgradeConfig, checkForDocsJson, getVersions, suppressConsoleWarnings, terminate, readLocalOpenApiFile, } from './helpers.js';
|
|
20
|
+
import { init } from './init.js';
|
|
20
21
|
import { mdxLinter } from './mdxLinter.js';
|
|
21
22
|
import { migrateMdx } from './migrateMdx.js';
|
|
22
23
|
import { update } from './update.js';
|
|
@@ -183,6 +184,20 @@ export const cli = ({ packageName = 'mint' }) => {
|
|
|
183
184
|
const { cli, client } = getVersions();
|
|
184
185
|
addLog(_jsxs(Text, { children: [_jsx(Text, { bold: true, color: "green", children: "cli version" }), ' ', cli] }));
|
|
185
186
|
addLog(_jsxs(Text, { children: [_jsx(Text, { bold: true, color: "green", children: "client version" }), ' ', client] }));
|
|
187
|
+
}))
|
|
188
|
+
.command('new [directory]', 'Create a new Mintlify documentation site', (yargs) => yargs.positional('directory', {
|
|
189
|
+
describe: 'The directory to initialize your documentation',
|
|
190
|
+
type: 'string',
|
|
191
|
+
default: '.',
|
|
192
|
+
}), (_a) => __awaiter(void 0, [_a], void 0, function* ({ directory }) {
|
|
193
|
+
try {
|
|
194
|
+
yield init(directory);
|
|
195
|
+
yield terminate(0);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
addLog(_jsx(ErrorLog, { message: error instanceof Error ? error.message : 'error occurred' }));
|
|
199
|
+
yield terminate(1);
|
|
200
|
+
}
|
|
186
201
|
}))
|
|
187
202
|
// Print the help menu when the user enters an invalid command.
|
|
188
203
|
.strictCommands()
|
package/bin/init.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { select, input } from '@inquirer/prompts';
|
|
12
|
+
import { addLogs, addLog, SpinnerLog, removeLastLog } from '@mintlify/previewing';
|
|
13
|
+
import { docsConfigSchema } from '@mintlify/validation';
|
|
14
|
+
import AdmZip from 'adm-zip';
|
|
15
|
+
import fse from 'fs-extra';
|
|
16
|
+
import { Box, Text } from 'ink';
|
|
17
|
+
const sendOnboardingMessage = (installDir) => {
|
|
18
|
+
addLogs(_jsx(Text, { bold: true, children: "Documentation Setup!" }), _jsx(Text, { children: "To see your docs run" }), _jsxs(Box, { children: [_jsx(Text, { color: "blue", children: "cd" }), _jsxs(Text, { children: [" ", installDir] })] }), _jsx(Text, { color: "blue", children: "mint dev" }));
|
|
19
|
+
};
|
|
20
|
+
export function init(installDir) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
yield fse.ensureDir(installDir);
|
|
23
|
+
const dirContents = yield fse.readdir(installDir).catch(() => []);
|
|
24
|
+
if (dirContents.length > 0) {
|
|
25
|
+
const choice = yield select({
|
|
26
|
+
message: `Directory ${installDir} is not empty. What would you like to do?`,
|
|
27
|
+
choices: [
|
|
28
|
+
{ name: 'Create in a subdirectory', value: 'subdir' },
|
|
29
|
+
{ name: 'Overwrite current directory (may lose contents)', value: 'overwrite' },
|
|
30
|
+
{ name: 'Cancel', value: 'cancel' },
|
|
31
|
+
],
|
|
32
|
+
});
|
|
33
|
+
if (choice === 'cancel') {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (choice === 'subdir') {
|
|
37
|
+
const subdir = yield input({
|
|
38
|
+
message: 'Subdirectory name:',
|
|
39
|
+
default: 'docs',
|
|
40
|
+
});
|
|
41
|
+
if (!subdir || subdir.trim() === '') {
|
|
42
|
+
throw new Error('Subdirectory name cannot be empty');
|
|
43
|
+
}
|
|
44
|
+
installDir = installDir === '.' ? subdir : `${installDir}/${subdir}`;
|
|
45
|
+
yield fse.ensureDir(installDir);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const defaultProject = installDir == '.' ? 'Mintlify' : installDir;
|
|
49
|
+
const projectName = yield input({
|
|
50
|
+
message: 'Project Name',
|
|
51
|
+
default: defaultProject,
|
|
52
|
+
});
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
+
const themes = docsConfigSchema.options.map((option) => {
|
|
55
|
+
return option.shape.theme._def.value;
|
|
56
|
+
});
|
|
57
|
+
const theme = yield select({
|
|
58
|
+
message: 'Theme',
|
|
59
|
+
choices: themes.map((t) => ({
|
|
60
|
+
name: t,
|
|
61
|
+
value: t,
|
|
62
|
+
})),
|
|
63
|
+
});
|
|
64
|
+
addLog(_jsx(SpinnerLog, { message: "downloading starter template..." }));
|
|
65
|
+
const response = yield fetch('https://github.com/mintlify/starter/archive/refs/heads/main.zip');
|
|
66
|
+
const buffer = yield response.arrayBuffer();
|
|
67
|
+
yield fse.writeFile(installDir + '/starter.zip', Buffer.from(buffer));
|
|
68
|
+
removeLastLog();
|
|
69
|
+
addLog(_jsx(SpinnerLog, { message: "extracting..." }));
|
|
70
|
+
new AdmZip(installDir + '/starter.zip').extractAllTo(installDir, true);
|
|
71
|
+
removeLastLog();
|
|
72
|
+
yield fse.copy(installDir + '/starter-main', installDir, {
|
|
73
|
+
overwrite: true,
|
|
74
|
+
filter: (src) => !src.includes('starter-main/starter-main'),
|
|
75
|
+
});
|
|
76
|
+
yield fse.remove(installDir + '/starter.zip');
|
|
77
|
+
yield fse.remove(installDir + '/starter-main');
|
|
78
|
+
const docsJsonPath = installDir + '/docs.json';
|
|
79
|
+
const docsConfig = yield fse.readJson(docsJsonPath);
|
|
80
|
+
docsConfig.theme = theme;
|
|
81
|
+
docsConfig.name = projectName;
|
|
82
|
+
yield fse.writeJson(docsJsonPath, docsConfig, { spaces: 2 });
|
|
83
|
+
sendOnboardingMessage(installDir);
|
|
84
|
+
});
|
|
85
|
+
}
|