Skip to content

Commit a1954b1

Browse files
Merge pull request #64 from PowershellFrameworkCollective/development
2.2.5.37
2 parents b6e0776 + 8b43816 commit a1954b1

File tree

17 files changed

+188
-120
lines changed

17 files changed

+188
-120
lines changed

PSModuleDevelopment/PSModuleDevelopment.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
RootModule = 'PSModuleDevelopment.psm1'
55

66
# Version number of this module.
7-
ModuleVersion = '2.2.5.31'
7+
ModuleVersion = '2.2.5.37'
88

99
# ID used to uniquely identify this module
1010
GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6'

PSModuleDevelopment/PSModuleDevelopment.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$script:PSModuleRoot = $PSScriptRoot
2-
$script:PSModuleVersion = "2.2.5.31"
2+
$script:PSModuleVersion = "2.2.5.37"
33

44
$script:doDotSource = $false
55
if (Get-PSFConfigValue -FullName PSModuleDevelopment.Import.DoDotSource) { $script:doDotSource = $true }

PSModuleDevelopment/changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
# Changelog
2+
## 2.2.5.37 ( October 20th, 2018)
3+
- Upd: Set-PSMDModulePath - add `-Module` parameter to persist the setting
4+
- Upd: Set-PSMDModulePath - add `-Register` parameter for integrated persistence
5+
- Upd: Set-PSMDEncoding - use `PSFEncoding` parameter class & tabcompletion
6+
- Upd: Template PSFProject - build directly into psm1
7+
- Upd: Template PSFProject, PSFModule - automatically read version in psm1 from psd1, rather than requiring explicit maintenance.
8+
- Fix: Template PSFTest - use category exclusions
9+
210
## 2.2.5.31 (September 29th, 2018)
311
- Fix: Template PSFProject dependencies installed correctly
412

PSModuleDevelopment/functions/refactor/Set-PSMDEncoding.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
[string[]]
4141
$Path,
4242

43-
[System.Text.Encoding]
44-
$Encoding = [System.Text.Encoding]::UTF8,
43+
[PSFEncoding]
44+
$Encoding = (Get-PSFConfigValue -FullName 'psframework.text.encoding.defaultwrite' -Fallback 'utf-8'),
4545

