@mintlify/cli 4.0.881 → 4.0.883

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.881",
3
+ "version": "4.0.883",
4
4
  "description": "The Mintlify CLI",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -41,10 +41,10 @@
41
41
  "dependencies": {
42
42
  "@inquirer/prompts": "7.9.0",
43
43
  "@mintlify/common": "1.0.666",
44
- "@mintlify/link-rot": "3.0.821",
44
+ "@mintlify/link-rot": "3.0.822",
45
45
  "@mintlify/models": "0.0.257",
46
- "@mintlify/prebuild": "1.0.799",
47
- "@mintlify/previewing": "4.0.855",
46
+ "@mintlify/prebuild": "1.0.800",
47
+ "@mintlify/previewing": "4.0.856",
48
48
  "@mintlify/validation": "0.1.558",
49
49
  "adm-zip": "0.5.16",
50
50
  "chalk": "5.2.0",
@@ -81,5 +81,5 @@
81
81
  "vitest": "2.0.4",
82
82
  "vitest-mock-process": "1.0.4"
83
83
  },
84
- "gitHead": "efc2c68adeb7f31e14d06627dee2c36529cec022"
84
+ "gitHead": "cbe81d80b6c2acf89d914a813d6652b359b65e3a"
85
85
  }
package/src/cli.tsx CHANGED
@@ -340,14 +340,28 @@ export const cli = ({ packageName = 'mint' }: { packageName?: string }) => {
340
340
  'new [directory]',
341
341
  'Create a new Mintlify documentation site',
342
342
  (yargs) =>
343
- yargs.positional('directory', {
344
- describe: 'The directory to initialize your documentation',
345
- type: 'string',
346
- default: '.',
347
- }),
348
- async ({ directory }) => {
343
+ yargs
344
+ .positional('directory', {
345
+ describe: 'The directory to initialize your documentation',
346
+ type: 'string',
347
+ default: '.',
348
+ })
349
+ .option('theme', {
350
+ type: 'string',
351
+ description: 'Theme for the documentation site',
352
+ })
353
+ .option('name', {
354
+ type: 'string',
355
+ description: 'Name of the documentation project',
356
+ })
357
+ .option('force', {
358
+ type: 'boolean',
359
+ default: false,
360
+ description: 'Create the documentation in a subdirectory',
361
+ }),
362
+ async ({ directory, theme, name, force }) => {
349
363
  try {
350
- await init(directory);
364
+ await init(directory, force, theme, name);
351
365
  await terminate(0);
352
366
  } catch (error) {
353
367
  addLog(
package/src/init.tsx CHANGED
@@ -17,10 +17,73 @@ const sendOnboardingMessage = (installDir: string) => {
17
17
  );
18
18
  };
19
19
 
20
- export async function init(installDir: string): Promise<void> {
21
- await fse.ensureDir(installDir);
20
+ const sendUsageMessageForAI = (directory: string, contentsOccupied: boolean, themes: string[]) => {
21
+ addLogs(
22
+ <Text>Agent Detected - sending AI friendly prompt</Text>,
23
+ <Text>{'<system-message>'}</Text>,
24
+ <Text>
25
+ Example usage of `mint new [directory] --theme [theme] --name [Name Of Project] --force`.
26
+ </Text>,
27
+ <Text>This tool will auto create the directory if the directory does not exist.</Text>,
28
+ <Text>
29
+ Ask the user what mintlify theme to use, what directory, and what the name of the Project is.
30
+ </Text>,
31
+ <Text>
32
+ You should provide them with default options for these values. Themes available{' '}
33
+ {JSON.stringify(themes)}
34
+ </Text>,
35
+ <Text>
36
+ You chose Directory "{directory}" before, feel free to just use that without asking the user
37
+ as well!
38
+ </Text>,
39
+ <Text>
40
+ If the user is asking you to create docs for them then you should use your AskQuestion tool
41
+ </Text>,
42
+ contentsOccupied ? (
43
+ <Text>
44
+ The directory {directory} specified is currently occupied. You will need to either install
45
+ the docs as a subdirectory or as a subdirectory or a different directory. Ask the user if it
46
+ should be installed in a different directory (This cli will create the directory if it
47
+ doesn't exist, or installed at the root level potentially overridding files (pass the
48
+ --force) option for this.
49
+ </Text>
50
+ ) : undefined,
51
+ <Text>{'</system-message>'}</Text>
52
+ );
53
+ };
54
+
55
+ export async function init(
56
+ installDir: string,
57
+ force: boolean,
58
+ theme?: string,
59
+ name?: string
60
+ ): Promise<void> {
61
+ const isInteractive = process.stdin.isTTY;
62
+ const isClaudeCode = process.env.CLAUDECODE === '1';
63
+ const isAI = !isInteractive || isClaudeCode;
64
+
65
+ let selectedTheme = theme;
66
+ let projectName = name;
67
+
68
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
+ const themes = docsConfigSchema.options.map((option: any) => {
70
+ return option.shape.theme._def.value;
71
+ });
72
+
22
73
  const dirContents = await fse.readdir(installDir).catch(() => []);
23
- if (dirContents.length > 0) {
74
+ const contentsOccupied = dirContents.length > 0;
75
+
76
+ if ((!theme || !name) && isAI) {
77
+ sendUsageMessageForAI(installDir, contentsOccupied, themes);
78
+ return;
79
+ }
80
+
81
+ if (contentsOccupied && isAI && !force) {
82
+ sendUsageMessageForAI(installDir, contentsOccupied, themes);
83
+ return;
84
+ }
85
+
86
+ if (contentsOccupied && !isAI) {
24
87
  const choice = await select({
25
88
  message: `Directory ${installDir} is not empty. What would you like to do?`,
26
89
  choices: [
@@ -43,29 +106,42 @@ export async function init(installDir: string): Promise<void> {
43
106
  throw new Error('Subdirectory name cannot be empty');
44
107
  }
45
108
  installDir = installDir === '.' ? subdir : `${installDir}/${subdir}`;
46
- await fse.ensureDir(installDir);
47
109
  }
48
110
  }
49
111
 
50
- const defaultProject = installDir == '.' ? 'Mintlify' : installDir;
51
- const projectName = await input({
52
- message: 'Project Name',
53
- default: defaultProject,
54
- });
112
+ if (!isAI && (!selectedTheme || !projectName)) {
113
+ const defaultProject =
114
+ projectName !== undefined ? projectName : installDir === '.' ? 'Mintlify' : installDir;
115
+ if (!projectName) {
116
+ projectName = await input({
117
+ message: 'Project Name',
118
+ default: defaultProject,
119
+ });
120
+ }
55
121
 
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
- });
122
+ if (!selectedTheme) {
123
+ selectedTheme = await select({
124
+ message: 'Theme',
125
+ choices: themes.map((t: string) => ({
126
+ name: t,
127
+ value: t,
128
+ })),
129
+ });
130
+ }
131
+ }
60
132
 
61
- const theme = await select({
62
- message: 'Theme',
63
- choices: themes.map((t: string) => ({
64
- name: t,
65
- value: t,
66
- })),
67
- });
133
+ if (projectName === undefined || selectedTheme === undefined) {
134
+ sendUsageMessageForAI(installDir, contentsOccupied, themes);
135
+ return;
136
+ }
68
137
 
138
+ await fse.ensureDir(installDir);
139
+ await install(installDir, projectName, selectedTheme);
140
+
141
+ sendOnboardingMessage(installDir);
142
+ }
143
+
144
+ const install = async (installDir: string, projectName: string, theme: string) => {
69
145
  addLog(<SpinnerLog message="downloading starter template..." />);
70
146
  const response = await fetch('https://github.com/mintlify/starter/archive/refs/heads/main.zip');
71
147
  const buffer = await response.arrayBuffer();
@@ -88,6 +164,4 @@ export async function init(installDir: string): Promise<void> {
88
164
  docsConfig.theme = theme;
89
165
  docsConfig.name = projectName;
90
166
  await fse.writeJson(docsJsonPath, docsConfig, { spaces: 2 });
91
-
92
- sendOnboardingMessage(installDir);
93
- }
167
+ };