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+
38Write-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}
2533else {
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
5266if ($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 }
0 commit comments