-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.bat
More file actions
106 lines (88 loc) · 2.89 KB
/
Copy pathstart.bat
File metadata and controls
106 lines (88 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
@echo off
chcp 65001 >nul 2>&1
title AutoScriptor
set "ROOT=%~dp0"
cd /d "%ROOT%"
REM 将便携版/运行态下的 accounts\*.json 覆盖回仓库 data\accounts\
if not exist "dist_electron\zaobi\data\accounts\" goto :skip_acc_sync
if not exist "data\accounts\" mkdir "data\accounts"
copy /y "dist_electron\zaobi\data\accounts\*.json" "data\accounts\" >nul 2>&1
if errorlevel 1 echo [WARN] 未找到 dist_electron\zaobi\data\accounts\*.json,跳过同步。
:skip_acc_sync
cd /d "%ROOT%webapp"
set "BRANCH=feat/launcher"
REM ── 检查 git ──
where git >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo [WARN] git not found, skipping update.
goto :START_APP
)
REM ── 拉取远程更新 ──
echo [*] Fetching updates from origin/%BRANCH% ...
git fetch origin %BRANCH% 2>nul
if %ERRORLEVEL% neq 0 (
echo [WARN] git fetch failed, continuing with current version.
goto :START_APP
)
REM ── 对比本地与远程 commit ──
for /f "delims=" %%i in ('git rev-parse HEAD 2^>nul') do set "LOCAL_SHA=%%i"
for /f "delims=" %%i in ('git rev-parse "origin/%BRANCH%" 2^>nul') do set "REMOTE_SHA=%%i"
if "%LOCAL_SHA%"=="%REMOTE_SHA%" (
echo [*] Already up to date.
goto :START_APP
)
echo [*] Updates available: %LOCAL_SHA:~0,8% -^> %REMOTE_SHA:~0,8%
echo [*] Stashing local changes...
git stash --quiet 2>nul
echo [*] Pulling latest code...
git pull --ff-only origin %BRANCH%
if %ERRORLEVEL% neq 0 (
echo [WARN] pull --ff-only failed, trying reset...
git reset --hard "origin/%BRANCH%"
)
echo [*] Restoring local changes...
git stash pop --quiet 2>nul
REM ── 更新 Python 依赖 ──
if exist ".venv\Scripts\pip.exe" (
echo [*] Updating Python dependencies...
.venv\Scripts\pip.exe install -r requirements.txt --quiet 2>nul
)
echo [*] Update complete.
:START_APP
REM ── 清理残留的 5000 端口占用(上次异常退出时可能残留 Python 进程) ──
echo [*] Checking port 5000...
set "_FOUND_STALE="
for /f "tokens=5" %%a in ('netstat -aon 2^>nul ^| findstr ":5000.*LISTENING"') do (
if %%a NEQ 0 (
set "_FOUND_STALE=1"
echo [*] Killing stale process on port 5000 ^(PID: %%a^)
taskkill /PID %%a /T /F >nul 2>&1
)
)
if defined _FOUND_STALE (
echo [*] Waiting for port release...
timeout /t 1 /nobreak >nul 2>&1
)
cd /d "%ROOT%webapp"
where npm >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo [ERROR] npm not found. Please install Node.js first.
echo https://nodejs.org/
pause
exit /b 1
)
if not exist "node_modules\" (
echo [*] Installing npm dependencies...
call npm install
if %ERRORLEVEL% neq 0 (
echo.
echo [ERROR] npm install failed.
pause
exit /b 1
)
)
echo [*] Starting AutoScriptor...
> "%TEMP%\_as_launch.vbs" echo CreateObject("WScript.Shell").Run "cmd /c cd /d ""%CD%"" && npm start", 0, False
wscript "%TEMP%\_as_launch.vbs"
del "%TEMP%\_as_launch.vbs" 2>nul
exit 0