#!/usr/bin/env node /** * DrawNote Skill 安装验证和修复工具 * 检查依赖是否正确安装,并提供修复选项 */ const fs = require('fs'); const path = require('path'); const { spawn, execSync } = require('child_process'); console.log('🔍 DrawNote Skill 安装验证工具'); console.log('================================'); const skillDir = path.dirname(__dirname); const nodeModulesDir = path.join(skillDir, 'node_modules'); const playwrightDir = path.join(nodeModulesDir, 'playwright'); const packageJsonPath = path.join(skillDir, 'package.json'); // 验证函数 function verifyInstallation() { const issues = []; // 检查基本文件 if (!fs.existsSync(packageJsonPath)) { issues.push('❌ package.json 不存在'); } // 检查 node_modules if (!fs.existsSync(nodeModulesDir)) { issues.push('❌ node_modules 目录不存在'); } else { // 检查 playwright if (!fs.existsSync(playwrightDir)) { issues.push('❌ Playwright 模块不存在'); } // 检查其他依赖 const requiredPackages = ['playwright', 'playwright-core']; requiredPackages.forEach(pkg => { const pkgPath = path.join(nodeModulesDir, pkg); if (!fs.existsSync(pkgPath)) { issues.push(`❌ ${pkg} 包不存在`); } }); } return issues; } // 修复函数 function attemptFix(issues) { console.log('\n🔧 尝试自动修复...'); try { // 检查 npm 是否可用 execSync('which npm', { stdio: 'ignore' }); } catch (error) { console.log('❌ npm 不可用,请先安装 Node.js 和 npm'); return false; } console.log('📦 运行 npm install...'); const installProcess = spawn('npm', ['install'], { cwd: skillDir, stdio: 'inherit' }); return new Promise((resolve) => { installProcess.on('close', (code) => { if (code === 0) { console.log('✅ npm install 完成'); resolve(true); } else { console.log(`❌ npm install 失败,退出码: ${code}`); resolve(false); } }); installProcess.on('error', (error) => { console.error('❌ 安装过程出错:', error.message); resolve(false); }); }); } // 测试截图功能 function testScreenshotFunction() { console.log('\n🧪 测试截图功能...'); try { // 创建测试 HTML const testHtml = `