Skip to content

Commit c99d091

Browse files
authored
Merge pull request #8 from pwshdevs/develop
Release 1.0.8
2 parents fd4a843 + 49b3815 commit c99d091

24 files changed

Lines changed: 882 additions & 121 deletions

.gitignore

Lines changed: 485 additions & 0 deletions
Large diffs are not rendered by default.

DevSetup/DevSetup.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'DevSetup.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.0.7'
15+
ModuleVersion = '1.0.8'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()

DevSetup/Private/Commands/Export-DevSetupEnv.Tests.ps1

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
BeforeAll {
22
. $PSScriptRoot\Export-DevSetupEnv.ps1
33
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Get-DevSetupEnvPath.ps1
4+
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Get-DevSetupLocalEnvPath.ps1
5+
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Get-DevSetupCommunityEnvPath.ps1
46
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Write-NewConfig.ps1
57
Mock Get-DevSetupEnvPath { "TestDrive:\DevSetupEnvs" }
68
Mock Get-DevSetupLocalEnvPath { "TestDrive:\DevSetupEnvs\local"}
9+
Mock Get-DevSetupCommunityEnvPath { "TestDrive:\DevSetupEnvs\community"}
710
Mock Write-NewConfig { param($OutFile) $OutFile }
811
Mock Write-Host { }
912
Mock Write-Error { }
@@ -20,6 +23,15 @@ Describe "Export-DevSetupEnv" {
2023
}
2124
}
2225

26+
Context "When called with a valid path" {
27+
It "Should create the config file and return its path" {
28+
$result = Export-DevSetupEnv -Path "TestDrive:\MyCustomPath\MyEnv.devsetup"
29+
$result | Should -Be "TestDrive:\MyCustomPath\MyEnv.devsetup"
30+
Assert-MockCalled Write-NewConfig -Exactly 1 -Scope It -ParameterFilter { $OutFile -eq "TestDrive:\MyCustomPath\MyEnv.devsetup" }
31+
Assert-MockCalled Write-Host -Scope It -ParameterFilter { $Object -match "exported to" -and $ForegroundColor -eq "Green" }
32+
}
33+
}
34+
2335
Context "When called with a name that needs sanitization" {
2436
It "Should sanitize the name and warn" {
2537
$result = Export-DevSetupEnv -Name "Data Science Environment!"
@@ -28,6 +40,14 @@ Describe "Export-DevSetupEnv" {
2840
}
2941
}
3042

43+
Context "When called with a path that needs sanitization" {
44+
It "Should sanitize the path and warn" {
45+
$result = Export-DevSetupEnv -Path "TestDrive:\MyCustomPath\MyEnv!.devsetup"
46+
$result | Should -Be "TestDrive:\MyCustomPath\MyEnv.devsetup"
47+
Assert-MockCalled Write-Host -Scope It -ParameterFilter { $Object -match "sanitized" -and $ForegroundColor -eq "Yellow" }
48+
}
49+
}
50+
3151
Context "When Write-NewConfig fails" {
3252
It "Should write error and return null" {
3353
Mock Write-NewConfig { param($OutFile) $null }
@@ -36,4 +56,4 @@ Describe "Export-DevSetupEnv" {
3656
Assert-MockCalled Write-Error -Exactly 1 -Scope It -ParameterFilter { $Message -match "Failed to create configuration file" }
3757
}
3858
}
39-
}
59+
}

DevSetup/Private/Commands/Export-DevSetupEnv.ps1

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,56 @@
6060
#>
6161

