-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.ps1
87 lines (68 loc) · 3.06 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
[CmdletBinding()]
param(
[string]$sha,
[string]$version
)
$dotnetTemplates = "$PSScriptRoot\src\Get-InstalledDotnetTemplates.ps1"
. "$PSScriptRoot\src\functions\Compress-String.ps1"
. "$PSScriptRoot\src\functions\Set-BlankLine.ps1"
$sourceBashScript = "$PSScriptRoot\src\init.sh"
$componentScriptDirectory = "$PSScriptRoot\src\components"
$functionScriptDirectory = "$PSScriptRoot\src\functions"
$artifactScriptPath = "$PSScriptRoot\artifacts\"
$artifactPSScript = "$artifactScriptPath\init.ps1"
$artifactBashScript = "$artifactScriptPath\init.sh"
$compressedHeader = "# Compressed artifacts"
function Compress-ComponentScripts {
$scriptBlock = $compressedHeader
Write-Verbose $scriptBlock
$scriptBlock += "`r`n"
$scriptBlock += "`$dotnetzero = New-Object -TypeName PSObject"
if ($version) {
# Add version info
$version = "Version: $version"
Write-Host $version
$scriptBlock += "`r`n"
$scriptBlock += "`$dotnetzero | Add-Member -MemberType NoteProperty -Name components_version -Value `"$((Compress-String -StringContent $version))`""
}
if ($sha) {
# Add source code sha
$sha = "Sha: $sha"
Write-Host $sha
$scriptBlock += "`r`n"
$scriptBlock += "`$dotnetzero | Add-Member -MemberType NoteProperty -Name components_sha -Value `"$((Compress-String -StringContent $sha))`""
}
# Add licence encoded data
$scriptBlock += "`r`n"
$scriptBlock += "`$dotnetzero | Add-Member -MemberType NoteProperty -Name components_license -Value `"$((Compress-String -StringContent (Get-Content -Raw -Path "$PSScriptRoot\LICENSE")))`""
Get-ChildItem -Path $componentScriptDirectory -Recurse | `
Where-Object { ! $_.PSIsContainer } | `
ForEach-Object {
$variableName = "$($_.Directory.BaseName)_$($_.BaseName -replace "-", $null)"
$stringData = Get-Content -Raw -Path $_.FullName
$compressedData = Compress-String -StringContent $stringData
$scriptBlock += "`r`n"
$scriptBlock += "`$dotnetzero | Add-Member -MemberType NoteProperty -Name $($variableName) -Value `"$compressedData`""
}
return $scriptBlock | Set-BlankLine -Count 0
}
function Join-FunctionScripts {
$functionContent = "# Functions"
$functionContent += "`r`n"
Get-ChildItem -Path $functionScriptDirectory | Sort-Object FullName | ForEach-Object {
$functionContent += $(Get-Content -Raw -Path $_.FullName) | Set-BlankLine
}
return $functionContent
}
function New-CompiledScrpt {
if (Test-Path -Path $artifactScriptPath) {
Remove-Item -Force -Recurse -Path $artifactScriptPath
}
New-Item -ItemType Directory -Path $artifactScriptPath -Force | Out-Null
# Build the powershell script
Set-Content -Encoding Ascii -Path $artifactPSScript -Value $(Compress-ComponentScripts) -Force
Add-Content -Encoding Ascii -Path $artifactPSScript -Value (Join-FunctionScripts)
# Build the bash script
Set-Content -Encoding Ascii -Path $artifactBashScript -Value (Get-Content -Raw $sourceBashScript)
}
New-CompiledScrpt