Functions/Update-MyModuleManifest.ps1
function Update-MyModuleManifest { [CmdletBinding()] param ( [Parameter()] [ArgumentCompleter( { param ( $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters ) Get-ChildItem "$($env:USERPROFILE)\Git\$wordToComplete*" -Directory -Name | ForEach-Object { $_ } } )] [string] $Module, [Parameter()] [ValidateSet("Minor", "Major", "Build")] [string] $VersionChange = "Build" ) if (!($Module)) { $PossibleModulename = Get-Item . | Select-Object -ExpandProperty Name $ModuleFile = "$PossibleModulename.psd1" Write-Verbose "ModuleFile: $ModuleFile" if (Test-Path $ModuleFile) { $Module = $PossibleModulename Write-Verbose "Module: $Module" } } Write-Verbose "Module: $Module" $FullPath = Join-Path "$($env:USERPROFILE)\Git" $Module Write-Verbose $FullPath Write-Verbose "Test-Path $FullPath" if (Test-Path $FullPath) { $ModuleFolders = Get-Item $FullPath } else { throw "No module file found" # #Set-Location $MyModulePath # $MyModulePath = "$($env:USERPROFILE)\Git" # if ($Module) { # $ModuleFolders = Get-ChildItem $MyModulePath -Directory -Exclude ".git" | Where-Object Name -EQ $Module # } else { # $ModuleFolders = Get-ChildItem $MyModulePath -Directory -Exclude ".git", "PackageManagement" # } } foreach ($m in $ModuleFolders) { Write-Output "Updating module: $($m.BaseName)" Write-Verbose $m.FullName $FunctionsToExport = (Get-ChildItem (Join-Path $m.FullName -ChildPath "Functions") -File).BaseName $VariablesToExport = @('-') if (Test-Path (Join-Path $m.FullName -ChildPath "Variables")) { $VariablesToExport = (Get-ChildItem (Join-Path $m.FullName -ChildPath "Variables")).BaseName } if (Test-Path (Join-Path $m.FullName -ChildPath "Other\RequiredModules.csv")) { $RequiredModules = Import-Csv (Join-Path $m.FullName -ChildPath "Other\RequiredModules.csv") | Select-Object -ExpandProperty Modulename } else { $RequiredModules = @() } if (Test-Path (Join-Path $m.FullName -ChildPath "Other\ModuleDescription.txt")) { $ModuleDescription = Get-Content (Join-Path $m.FullName -ChildPath "Other\ModuleDescription.txt") } else { $ModuleDescription = $m.BaseName } if (Test-Path (Join-Path $m.FullName -ChildPath ($m.BaseName + ".psd1"))) { $ModuleInfo = Get-Module $m.FullName -ListAvailable if ($VersionChange -eq "Major") { $CurrentVersion = $ModuleInfo.Version.Major $NewVersion = $CurrentVersion + 1 $NewVersion = "$($NewVersion).0.0" } elseif ($VersionChange -eq "Minor") { $CurrentVersion = $ModuleInfo.Version.Minor $NewVersion = $CurrentVersion + 1 $NewVersion = "$($ModuleInfo.Version.Major).$($NewVersion).0" } elseif ($VersionChange -eq "Build") { $CurrentVersion = $ModuleInfo.Version.Build $NewVersion = $CurrentVersion + 1 $NewVersion = "$($ModuleInfo.Version.Major).$($ModuleInfo.Version.Minor).$NewVersion" } } else { $NewVersion = "0.0.1" } $ModuleManifestParameters = @{ Path = (Join-Path $m.FullName -ChildPath ($m.BaseName + ".psd1")) RootModule = $m.BaseName + ".psm1" ModuleVersion = $NewVersion FunctionsToExport = $FunctionsToExport VariablesToExport = $VariablesToExport Copyright = "(c) $((Get-Date).Year) JT. All rights reserved." } if ($RequiredModules) { $ModuleManifestParameters.Add("RequiredModules", $RequiredModules) } if ($ModuleDescription) { $ModuleManifestParameters.Add("Description", $ModuleDescription) } #$ModuleManifestParameters if (Test-Path $ModuleManifestParameters.Path) { Update-ModuleManifest @ModuleManifestParameters } else { $psmContent = @" (Get-ChildItem "`$PSScriptRoot\Functions") | ForEach-Object { . `$_.FullName } "@ $psmContent | Out-File (Join-Path $m.FullName -ChildPath ($m.BaseName + ".psm1")) New-ModuleManifest @ModuleManifestParameters } if (Test-Path (Join-Path $m.FullName ".git")) { $CurrentLocation = Get-Location Set-Location $m.FullName # $m.FullName Write-Host "$($m.BaseName).psd1" git add ".\$($m.BaseName).psd1" git commit -i ".\$($m.BaseName).psd1" -m "Version update" Set-Location $CurrentLocation } } Test-ModuleManifest $ModuleManifestParameters.Path | Format-List $ModuleManifestParameters | Format-Table } |