$path = "C:\PSRepoLocal\"
Write-Host "Starting 01.create-module-folder.ps1"
Remove-ItemIfExists .\fun-new-test-module
Remove-ItemIfExists "$path\fun-new-test-module*"

Write-Host "Ensure C:\PSRepoLocal Exists"

If(!(test-path $path))
      New-Item -ItemType Directory -Force -Path $path

Write-Host "Register a file share on my local machine"
if ((Get-PsRepository PSRepoLocal | Measure).Count -lt 1) {  
  Register-PSRepository `
    -Name PSRepoLocal `
    -SourceLocation $path `
    -ScriptSourceLocation $path `
    -InstallationPolicy Trusted

Write-Verbose "Creating new directory fun-new-test-module"
New-Item "fun-new-test-module" -ItemType Directory -Force

Write-Verbose "Changing location to fun-new-test-module"
Set-Location fun-new-test-module

Write-Verbose "
Initialize-Psm -y

Initialize-Psm -y -WhatIf
Initialize-Psm -y -Verbose

Write-Verbose "
Add-PsmFunction Ping-Something

Add-PsmFunction "Ping-Something" -WhatIf
Add-PsmFunction "Ping-Something" -Verbose

Write-Verbose "
Add-PsmTest Ping-Something

Add-PsmTest "Ping-Something" -WhatIf
Add-PsmTest "Ping-Something" -Verbose

Write-Verbose "
Add-PsmFunction Ping-SomethingElse

Add-PsmFunction "Ping-SomethingElse" -WhatIf
Add-PsmFunction "Ping-SomethingElse" -Verbose

Write-Verbose "
Add-PsmInternalFunction Ping-SomethingInternal

Add-PsmInternalFunction "Ping-SomethingInternal" -WhatIf
Add-PsmInternalFunction "Ping-SomethingInternal" -Verbose

# Write-Verbose "
# Add-PsmDependency PSScriptAnalyzer
# "
# Add-PsmDependency "PSScriptAnalyzer" -Whatif
# Add-PsmDependency "PSScriptAnalyzer" -Verbose

Write-Verbose "

Write-PsmManifest -WhatIf
Write-PsmManifest -Verbose

Write-Verbose "Workspace: "

Test-ModuleManifest -Path .\fun-new-test-module.psd1

Write-Verbose "Changing location to original location"
Set-Location ..

Write-Host "Publish module to local repository"
Publish-Module -Path ".\fun-new-test-module" -NuGetApiKey "..." -Repository PSRepoLocal -Verbose -Force

Write-Verbose "Removing fun-new-test-module directory"
Remove-Item "fun-new-test-module" -Recurse -Force
Write-Host "Goodbye from Module-Test script 01"