Skip to content

Commit

Permalink
Condensed the code for this cscript
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffpatton1971 committed Jul 18, 2024
1 parent a181b7d commit 4afe2f5
Showing 1 changed file with 28 additions and 54 deletions.
82 changes: 28 additions & 54 deletions createpowershellmodule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,38 @@ param (
[string]$Imports,
[string]$Debug = 'false'
)
try
{

try {
Write-Host "::group::Starting the Create PowerShell Module task..."
Write-Host "::group::Setting up variables"

[bool]$Debug = [System.Convert]::ToBoolean($Debug)

if ([string]::IsNullOrEmpty($Source))
{
$sourcePath = "$($env:GITHUB_WORKSPACE)"
}
else
{
$sourcePath = "$($env:GITHUB_WORKSPACE)\$($Source)"
}
$Debug = [System.Convert]::ToBoolean($Debug)

if ([string]::IsNullOrEmpty($Output))
{
$outputPath = "$($env:GITHUB_WORKSPACE)\output"
}
else
{
$outputPath = "$($env:GITHUB_WORKSPACE)\$($Output)"
}
$sourcePath = if ([string]::IsNullOrEmpty($Source)) { $env:GITHUB_WORKSPACE } else { Join-Path $env:GITHUB_WORKSPACE $Source }
$outputPath = if ([string]::IsNullOrEmpty($Output)) { Join-Path $env:GITHUB_WORKSPACE "output" } else { Join-Path $env:GITHUB_WORKSPACE $Output }

$Module = Get-ChildItem -Path $SourcePath -Filter "$($ModuleName).psd1" -Recurse
$Module = Get-ChildItem -Path $sourcePath -Filter "$ModuleName.psd1" -Recurse
$ModuleRoot = $Module.Directory.FullName
$Destination = "$($outputPath)\$($ModuleName)"
$modulePath = "$($Destination)\$($ModuleName).psm1"
$Destination = Join-Path $outputPath $ModuleName
$modulePath = Join-Path $Destination "$ModuleName.psm1"

if ($Debug)
{
Write-Host "ModuleName : $($ModuleName)"
Write-Host "SourcePath : $($sourcePath)"
Write-Host "OutputPath : $($outputPath)"
Write-Host "Destination : $($Destination)"
Write-Host "ManifestPath : $($ManifestPath)"
Write-Host "ModuleRoot : $($ModuleRoot)"
Write-Host "Imports : $($imports)"
if ($Debug) {
Write-Host "ModuleName : $ModuleName"
Write-Host "SourcePath : $sourcePath"
Write-Host "OutputPath : $outputPath"
Write-Host "Destination : $Destination"
Write-Host "ModuleRoot : $ModuleRoot"
Write-Host "Imports : $Imports"
}

$stringbuilder = [System.Text.StringBuilder]::new()
$importFolders = $imports.Split(',')
$importFolders = $Imports.Split(',')

Write-Host "::endgroup::"

Write-Host "::group::Copying Manifest"

if ($Debug)
{
if ($Debug) {
Write-Host "Testing Output"
}

Expand All @@ -63,42 +45,34 @@ try
}

Write-Host "::group::Processing import folders..."
foreach ($importFolder in $importFolders)
{
Write-Host "Importing from [$($ModuleRoot)\$($importFolder)]"
if ($Debug)
{
foreach ($importFolder in $importFolders) {
Write-Host "Importing from [$ModuleRoot\$importFolder]"
if ($Debug) {
Write-Host "Testing ImportFolder"
}
if (Test-Path "$ModuleRoot\$importFolder")
{
$fileList = Get-ChildItem "$($ModuleRoot)\$($importFolder)\*.ps1" -Exclude "*.Tests.ps1"
foreach ($file in $fileList)
{
if (Test-Path -Path (Join-Path $ModuleRoot $importFolder)) {
$fileList = Get-ChildItem -Path (Join-Path $ModuleRoot $importFolder) -Filter "*.ps1" -Exclude "*.Tests.ps1"
foreach ($file in $fileList) {
Write-Host " Importing [.$($file.BaseName)]"
if ($Debug)
{
if ($Debug) {
Write-Host "Reading file: $file.FullName"
}
$stringbuilder.AppendLine("# .$($file.BaseName)") | Out-Null
$stringbuilder.AppendLine([System.IO.File]::ReadAllText($file.FullName)) | Out-Null
}
}
else
{
} else {
Write-Host "##[warning]Folder $importFolder not found at $ModuleRoot"
}
}
Write-Host "::endgroup::"

Write-Host "::group::Creating module [$($modulePath)]"
Write-Host "::group::Creating module [$modulePath]"
Set-Content -Path $modulePath -Value $stringbuilder.ToString()
Write-Host "BuildModule task completed successfully."
Write-Host "::endgroup::"
Write-Host "::endgroup::"
}
catch
{
catch {
Write-Host "##[error]An error occurred: $($_.Exception.Message)"
exit 1
}
}

0 comments on commit 4afe2f5

Please sign in to comment.