6262
Function Export-DevSetupEnv {
63+
[CmdletBinding()]
6364
Param(
64-
[string]$Name
65+
[Parameter(Mandatory=$true, ParameterSetName="Export")]
66+
[string]$Name,
67+
[Parameter(Mandatory=$true, ParameterSetName="ExportPath")]
68+
[string]$Path
6569
)
66-
# Sanitize EnvName to only contain alphanumeric characters, hyphens, and periods
67-
$sanitizedEnvName = $Name -replace '[^a-zA-Z0-9\-\.]', ''
68-
if ($sanitizedEnvName -ne $Name) {
69-
Write-Host "EnvName sanitized from '$Name' to '$sanitizedEnvName' (removed non-alphanumeric characters)" -ForegroundColor Yellow
70+
$OutFile = $null
71+
if($PSBoundParameters.ContainsKey('Name')) {
72+
$Provider = "local"
73+
74+
if($Name -like "*:*") {
75+
$Parts = $Name.Split(":")
76+
$Name = $Parts[1];
77+
$Provider = $Parts[0]
78+
}
79+
$SanitizedEnvName = $Name -replace '[^a-zA-Z0-9\-\.]', ''
80+
if ($SanitizedEnvName -ne $Name) {
81+
Write-Host "EnvName sanitized from '$Name' to '$SanitizedEnvName' (removed non-alphanumeric characters)" -ForegroundColor Yellow
82+
}
83+
84+
$BasePath = Join-Path -Path (Get-DevSetupEnvPath) -ChildPath $Provider
85+
if(-not (Test-Path -Path $BasePath)) {
86+
New-Item -Path $BasePath -ItemType Directory -Force | Out-Null
87+
}
88+
89+
$OutFile = Join-Path -Path $BasePath -ChildPath "$SanitizedEnvName.devsetup"
90+
} elseif($PSBoundParameters.ContainsKey('Path')) {
91+
$BasePath = Split-Path -Path $Path -Parent
92+
if(-not (Test-Path -Path $BasePath)) {
93+
New-Item -Path $BasePath -ItemType Directory -Force | Out-Null
94+
}
95+
$Name = Split-Path -Path $Path -Leaf
96+
if($Name -notlike "*.devsetup") {
97+
$Name = "$Name.devsetup"
98+
}
99+
100+
$SanitizedEnvName = $Name -replace '[^a-zA-Z0-9\-\.]', ''
101+
102+
if ($SanitizedEnvName -ne $Name) {
103+
Write-Host "EnvName sanitized from '$Name' to '$SanitizedEnvName' (removed non-alphanumeric characters)" -ForegroundColor Yellow
104+
}
105+
$OutFile = Join-Path -Path $BasePath -ChildPath $SanitizedEnvName
70106
}
71-
$Name = $sanitizedEnvName
72-
$OutFile = Join-Path -Path (Get-DevSetupLocalEnvPath) -ChildPath "$Name.devsetup"
107+
108+
if(-not $OutFile) {
109+
Write-Error "Failed to determine output file path"
110+
return $null
111+
}
112+
73113
$config = Write-NewConfig -OutFile $OutFile
74114
if (-not $config) {
75115
Write-Error "Failed to create configuration file"

DevSetup/Private/Commands/Initialize-DevSetup.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
BeforeAll {
22
. $PSScriptRoot\Initialize-DevSetup.ps1
33
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Get-DevSetupPath.ps1
4+
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Get-DevSetupEnvPath.ps1
5+
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Get-DevSetupLocalEnvPath.ps1
6+
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Get-DevSetupCommunityEnvPath.ps1
47
. $PSScriptRoot\..\..\..\DevSetup\Private\Providers\Core\Install-CoreDependencies.ps1
58
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Initialize-DevSetupEnvs.ps1
69
Mock Write-Host { }

DevSetup/Private/Commands/Show-DevSetupEnvList.Tests.ps1

Lines changed: 87 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ BeforeAll {
66
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Get-DevSetupPath.ps1
77
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Test-OperatingSystem.ps1
88
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Format-PrettyTable.ps1
9+
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Write-StatusMessage.ps1
910
Mock Get-DevSetupPath { "C:\DevSetup" }
1011
Mock Optimize-DevSetupEnvs { }
1112
Mock Write-Host { }
@@ -15,13 +16,14 @@ BeforeAll {
1516
Mock Get-Content { '[{"name":"EnvWin","version":"1.0","platform":"windows","file":"envwin.yaml"},{"name":"EnvLinux","version":"2.0","platform":"linux","file":"envlinux.yaml"},{"name":"EnvMac","version":"3.0","platform":"macos","file":"envmac.yaml"},{"name":"EnvCross","version":"4.0","platform":"cross-platform","file":"envcross.yaml"},{"name":"EnvUnspec","version":"5.0","file":"envunspec.yaml"}]' }
1617
Mock ConvertFrom-Json {
1718
@(
18-
@{ name = "EnvWin"; version = "1.0"; platform = "windows"; file = "envwin.yaml" },
19-
@{ name = "EnvLinux"; version = "2.0"; platform = "linux"; file = "envlinux.yaml" },
20-
@{ name = "EnvMac"; version = "3.0"; platform = "macos"; file = "envmac.yaml" },
21-
@{ name = "EnvCross"; version = "4.0"; platform = "cross-platform"; file = "envcross.yaml" },
22-
@{ name = "EnvUnspec"; version = "5.0"; file = "envunspec.yaml" }
19+
@{ name = "EnvWin"; version = "1.0"; platform = "windows"; provider = "local"; file = "envwin.yaml" },
20+
@{ name = "EnvLinux"; version = "2.0"; platform = "linux"; provider = "community"; file = "envlinux.yaml" },
21+
@{ name = "EnvMac"; version = "3.0"; platform = "macos"; provider = "other"; file = "envmac.yaml" },
22+
@{ name = "EnvCross"; version = "4.0"; platform = "cross-platform"; provider = "local"; file = "envcross.yaml" },
23+
@{ name = "EnvUnspec"; version = "5.0"; provider = "other2"; file = "envunspec.yaml" }
2324
)
2425
}
26+
Mock Write-StatusMessage { Param($Message) }
2527
}
2628

2729
Describe "Show-DevSetupEnvList" {
@@ -49,8 +51,8 @@ Describe "Show-DevSetupEnvList" {
4951
Mock Format-PrettyTable { }
5052
Mock Test-OperatingSystem { param($Windows, $Linux, $MacOS) if ($Windows) { $true } else { $false } }
5153
Show-DevSetupEnvList -Platform "current"
52-
Assert-MockCalled Write-Host -Scope It -ParameterFilter { $Object -match "Filtering for current platform: windows" }
53-
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It
54+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter { $Message -match "Filtering for platform: windows" }
55+
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It -ParameterFilter { $Rows.Count -eq 1 }
5456
}
5557
}
5658

@@ -59,8 +61,8 @@ Describe "Show-DevSetupEnvList" {
5961
Mock Format-PrettyTable { }
6062
Mock Test-OperatingSystem { param($Windows, $Linux, $MacOS) if ($Linux) { $true } else { $false } }
6163
Show-DevSetupEnvList -Platform "current"
62-
Assert-MockCalled Write-Host -Scope It -ParameterFilter { $Object -match "Filtering for current platform: linux" }
63-
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It
64+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter { $Message -match "Filtering for platform: linux" }
65+
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It -ParameterFilter { $Rows.Count -eq 1 }
6466
}
6567
}
6668

@@ -69,28 +71,98 @@ Describe "Show-DevSetupEnvList" {
6971
Mock Format-PrettyTable { }
7072
Mock Test-OperatingSystem { param($Windows, $Linux, $MacOS) if ($MacOS) { $true } else { $false } }
7173
Show-DevSetupEnvList -Platform "current"
72-
Assert-MockCalled Write-Host -Scope It -ParameterFilter { $Object -match "Filtering for current platform: macos" }
73-
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It
74+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter { $Message -match "Filtering for platform: macos" }
75+
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It -ParameterFilter { $Rows.Count -eq 1 }
7476
}
7577
}
7678

7779
Context "When filtering for all platforms" {
7880
It "Should show all environments without filtering" {
7981
Mock Format-PrettyTable { }
8082
Show-DevSetupEnvList -Platform "all"
81-
Assert-MockCalled Write-Host -Scope It -ParameterFilter { $Object -match "Showing all environments regardless of platform" }
82-
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It
83+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter { $Message -match "Filtering for platform: all" }
84+
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It -ParameterFilter { $Rows.Count -eq 5 }
8385
}
8486
}
8587

8688
Context "When filtering for specific platform (windows)" {
8789
It "Should filter and display only windows-compatible environments" {
8890
Mock Format-PrettyTable { }
8991
Show-DevSetupEnvList -Platform "windows"
90-
Assert-MockCalled Write-Host -Scope It -ParameterFilter { $Object -match "Filtering for platform: windows" }
91-
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It
92+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter { $Message -match "Filtering for platform: windows" }
93+
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It -ParameterFilter { $Rows.Count -eq 1 }
94+
}
95+
}
96+
97+
Context "When filtering for specific platform (windows) and provider (local)" {
98+
It "Should filter and display only windows-compatible environments from local provider" {
99+
Mock Format-PrettyTable { }
100+
Show-DevSetupEnvList -Platform "windows" -Provider "local"
101+
$script:count = 0;
102+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter {
103+
if($script:count -eq 0) { $Message -match "Filtering for platform: windows" }
104+
if($script:count -eq 1) { $Message -match ", provider: local" }
105+
$script:count++;
106+
} -Times 2
107+
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It -ParameterFilter { $Rows.Count -eq 1 }
92108
}
93109
}
110+
111+
Context "When filtering for specific platform (windows) and provider (community)" {
112+
It "Should filter and display only windows-compatible environments from community provider" {
113+
Mock Format-PrettyTable { }
114+
Show-DevSetupEnvList -Platform "windows" -Provider "community"
115+
$script:count = 0;
116+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter {
117+
if($script:count -eq 0) { $Message -match "Filtering for platform: windows" }
118+
if($script:count -eq 1) { $Message -match ", provider: community" }
119+
$script:count++;
120+
} -Times 2
121+
Assert-MockCalled Format-PrettyTable -Exactly 0 -Scope It -ParameterFilter { $Rows.Count -eq 0 }
122+
}
123+
}
124+
125+
Context "When filtering for specific platform (linux) and provider (community)" {
126+
It "Should filter and display only linux-compatible environments from community provider" {
127+
Mock Format-PrettyTable { }
128+
Show-DevSetupEnvList -Platform "linux" -Provider "community"
129+
$script:count = 0;
130+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter {
131+
if($script:count -eq 0) { $Message -match "Filtering for platform: linux" }
132+
if($script:count -eq 1) { $Message -match ", provider: community" }
133+
$script:count++;
134+
} -Times 2
135+
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It -ParameterFilter { $Rows.Count -eq 1 }
136+
}
137+
}
138+
139+
Context "When filtering for specific platform (macos) and provider (other)" {
140+
It "Should filter and display only macos-compatible environments from other provider" {
141+
Mock Format-PrettyTable { }
142+
Show-DevSetupEnvList -Platform "macos" -Provider "other"
143+
$script:count = 0;
144+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter {
145+
if($script:count -eq 0) { $Message -match "Filtering for platform: macos" }
146+
if($script:count -eq 1) { $Message -match ", provider: other" }
147+
$script:count++;
148+
} -Times 2
149+
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It -ParameterFilter { $Rows.Count -eq 1 }
150+
}
151+
}
152+
153+
Context "When filtering for specific platform (all) and provider (local)" {
154+
It "Should filter and display all environment from local provider" {
155+
Mock Format-PrettyTable { }
156+
Show-DevSetupEnvList -Platform "all" -Provider "local"
157+
$script:count = 0;
158+
Assert-MockCalled Write-StatusMessage -Scope It -ParameterFilter {
159+
if($script:count -eq 0) { $Message -match "Filtering for platform: all" }
160+
if($script:count -eq 1) { $Message -match ", provider: local" }
161+
$script:count++;
162+
} -Times 2
163+
Assert-MockCalled Format-PrettyTable -Exactly 1 -Scope It -ParameterFilter { $Rows.Count -eq 2 }
164+
}
165+
}
94166

95167
Context "When no environments are found for a platform" {
96168
It "Should display guidance message" {

DevSetup/Private/Commands/Show-DevSetupEnvList.ps1

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ Function Show-DevSetupEnvList {
6969
Param (
7070
[Parameter(Mandatory=$false, Position=0)]
7171
[ValidateSet("current", "all", "windows", "linux", "macos")]
72-
[string]$Platform = "current" # Default to current platform
72+
[string]$Platform = "current", # Default to current platform
73+
[Parameter(Mandatory=$false)]
74+
[string]$Provider,
75+
[Parameter(Mandatory=$false)]
76+
[switch]$Installed
7377
)
7478

7579

@@ -88,13 +92,18 @@ Function Show-DevSetupEnvList {
8892
} else {
8993
$platformFilter = "windows"
9094
}
91-
Write-Host "Filtering for current platform: $platformFilter" -ForegroundColor Gray
92-
} elseif ($platformFilter -eq "all") {
93-
Write-Host "Showing all environments regardless of platform" -ForegroundColor Gray
94-
} else {
95-
Write-Host "Filtering for platform: $platformFilter" -ForegroundColor Gray
95+
}
96+
Write-StatusMessage "Filtering for platform: $platformFilter" -ForegroundColor Gray -NoNewLine
97+
98+
if($Provider) {
99+
Write-StatusMessage ", provider: $Provider" -ForegroundColor Gray -NoNewLine
96100
}
97101

102+
if($Installed) {
103+
Write-StatusMessage ", installed only" -ForegroundColor Gray -NoNewLine
104+
}
105+
Write-Host ""
106+
98107
# Get the environments.json file path
99108
$devSetupPath = Get-DevSetupPath
100109
$environmentsJsonPath = Join-Path -Path $devSetupPath -ChildPath "environments.json"
@@ -114,17 +123,16 @@ Function Show-DevSetupEnvList {
114123
}
115124
}
116125

126+
if ($Provider) {
127+
$environments = $environments | Where-Object { $_.provider -and ($_.provider.ToLower() -eq $Provider.ToLower()) }
128+
}
129+
#if ($Installed) {
130+
# $environments = $environments | Where-Object { Test-DevSetupEnvInstalled -Name $_.name -Provider $_.provider }
131+
#}
132+
117133
# Filter environments by platform
118134
if ($platformFilter -ne "all") {
119-
$filteredEnvironments = @()
120-
foreach ($env in $environments) {
121-
$envPlatform = if ($env.platform) { $env.platform.ToLower() } else { "" }
122-
# Match exact platform or cross-platform environments
123-
if ($envPlatform -eq $platformFilter) {
124-
$filteredEnvironments += $env
125-
}
126-
}
127-
$environments = $filteredEnvironments
135+
$environments = $environments | Where-Object { ($_.platform -and ($_.platform.ToLower() -eq $platformFilter)) }
128136
}
129137

130138
if ($environments.Count -eq 0) {

DevSetup/Private/Commands/Uninstall-DevSetupEnv.Tests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ BeforeAll {
22
. $PSScriptRoot\Uninstall-DevSetupEnv.ps1
33
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Read-ConfigurationFile.ps1
44
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Get-DevSetupEnvPath.ps1
5+
. $PSScriptRoot\..\..\..\DevSetup\Private\Utils\Test-OperatingSystem.ps1
56
. $PSScriptRoot\..\..\..\DevSetup\Private\Providers\Scoop\Uninstall-ScoopComponents.ps1
67
. $PSScriptRoot\..\..\..\DevSetup\Private\Providers\Chocolatey\Uninstall-ChocolateyPackages.ps1
78
. $PSScriptRoot\..\..\..\DevSetup\Private\Providers\PowerShell\Uninstall-PowershellModules.ps1
@@ -11,6 +12,7 @@ BeforeAll {
1112
Mock Uninstall-PowershellModules { $true }
1213
Mock Uninstall-ChocolateyPackages { $true }
1314
Mock Uninstall-ScoopComponents { $true }
15+
Mock Test-OperatingSystem { $true }
1416
Mock Write-Host { }
1517
Mock Write-Error { }
1618
}

0 commit comments

Comments
 (0)