Skip to content

Commit d17b123

Browse files
Windows tests
1 parent bfe9f1e commit d17b123

File tree

7 files changed

+510
-0
lines changed

7 files changed

+510
-0
lines changed

.device_scripts/codequill.bat

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
@echo off
2+
setlocal enabledelayedexpansion
3+
4+
:: Array of required scripts
5+
set "REQUIRED_SCRIPTS=install.bat uninstall.bat start.bat desktop.bat remove_desktop.bat"
6+
7+
:: Base URL for downloading scripts
8+
set "BASE_URL=https://raw.githubusercontent.com/The-Best-Codes/codequill/main/.device_scripts"
9+
10+
:: Function to check and download missing scripts
11+
:check_and_download_scripts
12+
for %%s in (%REQUIRED_SCRIPTS%) do (
13+
if not exist "%%s" (
14+
echo Downloading %%s...
15+
powershell -Command "(New-Object Net.WebClient).DownloadFile('%BASE_URL%/%%s', '%%s')"
16+
if errorlevel 1 (
17+
echo Failed to download %%s. Please check your internet connection and try again.
18+
exit /b 1
19+
)
20+
)
21+
)
22+
exit /b 0
23+
24+
:: Function to display the header
25+
:show_header
26+
cls
27+
echo ==================================
28+
echo CodeQuill Manager
29+
echo ==================================
30+
echo.
31+
exit /b 0
32+
33+
:: Function to display the menu
34+
:show_menu
35+
echo Please select an option:
36+
echo 1) Install / Update
37+
echo 2) Uninstall
38+
echo 3) Open CodeQuill
39+
echo 4) Cancel or Exit
40+
echo.
41+
set /p "choice=Enter your choice [1-4]: "
42+
exit /b 0
43+
44+
:: Main script
45+
call :check_and_download_scripts
46+
47+
:main_loop
48+
call :show_header
49+
call :show_menu
50+
51+
if "%choice%"=="1" (
52+
echo Installing / Updating CodeQuill...
53+
call install.bat
54+
echo Setting up desktop integration...
55+
call desktop.bat
56+
echo CodeQuill has been installed/updated successfully!
57+
pause
58+
goto main_loop
59+
) else if "%choice%"=="2" (
60+
echo Uninstalling CodeQuill...
61+
call remove_desktop.bat
62+
call uninstall.bat
63+
echo CodeQuill has been uninstalled successfully!
64+
pause
65+
goto main_loop
66+
) else if "%choice%"=="3" (
67+
echo Opening CodeQuill...
68+
start "" start.bat
69+
exit /b 0
70+
) else if "%choice%"=="4" (
71+
echo Exiting CodeQuill Manager. Goodbye!
72+
exit /b 0
73+
) else (
74+
echo Invalid option. Please try again.
75+
pause
76+
goto main_loop
77+
)

