Skip to content

Commit 5e868e1

Browse files
author
Friedrich Weinmann
committed
PSFProject next
1 parent aa0e1e6 commit 5e868e1

19 files changed

+257
-280
lines changed

PSModuleDevelopment/changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
# Changelog
2+
## 2.2.7.91 (May 30th, 2020)
3+
4+
- Upd: Template PSFTest - Pester v5 compatibility
5+
- Upd: Template PSFModule - Pester v5 compatibility
6+
- Upd: Template PSFProject - Pester v5 compatibility
7+
- Upd: Template PSFProject - Simplified module import workflow
8+
- Upd: Template PSFProject - Improved build process cross-agent convenience
9+
- Upd: Template PSFProject - Prerequisites task automatically detects module dependencies
10+
- Upd: Template PSFProject - Prerequisites task can be configured to work with any registered repository
11+
- Upd: Export-PSMDString - Now also detects splatted localization strings (thanks @StevePlp ; #117)
12+
213
## 2.2.7.90 (September 1st, 2019)
314
- New: Export-PSMDString - Parses strings from modules using the PSFramework localization feature.
415
- Upd: Measure-PSMDCommand - Renamed from Measure-PSMDCommandEx, performance upgrades, adding option for comparing multiple test sets.

templates/PSFModule/PSMDTemplate.ps1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
TemplateName = 'PSFModule'
3-
Version = "1.1.1.0"
3+
Version = "1.1.2.0"
44
AutoIncrementVersion = $true
55
Tags = 'module','psframework'
66
Author = 'Friedrich Weinmann'
@@ -22,10 +22,8 @@
2222
testfolder = {
2323

2424
}
25-
testresults = {
26-
@'
27-
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
28-
'@
25+
pesterconfig = {
26+
2927
}
3028
}
3129
}
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
# Add all things you want to run after importing the main code
1+
<#
2+
Add all things you want to run after importing the main function code
3+
4+
WARNING: ONLY provide paths to files!
5+
6+
After building the module, this file will be completely ignored, adding anything but paths to files ...
7+
- Will not work after publishing
8+
- Could break the build process
9+
#>
10+
11+
$moduleRoot = Split-Path (Split-Path $PSScriptRoot)
212

313
# Load Configurations
4-
foreach ($file in (Get-ChildItem "$($script:ModuleRoot)\internal\configurations\*.ps1" -ErrorAction Ignore)) {
5-
. Import-ModuleFile -Path $file.FullName
6-
}
14+
(Get-ChildItem "$moduleRoot\internal\configurations\*.ps1" -ErrorAction Ignore).FullName
715

816
# Load Scriptblocks
9-
foreach ($file in (Get-ChildItem "$($script:ModuleRoot)\internal\scriptblocks\*.ps1" -ErrorAction Ignore)) {
10-
. Import-ModuleFile -Path $file.FullName
11-
}
17+
(Get-ChildItem "$moduleRoot\internal\scriptblocks\*.ps1" -ErrorAction Ignore).FullName
1218

1319
# Load Tab Expansion
14-
foreach ($file in (Get-ChildItem "$($script:ModuleRoot)\internal\tepp\*.tepp.ps1" -ErrorAction Ignore)) {
15-
. Import-ModuleFile -Path $file.FullName
16-
}
20+
(Get-ChildItem "$moduleRoot\internal\tepp\*.tepp.ps1" -ErrorAction Ignore).FullName
1721

1822
# Load Tab Expansion Assignment
19-
. Import-ModuleFile -Path "$($script:ModuleRoot)\internal\tepp\assignment.ps1"
23+
"$moduleRoot\internal\tepp\assignment.ps1"
2024

2125
# Load License
22-
. Import-ModuleFile -Path "$($script:ModuleRoot)\internal\scripts\license.ps1"
26+
"$moduleRoot\internal\scripts\license.ps1"
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
# Add all things you want to run before importing the main code
1+
<#
2+
Add all things you want to run before importing the main function code.
3+
4+
WARNING: ONLY provide paths to files!
5+
6+
After building the module, this file will be completely ignored, adding anything but paths to files ...
7+
- Will not work after publishing
8+
- Could break the build process
9+
#>
10+
11+
$moduleRoot = Split-Path (Split-Path $PSScriptRoot)
212

313
# Load the strings used in messages
4-
. Import-ModuleFile -Path "$($script:ModuleRoot)\internal\scripts\strings.ps1"
14+
"$moduleRoot\internal\scripts\strings.ps1"

templates/PSFModule/þnameþ.psm1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ function Import-ModuleFile
5454
if ($importIndividualFiles)
5555
{
5656
# Execute Preimport actions
57-
. Import-ModuleFile -Path "$ModuleRoot\internal\scripts\preimport.ps1"
57+
foreach ($path in (& "$ModuleRoot\internal\scripts\preimport.ps1")) {
58+
. Import-ModuleFile -Path $path
59+
}
5860

5961
# Import all internal functions
6062
foreach ($function in (Get-ChildItem "$ModuleRoot\internal\functions" -Filter "*.ps1" -Recurse -ErrorAction Ignore))
@@ -69,7 +71,9 @@ if ($importIndividualFiles)
6971
}
7072

7173
# Execute Postimport actions
72-
. Import-ModuleFile -Path "$ModuleRoot\internal\scripts\postimport.ps1"
74+
foreach ($path in (& "$ModuleRoot\internal\scripts\postimport.ps1")) {
75+
. Import-ModuleFile -Path $path
76+
}
7377

