Repository navigation
Expand file tree
/
Copy pathNetboxTools.build.ps1
More file actions
111 lines (93 loc) · 4.31 KB
/
Copy pathNetboxTools.build.ps1
File metadata and controls
111 lines (93 loc) · 4.31 KB
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
#Requires -Modules 'InvokeBuild', 'Microsoft.Powershell.PlatyPS', 'Pester', 'PsScriptAnalyzer'
param (
[string]$Version = '1.0.0'
)
[string]$ModuleName = 'NetboxTools'
[string]$ModuleSourcePath = "$PSScriptRoot\Source"
[string]$HelpSourcePath = "$PSScriptRoot\Docs\Help"
[string]$BuildSourcePath = "$PSScriptRoot"
[string]$OutputPath = "$PSScriptRoot\Bin\$ModuleName\$Version"
task Clean {
If (Test-Path -Path $OutputPath) {
"Removing existing files and folders in $OutputPath"
Get-ChildItem $OutputPath | Remove-Item -Force -Recurse
}
Else {
"$OutputPath is not present, nothing to clean up."
$Null = New-Item -ItemType Directory -Path $OutputPath
}
}
task Unit_Tests {
.$PSScriptRoot\Tests\TestRunner.ps1 -ModuleLoadPath "$PSScriptRoot\Source\NetboxTools.psm1" -Verbosity Normal -CodeCoveragePath "$PSScriptRoot\Source\Public"
}
task Unit_Tests_Compiled {
.$PSScriptRoot\Tests\TestRunner.ps1 -ModuleLoadPath "$OutputPath\NetboxTools.psm1" -Verbosity Normal -CodeCoveragePath "$OutputPath\NetboxTools.psm1"
}
task RunScriptAnalyzer {
Invoke-ScriptAnalyzer -Path $ModuleSourcePath -Recurse -Severity Error -EnableExit
}
Task Build_Documentation {
# New-ExternalHelp -Path $HelpSourcePath -OutputPath "$OutputPath\en-US"
$mdfiles = Measure-PlatyPSMarkdown -Path ".\Docs\Help\*.md"
$mdfiles | Where-Object Filetype -match 'CommandHelp' |
Import-MarkdownCommandHelp -Path { $_.FilePath } |
Export-MamlCommandHelp -OutputFolder "$OutputPath\en-US"
Move-Item -Path "$OutputPath\en-US\NetboxTools\NetboxTools-Help.xml" -Destination "$OutputPath\en-US\NetboxTools-Help.xml" -Force
Remove-Item "$OutputPath\en-US\NetboxTools" -Force
}
task Compile_Module {
$PSM1Name = "$ModuleName.psm1"
New-Item -Name $PSM1Name -Path $OutputPath -ItemType File -Force
$PSM1Path = (Join-Path -Path $OutputPath -ChildPath $PSM1Name)
$PSD1Name = "$ModuleName.psd1"
New-Item -Name $PSD1Name -Path $OutputPath -ItemType File -Force
$PSD1Path = (Join-Path -Path $OutputPath -ChildPath $PSD1Name)
$ExportedFunctionList = [System.Collections.Generic.List[string]]::new()
# PreCode
Get-ChildItem "$BuildSourcePath\Tools\_PreModule*.ps1" | ForEach-Object {
$FileContent = Get-Content $_.FullName
"#region PreCode $($_.BaseName)`n" | Out-File $PSM1Path -Append
$FileContent | Out-File $PSM1Path -Append
"#endregion PreCode $($_.BaseName)`n" | Out-File $PSM1Path -Append
}
# Classes
Get-ChildItem "$ModuleSourcePath\Classes" *.ps1 | ForEach-Object {
$FileContent = Get-Content $_.FullName
"#region $($_.BaseName)`n" | Out-File $PSM1Path -Append
$FileContent | Out-File $PSM1Path -Append
"#endregion $($_.BaseName)`n" | Out-File $PSM1Path -Append
}
# Private functions
Get-ChildItem "$ModuleSourcePath\Private" *.ps1 | ForEach-Object {
$FileContent = Get-Content $_.FullName
"#region $($_.BaseName)`n" | Out-File $PSM1Path -Append
$FileContent | Out-File $PSM1Path -Append
"#endregion $($_.BaseName)`n" | Out-File $PSM1Path -Append
}
# Public functions
Get-ChildItem "$ModuleSourcePath\Public" *.ps1 | ForEach-Object {
$ExportedFunctionList.Add($_.BaseName)
$FileContent = Get-Content $_.FullName
"#region $($_.BaseName)`n" | Out-File $PSM1Path -Append
$FileContent | Out-File $PSM1Path -Append
"#endregion $($_.BaseName)`n" | Out-File $PSM1Path -Append
}
# PostCode
Get-ChildItem "$BuildSourcePath\Tools\_PostModule*.ps1" | ForEach-Object {
$FileContent = Get-Content $_.FullName
"#region PostCode $($_.BaseName)`n" | Out-File $PSM1Path -Append
$FileContent | Out-File $PSM1Path -Append
"#endregion PostCode $($_.BaseName)`n" | Out-File $PSM1Path -Append
}
# Manifest
Update-ModuleManifest -Path "$ModuleSourcePath\$ModuleName.psd1" -ModuleVersion $Version -FunctionsToExport $ExportedFunctionList
Copy-Item -Path "$ModuleSourcePath\$ModuleName.psd1" -Destination $PSD1Path
}
Get-Module -Name $ModuleName | Remove-Module -Force
# Default task :
task . Clean,
Unit_Tests,
RunScriptAnalyzer,
Build_Documentation,
Compile_Module,
Unit_Tests_Compiled