forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.ps1
More file actions
410 lines (358 loc) · 16.5 KB
/
Copy pathbootstrap.ps1
File metadata and controls
410 lines (358 loc) · 16.5 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# =============================================================================
# Invoisio — Contributor Bootstrap Script (PowerShell)
# =============================================================================
# Sets up the full development environment for all active workspaces:
# backend — NestJS + Prisma + PostgreSQL
# web — Next.js 16
# mobile — Expo React Native
# soroban — Rust Soroban smart contracts
#
# Usage:
# .\scripts\bootstrap.ps1 # bootstrap all workspaces
# .\scripts\bootstrap.ps1 -Target backend # backend only
# .\scripts\bootstrap.ps1 -Target web # web only
# .\scripts\bootstrap.ps1 -Target mobile # mobile only
# .\scripts\bootstrap.ps1 -Target soroban # soroban only
#
# Requirements:
# Node.js 18+, npm, PostgreSQL 14+ (for backend), Rust + Cargo (for soroban)
# =============================================================================
[CmdletBinding()]
param(
[ValidateSet("all","backend","web","mobile","soroban")]
[string]$Target = "all"
)
$ErrorActionPreference = "Stop"
# ── Colour helpers ────────────────────────────────────────────────────────────
function Write-Info { param($Msg) Write-Host " ℹ️ $Msg" -ForegroundColor Cyan }
function Write-Success { param($Msg) Write-Host " ✅ $Msg" -ForegroundColor Green }
function Write-Warn { param($Msg) Write-Host " ⚠️ $Msg" -ForegroundColor Yellow }
function Write-Err { param($Msg) Write-Host " ❌ $Msg" -ForegroundColor Red }
function Write-Header {
param($Msg)
Write-Host ""
Write-Host "══════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " $Msg" -ForegroundColor Cyan
Write-Host "══════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
}
# ── Repo root ─────────────────────────────────────────────────────────────────
$RepoRoot = Split-Path -Parent $PSScriptRoot
# =============================================================================
# HELPER: Check if a command exists
# =============================================================================
function Test-Command {
param(
[string]$Name,
[string]$InstallHint = ""
)
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
Write-Err "Required command not found: $Name"
if ($InstallHint) {
Write-Host " Install hint: $InstallHint" -ForegroundColor Yellow
}
return $false
}
return $true
}
# =============================================================================
# HELPER: Verify Node.js version >= 18
# =============================================================================
function Test-NodeVersion {
$verStr = (node --version 2>&1) -replace "v",""
$major = [int]($verStr.Split(".")[0])
if ($major -lt 18) {
Write-Err "Node.js 18+ required. Current: v$verStr"
return $false
}
Write-Success "Node.js v$verStr"
return $true
}
# =============================================================================
# HELPER: copy .env.example → .env if .env does not exist
# =============================================================================
function Copy-EnvFile {
param([string]$Dir)
$example = Join-Path $Dir ".env.example"
$target = Join-Path $Dir ".env"
if (Test-Path $target) {
Write-Info ".env already exists in $(Split-Path -Leaf $Dir), skipping copy"
return
}
if (-not (Test-Path $example)) {
Write-Warn "No .env.example found in $(Split-Path -Leaf $Dir)"
return
}
Copy-Item $example $target
Write-Success "Copied .env.example → .env in $(Split-Path -Leaf $Dir)"
Write-Warn "Review $target and fill in any blank values before running the app"
}
# =============================================================================
# HELPER: create mobile .env if it doesn't exist
# =============================================================================
function New-MobileEnv {
$target = Join-Path $RepoRoot "mobile\.env"
if (Test-Path $target) {
Write-Info ".env already exists in mobile, skipping creation"
return
}
$content = @"
# Mobile app environment variables
# Fill in the values below before running the app
# Backend API URL (e.g. http://localhost:3001 for local dev)
API_URL=http://localhost:3001
# Stellar network passphrase
# Testnet: "Test SDF Network ; September 2015"
# Mainnet: "Public Global Stellar Network ; September 2015"
STELLAR_NETWORK_PASSPHRASE=Test SDF Network ; September 2015
# Reown (WalletConnect) project ID — get yours at https://cloud.reown.com
REOWN_PROJECT_ID=your_reown_project_id_here
# App display name
APP_NAME=Invoisio
"@
Set-Content -Path $target -Value $content -Encoding UTF8
Write-Success "Created mobile\.env with required variables"
Write-Warn "Edit mobile\.env and set API_URL and REOWN_PROJECT_ID before running the app"
}
# =============================================================================
# WORKSPACE: backend
# =============================================================================
function Invoke-BackendBootstrap {
Write-Header "Backend (NestJS + Prisma + PostgreSQL)"
$dir = Join-Path $RepoRoot "backend"
$failed = $false
# ── Prerequisites ──────────────────────────────────────────────────────
Write-Info "Checking prerequisites..."
if (-not (Test-Command "node" "https://nodejs.org/en/download (Node.js 18+)")) { $failed = $true }
if (-not (Test-Command "npm" "Comes with Node.js")) { $failed = $true }
if ((Get-Command "node" -ErrorAction SilentlyContinue) -and -not $failed) {
if (-not (Test-NodeVersion)) { $failed = $true }
}
# PostgreSQL — non-fatal
if (Get-Command "psql" -ErrorAction SilentlyContinue) {
$psqlVer = (psql --version 2>&1)
Write-Success "PostgreSQL client: $psqlVer"
} else {
Write-Warn "psql not found — make sure PostgreSQL is accessible (local or Docker)"
Write-Warn "Docker alternative: docker run -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:16"
}
if ($failed) {
Write-Err "Backend prerequisites not met. Fix the issues above and re-run."
return $false
}
# ── Environment ────────────────────────────────────────────────────────
Write-Info "Setting up environment..."
Copy-EnvFile $dir
# ── Install dependencies ───────────────────────────────────────────────
Write-Info "Installing npm dependencies..."
Push-Location $dir
try {
npm install
if ($LASTEXITCODE -ne 0) { throw "npm install failed" }
Write-Success "npm install complete"
# ── Prisma generate ────────────────────────────────────────────────
Write-Info "Generating Prisma client..."
npx prisma generate
if ($LASTEXITCODE -ne 0) { throw "prisma generate failed" }
Write-Success "Prisma client generated"
} finally {
Pop-Location
}
# ── Summary ────────────────────────────────────────────────────────────
Write-Host ""
Write-Success "Backend ready!"
Write-Host " Next steps:" -ForegroundColor White
Write-Host " 1. Ensure PostgreSQL is running and backend\.env DATABASE_URL is correct"
Write-Host " 2. cd backend; npx prisma migrate dev # apply DB migrations"
Write-Host " 3. cd backend; npm run start:dev # start dev server on :3001"
Write-Host ""
return $true
}
# =============================================================================
# WORKSPACE: web
# =============================================================================
function Invoke-WebBootstrap {
Write-Header "Web (Next.js 16)"
$dir = Join-Path $RepoRoot "web"
$failed = $false
Write-Info "Checking prerequisites..."
if (-not (Test-Command "node" "https://nodejs.org/en/download (Node.js 18+)")) { $failed = $true }
if (-not (Test-Command "npm" "Comes with Node.js")) { $failed = $true }
if ((Get-Command "node" -ErrorAction SilentlyContinue) -and -not $failed) {
if (-not (Test-NodeVersion)) { $failed = $true }
}
if ($failed) {
Write-Err "Web prerequisites not met. Fix the issues above and re-run."
return $false
}
Write-Info "Installing npm dependencies..."
Push-Location $dir
try {
npm install
if ($LASTEXITCODE -ne 0) { throw "npm install failed" }
Write-Success "npm install complete"
} finally {
Pop-Location
}
Write-Host ""
Write-Success "Web ready!"
Write-Host " Next steps:" -ForegroundColor White
Write-Host " 1. cd web; npm run dev # start dev server on http://localhost:3000"
Write-Host ""
return $true
}
# =============================================================================
# WORKSPACE: mobile
# =============================================================================
function Invoke-MobileBootstrap {
Write-Header "Mobile (Expo React Native)"
$dir = Join-Path $RepoRoot "mobile"
$failed = $false
Write-Info "Checking prerequisites..."
if (-not (Test-Command "node" "https://nodejs.org/en/download (Node.js 18+)")) { $failed = $true }
if (-not (Test-Command "npm" "Comes with Node.js")) { $failed = $true }
if ((Get-Command "node" -ErrorAction SilentlyContinue) -and -not $failed) {
if (-not (Test-NodeVersion)) { $failed = $true }
}
if ($failed) {
Write-Err "Mobile prerequisites not met. Fix the issues above and re-run."
return $false
}
Write-Info "Setting up environment..."
New-MobileEnv
Write-Info "Installing npm dependencies..."
Push-Location $dir
try {
npm install
if ($LASTEXITCODE -ne 0) { throw "npm install failed" }
Write-Success "npm install complete"
} finally {
Pop-Location
}
# Expo CLI check
if (-not (Get-Command "expo" -ErrorAction SilentlyContinue)) {
Write-Warn "Expo CLI not found globally — you can still use 'npx expo'"
Write-Info "To install globally: npm install -g expo-cli"
} else {
Write-Success "Expo CLI available"
}
Write-Host ""
Write-Success "Mobile ready!"
Write-Host " Next steps:" -ForegroundColor White
Write-Host " 1. Edit mobile\.env — set API_URL and REOWN_PROJECT_ID"
Write-Host " 2. cd mobile; npx expo start # start Expo dev server"
Write-Host " 3. Scan the QR code with Expo Go (iOS/Android)"
Write-Host " or press 'a' for Android emulator / 'i' for iOS simulator"
Write-Host ""
return $true
}
# =============================================================================
# WORKSPACE: soroban
# =============================================================================
function Invoke-SorobanBootstrap {
Write-Header "Soroban (Rust Smart Contracts)"
$dir = Join-Path $RepoRoot "soroban"
$failed = $false
Write-Info "Checking prerequisites..."
# Rust toolchain
if (-not (Test-Command "rustc" "https://rustup.rs — run: winget install Rustlang.Rustup")) { $failed = $true }
if (-not (Test-Command "cargo" "Comes with Rust — see above")) { $failed = $true }
if (-not (Test-Command "rustup" "Comes with Rust — see above")) { $failed = $true }
if ($failed) {
Write-Err "Rust toolchain not found. Install it first, then re-run."
Write-Host ""
Write-Host " Windows (recommended):" -ForegroundColor Yellow
Write-Host " winget install Rustlang.Rustup" -ForegroundColor Yellow
Write-Host " or download the installer from https://rustup.rs" -ForegroundColor Yellow
return $false
}
$rustVer = (rustc --version 2>&1)
$cargoVer = (cargo --version 2>&1)
Write-Success "Rust: $rustVer"
Write-Success "Cargo: $cargoVer"
# wasm32v1-none target
Write-Info "Checking wasm32v1-none target..."
$installedTargets = (rustup target list --installed 2>&1)
if ($installedTargets -match "wasm32v1-none") {
Write-Success "wasm32v1-none target already installed"
} else {
Write-Info "Installing wasm32v1-none target..."
rustup target add wasm32v1-none
if ($LASTEXITCODE -ne 0) { throw "Failed to add wasm32v1-none target" }
Write-Success "wasm32v1-none target installed"
}
# Stellar CLI
Write-Info "Checking Stellar CLI..."
if (Get-Command "stellar" -ErrorAction SilentlyContinue) {
$stellarVer = (stellar --version 2>&1 | Select-Object -First 1)
Write-Success "Stellar CLI: $stellarVer"
} else {
Write-Warn "Stellar CLI not found — required to build, deploy, and invoke contracts"
Write-Host ""
Write-Host " Install Stellar CLI:" -ForegroundColor Yellow
Write-Host " cargo install --locked stellar-cli --features opt" -ForegroundColor Yellow
Write-Host ""
Write-Warn "Skipping Stellar CLI install (run the command above manually)"
Write-Warn "You can still compile and test locally without it using 'cargo build' / 'cargo test'"
}
# cargo check
Write-Info "Verifying contract compiles (cargo check)..."
Push-Location $dir
try {
cargo check --quiet
if ($LASTEXITCODE -ne 0) { throw "cargo check failed" }
Write-Success "Contract compiles successfully"
} finally {
Pop-Location
}
Write-Host ""
Write-Success "Soroban ready!"
Write-Host " Next steps:" -ForegroundColor White
Write-Host " 1. cd soroban; .\build.sh # compile to WASM (use WSL or Git Bash on Windows)"
Write-Host " 2. cd soroban; cargo test # run unit tests (no network needed)"
Write-Host " 3. cd soroban; .\deploy.sh # deploy to Stellar testnet (WSL/Git Bash)"
Write-Host ""
Write-Host " Note: The .sh shell scripts require WSL 2 or Git Bash on Windows." -ForegroundColor Cyan
Write-Host " Full docs: soroban\README.md" -ForegroundColor Cyan
Write-Host ""
return $true
}
# =============================================================================
# MAIN
# =============================================================================
Write-Host ""
Write-Host "🧾 Invoisio — Contributor Bootstrap" -ForegroundColor Cyan -NoNewline
Write-Host " (Target: $Target)" -ForegroundColor White
Write-Host ""
$overallFailed = $false
function Invoke-Workspace {
param([string]$Name)
$fn = "Invoke-$([System.Globalization.CultureInfo]::CurrentCulture.TextInfo.ToTitleCase($Name))Bootstrap"
$result = & $fn
if (-not $result) { $script:overallFailed = $true }
}
switch ($Target) {
"all" {
Invoke-Workspace "Backend"
Invoke-Workspace "Web"
Invoke-Workspace "Mobile"
Invoke-Workspace "Soroban"
}
default {
$titleName = [System.Globalization.CultureInfo]::CurrentCulture.TextInfo.ToTitleCase($Target)
Invoke-Workspace $titleName
}
}
Write-Host ""
if (-not $overallFailed) {
Write-Host "🎉 Bootstrap complete! Happy hacking." -ForegroundColor Green
Write-Host ""
Write-Host "Docs & guides:" -ForegroundColor Cyan
Write-Host " CONTRIBUTING.md — contribution guide"
Write-Host " backend\README.md — backend setup details"
Write-Host " soroban\README.md — Soroban build/deploy/invoke"
Write-Host " mobile\SMOKE_TEST_CHECKLIST.md — mobile smoke tests"
} else {
Write-Err "Bootstrap finished with errors. Fix the issues above and re-run."
exit 1
}