38
38
Skip automatic folder creation for project templates.
39
39
By default, this command will create a folder to place files&folders in when creating a project.
40
40
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
+
41
46
. PARAMETER Parameters
42
47
A Hashtable containing parameters for use in creating the template.
43
48
75
80
[Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSPossibleIncorrectUsageOfAssignmentOperator" , " " )]
76
81
[CmdletBinding (SupportsShouldProcess = $true )]
77
82
param (
78
- [Parameter (Mandatory = $true , ValueFromPipeline = $true , ParameterSetName = ' Template' )]
79
- [PSModuleDevelopment.Template.TemplateInfo []]
80
- $Template ,
81
-
82
83
[Parameter (Mandatory = $true , Position = 0 , ParameterSetName = ' NameStore' )]
83
84
[Parameter (Mandatory = $true , Position = 0 , ParameterSetName = ' NamePath' )]
84
85
[string ]
85
86
$TemplateName ,
86
87
88
+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , ParameterSetName = ' Template' )]
89
+ [PSModuleDevelopment.Template.TemplateInfo []]
90
+ $Template ,
91
+
87
92
[Parameter (ParameterSetName = ' NameStore' )]
88
93
[string ]
89
94
$Store = " *" ,
100
105
[string ]
101
106
$Name ,
102
107
108
+ [PSFEncoding ]
109
+ $Encoding = (Get-PSFConfigValue - FullName ' PSFramework.Text.Encoding.DefaultWrite' ),
110
+
103
111
[switch ]
104
112
$NoFolder ,
105
113
176
184
[string ]
177
185
$OutPath ,
178
186
187
+ [PSFEncoding ]
188
+ $Encoding ,
189
+
179
190
[bool ]
180
191
$NoFolder ,
181
192
237
248
{
238
249
foreach ($child in $templateData.Children )
239
250
{
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
241
252
}
242
253
if ($Raw -and $templateData.Scripts.Values )
243
254
{
272
283
273
284
foreach ($child in $templateData.Children )
274
285
{
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
276
287
}
277
288
278
289
# region Write Config File (Raw)
308
319
}
309
320
310
321
$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
312
323
}
313
324
# endregion Write Config File (Raw)
314
325
}
327
338
[string ]
328
339
$Path ,
329
340
341
+ [PSFEncoding ]
342
+ $Encoding ,
343
+
330
344
[hashtable ]
331
345
$ParameterFlat ,
332
346
373
387
$text = $text -replace " $ ( $identifier ) !$ ( [regex ]::Escape($param )) !$ ( $identifier ) " , $ParameterScript [$param ]
374
388
}
375
389
}
376
- [System.IO.File ]::WriteAllText($destPath , $text )
390
+ [System.IO.File ]::WriteAllText($destPath , $text , $Encoding )
377
391
}
378
392
else
379
393
{
417
431
{
418
432
if ($PSCmdlet.ShouldProcess ($item , " Invoking template" ))
419
433
{
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 }
421
435
catch { Stop-PSFFunction - Message " Failed to invoke template $ ( $item ) " - EnableException $EnableException - ErrorRecord $_ - Target $item - Tag ' fail' , ' template' , ' invoke' - Continue }
422
436
}
423
437
}
424
438
foreach ($item in $templates )
425
439
{
426
440
if ($PSCmdlet.ShouldProcess ($item , " Invoking template" ))
427
441
{
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 }
429
443
catch { Stop-PSFFunction - Message " Failed to invoke template $ ( $item ) " - EnableException $EnableException - ErrorRecord $_ - Target $item - Tag ' fail' , ' template' , ' invoke' - Continue }
430
444
}
431
445
}
432
446
}
433
- end
434
- {
435
-
436
- }
437
447
}
438
448
439
449
if (-not (Test-Path Alias:\imt)) { Set-Alias - Name imt - Value Invoke-PSMDTemplate }
0 commit comments