Skip to content

Commit

Permalink
Merge pull request #60 from SamErde/prerelease
Browse files Browse the repository at this point in the history
Merge prerelease to main for publishing
  • Loading branch information
SamErde authored Jan 31, 2025
2 parents 36669b6 + 487f23c commit 0b0abf9
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 64 deletions.
2 changes: 1 addition & 1 deletion docs/PSPreworkout.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module Name: PSPreworkout
Module Guid: 378339de-a0df-4d44-873b-4fd32c388e06
Download Help Link: NA
Help Version: 1.6.1
Help Version: 1.7.0
Locale: en-US
---

Expand Down
6 changes: 4 additions & 2 deletions src/Artifacts/PSPreworkout.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RootModule = 'PSPreworkout.psm1'

# Version number of this module.
ModuleVersion = '1.6.1'
ModuleVersion = '1.7.0'

# Supported PSEditions = @('Desktop', 'Core')
CompatiblePSEditions = @('Core', 'Desktop')
Expand Down Expand Up @@ -82,7 +82,9 @@
)

# List of all files packaged with this module
FileList = @()
FileList = @(
'ScriptTemplate.txt'
)

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{
Expand Down
91 changes: 80 additions & 11 deletions src/Artifacts/PSPreworkout.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -949,26 +949,95 @@ function New-ScriptFromTemplate {
.EXTERNALHELP PSPreworkout-help.xml
#>

[CmdletBinding()]
__ALIAS__
[CmdletBinding(HelpUri = 'https://day3bits.com/PSPreworkout/New-ScriptFromTemplate')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'OK')]
#[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Making it pretty.')]
[Alias('New-Script')]
param (
# The name of the new function.
[Parameter(Mandatory, ParameterSetName = 'Named', Position = 0)]
[ValidateNotNullOrEmpty()]
[string]
$Name,

)
# The verb to use for the function name.
[Parameter(Mandatory, ParameterSetName = 'VerbNoun', Position = 0)]
[ValidateNotNullOrEmpty()]
[string]
$Verb,

begin {
# The noun to use for the function name.
[Parameter(Mandatory, ParameterSetName = 'VerbNoun', Position = 1)]
[ValidateNotNullOrEmpty()]
[string]
$Noun,

} # end begin block
# Synopsis of the new function.
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]
$Synopsis,

process {
# Description of the new function.
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]
$Description,

} # end process block
# Optional alias for the new function.
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]
$Alias,

end {
# Name of the author of the script
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]
$Author = (Get-CimInstance -ClassName Win32_UserAccount -Filter "Name = `'$([System.Security.Principal.WindowsIdentity]::GetCurrent().Name.Split('\')[1])`'").FullName,

} # end end block
# Parameter name(s) to include
#[Parameter()]
#[ValidateNotNullOrEmpty()]
#[string[]]
#$Parameter,

} # end function New-Function
'@
# Path of the directory to save the new function in.
[Parameter()]
[ValidateScript({ Test-Path -Path $_ -PathType Container })]
[string]
$Path,

# Optionally skip name validation checks.
[Parameter()]
[switch]
$SkipValidation
)

if ($PSBoundParameters.ContainsKey('Verb') -and -not $SkipValidation -and $Verb -notin (Get-Verb).Verb) {
Write-Warning "`"$Verb`" is not an approved verb. Please run `"Get-Verb`" to see a list of approved verbs."
break
}

if ($PSBoundParameters.ContainsKey('Verb') -and $PSBoundParameters.ContainsKey('Noun')) {
$Name = "$Verb-$Noun"
}

if ($PSBoundParameters.ContainsKey('Name') -and -not $SkipValidation -and
$Name -match '\w-\w' -and $Name.Split('-')[0] -notin (Get-Verb).Verb ) {
Write-Warning "It looks like you are not using an approved verb: `"$($Name.Split('-')[0]).`" Please run `"Get-Verb`" to see a list of approved verbs."
}

# Set the script path and filename. Use current directory if no path specified.
if (Test-Path -Path $Path -PathType Container) {
$ScriptPath = [System.IO.Path]::Combine($Path, "$Name.ps1")
} else {
$ScriptPath = ".\$Name.ps1"
}

# Create the function builder string builder and function body string.
$FunctionBuilder = [System.Text.StringBuilder]::New()
$FunctionBody = (Get-Content -Path "$PSScriptRoot\ScriptTemplate.txt" -Raw)

