66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
启动脚本生成模块
|
|
"""
|
|
|
|
|
|
def create_bat_scripts(project_root, project_name, frontend_type, backend_type):
|
|
"""创建启动脚本"""
|
|
print("\n📝 创建启动脚本...")
|
|
|
|
# 前端启动命令
|
|
frontend_start_cmd = "npm run dev"
|
|
|
|
# 后端启动命令
|
|
backend_start_commands = {
|
|
"golang": "go run main.go",
|
|
"gin": "go run main.go",
|
|
"flask": "venv\\Scripts\\python app.py",
|
|
"fastapi": "venv\\Scripts\\python main.py",
|
|
"django": "venv\\Scripts\\python run.py",
|
|
"spring": "mvn spring-boot:run",
|
|
"express": "npm run dev",
|
|
"nestjs": "npm run start:dev"
|
|
}
|
|
backend_start_cmd = backend_start_commands.get(backend_type, "echo 未知后端类型")
|
|
|
|
# 1. 开启前端.bat
|
|
start_frontend = project_root / "开启前端.bat"
|
|
start_frontend.write_text(f'''@echo off
|
|
chcp 65001 >nul
|
|
echo ====================================
|
|
echo 启动前端项目 ({frontend_type.upper()})
|
|
echo ====================================
|
|
cd {project_name}-frontend
|
|
{frontend_start_cmd}
|
|
pause
|
|
''', encoding='utf-8')
|
|
|
|
# 2. 开启后端.bat
|
|
start_backend = project_root / "开启后端.bat"
|
|
start_backend.write_text(f'''@echo off
|
|
chcp 65001 >nul
|
|
echo ====================================
|
|
echo 启动后端项目 ({backend_type.upper()})
|
|
echo ====================================
|
|
cd {project_name}-backend
|
|
{backend_start_cmd}
|
|
pause
|
|
''', encoding='utf-8')
|
|
|
|
# 3. 构建前端.bat
|
|
build_frontend = project_root / "构建前端.bat"
|
|
build_frontend.write_text(f'''@echo off
|
|
chcp 65001 >nul
|
|
echo ====================================
|
|
echo 构建前端项目 ({frontend_type.upper()})
|
|
echo ====================================
|
|
cd {project_name}-frontend
|
|
npm run build
|
|
echo.
|
|
echo ✅ 构建完成!输出目录: dist
|
|
pause
|
|
''', encoding='utf-8')
|
|
|
|
print("✅ 启动脚本创建成功")
|