1+ @ echo off
2+ setlocal enabledelayedexpansion
3+
4+ :: Function to print colored text
5+ :print_color
6+ set " color = %~1 "
7+ set " text = %~2 "
8+ powershell -Command " Write-Host '%text% ' -ForegroundColor %color% "
9+ exit /b
10+
11+ :: Function to print step
12+ :print_step
13+ call :print_color Cyan "
14+ 📌 %~1 "
15+ exit /b
16+
17+ :: Function to cleanup and exit
18+ :cleanup_and_exit
19+ call :print_color Yellow "
20+
21+ 🛑 Stopping CodeQuill..."
22+
23+ if defined NEXT_PID (
24+ tasklist /FI " PID eq %NEXT_PID% " 2 > NUL | find /I /N " node.exe" > NUL
25+ if !ERRORLEVEL! equ 0 (
26+ taskkill /F /PID %NEXT_PID%
27+ call :print_color Green " ✅ Next.js server stopped"
28+ ) else (
29+ call :print_color Yellow " ⚠️ Next.js server was not running"
30+ )
31+ ) else (
32+ call :print_color Yellow " ⚠️ Next.js server PID not set"
33+ )
34+
35+ call :print_color Magenta "
36+ ==========================
37+ 👋 CodeQuill has stopped 👋
38+ ==========================
39+ "
40+ exit /b
41+
42+ :: Start message
43+ call :print_color Magenta "
44+ ==========================
45+ 🚀 Starting CodeQuill 🚀
46+ ==========================
47+ "
48+
49+ :: Change to the CodeQuill directory
50+ cd /d " %~dp0 codequill" || (
51+ call :print_color Red " ❌ Failed to change to CodeQuill directory"
52+ exit /b 1
53+ )
54+ call :print_step " Changed to directory: %CD% "
55+
56+ :: Check if .next directory exists
57+ if not exist " .next" (
58+ call :print_step " The .next directory is missing. Running 'next build'..."
59+ call npm run build
60+ if !ERRORLEVEL! neq 0 (
61+ call :print_color Red " ❌ Build failed. Please check for errors and try again."
62+ exit /b 1
63+ )
64+ call :print_color Green " ✅ Build completed successfully."
65+ ) else (
66+ call :print_step " .next directory found. Skipping build."
67+ )
68+
69+ :: Check if settings.json exists
70+ if exist " settings.json" (
71+ :: Extract port from settings.json
72+ for /f " tokens=2 delims=:," %%a in ('findstr /C:" port" settings.json') do set PORT = %%a
73+ set PORT = !PORT: =!
74+ if not defined PORT (
75+ set PORT = 1291
76+ call :print_step " No port specified in settings.json. Using default port: !PORT! "
77+ ) else (
78+ call :print_step " Using port from settings.json: !PORT! "
79+ )
80+ ) else (
81+ set PORT = 1291
82+ call :print_step " settings.json not found. Using default port: !PORT! "
83+ )
84+
85+ :: Start the Next.js server in the background
86+ call :print_step " Starting Next.js server on port !PORT! ..."
87+ start " " npm run start -- -p !PORT!
88+ for /f " tokens=2" %%a in ('tasklist /fi " imagename eq node.exe" /fo list ^ | find " PID:" ') do set NEXT_PID = %%a
89+
90+ :: Function to check if the server is ready
91+ :check_server
92+ powershell -Command " (Invoke-WebRequest -Uri http://localhost:!PORT! -UseBasicParsing -DisableKeepAlive).StatusCode" > nul 2 >& 1
93+ if !ERRORLEVEL! neq 0 (
94+ timeout /t 1 /nobreak > nul
95+ goto check_server
96+ )
97+ call :print_color Green " ✅ Next.js server is ready!"
98+
99+ :: Start Electron
100+ call :print_step " Starting Electron..."
101+ set ELECTRON_START_URL = http://localhost:!PORT!
102+ call npm run electron -- --no-sandbox
103+
104+ :: Electron has exited, so we can clean up
105+ call :cleanup_and_exit
0 commit comments