From bd2fccb2ad1e8448698cf36d916bfb5233d184dc Mon Sep 17 00:00:00 2001 From: Nigel Tatschner Date: Thu, 4 Apr 2024 19:15:24 +0100 Subject: [PATCH] Updates --- .../Public/Update-NTModuleManifest.ps1 | 41 ++++++++----- Modules/Tatux.Utils/Tatux.Utils_test.psd1 | 59 +++++++++++++++++++ 2 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 Modules/Tatux.Utils/Tatux.Utils_test.psd1 diff --git a/Modules/Tatux.Utils/Public/Update-NTModuleManifest.ps1 b/Modules/Tatux.Utils/Public/Update-NTModuleManifest.ps1 index 887e6a5..aa58990 100644 --- a/Modules/Tatux.Utils/Public/Update-NTModuleManifest.ps1 +++ b/Modules/Tatux.Utils/Public/Update-NTModuleManifest.ps1 @@ -1,21 +1,32 @@ function Update-NTModuleManifest { [CmdletBinding()] param( - [ValidateScript({ - if (-Not (Test-Path -Path $_) -or $_.EndsWith(".psd1") -eq $false) { - throw "Enter a valid manifest file." + [ValidateScript({ + if (-Not (Test-Path -Path $_) -or $_.EndsWith(".psd1") -eq $false) { + throw "Enter a valid manifest file." + } + else { + $true + } + })] + [string]$Path + ) + # Test if field CmdletsToExport exists in the manifest file + $ManifestFileContent = Get-Content -Path $Path + $ModuleRoot = Split-Path -Path $Path -Parent + $PublicFunctions = Join-Path -Path $ModuleRoot -ChildPath "Public" + if ([string]::IsNullOrEmpty($ManifestFileContent -match '[\s|\t]*CmdletsToExport\s*=.*') -eq $false) { + $LineWithCmdletsToExport = $($ManifestFileContent | Select-String -Pattern '^[\s|\t]*CmdletsToExport\s*=(.*)$') + $LineNumber = $LineWithCmdletsToExport.LineNumber - 1 + $ManifestFileLines = $ManifestFileContent -split "`n" + $CmdletsToExport = $(Get-ChildItem -Path $PublicFunctions -Filter "*.ps1" | Where-Object { $_.Name -notlike "*.tests.ps1" | select Name }) -join ', ' + $NewLine = "CmdletsToExport = @($CmdletsToExport)" + Write-Output "Replacing line: $LineWithCmdletsToExport with $NewLine" + $ManifestFileContent = $ManifestFileLines[$LineNumber] -replace [regex]::Escape($LineWithCmdletsToExport.Matches.Groups[1].Value), $NewLine + $ManifestFileContent = $ManifestFileLines -join "`n" + Set-Content -Path $Path -Value $ManifestFileContent } else { - $true + Write-Error "CmdletsToExport field could not be found in the manifest file." + break } - )] - [string]$Path - - ) -# Test if paths a valid manifest file and if so has the right field FunctionsToExport - $ManifestFileContent = Get-Content -Path $Path -Raw - - if ($ManifestFileContent -match "FunctionsToExport =") { - $LineToReplace = $ManifestFileContent | Select-String -Pattern "^FunctionsToExport = .*$" - } - } \ No newline at end of file diff --git a/Modules/Tatux.Utils/Tatux.Utils_test.psd1 b/Modules/Tatux.Utils/Tatux.Utils_test.psd1 new file mode 100644 index 0000000..b5e4a0d --- /dev/null +++ b/Modules/Tatux.Utils/Tatux.Utils_test.psd1 @@ -0,0 +1,59 @@ +# +# Module manifest for module 'PSGet_Tatux.Utils' +# +# Generated by: Nigel Tatschner +# +# Generated on: 25/03/2020 +# + +@{ + + # Script module or binary module file associated with this manifest. + #RootModule = 'Tatux.Utils' + + # Version number of this module. + ModuleVersion = '0.2.28' + + # ID used to uniquely identify this module + GUID = '061256e7-9e17-4571-9481-baca2e0bc13e' + + # Author of this module + Author = 'Nigel Tatschner' + + # Company or vendor of this module + CompanyName = 'Tatux Solutions' + + # Copyright statement for this module + Copyright = '(c) 2023 . All rights reserved.' + + # Description of the functionality provided by this module + Description = 'A Set of utilities ive created to help with various tasks' + + # Minimum version of the Windows PowerShell engine required by this module + PowerShellVersion = '5.1' + + #Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. + FunctionsToExport = '*' + + # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. + CmdletsToExport = '*' + + # Variables to export from this module + VariablesToExport = '*' + + # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. + AliasesToExport = @() + + NestedModules = @('Tatux.Utils.psm1') + + # 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 = @{ + + PSData = @{ + # ReleaseNotes of this module + ReleaseNotes = 'Updated the template for pester tests' + } # End of PSData hashtable + + } # End of PrivateData hashtable + + }