@mintlify/cli 4.0.881 → 4.0.882

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/bin/cli.js CHANGED
@@ -235,13 +235,27 @@ export const cli = ({ packageName = 'mint' }) => {
235
235
  addLog(_jsxs(Text, { children: [_jsx(Text, { bold: true, color: "green", children: "cli version" }), ' ', cli] }));
236
236
  addLog(_jsxs(Text, { children: [_jsx(Text, { bold: true, color: "green", children: "client version" }), ' ', client] }));
237
237
  }))
238
- .command('new [directory]', 'Create a new Mintlify documentation site', (yargs) => yargs.positional('directory', {
238
+ .command('new [directory]', 'Create a new Mintlify documentation site', (yargs) => yargs
239
+ .positional('directory', {
239
240
  describe: 'The directory to initialize your documentation',
240
241
  type: 'string',
241
242
  default: '.',
242
- }), (_a) => __awaiter(void 0, [_a], void 0, function* ({ directory }) {
243
+ })
244
+ .option('theme', {
245
+ type: 'string',
246
+ description: 'Theme for the documentation site',
247
+ })
248
+ .option('name', {
249
+ type: 'string',
250
+ description: 'Name of the documentation project',
251
+ })
252
+ .option('force', {
253
+ type: 'boolean',
254
+ default: false,
255
+ description: 'Create the documentation in a subdirectory',
256
+ }), (_a) => __awaiter(void 0, [_a], void 0, function* ({ directory, theme, name, force }) {
243
257
  try {
244
- yield init(directory);
258
+ yield init(directory, force, theme, name);
245
259
  yield terminate(0);
246
260
  }
247
261
  catch (error) {
package/bin/init.js CHANGED
@@ -17,11 +17,31 @@ import { Box, Text } from 'ink';
17
17
  const sendOnboardingMessage = (installDir) => {
18
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
19
  };
20
- export function init(installDir) {
20
+ const sendUsageMessageForAI = (directory, contentsOccupied, themes) => {
21
+ addLogs(_jsx(Text, { children: "Agent Detected - sending AI friendly prompt" }), _jsx(Text, { children: '<system-message>' }), _jsx(Text, { children: "Example usage of `mint new [directory] --theme [theme] --name [Name Of Project] --force`." }), _jsx(Text, { children: "This tool will auto create the directory if the directory does not exist." }), _jsx(Text, { children: "Ask the user what mintlify theme to use, what directory, and what the name of the Project is." }), _jsxs(Text, { children: ["You should provide them with default options for these values. Themes available", ' ', JSON.stringify(themes)] }), _jsxs(Text, { children: ["You chose Directory \"", directory, "\" before, feel free to just use that without asking the user as well!"] }), _jsx(Text, { children: "If the user is asking you to create docs for them then you should use your AskQuestion tool" }), contentsOccupied ? (_jsxs(Text, { children: ["The directory ", directory, " specified is currently occupied. You will need to either install the docs as a subdirectory or as a subdirectory or a different directory. Ask the user if it should be installed in a different directory (This cli will create the directory if it doesn't exist, or installed at the root level potentially overridding files (pass the --force) option for this."] })) : undefined, _jsx(Text, { children: '</system-message>' }));
22
+ };
23
+ export function init(installDir, force, theme, name) {
21
24
  return __awaiter(this, void 0, void 0, function* () {
22
- yield fse.ensureDir(installDir);
25
+ const isInteractive = process.stdin.isTTY;
26
+ const isClaudeCode = process.env.CLAUDECODE === '1';
27
+ const isAI = !isInteractive || isClaudeCode;
28
+ let selectedTheme = theme;
29
+ let projectName = name;
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ const themes = docsConfigSchema.options.map((option) => {
32
+ return option.shape.theme._def.value;
33
+ });
23
34
  const dirContents = yield fse.readdir(installDir).catch(() => []);
24
- if (dirContents.length > 0) {
35
+ const contentsOccupied = dirContents.length > 0;
36
+ if ((!theme || !name) && isAI) {
37
+ sendUsageMessageForAI(installDir, contentsOccupied, themes);
38
+ return;
39
+ }
40
+ if (contentsOccupied && isAI && !force) {
41
+ sendUsageMessageForAI(installDir, contentsOccupied, themes);
42
+ return;
43
+ }
44
+ if (contentsOccupied && !isAI) {
25
45
  const choice = yield select({
26
46
  message: `Directory ${installDir} is not empty. What would you like to do?`,
27
47
  choices: [
@@ -42,44 +62,53 @@ export function init(installDir) {
42
62
  throw new Error('Subdirectory name cannot be empty');
43
63
  }
44
64
  installDir = installDir === '.' ? subdir : `${installDir}/${subdir}`;
45
- yield fse.ensureDir(installDir);
46
65
  }
47
66
  }
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 });
67
+ if (!isAI && (!selectedTheme || !projectName)) {
68
+ const defaultProject = projectName !== undefined ? projectName : installDir === '.' ? 'Mintlify' : installDir;
69
+ if (!projectName) {
70
+ projectName = yield input({
71
+ message: 'Project Name',
72
+ default: defaultProject,
73
+ });
74
+ }
75
+ if (!selectedTheme) {
76
+ selectedTheme = yield select({
77
+ message: 'Theme',
78
+ choices: themes.map((t) => ({
79
+ name: t,
80
+ value: t,
81
+ })),
82
+ });
83
+ }
84
+ }
85
+ if (projectName === undefined || selectedTheme === undefined) {
86
+ sendUsageMessageForAI(installDir, contentsOccupied, themes);
87
+ return;
88
+ }
89
+ yield fse.ensureDir(installDir);
90
+ yield install(installDir, projectName, selectedTheme);
83
91
  sendOnboardingMessage(installDir);
84
92
  });
85
93
  }
94
+ const install = (installDir, projectName, theme) => __awaiter(void 0, void 0, void 0, function* () {
95
+ addLog(_jsx(SpinnerLog, { message: "downloading starter template..." }));
96
+ const response = yield fetch('https://github.com/mintlify/starter/archive/refs/heads/main.zip');
97
+ const buffer = yield response.arrayBuffer();
98
+ yield fse.writeFile(installDir + '/starter.zip', Buffer.from(buffer));
99
+ removeLastLog();
100
+ addLog(_jsx(SpinnerLog, { message: "extracting..." }));
101
+ new AdmZip(installDir + '/starter.zip').extractAllTo(installDir, true);
102
+ removeLastLog();
103
+ yield fse.copy(installDir + '/starter-main', installDir, {
104
+ overwrite: true,
105
+ filter: (src) => !src.includes('starter-main/starter-main'),
106
+ });
107
+ yield fse.remove(installDir + '/starter.zip');
108
+ yield fse.remove(installDir + '/starter-main');
109
+ const docsJsonPath = installDir + '/docs.json';
110
+ const docsConfig = yield fse.readJson(docsJsonPath);
111
+ docsConfig.theme = theme;
112
+ docsConfig.name = projectName;
113
+ yield fse.writeJson(docsJsonPath, docsConfig, { spaces: 2 });
114
+ });