OCram85/DroneHelper
OCram85
/
DroneHelper
Archived
1
0
Fork 0
This repository has been archived on 2023-10-10. You can view files and clone it, but cannot push or open issues or pull requests.
DroneHelper/src/Build/Merge-ModuleRoot.ps1

43 lines
1.3 KiB
PowerShell

function Merge-ModuleRoot {
<#
.SYNOPSIS
Merges single ps1 files into one module script file.
.DESCRIPTION
This Cmdlet is used in build pipeline to reduce the file load and import performance to the target module.
.INPUTS
[None] No pipeline input.
.OUTPUTS
[None] No pipeline output.
.EXAMPLE
Import-Module -Name DroneHelper; Merge-ModuleRoot
#>
[CmdletBinding()]
param ()
process {
$Repo = Get-RepoPath
$srcFiles = Get-ChildItem -Path $Repo.Src.Path -Recurse -File | Where-Object {
($_.Name -notmatch '.Tests.') -and ($_.Name -match '.ps1') -and ($_.Name -notmatch '.ps1xml')
}
$Output = @()
foreach ($psFile in $srcFiles) {
$fileContent = Get-Content -Path $psFile.FullName -Raw -Encoding 'utf8'
$Output += '# srcFile: {0}' -f $psFile.FullName
$Output += $fileContent.TrimEnd()
$Output += '{0}' -f [Environment]::NewLine
}
try {
$Output | Out-File -FilePath $Repo.Bin.ScriptModuleName -Encoding 'utf8' -Force -ErrorAction Stop
}
catch {
Write-FailureStateFile -StepName 'MergeModuleRoot'
throw 'Could not write the final module root script file!'
}
}
}