#!/usr/bin/env python3
|
"""
|
Art Design Pro Skill 初始化配置
|
|
运行此脚本以适配当前项目配置:
|
python init.py
|
|
功能:
|
- 自动检测项目类型(完整 ADP / 部分集成 / 未集成)
|
- 自动检测项目配置
|
- 生成 project-config.json
|
"""
|
|
import json
|
import sys
|
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 ProjectDetector:
|
"""项目类型检测器"""
|
|
def __init__(self, project_root):
|
self.project_root = Path(project_root)
|
|
def detect_project_type(self):
|
"""检测项目类型"""
|
print("🔍 检测项目类型...")
|
|
# 检查 1: 是否是完整 Art Design Pro 项目
|
if self._is_full_adp_project():
|
return "full_adp"
|
|
# 检查 2: 是否部分集成
|
if self._is_partial_integration():
|
return "partial"
|
|
# 检查 3: 未集成
|
return "none"
|
|
def _is_full_adp_project(self):
|
"""检测是否是完整的 Art Design Pro 项目"""
|
checks = []
|
|
# 检查关键目录
|
checks.append((self.project_root / "src" / "components" / "core").exists())
|
checks.append((self.project_root / "src" / "hooks" / "core").exists())
|
checks.append((self.project_root / "src" / "views" / "examples").exists())
|
checks.append((self.project_root / "src" / "views" / "system").exists())
|
|
# 检查 README 或 package.json
|
readme = self.project_root / "README.md"
|
if readme.exists():
|
with open(readme, encoding="utf-8", errors="ignore") as f:
|
content = f.read()
|
checks.append("Art Design Pro" in content or "art-design-pro" in content)
|
|
# 至少 5 项检查通过才认为是完整项目
|
return sum(checks) >= 5
|
|
def _is_partial_integration(self):
|
"""检测是否部分集成"""
|
# 至少有组件目录
|
components_dir = self.project_root / "src" / "components" / "core"
|
if not components_dir.exists():
|
return False
|
|
# 检查是否有足够多的组件(递归查找所有子目录)
|
components = list(components_dir.glob("**/index.vue"))
|
return len(components) >= 30
|
|
def check_dependencies(self):
|
"""检查依赖安装"""
|
print("\n📦 检查依赖...")
|
|
package_json = self.project_root / "package.json"
|
if not package_json.exists():
|
return {"installed": False, "missing": ["package.json 不存在"]}
|
|
with open(package_json, encoding="utf-8", errors="ignore") as f:
|
try:
|
deps = json.load(f)
|
except json.JSONDecodeError:
|
return {"installed": False, "missing": ["package.json 格式错误"]}
|
|
required = [
|
"vue", "vue-router", "pinia", "element-plus", "axios", "echarts"
|
]
|
|
missing = []
|
for dep in required:
|
if dep not in deps.get("dependencies", {}):
|
missing.append(dep)
|
|
if missing:
|
return {"installed": False, "missing": missing}
|
else:
|
return {"installed": True, "missing": []}
|
|
def check_build_config(self):
|
"""检查构建配置"""
|
print("\n⚙️ 检查构建配置...")
|
|
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:
|
return {"configured": False, "issues": ["vite.config.js 不存在"]}
|
|
with open(vite_config, encoding="utf-8", errors="ignore") as f:
|
content = f.read()
|
|
issues = []
|
|
# 检查必需的插件
|
if "unplugin-auto-import" not in content:
|
issues.append("缺少 unplugin-auto-import")
|
if "unplugin-vue-components" not in content:
|
issues.append("缺少 unplugin-vue-components")
|
if "ElementPlusResolver" not in content:
|
issues.append("缺少 ElementPlusResolver")
|
if "'@/'" not in content and '"@/"' not in content:
|
issues.append("缺少路径别名配置")
|
|
if issues:
|
return {"configured": False, "issues": issues}
|
else:
|
return {"configured": True, "issues": []}
|
|
def check_components(self):
|
"""检查组件安装"""
|
print("\n🧩 检查组件...")
|
|
components_dir = self.project_root / "src" / "components" / "core"
|
if not components_dir.exists():
|
return {"installed": False, "count": 0, "status": "目录不存在"}
|
|
components = list(components_dir.glob("**/index.vue"))
|
count = len(components)
|
|
if count == 0:
|
return {"installed": False, "count": 0, "status": "无组件"}
|
elif count < 50:
|
return {"installed": False, "count": count, "status": "不完整"}
|
else:
|
return {"installed": True, "count": count, "status": "完整"}
|
|
def generate_integration_report(self):
|
"""生成集成报告"""
|
print("\n" + "="*60)
|
print("📊 Art Design Pro 集成状态报告")
|
print("="*60)
|
|
project_type = self.detect_project_type()
|
|
if project_type == "full_adp":
|
print("\n✅ 检测结果:完整的 Art Design Pro 项目")
|
print("\n🎉 所有组件已就绪!你可以:")
|
print(" 1. 使用 search.py 查找组件")
|
print(" python skill/art-design-pro/scripts/search.py table")
|
print(" 2. 使用 generate.py 生成代码")
|
print(" python skill/art-design-pro/scripts/generate.py --help")
|
print(" 3. 查看 INTEGRATION_GUIDE.md 了解集成详情")
|
print(" 4. 查看 docs/ 目录中的文档")
|
|
return True
|
|
elif project_type == "partial":
|
print("\n⚠️ 检测结果:部分集成 Art Design Pro")
|
|
# 详细检查
|
deps = self.check_dependencies()
|
config = self.check_build_config()
|
components = self.check_components()
|
|
print("\n发现的问题:")
|
|
if not deps["installed"]:
|
print(f"\n❌ 依赖问题:")
|
for dep in deps["missing"][:3]:
|
print(f" - {dep}")
|
print(" 修复: pnpm add " + " ".join(deps["missing"]))
|
|
if not config["configured"]:
|
print(f"\n❌ 配置问题:")
|
for issue in config["issues"]:
|
print(f" - {issue}")
|
print(" 修复: 参考 templates/vite.config.js.template")
|
|
if not components["installed"]:
|
print(f"\n⚠️ 组件问题: {components['status']}({components['count']} 个)")
|
print(" 建议: 检查组件目录是否完整")
|
|
print("\n💡 下一步操作:")
|
print(" 1. 修复上述问题")
|
print(" 2. 运行验证脚本: python skill/art-design-pro/scripts/verify.py")
|
print(" 3. 查看集成指南: INTEGRATION_GUIDE.md")
|
|
return False
|
|
else: # project_type == "none"
|
print("\n❌ 检测结果:未集成 Art Design Pro")
|
|
print("\n💡 你需要先集成 Art Design Pro:")
|
print("\n 推荐方式:克隆完整项目")
|
print(" git clone https://github.com/Daymychen/art-design-pro.git your-project")
|
print(" cd your-project")
|
print(" pnpm install")
|
print(" pnpm dev")
|
|
print("\n 或查看集成指南:")
|
print(" 📄 INTEGRATION_GUIDE.md - 完整的集成步骤")
|
|
return False
|
|
|
# ==================== 原有功能保持不变 ====================
|
|
def get_config_path():
|
"""获取配置文件路径"""
|
return Path(__file__).parent.parent / "project-config.json"
|
|
|
def load_config():
|
"""加载当前配置"""
|
config_path = get_config_path()
|
if config_path.exists():
|
with open(config_path, 'r', encoding='utf-8') as f:
|
return json.load(f)
|
return None
|
|
|
def save_config(config):
|
"""保存配置"""
|
config_path = get_config_path()
|
with open(config_path, 'w', encoding='utf-8') as f:
|
json.dump(config, f, indent=2, ensure_ascii=False)
|
print(f"✅ 配置已保存到: {config_path}")
|
|
|
def auto_detect_project():
|
"""自动检测项目配置"""
|
skill_path = Path(__file__).parent.parent
|
project_root = skill_path.parent.parent
|
|
config = {
|
"project": {
|
"name": project_root.name,
|
"root": str(project_root)
|
},
|
"paths": {},
|
"artDesignPro": {},
|
"generation": {}
|
}
|
|
# 检测前端目录
|
possible_src = [
|
project_root / "frontend" / "src",
|
project_root / "src",
|
project_root / "client" / "src",
|
]
|
|
src_dir = None
|
for path in possible_src:
|
if path.exists():
|
src_dir = path
|
break
|
|
if src_dir:
|
config["paths"]["src"] = str(src_dir.relative_to(project_root))
|
config["paths"]["views"] = f"{src_dir.relative_to(project_root)}/views"
|
config["paths"]["components"] = f"{src_dir.relative_to(project_root)}/components"
|
config["paths"]["router"] = f"{src_dir.relative_to(project_root)}/router"
|
config["paths"]["api"] = f"{src_dir.relative_to(project_root)}/api"
|
|
# 检测 Art Design Pro 组件
|
core_components = src_dir / "components" / "core"
|
if core_components.exists():
|
config["artDesignPro"]["componentsPath"] = f"{src_dir.relative_to(project_root)}/components/core"
|
|
# 检测示例目录
|
examples = src_dir / "views" / "examples"
|
if examples.exists():
|
config["artDesignPro"]["examplesPath"] = f"{src_dir.relative_to(project_root)}/views/examples"
|
|
# 检测系统目录
|
system = src_dir / "views" / "system"
|
if system.exists():
|
config["artDesignPro"]["systemPath"] = f"{src_dir.relative_to(project_root)}/views/system"
|
|
config["generation"]["outputPath"] = f"{src_dir.relative_to(project_root)}/views"
|
config["generation"]["useJavaScript"] = False
|
config["generation"]["useJavaScript"] = True
|
config["generation"]["useCompositionAPI"] = True
|
|
return config
|
|
|
def interactive_config():
|
"""交互式配置"""
|
print("🚀 Art Design Pro Skill 初始化配置\n")
|
print("请回答以下问题以配置 skill(直接回车使用默认值):\n")
|
|
config = {
|
"project": {
|
"name": input("项目名称: ").strip() or "your-project"
|
},
|
"paths": {},
|
"artDesignPro": {},
|
"generation": {
|
"useJavaScript": False,
|
"useJavaScript": True,
|
"useCompositionAPI": True
|
}
|
}
|
|
# 路径配置
|
src = input(f"源代码目录 [src]: ").strip() or "src"
|
config["paths"]["src"] = src
|
config["paths"]["views"] = f"{src}/views"
|
config["paths"]["components"] = f"{src}/components"
|
config["paths"]["router"] = f"{src}/router"
|
config["paths"]["api"] = f"{src}/api"
|
|
# Art Design Pro 配置
|
comp_path = input(f"Art Design Pro 组件路径 [src/components/core]: ").strip() or "src/components/core"
|
config["artDesignPro"]["componentsPath"] = comp_path
|
|
examples_path = input(f"示例页面路径 [src/views/examples]: ").strip() or "src/views/examples"
|
config["artDesignPro"]["examplesPath"] = examples_path
|
|
# 代码生成配置
|
output_path = input(f"生成代码输出路径 [src/views]: ").strip() or "src/views"
|
config["generation"]["outputPath"] = output_path
|
|
return config
|
|
|
def main():
|
"""主函数"""
|
import argparse
|
|
parser = argparse.ArgumentParser(description='Art Design Pro Skill 初始化配置')
|
parser.add_argument('--check', '-c', action='store_true', help='检查项目集成状态')
|
parser.add_argument('--auto', '-a', action='store_true', help='自动检测并生成配置')
|
args = parser.parse_args()
|
|
# 如果是检查模式
|
if args.check:
|
skill_path = Path(__file__).parent.parent
|
project_root = skill_path.parent.parent
|
|
detector = ProjectDetector(project_root)
|
detector.generate_integration_report()
|
return
|
|
print("=" * 60)
|
print("Art Design Pro Skill - 初始化配置")
|
print("=" * 60)
|
print()
|
|
# 检查是否已有配置
|
existing_config = load_config()
|
if existing_config and not args.auto:
|
print(f"📋 当前配置:")
|
print(json.dumps(existing_config, indent=2, ensure_ascii=False))
|
print()
|
choice = input("是否重新配置? (y/N): ").strip().lower()
|
if choice != 'y':
|
print("✅ 保持现有配置")
|
print()
|
print("💡 提示: 使用 --check 选项检查集成状态")
|
return
|
|
# 选择配置方式
|
if args.auto:
|
print("\n🔍 使用自动检测模式...")
|
choice = "1"
|
else:
|
print("\n配置方式:")
|
print("1. 自动检测(推荐)")
|
print("2. 手动配置")
|
choice = input("\n请选择 (1/2): ").strip() or "1"
|
|
if choice == "1":
|
print("\n🔍 正在自动检测项目配置...")
|
config = auto_detect_project()
|
print("✅ 自动检测完成")
|
else:
|
config = interactive_config()
|
|
# 保存配置
|
save_config(config)
|
|
# 显示配置摘要
|
print("\n" + "=" * 60)
|
print("配置摘要:")
|
print("=" * 60)
|
print(f"项目名称: {config['project']['name']}")
|
print(f"源代码目录: {config['paths'].get('src', 'src')}")
|
print(f"组件路径: {config['artDesignPro'].get('componentsPath', 'src/components/core')}")
|
print(f"生成输出: {config['generation'].get('outputPath', 'src/views')}")
|
print()
|
print("✅ 初始化完成!现在可以使用 skill 了。")
|
print()
|
print("下一步:")
|
print(" 1. 测试组件搜索: python scripts/search.py table")
|
print(" 2. 生成代码: python scripts/generate.py crud --name 'User' --path 'system/user' --fields 'username,email'")
|
print(" 3. 检查集成状态: python scripts/verify.py")
|
print()
|
|
|
if __name__ == "__main__":
|
main()
|