fix: 创建Windows专用批处理脚本,解决bash脚本无法运行的问题

问题:Windows PowerShell不支持bash脚本,导致 pnpm run dev 报错 "invalid option name"。

解决方案:
1. 创建Windows批处理脚本文件:
   - scripts/dev.bat:开发环境启动(含端口清除逻辑)
   - scripts/build.bat:构建脚本(安装依赖+构建+打包)
   - scripts/start.bat:生产环境启动

2. 更新package.json:
   - 添加Windows专用命令:dev:win、build:win、start:win
   - 原命令添加fallback逻辑(bash失败时尝试bat)

3. Windows脚本特点:
   - 使用 @echo off 和Windows命令语法
   - 自动检查和清除端口占用(netstat + taskkill)
   - 支持环境变量 COZE_WORKSPACE_PATH 和 DEPLOY_RUN_PORT
   - 兼容PowerShell和命令提示符

Windows用户运行方式:
- 推荐:pnpm run dev:win
- 或直接:scripts\dev.bat

Coze-Commit-Type: user
Coze-User-ID: 3722323274763196
Coze-Conversation-ID: 9894087
This commit is contained in:
user9994793890
2026-07-08 14:03:32 +08:00
parent a5eaa68dca
commit c2dabee453
4 changed files with 72 additions and 4 deletions

32
scripts/dev.bat Normal file
View File

@@ -0,0 +1,32 @@
@echo off
REM Windows开发环境启动脚本
REM 设置端口
set PORT=5000
if not defined DEPLOY_RUN_PORT set DEPLOY_RUN_PORT=%PORT%
REM 检查并清除端口占用
echo Checking port %DEPLOY_RUN_PORT%...
netstat -ano | findstr :%DEPLOY_RUN_PORT% | findstr LISTENING >nul
if %errorlevel% equ 0 (
echo Port %DEPLOY_RUN_PORT% is in use, attempting to clear...
for /f "tokens=5" %%a in ('netstat -ano ^| findstr :%DEPLOY_RUN_PORT% ^| findstr LISTENING') do (
echo Killing process %%a on port %DEPLOY_RUN_PORT%
taskkill /PID %%a /F >nul 2>&1
)
timeout /t 2 /nobreak >nul
echo Port %DEPLOY_RUN_PORT% cleared.
) else (
echo Port %DEPLOY_RUN_PORT% is free.
)
REM 设置工作目录
if not defined COZE_WORKSPACE_PATH set COZE_WORKSPACE_PATH=%cd%
echo Starting HTTP service on port %DEPLOY_RUN_PORT% for dev...
echo Working directory: %COZE_WORKSPACE_PATH%
REM 启动开发服务器
cd /d "%COZE_WORKSPACE_PATH%"
set PORT=%DEPLOY_RUN_PORT%
pnpm tsx watch src/server.ts