-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.ps1
58 lines (47 loc) · 2.17 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
#Requires -Version 5.1
$ErrorActionPreference = 'Stop'
# Get cert path
[System.String]$CertPath = Read-Host -Prompt 'Please enter cert path (Cert:\CurrentUser\My\71C28FC065F(...)367825B1AF)'
if (-not (Test-Path -Path $CertPath)) {
Write-Host -Object "Cert $CertPath not found!"
return
}
$Cert = Get-Item -Path $CertPath
# Remove old build if available
if (Test-Path -Path '.\build') {
Remove-Item -Path '.\build' -Recurse -Force
}
# Load the config.json
$Config = Get-Content -Path '.\config.json' | ConvertFrom-Json
# Create folder structure
New-Item -Path ('.\build\' + $Config.ModuleName) -ItemType Directory
# Get functions to export
[System.String[]]$FunctionsToExport = (Get-ChildItem -Path '.\functions').BaseName
# Create powershell module manifest
New-ModuleManifest -Path ('.\build\' + $Config.ModuleName + '\' + $Config.ModuleName + '.psd1') `
-Guid $Config.GUID `
-Author $Config.Author `
-CompanyName $Config.CompanyName `
-Copyright $Config.Copyright `
-ModuleVersion $Config.ModuleVersion `
-Description $Config.Description `
-PowerShellVersion $Config.PowerShellVersion `
-FunctionsToExport $FunctionsToExport `
-ProjectUri $Config.ProjectUri `
-LicenseUri $Config.LicenseUri `
-ReleaseNotes $Config.ReleaseNotes `
-RootModule "$($Config.ModuleName).psm1" `
-Tags $Config.Tags `
-IconUri $Config.IconUri
# Replace the "# Generated by: XY"
[System.String]$ModuleManifest = Get-Content -Path ('.\build\' + $Config.ModuleName + '\' + $Config.ModuleName + '.psd1') -Raw
$ModuleManifest = $ModuleManifest -replace '# Generated by: .*' , "# Generated by: $($Config.CompanyName)"
Set-Content -Path ('.\build\' + $Config.ModuleName + '\' + $Config.ModuleName + '.psd1') -Value $ModuleManifest
# Create the powershell module
foreach ($Funciton in (Get-ChildItem -Path '.\functions')) {
Get-Content -Path $Funciton.FullName -Raw | Add-Content -Path ('.\build\' + $Config.ModuleName + '\' + $Config.ModuleName + '.psm1')
}
# Sign the generated files
foreach ($File in (Get-ChildItem -Path '.\build\*' -Recurse)) {
Set-AuthenticodeSignature -FilePath $File.FullName -Certificate $Cert -TimestampServer 'http://timestamp.digicert.com'
}