-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
101 lines (57 loc) · 3.24 KB
/
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
[cmdletbinding()]
param (
[Parameter(Mandatory=$false)]
[String]
$SourceFolder = [Environment]::GetEnvironmentVariable('BUILD_SOURCESDIRECTORY'),
[Parameter(Mandatory=$false)]
[String]
$ModuleName=[Environment]::GetEnvironmentVariable('ModuleName'),
[Parameter(Mandatory=$false)]
[String]
$ModuleVersion=[Environment]::GetEnvironmentVariable('ModuleVersion')
)
Install-Module Az -Force -AllowClobber
install-Module platyPS -Force -AllowClobber
import-module -name AZ
$PathSeparator = [IO.Path]::DirectorySeparatorChar
#Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
#Install-Module -Name platyPS -Scope CurrentUser
$BuildFolder = join-path -path $SourceFolder -childpath "generated"
$BuildModulePath = join-path -path $BuildFolder -ChildPath $ModuleName
$BuildModuleDoc = join-path -path $BuildModulePath -ChildPath "docs"
$BuildModuleClasses = join-path -path $BuildModulePath -ChildPath "classes"
$BuildModulePrivateFolder = join-path -path $BuildModulePath -ChildPath "private"
$BuildModulePublicFolder = join-path -path $BuildModulePath -ChildPath "public"
$ModuleSourceFolder = join-path -path $SourceFolder -childpath "src"
$ModuleSourceFolder = join-path -path $ModuleSourceFolder -childpath $ModuleName
if (Test-Path $BuildFolder) {
Remove-Item -Path $BuildFolder -Force -Recurse -Confirm:$false
}
new-item -Path $BuildFolder -ItemType Directory
new-item -Path $BuildModulePath -ItemType Directory
$BuildModuleManifest = Join-Path -Path $BuildModulePath -ChildPath "$($ModuleName).psd1"
$BuildModulePSM1 = Join-Path -Path $BuildModulePath -ChildPath "$($ModuleName).psm1"
$SourceMouduleManifest = Join-Path -Path $ModuleSourceFolder -ChildPath "module.psd1"
Copy-Item -Path $SourceMouduleManifest -Destination $BuildModuleManifest -Force
$PublicFunctionsList = Get-ChildItem -Path $ModuleSourceFolder -Include 'Public' -Recurse -Directory | Get-ChildItem -Include *.ps1 -File
$AllFunctionsAndClasses = Get-ChildItem -Path $ModuleSourceFolder -Include 'Public', 'classes' -Recurse -Directory | Get-ChildItem -Include *.ps1 -File
$AllJsonFiles = Get-ChildItem -Path $ModuleSourceFolder -Include 'json' -Recurse -Directory | Get-ChildItem -Include *.json -File
new-item -Path $BuildModulePSM1 -ItemType File
Get-ChildItem -Path $ModuleSourceFolder -Include 'json' -Recurse -Directory | Get-ChildItem -Include *.json -File
if ($AllFunctionsAndClasses) {
Foreach ($FunctionAndClass in $AllFunctionsAndClasses) {
Get-Content -Path $FunctionAndClass.FullName | Add-Content -Path $BuildModulePSM1
}
}
if ($AllJsonFiles) {
Foreach ($JsonFile in $AllJsonFiles) {
$destination = join-path -Path $BuildModulePath -ChildPath $JsonFile.Name
Copy-Item -Path $JsonFile.FullName -Destination $destination -Force
}
}
Update-ModuleManifest -Path $BuildModuleManifest -FunctionsToExport $PublicFunctionsList.BaseName
Update-ModuleManifest -Path $BuildModuleManifest -ModuleVersion $ModuleVersion
Update-ModuleManifest -Path $BuildModuleManifest -RootModule "$($ModuleName).psm1"
Import-Module platyPS -Force
$ModuleInformation = Import-module -Name $BuildModuleManifest -PassThru
New-MarkdownHelp -Module $ModuleName -OutputFolder $BuildModuleDoc -ErrorAction SilentlyContinue