Skip to content

Commit 5fe1350

Browse files
authored
Merge pull request #9 from tinuwalther/develop
Release V1.0.5
2 parents 8c2732c + 5838f05 commit 5fe1350

File tree

5 files changed

+37
-24
lines changed

5 files changed

+37
-24
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Version | Description | Date | Author
44
-|-|-|-
5+
1.0.5 | Automatically rename Example-Function 'Get-PRESomeSettings.ps1' | 2019-10-19 | Martin Walther
6+
1.0.4 | Allows to set the module version each time the build.ps1 is started | 2019-10-16 | Josh Burkard
57
1.0.3 | Save prefix in json instead of variable | 2019-09-09 | Martin Walther
68
1.0.2 | Change return of functions to PsCustomObject | 2019-09-09 | Martin Walther
79
1.0.1 | Automate some manually steps | 2019-09-07 | Martin Walther

CI/Build-Module.ps1

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# Semantic Versioning: https://semver.org/
22

3+
if((Get-Module -Name Pester).Version -match '^3\.\d{1}\.\d{1}'){
4+
Remove-Module -Name Pester
5+
Import-Module -Name Pester -MinimumVersion 4.4.1
6+
}
7+
38
Write-Host "[BUILD] [START] Launching Build Process" -ForegroundColor Green
49

510
#region prepare folders
611
$Current = (Split-Path -Path $MyInvocation.MyCommand.Path)
712
$Root = ((Get-Item $Current).Parent).FullName
813
$TestsPath = Join-Path -Path $Root -ChildPath "Tests"
914
$CISourcePath = Join-Path -Path $Root -ChildPath "CI"
15+
$CodeSourcePath = Join-Path -Path $Root -ChildPath "Code"
1016
$TestsScript = Join-Path -Path $TestsPath -ChildPath "Functions.Tests.ps1"
1117
$TestsFailures = Join-Path -Path $TestsPath -ChildPath "Functions.Tests.json"
1218
$Settings = Join-Path -Path $CISourcePath -ChildPath "Module-Settings.json"
@@ -18,25 +24,33 @@ if(Test-Path -Path $Settings){
1824
$ModuleName = $ModuleSettings.ModuleName
1925
$ModuleDescription = $ModuleSettings.ModuleDescription
2026
$ModuleVersion = $ModuleSettings.ModuleVersion
27+
$prompt = Read-Host "Enter the Version number of this module in the Semantic Versioning notation [$( $ModuleVersion )]"
28+
if (!$prompt -eq "") { $ModuleVersion = $prompt }
2129
$ModuleAuthor = $ModuleSettings.ModuleAuthor
2230
$ModuleCompany = $ModuleSettings.ModuleCompany
2331
$ModulePrefix = $ModuleSettings.ModulePrefix
2432
}
2533
else{
2634
$ModuleName = Read-Host 'Enter the name of the module without the extension'
27-
$ModuleVersion = Read-Host 'Enter the Version number of this module in the Semantic Versioning notation'
35+
$ModuleVersion = Read-Host 'Enter the Version number of this module in the Semantic Versioning notation [1.0.0]'
2836
$ModuleDescription = Read-Host 'Enter the Description of the functionality provided by this module'
2937
$ModuleAuthor = Read-Host 'Enter the Author of this module'
3038
$ModuleCompany = Read-Host 'Enter the Company or vendor of this module'
3139
$ModulePrefix = Read-Host 'Enter the Prefix for all functions of this module'
32-
[PSCustomObject] @{
33-
ModuleName = $ModuleName
34-
ModuleVersion = $ModuleVersion
35-
ModuleDescription = $ModuleDescription
36-
ModuleAuthor = $ModuleAuthor
37-
ModuleCompany = $ModuleCompany
38-
ModulePrefix = $ModulePrefix
39-
} | ConvertTo-Json | Out-File -FilePath $Settings -Encoding utf8
40+
}
41+
[PSCustomObject] @{
42+
ModuleName = $ModuleName
43+
ModuleVersion = $ModuleVersion
44+
ModuleDescription = $ModuleDescription
45+
ModuleAuthor = $ModuleAuthor
46+
ModuleCompany = $ModuleCompany
47+
ModulePrefix = $ModulePrefix
48+
} | ConvertTo-Json | Out-File -FilePath $Settings -Encoding utf8
49+
50+
Get-ChildItem -Path $CodeSourcePath -Filter '*-*.ps1' | ForEach-Object {
51+
$newname = $($_.Name -replace '-PRE',"-$($ModulePrefix)")
52+
(Get-Content -Path $_.FullName) -replace '-PRE',"-$($ModulePrefix)" | Set-Content -Path $_.FullName
53+
Rename-Item -Path $_.FullName -NewName $newname -PassThru
4054
}
4155
#endregion
4256

