-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-local.ps1
More file actions
315 lines (267 loc) · 10.1 KB
/
install-local.ps1
File metadata and controls
315 lines (267 loc) · 10.1 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
#!/usr/bin/env pwsh
#Requires -Version 7.2
<#
.SYNOPSIS
Install PSCue module by building from source.
.DESCRIPTION
This script builds PSCue from source and installs it to ~/.local/pwsh-modules/PSCue/
Requires .NET 9.0 SDK to be installed.
.PARAMETER Force
Overwrite existing installation without prompting.
.PARAMETER Update
Pull the latest changes from the remote before building. Runs 'git pull' on the current branch.
.PARAMETER InstallPath
Custom installation directory. When specified, installs to this path instead of ~/.local/pwsh-modules/PSCue.
Useful for dev/test installations that don't conflict with the production module.
.EXAMPLE
./install-local.ps1
Build and install PSCue from source.
.EXAMPLE
./install-local.ps1 -Force
Build and install, overwriting any existing installation.
.EXAMPLE
./install-local.ps1 -Update -Force
Pull latest changes, then build and install.
.EXAMPLE
./install-local.ps1 -Force -InstallPath D:\temp\PSCue-dev
Build and install to a custom directory for dev testing.
#>
[CmdletBinding()]
param(
[switch]$Force,
[switch]$Update,
[string]$InstallPath
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
# ANSI color codes
$Reset = "`e[0m"
$Green = "`e[32m"
$Yellow = "`e[33m"
$Red = "`e[31m"
$Cyan = "`e[36m"
$Bold = "`e[1m"
function Write-Status {
param([string]$Message)
Write-Host "${Green}${Bold}==>${Reset} ${Message}" -ForegroundColor Green
}
function Write-Info {
param([string]$Message)
Write-Host "${Cyan}${Message}${Reset}" -ForegroundColor Cyan
}
function Write-Warning {
param([string]$Message)
Write-Host "${Yellow}Warning: ${Message}${Reset}" -ForegroundColor Yellow
}
function Write-Error {
param([string]$Message)
Write-Host "${Red}Error: ${Message}${Reset}" -ForegroundColor Red
}
# Get the repository root directory
$RepoRoot = $PSScriptRoot
Write-Info "Repository: $RepoRoot"
# Check if the local clone is up-to-date with remote
Write-Status "Checking if repository is up-to-date..."
try {
Push-Location $RepoRoot
$branch = & git rev-parse --abbrev-ref HEAD 2>&1
& git fetch origin $branch --quiet 2>&1
$local = & git rev-parse HEAD 2>&1
$remote = & git rev-parse "origin/$branch" 2>&1
if ($local -ne $remote) {
$behind = & git rev-list --count "HEAD..origin/$branch" 2>&1
$ahead = & git rev-list --count "origin/$branch..HEAD" 2>&1
$status = @()
if ([int]$behind -gt 0) { $status += "$behind commit(s) behind" }
if ([int]$ahead -gt 0) { $status += "$ahead commit(s) ahead of" }
Write-Warning "Local branch '$branch' is $($status -join ' and ') origin/$branch."
if ($Update) {
Write-Status "Pulling latest changes..."
& git pull --quiet 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error "git pull failed. Resolve conflicts and try again."
exit 1
}
Write-Info "Repository updated successfully."
} elseif (-not $Force) {
$response = Read-Host "Continue anyway? (y/N)"
if ($response -ne 'y' -and $response -ne 'Y') {
Write-Info "Installation cancelled. Run 'git pull' or use -Update to update."
exit 0
}
}
} else {
Write-Info "Repository is up-to-date with origin/$branch."
}
} catch {
Write-Warning "Could not check remote status: $_"
Write-Warning "Continuing with installation..."
} finally {
Pop-Location
}
# Detect platform and architecture
$IsWindowsPlatform = $IsWindows -or ($PSVersionTable.PSVersion.Major -le 5)
$Platform = if ($IsWindowsPlatform) { 'win' } elseif ($IsMacOS) { 'osx' } else { 'linux' }
$Architecture = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLower()
# Map architecture names
$RID = "$Platform-$Architecture"
Write-Info "Platform: $RID"
# Check for .NET SDK
Write-Status "Checking for .NET SDK..."
try {
$dotnetVersion = & dotnet --version 2>&1
Write-Info ".NET SDK version: $dotnetVersion"
} catch {
Write-Error ".NET SDK not found. Please install .NET SDK 10 or later."
Write-Info "Download from: https://dotnet.microsoft.com/download"
exit 1
}
# Define installation directory
$InstallDir = if ($InstallPath) { $InstallPath } else { Join-Path $HOME ".local/pwsh-modules/PSCue" }
Write-Info "Installation directory: $InstallDir"
# Check if already installed — prompt now, but defer deletion until after builds succeed
$AlreadyInstalled = Test-Path $InstallDir
if ($AlreadyInstalled) {
if (-not $Force) {
Write-Warning "PSCue is already installed at: $InstallDir"
$response = Read-Host "Overwrite existing installation? (y/N)"
if ($response -ne 'y' -and $response -ne 'Y') {
Write-Info "Installation cancelled."
exit 0
}
}
}
# Build ArgumentCompleter (NativeAOT)
Write-Status "Building ArgumentCompleter (NativeAOT)..."
$CompleterProject = Join-Path $RepoRoot "src/PSCue.ArgumentCompleter/PSCue.ArgumentCompleter.csproj"
Push-Location $RepoRoot
try {
& dotnet publish $CompleterProject -c Release -o publish -r $RID
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to build PSCue.ArgumentCompleter"
exit 1
}
} finally {
Pop-Location
}
# Build Module
Write-Status "Building Module..."
$PredictorProject = Join-Path $RepoRoot "src/PSCue.Module/PSCue.Module.csproj"
Push-Location $RepoRoot
try {
& dotnet publish $PredictorProject -c Release -o publish
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to build PSCue.Module"
exit 1
}
} finally {
Pop-Location
}
# Both builds succeeded — now safe to remove existing installation and create fresh directory
if ($AlreadyInstalled) {
Write-Warning "Removing existing installation..."
Remove-Item -Path $InstallDir -Recurse -Force
}
# Create installation directory
Write-Status "Creating installation directory..."
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
# Copy files to installation directory
Write-Status "Installing files..."
# Copy ArgumentCompleter executable
$CompleterExe = if ($IsWindowsPlatform) { "pscue-completer.exe" } else { "pscue-completer" }
$CompleterSource = Join-Path $RepoRoot "publish/$CompleterExe"
$CompleterDest = Join-Path $InstallDir $CompleterExe
if (Test-Path $CompleterSource) {
Copy-Item -Path $CompleterSource -Destination $CompleterDest -Force
Write-Info " Installed: $CompleterExe"
# Make executable on Unix systems
if (-not $IsWindowsPlatform) {
& chmod +x $CompleterDest
}
} else {
Write-Error "ArgumentCompleter executable not found at: $CompleterSource"
exit 1
}
# Copy Module DLL and dependencies
$PredictorSource = Join-Path $RepoRoot "publish"
$PredictorDll = "PSCue.Module.dll"
$PredictorDllSource = Join-Path $PredictorSource $PredictorDll
$PredictorDllDest = Join-Path $InstallDir $PredictorDll
if (Test-Path $PredictorDllSource) {
Copy-Item -Path $PredictorDllSource -Destination $PredictorDllDest -Force
Write-Info " Installed: $PredictorDll"
} else {
Write-Error "Module DLL not found at: $PredictorDllSource"
exit 1
}
# Copy required dependencies
$Dependencies = @(
"PSCue.Shared.dll",
"PSCue.Module.deps.json",
"Microsoft.Data.Sqlite.dll",
"SQLitePCLRaw.batteries_v2.dll",
"SQLitePCLRaw.core.dll",
"SQLitePCLRaw.provider.e_sqlite3.dll",
"Spectre.Console.dll"
)
foreach ($dep in $Dependencies) {
$depSource = Join-Path $PredictorSource $dep
$depDest = Join-Path $InstallDir $dep
if (Test-Path $depSource) {
Copy-Item -Path $depSource -Destination $depDest -Force
Write-Info " Installed: $dep"
} else {
Write-Warning "Dependency not found: $dep (may not be required)"
}
}
# Copy native SQLite libraries for current platform
$RuntimesSource = Join-Path $PredictorSource "runtimes/$RID/native"
if (Test-Path $RuntimesSource) {
$RuntimesDest = Join-Path $InstallDir "runtimes/$RID/native"
New-Item -ItemType Directory -Path (Split-Path $RuntimesDest -Parent) -Force | Out-Null
Copy-Item -Path $RuntimesSource -Destination $RuntimesDest -Recurse -Force
Write-Info " Installed: runtimes/$RID/native/ (native SQLite libraries)"
# Also copy native DLL directly to module root for easier loading by PowerShell
$NativeDll = if ($IsWindowsPlatform) { "e_sqlite3.dll" } elseif ($IsMacOS) { "libe_sqlite3.dylib" } else { "libe_sqlite3.so" }
$NativeDllSource = Join-Path $RuntimesSource $NativeDll
if (Test-Path $NativeDllSource) {
Copy-Item -Path $NativeDllSource -Destination (Join-Path $InstallDir $NativeDll) -Force
Write-Info " Installed: $NativeDll (to module root)"
}
}
# Copy module files
$ModuleSource = Join-Path $RepoRoot "module"
Copy-Item -Path "$ModuleSource/PSCue.psd1" -Destination $InstallDir -Force
Copy-Item -Path "$ModuleSource/PSCue.psm1" -Destination $InstallDir -Force
Write-Info " Installed: PSCue.psd1"
Write-Info " Installed: PSCue.psm1"
# Copy Functions directory (PowerShell module functions)
$FunctionsSource = Join-Path $ModuleSource "Functions"
if (Test-Path $FunctionsSource) {
$FunctionsDest = Join-Path $InstallDir "Functions"
Copy-Item -Path $FunctionsSource -Destination $FunctionsDest -Recurse -Force
Write-Info " Installed: Functions/ (PowerShell module functions)"
}
# Success!
Write-Host ""
Write-Status "PSCue installation complete!"
Write-Host ""
# Display setup instructions
Write-Host "${Bold}Setup Instructions:${Reset}"
Write-Host ""
Write-Host "1. Add PSCue to your PowerShell profile:"
Write-Host ""
$ImportPath = Join-Path $InstallDir "PSCue.psd1"
Write-Host " ${Cyan}Import-Module $ImportPath${Reset}"
Write-Host ""
Write-Host "2. Enable inline predictions (recommended):"
Write-Host ""
Write-Host " ${Cyan}Set-PSReadLineOption -PredictionSource HistoryAndPlugin${Reset}"
Write-Host ""
Write-Host "3. Restart your PowerShell session or reload your profile:"
Write-Host ""
Write-Host " ${Cyan}. `$PROFILE${Reset}"
Write-Host ""
Write-Host "For more information, visit: ${Cyan}https://github.com/lucaspimentel/PSCue${Reset}"
Write-Host ""