7478
# End it here, do not load compiled code below
7579
return

templates/PSFProject/PSMDTemplate.ps1

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
TemplateName = 'PSFProject'
3-
Version = "1.3.1.0"
3+
Version = "1.3.2.0"
44
AutoIncrementVersion = $true
55
Tags = 'module','psframework'
66
Author = 'Friedrich Weinmann'
@@ -34,11 +34,8 @@ Write-PSFMessage -Level Important -Message "Creating test result folder"
3434
$null = New-Item -Path "$PSScriptRoot\..\.." -Name TestResults -ItemType Directory -Force
3535
'@
3636
}
37-
testresults = {
38-
@'
39-
$TestOuputFile = Join-Path "$PSScriptRoot\..\..\TestResults" "TEST-$($file.BaseName).xml"
40-
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru -OutputFile $TestOuputFile -OutputFormat NUnitXml
41-
'@
37+
pesterconfig = {
38+
'[PesterConfiguration]::Default.TestResult.Enabled = $true'
4239
}
4340
}
4441
}

templates/PSFProject/README.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,25 @@ Remember, it's the first thing a visitor will see.
77
# Project Setup Instructions
88
## Working with the layout
99

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.
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 & folders, make sure they are covered by either `postimport.ps1` or `preimport.ps1`.
16+
This adds them to both the import and the build sequence.
1917

2018
## Setting up CI/CD
2119

2220
> To create a PR validation pipeline, set up tasks like this:
2321
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)
22+
- Install Prerequisites (PowerShell Task; VSTS-Prerequisites.ps1)
23+
- Validate (PowerShell Task; VSTS-Validate.ps1)
24+
- Publish Test Results (Publish Test Results; NUnit format; Run no matter what)
2725

2826
> To create a build/publish pipeline, set up tasks like this:
2927
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)
28+
- Install Prerequisites (PowerShell Task; VSTS-Prerequisites.ps1)
29+
- Validate (PowerShell Task; VSTS-Validate.ps1)
30+
- Build (PowerShell Task; VSTS-Build.ps1)
31+
- Publish Test Results (Publish Test Results; NUnit format; Run no matter what)

templates/PSFProject/build/filesAfter.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

templates/PSFProject/build/filesBefore.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

templates/PSFProject/build/vsts-build.ps1

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ if (-not $WorkingDirectory)
3030
}
3131
else { $WorkingDirectory = $env:SYSTEM_DEFAULTWORKINGDIRECTORY }
3232
}
33+
if (-not $WorkingDirectory) { $WorkingDirectory = Split-Path $PSScriptRoot }
3334
#endregion Handle Working Directory Defaults
3435

3536
# Prepare publish folder
@@ -42,19 +43,15 @@ $text = @()
4243
$processed = @()
4344

4445
# Gather Stuff to run before
45-
foreach ($line in (Get-Content "$($PSScriptRoot)\filesBefore.txt" | Where-Object { $_ -notlike "#*" }))
46+
foreach ($filePath in (& "$($PSScriptRoot)\..\þnameþ\internal\scripts\preimport.ps1"))
4647
{
47-
if ([string]::IsNullOrWhiteSpace($line)) { continue }
48+
if ([string]::IsNullOrWhiteSpace($filePath)) { continue }
4849

49-
$basePath = Join-Path "$($publishDir.FullName)\þnameþ" $line
50-
foreach ($entry in (Resolve-PSFPath -Path $basePath))
51-
{
52-
$item = Get-Item $entry
53-
if ($item.PSIsContainer) { continue }
54-
if ($item.FullName -in $processed) { continue }
55-
$text += [System.IO.File]::ReadAllText($item.FullName)
56-
$processed += $item.FullName
57-
}
50+
$item = Get-Item $filePath
51+
if ($item.PSIsContainer) { continue }
52+
if ($item.FullName -in $processed) { continue }
53+
$text += [System.IO.File]::ReadAllText($item.FullName)
54+
$processed += $item.FullName
5855
}
5956

6057
# Gather commands
@@ -66,19 +63,15 @@ Get-ChildItem -Path "$($publishDir.FullName)\þnameþ\functions\" -Recurse -File
6663
}
6764

6865
# Gather stuff to run afterwards
69-
foreach ($line in (Get-Content "$($PSScriptRoot)\filesAfter.txt" | Where-Object { $_ -notlike "#*" }))
66+
foreach ($filePath in (& "$($PSScriptRoot)\..\þnameþ\internal\scripts\postimport.ps1"))
7067
{
71-
if ([string]::IsNullOrWhiteSpace($line)) { continue }
68+
if ([string]::IsNullOrWhiteSpace($filePath)) { continue }
7269

73-
$basePath = Join-Path "$($publishDir.FullName)\þnameþ" $line
74-
foreach ($entry in (Resolve-PSFPath -Path $basePath))
75-
{
76-
$item = Get-Item $entry
77-
if ($item.PSIsContainer) { continue }
78-
if ($item.FullName -in $processed) { continue }
79-
$text += [System.IO.File]::ReadAllText($item.FullName)
80-
$processed += $item.FullName
81-
}
70+
$item = Get-Item $filePath
71+
if ($item.PSIsContainer) { continue }
72+
if ($item.FullName -in $processed) { continue }
73+
$text += [System.IO.File]::ReadAllText($item.FullName)
74+
$processed += $item.FullName
8275
}
8376
#endregion Gather text data to compile
8477

0 commit comments

Comments
 (0)