@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintlify/cli",
3
- "version": "4.0.781",
3
+ "version": "4.0.783",
4
4
  "description": "The Mintlify CLI",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -39,12 +39,14 @@
39
39
  "format:check": "prettier . --check"
40
40
  },
41
41
  "dependencies": {
42
- "@mintlify/common": "1.0.583",
43
- "@mintlify/link-rot": "3.0.724",
42
+ "@inquirer/prompts": "^7.9.0",
43
+ "@mintlify/common": "1.0.585",
44
+ "@mintlify/link-rot": "3.0.726",
44
45
  "@mintlify/models": "0.0.236",
45
- "@mintlify/prebuild": "1.0.711",
46
- "@mintlify/previewing": "4.0.760",
47
- "@mintlify/validation": "0.1.507",
46
+ "@mintlify/prebuild": "1.0.713",
47
+ "@mintlify/previewing": "4.0.762",
48
+ "@mintlify/validation": "0.1.509",
49
+ "adm-zip": "^0.5.10",
48
50
  "chalk": "^5.2.0",
49
51
  "color": "^4.2.3",
50
52
  "detect-port": "^1.5.1",
@@ -66,6 +68,7 @@
66
68
  "@mintlify/ts-config": "2.0.2",
67
69
  "@trivago/prettier-plugin-sort-imports": "^4.2.1",
68
70
  "@tsconfig/recommended": "1.x",
71
+ "@types/adm-zip": "^0.5.7",
69
72
  "@types/detect-port": "^1.3.2",
70
73
  "@types/node": "^18.7.13",
71
74
  "@types/yargs": "^17.0.13",
@@ -78,5 +81,5 @@
78
81
  "vitest": "^2.0.4",
79
82
  "vitest-mock-process": "^1.0.4"
80
83
  },
81
- "gitHead": "800cb24f2e15b125779ccfc8cc0ba8d8ef49aa14"
84
+ "gitHead": "78f8f714999cad2454683e01fb4f856e0336cdbb"
82
85
  }
package/src/cli.tsx CHANGED
@@ -28,6 +28,7 @@ import {
28
28
  terminate,
29
29
  readLocalOpenApiFile,
30
30
  } from './helpers.js';
31
+ import { init } from './init.js';
31
32
  import { mdxLinter } from './mdxLinter.js';
32
33
  import { migrateMdx } from './migrateMdx.js';
33
34
  import { update } from './update.js';
@@ -274,6 +275,27 @@ export const cli = ({ packageName = 'mint' }: { packageName?: string }) => {
274
275
  );
275
276
  }
276
277
  )
278
+ .command(
279
+ 'new [directory]',
280
+ 'Create a new Mintlify documentation site',
281
+ (yargs) =>
282
+ yargs.positional('directory', {
283
+ describe: 'The directory to initialize your documentation',
284
+ type: 'string',
285
+ default: '.',
286
+ }),
287
+ async ({ directory }) => {
288
+ try {
289
+ await init(directory);
290
+ await terminate(0);
291
+ } catch (error) {
292
+ addLog(
293
+ <ErrorLog message={error instanceof Error ? error.message : 'error occurred'} />
294
+ );
295
+ await terminate(1);
296
+ }
297
+ }
298
+ )
277
299
  // Print the help menu when the user enters an invalid command.
278
300
  .strictCommands()
279
301
  .demandCommand(1, 'unknown command. see above for the list of supported commands.')
package/src/init.tsx ADDED
@@ -0,0 +1,93 @@
1
+ import { select, input } from '@inquirer/prompts';
2
+ import { addLogs, addLog, SpinnerLog, removeLastLog } from '@mintlify/previewing';
3
+ import { docsConfigSchema } from '@mintlify/validation';
4
+ import AdmZip from 'adm-zip';
5
+ import fse from 'fs-extra';
6
+ import { Box, Text } from 'ink';
7
+
8
+ const sendOnboardingMessage = (installDir: string) => {
9
+ addLogs(
10
+ <Text bold>Documentation Setup!</Text>,
11
+ <Text>To see your docs run</Text>,
12
+ <Box>
13
+ <Text color="blue">cd</Text>
14
+ <Text> {installDir}</Text>
15
+ </Box>,
16
+ <Text color="blue">mint dev</Text>
17
+ );
18
+ };
19
+
20
+ export async function init(installDir: string): Promise<void> {
21
+ await fse.ensureDir(installDir);
22
+ const dirContents = await fse.readdir(installDir).catch(() => []);
23
+ if (dirContents.length > 0) {
24
+ const choice = await select({
25
+ message: `Directory ${installDir} is not empty. What would you like to do?`,
26
+ choices: [
27
+ { name: 'Create in a subdirectory', value: 'subdir' },
28
+ { name: 'Overwrite current directory (may lose contents)', value: 'overwrite' },
29
+ { name: 'Cancel', value: 'cancel' },
30
+ ],
31
+ });
32
+
33
+ if (choice === 'cancel') {
34
+ return;
35
+ }
36
+
37
+ if (choice === 'subdir') {
38
+ const subdir = await input({
39
+ message: 'Subdirectory name:',
40
+ default: 'docs',
41
+ });
42
+ if (!subdir || subdir.trim() === '') {
43
+ throw new Error('Subdirectory name cannot be empty');
44
+ }
45
+ installDir = installDir === '.' ? subdir : `${installDir}/${subdir}`;
46
+ await fse.ensureDir(installDir);
47
+ }
48
+ }
49
+
50
+ const defaultProject = installDir == '.' ? 'Mintlify' : installDir;
51
+ const projectName = await input({
52
+ message: 'Project Name',
53
+ default: defaultProject,
54
+ });
55
+
56
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+ const themes = docsConfigSchema.options.map((option: any) => {
58
+ return option.shape.theme._def.value;
59
+ });
60
+
61
+ const theme = await select({
62
+ message: 'Theme',
63
+ choices: themes.map((t: string) => ({
64
+ name: t,
65
+ value: t,
66
+ })),
67
+ });
68
+
69
+ addLog(<SpinnerLog message="downloading starter template..." />);
70
+ const response = await fetch('https://github.com/mintlify/starter/archive/refs/heads/main.zip');
71
+ const buffer = await response.arrayBuffer();
72
+ await fse.writeFile(installDir + '/starter.zip', Buffer.from(buffer));
73
+ removeLastLog();
74
+
75
+ addLog(<SpinnerLog message="extracting..." />);
76
+ new AdmZip(installDir + '/starter.zip').extractAllTo(installDir, true);
77
+ removeLastLog();
78
+
79
+ await fse.copy(installDir + '/starter-main', installDir, {
80
+ overwrite: true,
81
+ filter: (src) => !src.includes('starter-main/starter-main'),
82
+ });
83
+ await fse.remove(installDir + '/starter.zip');
84
+ await fse.remove(installDir + '/starter-main');
85
+
86
+ const docsJsonPath = installDir + '/docs.json';
87
+ const docsConfig = await fse.readJson(docsJsonPath);
88
+ docsConfig.theme = theme;
89
+ docsConfig.name = projectName;
90
+ await fse.writeJson(docsJsonPath, docsConfig, { spaces: 2 });
91
+
92
+ sendOnboardingMessage(installDir);
93
+ }