-
Notifications
You must be signed in to change notification settings - Fork 402
Expand file tree
/
Copy pathbuild.ps1
More file actions
282 lines (234 loc) · 8.16 KB
/
build.ps1
File metadata and controls
282 lines (234 loc) · 8.16 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
param(
[Parameter(Position=0)]
[string]$Command = "help"
)
# Check if docker compose is available
$dockerCompose = "docker compose"
try {
docker-compose version | Out-Null
$dockerCompose = "docker-compose"
} catch {
# Try docker compose
}
function Test-Command {
param($CommandName)
try { Get-Command $CommandName -ErrorAction Stop | Out-Null; return $true } catch { return $false }
}
function Check-Dependencies {
Write-Host "Checking dependencies..." -ForegroundColor Green
Write-Host "Node.js: " -NoNewline
if (Test-Command "node") { node --version } else { Write-Host "Not installed" -ForegroundColor Red }
Write-Host "npm: " -NoNewline
if (Test-Command "npm") { npm --version } else { Write-Host "Not installed" -ForegroundColor Red }
Write-Host ".NET: " -NoNewline
if (Test-Command "dotnet") { dotnet --version } else { Write-Host "Not installed" -ForegroundColor Red }
Write-Host "Docker: " -NoNewline
if (Test-Command "docker") { docker --version } else { Write-Host "Not installed" -ForegroundColor Red }
Write-Host "Docker Compose: " -NoNewline
try { Invoke-Expression "$dockerCompose version" } catch { Write-Host "Not available" -ForegroundColor Red }
}
function Build-Frontend {
Write-Host "Building frontend..." -ForegroundColor Green
if (-not (Test-Command "node")) {
Write-Host "Error: Node.js not installed" -ForegroundColor Red
exit 1
}
if (-not (Test-Command "npm")) {
Write-Host "Error: npm not installed" -ForegroundColor Red
exit 1
}
Set-Location web
npm install
npm run build
Set-Location ..
Write-Host "Frontend build completed!" -ForegroundColor Green
}
function Build-Docs {
Write-Host "Building docs..." -ForegroundColor Green
if (-not (Test-Command "node")) {
Write-Host "Error: Node.js not installed" -ForegroundColor Red
exit 1
}
if (-not (Test-Command "npm")) {
Write-Host "Error: npm not installed" -ForegroundColor Red
exit 1
}
Set-Location docs
npm install
npm run build
Set-Location ..
Write-Host "Docs build completed!" -ForegroundColor Green
}
function Install-Frontend {
Write-Host "Installing frontend dependencies..." -ForegroundColor Green
if (-not (Test-Command "node")) {
Write-Host "Error: Node.js not installed" -ForegroundColor Red
exit 1
}
if (-not (Test-Command "npm")) {
Write-Host "Error: npm not installed" -ForegroundColor Red
exit 1
}
Set-Location web
npm install
Set-Location ..
Set-Location docs
npm install
Set-Location ..
Write-Host "Frontend dependencies installed!" -ForegroundColor Green
}
function Install-Backend {
Write-Host "Installing backend dependencies..." -ForegroundColor Green
if (-not (Test-Command "dotnet")) {
Write-Host "Error: .NET CLI not installed" -ForegroundColor Red
exit 1
}
dotnet restore OpenDeepWiki.sln
Write-Host "Backend dependencies restored!" -ForegroundColor Green
}
function Install-All {
Install-Frontend
Install-Backend
}
function Test-Backend {
Write-Host "Running backend tests..." -ForegroundColor Green
if (-not (Test-Command "dotnet")) {
Write-Host "Error: .NET CLI not installed" -ForegroundColor Red
exit 1
}
dotnet test tests/OpenDeepWiki.Tests/OpenDeepWiki.Tests.csproj --logger "console;verbosity=detailed"
}
function Test-Frontend {
Write-Host "Running frontend tests..." -ForegroundColor Green
if (-not (Test-Command "node")) {
Write-Host "Error: Node.js not installed" -ForegroundColor Red
exit 1
}
if (-not (Test-Command "npm")) {
Write-Host "Error: npm not installed" -ForegroundColor Red
exit 1
}
Set-Location web
npm test
Set-Location ..
}
function Test-All {
Test-Backend
Test-Frontend
}
function Lint-Frontend {
Write-Host "Running frontend linting..." -ForegroundColor Green
if (-not (Test-Command "node")) {
Write-Host "Error: Node.js not installed" -ForegroundColor Red
exit 1
}
if (-not (Test-Command "npm")) {
Write-Host "Error: npm not installed" -ForegroundColor Red
exit 1
}
Set-Location web
npm run lint
Set-Location ..
Set-Location docs
npm run lint
Set-Location ..
}
function Format-Backend {
Write-Host "Formatting backend code..." -ForegroundColor Green
if (-not (Test-Command "dotnet")) {
Write-Host "Error: .NET CLI not installed" -ForegroundColor Red
exit 1
}
dotnet format OpenDeepWiki.sln
}
function Docker-Build {
Write-Host "Building all Docker images..." -ForegroundColor Green
Build-Frontend
Invoke-Expression "$dockerCompose build"
}
function Docker-Up {
Write-Host "Starting all services..." -ForegroundColor Green
Invoke-Expression "$dockerCompose up -d"
}
function Docker-Down {
Write-Host "Stopping all services..." -ForegroundColor Green
Invoke-Expression "$dockerCompose down"
}
function Docker-Restart {
Docker-Down
Docker-Up
}
function Docker-Dev {
Write-Host "Starting development environment..." -ForegroundColor Green
Invoke-Expression "$dockerCompose up"
}
function Docker-Logs {
Write-Host "Showing service logs..." -ForegroundColor Green
Invoke-Expression "$dockerCompose logs -f"
}
function Docker-Clean {
Write-Host "Cleaning Docker resources..." -ForegroundColor Green
Invoke-Expression "$dockerCompose down --rmi all --volumes --remove-orphans"
docker system prune -f
}
function Show-Help {
Write-Host "Usage:" -ForegroundColor Cyan
Write-Host "Docker Commands:"
Write-Host " .\build.ps1 build - Build all Docker images"
Write-Host " .\build.ps1 up - Start all services (detached)"
Write-Host " .\build.ps1 down - Stop all services"
Write-Host " .\build.ps1 restart - Restart all services"
Write-Host " .\build.ps1 dev - Start development environment"
Write-Host " .\build.ps1 logs - Show service logs"
Write-Host " .\build.ps1 clean - Clean Docker resources"
Write-Host ""
Write-Host "Build Commands:"
Write-Host " .\build.ps1 build-frontend - Build frontend project"
Write-Host " .\build.ps1 build-docs - Build documentation"
Write-Host ""
Write-Host "Install Commands:"
Write-Host " .\build.ps1 install - Install all dependencies"
Write-Host " .\build.ps1 install-frontend - Install frontend dependencies"
Write-Host " .\build.ps1 install-backend - Install backend dependencies"
Write-Host ""
Write-Host "Test Commands:"
Write-Host " .\build.ps1 test - Run all tests"
Write-Host " .\build.ps1 test-backend - Run backend tests"
Write-Host " .\build.ps1 test-frontend - Run frontend tests"
Write-Host ""
Write-Host "Code Quality:"
Write-Host " .\build.ps1 lint - Run linting"
Write-Host " .\build.ps1 format - Format code"
Write-Host ""
Write-Host "Utilities:"
Write-Host " .\build.ps1 check-deps - Check system dependencies"
Write-Host " .\build.ps1 help - Show this help"
}
# Execute command
switch ($Command.ToLower()) {
"check-deps" { Check-Dependencies }
"build" { Docker-Build }
"build-frontend" { Build-Frontend }
"build-docs" { Build-Docs }
"up" { Docker-Up }
"down" { Docker-Down }
"restart" { Docker-Restart }
"dev" { Docker-Dev }
"logs" { Docker-Logs }
"clean" { Docker-Clean }
"install" { Install-All }
"install-frontend" { Install-Frontend }
"install-backend" { Install-Backend }
"test" { Test-All }
"test-backend" { Test-Backend }
"test-frontend" { Test-Frontend }
"lint" { Lint-Frontend }
"format" { Format-Backend }
"help" { Show-Help }
default {
Write-Host "Unknown command: $Command" -ForegroundColor Red
Write-Host ""
Show-Help
exit 1
}
}