Skip to content

Commit 4d9e6bf

Browse files
Adding paramter -Encoding
1 parent 90e4dca commit 4d9e6bf

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

PSModuleDevelopment/changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22
##
3-
- Upd: Template: PSFProject added Azure Functions Project CI/CD integration
3+
- New: Template: AzureFunctionRest - creates an azure function designed for rest API trigger.
4+
- Upd: Template: PSFProject added Azure Functions Project CI/CD integration.
5+
- Upd: Invoke-PSMDTemplate supports `-Encoding` parameter, defaulting to utf8 with BOM.
46

57
## 2.2.6.62 (April 30th, 2019)
68
- New: Get-PSMDArgumentCompleter - Lists registered argument completers on PS5+

PSModuleDevelopment/functions/templating/Invoke-PSMDTemplate.ps1

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
Skip automatic folder creation for project templates.
3939
By default, this command will create a folder to place files&folders in when creating a project.
4040
41+
.PARAMETER Encoding
42+
The encoding to apply to text files.
43+
The default setting for this can be configured by updating the 'PSFramework.Text.Encoding.DefaultWrite' configuration setting.
44+
The initial default value is utf8 with BOM.
45+
4146
.PARAMETER Parameters
4247
A Hashtable containing parameters for use in creating the template.
4348
@@ -75,15 +80,15 @@
7580
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSPossibleIncorrectUsageOfAssignmentOperator", "")]
7681
[CmdletBinding(SupportsShouldProcess = $true)]
7782
param (
78-
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Template')]
79-
[PSModuleDevelopment.Template.TemplateInfo[]]
80-
$Template,
81-
8283
[Parameter(Mandatory = $true, Position = 0, ParameterSetName = 'NameStore')]
8384
[Parameter(Mandatory = $true, Position = 0, ParameterSetName = 'NamePath')]
8485
[string]
8586
$TemplateName,
8687

88+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Template')]
89+
[PSModuleDevelopment.Template.TemplateInfo[]]
90+
$Template,
91+
8792
[Parameter(ParameterSetName = 'NameStore')]
8893
[string]
8994
$Store = "*",
@@ -100,6 +105,9 @@
100105
[string]
101106
$Name,
102107

108+
[PSFEncoding]
109+
$Encoding = (Get-PSFConfigValue -FullName 'PSFramework.Text.Encoding.DefaultWrite'),
110+
103111
[switch]
104112
$NoFolder,
105113

@@ -176,6 +184,9 @@
176184
[string]
177185
$OutPath,
178186

187+
[PSFEncoding]
188+
$Encoding,
189+
179190
[bool]
180191
$NoFolder,
181192

@@ -237,7 +248,7 @@
237248
{
238249
foreach ($child in $templateData.Children)
239250
{
240-
Write-TemplateItem -Item $child -Path $OutPath -ParameterFlat $Parameters -ParameterScript $scriptParameters -Raw $Raw
251+
Write-TemplateItem -Item $child -Path $OutPath -Encoding $Encoding -ParameterFlat $Parameters -ParameterScript $scriptParameters -Raw $Raw
241252
}
242253
if ($Raw -and $templateData.Scripts.Values)
243254
{
@@ -272,7 +283,7 @@
272283

273284
foreach ($child in $templateData.Children)
274285
{
275-
Write-TemplateItem -Item $child -Path $newFolder.FullName -ParameterFlat $Parameters -ParameterScript $scriptParameters -Raw $Raw
286+
Write-TemplateItem -Item $child -Path $newFolder.FullName -Encoding $Encoding -ParameterFlat $Parameters -ParameterScript $scriptParameters -Raw $Raw
276287
}
277288

278289
#region Write Config File (Raw)
@@ -308,7 +319,7 @@
308319
}
309320

310321
$configFile = Join-Path $newFolder.FullName "PSMDTemplate.ps1"
311-
Set-Content -Path $configFile -Value $optionsTemplate -Encoding UTF8
322+
Set-Content -Path $configFile -Value $optionsTemplate -Encoding ([PSFEncoding]'utf-8').Encoding
312323
}
313324
#endregion Write Config File (Raw)
314325
}
@@ -327,6 +338,9 @@
327338
[string]
328339
$Path,
329340

341+
[PSFEncoding]
342+
$Encoding,
343+
330344
[hashtable]
331345
$ParameterFlat,
332346

@@ -373,7 +387,7 @@
373387
$text = $text -replace "$($identifier)!$([regex]::Escape($param))!$($identifier)", $ParameterScript[$param]
374388
}
375389
}
376-
[System.IO.File]::WriteAllText($destPath, $text)
390+
[System.IO.File]::WriteAllText($destPath, $text, $Encoding)
377391
}
378392
else
379393
{
@@ -417,23 +431,19 @@
417431
{
418432
if ($PSCmdlet.ShouldProcess($item, "Invoking template"))
419433
{
420-
try { Invoke-Template -Template $item -OutPath $resolvedPath.ProviderPath -NoFolder $NoFolder -Parameters $Parameters.Clone() -Raw $Raw -Silent $Silent }
434+
try { Invoke-Template -Template $item -OutPath $resolvedPath.ProviderPath -NoFolder $NoFolder -Encoding $Encoding -Parameters $Parameters.Clone() -Raw $Raw -Silent $Silent }
421435
catch { Stop-PSFFunction -Message "Failed to invoke template $($item)" -EnableException $EnableException -ErrorRecord $_ -Target $item -Tag 'fail', 'template', 'invoke' -Continue }
422436
}
423437
}
424438
foreach ($item in $templates)
425439
{
426440
if ($PSCmdlet.ShouldProcess($item, "Invoking template"))
427441
{
428-
try { Invoke-Template -Template $item -OutPath $resolvedPath.ProviderPath -NoFolder $NoFolder -Parameters $Parameters.Clone() -Raw $Raw -Silent $Silent }
442+
try { Invoke-Template -Template $item -OutPath $resolvedPath.ProviderPath -NoFolder $NoFolder -Encoding $Encoding -Parameters $Parameters.Clone() -Raw $Raw -Silent $Silent }
429443
catch { Stop-PSFFunction -Message "Failed to invoke template $($item)" -EnableException $EnableException -ErrorRecord $_ -Target $item -Tag 'fail', 'template', 'invoke' -Continue }
430444
}
431445
}
432446
}
433-
end
434-
{
435-
436-
}
437447
}
438448

439449
if (-not (Test-Path Alias:\imt)) { Set-Alias -Name imt -Value Invoke-PSMDTemplate }

0 commit comments

Comments
 (0)