-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.build.ps1
150 lines (124 loc) · 5.02 KB
/
default.build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
task . Clean, Build, Tests, BuildMarkdown, ExportHelp, GenerateGraph, Stats
task Tests ImportCompipledModule, Pester
task CreateManifest CopyPSD, UpdatPublicFunctionsToExport
task Build Compile, CreateManifest
task Stats RemoveStahts, WriteStats
task Help BuildMarkdown, ExportHelp
$ModuleName = Split-Path -Path $PSScriptRoot -Leaf
$srcPath = Join-Path -Path $PSScriptRoot -ChildPath "src"
$srcModulePath = Join-Path -Path $srcPath -ChildPath "$($ModuleName).psd1"
$srcModuleVersion = (Import-PowerShellDataFile -Path $srcModulePath).ModuleVersion
$graphsPath = Join-Path -Path $srcPath -ChildPath "Graphs"
$docsPath = [System.IO.Path]::Combine($PSScriptRoot, "docs", "en-US")
$OutPutFolder = "$PSScriptRoot\Release"
$statsjsonPath = [System.IO.Path]::Combine($OutPutFolder, $ModuleName, $srcModuleVersion, "stats.json")
$ImportFolders = @('Public', 'Private')
$PsmPath = Join-Path -Path $PSScriptRoot -ChildPath "Release\$($ModuleName)\$($srcModuleVersion)\$($ModuleName).psm1"
$PsdPath = Join-Path -Path $PSScriptRoot -ChildPath "Release\$($ModuleName)\$($srcModuleVersion)\$($ModuleName).psd1"
$HelpPath = Join-Path -Path $PSScriptRoot -ChildPath "Release\$($ModuleName)\$($srcModuleVersion)\en-US"
$PublicFolder = Join-Path -Path $srcPath -ChildPath 'Public'
task "Clean" {
if (-not(Test-Path $OutPutFolder))
{
New-Item -ItemType Directory -Path $OutPutFolder > $null
}
Remove-Item -Path "$($OutPutFolder)\*" -Force -Recurse
}
task Compile {
if (Test-Path -Path $PsmPath)
{
Remove-Item -Path $PsmPath -Recurse -Force
}
New-Item -Path $PsmPath -Force > $null
foreach ($folder in $ImportFolders)
{
$currentFolder = Join-Path -Path $srcPath -ChildPath $folder
Write-Verbose -Message "Checking folder [$currentFolder]"
if (Test-Path -Path $currentFolder)
{
$files = Get-ChildItem -Path $currentFolder -File -Filter '*.ps1'
foreach ($file in $files)
{
Write-Verbose -Message "Adding $($file.FullName)"
Get-Content -Path $file.FullName >> $PsmPath
}
}
}
}
task CopyPSD {
New-Item -Path (Split-Path $PsdPath) -ItemType Directory -ErrorAction 0
$copy = @{
Path = Join-Path -Path $srcPath -ChildPath "$($ModuleName).psd1"
Destination = $PsdPath
Force = $true
Verbose = $true
}
Copy-Item @copy
}
task UpdatPublicFunctionsToExport -if (Test-Path -Path $PublicFolder) {
$publicFunctions = (Get-ChildItem -Path $PublicFolder |
Select-Object -ExpandProperty BaseName) -join "', '"
$publicFunctions = "FunctionsToExport = @('{0}')" -f $publicFunctions
(Get-Content -Path $PsdPath) -replace "FunctionsToExport = '\*'", $publicFunctions | Set-Content -Path $PsdPath
}
task ImportCompipledModule -if (Test-Path -Path $PsmPath) {
Get-Module -Name $ModuleName |
Remove-Module -Force
Import-Module -Name $PsdPath -Force
}
task Pester {
$resultFile = "{0}\testResults{1}.xml" -f $OutPutFolder, (Get-date -Format 'yyyyMMdd_hhmmss')
$testFolder = Join-Path -Path $PSScriptRoot -ChildPath 'Tests\*'
Invoke-Pester -Path $testFolder -OutputFile $resultFile -OutputFormat NUnitxml -Verbose
}
task GenerateGraph -if (Test-Path -Path $graphsPath) {
$Graphs = Get-ChildItem -Path $graphsPath
Foreach ($graph in $Graphs)
{
$graphLocation = [IO.Path]::Combine($OutPutFolder, $ModuleName, $srcModuleVersion, "$($graph.BaseName).png")
}
}
task RemoveStats {
if (Test-Path -Path $statsjsonPath)
{
Remove-Item -Force -Verbose -Path $statsjsonPath
}
}
task WriteStats {
$folders = Get-ChildItem -Directory |
Where-Object { $PSItem.Name -ne 'Release' }
$stats = foreach ($folder in $folders)
{
$files = Get-ChildItem "$($folder.FullName)\*" -File
if ($files)
{
Get-Content -Path $files |
Measure-Object -Word -Line -Character |
Select-Object -Property @{N = "FolderName"; E = { $folder.Name } }, Words, Lines, Characters
}
}
$stats | ConvertTo-Json > $statsjsonPath
}
task ExportHelp -if (Test-Path -Path $docsPath) {
New-ExternalHelp -Path $docsPath -OutputPath $HelpPath -Force
}
task BuildMarkdown {
$moduleInfo = Import-Module $PsdPath -Global -Force -PassThru
if ($moduleInfo.ExportedCommands.Count -eq 0)
{
Write-Output "No commands have been exported. Skipping Step BuildMarkdown."
return
}
if (Get-ChildItem -Path $docsPath)
{
Get-ChildItem -Path $docsPath | Remove-Item -Exclude about* -Force
}
# ErrorAction set to SilentlyContinue so this command will not overwrite an existing MD file.
$splat = @{
Module = $ModuleName
Locale = "en-US"
OutputFolder = $docsPath
ErrorAction = "SilentlyContinue"
}
New-MarkdownHelp @splat
}