Skip to content

Commit 6a79d23

Browse files
Merge pull request #182 from PowershellFrameworkCollective/development
2.2.11.146
2 parents 51f0dab + 730f49b commit 6a79d23

File tree

18 files changed

+417
-42
lines changed

18 files changed

+417
-42
lines changed

PSModuleDevelopment/PSModuleDevelopment.psd1

Lines changed: 3 additions & 3 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.11.139'
8+
ModuleVersion = '2.2.11.146'
99

1010
# ID used to uniquely identify this module
1111
GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6'
@@ -28,8 +28,8 @@
2828
# Modules that must be imported into the global environment prior to importing
2929
# this module
3030
RequiredModules = @(
31-
@{ ModuleName = 'PSFramework'; ModuleVersion = '1.6.214' }
32-
@{ ModuleName = 'string'; ModuleVersion = '1.0.0' }
31+
@{ ModuleName = 'PSFramework'; ModuleVersion = '1.7.270' }
32+
@{ ModuleName = 'string'; ModuleVersion = '1.1.3' }
3333
)
3434

3535
# Assemblies that must be loaded prior to importing this module

PSModuleDevelopment/changelog.md

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

3+
## 2.2.11.146 (2023-05-31)
4+
5+
+ Upd: Export-PSMDString - added support for Get-PSMDLocalizedString calls (#181, thanks @nyanhp)
6+
+ Upd: Invoke-PSMDTemplate - added support from template configuration files (#161)
7+
+ Upd: Template MiniModule - added gitignore & main branch for automation (#179, Thanks @nyanhp)
8+
+ Upd: Template MiniModule - switched github automation from windows-2019 to windows-latest
9+
+ Upd: Template PSFProject - added main branch to build autopmation
10+
+ Upd: Template PSFProject - switched github automation from windows-2019 to windows-latest
11+
+ Upd: Templating - added common picture formats to the list of binary file extensions (#175)
12+
313
## 2.2.11.139 (2022-04-29)
414

515
+ Fix: Invoke-PSMDTemplate - fails to generate templates on PS 5.1, due to splatting vs. explicitly bound parameter (#172)

PSModuleDevelopment/functions/refactor/Export-PSMDString.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@
4848
#region Command Parameters
4949
$commandAsts = $ast.FindAll({
5050
if ($args[0] -isnot [System.Management.Automation.Language.CommandAst]) { return $false }
51-
if ($args[0].CommandElements[0].Value -notmatch '^Invoke-PSFProtectedCommand$|^Write-PSFMessage$|^Stop-PSFFunction$|^Test-PSFShouldProcess$') { return $false }
52-
if (-not ($args[0].CommandElements.ParameterName -match '^String$|^ActionString$')) { return $false }
51+
if ($args[0].CommandElements[0].Value -notmatch '^Invoke-PSFProtectedCommand$|^Write-PSFMessage$|^Stop-PSFFunction$|^Test-PSFShouldProcess$|^Get-PSFLocalizedString$') { return $false }
52+
if (-not ($args[0].CommandElements.ParameterName -match '^String$|^ActionString$|^Name$')) { return $false }
5353
$true
5454
}, $true)
5555

5656
foreach ($commandAst in $commandAsts)
5757
{
58-
$stringParam = $commandAst.CommandElements | Where-Object ParameterName -match '^String$|^ActionString$'
58+
$stringParam = $commandAst.CommandElements | Where-Object ParameterName -match '^String$|^ActionString$|^Name$'
5959
$stringParamValue = $commandAst.CommandElements[($commandAst.CommandElements.IndexOf($stringParam) + 1)].Value
6060

61-
$stringValueParam = $commandAst.CommandElements | Where-Object ParameterName -match '^StringValues$|^ActionStringValues$'
61+
$stringValueParam = $commandAst.CommandElements | Where-Object ParameterName -match '^StringValues$|^ActionStringValues$|^Name$'
6262
if ($stringValueParam)
6363
{
6464
$stringValueParamValue = $commandAst.CommandElements[($commandAst.CommandElements.IndexOf($stringValueParam) + 1)].Extent.Text

PSModuleDevelopment/functions/refactor/Set-PSMDParameterHelp.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
- Will only process the parameter 'Foo'
4848
- And replace the current text with the one specified
4949
#>
50-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
51-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
52-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
50+
5351
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
5452
[CmdletBinding()]
5553
Param (

PSModuleDevelopment/functions/templating/Invoke-PSMDTemplate.ps1

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
6060
.PARAMETER Silent
6161
This places the function in unattended mode, causing it to error on anything requiring direct user input.
62+
63+
.PARAMETER NoConfigFile
64+
By default, this command will look in the execution path and above for files named "PSMDConfig.psd1" to populate template parameters from.
6265
6366
.PARAMETER EnableException
6467
Replaces user friendly yellow warnings with bloody red exceptions of doom!
@@ -132,12 +135,17 @@
132135

133136
[switch]
134137
$Silent,
138+
139+
[switch]
140+
$NoConfigFile,
135141

136142
[switch]
137143
$EnableException
138144
)
139145

140146
begin {
147+
$resolvedPath = Resolve-PSFPath -Path $OutPath
148+
141149
$templates = @()
142150
switch ($PSCmdlet.ParameterSetName) {
143151
'NameStore' { $templates = Get-PSMDTemplate -TemplateName $TemplateName -Store $Store }
@@ -152,12 +160,8 @@
152160
if (-not $Parameters) { $Parameters = @{ } }
153161
if ($Name) { $Parameters["Name"] = $Name }
154162

155-
foreach ($config in (Get-PSFConfig -Module 'PSModuleDevelopment' -Name 'Template.ParameterDefault.*')) {
156-
$cfgName = $config.Name -replace '^.+\.([^\.]+)$', '$1'
157-
if (-not $Parameters.ContainsKey($cfgName)) {
158-
$Parameters[$cfgName] = $config.Value
159-
}
160-
}
163+
if ($NoConfigFile) { $paramCloned = Resolve-TemplateParameter -Configuration $Parameters -FromConfiguration}
164+
else { $paramCloned = Resolve-TemplateParameter -Path $resolvedPath -Configuration $Parameters -FromConfiguration }
161165
#endregion Parameter Processing
162166

163167
#region Helper function
@@ -440,8 +444,8 @@
440444
if (Test-PSFFunctionInterrupt) { return }
441445

442446
$invokeParam = @{
443-
Parameters = $Parameters.Clone()
444-
OutPath = Resolve-PSFPath -Path $OutPath
447+
Parameters = $paramCloned
448+
OutPath = $resolvedPath
445449
NoFolder = $NoFolder
446450
Encoding = $Encoding
447451
Raw = $Raw

PSModuleDevelopment/internal/configurations/template.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Set-PSFConfig -Module 'PSModuleDevelopment' -Name 'Template.ParameterDefault.Aut
66
Set-PSFConfig -Module 'PSModuleDevelopment' -Name 'Template.ParameterDefault.Company' -Value "MyCompany" -Initialize -Validation 'string' -Description "The default value to set for the parameter 'Company'. This same setting can be created for any other parameter name."
77

88
# The file extensions that will not be scanned for content replacement and will be stored as bytes
9-
Set-PSFConfig -Module 'PSModuleDevelopment' -Name 'Template.BinaryExtensions' -Value @('.dll', '.exe', '.pdf', '.doc', '.docx', '.xls', '.xlsx') -Initialize -Description "When creating a template, files with these extensions will be included as raw bytes and not interpreted for parameter insertion."
9+
Set-PSFConfig -Module 'PSModuleDevelopment' -Name 'Template.BinaryExtensions' -Value @('.dll', '.exe', '.pdf', '.doc', '.docx', '.xls', '.xlsx','.png','.ico','.bmp','.jpg','.jpeg','.pdb') -Initialize -Description "When creating a template, files with these extensions will be included as raw bytes and not interpreted for parameter insertion."
1010

1111
# Define the default store. To add more stores, just add a similar setting with a different last name segment
1212
Set-PSFConfig -Module 'PSModuleDevelopment' -Name 'Template.Store.Default' -Value (Join-Path -Path (Get-PSFPath -Name AppData) -ChildPath "WindowsPowerShell/PSModuleDevelopment/Templates") -Initialize -Validation "string" -Description "Path to the default directory where PSModuleDevelopment will store its templates. You can add additional stores by creating the same setting again, only changing the last name segment to a new name and configuring a separate path."
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
function Resolve-TemplateParameter {
2+
<#
3+
.SYNOPSIS
4+
Resolves the parameters to invoke a template with.
5+
6+
.DESCRIPTION
7+
Resolves the parameters to invoke a template with.
8+
9+
This processes parameters with the following, ascending priority:
10+
11+
- From Configuration (if specified)
12+
- From PSMD Configuration files (if specified)
13+
- From being explicitly specified on invocation
14+
15+
Explicitly bound parameters will thus always win.
16+
17+
.PARAMETER Path
18+
Path in which the template is being invoked.
19+
If this parameter is specified, it will search the path and all parent paths for PSMDConfig.psd1 files.
20+
Then read the settings from them, starting at the root path.
21+
The deeper the path, the later the settings are loaded, overwriting settings from parent folders in case of conflict.
22+
23+
.PARAMETER Configuration
24+
The Configuration settings specified by the user.
25+
These take precedence over anything else.
26+
27+
.PARAMETER FromConfiguration
28+
Whether to load configuration settings from configuration.
29+
30+
.EXAMPLE
31+
PS C:\> Resolve-TemplateParameter -Path $resolvedPath -Configuration $Configuration -FromConfiguration
32+
33+
Resolves all parameters for the current template.
34+
#>
35+
[OutputType([hashtable])]
36+
[CmdletBinding()]
37+
param (
38+
[string]
39+
$Path,
40+
41+
[hashtable]
42+
$Configuration = @{ },
43+
44+
[switch]
45+
$FromConfiguration
46+
)
47+
process {
48+
$newConfiguration = @{ }
49+
50+
if ($Path) {
51+
$currentPath = $Path
52+
$paths = while ($currentPath) {
53+
$currentPath
54+
$currentPath = Split-Path $currentPath
55+
}
56+
57+
foreach ($rootPath in $paths | Sort-Object Length) {
58+
$configPath = Join-Path $rootPath 'PSMDConfig.psd1'
59+
if (-not (Test-Path -Path $configPath)) { continue }
60+
61+
$cfg = Import-PSFPowerShellDataFile -Path $configPath
62+
if ($cfg -and $cfg -is [hashtable]) {
63+
foreach ($pair in $cfg.GetEnumerator()) {
64+
$newConfiguration[$pair.Key] = $pair.Value
65+
}
66+
}
67+
}
68+
}
69+
70+
foreach ($pair in $Configuration.GetEnumerator()) {
71+
$newConfiguration[$pair.Key] = $pair.Value
72+
}
73+
74+
if ($FromConfiguration) {
75+
foreach ($config in Get-PSFConfig -Module 'PSModuleDevelopment' -Name 'Template.ParameterDefault.*') {
76+
$cfgName = $config.Name -replace '^.+\.([^\.]+)$', '$1'
77+
if (-not $newConfiguration.ContainsKey($cfgName)) {
78+
$newConfiguration[$cfgName] = $config.Value
79+
}
80+
}
81+
}
82+
83+
$newConfiguration
84+
}
85+
}

README.md

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,70 @@
1-
# Purpose
1+
# PSModuleDevelopment
22

3-
The PSModuleDevelopment module is designed to provide tools that help with - big surprise incoming - module development.
4-
This attempts to help with:
5-
- Speeding up iterative procedures, especially reinitiating tests runs
6-
- Debugging Execution
7-
- Development Research & Analytics
8-
- Miscellaneous other things
3+
Welcome to your one stop for PowerShell development tools!
4+
This project is designed to help you with accelerating your coding workflows through a wide range of utilities.
5+
Its flagship feature is a *templating engine* that allows you to swiftly create new projects - either by using some of the default templates or easily creating your own.
96

10-
# Alias Warning
7+
## Online Documentation
118

12-
This module actually ships with convenience aliases.
9+
As this module is part of the PSFramework project, its documentation can be found on [PSFramework.org](https://psframework.org/documentation/documents/psmoduledevelopment/templates.html).
1310

14-
Generally, modules should leave aliases like that to the user's preference.
15-
However, in this instance, the main purpose is to optimize the performance of the developer, which requires the use of aliases.
11+
> As ever, documentation takes time out of _"more features!"_, so there could be more, but at least the templating is covered in depth.
1612
17-
Due to this, the decision was made to ship the module with aliases.
13+
## Install
1814

19-
# Configuration Notice
15+
To get read to use this module, run this:
2016

21-
This module uses the PSFramework for configuration management (and many other things).
22-
Run `Get-PSFConfig -Module PSModuleDevelopment` in order to retrieve the full list of configurations set.
17+
```powershell
18+
Install-Module PSModuleDevelopment -Scope CurrentUser
19+
```
2320

24-
# Profile notice
21+
## Profit
2522

26-
Some features of this module assume, that it is in the profile and automtically imported on console start.
27-
It is still possible to profit from the module without this, but it is highly recommended to add the module import to the PowerShell profile
23+
With that you are ready to go and have fun with it.
24+
A few examples of what it can do for you:
25+
26+
> Create a new module project
27+
28+
```powershell
29+
Invoke-PSMDTemplate MiniModule
30+
```
31+
32+
> Parse a script file and export all functions into dedicated files
33+
34+
```powershell
35+
Split-PSMDScriptFile -File .\largescript.ps1 -Path .\functions
36+
```
37+
38+
> Fix all the file encodings
39+
40+
```powershell
41+
Get-ChildItem -Recurse -File | Set-PSMDEncoding
42+
```
43+
44+
> Fix parameter blocks
45+
46+
```powershell
47+
Get-ChildItem -Recurse -File | Set-PSMDCmdletBinding
48+
```
49+
50+
> Get better members
51+
52+
```powershell
53+
Get-Date | Get-PSMDMember -Name ToString
54+
```
55+
56+
> Search for Assemblies and Types
57+
58+
```powershell
59+
# List all assemblies
60+
Get-PSMDAssembly
61+
62+
# Search for types in that assembly
63+
Get-PSMDAssembly *ActiveDirectory* | Find-PSMDType
64+
65+
# Search for all types implementing IEnumerable
66+
Find-PSMDType -Implements IEnumerable
67+
68+
# Get Constructors
69+
[DateTime] | Get-PSMDConstructor
70+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
param (
2+
$Path
3+
)
4+
5+
New-PSMDTemplate -ReferencePath "$PSScriptRoot" -OutPath $Path
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@{
2+
TemplateName = 'dscclass'
3+
Version = "1.0.0.0"
4+
AutoIncrementVersion = $true
5+
Tags = 'dscresource'
6+
Author = 'Jan-Hendrik Peters'
7+
Description = 'Basic class-based DSC resource template with support for Azure Guest Configuration'
8+
Exclusions = @("PSMDInvoke.ps1") # Contains list of files - relative path to root - to ignore when building the template
9+
Scripts = @{
10+
guid = {
11+
[System.Guid]::NewGuid().ToString()
12+
}
13+
year = {
14+
Get-Date -Format "yyyy"
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)