Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ntatschner committed Apr 4, 2024
1 parent b36d3b6 commit bd2fccb
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 15 deletions.
41 changes: 26 additions & 15 deletions Modules/Tatux.Utils/Public/Update-NTModuleManifest.ps1
Original file line number Diff line number Diff line change
@@ -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 = .*$"
}

}
59 changes: 59 additions & 0 deletions Modules/Tatux.Utils/Tatux.Utils_test.psd1
Original file line number Diff line number Diff line change
@@ -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

}

0 comments on commit bd2fccb

Please sign in to comment.