Skip to content

Commit 62d62a6

Browse files
Merge pull request #206 from PowershellFrameworkCollective/typeconversion-fix
fixing object conversion
2 parents 5281c03 + 52dcd56 commit 62d62a6

File tree

15 files changed

+165
-23
lines changed

15 files changed

+165
-23
lines changed

PSModuleDevelopment/PSModuleDevelopment.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Version number of this module.
77

8-
ModuleVersion = '2.2.12.171'
8+
ModuleVersion = '2.2.12.172'
99

1010
# ID used to uniquely identify this module
1111
GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6'
@@ -29,7 +29,7 @@
2929
# this module
3030
RequiredModules = @(
3131
@{ ModuleName = 'PSFramework'; ModuleVersion = '1.12.346' }
32-
@{ ModuleName = 'string'; ModuleVersion = '1.1.3' }
32+
@{ ModuleName = 'string'; ModuleVersion = '1.1.5' }
3333
)
3434

3535
# Assemblies that must be loaded prior to importing this module
Binary file not shown.
Binary file not shown.

PSModuleDevelopment/bin/PSModuleDevelopment.xml

Lines changed: 29 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PSModuleDevelopment/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.2.12.172 (2024-10-06)
4+
5+
+ Fix: Invoke-PSMDTemplate - On WinPS, script-logic on templates is not executed
6+
37
## 2.2.12.171 (2024-10-04)
48

59
+ Upd: Raised PSFramework dependency due to critical security update

PSModuleDevelopment/functions/templating/Get-PSMDTemplate.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@
9191
#region Scan folders
9292
if (Test-PSFParameterBinding -ParameterName "Path")
9393
{
94-
$templateInfos = Get-ChildItem -Path $Path -Filter "$($TemplateName)-*.Info.xml" | Where-Object { ($_.Name -replace "-\d+(\.\d+){0,3}.Info.xml$") -like $TemplateName }
94+
$templateInfos = Get-ChildItem -Path $Path -Filter "$($TemplateName)-*-Info.xml" | Where-Object { ($_.Name -replace "-\d+(\.\d+){0,3}-Info.xml$") -like $TemplateName }
9595

9696
foreach ($info in $templateInfos)
9797
{
9898
$data = Import-PSFClixml $info.FullName
99-
$data.Path = $info.FullName -replace '\.Info\.xml$','.xml'
99+
$data.Path = $info.FullName -replace '-Info\.xml$','.xml'
100100
$prospects += $data
101101
}
102102
}

PSModuleDevelopment/functions/templating/Invoke-PSMDTemplate.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@
317317
[OutputType([PSModuleDevelopment.Template.TemplateResult])]
318318
[CmdletBinding()]
319319
param (
320-
[PSModuleDevelopment.Template.TemplateItemBase]
320+
# Fixing that in the next PSFramework release: https://github.com/PowershellFrameworkCollective/psframework/issues/646
321+
#[PSFramework.Utility.ScriptTransformation('PSModuleDevelopment.TemplateItem', [PSModuleDevelopment.Template.TemplateItemBase])]
322+
#[PSModuleDevelopment.Template.TemplateItemBase]
321323
$Item,
322324

323325
[string]

PSModuleDevelopment/internal/scripts/initialize.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@ if (-not (Test-Path (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Debug.Con
1010
#endregion Ensure Config path exists
1111

1212
# Pass on the host UI to the library
13-
[PSModuleDevelopment.Utility.UtilityHost]::RawUI = $host.UI.RawUI
13+
[PSModuleDevelopment.Utility.UtilityHost]::RawUI = $host.UI.RawUI
14+
15+
# Register Type-Conversion to fix template issues in serialization edge-casaes
16+
Register-PSFArgumentTransformationScriptblock -Name 'PSModuleDevelopment.TemplateItem' -Scriptblock {
17+
if ($_ -is [PSModuleDevelopment.Template.TemplateItemBase]) { return $_ }
18+
[PSModuleDevelopment.Template.TemplateHost]::GetTemplateItem($_)
19+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Describe "Verifying templating component" {
2+
BeforeAll {
3+
$outPath = (Get-Item -Path 'TestDrive:\').FullName
4+
$resourcePath = Resolve-PSFPath -Path "$PSScriptRoot\..\resources"
5+
$templateName = 'TestTemplate-{0}' -f (Get-Random)
6+
}
7+
8+
It "Should Record the template correctly" {
9+
{ New-PSMDTemplate -TemplateName $templateName -FilePath "$resourcePath\þnameþ.txt" -OutPath $outPath -EnableException -ErrorAction Stop } | Should -Not -Throw
10+
$templateInfo = Get-PSMDTemplate -TemplateName $templateName -Path $outPath
11+
$templateRaw = Import-PSFClixml -Path $templateInfo.Path
12+
try { $template = [PSModuleDevelopment.Template.Template]$templateRaw }
13+
catch {
14+
Write-Warning "Conversion to template Failed!"
15+
Write-Warning "======================================================================="
16+
$_ | Format-List -Force | Out-Host
17+
Write-Warning "======================================================================="
18+
$_.Exception | Format-List -Force | Out-Host
19+
Write-Warning "======================================================================="
20+
throw
21+
}
22+
$template.Name | Should -Be $templateName
23+
$template.Parameters.Count | Should -Be 1
24+
$template.Scripts.Count | Should -Be 1
25+
$template.Scripts.Values.ScriptBlock | Should -BeOfType ([scriptblock])
26+
}
27+
28+
It "Should Invoke the template correctly" {
29+
{ Invoke-PSMDTemplate -TemplateName $templateName -Path $outPath -OutPath $outPath -Name Test -EnableException } | Should -Not -Throw
30+
$content = Get-Content -Path "TestDrive:\Test.txt" -ErrorAction Stop
31+
$values = $content | ConvertFrom-StringData -ErrorAction Stop
32+
$values.Name | Should -Be Test
33+
$values.Value | Should -Be '123'
34+
}
35+
36+
It "Should Remove the template correctly" {
37+
{ Remove-PSMDTemplate -TemplateName $templateName -EnableException -Confirm:$false } | Should -Not -Throw
38+
Get-PSMDTemplate -TemplateName $templateName | Should -BeNullOrEmpty
39+
}
40+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Name = þnameþ
2+
Value = þ{ "123" }þ

0 commit comments

Comments
 (0)