import chalk from 'chalk'; const MINT_GREEN = '#18E299'; const mint = chalk.hex(MINT_GREEN); interface CommandEntry { name: string; description: string; } interface CommandGroup { title: string; commands: CommandEntry[]; } const GROUPS: CommandGroup[] = [ { title: 'Preview', commands: [ { name: 'dev', description: 'Start a local preview of your site' }, { name: 'new', description: 'Scaffold a new documentation site' }, { name: 'deploy', description: 'Provision a docs site without login; get Git push instructions', }, ], }, { title: 'Quality', commands: [ { name: 'validate', description: 'Validate the site build (strict)' }, { name: 'broken-links', description: 'Find broken links before you ship', }, { name: 'a11y', description: 'Check site for accessibility issues' }, { name: 'score', description: 'Run agent-readiness checks' }, ], }, { title: 'Insights', commands: [ { name: 'analytics', description: 'View analytics for your site' }, { name: 'automations', description: 'Create and manage automations' }, ], }, { title: 'Account', commands: [ { name: 'login', description: 'Authenticate with Mintlify' }, { name: 'claim', description: 'Claim a site created with mint deploy' }, { name: 'logout', description: 'Sign out on this device' }, { name: 'status', description: 'View authentication status' }, ], }, { title: 'CLI', commands: [ { name: 'config', description: 'Manage CLI configuration' }, { name: 'update', description: 'Update to the latest version' }, ], }, ]; const EXAMPLES: CommandEntry[] = [ { name: 'dev', description: 'Start a local preview of your site' }, { name: 'new docs', description: 'Scaffold a new site in ./docs' }, { name: 'claim --email you@example.com', description: 'Get a claim link; use the deployment directory', }, { name: 'claim --code ', description: 'Finish the claim in the same directory' }, { name: 'validate', description: 'Validate your site before shipping' }, { name: 'broken-links', description: 'Find broken links across your site' }, ]; const COMMAND_NAME_WIDTH = GROUPS.flatMap((group) => group.commands).reduce( (max, command) => Math.max(max, command.name.length), 0 ) + 2; // `name description`, name padded to a shared column and colored mint. Padding // is computed on the raw name so ANSI codes don't throw off the alignment. const commandRow = (name: string, description: string, nameWidth: number, indent: number): string => ' '.repeat(indent) + mint(name.padEnd(nameWidth)) + chalk.dim(description); export interface WelcomeOptions { packageName: string; version?: string; signedIn: boolean; subdomain?: string; } /** * Builds the branded welcome / help screen as a ready-to-print string: the * Mintlify leaf beside an identity block, then grouped examples and commands. */ export function renderWelcome({ packageName, version, signedIn, subdomain, }: WelcomeOptions): string { const title = `${packageName.charAt(0).toUpperCase()}${packageName.slice(1)} CLI`; // Only prefix "v" for real semver versions; the linked-dev build reports a // descriptive string ("linked to local package"). const versionLabel = version ? (/^\d/.test(version) ? `v${version}` : version) : undefined; const identity: string[] = [ chalk.bold(title) + (versionLabel ? chalk.dim(` ${versionLabel}`) : ''), '', signedIn ? chalk.dim('Signed in to Mintlify') : chalk.dim('Run ') + mint(`${packageName} login`) + chalk.dim(' to sign in'), ...(subdomain ? [chalk.dim(`Project ${subdomain}`)] : []), ]; const lines: string[] = ['']; lines.push(...identity); // Examples. const exampleWidth = EXAMPLES.reduce((max, example) => Math.max(max, `${packageName} ${example.name}`.length), 0) + 2; lines.push('', ' ' + chalk.bold('EXAMPLES')); for (const example of EXAMPLES) { lines.push(commandRow(`${packageName} ${example.name}`, example.description, exampleWidth, 3)); } // Commands, grouped. lines.push('', ' ' + chalk.bold('COMMANDS')); for (const group of GROUPS) { lines.push('', ' ' + chalk.bold(group.title)); for (const command of group.commands) { lines.push(commandRow(command.name, command.description, COMMAND_NAME_WIDTH, 5)); } } lines.push( '', ' ' + chalk.dim('Run ') + mint(`${packageName} --help`) + chalk.dim(' for details on any command.'), '' ); return lines.join('\n') + '\n'; }