Skip to content

Commit

Permalink
Merge pull request #3 from techthoughts2/Enhancements
Browse files Browse the repository at this point in the history
Enhancements
  • Loading branch information
techthoughts2 authored Dec 8, 2024
2 parents 724a682 + 463e4be commit e81ffb0
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 11 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
],
"cSpell.words": [
"jakemorrison",
"Pscx",
"shortcode"
]
}
Expand Down
3 changes: 1 addition & 2 deletions docs/Add-EmojiToText.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, -WarningVariable, and -ProgressAction.
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
Expand All @@ -110,4 +110,3 @@ This function uses the Public data set from the Unicode Data Files and adheres t
[https://pwshEmojiExplorer.readthedocs.io/en/latest/Add-EmojiToText/](https://pwshEmojiExplorer.readthedocs.io/en/latest/Add-EmojiToText/)
[https://www.unicode.org/license.txt](https://www.unicode.org/license.txt)
7 changes: 7 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ 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.2.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.4]

- Module Changes
- Addressed bug where `Expand-XMLDataSet` can fail if user has `Expand-Archive` from `Pscx` module, not from `Microsoft.PowerShell.Archive`
- Build Updates
- Added `MarkdownRepair.ps1` and added Markdown repair logic to InvokeBuild script. This is to account for an issue in PowerShell `7.4.0`+ where a new parameter was introduced that platyPS can not handle during help creation. Ref: [platyPS issue]([text](https://github.com/PowerShell/platyPS/issues/595)).

## [0.8.2]

- Module Changes
Expand Down
3 changes: 1 addition & 2 deletions docs/Get-AllEmoji.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, -WarningVariable, and -ProgressAction.
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
Expand All @@ -80,4 +80,3 @@ This function uses the Public data set from the Unicode Data Files and adheres t
[https://pwshEmojiExplorer.readthedocs.io/en/latest/Get-AllEmoji/](https://pwshEmojiExplorer.readthedocs.io/en/latest/Get-AllEmoji/)
[https://www.unicode.org/license.txt](https://www.unicode.org/license.txt)
3 changes: 1 addition & 2 deletions docs/Get-Emoji.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, -WarningVariable, and -ProgressAction.
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
Expand All @@ -301,4 +301,3 @@ This function uses the Public data set from the Unicode Data Files and adheres t
[https://pwshEmojiExplorer.readthedocs.io/en/latest/Get-Emoji/](https://pwshEmojiExplorer.readthedocs.io/en/latest/Get-Emoji/)
[https://www.unicode.org/license.txt](https://www.unicode.org/license.txt)
2 changes: 1 addition & 1 deletion docs/pwshEmojiExplorer.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module Name: pwshEmojiExplorer
Module Guid: 6e4813c7-6f30-42e8-adc4-b3d9b46bce9a
Download Help Link: NA
Help Version: 0.8.2
Help Version: 0.8.4
Locale: en-US
---

Expand Down
135 changes: 135 additions & 0 deletions src/MarkdownRepair.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<#
.SYNOPSIS
Repair PlatyPS generated markdown files.
.NOTES
This file is temporarily required to handle platyPS help generation.
https://github.com/PowerShell/platyPS/issues/595
This is a result of a breaking change introduced in PowerShell 7.4.0:
https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-74?view=powershell-7.4
Breaking Changes: Added the ProgressAction parameter to the Common Parameters
modified from source: https://github.com/PowerShell/platyPS/issues/595#issuecomment-1820971702
#>

function Remove-CommonParameterFromMarkdown {
<#
.SYNOPSIS
Remove a PlatyPS generated parameter block.
.DESCRIPTION
Removes parameter block for the provided parameter name from the markdown file provided.
#>
param(
[Parameter(Mandatory)]
[string[]]
$Path,

[Parameter(Mandatory = $false)]
[string[]]
$ParameterName = @('ProgressAction')
)
$ErrorActionPreference = 'Stop'
foreach ($p in $Path) {
$content = (Get-Content -Path $p -Raw).TrimEnd()
$updateFile = $false
foreach ($param in $ParameterName) {
if (-not ($Param.StartsWith('-'))) {
$param = "-$($param)"
}
# Remove the parameter block
$pattern = "(?m)^### $param\r?\n[\S\s]*?(?=#{2,3}?)"
$newContent = $content -replace $pattern, ''
# Remove the parameter from the syntax block
$pattern = " \[$param\s?.*?]"
$newContent = $newContent -replace $pattern, ''
if ($null -ne (Compare-Object -ReferenceObject $content -DifferenceObject $newContent)) {
Write-Verbose "Added $param to $p"
# Update file content
$content = $newContent
$updateFile = $true
}
}
# Save file if content has changed
if ($updateFile) {
$newContent | Out-File -Encoding utf8 -FilePath $p
Write-Verbose "Updated file: $p"
}
}
return
}

function Add-MissingCommonParameterToMarkdown {
param(
[Parameter(Mandatory)]
[string[]]
$Path,

[Parameter(Mandatory = $false)]
[string[]]
$ParameterName = @('ProgressAction')
)
$ErrorActionPreference = 'Stop'
foreach ($p in $Path) {
$content = (Get-Content -Path $p -Raw).TrimEnd()
$updateFile = $false
foreach ($NewParameter in $ParameterName) {
if (-not ($NewParameter.StartsWith('-'))) {
$NewParameter = "-$($NewParameter)"
}
$pattern = '(?m)^This cmdlet supports the common parameters:(.+?)\.'
$replacement = {
$Params = $_.Groups[1].Captures[0].ToString() -split ' '
$CommonParameters = @()
foreach ($CommonParameter in $Params) {
if ($CommonParameter.StartsWith('-')) {
if ($CommonParameter.EndsWith(',')) {
$CleanParam = $CommonParameter.Substring(0, $CommonParameter.Length - 1)
}
elseif ($p.EndsWith('.')) {
$CleanParam = $CommonParameter.Substring(0, $CommonParameter.Length - 1)
}
else {
$CleanParam = $CommonParameter
}
$CommonParameters += $CleanParam
}
}
if ($NewParameter -notin $CommonParameters) {
$CommonParameters += $NewParameter
}
$CommonParameters[-1] = "and $($CommonParameters[-1]). "
return "This cmdlet supports the common parameters: " + (($CommonParameters | Sort-Object) -join ', ')
}
$newContent = $content -replace $pattern, $replacement
if ($null -ne (Compare-Object -ReferenceObject $content -DifferenceObject $newContent)) {
Write-Verbose "Added $NewParameter to $p"
$updateFile = $true
$content = $newContent
}
}
# Save file if content has changed
if ($updateFile) {
$newContent | Out-File -Encoding utf8 -FilePath $p
Write-Verbose "Updated file: $p"
}
}
return
}

function Repair-PlatyPSMarkdown {
param(
[Parameter(Mandatory)]
[string[]]
$Path,

[Parameter()]
[string[]]
$ParameterName = @('ProgressAction')
)
$ErrorActionPreference = 'Stop'
$Parameters = @{
Path = $Path
ParameterName = $ParameterName
}
$null = Remove-CommonParameterFromMarkdown @Parameters
$null = Add-MissingCommonParameterToMarkdown @Parameters
return
}
15 changes: 13 additions & 2 deletions src/pwshEmojiExplorer.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#>

#Include: Settings
$ModuleName = (Split-Path -Path $BuildFile -Leaf).Split('.')[0]
$ModuleName = [regex]::Match((Get-Item $BuildFile).Name, '^(.*)\.build\.ps1$').Groups[1].Value
. "./$ModuleName.Settings.ps1"

function Test-ManifestBool ($Path) {
Expand Down Expand Up @@ -67,7 +67,7 @@ Add-BuildTask BuildNoIntegration -Jobs $str2

# Pre-build variables to be used by other portions of the script
Enter-Build {
$script:ModuleName = (Split-Path -Path $BuildFile -Leaf).Split('.')[0]
$script:ModuleName = [regex]::Match((Get-Item $BuildFile).Name, '^(.*)\.build\.ps1$').Groups[1].Value

# Identify other required paths
$script:ModuleSourcePath = Join-Path -Path $BuildRoot -ChildPath $script:ModuleName
Expand Down Expand Up @@ -384,6 +384,17 @@ Add-BuildTask CreateMarkdownHelp -After CreateHelpStart {
throw 'Missing GUID. Please review and rebuild.'
}

Write-Build Gray ' Evaluating if running 7.4.0 or higher...'
# https://github.com/PowerShell/platyPS/issues/595
if ($PSVersionTable.PSVersion -ge [version]'7.4.0') {
Write-Build Gray ' Performing Markdown repair'
# dot source markdown repair
. $BuildRoot\MarkdownRepair.ps1
$OutputDir | Get-ChildItem -File | ForEach-Object {
Repair-PlatyPSMarkdown -Path $_.FullName
}
}

Write-Build Gray ' Checking for missing documentation in md files...'
$MissingDocumentation = Select-String -Path "$script:ArtifactsPath\docs\*.md" -Pattern "({{.*}})"
if ($MissingDocumentation.Count -gt 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/pwshEmojiExplorer/Private/Expand-XMLDataSet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function Expand-XMLDataSet {
ErrorAction = 'Stop'
Path = '{0}/{1}' -f $script:dataPath, $script:dataFileZip
}
$null = Expand-Archive @expandArchiveSplat
$null = Microsoft.PowerShell.Archive\Expand-Archive @expandArchiveSplat
Write-Verbose -Message 'Expand completed.'
} #try
catch {
Expand Down
2 changes: 1 addition & 1 deletion src/pwshEmojiExplorer/pwshEmojiExplorer.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'pwshEmojiExplorer.psm1'

# Version number of this module.
ModuleVersion = '0.8.2'
ModuleVersion = '0.8.4'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down

0 comments on commit e81ffb0

Please sign in to comment.