From af078c52dd123d7691d5a1c255ad68da778b0a3d Mon Sep 17 00:00:00 2001 From: Ferdi Weiner <36640422+ferwe@users.noreply.github.com> Date: Mon, 9 May 2022 20:26:04 +0200 Subject: [PATCH 1/5] Update azure-pipelines.yml As the windows 2016 hosted runners is deprecated, the best practice is to replace it with windows-latest. Any new PSMDProject shouldn't use the 2016 host anymore. See GitHub Issue: https://github.com/actions/virtual-environments/issues/5403 Windows 2016 hosted runners were scheduled for full removal on April 1, 2022. However, we are still seeing significant usage from customers and we want to give them more time to migrate to the new runners. In order to give customers another chance to move to either windows-2019 or windows-2022 we will delay the removal of windows-2016 until June 30, 2022. --- templates/PSFProject/azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/PSFProject/azure-pipelines.yml b/templates/PSFProject/azure-pipelines.yml index f33fd30..444347c 100644 --- a/templates/PSFProject/azure-pipelines.yml +++ b/templates/PSFProject/azure-pipelines.yml @@ -1,5 +1,5 @@ pool: - name: Hosted VS2017 + vmImage: "windows-latest" steps: - task: PowerShell@2 displayName: Prerequisites From e2d6b42e2040d9aadc3e888b9f0875636debccb4 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Peters Date: Wed, 20 Jul 2022 12:25:54 +0200 Subject: [PATCH 2/5] Added class-based DSC resource template --- .../DscClassBasedResource/PSMDInvoke.ps1 | 5 + .../DscClassBasedResource/PSMDTemplate.ps1 | 17 +++ .../\303\276name\303\276.psd1" | 85 ++++++++++++ .../\303\276name\303\276.psm1" | 124 ++++++++++++++++++ 4 files changed, 231 insertions(+) create mode 100644 templates/DscClassBasedResource/PSMDInvoke.ps1 create mode 100644 templates/DscClassBasedResource/PSMDTemplate.ps1 create mode 100644 "templates/DscClassBasedResource/\303\276name\303\276.psd1" create mode 100644 "templates/DscClassBasedResource/\303\276name\303\276.psm1" diff --git a/templates/DscClassBasedResource/PSMDInvoke.ps1 b/templates/DscClassBasedResource/PSMDInvoke.ps1 new file mode 100644 index 0000000..336940e --- /dev/null +++ b/templates/DscClassBasedResource/PSMDInvoke.ps1 @@ -0,0 +1,5 @@ +param ( + $Path +) + +New-PSMDTemplate -ReferencePath "$PSScriptRoot" -OutPath $Path diff --git a/templates/DscClassBasedResource/PSMDTemplate.ps1 b/templates/DscClassBasedResource/PSMDTemplate.ps1 new file mode 100644 index 0000000..2366d77 --- /dev/null +++ b/templates/DscClassBasedResource/PSMDTemplate.ps1 @@ -0,0 +1,17 @@ +@{ + TemplateName = 'dscclass' + Version = "1.0.0.0" + AutoIncrementVersion = $true + Tags = 'dscresource' + Author = 'Jan-Hendrik Peters' + Description = 'Basic class-based DSC resource template with support for Azure Guest Configuration' + Exclusions = @("PSMDInvoke.ps1") # Contains list of files - relative path to root - to ignore when building the template + Scripts = @{ + guid = { + [System.Guid]::NewGuid().ToString() + } + year = { + Get-Date -Format "yyyy" + } + } +} \ No newline at end of file diff --git "a/templates/DscClassBasedResource/\303\276name\303\276.psd1" "b/templates/DscClassBasedResource/\303\276name\303\276.psd1" new file mode 100644 index 0000000..0b8a43e --- /dev/null +++ "b/templates/DscClassBasedResource/\303\276name\303\276.psd1" @@ -0,0 +1,85 @@ +@{ + # Script module or binary module file associated with this manifest + RootModule = 'þnameþ.psm1' + + # Version number of this module. + ModuleVersion = '1.0.0' + + # ID used to uniquely identify this module + GUID = 'þ!guid!þ' + + # Author of this module + Author = 'þauthorþ' + + # Company or vendor of this module + CompanyName = 'þcompanyþ' + + # Copyright statement for this module + Copyright = 'Copyright (c) þ!year!þ þauthorþ' + + # Description of the functionality provided by this module + Description = 'þdescriptionþ' + + # Minimum version of the Windows PowerShell engine required by this module + PowerShellVersion = '5.0' + + # Modules that must be imported into the global environment prior to importing + # this module + # RequiredModules = @() + + # Assemblies that must be loaded prior to importing this module + # RequiredAssemblies = @('bin\þnameþ.dll') + + # Type files (.ps1xml) to be loaded when importing this module + # TypesToProcess = @('xml\þnameþ.Types.ps1xml') + + # Format files (.ps1xml) to be loaded when importing this module + # FormatsToProcess = @('xml\þnameþ.Format.ps1xml') + + # Functions to export from this module + FunctionsToExport = '' + + # Cmdlets to export from this module + # CmdletsToExport = '' + + # Variables to export from this module + # VariablesToExport = '' + + # Aliases to export from this module + # AliasesToExport = '' + + DscResourcesToExport = @( + 'þnameþ' + ) + + # List of all modules packaged with this module + ModuleList = @() + + # List of all files packaged with this module + FileList = @() + + # Private data to pass to the module specified in ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. + PrivateData = @{ + + #Support for PowerShellGet galleries. + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + # Tags = @() + + # A URL to the license for this module. + # LicenseUri = '' + + # A URL to the main website for this project. + # ProjectUri = '' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + } # End of PSData hashtable + + } # End of PrivateData hashtable +} \ No newline at end of file diff --git "a/templates/DscClassBasedResource/\303\276name\303\276.psm1" "b/templates/DscClassBasedResource/\303\276name\303\276.psm1" new file mode 100644 index 0000000..90da77b --- /dev/null +++ "b/templates/DscClassBasedResource/\303\276name\303\276.psm1" @@ -0,0 +1,124 @@ +enum Ensure +{ + Present + Absent +} + +# Support for DSC v3, or Azure Guest Configuration +class Reason +{ + [DscProperty()] + [string] $Code + + [DscProperty()] + [string] $Phrase +} + +function Get-Resource +{ + [OutputType([hashtable])] + [CmdletBinding()] + param + ( + ) + + $reasonList = @() + + if ($Ensure -eq 'Present' -and -not $successfulTests) + { + $reasonList += @{ + Code = 'þnameþ:þnameþ:SomethingAwfulHappened' + Phrase = "Extend the reasonList with all errors" + } + } + + return @{ + Reasons = $reasonList + } +} + +function Set-Resource +{ + [CmdletBinding()] + param + ( + ) + +} + +function Test-Resource +{ + [OutputType([bool])] + [CmdletBinding()] + param + ( + + ) + + return $true +} + +[DscResource()] +class þnameþ +{ + [DscProperty(Key)] [string] $YourKeyProperty + [DscProperty(Mandatory)] [string] $YourRequiredProperty + [DscProperty()] [string[]] $YourStandardProperty + [DscProperty()] [Ensure] $Ensure # Usually a good idea to include + [DscProperty(NotConfigurable)] [Reason[]] $Reasons # Reserved for Azure Guest Configuration + + þnameþ () + { + $this.Ensure = 'Present' # Set up defaults + } + + [þnameþ] Get() + { + $parameter = $this.GetConfigurableDscProperties() + return (Get-Resource @parameter) + } + + [void] Set() + { + $parameter = $this.GetConfigurableDscProperties() + Set-Resource @parameter + } + + [bool] Test() + { + $parameter = $this.GetConfigurableDscProperties() + return (Test-Resource @parameter) + } + + [Hashtable] GetConfigurableDscProperties() + { + # This method returns a hashtable of properties with two special workarounds + # The hashtable will not include any properties marked as "NotConfigurable" + # Any properties with a ValidateSet of "True","False" will beconverted to Boolean type + # The intent is to simplify splatting to functions + # Source: https://gist.github.com/mgreenegit/e3a9b4e136fc2d510cf87e20390daa44 + $DscProperties = @{} + foreach ($property in [þnameþ].GetProperties().Name) + { + # Checks if "NotConfigurable" attribute is set + $notConfigurable = [þnameþ].GetProperty($property).GetCustomAttributes($false).Where({ $_ -is [System.Management.Automation.DscPropertyAttribute] }).NotConfigurable + if (!$notConfigurable) + { + $value = $this.$property + # Gets the list of valid values from the ValidateSet attribute + $validateSet = [þnameþ].GetProperty($property).GetCustomAttributes($false).Where({ $_ -is [System.Management.Automation.ValidateSetAttribute] }).ValidValues + if ($validateSet) + { + # Workaround for boolean types + if ($null -eq (Compare-Object @('True', 'False') $validateSet)) + { + $value = [System.Convert]::ToBoolean($this.$property) + } + } + # Add property to new + $DscProperties.add($property, $value) + } + } + return $DscProperties + } +} From 7f235ad9ec8e71705646dda11b6bd918c66ae3d4 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Peters Date: Tue, 21 Feb 2023 20:14:50 +0100 Subject: [PATCH 3/5] Add gitignore, include branch main --- templates/MiniModule/.github/workflows/build.yml | 1 + templates/MiniModule/.gitignore | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 templates/MiniModule/.gitignore diff --git a/templates/MiniModule/.github/workflows/build.yml b/templates/MiniModule/.github/workflows/build.yml index 80cac05..3c216cf 100644 --- a/templates/MiniModule/.github/workflows/build.yml +++ b/templates/MiniModule/.github/workflows/build.yml @@ -2,6 +2,7 @@ push: branches: - master + - main jobs: build: diff --git a/templates/MiniModule/.gitignore b/templates/MiniModule/.gitignore new file mode 100644 index 0000000..82e1864 --- /dev/null +++ b/templates/MiniModule/.gitignore @@ -0,0 +1,2 @@ +publish +TestResults From a6c4debbf1180c7378a2114ae7c19351332bc2cd Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Peters Date: Tue, 23 May 2023 12:14:32 +0200 Subject: [PATCH 4/5] Export strings retrieved by Get-PSFLocalizedString --- .../functions/refactor/Export-PSMDString.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PSModuleDevelopment/functions/refactor/Export-PSMDString.ps1 b/PSModuleDevelopment/functions/refactor/Export-PSMDString.ps1 index 52b16b6..a3a829a 100644 --- a/PSModuleDevelopment/functions/refactor/Export-PSMDString.ps1 +++ b/PSModuleDevelopment/functions/refactor/Export-PSMDString.ps1 @@ -48,17 +48,17 @@ #region Command Parameters $commandAsts = $ast.FindAll({ if ($args[0] -isnot [System.Management.Automation.Language.CommandAst]) { return $false } - if ($args[0].CommandElements[0].Value -notmatch '^Invoke-PSFProtectedCommand$|^Write-PSFMessage$|^Stop-PSFFunction$|^Test-PSFShouldProcess$') { return $false } - if (-not ($args[0].CommandElements.ParameterName -match '^String$|^ActionString$')) { return $false } + if ($args[0].CommandElements[0].Value -notmatch '^Invoke-PSFProtectedCommand$|^Write-PSFMessage$|^Stop-PSFFunction$|^Test-PSFShouldProcess$|^Get-PSFLocalizedString$') { return $false } + if (-not ($args[0].CommandElements.ParameterName -match '^String$|^ActionString$|^Name$')) { return $false } $true }, $true) foreach ($commandAst in $commandAsts) { - $stringParam = $commandAst.CommandElements | Where-Object ParameterName -match '^String$|^ActionString$' + $stringParam = $commandAst.CommandElements | Where-Object ParameterName -match '^String$|^ActionString$|^Name$' $stringParamValue = $commandAst.CommandElements[($commandAst.CommandElements.IndexOf($stringParam) + 1)].Value - $stringValueParam = $commandAst.CommandElements | Where-Object ParameterName -match '^StringValues$|^ActionStringValues$' + $stringValueParam = $commandAst.CommandElements | Where-Object ParameterName -match '^StringValues$|^ActionStringValues$|^Name$' if ($stringValueParam) { $stringValueParamValue = $commandAst.CommandElements[($commandAst.CommandElements.IndexOf($stringValueParam) + 1)].Extent.Text From 730f49bee941a4613dc25b579a80cbaed7750c23 Mon Sep 17 00:00:00 2001 From: Friedrich Weinmann Date: Wed, 31 May 2023 10:35:56 +0200 Subject: [PATCH 5/5] updates --- PSModuleDevelopment/PSModuleDevelopment.psd1 | 6 +- PSModuleDevelopment/changelog.md | 10 +++ .../refactor/Set-PSMDParameterHelp.ps1 | 4 +- .../templating/Invoke-PSMDTemplate.ps1 | 20 +++-- .../internal/configurations/template.ps1 | 2 +- .../templating/Resolve-TemplateParameter.ps1 | 85 +++++++++++++++++++ README.md | 79 +++++++++++++---- .../MiniModule/.github/workflows/build.yml | 2 +- .../MiniModule/.github/workflows/validate.yml | 2 +- .../PSFProject/.github/workflows/build.yml | 3 +- .../PSFProject/.github/workflows/validate.yml | 2 +- 11 files changed, 178 insertions(+), 37 deletions(-) create mode 100644 PSModuleDevelopment/internal/functions/templating/Resolve-TemplateParameter.ps1 diff --git a/PSModuleDevelopment/PSModuleDevelopment.psd1 b/PSModuleDevelopment/PSModuleDevelopment.psd1 index 957035b..74bf660 100644 --- a/PSModuleDevelopment/PSModuleDevelopment.psd1 +++ b/PSModuleDevelopment/PSModuleDevelopment.psd1 @@ -5,7 +5,7 @@ # Version number of this module. - ModuleVersion = '2.2.11.139' + ModuleVersion = '2.2.11.146' # ID used to uniquely identify this module GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6' @@ -28,8 +28,8 @@ # Modules that must be imported into the global environment prior to importing # this module RequiredModules = @( - @{ ModuleName = 'PSFramework'; ModuleVersion = '1.6.214' } - @{ ModuleName = 'string'; ModuleVersion = '1.0.0' } + @{ ModuleName = 'PSFramework'; ModuleVersion = '1.7.270' } + @{ ModuleName = 'string'; ModuleVersion = '1.1.3' } ) # Assemblies that must be loaded prior to importing this module diff --git a/PSModuleDevelopment/changelog.md b/PSModuleDevelopment/changelog.md index 48a3d12..268805b 100644 --- a/PSModuleDevelopment/changelog.md +++ b/PSModuleDevelopment/changelog.md @@ -1,5 +1,15 @@ # Changelog +## 2.2.11.146 (2023-05-31) + ++ Upd: Export-PSMDString - added support for Get-PSMDLocalizedString calls (#181, thanks @nyanhp) ++ Upd: Invoke-PSMDTemplate - added support from template configuration files (#161) ++ Upd: Template MiniModule - added gitignore & main branch for automation (#179, Thanks @nyanhp) ++ Upd: Template MiniModule - switched github automation from windows-2019 to windows-latest ++ Upd: Template PSFProject - added main branch to build autopmation ++ Upd: Template PSFProject - switched github automation from windows-2019 to windows-latest ++ Upd: Templating - added common picture formats to the list of binary file extensions (#175) + ## 2.2.11.139 (2022-04-29) + Fix: Invoke-PSMDTemplate - fails to generate templates on PS 5.1, due to splatting vs. explicitly bound parameter (#172) diff --git a/PSModuleDevelopment/functions/refactor/Set-PSMDParameterHelp.ps1 b/PSModuleDevelopment/functions/refactor/Set-PSMDParameterHelp.ps1 index d466dbc..49e4aeb 100644 --- a/PSModuleDevelopment/functions/refactor/Set-PSMDParameterHelp.ps1 +++ b/PSModuleDevelopment/functions/refactor/Set-PSMDParameterHelp.ps1 @@ -47,9 +47,7 @@ - Will only process the parameter 'Foo' - And replace the current text with the one specified #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] [CmdletBinding()] Param ( diff --git a/PSModuleDevelopment/functions/templating/Invoke-PSMDTemplate.ps1 b/PSModuleDevelopment/functions/templating/Invoke-PSMDTemplate.ps1 index 1e8804a..3a8b34f 100644 --- a/PSModuleDevelopment/functions/templating/Invoke-PSMDTemplate.ps1 +++ b/PSModuleDevelopment/functions/templating/Invoke-PSMDTemplate.ps1 @@ -59,6 +59,9 @@ .PARAMETER Silent This places the function in unattended mode, causing it to error on anything requiring direct user input. + + .PARAMETER NoConfigFile + By default, this command will look in the execution path and above for files named "PSMDConfig.psd1" to populate template parameters from. .PARAMETER EnableException Replaces user friendly yellow warnings with bloody red exceptions of doom! @@ -132,12 +135,17 @@ [switch] $Silent, + + [switch] + $NoConfigFile, [switch] $EnableException ) begin { + $resolvedPath = Resolve-PSFPath -Path $OutPath + $templates = @() switch ($PSCmdlet.ParameterSetName) { 'NameStore' { $templates = Get-PSMDTemplate -TemplateName $TemplateName -Store $Store } @@ -152,12 +160,8 @@ if (-not $Parameters) { $Parameters = @{ } } if ($Name) { $Parameters["Name"] = $Name } - foreach ($config in (Get-PSFConfig -Module 'PSModuleDevelopment' -Name 'Template.ParameterDefault.*')) { - $cfgName = $config.Name -replace '^.+\.([^\.]+)$', '$1' - if (-not $Parameters.ContainsKey($cfgName)) { - $Parameters[$cfgName] = $config.Value - } - } + if ($NoConfigFile) { $paramCloned = Resolve-TemplateParameter -Configuration $Parameters -FromConfiguration} + else { $paramCloned = Resolve-TemplateParameter -Path $resolvedPath -Configuration $Parameters -FromConfiguration } #endregion Parameter Processing #region Helper function @@ -440,8 +444,8 @@ if (Test-PSFFunctionInterrupt) { return } $invokeParam = @{ - Parameters = $Parameters.Clone() - OutPath = Resolve-PSFPath -Path $OutPath + Parameters = $paramCloned + OutPath = $resolvedPath NoFolder = $NoFolder Encoding = $Encoding Raw = $Raw diff --git a/PSModuleDevelopment/internal/configurations/template.ps1 b/PSModuleDevelopment/internal/configurations/template.ps1 index 79a6981..1a14e46 100644 --- a/PSModuleDevelopment/internal/configurations/template.ps1 +++ b/PSModuleDevelopment/internal/configurations/template.ps1 @@ -6,7 +6,7 @@ Set-PSFConfig -Module 'PSModuleDevelopment' -Name 'Template.ParameterDefault.Aut 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." # The file extensions that will not be scanned for content replacement and will be stored as bytes -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." +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." # Define the default store. To add more stores, just add a similar setting with a different last name segment 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." diff --git a/PSModuleDevelopment/internal/functions/templating/Resolve-TemplateParameter.ps1 b/PSModuleDevelopment/internal/functions/templating/Resolve-TemplateParameter.ps1 new file mode 100644 index 0000000..dc13491 --- /dev/null +++ b/PSModuleDevelopment/internal/functions/templating/Resolve-TemplateParameter.ps1 @@ -0,0 +1,85 @@ +function Resolve-TemplateParameter { + <# + .SYNOPSIS + Resolves the parameters to invoke a template with. + + .DESCRIPTION + Resolves the parameters to invoke a template with. + + This processes parameters with the following, ascending priority: + + - From Configuration (if specified) + - From PSMD Configuration files (if specified) + - From being explicitly specified on invocation + + Explicitly bound parameters will thus always win. + + .PARAMETER Path + Path in which the template is being invoked. + If this parameter is specified, it will search the path and all parent paths for PSMDConfig.psd1 files. + Then read the settings from them, starting at the root path. + The deeper the path, the later the settings are loaded, overwriting settings from parent folders in case of conflict. + + .PARAMETER Configuration + The Configuration settings specified by the user. + These take precedence over anything else. + + .PARAMETER FromConfiguration + Whether to load configuration settings from configuration. + + .EXAMPLE + PS C:\> Resolve-TemplateParameter -Path $resolvedPath -Configuration $Configuration -FromConfiguration + + Resolves all parameters for the current template. + #> + [OutputType([hashtable])] + [CmdletBinding()] + param ( + [string] + $Path, + + [hashtable] + $Configuration = @{ }, + + [switch] + $FromConfiguration + ) + process { + $newConfiguration = @{ } + + if ($Path) { + $currentPath = $Path + $paths = while ($currentPath) { + $currentPath + $currentPath = Split-Path $currentPath + } + + foreach ($rootPath in $paths | Sort-Object Length) { + $configPath = Join-Path $rootPath 'PSMDConfig.psd1' + if (-not (Test-Path -Path $configPath)) { continue } + + $cfg = Import-PSFPowerShellDataFile -Path $configPath + if ($cfg -and $cfg -is [hashtable]) { + foreach ($pair in $cfg.GetEnumerator()) { + $newConfiguration[$pair.Key] = $pair.Value + } + } + } + } + + foreach ($pair in $Configuration.GetEnumerator()) { + $newConfiguration[$pair.Key] = $pair.Value + } + + if ($FromConfiguration) { + foreach ($config in Get-PSFConfig -Module 'PSModuleDevelopment' -Name 'Template.ParameterDefault.*') { + $cfgName = $config.Name -replace '^.+\.([^\.]+)$', '$1' + if (-not $newConfiguration.ContainsKey($cfgName)) { + $newConfiguration[$cfgName] = $config.Value + } + } + } + + $newConfiguration + } +} \ No newline at end of file diff --git a/README.md b/README.md index 933c61f..9329c12 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,70 @@ -# Purpose +# PSModuleDevelopment -The PSModuleDevelopment module is designed to provide tools that help with - big surprise incoming - module development. -This attempts to help with: - - Speeding up iterative procedures, especially reinitiating tests runs - - Debugging Execution - - Development Research & Analytics - - Miscellaneous other things +Welcome to your one stop for PowerShell development tools! +This project is designed to help you with accelerating your coding workflows through a wide range of utilities. +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. -# Alias Warning +## Online Documentation -This module actually ships with convenience aliases. +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). -Generally, modules should leave aliases like that to the user's preference. -However, in this instance, the main purpose is to optimize the performance of the developer, which requires the use of aliases. +> As ever, documentation takes time out of _"more features!"_, so there could be more, but at least the templating is covered in depth. -Due to this, the decision was made to ship the module with aliases. +## Install -# Configuration Notice +To get read to use this module, run this: -This module uses the PSFramework for configuration management (and many other things). -Run `Get-PSFConfig -Module PSModuleDevelopment` in order to retrieve the full list of configurations set. +```powershell +Install-Module PSModuleDevelopment -Scope CurrentUser +``` -# Profile notice +## Profit -Some features of this module assume, that it is in the profile and automtically imported on console start. -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 \ No newline at end of file +With that you are ready to go and have fun with it. +A few examples of what it can do for you: + +> Create a new module project + +```powershell +Invoke-PSMDTemplate MiniModule +``` + +> Parse a script file and export all functions into dedicated files + +```powershell +Split-PSMDScriptFile -File .\largescript.ps1 -Path .\functions +``` + +> Fix all the file encodings + +```powershell +Get-ChildItem -Recurse -File | Set-PSMDEncoding +``` + +> Fix parameter blocks + +```powershell +Get-ChildItem -Recurse -File | Set-PSMDCmdletBinding +``` + +> Get better members + +```powershell +Get-Date | Get-PSMDMember -Name ToString +``` + +> Search for Assemblies and Types + +```powershell +# List all assemblies +Get-PSMDAssembly + +# Search for types in that assembly +Get-PSMDAssembly *ActiveDirectory* | Find-PSMDType + +# Search for all types implementing IEnumerable +Find-PSMDType -Implements IEnumerable + +# Get Constructors +[DateTime] | Get-PSMDConstructor +``` diff --git a/templates/MiniModule/.github/workflows/build.yml b/templates/MiniModule/.github/workflows/build.yml index 3c216cf..a8949be 100644 --- a/templates/MiniModule/.github/workflows/build.yml +++ b/templates/MiniModule/.github/workflows/build.yml @@ -7,7 +7,7 @@ jobs: build: - runs-on: windows-2019 + runs-on: windows-latest steps: - uses: actions/checkout@v1 diff --git a/templates/MiniModule/.github/workflows/validate.yml b/templates/MiniModule/.github/workflows/validate.yml index 0b516ce..51423aa 100644 --- a/templates/MiniModule/.github/workflows/validate.yml +++ b/templates/MiniModule/.github/workflows/validate.yml @@ -3,7 +3,7 @@ jobs: validate: - runs-on: windows-2019 + runs-on: windows-latest steps: - uses: actions/checkout@v1 diff --git a/templates/PSFProject/.github/workflows/build.yml b/templates/PSFProject/.github/workflows/build.yml index 2bd1de8..08e7b53 100644 --- a/templates/PSFProject/.github/workflows/build.yml +++ b/templates/PSFProject/.github/workflows/build.yml @@ -2,11 +2,12 @@ on: push: branches: - master + - main jobs: build: - runs-on: windows-2019 + runs-on: windows-latest steps: - uses: actions/checkout@v1 diff --git a/templates/PSFProject/.github/workflows/validate.yml b/templates/PSFProject/.github/workflows/validate.yml index 64387f3..8db7349 100644 --- a/templates/PSFProject/.github/workflows/validate.yml +++ b/templates/PSFProject/.github/workflows/validate.yml @@ -3,7 +3,7 @@ on: [pull_request] jobs: validate: - runs-on: windows-2019 + runs-on: windows-latest steps: - uses: actions/checkout@v1