-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup-env.cmd
More file actions
196 lines (172 loc) · 6.64 KB
/
Copy pathsetup-env.cmd
File metadata and controls
196 lines (172 loc) · 6.64 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
cd /d "%~dp0"
echo.
echo ============================================================
echo Codex Assistant - Dev Environment Setup
echo ============================================================
echo.
:: ---- Step 1: Check Node.js ----
echo [1/7] Checking Node.js...
where node >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Node.js not found in PATH!
echo Please install Node.js 22+ and try again.
goto :fail
)
for /f "tokens=*" %%v in ('node -v') do echo Node.js: %%v
:: ---- Step 2: Check Rust ----
echo [2/7] Checking Rust...
where rustc >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Rust not found in PATH!
echo Please install Rust from https://rustup.rs
goto :fail
)
for /f "tokens=*" %%v in ('rustc -V') do echo Rust: %%v
:: ---- Step 3: npm install ----
echo [3/7] Installing npm dependencies...
call npm install
if %errorlevel% neq 0 (
echo [ERROR] npm install failed!
goto :fail
)
echo Done.
:: ---- Step 4: Create directories ----
echo [4/7] Creating project directories...
if not exist "frontend" mkdir "frontend"
if not exist "user" mkdir "user"
if not exist "node" mkdir "node"
echo Done.
:: ---- Step 5: Copy Node.js binary ----
echo [5/7] Setting up bundled Node.js...
set "BUNDLED_NODE=node\node.exe"
:: Try system node first
for /f "tokens=*" %%p in ('where node 2^>nul') do (
if exist "%%p" (
if not exist "%BUNDLED_NODE%" (
copy /y "%%p" "%BUNDLED_NODE%" >nul
echo Copied from system: %%p
)
)
)
:: Fallback: managed Node.js
if not exist "%BUNDLED_NODE%" (
if exist "%USERPROFILE%\.workbuddy\binaries\node\versions\22.22.2\node.exe" (
copy /y "%USERPROFILE%\.workbuddy\binaries\node\versions\22.22.2\node.exe" "%BUNDLED_NODE%" >nul
echo Copied from managed Node 22.22.2
)
)
if not exist "%BUNDLED_NODE%" (
if exist "%USERPROFILE%\.workbuddy\binaries\node\versions\24.14.1\node.exe" (
copy /y "%USERPROFILE%\.workbuddy\binaries\node\versions\24.14.1\node.exe" "%BUNDLED_NODE%" >nul
echo Copied from managed Node 24.14.1
)
)
:: Also copy to src-tauri\resources\node\ for Tauri bundling
if not exist "src-tauri\resources\node" mkdir "src-tauri\resources\node"
if exist "%BUNDLED_NODE%" (
copy /y "%BUNDLED_NODE%" "src-tauri\resources\node\node.exe" >nul
echo Synced to Tauri resources
)
echo Done.
:: ---- Step 6: Generate missing resources ----
echo [6/7] Generating missing resources...
:: frontend/index.html
if not exist "frontend\index.html" (
echo ^<!DOCTYPE html^>^<html lang="en"^>^<head^>^<meta charset="UTF-8"^>^<title^>Codex Assistant^</title^>^</head^>^<body style="background:#0d1117;color:#c9d1d9;display:flex;align-items:center;justify-content:center;height:100vh;font-family:sans-serif"^>^<p^>Starting...^</p^>^</body^>^</html^> > "frontend\index.html"
echo Created frontend/index.html
)
:: user/.env
if not exist "user\.env" (
echo # Codex Assistant Config > "user\.env"
echo # Auto-generated by setup-env.cmd >> "user\.env"
echo. >> "user\.env"
echo PROXY_PORT=4000 >> "user\.env"
echo LOG_LEVEL=info >> "user\.env"
echo DEFAULT_PROVIDER=deepseek >> "user\.env"
echo Created user/.env
)
:: Generate icons using Python (Pillow)
echo Generating icons...
set "PYTHON_EXE="
for %%p in (
"%USERPROFILE%\.workbuddy\binaries\python\versions\3.13.12\python.exe"
"%USERPROFILE%\.workbuddy\binaries\python\versions\3.12.10\python.exe"
"%LOCALAPPDATA%\Programs\Python\Python312\python.exe"
"python"
) do (
if not defined PYTHON_EXE (
where "%%~p" >nul 2>&1 && set "PYTHON_EXE=%%~p"
)
)
if defined PYTHON_EXE (
"%PYTHON_EXE%" -c "from PIL import Image; print('Pillow OK')" >nul 2>&1
if !errorlevel! neq 0 (
echo Installing Pillow...
"%PYTHON_EXE%" -m pip install Pillow -q 2>nul
)
)
:: Generate icon.ico
if not exist "src-tauri\icons\icon.ico" (
if defined PYTHON_EXE (
"%PYTHON_EXE%" -c "from PIL import Image; img32=Image.open('src-tauri/icons/32x32.png'); img128=Image.open('src-tauri/icons/128x128.png'); img32.save('src-tauri/icons/icon.ico',format='ICO',sizes=[(32,32),(128,128)])" 2>nul
if exist "src-tauri\icons\icon.ico" ( echo Created icons/icon.ico ) else ( echo [WARN] icon.ico generation failed, using fallback )
) else (
:: Fallback: copy 32x32.png as icon.ico (not ideal but allows build)
copy /y "src-tauri\icons\32x32.png" "src-tauri\icons\icon.ico" >nul 2>&1
echo [WARN] Pillow not available, using PNG fallback for icon.ico
)
)
:: Generate ui-favicon.ico
if not exist "src-tauri\resources\ui-favicon.ico" (
if defined PYTHON_EXE (
"%PYTHON_EXE%" -c "from PIL import Image; img=Image.open('src-tauri/icons/32x32.png'); img.save('src-tauri/resources/ui-favicon.ico',format='ICO',sizes=[(32,32)])" 2>nul
if exist "src-tauri\resources\ui-favicon.ico" ( echo Created ui-favicon.ico ) else ( echo [WARN] ui-favicon.ico generation failed )
) else (
copy /y "src-tauri\icons\32x32.png" "src-tauri\resources\ui-favicon.ico" >nul 2>&1
echo [WARN] Pillow not available, using PNG fallback for ui-favicon.ico
)
)
echo Done.
:: ---- Step 7: Verify ----
echo [7/7] Verifying setup...
set "ALL_OK=1"
call :checkfile "frontend\index.html" || set "ALL_OK=0"
call :checkfile "user\.env" || set "ALL_OK=0"
call :checkfile "%BUNDLED_NODE%" || set "ALL_OK=0"
call :checkfile "src-tauri\resources\node\node.exe" || set "ALL_OK=0"
call :checkfile "src-tauri\icons\icon.ico" || set "ALL_OK=0"
call :checkfile "src-tauri\resources\ui-favicon.ico" || set "ALL_OK=0"
call :checkfile "ui-server.mjs" || set "ALL_OK=0"
if "%ALL_OK%"=="0" (
echo [WARN] Some files are missing. Run again or check manually.
)
:: ---- Done ----
echo.
echo ============================================================
echo Setup complete! You can now run:
echo start-dev.cmd - launch dev build
echo npm run tauri:dev - launch from terminal
echo ============================================================
echo.
goto :done
:: ---- Helper: check file exists ----
:checkfile
if not exist "%~1" (
echo [MISSING] %~1
exit /b 1
)
echo [OK] %~1
exit /b 0
:: ---- Failure ----
:fail
echo.
echo ============================================================
echo SETUP FAILED! Fix the errors above and try again.
echo ============================================================
echo.
:done
endlocal
pause