#!/usr/bin/env node import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // 读取开发工具配置 const configPath = path.join(__dirname, '../.dev-tools-config.json'); const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); // 获取命令行参数 const args = process.argv.slice(2); const enableAll = args.includes('--enable'); const disableAll = args.includes('--disable'); console.log('🔧 开发工具设置脚本'); console.log('===================='); // 更新配置文件 function updateConfig(config) { fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); console.log('✅ 配置文件已更新'); } // 检查工具状态 function checkToolStatus(toolName, toolConfig) { return toolConfig.enabled ? '✅ 已启用' : '❌ 已禁用'; } // 设置工具状态 function setToolStatus(toolName, enabled) { config.tools[toolName].enabled = enabled; const status = enabled ? '启用' : '禁用'; console.log(`${enabled ? '✅' : '❌'} ${toolName}: ${status}`); } // 主逻辑 if (enableAll) { console.log('🔓 启用所有开发工具...'); Object.keys(config.tools).forEach(toolName => { setToolStatus(toolName, true); }); updateConfig(config); console.log('\n🎉 所有开发工具已启用!运行以下命令使用:'); console.log(' npm run lint # ESLint检查'); console.log(' npm run lint:fix # ESLint自动修复'); console.log(' npm run format # Prettier格式化'); console.log(' npm run format:check # Prettier检查'); } else if (disableAll) { console.log('🔒 禁用所有开发工具...'); Object.keys(config.tools).forEach(toolName => { setToolStatus(toolName, false); }); updateConfig(config); console.log('\n🛌 所有开发工具已禁用!'); } else { console.log('📊 当前开发工具状态:'); Object.entries(config.tools).forEach(([toolName, toolConfig]) => { console.log(` ${checkToolStatus(toolName, toolConfig)} ${toolName} - ${toolConfig.description}`); }); console.log('\n📖 使用说明:'); console.log(' npm run scripts:setup # 查看当前状态'); console.log(' npm run scripts:enable # 启用所有工具'); console.log(' npm run scripts:disable # 禁用所有工具'); console.log('\n💡 提示:也可以直接编辑 .dev-tools-config.json 文件来单独控制每个工具'); }