Guest User

Untitled

a guest
Jun 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. [cmdletbinding()]
  2. param (
  3. $SourceFolder = $PSScriptRoot
  4. )
  5.  
  6. if (-not (Get-Module PSDepend -ListAvailable)) {
  7. Install-Module PSDepend -Repository (Get-PSRepository)[0].Name -Scope CurrentUser
  8. }
  9. Push-Location $PSScriptRoot -StackName BuildScript
  10. Invoke-PSDepend -Path $SourceFolder -Confirm:$false
  11. Pop-Location -StackName BuildScript
  12.  
  13. Write-Verbose -Message "Working in $SourceFolder" -verbose
  14. $Module = Get-ChildItem -Path $SourceFolder -Filter *.psd1 -Recurse | Select-String -Pattern 'RootModule' | Select-Object -First 1 -ExpandProperty Path
  15. $Module = Get-Item -Path $Module
  16.  
  17. $DestinationModule = "$($Module.Directory.FullName)\$($Module.BaseName).psm1"
  18. Write-Verbose -Message "Attempting to work with $DestinationModule" -verbose
  19.  
  20. if (Test-Path -Path $DestinationModule ) {
  21. Remove-Item -Path $DestinationModule -Confirm:$False -force
  22. }
  23.  
  24. $PublicFunctions = Get-ChildItem -Path $SourceFolder -Include 'Public', 'External' -Recurse -Directory | Get-ChildItem -Include *.ps1 -File
  25. $PrivateFunctions = Get-ChildItem -Path $SourceFolder -Include 'Private', 'Internal' -Recurse -Directory | Get-ChildItem -Include *.ps1 -File
  26.  
  27. if ($PublicFunctions -or $PrivateFunctions) {
  28. Write-Verbose -message "Found Private or Public functions. Will compile these into the psm1 and only export public functions."
  29.  
  30. Foreach ($PrivateFunction in $PrivateFunctions) {
  31. Get-Content -Path $PrivateFunction.FullName | Add-Content -Path $DestinationModule
  32. }
  33. Write-Verbose -Message "Found $($PrivateFunctions.Count) Private functions and added them to the psm1."
  34. }
  35. else {
  36. Write-Verbose -Message "Didnt' find any Private or Public functions, will assume all functions should be made public."
  37.  
  38. $PublicFunctions = Get-ChildItem -Path $SourceFolder -Include *.ps1 -Recurse -File
  39. }
  40.  
  41. Foreach ($PublicFunction in $PublicFunctions) {
  42. Get-Content -Path $PublicFunction.FullName | Add-Content -Path $DestinationModule
  43. }
  44. Write-Verbose -Message "Found $($PublicFunctions.Count) Public functions and added them to the psm1."
  45.  
  46. $PublicFunctionNames = $PublicFunctions |
  47. Select-String -Pattern 'Function (\w+-\w+) {' -AllMatches |
  48. Foreach-Object {
  49. $_.Matches.Groups[1].Value
  50. }
  51. Write-Verbose -Message "Making $($PublicFunctionNames.Count) functions available via Export-ModuleMember"
  52.  
  53. "Export-ModuleMember -Function {0}" -f ($PublicFunctionNames -join ',') | Add-Content $DestinationModule
  54.  
  55. $var = Invoke-Pester -Script $SourceFolder -Show Fails #-CodeCoverage $DestinationModule -CodeCoverageOutputFile "$SourceFolder\..\$($Module.Basename)CodeCoverage.xml" -CodeCoverageOutputFileFormat JaCoCo -PassThru -Show Fails
  56.  
  57. Invoke-ScriptAnalyzer -Path $DestinationModule
Add Comment
Please, Sign In to add comment