33[CmdletBinding ()]
44param ()
55
6+ Function Write-StatusMessage {
7+ [CmdletBinding ()]
8+ Param (
9+ [Parameter (Mandatory = $true , Position = 0 )]
10+ [string ]$Message ,
11+ [Parameter (Mandatory = $false )]
12+ [string ]$ForegroundColor = " Gray" ,
13+ [Parameter (Mandatory = $false )]
14+ [int ]$Indent = 0 ,
15+ [Parameter (Mandatory = $false )]
16+ [ValidateSet (" Default" , " Verbose" , " Debug" , " Warning" , " Error" )]
17+ [string ]$Verbosity = " Default" ,
18+ [Parameter (Mandatory = $false )]
19+ [int ]$Width = 0 ,
20+ [Parameter (Mandatory = $false )]
21+ [switch ]$NoNewLine
22+ )
23+
24+ if ($Indent -gt 0 ) {
25+ $Message = " $ ( ' ' * $Indent ) $Message "
26+ }
27+
28+ if ($Width -gt 0 ) {
29+ if ($Message.Length -gt $Width ) {
30+ $Message = $Message.Substring (0 , $Width - 3 ) + " ..." ;
31+ } else {
32+ $Message = $Message.PadRight ($Width , " " );
33+ }
34+ }
35+
36+ $messageParams = @ { }
37+
38+ if ($Verbosity -eq " Default" ) {
39+ $messageParams.Object = $Message
40+ $messageParams.ForegroundColor = $ForegroundColor
41+ $messageParams.NoNewLine = $NoNewLine.IsPresent
42+ } else {
43+ $messageParams.Message = $Message
44+ }
45+ # $messageParams.Object = $Message
46+
47+ switch ($Verbosity ) {
48+ " Verbose" {
49+ Write-Verbose @messageParams
50+ }
51+ " Debug" {
52+ Write-Debug @messageParams
53+ }
54+ " Warning" {
55+ Write-Warning @messageParams
56+ }
57+ " Error" {
58+ Write-Error @messageParams
59+ }
60+ " Default" {
61+ Write-Host @messageParams
62+ }
63+ }
64+ }
65+
66+ function Center-Text ($text , $width ) {
67+ $text = " $text "
68+ $pad = $width - $text.Length
69+ if ($pad -le 0 ) { return $text }
70+ $left = [math ]::Floor($pad / 2 )
71+ $right = $pad - $left
72+ (' ' * $left ) + $text + (' ' * $right )
73+ }
74+
75+ function Left-Text ($text , $width ) {
76+ $text = " $text "
77+ if ($text.Length -ge $width ) { return $text }
78+ return $text + (' ' * ($width - $text.Length ))
79+ }
80+
81+ function Right-Text ($text , $width ) {
82+ $text = " $text "
83+ if ($text.Length -ge $width ) { return $text }
84+ return (' ' * ($width - $text.Length )) + $text
85+ }
86+
87+ $successCheck = [char ]0x2713
88+
689Write-Host " DevSetup Module Installer" - ForegroundColor Cyan
790Write-Host " =========================" - ForegroundColor Cyan
891
@@ -28,148 +111,138 @@ try {
28111
29112 Write-Debug " DevSetup module found and verified."
30113
31- # Determine the correct user modules path based on PowerShell version
32- $UserModulesPath = $null
33-
34- if ($PSVersionTable.PSVersion.Major -ge 6 ) {
35- # PowerShell 6+ (Core)
36- # In PS 6+, $IsWindows, $IsLinux, $IsMacOS variables are available
37- if ((Get-Variable - Name " IsWindows" - ErrorAction SilentlyContinue) -and $IsWindows ) {
38- # Windows
39- $UserModulesPath = Join-Path - Path $env: USERPROFILE - ChildPath " Documents\PowerShell\Modules"
40- } elseif ((Get-Variable - Name " IsLinux" - ErrorAction SilentlyContinue) -and $IsLinux ) {
41- # Linux
42- $UserModulesPath = Join-Path - Path $env: HOME - ChildPath " .local/share/powershell/Modules"
43- } elseif ((Get-Variable - Name " IsMacOS" - ErrorAction SilentlyContinue) -and $IsMacOS ) {
44- # macOS
45- $UserModulesPath = Join-Path - Path $env: HOME - ChildPath " .local/share/powershell/Modules"
46- } else {
47- # Fallback - assume Windows for PowerShell 6+ if platform detection fails
48- $UserModulesPath = Join-Path - Path $env: USERPROFILE - ChildPath " Documents\PowerShell\Modules"
49- }
50- } else {
51- # PowerShell 5.1 (Windows PowerShell) - always Windows
52- $UserModulesPath = Join-Path - Path $env: USERPROFILE - ChildPath " Documents\WindowsPowerShell\Modules"
53- }
114+ # Get the PSModulePath environment variable
115+ $psModulePath = $Env: PSModulePath
116+
117+ # Split the string into an array of individual paths using the platform-specific path separator
118+ $modulePaths = $psModulePath -split [System.IO.Path ]::PathSeparator
119+
120+ # Determine the correct user modules path based on env:PSModulePath
121+ $UserModulesPath = ($modulePaths | Select-Object - First 1 )
54122
55123 if (-not $UserModulesPath ) {
56124 throw " Unable to determine user modules path for PowerShell version $ ( $PSVersionTable.PSVersion ) "
57125 }
58126
59- Write-Host " PowerShell Version: $ ( $PSVersionTable.PSVersion ) " - ForegroundColor Yellow
60- Write-Host " PowerShell Edition: $ ( $PSVersionTable.PSEdition ) " - ForegroundColor Yellow
61127 Write-Debug " Target user modules path: $UserModulesPath "
62128
63129 # Show current PSModulePath for debugging
64130 Write-Debug " Current PSModulePath:"
65131 ($env: PSModulePath -split [IO.Path ]::PathSeparator) | ForEach-Object { Write-Debug " $_ " }
66132
67133 # Get the module version from the manifest
134+ $ModuleVersion = $null
68135 Write-Debug " Reading module version from manifest..."
69136 try {
70137 $ManifestData = Import-PowerShellDataFile - Path $ModuleManifest
71138 $ModuleVersion = $ManifestData.ModuleVersion
72139 if (-not $ModuleVersion ) {
73140 throw " ModuleVersion not found in manifest"
74141 }
75- Write-Host " Installing DevSetup Module version: $ModuleVersion " - ForegroundColor Green
76142 } catch {
77143 Write-Warning " Failed to read module version from manifest: $_ "
78144 Write-Host " Using default version: 1.0.0" - ForegroundColor Yellow
79145 $ModuleVersion = " 1.0.0"
80146 }
81147
148+ Write-Host " Installing DevSetup Module version: $ModuleVersion ..." - ForegroundColor Yellow
149+
150+ Write-StatusMessage " - Checking PowerShell Version..." - Width 60 - NoNewLine - ForegroundColor Gray
151+ Write-StatusMessage (Right- Text " [$ ( $PSVersionTable.PSVersion ) ]" 20 ) - ForegroundColor Green
152+ Write-StatusMessage " - Checking PowerShell Edition..." - Width 60 - NoNewLine - ForegroundColor Gray
153+ Write-StatusMessage (Right- Text " [$ ( $PSVersionTable.PSEdition ) ]" 20 ) - ForegroundColor Green
154+
82155 $nugetProvider = Get-PackageProvider - Name NuGet - ErrorAction SilentlyContinue
83156
157+ Write-StatusMessage " - Installing NuGet Package Provider..." - Width 60 - NoNewLine - ForegroundColor Gray
84158 if ($nugetProvider ) {
85- Write-Host " NuGet PackageProvider is already installed (version: $ ( $nugetProvider.Version ) ) " - ForegroundColor Green
159+ Write-StatusMessage (Right - Text " [ $ ( $nugetProvider.Version ) ] " 20 ) - ForegroundColor Green
86160 } else {
87- Write-Host " Installing NuGet PackageProvider..." - ForegroundColor Cyan
88- $env: __SuppressAutoNuGetProviderPrompt = ' true'
89- $env: POWERSHELL_UPDATECHECK = ' Off'
90- Install-PackageProvider - Name NuGet - MinimumVersion 2.8 .5.201 - Force - Scope CurrentUser - ForceBootstrap
161+ Install-PackageProvider - Name NuGet - Force - ForceBootstrap
91162
92163 # Verify installation
93164 $nugetProvider = Get-PackageProvider - Name NuGet - ErrorAction SilentlyContinue
94165 if ($nugetProvider ) {
95- Write-Host " NuGet PackageProvider successfully installed (version: $ ( $nugetProvider.Version ) ) " - ForegroundColor Green
166+ Write-StatusMessage (Right - Text " [ $ ( $nugetProvider.Version ) ] " 20 ) - ForegroundColor Green
96167 } else {
97168 throw " Failed to install NuGet PackageProvider"
98169 }
99170 }
100171
101172 # Install required module dependencies
102- Write-Host " Installing module dependencies..." - ForegroundColor Cyan
103173 try {
104174 $RequiredModules = $ManifestData.RequiredModules
105175 if ($RequiredModules -and $RequiredModules.Count -gt 0 ) {
106176 foreach ($RequiredModule in $RequiredModules ) {
107- Write-Host " - Checking dependency: $RequiredModule " - ForegroundColor Gray
108-
177+ Write-StatusMessage " - Installing powershell dependency $RequiredModule ..." - Width 60 - NoNewLine - ForegroundColor Gray
109178 # Check if the module is already installed
110179 $InstalledModule = Get-Module - ListAvailable - Name $RequiredModule - ErrorAction SilentlyContinue
111180 if ($InstalledModule ) {
112- Write-Host " - Already installed: $RequiredModule (version: $ ( $ InstalledModule [0 ].Version) ) " - ForegroundColor Green
181+ Write-StatusMessage (Right - Text " [ $ ( $ InstalledModule [0 ].Version) ] " 20 ) - ForegroundColor Green
113182 } else {
114- Write-Host " - Installing: $RequiredModule " - ForegroundColor Yellow
115183 try {
116184 Install-Module - Name $RequiredModule - Scope CurrentUser - Force - AllowClobber - ErrorAction Stop
117- Write-Host " - Successfully installed: $RequiredModule " - ForegroundColor Green
185+ $InstalledModule = Get-Module - ListAvailable - Name $RequiredModule - ErrorAction SilentlyContinue
186+ Write-StatusMessage (Right- Text " [$ ( $InstalledModule [0 ].Version) ]" 20 ) - ForegroundColor Green
118187 } catch {
119- Write-Warning " - Failed to install $RequiredModule `: $_ "
120- Write-Host " - You may need to install this module manually later" - ForegroundColor Yellow
188+ Write-StatusMessage (Right- Text " [FAILED]" 20 ) - ForegroundColor Red
121189 }
122190 }
123191 }
124192 } else {
125- Write-Host " - No required modules specified in manifest" - ForegroundColor Gray
193+ Write-StatusMessage " - No required modules specified in manifest..." - Width 60 - NoNewLine - ForegroundColor Gray
194+ Write-StatusMessage (Right- Text " [$successCheck ]" 20 ) - ForegroundColor Green
126195 }
127196 } catch {
128197 Write-Warning " Failed to process required modules from manifest: $_ "
129- Write-Host " Continuing with installation..." - ForegroundColor Yellow
198+ Write-Host " - Continuing with installation..." - ForegroundColor Gray
130199 }
131200
132201 # Create the user modules directory if it doesn't exist
133202 if (-not (Test-Path $UserModulesPath )) {
134- Write-Host " Creating user modules directory: $UserModulesPath " - ForegroundColor Cyan
203+ Write-StatusMessage " - Creating user modules directory... " - Width 60 - NoNewLine - ForegroundColor Gray
135204 New-Item - Path $UserModulesPath - ItemType Directory - Force | Out-Null
205+ Write-StatusMessage (Right- Text " [$successCheck ]" 20 ) - ForegroundColor Green
136206 }
137207
138208 # Define the target installation path with version
139209 $TargetModuleBasePath = Join-Path - Path $UserModulesPath - ChildPath " DevSetup"
140210 $TargetModulePath = Join-Path - Path $TargetModuleBasePath - ChildPath $ModuleVersion
141211
142- Write-Host " - Install Path: $TargetModulePath " - ForegroundColor Gray
143-
144212 # Remove existing installation if it exists
145213 if (Test-Path $TargetModuleBasePath ) {
146- Write-Host " - Removing existing DevSetup module versions..." - ForegroundColor Gray
214+ Write-StatusMessage " - Removing existing DevSetup module versions..." - Width 60 - NoNewLine - ForegroundColor Gray
147215 Remove-Item - Path $TargetModuleBasePath - Recurse - Force | Out-Null
216+ Write-StatusMessage (Right- Text " [$successCheck ]" 20 ) - ForegroundColor Green
148217 }
149218
150219 # Create the versioned directory structure
151- Write-Host " - Creating versioned directory structure..." - ForegroundColor Gray
220+ Write-StatusMessage " - Creating versioned directory structure..." - Width 60 - NoNewLine - ForegroundColor Gray
152221 New-Item - Path $TargetModulePath - ItemType Directory - Force | Out-Null
222+ Write-StatusMessage (Right- Text " [$successCheck ]" 20 ) - ForegroundColor Green
153223
154224 # Copy the DevSetup module contents to the versioned path
155- Write-Host " - Installing DevSetup module..." - ForegroundColor Gray
225+ Write-StatusMessage " - Installing DevSetup module..." - Width 60 - NoNewLine - ForegroundColor Gray
156226 Copy-Item - Path " $DevSetupModulePath \*" - Destination $TargetModulePath - Recurse - Force | Out-Null
157-
227+ Write-StatusMessage (Right- Text " [$successCheck ]" 20 ) - ForegroundColor Green
228+
158229 # Verify the installation
159- Write-Host " - Verifying installation..." - ForegroundColor Gray
230+ Write-StatusMessage " - Verifying installation..." - Width 60 - NoNewLine - ForegroundColor Gray
160231
161232 # Check if the module is now in PSModulePath
162233 $ModuleFound = Get-Module - ListAvailable - Name " DevSetup" - ErrorAction SilentlyContinue
163234 if ($ModuleFound ) {
164- Write-Host " - Installation Verified..." - ForegroundColor Gray
235+ # Write-Host "- Installation Verified..." -ForegroundColor Gray
236+ Write-StatusMessage (Right- Text " [$successCheck ]" 20 ) - ForegroundColor Green
165237 $ModuleFound | ForEach-Object {
166238 Write-Debug " - Version: $ ( $_.Version ) at $ ( $_.ModuleBase ) "
167239 }
168240 } else {
241+ Write-StatusMessage (Right- Text " [FAILED]" 20 ) - ForegroundColor Red
169242 Write-Warning " DevSetup module not found in module search paths!"
170- Write-Host " Manual verification - checking installation path..." - ForegroundColor Yellow
243+ Write-Host " - Manual verification - checking installation path..." - ForegroundColor Yellow
171244 if (Test-Path (Join-Path $TargetModulePath " DevSetup.psd1" )) {
172- Write-Host " Module files exist at target path: $TargetModulePath " - ForegroundColor Green
245+ Write-Host " - Module files exist at target path: $TargetModulePath " - ForegroundColor Green
173246 } else {
174247 Write-Error " Module files not found at target path!"
175248 }
@@ -199,6 +272,7 @@ try {
199272 }
200273
201274 Write-Host " `n Installation completed successfully!" - ForegroundColor Green
275+ # Write-Host "Install Path:`n- $TargetModulePath`n" -ForegroundColor Gray
202276 Write-Host " You can now use DevSetup commands in any PowerShell session." - ForegroundColor White
203277
204278 # Add the module to the current session's auto-import
@@ -209,9 +283,9 @@ try {
209283 Write-Debug " DevSetup module loaded in current session."
210284 }
211285
212- Write-Host " `n To get started, try :" - ForegroundColor Cyan
213- Write-Host " Use-DevSetup -Init" - ForegroundColor White
214- Write-Host " # or use the alias:" - ForegroundColor Gray
286+ Write-Host " `n To get started, run :" - ForegroundColor Cyan
287+ # Write-Host " Use-DevSetup -Init" -ForegroundColor White
288+ # Write-Host " # or use the alias:" -ForegroundColor Gray
215289 Write-Host " devsetup -Init" - ForegroundColor White
216290
217291 Write-Host " `n Note: If the command isn't found in new sessions, run:" - ForegroundColor Yellow
@@ -226,5 +300,6 @@ try {
226300 exit 1
227301}
228302
229- Write-Host " `n Press any key to continue..." - ForegroundColor Gray
230- $null = $Host.UI.RawUI.ReadKey (" NoEcho,IncludeKeyDown" )
303+ Write-Host " "
304+ # Write-Host "`nPress any key to continue..." -ForegroundColor Gray
305+ # $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
0 commit comments