Skip to content

Commit

Permalink
fixes #89 - added prompt for classes
Browse files Browse the repository at this point in the history
  • Loading branch information
techthoughts2 committed Aug 8, 2024
1 parent 215e499 commit 75da12f
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 10 deletions.
3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/Catesta-Basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions docs/Catesta-ModuleSchema.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion docs/Catesta.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---

Expand Down
1 change: 1 addition & 0 deletions src/Catesta.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Catesta/Catesta.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'Catesta.psm1'

# Version number of this module.
ModuleVersion = '2.16.0'
ModuleVersion = '2.20.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
12 changes: 10 additions & 2 deletions src/Catesta/Resources/Module/plasterManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<!--
CodingStyle
FN -g
psClasses -g
Help -g
ModuleName -g
Options
Expand All @@ -18,7 +19,7 @@
<metadata>
<name>Catesta</name>
<id>258a61ba-566b-4c3a-8230-c2b6861a1a8d</id>
<version>2.16.0</version>
<version>2.20.0</version>
<title>Catesta</title>
<description>Scaffolds a new PowerShell module project</description>
<author>Jake Morrison</author>
Expand All @@ -34,6 +35,10 @@
<parameter name='Description' type='text' prompt='Enter a description for the module'/>
<parameter name='Version' type='text' prompt='Enter the version number of the module' default='0.0.1'/>
<parameter name='FN' type='user-fullname' store='text' prompt='Enter your full name'/>
<parameter name='psClasses' type='choice' default='0' store='text' prompt='Will you use classes in your module?'>
<choice label='&amp;No' help='Classes will not be used in this PowerShell module.' value='No'/>
<choice label='&amp;Yes' help='Classes will be used in this PowerShell module.' value='Yes'/>
</parameter>
<!-- CI/CD -->
<parameter name='CICD' type='choice' default='0' store='text' prompt='Which CICD tool will you use to build and deploy your project?'>
<choice label='&amp;Module Only' help='Does not add CI/CD process files. Module scaffolding only.' value='NONE'/>
Expand Down Expand Up @@ -177,11 +182,13 @@
<file source='' destination='src\${PLASTER_PARAM_ModuleName}'/>
<file source='' destination='src\${PLASTER_PARAM_ModuleName}\Public'/>
<file source='' destination='src\${PLASTER_PARAM_ModuleName}\Private'/>
<file condition="$PLASTER_PARAM_psClasses -eq 'Yes'" source='' destination='src\${PLASTER_PARAM_ModuleName}\Classes'/>

<!-- Module Files -->

<templateFile source='..\Module\src\Module\Private\Get-Day.ps1' destination='src\${PLASTER_PARAM_ModuleName}\Private\Get-Day.ps1' />
<templateFile source='..\Module\src\Module\Public\Get-HelloWorld.ps1' destination='src\${PLASTER_PARAM_ModuleName}\Public\Get-HelloWorld.ps1' />
<file condition="$PLASTER_PARAM_psClasses -eq 'Yes'" source='..\Module\src\Module\Classes\SampleClass.ps1' destination='src\${PLASTER_PARAM_ModuleName}\Classes\SampleClass.ps1' />

<templateFile source='..\Module\src\PSModule.build.ps1' destination='src\${PLASTER_PARAM_ModuleName}.build.ps1'/>
<file source='..\Module\src\PSModule.Settings.ps1' destination='src\${PLASTER_PARAM_ModuleName}.Settings.ps1'/>
Expand Down Expand Up @@ -326,7 +333,8 @@
<!-- Manifest -->
<newModuleManifest destination='src\${PLASTER_PARAM_ModuleName}\${PLASTER_PARAM_ModuleName}.psd1' moduleVersion='$PLASTER_PARAM_Version' rootModule='${PLASTER_PARAM_ModuleName}.psm1' encoding='UTF8-NoBOM' openInEditor="true" author='$PLASTER_PARAM_FN' description='$PLASTER_PARAM_description'/>
<file source='..\Module\src\Module\Imports.ps1' destination='src\${PLASTER_PARAM_ModuleName}\Imports.ps1'/>
<file source='..\Module\src\Module\Module.psm1' destination='src\${PLASTER_PARAM_ModuleName}\${PLASTER_PARAM_ModuleName}.psm1' openInEditor="true"/>
<file condition="$PLASTER_PARAM_psClasses -eq 'No'" source='..\Module\src\Module\Module.psm1' destination='src\${PLASTER_PARAM_ModuleName}\${PLASTER_PARAM_ModuleName}.psm1' openInEditor="true"/>
<file condition="$PLASTER_PARAM_psClasses -eq 'Yes'" source='..\Module\src\Module\Module_Classes.psm1' destination='src\${PLASTER_PARAM_ModuleName}\${PLASTER_PARAM_ModuleName}.psm1' openInEditor="true"/>

<!-- Required modules -->
<requireModule condition="$PLASTER_PARAM_Pester -eq '4'" name='Pester' minimumVersion='4.7.2' message='Without Pester, you will not be able to run the provided Pester test to validate your module manifest file.`nWithout version 4.5.0, VS Code will not display Pester warnings and errors in the Problems panel.'/>
Expand Down
36 changes: 36 additions & 0 deletions src/Catesta/Resources/Module/src/Module/Classes/SampleClass.ps1
Original file line number Diff line number Diff line change
@@ -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."
}
}
7 changes: 3 additions & 4 deletions src/Catesta/Resources/Module/src/Module/Module.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Export-ModuleMember -Function $public.Basename
34 changes: 34 additions & 0 deletions src/Catesta/Resources/Module/src/Module/Module_Classes.psm1
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/Catesta/Resources/Vault/plasterManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<metadata>
<name>Catesta</name>
<id>d531e058-52b8-4dd2-8162-01c95d1eb8f7</id>
<version>2.16.0</version>
<version>2.20.0</version>
<title>Catesta</title>
<description>Scaffolds a new PowerShell SecretManagement extension vault module project</description>
<author>Jake Morrison</author>
Expand Down
4 changes: 4 additions & 0 deletions src/Tests/Integration/FileChecks.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down
Loading

0 comments on commit 75da12f

Please sign in to comment.