zhou zhou
2026-03-27 fec285d150b377d004e47f0973d298b92fe4c711
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/usr/bin/env python3
"""
Art Design Pro 集成验证工具
 
用法:
  python scripts/verify.py
  python scripts/verify.py --verbose
 
功能:
  检查项目的 Art Design Pro 集成状态,包括依赖、配置、组件等
"""
 
import os
import sys
import json
from pathlib import Path
 
if hasattr(sys.stdout, "reconfigure"):
    sys.stdout.reconfigure(encoding="utf-8")
if hasattr(sys.stderr, "reconfigure"):
    sys.stderr.reconfigure(encoding="utf-8")
 
 
class IntegrationVerifier:
    def __init__(self, project_root=None, verbose=False):
        # 如果未指定项目根目录,使用当前目录
        self.project_root = Path(project_root) if project_root else Path.cwd()
        self.verbose = verbose
        self.issues = []
        self.warnings = []
        self.success = []
 
    def log(self, message):
        """打印日志"""
        print(message)
 
    def check_dependencies(self):
        """检查依赖安装情况"""
        self.log("\n📦 检查依赖...")
 
        package_json = self.project_root / 'package.json'
        if not package_json.exists():
            self.issues.append("❌ package.json 不存在")
            self.log("  ❌ package.json 不存在")
            return False
 
        with open(package_json, encoding='utf-8', errors='ignore') as f:
            try:
                deps = json.load(f)
            except json.JSONDecodeError:
                self.issues.append("❌ package.json 格式错误")
                self.log("  ❌ package.json 格式错误")
                return False
 
        # 必需的生产依赖
        required_deps = [
            'vue', 'vue-router', 'pinia',
            'element-plus', 'axios', 'echarts'
        ]
 
        # 必需的开发依赖
        required_dev_deps = [
            'vite',
            'unplugin-auto-import',
            'unplugin-vue-components',
            'unplugin-element-plus'
        ]
 
        missing = []
 
        # 检查生产依赖
        for dep in required_deps:
            if dep not in deps.get('dependencies', {}):
                missing.append(f"{dep} (dependencies)")
 
        # 检查开发依赖
        for dep in required_dev_deps:
            if dep not in deps.get('devDependencies', {}):
                missing.append(f"{dep} (devDependencies)")
 
        if missing:
            issue = f"❌ 缺少依赖: {', '.join(missing[:3])}"
            if len(missing) > 3:
                issue += f" 等 {len(missing)} 个"
            self.issues.append(issue)
            self.log(f"  {issue}")
            return False
        else:
            self.log("  ✅ dependencies: 所有必需依赖已安装")
            self.success.append("dependencies")
            return True
 
    def check_vite_config(self):
        """检查 Vite 配置"""
        self.log("\n⚙️  检查 Vite 配置...")
 
        vite_config = None
        for candidate in ['vite.config.js', 'vite.config.mjs', 'vite.config.cjs', 'vite.config.js']:
            config_path = self.project_root / candidate
            if config_path.exists():
                vite_config = config_path
                break
 
        if not vite_config:
            self.issues.append("❌ vite.config.js 不存在")
            self.log("  ❌ vite.config.js 不存在")
            return False
 
        with open(vite_config, encoding='utf-8', errors='ignore') as f:
            content = f.read()
 
        # 检查关键配置项
        checks = {
            'unplugin-auto-import': 'unplugin-auto-import' in content,
            'unplugin-vue-components': 'unplugin-vue-components' in content,
            'ElementPlusResolver': 'ElementPlusResolver' in content,
            'path alias': ('@/' in content or "'@':" in content or '"@":' in content),
            'tailwindcss': 'tailwindcss' in content.lower()
        }
 
        issues = [name for name, passed in checks.items() if not passed]
        if issues:
            issue = f"❌ build_config: 缺少或配置错误: {', '.join(issues)}"
            self.issues.append(issue)
            self.log(f"  {issue}")
 
            if self.verbose:
                self.log("  详细说明:")
                if 'unplugin-auto-import' in issues:
                    self.log("    - 缺少 unplugin-auto-import 配置")
                if 'path alias' in issues:
                    self.log("    - 缺少路径别名配置(@/)")
                self.log("  参考: templates/vite.config.js.template")
            return False
        else:
            self.log("  ✅ build_config: Vite 配置正确")
            self.success.append("build_config")
            return True
 
    def check_components(self):
        """检查组件安装"""
        self.log("\n🧩 检查组件...")
 
        components_dir = self.project_root / 'src' / 'components' / 'core'
        if not components_dir.exists():
            self.issues.append("❌ components: src/components/core 目录不存在")
            self.log("  ❌ components: src/components/core 目录不存在")
            self.log("  建议: 先运行 python scripts/init.py")
            return False
 
        # 统计组件数量(递归查找所有子目录)
        components = list(components_dir.glob('**/index.vue'))
        component_count = len(components)
 
        if component_count < 50:
            warning = f"⚠️  components: 只找到 {component_count} 个组件(预期 56+)"
            self.warnings.append(warning)
            self.log(f"  {warning}")
 
            if self.verbose:
                self.log("  组件可能不完整,建议重新复制组件目录")
            return False
        else:
            self.log(f"  ✅ components: 找到 {component_count} 个组件")
            self.success.append("components")
            return True
 
    def check_js_runtime_config(self):
        """检查 JS 版自动导入配置"""
        self.log("\n📝 检查 JS 运行时配置...")
 
        auto_import_config = self.project_root / '.auto-import.json'
        if auto_import_config.exists():
            self.log("  ✅ auto-import: ESLint 自动导入配置存在")
            self.success.append("auto-import")
            return True
 
        warning = "⚠️  auto-import: 未找到 .auto-import.json,可能尚未运行过构建或 dev"
        self.warnings.append(warning)
        self.log(f"  {warning}")
        return False
 
    def run_all_checks(self):
        """运行所有检查"""
        print("="*60)
        print("🔍 Art Design Pro 集成验证")
        print("="*60)
        print()
 
        # 检查项目根目录
        self.log(f"📁 项目目录: {self.project_root}")
 
        # 执行各项检查
        deps_ok = self.check_dependencies()
        vite_ok = self.check_vite_config()
        components_ok = self.check_components()
        auto_import_ok = self.check_js_runtime_config()
 
        print()
        print("="*60)
        print("📊 验证完成")
        print("="*60)
 
        # 输出结果
        all_good = not self.issues and not self.warnings
 
        if self.success:
            print(f"\n✅ 通过的检查 ({len(self.success)}):")
            for item in self.success:
                print(f"  ✅ {item}")
 
        if self.warnings:
            print(f"\n⚠️  警告 ({len(self.warnings)}):")
            for warning in self.warnings:
                print(f"  {warning}")
 
        if self.issues:
            print(f"\n❌ 发现问题 ({len(self.issues)}):")
            for issue in self.issues:
                print(f"  {issue}")
 
        # 给出修复建议
        if self.issues:
            print("\n💡 修复建议:")
            if "package.json" in " ".join(self.issues):
                print("  1. 安装缺失依赖")
                print("     pnpm add <缺失的依赖>")
            if "vite.config.js" in " ".join(self.issues):
                print("  2. 更新 Vite 配置")
                print("     参考: templates/vite.config.js.template")
            if "components/core" in " ".join(self.issues):
                print("  3. 复制 Art Design Pro 组件")
                print("     详见: INTEGRATION_GUIDE.md")
            print("  4. 运行: python scripts/init.py")
 
        # 返回退出码
        if all_good:
            print("\n🎉 所有检查通过!你的项目已正确集成 Art Design Pro")
            return 0
        elif not self.issues:
            print("\n✨ 集成基本完成,有一些小警告但不影响使用")
            return 0
        else:
            print("\n❌ 集成存在问题,请按照提示修复")
            return 1
 
 
def main():
    import argparse
 
    parser = argparse.ArgumentParser(description='Art Design Pro 集成验证工具')
    parser.add_argument('--verbose', '-v', action='store_true', help='显示详细输出')
    parser.add_argument('--project-root', '-p', type=str, help='项目根目录(默认当前目录)')
 
    args = parser.parse_args()
 
    verifier = IntegrationVerifier(
        project_root=args.project_root,
        verbose=args.verbose
    )
 
    sys.exit(verifier.run_all_checks())
 
 
if __name__ == '__main__':
    main()