239 lines
6.2 KiB
Batchfile
239 lines
6.2 KiB
Batchfile
@echo off
|
||
chcp 65001 >nul
|
||
setlocal enabledelayedexpansion
|
||
|
||
:: PromptForge Windows 自动化安装脚本
|
||
|
||
echo ================================
|
||
echo PromptForge 自动化安装脚本
|
||
echo ================================
|
||
echo.
|
||
|
||
:: 颜色定义
|
||
set "RED=[91m"
|
||
set "GREEN=[92m"
|
||
set "YELLOW=[93m"
|
||
set "BLUE=[94m"
|
||
set "NC=[0m"
|
||
|
||
:: 打印带颜色的消息
|
||
:print_message
|
||
echo %GREEN%[INFO]%NC% %~1
|
||
goto :eof
|
||
|
||
:print_warning
|
||
echo %YELLOW%[WARNING]%NC% %~1
|
||
goto :eof
|
||
|
||
:print_error
|
||
echo %RED%[ERROR]%NC% %~1
|
||
goto :eof
|
||
|
||
:: 检查系统要求
|
||
call :print_message "检查系统要求..."
|
||
|
||
:: 检查 Windows 版本
|
||
for /f "tokens=4-5 delims=. " %%i in ('ver') do set VERSION=%%i.%%j
|
||
if %VERSION% LSS 10.0 (
|
||
call :print_error "Windows 版本过低,需要 Windows 10 或更高版本"
|
||
pause
|
||
exit /b 1
|
||
) else (
|
||
call :print_message "Windows 版本检查通过: %VERSION%"
|
||
)
|
||
|
||
:: 检查内存
|
||
for /f "tokens=2 delims==" %%a in ('wmic computersystem get TotalPhysicalMemory /value') do set MEMORY=%%a
|
||
set /a MEMORY_GB=%MEMORY:~0,-1%/1024/1024/1024
|
||
if %MEMORY_GB% LSS 4 (
|
||
call :print_warning "内存不足,推荐至少 4GB RAM,当前: %MEMORY_GB%GB"
|
||
) else (
|
||
call :print_message "内存检查通过: %MEMORY_GB%GB"
|
||
)
|
||
|
||
:: 检查磁盘空间
|
||
for /f "tokens=3" %%a in ('dir /-c ^| find "bytes free"') do set DISK_SPACE=%%a
|
||
set /a DISK_SPACE_GB=%DISK_SPACE:~0,-1%/1024/1024/1024
|
||
if %DISK_SPACE_GB% LSS 2 (
|
||
call :print_warning "磁盘空间不足,推荐至少 2GB,当前: %DISK_SPACE_GB%GB"
|
||
) else (
|
||
call :print_message "磁盘空间检查通过: %DISK_SPACE_GB%GB"
|
||
)
|
||
|
||
:: 检查 Node.js
|
||
call :print_message "检查 Node.js..."
|
||
|
||
node --version >nul 2>&1
|
||
if %errorlevel% neq 0 (
|
||
call :print_warning "Node.js 未安装"
|
||
call :install_nodejs
|
||
) else (
|
||
for /f "tokens=*" %%i in ('node --version') do set NODE_VERSION=%%i
|
||
call :print_message "Node.js 版本检查通过: %NODE_VERSION%"
|
||
)
|
||
|
||
:: 检查 npm
|
||
npm --version >nul 2>&1
|
||
if %errorlevel% neq 0 (
|
||
call :print_error "npm 未安装"
|
||
pause
|
||
exit /b 1
|
||
) else (
|
||
for /f "tokens=*" %%i in ('npm --version') do set NPM_VERSION=%%i
|
||
call :print_message "npm 版本: v%NPM_VERSION%"
|
||
)
|
||
|
||
:: 检查 MySQL
|
||
call :print_message "检查 MySQL..."
|
||
|
||
mysql --version >nul 2>&1
|
||
if %errorlevel% neq 0 (
|
||
call :print_warning "MySQL 未安装"
|
||
call :install_mysql
|
||
) else (
|
||
for /f "tokens=*" %%i in ('mysql --version') do set MYSQL_VERSION=%%i
|
||
call :print_message "MySQL 版本检查通过: %MYSQL_VERSION%"
|
||
)
|
||
|
||
:: 检查 Git
|
||
call :print_message "检查 Git..."
|
||
|
||
git --version >nul 2>&1
|
||
if %errorlevel% neq 0 (
|
||
call :print_warning "Git 未安装"
|
||
call :install_git
|
||
) else (
|
||
for /f "tokens=*" %%i in ('git --version') do set GIT_VERSION=%%i
|
||
call :print_message "Git 版本检查通过: %GIT_VERSION%"
|
||
)
|
||
|
||
:: 安装项目依赖
|
||
call :print_message "安装项目依赖..."
|
||
|
||
if exist "package.json" (
|
||
npm install
|
||
if %errorlevel% neq 0 (
|
||
call :print_error "项目依赖安装失败"
|
||
pause
|
||
exit /b 1
|
||
) else (
|
||
call :print_message "项目依赖安装完成"
|
||
)
|
||
) else (
|
||
call :print_error "package.json 文件不存在"
|
||
pause
|
||
exit /b 1
|
||
)
|
||
|
||
:: 配置环境变量
|
||
call :print_message "配置环境变量..."
|
||
|
||
if not exist ".env.local" (
|
||
if exist ".env.example" (
|
||
copy ".env.example" ".env.local" >nul
|
||
call :print_message "已创建 .env.local 文件"
|
||
call :print_warning "请编辑 .env.local 文件,填入您的配置信息"
|
||
) else (
|
||
call :print_warning ".env.example 文件不存在,请手动创建 .env.local 文件"
|
||
)
|
||
) else (
|
||
call :print_message ".env.local 文件已存在"
|
||
)
|
||
|
||
:: 设置数据库
|
||
call :print_message "设置数据库..."
|
||
|
||
if exist "create-tables-final.js" (
|
||
call :print_message "创建数据库表..."
|
||
node create-tables-final.js
|
||
if %errorlevel% neq 0 (
|
||
call :print_warning "数据库表创建失败"
|
||
)
|
||
) else (
|
||
call :print_warning "数据库脚本不存在,跳过数据库设置"
|
||
)
|
||
|
||
if exist "create-template-data.js" (
|
||
call :print_message "创建测试数据..."
|
||
node create-template-data.js
|
||
if %errorlevel% neq 0 (
|
||
call :print_warning "测试数据创建失败"
|
||
)
|
||
) else (
|
||
call :print_warning "测试数据脚本不存在,跳过数据创建"
|
||
)
|
||
|
||
:: 验证安装
|
||
call :print_message "验证安装..."
|
||
|
||
:: 检查关键文件
|
||
set "FILES=package.json next.config.js src\app\layout.tsx"
|
||
for %%f in (%FILES%) do (
|
||
if exist "%%f" (
|
||
call :print_message "✓ %%f 存在"
|
||
) else (
|
||
call :print_warning "⚠ %%f 不存在"
|
||
)
|
||
)
|
||
|
||
:: 检查依赖
|
||
if exist "node_modules" (
|
||
call :print_message "✓ node_modules 目录存在"
|
||
) else (
|
||
call :print_error "✗ node_modules 目录不存在"
|
||
)
|
||
|
||
:: 类型检查
|
||
call :print_message "运行 TypeScript 类型检查..."
|
||
npm run type-check >nul 2>&1
|
||
if %errorlevel% neq 0 (
|
||
call :print_warning "⚠ TypeScript 类型检查失败"
|
||
) else (
|
||
call :print_message "✓ TypeScript 类型检查通过"
|
||
)
|
||
|
||
:: 显示后续步骤
|
||
echo.
|
||
echo %BLUE%================================%NC%
|
||
echo %BLUE% 安装完成!后续步骤:%NC%
|
||
echo %BLUE%================================%NC%
|
||
echo.
|
||
echo 1. 编辑 .env.local 文件,配置数据库和 API 密钥
|
||
echo 2. 启动开发服务器: npm run dev
|
||
echo 3. 访问 http://localhost:3000
|
||
echo 4. 注册新账户并开始使用
|
||
echo.
|
||
echo 📖 更多信息请查看:
|
||
echo - 安装指南: INSTALLATION_GUIDE.md
|
||
echo - 环境配置: ENV_SETUP_GUIDE.md
|
||
echo - 模板教程: TEMPLATE_TUTORIAL.md
|
||
echo.
|
||
echo 🚀 祝您使用愉快!
|
||
echo.
|
||
pause
|
||
goto :eof
|
||
|
||
:: 安装 Node.js
|
||
:install_nodejs
|
||
call :print_message "安装 Node.js..."
|
||
call :print_warning "请手动安装 Node.js: https://nodejs.org/"
|
||
call :print_warning "安装完成后重新运行此脚本"
|
||
pause
|
||
exit /b 1
|
||
|
||
:: 安装 MySQL
|
||
:install_mysql
|
||
call :print_message "安装 MySQL..."
|
||
call :print_warning "请手动安装 MySQL: https://dev.mysql.com/downloads/mysql/"
|
||
call :print_warning "安装完成后重新运行此脚本"
|
||
pause
|
||
exit /b 1
|
||
|
||
:: 安装 Git
|
||
:install_git
|
||
call :print_message "安装 Git..."
|
||
call :print_warning "请手动安装 Git: https://git-scm.com/"
|
||
call :print_warning "安装完成后重新运行此脚本"
|
||
pause
|
||
exit /b 1
|