-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMartinsProfile.build.ps1
177 lines (152 loc) · 5.46 KB
/
MartinsProfile.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#Requires -Version 7.4
#Requires -Modules @{ ModuleName="InvokeBuild"; ModuleVersion="5.11.1" }
param()
# Properties
$CompanyName = (property CompanyName 'Lupus Familiaris Software')
$Copyright = (property Copyright '(c) 2024, Martin Gill. All Rights Reserved.')
$ModuleName = (property ModuleName 'MartinsProfile')
$ModuleVersion = (property ModuleVersion '1.3.0')
# Paths
$SrcFolder = (property SrcFolder (Join-Path $BuildRoot 'src'))
$ClassesFolder = (property ClassFolder (Join-Path $srcFolder 'Classes'))
$PublicFolder = (property PublicFolder (Join-Path $srcFolder 'Public'))
$PrivateFolder = (property PrivateFolder (Join-Path $srcFolder 'Private'))
$OutputFolder = (property ModuleOutputFolder (Join-Path $BuildRoot 'artifacts'))
$ModuleOutputFolder = (property ModuleOutputFolder (Join-Path $OutputFolder $ModuleName))
$DevRepoPath = (property DevRepoPath (Join-Path $OutputFolder 'devrepo'))
task Build GenerateModule, CopyAdditionalFiles, GenerateManifest, {
}
task Clean {
remove $ModuleOutputFolder
}
task EnsureFolders {
$null = New-Item -Path $ModuleOutputFolder -ItemType Directory -Force
}
$ClassScripts = Get-ChildItem -Path $ClassesFolder -Recurse -Filter '*.ps1'
$PublicScripts = Get-ChildItem -Path $PublicFolder -Recurse -Filter '*.ps1'
$PrivateScripts = Get-ChildItem -Path $PrivateFolder -Recurse -Filter '*.ps1'
task GenerateModule EnsureFolders, {
$sb = [System.Text.StringBuilder]::new()
# Classes
$ClassScripts | ForEach-Object {
$content = Get-Content -Raw -Path $_
Write-Verbose "Adding Classes: $_"
$null = $sb.AppendLine($content)
}
# Private Functions
$PrivateScripts | ForEach-Object {
$content = Get-Content -Raw -Path $_
Write-Verbose "Adding Private: $_"
$null = $sb.AppendLine($content)
}
# Public Functions
$PublicScripts | ForEach-Object {
$content = Get-Content -Raw -Path $_
Write-Verbose "Adding Public: $_"
$null = $sb.AppendLine($content)
}
# Init Script
Write-Verbose 'Adding init script'
$content = Get-Content -Raw -Path (Join-Path $SrcFolder init.ps1)
$null = $sb.AppendLine($content)
Write-Verbose 'Writing root module file'
Set-Content -Path (Join-Path $ModuleOutputFolder "$moduleName.psm1") -Value $sb.ToString()
}
task CopyAdditionalFiles {
$additionalFiles = @(
@{
Name = 'config'
Path = 'config'
}
@{
Name = 'Dlls'
Path = 'Dlls'
}
@{
Name = 'Types'
Path = 'Types'
}
@{
Name = 'Formats'
Path = 'Formats'
}
)
Write-Verbose 'Copying Additional Files'
$additionalFiles | ForEach-Object {
Write-Verbose "Copying $($_.Name)"
Copy-Item -Path "$SrcFolder/$($_.Path)" -Destination "$ModuleOutputFolder/$($_.Path)" -Recurse -Force
}
}
task GenerateManifest EnsureFolders, {
$manifest = @{
Path = "$ModuleOutputFolder/$ModuleName.psd1"
NestedModules = @()
Guid = '585b8e60-7427-478c-ad52-43302e91c970'
CompanyName = $CompanyName
Copyright = $Copyright
RootModule = "$ModuleName.psm1"
ModuleVersion = $ModuleVersion
Description = "Martin's Personal Profile"
# ProcessorArchitecture = 'MSIL'
PowerShellVersion = '7.0'
# ClrVersion = ''
# DotNetFrameworkVersion = ''
# PowerShellHostName = ''
# PowerShellHostVersion = ''
RequiredModules = @(
@{
ModuleName = 'PSReadline'
ModuleVersion = '2.3.4'
}
@{
ModuleName = 'Terminal-Icons'
ModuleVersion = '0.11.0'
}
@{
ModuleName = 'posh-git'
ModuleVersion = '1.1.0'
}
)
TypesToProcess = Get-ChildItem -Path "$srcFolder/Types/*.ps1xml" | ForEach-Object { "Types/$($_.Name)" }
FormatsToProcess = Get-ChildItem -Path "$srcFolder/Formats/*.ps1xml" | ForEach-Object { "Formats/$($_.Name)" }
ScriptsToProcess = ''
RequiredAssemblies = @('Dlls/Humanizer.dll')
FileList = @()
ModuleList = @()
FunctionsToExport = @($PublicScripts | ForEach-Object { $_.BaseName })
AliasesToExport = @()
VariablesToExport = @()
CmdletsToExport = @()
DscResourcesToExport = @()
CompatiblePSEditions = 'Core'
PrivateData = @{}
# Tags = @()
# ProjectUri = ''
# LicenseUri = ''
# IconUri = ''
ReleaseNotes = 'TODO: Release Notes'
# Prerelease = ''
RequireLicenseAcceptance = $false
# HelpInfoUri = ''
PassThru = $false
DefaultCommandPrefix = "Pro"
WhatIf = $false
}
New-ModuleManifest @manifest
}
task CreateDevRepository -If { @(Get-PSResourceRepository | Where-Object Name -eq 'MartinsProfileDev').Count -eq 0 } {
$null = New-Item $DevRepoPath -Force -ItemType Directory
Register-PSResourceRepository -Name MartinsProfileDev -Uri $DevRepoPath -Trusted
}
task PublishLocal Build, CreateDevRepository, {
Publish-PSResource -Path $ModuleOutputFolder -Repository MartinsProfileDev -SkipDependenciesCheck
}
task DevInstall RemoveLocal, Build, ImportLocal, {
}
task RemoveLocal {
$null = Remove-Module MartinsProfile -ErrorAction SilentlyContinue
}
task ImportLocal {
Import-Module $ModuleOutputFolder/MartinsProfile
}
task Rebuild Clean,Build