.device_scripts/desktop.bat

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
echo [%color%m%text%[0m
9+
exit /b
10+
11+
:: Get the absolute path of the CodeQuill directory
12+
set "CODEQUILL_DIR=%~dp0"
13+
14+
:: Define the path for the shortcut
15+
set "SHORTCUT_PATH=%USERPROFILE%\Desktop\CodeQuill.lnk"
16+
17+
:: Define the path for the icon
18+
set "ICON_PATH=%CODEQUILL_DIR%codequill\app\favicon.ico"
19+
20+
:: Create the shortcut
21+
echo Set oWS = WScript.CreateObject("WScript.Shell") > CreateShortcut.vbs
22+
echo sLinkFile = "%SHORTCUT_PATH%" >> CreateShortcut.vbs
23+
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> CreateShortcut.vbs
24+
echo oLink.TargetPath = "%CODEQUILL_DIR%start.bat" >> CreateShortcut.vbs
25+
echo oLink.WorkingDirectory = "%CODEQUILL_DIR%" >> CreateShortcut.vbs
26+
echo oLink.Description = "AI-powered code editor" >> CreateShortcut.vbs
27+
echo oLink.IconLocation = "%ICON_PATH%" >> CreateShortcut.vbs
28+
echo oLink.Save >> CreateShortcut.vbs
29+
cscript //nologo CreateShortcut.vbs
30+
del CreateShortcut.vbs
31+
32+
:: Create the Manager shortcut
33+
set "MANAGER_SHORTCUT_PATH=%USERPROFILE%\Desktop\CodeQuill Manager.lnk"
34+
echo Set oWS = WScript.CreateObject("WScript.Shell") > CreateManagerShortcut.vbs
35+
echo sLinkFile = "%MANAGER_SHORTCUT_PATH%" >> CreateManagerShortcut.vbs
36+
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> CreateManagerShortcut.vbs
37+
echo oLink.TargetPath = "cmd.exe" >> CreateManagerShortcut.vbs
38+
echo oLink.Arguments = "/c %CODEQUILL_DIR%codequill.bat" >> CreateManagerShortcut.vbs
39+
echo oLink.WorkingDirectory = "%CODEQUILL_DIR%" >> CreateManagerShortcut.vbs
40+
echo oLink.Description = "CodeQuill Manager" >> CreateManagerShortcut.vbs
41+
echo oLink.IconLocation = "%ICON_PATH%" >> CreateManagerShortcut.vbs
42+
echo oLink.Save >> CreateManagerShortcut.vbs
43+
cscript //nologo CreateManagerShortcut.vbs
44+
del CreateManagerShortcut.vbs
45+
46+
call :print_color 32 "✅ CodeQuill desktop shortcuts created successfully!"
47+
call :print_color 36 "📌 Shortcut locations:"
48+
echo %SHORTCUT_PATH%
49+
echo %MANAGER_SHORTCUT_PATH%
50+
call :print_color 33 "ℹ️ The shortcuts should be available on your desktop immediately."
51+
52+
endlocal

.device_scripts/install.bat

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
echo [%color%m%text%[0m
9+
exit /b
10+
11+
:: Function to print step
12+
:print_step
13+
call :print_color 36 "
14+
📌 %~1"
15+
exit /b
16+
17+
:: Function to check command status
18+
:check_status
19+
if %errorlevel% equ 0 (
20+
call :print_color 32 "✅ Success"
21+
) else (
22+
call :print_color 31 "❌ Failed"
23+
exit /b 1
24+
)
25+
exit /b
26+
27+
:: Start installation
28+
call :print_color 35 "
29+
==================================
30+
🚀 CodeQuill Installation Script 🚀
31+
==================================
32+
"
33+
34+
:: Check if Git is installed
35+
where git >nul 2>&1
36+
if %errorlevel% neq 0 (
37+
call :print_color 31 "❌ Git is not installed. Please install Git and try again."
38+
exit /b 1
39+
)
40+
41+
:: Check if Node.js is installed
42+
where node >nul 2>&1
43+
if %errorlevel% neq 0 (
44+
call :print_color 31 "❌ Node.js is not installed. Please install Node.js and try again."
45+
exit /b 1
46+
)
47+
48+
:: Check if npm is installed
49+
where npm >nul 2>&1
50+
if %errorlevel% neq 0 (
51+
call :print_color 31 "❌ npm is not installed. Please install npm and try again."
52+
exit /b 1
53+
)
54+
55+
:: Check if codequill folder exists
56+
if exist "codequill" (
57+
call :print_step "CodeQuill folder already exists. Backing up database..."
58+
if exist "codequill\database.sqlite" (
59+
copy "codequill\database.sqlite" "database.sqlite.backup" >nul
60+
call :check_status
61+
) else (
62+
call :print_color 33 "⚠️ No database file found to backup."
63+
)
64+
65+
call :print_step "Removing existing CodeQuill folder..."
66+
rmdir /s /q "codequill"
67+
call :check_status
68+
)
69+
70+
:: Clone the repository
71+
call :print_step "Cloning the CodeQuill repository..."
72+
git clone https://github.com/The-Best-Codes/codequill.git
73+
call :check_status
74+
75+
:: Restore database if backup exists
76+
if exist "database.sqlite.backup" (
77+
call :print_step "Restoring database..."
78+
move "database.sqlite.backup" "codequill\database.sqlite" >nul
79+
call :check_status
80+
)
81+
82+
:: Change directory
83+
call :print_step "Changing to the CodeQuill directory..."
84+
cd codequill
85+
call :check_status
86+
87+
:: Install Node.js dependencies
88+
call :print_step "Installing Node.js dependencies..."
89+
npm install
90+
call :check_status
91+
92+
:: Install Electron dependencies
93+
call :print_step "Installing Electron dependencies..."
94+
npm install --save-dev electron electron-builder
95+
call :check_status
96+
97+
:: Build the Next.js app
98+
call :print_step "Building the Next.js app..."
99+
npm run build
100+
if %errorlevel% neq 0 (
101+
call :print_color 31 "❌ Build failed. Please check for errors and try again."
102+
exit /b 1
103+
)
104+
call :print_color 32 "✅ Build completed successfully."
105+
106+
call :print_color 35 "
107+
====================================
108+
🎉 Installation completed successfully! 🎉
109+
====================================
110+
111+
To start the server, run: start.bat
112+
"
113+
114+
endlocal

.device_scripts/remove_desktop.bat

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
echo [%color%m%text%[0m
9+
exit /b
10+
11+
:: Define the paths for the shortcuts
12+
set "SHORTCUT_PATH=%USERPROFILE%\Desktop\CodeQuill.lnk"
13+
set "MANAGER_SHORTCUT_PATH=%USERPROFILE%\Desktop\CodeQuill Manager.lnk"
14+
15+
:: Check if the shortcuts exist and remove them
16+
set "removed=0"
17+
18+
if exist "%SHORTCUT_PATH%" (
19+
del "%SHORTCUT_PATH%"
20+
set /a "removed+=1"
21+
)
22+
23+
if exist "%MANAGER_SHORTCUT_PATH%" (
24+
del "%MANAGER_SHORTCUT_PATH%"
25+
set /a "removed+=1"
26+
)
27+
28+
:: Print appropriate message based on removal status
29+
if %removed% gtr 0 (
30+
call :print_color 32 "✅ CodeQuill desktop shortcuts removed successfully!"
31+
) else (
32+
call :print_color 33 "⚠️ CodeQuill desktop shortcuts not found. Nothing to remove."
33+
)
34+
35+
call :print_color 33 "ℹ️ The changes should take effect immediately on your desktop."
36+
37+
endlocal

.device_scripts/start.bat

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 "%~dp0codequill" || (
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

Comments
 (0)