Public/Write-PsmManifest.ps1

function Write-PsmManifest {
  <#
    .Synopsis
      Write-PsmManifest writes a new manifest using the module-psd1.xml file.
    .DESCRIPTION
      Write-PsmManifest writes a new manifest using the module-psd1.xml file at the root of the repository.
      It is essentially a wrapper or New-ModuleManifest because that function doesn't accept piped input.
    .EXAMPLE
      Write-PsmManifest
      Write-PsmManifest -WhatIf
  #>
      
  [CmdletBinding(SupportsShouldProcess=$true)]  
  param ()  

  BEGIN{
    Write-Verbose "Starting Write-PsmManifest..."
    Confirm-IsInitializedModulePath
    $Psd1 = Import-CliXml .\module-psd1.xml
    $Psd1.Path = "$($Psd1.ModuleName).psd1"
    $emptyArray = @()
  }#begin

  PROCESS{
    if ($psCmdlet.ShouldProcess(<# on target --> #>"Current Module", <# What if: Performing operation --> #>"Writing the psd1 file here: $($Psd1.Path) $($Psd1 | ConvertTo-Json)")) { 
      Write-Host "Writing manifest here: $($Psd1.Path)"

      New-ModuleManifest `
        -Path $Psd1.Path `
        -DefaultCommandPrefix $Psd1.DefaultCommandPrefix `
        -RequiredModules $emptyArray `
        -FunctionsToExport $emptyArray `
        -AliasesToExport $emptyArray `
        -VariablesToExport $emptyArray `
        -NestedModules $Psd1.NestedModules `
        -Guid (New-Guid).Guid `
        -Author $Psd1.Author `
        -CompanyName $Psd1.CompanyName `
        -Copyright $Psd1.Copyright `
        -RootModule "$($Psd1.RootModule).psm1" `
        -ModuleVersion $Psd1.ModuleVersion `
        -Description $Psd1.Description 
      
      If (Confirm-IsNotNullOrEmptyObjectArray $Psd1.RequiredModules) {
        
        $requiredModules = $Psd1.RequiredModules | Foreach-Object {
          @{
            ModuleName = $_.Name
            ModuleVersion = $_.Version
          }
        }

        Update-ModuleManifest -Path $Psd1.Path -RequiredModules $requiredModules
      }
      
      If (Confirm-IsNotNullOrEmptyStringArray $Psd1.FunctionsToExport) {
        Update-ModuleManifest -Path $Psd1.Path -FunctionsToExport $Psd1.FunctionsToExport
      }
      
      If (Confirm-IsNotNullOrEmptyStringArray $Psd1.AliasesToExport) {
        Update-ModuleManifest -Path $Psd1.Path -AliasesToExport $Psd1.AliasesToExport
      }

      If (Confirm-IsNotNullOrEmptyStringArray $Psd1.CmdletsToExport) {
        Update-ModuleManifest -Path $Psd1.Path -CmdletsToExport $Psd1.CmdletsToExport
      }
      
      # If (Confirm-IsNullOrEmptyStringArray $Psd1.VariablesToExport) {
      # Update-ModuleManifest -Path $Psd1.Path -VariablesToExport $Psd1.VariablesToExport
      # }
      
      # If (Confirm-IsNullOrEmptyStringArray $Psd1.Tags) {
      # Update-ModuleManifest -Path $Psd1.Path -Tags $Psd1.Tags
      # }
      
      if ($Psd1.ProjectUri) {
        Update-ModuleManifest -Path $Psd1.Path -ProjectUri $Psd1.ProjectUri 
      }
      if ($Psd1.LicenseUri) {
        Update-ModuleManifest -Path $Psd1.Path -LicenseUri $Psd1.LicenseUri 
      }
      if ($Psd1.IconUri) {
        Update-ModuleManifest -Path $Psd1.Path -IconUri $Psd1.IconUri 
      }
      if ($Psd1.ReleaseNotes) {
        Update-ModuleManifest -Path $Psd1.Path -ReleaseNotes $Psd1.ReleaseNotes 
      }
      if ($Psd1.Prerelease) {
        Update-ModuleManifest -Path $Psd1.Path -Prerelease $Psd1.Prerelease 
      }
      
      ## Nice To Have's
        # -FileList $Psd1.FileList `
        # -ModuleList $Psd1.ModuleList `
        # -CmdletsToExport $Psd1.CmdletsToExport `
        # -DscResourcesToExport $Psd1.DscResourcesToExport `
        # -RequiredAssemblies $Psd1.RequiredAssemblies `
        # -CompatiblePSEditions $Psd1.CompatiblePSEditions `
     
      ## Handle these farther down the road...
        # -ProcessorArchitecture $Psd1.ProcessorArchitecture `
        # -PowerShellVersion $Psd1.PowerShellVersion `
        # -CLRVersion $Psd1.CLRVersion `
        # -DotNetFrameworkVersion $Psd1.DotNetFrameworkVersion `
        # -PowerShellHostName $Psd1.PowerShellHostName `
        # -PowerShellHostVersion $Psd1.PowerShellHostVersion `
        # -TypesToProcess $Psd1.TypesToProcess `
        # -FormatsToProcess $Psd1.FormatsToProcess `
        # -ScriptsToProcess $Psd1.ScriptsToProcess `
        # -RequireLicenseAcceptance $Psd1.RequireLicenseAcceptance `
        # -ExternalModuleDependencies $Psd1.ExternalModuleDependencies `
        # -HelpInfoUri $Psd1.HelpInfoUri `
        # -DefaultCommandPrefix $Psd1.DefaultCommandPrefix
    }
  }#process
  END{
    Write-Verbose "Finished Write-PsmManifest..."
  }#end
}  


### Internal Functions ###
function Confirm-IsNotNullOrEmptyObjectArray {
  param([psobject[]]$arr = @())

  if ($arr) {
    $true
    return
  } elseif ($arr.Length -gt 0) {
    $true
  } else {
    $false
  }
}

function Confirm-IsNotNullOrEmptyStringArray {
  param([string[]]$arr = @())

  if ($arr) {
    $true
    return
  } elseif ($arr.Length -gt 0) {
    $true
  } else {
    $false
  }
}

function Confirm-IsNullOrEmptyHashTable{
  param([Hashtable]$obj = @{})

  if ($obj -and $obj.Keys.Count -gt 0) {
    $false
  } else {
    $true
  }
}