43 lines
1.3 KiB
PowerShell
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!'
|
|
}
|
|
}
|
|
}
|