100 lines
3.5 KiB
PowerShell
100 lines
3.5 KiB
PowerShell
# Soul派对小程序 - Windows启动脚本
|
||
# 用于启动后端API服务器并指导打开微信开发者工具
|
||
|
||
Write-Host "==================================" -ForegroundColor Cyan
|
||
Write-Host " Soul派对·创业实验 启动脚本 " -ForegroundColor Cyan
|
||
Write-Host "==================================" -ForegroundColor Cyan
|
||
Write-Host ""
|
||
|
||
# 检查Node.js
|
||
try {
|
||
$nodeVersion = node -v
|
||
Write-Host "✅ Node.js版本: $nodeVersion" -ForegroundColor Green
|
||
} catch {
|
||
Write-Host "❌ 错误: 未检测到Node.js,请先安装Node.js" -ForegroundColor Red
|
||
Write-Host "下载地址: https://nodejs.org/" -ForegroundColor Yellow
|
||
exit 1
|
||
}
|
||
|
||
# 检查pnpm
|
||
$packageManager = "npm"
|
||
try {
|
||
$pnpmVersion = pnpm -v
|
||
Write-Host "✅ pnpm版本: $pnpmVersion" -ForegroundColor Green
|
||
$packageManager = "pnpm"
|
||
} catch {
|
||
Write-Host "⚠️ 警告: 未检测到pnpm,将使用npm..." -ForegroundColor Yellow
|
||
try {
|
||
$npmVersion = npm -v
|
||
Write-Host "✅ npm版本: $npmVersion" -ForegroundColor Green
|
||
} catch {
|
||
Write-Host "❌ 错误: 未检测到npm" -ForegroundColor Red
|
||
exit 1
|
||
}
|
||
}
|
||
|
||
Write-Host ""
|
||
Write-Host "1️⃣ 检查依赖..." -ForegroundColor Cyan
|
||
|
||
# 检查是否已安装依赖
|
||
if (-not (Test-Path "node_modules")) {
|
||
Write-Host "📦 正在安装依赖..." -ForegroundColor Yellow
|
||
if ($packageManager -eq "pnpm") {
|
||
pnpm install
|
||
} else {
|
||
npm install
|
||
}
|
||
|
||
if ($LASTEXITCODE -ne 0) {
|
||
Write-Host "❌ 依赖安装失败" -ForegroundColor Red
|
||
exit 1
|
||
}
|
||
} else {
|
||
Write-Host "✅ 依赖已安装" -ForegroundColor Green
|
||
}
|
||
|
||
Write-Host ""
|
||
Write-Host "2️⃣ 检查小程序配置..." -ForegroundColor Cyan
|
||
|
||
# 检查app.js中的API地址配置
|
||
$appJsPath = "miniprogram\app.js"
|
||
if (Test-Path $appJsPath) {
|
||
$appJsContent = Get-Content $appJsPath -Raw
|
||
if ($appJsContent -match "baseUrl:\s*['`"]([^'`"]+)['`"]") {
|
||
$currentApiUrl = $matches[1]
|
||
Write-Host " 当前API地址: $currentApiUrl" -ForegroundColor Gray
|
||
|
||
if ($currentApiUrl -notmatch "localhost") {
|
||
Write-Host "⚠️ 提示: API地址指向生产环境,本地开发建议修改为 http://localhost:3000" -ForegroundColor Yellow
|
||
}
|
||
}
|
||
}
|
||
|
||
Write-Host ""
|
||
Write-Host "3️⃣ 启动后端API服务器..." -ForegroundColor Cyan
|
||
Write-Host ""
|
||
Write-Host "🚀 服务器将运行在: http://localhost:3000" -ForegroundColor Green
|
||
Write-Host "📡 API接口地址: http://localhost:3000/api" -ForegroundColor Green
|
||
Write-Host ""
|
||
Write-Host "📱 下一步操作:" -ForegroundColor Cyan
|
||
Write-Host " 1. 打开微信开发者工具" -ForegroundColor White
|
||
Write-Host " 2. 点击 '导入项目'" -ForegroundColor White
|
||
Write-Host " 3. 选择项目目录: $PWD\miniprogram" -ForegroundColor White
|
||
Write-Host " 4. AppID会自动识别(或使用测试号)" -ForegroundColor White
|
||
Write-Host " 5. 在详情 -> 本地设置中,勾选 '不校验合法域名'" -ForegroundColor White
|
||
Write-Host " 6. 点击 '编译' 按钮" -ForegroundColor White
|
||
Write-Host ""
|
||
Write-Host "🔧 后台管理地址: http://localhost:3000/admin" -ForegroundColor Cyan
|
||
Write-Host ""
|
||
Write-Host "==================================" -ForegroundColor Cyan
|
||
Write-Host "按 Ctrl+C 停止服务器" -ForegroundColor Yellow
|
||
Write-Host "==================================" -ForegroundColor Cyan
|
||
Write-Host ""
|
||
|
||
# 启动开发服务器
|
||
if ($packageManager -eq "pnpm") {
|
||
pnpm run dev
|
||
} else {
|
||
npm run dev
|
||
}
|