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
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 = " *" ,
100105 [string ]
101106 $Name ,
102107
108+ [PSFEncoding ]
109+ $Encoding = (Get-PSFConfigValue - FullName ' PSFramework.Text.Encoding.DefaultWrite' ),
110+
103111 [switch ]
104112 $NoFolder ,
105113
176184 [string ]
177185 $OutPath ,
178186
187+ [PSFEncoding ]
188+ $Encoding ,
189+
179190 [bool ]
180191 $NoFolder ,
181192
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 {
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)
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 }
327338 [string ]
328339 $Path ,
329340
341+ [PSFEncoding ]
342+ $Encoding ,
343+
330344 [hashtable ]
331345 $ParameterFlat ,
332346
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 {
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
439449if (-not (Test-Path Alias:\imt)) { Set-Alias - Name imt - Value Invoke-PSMDTemplate }
0 commit comments