@@ -52,7 +66,6 @@ $TestsResult = Invoke-Pester -Script $TestsScript -PassThru -Show None
5266
if($TestsResult.FailedCount -eq 0){
5367
$ModuleFolderPath = Join-Path -Path $Root -ChildPath $ModuleName
5468
#$ModuleFolderPath = $Root
55-
$CodeSourcePath = Join-Path -Path $Root -ChildPath "Code"
5669
if(-not(Test-Path -Path $ModuleFolderPath)){
5770
$null = New-Item -Path $ModuleFolderPath -ItemType Directory
5871
}
@@ -98,17 +111,12 @@ if($TestsResult.FailedCount -eq 0){
98111
Write-Host "[BUILD] [PSD1 ] Adding functions to export" -ForegroundColor Green
99112
$FunctionsToExport = $PublicFunctions.BaseName
100113
$Manifest = Join-Path -Path $ModuleFolderPath -ChildPath "$($ModuleName).psd1"
101-
Update-ModuleManifest -Path $Manifest -FunctionsToExport $FunctionsToExport
114+
Update-ModuleManifest -Path $Manifest -FunctionsToExport $FunctionsToExport -ModuleVersion $ModuleVersion
102115

103116
Write-Host "[BUILD] [END ] [PSD1] building Manifest" -ForegroundColor Green
104117
#endregion
105118

106119
#region General Module-Tests
107-
if((Get-Module -Name Pester).Version -match '^3\.\d{1}\.\d{1}'){
108-
Remove-Module -Name Pester
109-
Import-Module -Name Pester -MinimumVersion 4.4.1
110-
}
111-
112120
Describe 'General module control' -Tags 'FunctionalQuality' {
113121

114122
It "Import $ModuleName without errors" {
@@ -125,7 +133,7 @@ if($TestsResult.FailedCount -eq 0){
125133
$functionname = $_
126134
It "Get-Command -Module $ModuleName should include Function $($functionname)" {
127135
Get-Command -Module $ModuleName | ForEach-Object {
128-
{if($functionname -match $_.Name){$true}} | should -betrue
136+
{if($functionname -match $_.Name){$true}else{$false}} | should -betrue
129137
}
130138
}
131139
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
function Get-SCSSomeSettings{
2+
function Get-PRESomeSettings{
33

44
<#
55

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- [Build-Module.ps1](#build-moduleps1)
99
- [Module-Settings.json](#module-settingsjson)
1010
- [Code](#code)
11-
- [Get-SCSSomeSettings.ps1](#get-scssomesettingsps1)
11+
- [Get-PRESomeSettings.ps1](#get-presomesettingsps1)
1212
- [Module-Folder](#module-folder)
1313
- [Manifest-File](#manifest-file)
1414
- [Module-File](#module-file)
@@ -60,11 +60,11 @@ The settings-file will be created, if you build the module at the first time and
6060

6161
## Code
6262

63-
In this folder save all your functions as PS1-Files with the Name of the function you want to have in the Module. e.g. Get-SCSSomeSettings.ps1.
63+
In this folder save all your functions as PS1-Files with the Name of the function you want to have in the Module. e.g. Get-PRESomeSettings.ps1.
6464

65-
### Get-SCSSomeSettings.ps1
65+
### Get-PRESomeSettings.ps1
6666

67-
This is an example function-file, you can copy and rename this file for your own use. Before you build your module, please delete the Get-SCSSomeSettings.ps1.
67+
This is an example function-file, you can copy and rename this file for your own use. Before you build your module, please be sure that you renamed the function name within the file.
6868

6969
## Module-Folder
7070

Tests/Functions.Tests.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ Get-ChildItem -Path $CodeSourcePath -Filter "*.ps1" | ForEach-Object {
7777
}
7878

7979
$Declaration = ( ( @( $Ast.FindAll( { $true } , $true ) ) | Where-Object { $_.Name.Extent.Text -eq "$('$')$p" } ).Extent.Text -replace 'INT32', 'INT' )
80-
$VariableType = ( "\[$( $ScriptCommand.Parameters."$p".ParameterType.Name )\]" -replace 'INT32', 'INT' )
80+
#$VariableType = ( "\[$( $ScriptCommand.Parameters."$p".ParameterType.Name )\]" -replace 'INT32', 'INT' )
8181
$VariableTypeFull = "\[$( $ScriptCommand.Parameters."$p".ParameterType.FullName )\]"
82-
$VariableType = $ScriptCommand.Parameters."$p".ParameterType.Name -replace 'INT32', 'INT'
82+
$VariableType = $ScriptCommand.Parameters."$p".ParameterType.Name
83+
$VariableType = $VariableType -replace 'INT32', 'INT'
84+
$VariableType = $VariableType -replace 'String\[\]', 'String'
85+
$VariableType = $VariableType -replace 'SwitchParameter', 'Switch'
8386
It "$ScriptName type '[$( $ScriptCommand.Parameters."$p".ParameterType.Name )]' should be declared for parameter '$( $p )'" {
8487
( ( $Declaration -match $VariableType ) -or ( $Declaration -match $VariableTypeFull ) ) | Should -Be $true
8588
}

0 commit comments

Comments
 (0)