#!/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()
|