4646
[switch]
4747
$EnableException
Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,80 @@
11
function Set-PSMDModulePath
22
{
3-
<#
4-
.SYNOPSIS
5-
Sets the path of the module currently being developed.
6-
7-
.DESCRIPTION
8-
Sets the path of the module currently being developed.
9-
This is used by several utility commands in order to not require any path input.
3+
<#
4+
.SYNOPSIS
5+
Sets the path of the module currently being developed.
106
11-
This is a wrapper around the psframework configuration system, the same action can be taken by running this command:
12-
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $Path
13-
14-
.PARAMETER Path
15-
The path to set as currently developed module.
7+
.DESCRIPTION
8+
Sets the path of the module currently being developed.
9+
This is used by several utility commands in order to not require any path input.
1610
17-
.PARAMETER EnableException
18-
Replaces user friendly yellow warnings with bloody red exceptions of doom!
19-
Use this if you want the function to throw terminating errors you want to catch.
20-
21-
.EXAMPLE
22-
Set-PSMDModulePath -Path "C:\github\dbatools"
11+
This is a wrapper around the psframework configuration system, the same action can be taken by running this command:
12+
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $Path
13+
14+
.PARAMETER Module
15+
The module, the path of which to register.
2316
24-
Sets the current module path to "C:\github\dbatools"
17+
.PARAMETER Path
18+
The path to set as currently developed module.
2519
26-
.EXAMPLE
27-
Set-PSMDModulePath -Path "C:\github\dbatools"
28-
Register-PSFConfig -FullName 'PSModuleDevelopment.Module.Path'
20+
.PARAMETER Register
21+
Register the specified path, to have it persist across sessions
22+
23+
.PARAMETER EnableException
24+
Replaces user friendly yellow warnings with bloody red exceptions of doom!
25+
Use this if you want the function to throw terminating errors you want to catch.
26+
27+
.EXAMPLE
28+
Set-PSMDModulePath -Path "C:\github\dbatools"
29+
30+
Sets the current module path to "C:\github\dbatools"
2931
30-
Sets the current module path to "C:\github\dbatools"
31-
Then stores the setting in registry, causing it to be persisted acros multiple sessions.
32-
#>
32+
.EXAMPLE
33+
Set-PSMDModulePath -Path "C:\github\dbatools" -Register
34+
35+
Sets the current module path to "C:\github\dbatools"
36+
Then stores the setting in registry, causing it to be persisted acros multiple sessions.
37+
#>
3338
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
3439
[CmdletBinding()]
35-
Param (
36-
[Parameter(Mandatory = $true)]
40+
param (
41+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Module')]
42+
[System.Management.Automation.PSModuleInfo]
43+
$Module,
44+
45+
[Parameter(Mandatory = $true, ParameterSetName = 'Path')]
3746
[string]
3847
$Path,
3948

49+
[switch]
50+
$Register,
51+
4052
[switch]
4153
$EnableException
4254
)
4355

44-
$resolvedPath = Resolve-Path -Path $Path
45-
if (Test-Path -Path $resolvedPath)
56+
process
4657
{
47-
if ((Get-Item $resolvedPath).PSIsContainer)
58+
if ($Path)
4859
{
49-
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $resolvedPath
60+
$resolvedPath = Resolve-PSFPath -Path $Path -Provider FileSystem -SingleItem
61+
if (Test-Path -Path $resolvedPath)
62+
{
63+
if ((Get-Item $resolvedPath).PSIsContainer)
64+
{
65+
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $resolvedPath
66+
if ($Register) { Register-PSFConfig -Module 'PSModuleDevelopment' -Name 'Module.Path' }
67+
return
68+
}
69+
}
70+
71+
Stop-PSFFunction -Target $Path -Message "Could not validate/resolve path: $Path" -EnableException $EnableException -Category InvalidArgument
5072
return
5173
}
74+
else
75+
{
76+
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $Module.ModuleBase
77+
if ($Register) { Register-PSFConfig -Module 'PSModuleDevelopment' -Name 'Module.Path' }
78+
}
5279
}
53-
54-
Stop-PSFFunction -Target $Path -Message "Could not validate/resolve path: $Path" -EnableException $EnableException -Category InvalidArgument
55-
return
5680
}

PSModuleDevelopment/internal/tabcompletion/assignment.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ Register-PSFTeppArgumentCompleter -Name PSMD_templatename -Command Invoke-PSMDTe
1919
Register-PSFTeppArgumentCompleter -Name PSMD_templatestore -Command Remove-PSMDTemplate -Parameter Store
2020
Register-PSFTeppArgumentCompleter -Name PSMD_templatename -Command Remove-PSMDTemplate -Parameter TemplateName
2121

22-
#endregion Templates
22+
#endregion Templates
23+
24+
#region Refactor
25+
Register-PSFTeppArgumentCompleter -Name psframework-encoding -Command Set-PSMDEncoding -Parameter Encoding
26+
#endregion Refactor

templates/CommandTest/þnameþ.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
$commonParameters = 'Verbose', 'Debug', 'ErrorAction', 'WarningAction', 'InformationAction', 'ErrorVariable', 'WarningVariable', 'InformationVariable', 'OutVariable', 'OutBuffer', 'PipelineVariable', 'Confirm', 'WhatIf'
1717
foreach ($parameter in ((Get-Command $Parameters.Name).Parameters.Values | Where-Object Name -NotIn $commonParameters))
1818
{
19-
$lines += " It 'Should habe the expected parameter $($parameter.Name)' {"
19+
$lines += " It 'Should have the expected parameter $($parameter.Name)' {"
2020
$lines += " `$parameter = (Get-Command $($Parameters.Name)).Parameters['$($parameter.Name)']"
2121
$lines += " `$parameter.Name | Should -Be '$($parameter.Name)'"
2222
$lines += " `$parameter.ParameterType.ToString() | Should -Be $($parameter.ParameterType.ToString())"

templates/PSFModule/þnameþ.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
ModuleToProcess = 'þnameþ.psm1'
44

55
# Version number of this module.
6-
ModuleVersion = '1.0.0.0'
6+
ModuleVersion = '1.0.0'
77

88
# ID used to uniquely identify this module
99
GUID = 'þ!guid!þ'

templates/PSFModule/þnameþ.psm1

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$script:ModuleRoot = $PSScriptRoot
2-
$script:ModuleVersion = "1.0.0.0"
2+
$script:ModuleVersion = (Import-PowerShellDataFile -Path "$($script:ModuleRoot)\þnameþ.psd1").ModuleVersion
33

44
# Detect whether at some level dotsourcing was enforced
55
$script:doDotSource = Get-PSFConfigValue -FullName þnameþ.Import.DoDotSource -Fallback $false
@@ -17,7 +17,7 @@ This is important when testing for paths.
1717
$importIndividualFiles = Get-PSFConfigValue -FullName þnameþ.Import.IndividualFiles -Fallback $false
1818
if ($þnameþ_importIndividualFiles) { $importIndividualFiles = $true }
1919
if (Test-Path (Resolve-PSFPath -Path "$($script:ModuleRoot)\..\.git" -SingleItem -NewChild)) { $importIndividualFiles = $true }
20-
if (-not (Test-Path (Resolve-PSFPath "$($script:ModuleRoot)\commands.ps1" -SingleItem -NewChild))) { $importIndividualFiles = $true }
20+
if ("<was not compiled>" -eq '<was not compiled>') { $importIndividualFiles = $true }
2121

2222
function Import-ModuleFile
2323
{
@@ -49,6 +49,7 @@ function Import-ModuleFile
4949
else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText((Resolve-Path $Path)))), $null, $null) }
5050
}
5151

