UNPKG

nextdevkit

Version:

A Comprehensive CLI Toolkit for Next.js Development

109 lines (108 loc) • 4.37 kB
import chalk from 'chalk'; import figlet from 'figlet'; import loadPackageJson from '../utils/loadPackageJson.js'; const commands = [ { name: 'create [projectName]', description: 'Create a new Next.js project with NextDevKit initialized.', usage: 'npx nextdevkit@latest create [projectName]', example: 'npx nextdevkit@latest create my-next-app' }, { name: 'init', description: 'Initialize NextDevKit in an existing Next.js project.', usage: 'npx nextdevkit@latest init', example: 'npx nextdevkit@latest init' }, { name: 'add <name>', description: 'Add a utility or React custom hook file to your project.', usage: 'npx nextdevkit@latest add <name>', example: 'npx nextdevkit@latest add useAxios' }, { name: 'remove <name>', description: 'Remove a utility or hook file from your project.', usage: 'npx nextdevkit@latest remove <name>', example: 'npx nextdevkit@latest remove useAxios' }, { name: 'generate <type> <name>', description: 'Generate a new component or page.', usage: 'npx nextdevkit@latest generate <type> <name>', example: 'npx nextdevkit@latest generate component Navbar' }, { name: 'list', description: 'List all available utility and hook files.', usage: 'npx nextdevkit@latest list', example: 'npx nextdevkit@latest list' }, { name: 'setup-linters', description: 'Set up ESLint, Prettier, Husky, and lint-staged.', usage: 'npx nextdevkit@latest setup-linters', example: 'npx nextdevkit@latest setup-linters' }, { name: 'help [command]', description: 'Display usage for commands with examples.', usage: 'npx nextdevkit@latest help [commandName]', example: 'npx nextdevkit@latest help generate' } ]; const displayBanner = (version) => { console.clear(); console.log(chalk.blue.bold(figlet.textSync('NextDevKit', { horizontalLayout: 'default' }))); console.log('\n' + chalk.white.bold('šŸš€ A Comprehensive CLI Toolkit for Next.js Development.\n') + chalk.white('šŸ”– Version: ') + chalk.green(version) + '\n' + chalk.white('šŸ‘¤ Created by: ') + chalk.green('Harshal Katakiya') + '\n' + chalk.white('🌐 GitHub: ') + chalk.underline.blue('https://github.com/Harshalkatakiya') + '\n'); }; const displayAllCommands = () => { console.log(chalk.green.bold('\n✨ Available Commands:\n')); const columnWidths = [30, 60]; const pad = (str, width) => str.padEnd(width); console.log(chalk.blue.bold(`${pad('Command', columnWidths[0])}${pad('Description', columnWidths[1])}`)); console.log(chalk.gray('-'.repeat(columnWidths.reduce((a, b) => a + b)))); commands.forEach((cmd) => { console.log(`${chalk.cyan(pad(cmd.name, columnWidths[0]))}${chalk.white(cmd.description)}`); }); console.log(`\nRun ${chalk.cyan('npx nextdevkit@latest help [command]')} for details on a specific command.\n`); }; const displayCommandUsage = (commandName) => { const command = commands.find((cmd) => cmd.name.split(' ')[0] === commandName.toLowerCase()); if (command) { console.log(chalk.green.bold(`\n✨ Command: ${chalk.cyan(command.name)}\n`)); console.log(`${chalk.white('šŸ“ Description:')} ${chalk.yellow(command.description)}\n`); console.log(`${chalk.white('šŸ“Œ Usage:')}\n ${chalk.cyan(command.usage)}\n`); console.log(`${chalk.white('šŸ” Example:')}\n ${chalk.cyan(command.example)}\n`); } else { console.log(chalk.red(`\nāŒ Unknown command '${commandName}'.\n`)); displayAllCommands(); } }; const displayUsage = async (subcommand) => { const packageJson = await loadPackageJson(); displayBanner(packageJson.version); console.log(chalk.green.bold('šŸ› ļø Usage: ') + chalk.cyan('npx nextdevkit@latest <command> [options]\n')); if (subcommand) { displayCommandUsage(subcommand); } else { displayAllCommands(); } console.log(chalk.gray('šŸ”— For more information, visit: ') + chalk.underline.blue('https://nextdevkit.vercel.app') + '\n'); }; export default displayUsage;