96 lines
3.1 KiB
Python
96 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
前后端分离项目初始化脚本 - 主程序
|
|
"""
|
|
|
|
import sys
|
|
from utils import print_banner, get_project_name, select_frontend, select_backend, select_use_tailwind
|
|
from directory import create_directory_structure
|
|
from frontend import init_react_project, init_vue_project, setup_tailwind
|
|
from backend import (
|
|
init_golang_project,
|
|
init_gin_project,
|
|
init_flask_project,
|
|
init_fastapi_project,
|
|
init_django_project,
|
|
init_spring_project,
|
|
init_express_project,
|
|
init_nestjs_project
|
|
)
|
|
from scripts import create_bat_scripts
|
|
|
|
|
|
def main():
|
|
"""主函数"""
|
|
print_banner()
|
|
|
|
# 获取项目信息
|
|
project_name = get_project_name()
|
|
frontend_type = select_frontend()
|
|
use_tailwind = select_use_tailwind()
|
|
backend_type = select_backend()
|
|
|
|
# 创建目录结构
|
|
project_root, frontend_dir, backend_dir = create_directory_structure(project_name)
|
|
|
|
# 初始化前端项目
|
|
if frontend_type == "react":
|
|
init_react_project(frontend_dir, project_name)
|
|
elif frontend_type == "vue":
|
|
init_vue_project(frontend_dir, project_name)
|
|
|
|
# 配置 Tailwind CSS
|
|
if use_tailwind:
|
|
setup_tailwind(frontend_dir, frontend_type)
|
|
|
|
# 初始化后端项目
|
|
if backend_type == "golang":
|
|
init_golang_project(backend_dir, project_name)
|
|
elif backend_type == "gin":
|
|
init_gin_project(backend_dir, project_name)
|
|
elif backend_type == "flask":
|
|
init_flask_project(backend_dir, project_name)
|
|
elif backend_type == "fastapi":
|
|
init_fastapi_project(backend_dir, project_name)
|
|
elif backend_type == "django":
|
|
init_django_project(backend_dir, project_name)
|
|
elif backend_type == "spring":
|
|
init_spring_project(backend_dir, project_name)
|
|
elif backend_type == "express":
|
|
init_express_project(backend_dir, project_name)
|
|
elif backend_type == "nestjs":
|
|
init_nestjs_project(backend_dir, project_name)
|
|
|
|
# 创建 BAT 脚本
|
|
create_bat_scripts(project_root, project_name, frontend_type, backend_type)
|
|
|
|
# 完成
|
|
print("\n" + "=" * 60)
|
|
print("🎉 项目初始化完成!")
|
|
print("=" * 60)
|
|
print(f"\n📁 项目位置: {project_root}")
|
|
print(f" ├── {project_name}-frontend ({frontend_type.upper()})")
|
|
print(f" ├── {project_name}-backend ({backend_type.upper()})")
|
|
print(f" ├── 开启前端.bat")
|
|
print(f" ├── 开启后端.bat")
|
|
print(f" └── 构建前端.bat")
|
|
print("\n💡 使用说明:")
|
|
print(f" 1. 双击 '开启前端.bat' 启动前端开发服务器")
|
|
print(f" 2. 双击 '开启后端.bat' 启动后端服务")
|
|
print(f" 3. 双击 '构建前端.bat' 构建前端生产版本")
|
|
print("\n✨ 祝开发愉快!")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
main()
|
|
except KeyboardInterrupt:
|
|
print("\n\n❌ 操作已取消")
|
|
sys.exit(0)
|
|
except Exception as e:
|
|
print(f"\n❌ 发生错误: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1)
|