# Replace template placeholders with strings from parameter inputs.
$FunctionBody = $FunctionBody -Replace 'New-Function', $Name
Expand Down
6 changes: 4 additions & 2 deletions src/PSPreworkout/PSPreworkout.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RootModule = 'PSPreworkout.psm1'

# Version number of this module.
ModuleVersion = '1.6.1'
ModuleVersion = '1.7.0'

# Supported PSEditions = @('Desktop', 'Core')
CompatiblePSEditions = @('Core', 'Desktop')
Expand Down Expand Up @@ -82,7 +82,9 @@
)

# List of all files packaged with this module
FileList = @()
FileList = @(
'ScriptTemplate.txt'
)

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{
Expand Down
55 changes: 9 additions & 46 deletions src/PSPreworkout/Public/New-ScriptFromTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,49 +44,49 @@ function New-ScriptFromTemplate {
param (
# The name of the new function.
[Parameter(Mandatory, ParameterSetName = 'Named', Position = 0)]
[ValidateNotNullorEmpty()]
[ValidateNotNullOrEmpty()]
[string]
$Name,

# The verb to use for the function name.
[Parameter(Mandatory, ParameterSetName = 'VerbNoun', Position = 0)]
[ValidateNotNullorEmpty()]
[ValidateNotNullOrEmpty()]
[string]
$Verb,

# The noun to use for the function name.
[Parameter(Mandatory, ParameterSetName = 'VerbNoun', Position = 1)]
[ValidateNotNullorEmpty()]
[ValidateNotNullOrEmpty()]
[string]
$Noun,

# Synopsis of the new function.
[Parameter()]
[ValidateNotNullorEmpty()]
[ValidateNotNullOrEmpty()]
[string]
$Synopsis,

# Description of the new function.
[Parameter()]
[ValidateNotNullorEmpty()]
[ValidateNotNullOrEmpty()]
[string]
$Description,

# Optional alias for the new function.
[Parameter()]
[ValidateNotNullorEmpty()]
[ValidateNotNullOrEmpty()]
[string]
$Alias,

# Name of the author of the script
[Parameter()]
[ValidateNotNullorEmpty()]
[ValidateNotNullOrEmpty()]
[string]
$Author = (Get-CimInstance -ClassName Win32_UserAccount -Filter "Name = `'$([System.Security.Principal.WindowsIdentity]::GetCurrent().Name.Split('\')[1])`'").FullName,

# Parameter name(s) to include
#[Parameter()]
#[ValidateNotNullorEmpty()]
#[ValidateNotNullOrEmpty()]
#[string[]]
#$Parameter,

Expand Down Expand Up @@ -125,44 +125,7 @@ function New-ScriptFromTemplate {

# Create the function builder string builder and function body string.
$FunctionBuilder = [System.Text.StringBuilder]::New()
$FunctionBody = @'
function New-Function {
<#
.SYNOPSIS
__SYNOPSIS__
.DESCRIPTION
__DESCRIPTION__
.EXAMPLE
__EXAMPLE__
.NOTES
Author: __AUTHOR__
Version: 0.0.1
Modified: __DATE__
#>
[CmdletBinding()]
__ALIAS__
param (
)
begin {
} # end begin block
process {
} # end process block
end {
} # end end block
} # end function New-Function
'@
$FunctionBody = (Get-Content -Path "$PSScriptRoot\ScriptTemplate.txt" -Raw)

# Replace template placeholders with strings from parameter inputs.
$FunctionBody = $FunctionBody -Replace 'New-Function', $Name
Expand Down
36 changes: 36 additions & 0 deletions src/PSPreworkout/ScriptTemplate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function New-Function {
<#
.SYNOPSIS
__SYNOPSIS__

.DESCRIPTION
__DESCRIPTION__

.EXAMPLE
__EXAMPLE__

.NOTES
Author: __AUTHOR__
Version: 0.0.1
Modified: __DATE__
#>

[CmdletBinding()]
__ALIAS__
param (

)

begin {

} # end begin block

process {

} # end process block

end {

} # end end block

} # end function New-Function
2 changes: 0 additions & 2 deletions src/Tests/Integration/SampleIntegrationTest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ BeforeAll {
Import-Module $PathToManifest -Force
}

<# RE-ENABLE AFTER REFACTORING 'NEW-SCRIPTFROMTEMPLATE'
Describe 'Integration Tests' -Tag Integration {
Context 'First Integration Tests' {
It 'should pass the first integration test' {
Expand All @@ -17,4 +16,3 @@ Describe 'Integration Tests' -Tag Integration {
}

Remove-Module $ModuleName -Force
#>

0 comments on commit 0b0abf9

Please sign in to comment.