diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 478315f..3ae30e2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,13 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [2.16.0] +## [2.20.0] - Catesta template module changes - CI/CD Changes: - Adjusted all action bootstrap for module installs to include a `SkipPublisherCheck` when installing Pester module on Windows builds. (https://github.com/pester/Pester/issues/2389) - Pester bumped from `5.5.0` to `5.6.1` - InvokeBuild bumped from `5.11.1` to `5.11.3` + - **New template question**: Catesta now asks if PowerShell Classes will be used in the module project. If `Yes` is specified a Classes structure will be scaffold. - Sample pester tests for Pester v5 refactored to follow Pester 5 rules - Refactored `ExportedFunctions.Tests.ps1` for better efficiency in loops - Minor spelling correction in sample Pester tests diff --git a/docs/Catesta-Basics.md b/docs/Catesta-Basics.md index c7efb84..4346cb6 100644 --- a/docs/Catesta-Basics.md +++ b/docs/Catesta-Basics.md @@ -33,6 +33,9 @@ New-VaultProject -DestinationPath $outPutPath * **Enter a description for the module:** *Description of what your module does* * **Enter the version number of the module (0.0.1)**: *Starting version #* * **Enter your full name**: *Module author name* +* **Will you use classes in your module?** + * [N] No + * [Y] Yes * **Which CICD tool will you use to build and deploy your project?**: *Choose CI/CD tool for automated project build and deployment.* * [M] Module Only * [G] GitHub Actions diff --git a/docs/Catesta-ModuleSchema.md b/docs/Catesta-ModuleSchema.md index ec011c2..84432a0 100644 --- a/docs/Catesta-ModuleSchema.md +++ b/docs/Catesta-ModuleSchema.md @@ -31,6 +31,14 @@ name : FN type : user-fullname default : +name : psClasses +type : choice +choices: + value : No + help : Classes will not be used in this PowerShell module. + value : Yes + help : Classes will be used in this PowerShell module. + name : CICD type : choice choices: @@ -254,6 +262,7 @@ ModuleName = 'text' Description = 'text' Version = '0.0.1' FN = 'user full name' +psClasses = 'No' CICD = 'GITHUB' GitHubAOptions = 'windows','pwshcore','linux','macos' AWSOptions = 'ps','pwshcore','pwsh' diff --git a/docs/Catesta.md b/docs/Catesta.md index b38a8d7..fa08c6f 100644 --- a/docs/Catesta.md +++ b/docs/Catesta.md @@ -2,7 +2,7 @@ Module Name: Catesta Module Guid: 6796b193-9013-468a-b022-837749af2d06 Download Help Link: NA -Help Version: 2.16.0 +Help Version: 2.20.0 Locale: en-US --- diff --git a/src/Catesta.build.ps1 b/src/Catesta.build.ps1 index 6037110..4fe2670 100644 --- a/src/Catesta.build.ps1 +++ b/src/Catesta.build.ps1 @@ -472,6 +472,7 @@ Add-BuildTask AssetCopy -Before Build { Copy-Item -Path "$script:ModuleSourcePath\*" -Destination $script:ArtifactsPath -Exclude *.psd1, *.psm1 -Recurse -ErrorAction Stop Copy-Item -Path "$script:ModuleSourcePath\Resources\Module\src\PSScriptAnalyzerSettings.psd1" -Destination "$script:ArtifactsPath\Resources\Module\src\PSScriptAnalyzerSettings.psd1" -ErrorAction Stop Copy-Item -Path "$script:ModuleSourcePath\Resources\Module\src\Module\Module.psm1" -Destination "$script:ArtifactsPath\Resources\Module\src\Module\Module.psm1" -ErrorAction Stop + Copy-Item -Path "$script:ModuleSourcePath\Resources\Module\src\Module\Module_Classes.psm1" -Destination "$script:ArtifactsPath\Resources\Module\src\Module\Module_Classes.psm1" -ErrorAction Stop # Copy-Item -Path "$script:ModuleSourcePath\Resources\Vault\src\PSVault\PSVault.psd1" -Destination "$script:ArtifactsPath\Resources\Vault\src\PSVault\PSVault.psd1" -ErrorAction Stop Copy-Item -Path "$script:ModuleSourcePath\Resources\Vault\src\PSVault\PSVault.psm1" -Destination "$script:ArtifactsPath\Resources\Vault\src\PSVault\PSVault.psm1" -ErrorAction Stop Copy-Item -Path "$script:ModuleSourcePath\Resources\Vault\src\PSVault\PSVault.Extension\PSVault.Extension.psd1" -Destination "$script:ArtifactsPath\Resources\Vault\src\PSVault\PSVault.Extension\PSVault.Extension.psd1" -ErrorAction Stop diff --git a/src/Catesta/Catesta.psd1 b/src/Catesta/Catesta.psd1 index 1149875..e613add 100644 --- a/src/Catesta/Catesta.psd1 +++ b/src/Catesta/Catesta.psd1 @@ -12,7 +12,7 @@ RootModule = 'Catesta.psm1' # Version number of this module. - ModuleVersion = '2.16.0' + ModuleVersion = '2.20.0' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/src/Catesta/Resources/Module/plasterManifest.xml b/src/Catesta/Resources/Module/plasterManifest.xml index a27cb1e..ae96436 100644 --- a/src/Catesta/Resources/Module/plasterManifest.xml +++ b/src/Catesta/Resources/Module/plasterManifest.xml @@ -5,6 +5,7 @@ @@ -177,11 +182,13 @@ + + @@ -326,7 +333,8 @@ - + + diff --git a/src/Catesta/Resources/Module/src/Module/Classes/SampleClass.ps1 b/src/Catesta/Resources/Module/src/Module/Classes/SampleClass.ps1 new file mode 100644 index 0000000..2c9bf7f --- /dev/null +++ b/src/Catesta/Resources/Module/src/Module/Classes/SampleClass.ps1 @@ -0,0 +1,36 @@ +<# +.NOTES + This class demonstrates basic class structure and functionality in PowerShell. + + # Create an instance of the SampleClass + $person = [SampleClass]::new('John Doe', 30) + + # Call the Greet method + $message = $person.Greet() + Write-Output $message + + # Increment the age and output a birthday message + $person.HaveBirthday() + + # Access the properties + Write-Output "Name: $($person.Name)" + Write-Output "Age: $($person.Age)" +#> +class SampleClass { + [string]$Name + [int]$Age + + SampleClass([string]$Name, [int]$Age) { + $this.Name = $Name + $this.Age = $Age + } + + [string]Greet() { + return "Hello, my name is $($this.Name) and I am $($this.Age) years old." + } + + [string]HaveBirthday() { + $this.Age++ + return "Happy Birthday $($this.Name)! You are now $($this.Age) years old." + } +} diff --git a/src/Catesta/Resources/Module/src/Module/Module.psm1 b/src/Catesta/Resources/Module/src/Module/Module.psm1 index 81f168f..516572b 100644 --- a/src/Catesta/Resources/Module/src/Module/Module.psm1 +++ b/src/Catesta/Resources/Module/src/Module/Module.psm1 @@ -16,7 +16,7 @@ try { } catch { Write-Error $_ - throw "Unable to get get file information from Public & Private src." + throw 'Unable to get get file information from Public & Private src.' } # dot source all .ps1 file(s) found @@ -25,10 +25,9 @@ foreach ($file in @($public + $private)) { . $file.FullName } catch { - throw "Unable to dot source [$($file.FullName)]" - + throw ('Unable to dot source {0}' -f $file.FullName) } } # export all public functions -Export-ModuleMember -Function $public.Basename \ No newline at end of file +Export-ModuleMember -Function $public.Basename diff --git a/src/Catesta/Resources/Module/src/Module/Module_Classes.psm1 b/src/Catesta/Resources/Module/src/Module/Module_Classes.psm1 new file mode 100644 index 0000000..38d5ead --- /dev/null +++ b/src/Catesta/Resources/Module/src/Module/Module_Classes.psm1 @@ -0,0 +1,34 @@ +# this psm1 is for local testing and development use only + +# dot source the parent import for local development variables +. $PSScriptRoot\Imports.ps1 + +# discover all ps1 file(s) in Public and Private paths + +$itemSplat = @{ + Filter = '*.ps1' + Recurse = $true + ErrorAction = 'Stop' +} +try { + $public = @(Get-ChildItem -Path "$PSScriptRoot\Public" @itemSplat) + $private = @(Get-ChildItem -Path "$PSScriptRoot\Private" @itemSplat) + $classes = @(Get-ChildItem -Path "$PSScriptRoot\Classes" @itemSplat) +} +catch { + Write-Error $_ + throw 'Unable to get get file information from Public/Private/Classes src.' +} + +# dot source all .ps1 file(s) found +foreach ($file in @($public + $private + $classes)) { + try { + . $file.FullName + } + catch { + throw ('Unable to dot source {0}' -f $file.FullName) + } +} + +# export all public functions +Export-ModuleMember -Function $public.Basename diff --git a/src/Catesta/Resources/Vault/plasterManifest.xml b/src/Catesta/Resources/Vault/plasterManifest.xml index b52bf64..d42c627 100644 --- a/src/Catesta/Resources/Vault/plasterManifest.xml +++ b/src/Catesta/Resources/Vault/plasterManifest.xml @@ -6,7 +6,7 @@ Catesta d531e058-52b8-4dd2-8162-01c95d1eb8f7 - 2.16.0 + 2.20.0 Catesta Scaffolds a new PowerShell SecretManagement extension vault module project Jake Morrison diff --git a/src/Tests/Integration/FileChecks.Tests.ps1 b/src/Tests/Integration/FileChecks.Tests.ps1 index caa913e..5a10bce 100644 --- a/src/Tests/Integration/FileChecks.Tests.ps1 +++ b/src/Tests/Integration/FileChecks.Tests.ps1 @@ -75,6 +75,10 @@ Describe 'File Checks' { $srcFiles.Name.Contains('Get-Day.ps1') | Should -BeExactly $true } #it + It 'should have a class example' { + $srcFiles.Name.Contains('SampleClass.ps1') | Should -BeExactly $true + } #it + } #context_module Context 'Vault Source Files' { diff --git a/src/Tests/Integration/New-ModuleProject.Tests.ps1 b/src/Tests/Integration/New-ModuleProject.Tests.ps1 index 2cc1eb9..2b7d6f2 100644 --- a/src/Tests/Integration/New-ModuleProject.Tests.ps1 +++ b/src/Tests/Integration/New-ModuleProject.Tests.ps1 @@ -43,6 +43,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'Yes' CICD = 'NONE' RepoType = 'NONE' CodingStyle = 'Stroustrup' @@ -69,6 +70,7 @@ Describe 'Module Integration Tests' { $moduleOnlyFiles.Name.Contains('PSScriptAnalyzerSettings.psd1') | Should -BeExactly $true $moduleOnlyFiles.Name.Contains('Get-HelloWorld.ps1') | Should -BeExactly $true $moduleOnlyFiles.Name.Contains('Get-Day.ps1') | Should -BeExactly $true + $moduleOnlyFiles.Name.Contains('SampleClass.ps1') | Should -BeExactly $true # Tests $moduleOnlyFiles.Name.Contains('SampleIntegrationTest.Tests.ps1') | Should -BeExactly $true @@ -142,6 +144,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'NONE' CodingStyle = 'Stroustrup' @@ -167,6 +170,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'NONE' CodingStyle = 'Stroustrup' @@ -191,6 +195,7 @@ Describe 'Module Integration Tests' { $moduleOnlyFiles.Name.Contains('PSScriptAnalyzerSettings.psd1') | Should -BeExactly $true $moduleOnlyFiles.Name.Contains('Get-HelloWorld.ps1') | Should -BeExactly $true $moduleOnlyFiles.Name.Contains('Get-Day.ps1') | Should -BeExactly $true + $moduleOnlyFiles.Name.Contains('SampleClass.ps1') | Should -BeExactly $false # Tests $moduleOnlyFiles.Name.Contains('SampleIntegrationTest.Tests.ps1') | Should -BeExactly $true @@ -211,6 +216,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'GITHUB' @@ -273,6 +279,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'GITLAB' @@ -333,6 +340,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'BITBUCKET' @@ -392,6 +400,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'CodeCommit' @@ -444,6 +453,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'AZURE' @@ -481,6 +491,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps' RepoType = 'GITHUB' @@ -537,6 +548,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps' RepoType = 'CodeCommit' @@ -593,6 +605,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'AZURE' AzureOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'GITHUB' @@ -632,6 +645,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'AZURE' AzureOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'AZURE' @@ -671,6 +685,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'AZURE' AzureOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'BITBUCKET' @@ -714,6 +729,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'APPVEYOR' AppveyorOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'GITHUB' @@ -756,6 +772,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'GITHUB' GitHubAOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'GITHUB' @@ -810,6 +827,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'GHACODEBUILD' GitHubACBOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'GITHUB' @@ -876,6 +894,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'BITBUCKET' RepoType = 'BITBUCKET' ReadtheDocs = 'NONE' @@ -914,6 +933,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'GITLAB' GitLabOptions = 'windows', 'pwshcore', 'linux' RepoType = 'GITLAB' @@ -960,6 +980,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'CODECOMMIT' ReadtheDocs = 'NONE' @@ -1019,6 +1040,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'GITHUB' ReadtheDocs = 'NONE' @@ -1099,6 +1121,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'GITLAB' ReadtheDocs = 'NONE' @@ -1178,6 +1201,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'GITHUB' ReadtheDocs = 'READTHEDOCS' @@ -1223,6 +1247,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'GITHUB' ReadtheDocs = 'READTHEDOCS' @@ -1270,6 +1295,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'NONE' CodingStyle = 'Stroustrup' @@ -1290,6 +1316,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'GITHUB' GitHubAOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'GITHUB' @@ -1319,6 +1346,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'GITHUB' @@ -1347,6 +1375,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'AZURE' AzureOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'GITHUB' @@ -1374,6 +1403,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'APPVEYOR' AppveyorOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'GITHUB' @@ -1402,6 +1432,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'BITBUCKET' RepoType = 'BITBUCKET' ReadtheDocs = 'NONE' @@ -1429,6 +1460,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'GITLAB' RepoType = 'GITLAB' ReadtheDocs = 'READTHEDOCS'