-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.bat
More file actions
110 lines (96 loc) · 3.02 KB
/
Copy pathstart.bat
File metadata and controls
110 lines (96 loc) · 3.02 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
107
108
109
110
@echo off
chcp 65001 >nul 2>&1
setlocal EnableDelayedExpansion
title Shogun - The Tenshu
:: Navigate to script directory (handles shortcut launches)
cd /d "%~dp0"
echo.
echo SHOGUN - Starting the Tenshu...
echo.
:: Check if venv exists (support both "venv" and ".venv" names)
set "VENV_DIR="
if exist "venv\Scripts\activate.bat" (
set "VENV_DIR=venv"
)
if exist ".venv\Scripts\activate.bat" (
set "VENV_DIR=.venv"
)
if "%VENV_DIR%"=="" (
echo ERROR: Virtual environment not found.
echo Looked for: venv\ and .venv\
echo Please run install.bat first.
echo.
echo Press any key to close...
pause >nul
exit /b 1
)
:: Activate venv
echo Using virtual environment: %VENV_DIR%
call %VENV_DIR%\Scripts\activate.bat
:: Build frontend on every launch so the served UI always matches this codebase.
:: This prevents stale laptop builds from hiding newly-added tabs or panels.
echo Building frontend assets...
cd frontend
call npm run build --silent
if errorlevel 1 (
cd ..
echo.
echo ERROR: Frontend build failed.
echo Please run Shogun-Repair-Update.bat, then start Shogun again.
echo.
echo Press any key to close...
pause >nul
exit /b 1
)
cd ..
echo Frontend assets ready.
:: A second shortcut launch should reopen the existing Tenshu, not try to bind
:: the same port and report that Shogun stopped.
powershell -NoProfile -ExecutionPolicy Bypass -Command "try { $response = Invoke-WebRequest -UseBasicParsing -TimeoutSec 2 'http://localhost:8000/api/v1/health'; if ($response.StatusCode -eq 200) { exit 0 } } catch {}; exit 1" >nul 2>&1
if not errorlevel 1 (
echo.
echo Shogun is already running. Opening the Tenshu...
set "SHOGUN_BROWSER_URL=http://localhost:8000"
set "SHOGUN_MANAGED_BROWSER=true"
python -m shogun
exit /b !ERRORLEVEL!
)
echo Shogun is starting at http://localhost:8000
echo Your browser will open automatically.
echo.
echo Press Ctrl+C to stop the server.
echo.
:: The Python server opens the browser as soon as it is ready.
set "SHOGUN_BROWSER_URL=http://localhost:8000"
set "SHOGUN_MANAGED_BROWSER=true"
:: Start the server (blocking; keeps the window open)
set "SHOGUN_LAUNCHER_MANAGED=true"
:run_shogun
python -m shogun
set "SHOGUN_EXIT_CODE=!ERRORLEVEL!"
if exist ".states\restart-requested" (
del /q ".states\restart-requested" >nul 2>&1
echo.
echo Restart requested. Starting Shogun again...
timeout /t 2 /nobreak >nul
goto run_shogun
)
if exist ".states\shutdown-requested" (
del /q ".states\shutdown-requested" >nul 2>&1
echo.
echo Tenshu shut down safely.
exit /b 0
)
:: If the server exits, keep the window open so the user can see errors
echo.
if "!SHOGUN_EXIT_CODE!"=="0" (
echo Shogun stopped normally.
) else (
echo ERROR: Shogun stopped unexpectedly ^(exit code !SHOGUN_EXIT_CODE!^).
if exist "logs\startup-error.log" (
echo Startup details: %CD%\logs\startup-error.log
)
)
echo Press any key to close this window.
pause >nul
exit /b !SHOGUN_EXIT_CODE!