Node.js CLI Tool
🛠️ Technologies
Node.jsCommander.jsChalkInquirer
📅 Timeline
Created:
Last Updated:
🏷️ Tags
一个强大的命令行工具,用于自动化常见的开发任务和文件操作。
🛠️ 主要功能
- 项目初始化:快速创建新项目模板
- 文件操作:批量重命名、格式化、转换
- Git 工具:自动化提交、分支管理
- 部署助手:一键部署到各种平台
- 代码生成:模板化代码生成器
📦 安装使用
全局安装
npm install -g dev-cli-tool
dev-cli --help
本地使用
npx dev-cli-tool init my-project
🎯 核心特性
交互式命令
使用 Inquirer.js 提供友好的交互式界面:
import inquirer from 'inquirer';
const questions = [
{
type: 'list',
name: 'framework',
message: 'Choose a framework:',
choices: ['React', 'Vue', 'Angular', 'Svelte']
},
{
type: 'confirm',
name: 'typescript',
message: 'Use TypeScript?',
default: true
}
];
const answers = await inquirer.prompt(questions);
彩色输出
使用 Chalk 提供美观的终端输出:
import chalk from 'chalk';
console.log(chalk.green('✓ Project created successfully!'));
console.log(chalk.yellow('⚠ Warning: File already exists'));
console.log(chalk.red('✗ Error: Unable to create directory'));
命令结构
基于 Commander.js 构建清晰的命令架构:
import { Command } from 'commander';
const program = new Command();
program
.name('dev-cli')
.description('CLI tool for development automation')
.version('1.0.0');
program
.command('init <name>')
.description('Initialize a new project')
.option('-t, --template <type>', 'project template', 'basic')
.action((name, options) => {
createProject(name, options);
});
🚀 支持的操作
项目模板
- React + TypeScript + Vite
- Next.js 应用
- Node.js 服务器
- Express API
- Vue 3 + Composition API
文件工具
- 批量重命名文件
- 格式化代码
- 图片压缩优化
- 文件类型转换
Git 集成
- 自动化提交流程
- 分支管理
- 版本标签创建
- 变更日志生成
📈 使用统计
这个工具已经帮助:
- 创建了 100+ 个项目
- 节省了 50+ 小时的重复工作
- 标准化了团队开发流程
🔮 未来计划
- 支持更多框架模板
- 集成 Docker 容器化
- 添加测试自动化
- 彩色终端输出
- 交互式命令界面