-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbootstrap.ps1
More file actions
141 lines (119 loc) · 3.9 KB
/
bootstrap.ps1
File metadata and controls
141 lines (119 loc) · 3.9 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
<#
CyberAi Hard‑Coded Bootstrap Script
Author: Jo’s Copilot
Purpose:
- Hard-coded for CyberAi repo
- Cleans corrupted pnpm virtual stores
- Removes poisoned metadata
- Detects portable Node conflicts
- Detects dangling symlinks
- Reinstalls deterministically (root + site)
- Validates esbuild/sharp/vite/astro
- Launches dev server
#>
$RepoRoot = "D:\tools\repos\SolanaRemix\CyberAi"
$SiteDir = "$RepoRoot\site"
Write-Host "`n=== CyberAi Bootstrap ===" -ForegroundColor Cyan
function Info($m){ Write-Host "[INFO] $m" -ForegroundColor Gray }
function Warn($m){ Write-Host "[WARN] $m" -ForegroundColor Yellow }
function Err ($m){ Write-Host "[ERROR] $m" -ForegroundColor Red }
# -----------------------------
# 1. Validate tooling
# -----------------------------
Info "Checking Node and pnpm availability"
if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
Err "Node not found on PATH"
exit 1
}
if (-not (Get-Command pnpm -ErrorAction SilentlyContinue)) {
Err "pnpm not found on PATH"
exit 1
}
$nodePath = (Get-Command node).Source
if ($nodePath -match "Portable|scoop|nvm") {
Warn "Portable Node detected — native binaries may break"
}
# -----------------------------
# 2. Detect corrupted pnpm metadata
# -----------------------------
Info "Scanning for pnpm virtual store corruption"
$PathsToCheck = @(
"$RepoRoot\node_modules\.pnpm",
"$RepoRoot\node_modules\.ignored",
"$RepoRoot\.pnpm",
"$RepoRoot\.pnpm-store",
"$RepoRoot\pnpm-lock.yaml",
"$RepoRoot\node_modules",
"$SiteDir\node_modules"
)
foreach ($p in $PathsToCheck) {
if (Test-Path $p) {
Warn "Found: $p"
}
}
# -----------------------------
# 3. Detect dangling symlinks
# -----------------------------
function Get-Dangling($path) {
if (-not (Test-Path $path)) { return @() }
Get-ChildItem -Recurse -Force $path |
Where-Object { $_.Attributes -match "ReparsePoint" } |
Where-Object { -not (Test-Path $_.Target) }
}
$dangRoot = Get-Dangling "$RepoRoot\node_modules"
$dangSite = Get-Dangling "$SiteDir\node_modules"
if ($dangRoot.Count -gt 0) { Warn "Dangling symlinks in root node_modules: $($dangRoot.Count)" }
if ($dangSite.Count -gt 0) { Warn "Dangling symlinks in site node_modules: $($dangSite.Count)" }
# -----------------------------
# 4. Cleanup (hard-coded, safe)
# -----------------------------
Info "Removing corrupted pnpm metadata and node_modules"
$RemoveTargets = @(
"$RepoRoot\node_modules\.pnpm",
"$RepoRoot\node_modules\.ignored",
"$RepoRoot\.pnpm",
"$RepoRoot\.pnpm-store",
"$RepoRoot\pnpm-lock.yaml",
"$RepoRoot\node_modules",
"$SiteDir\node_modules"
)
foreach ($t in $RemoveTargets) {
if (Test-Path $t) {
Info "Removing $t"
Remove-Item -Recurse -Force $t -ErrorAction SilentlyContinue
}
}
Info "Pruning global pnpm store"
pnpm store prune | Out-Null
# -----------------------------
# 5. Reinstall (root)
# -----------------------------
Info "Running pnpm install at repo root"
$rootInstall = pnpm install --dir $RepoRoot 2>&1
if ($rootInstall -match "Ignored build scripts") {
Warn "pnpm requires approve-builds — selecting all"
"a`n" | pnpm approve-builds --dir $RepoRoot | Out-Null
pnpm install --dir $RepoRoot | Out-Null
}
# -----------------------------
# 6. Reinstall (site)
# -----------------------------
Info "Installing site dependencies"
pnpm install --dir $SiteDir | Out-Null
# -----------------------------
# 7. Validate toolchain
# -----------------------------
function Validate($bin, $dir) {
Info "Validating $bin"
pnpm exec --dir $dir $bin --version
}
Validate "esbuild" $RepoRoot
Validate "sharp" $RepoRoot
Validate "vite" $SiteDir
Validate "astro" $SiteDir
# -----------------------------
# 8. Launch dev server
# -----------------------------
Write-Host "`n=== Launching Astro Dev Server ===" -ForegroundColor Green
Set-Location $SiteDir
pnpm run dev