52+
#region Load individual files
5253
if ($importIndividualFiles)
5354
{
5455
# Execute Preimport actions
@@ -68,18 +69,12 @@ if ($importIndividualFiles)
6869

6970
# Execute Postimport actions
7071
. Import-ModuleFile -Path "$ModuleRoot\internal\scripts\postimport.ps1"
71-
}
72-
else
73-
{
74-
if (Test-Path (Resolve-PSFPath "$($script:ModuleRoot)\resourcesBefore.ps1" -SingleItem -NewChild))
75-
{
76-
. Import-ModuleFile -Path "$($script:ModuleRoot)\resourcesBefore.ps1"
77-
}
78-
79-
. Import-ModuleFile -Path "$($script:ModuleRoot)\commands.ps1"
8072

81-
if (Test-Path (Resolve-PSFPath "$($script:ModuleRoot)\resourcesAfter.ps1" -SingleItem -NewChild))
82-
{
83-
. Import-ModuleFile -Path "$($script:ModuleRoot)\resourcesAfter.ps1"
84-
}
85-
}
73+
# End it here, do not load compiled code below
74+
return
75+
}
76+
#endregion Load individual files
77+
78+
#region Load compiled code
79+
"<compile code into here>"
80+
#endregion Load compiled code

templates/PSFProject/README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,32 @@
22

33
Insert a useful description for the þnameþ project here.
44

5-
Remember, it's the first thing a visitor will see.
5+
Remember, it's the first thing a visitor will see.
6+
7+
# Project Setup Instructions
8+
## Working with the layout
9+
10+
- Don't touch the psm1 file
11+
- Place functions you export in `functions/` (can have subfolders)
12+
- Place private/internal functions invisible to the user in `internal/functions` (can have subfolders)
13+
- Don't add code directly to the `postimport.ps1` or `preimport.ps1`.
14+
Those files are designed to import other files only.
15+
- When adding files you load during `preimport.ps1`, be sure to add corresponding entries to `filesBefore.txt`.
16+
The text files are used as reference when compiling the module during the build script.
17+
- When adding files you load during `postimport.ps1`, be sure to add corresponding entries to `filesAfter.txt`.
18+
The text files are used as reference when compiling the module during the build script.
19+
20+
## Setting up CI/CD
21+
22+
> To create a PR validation pipeline, set up tasks like this:
23+
24+
- Install Prerequisites (PowerShell Task; VSTS-Prerequisites.ps1)
25+
- Validate (PowerShell Task; VSTS-Validate.ps1)
26+
- Publish Test Results (Publish Test Results; NUnit format; Run no matter what)
27+
28+
> To create a build/publish pipeline, set up tasks like this:
29+
30+
- Install Prerequisites (PowerShell Task; VSTS-Prerequisites.ps1)
31+
- Validate (PowerShell Task; VSTS-Validate.ps1)
32+
- Build (PowerShell Task; VSTS-Build.ps1)
33+
- Publish Test Results (Publish Test Results; NUnit format; Run no matter what)

0 commit comments

Comments
 (0)