forked from microsoft/MSLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
54 lines (45 loc) · 1.74 KB
/
build.ps1
File metadata and controls
54 lines (45 loc) · 1.74 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
param(
[Parameter(Mandatory = $true)]
[string]$Version
)
$baseDir = ".\Scripts\"
$outputDir = ".\Output"
$outputFile = "Release.zip"
[array]$ignoredFiles = "0_Shared.ps1"
if(Test-Path -Path $outputDir) {
Remove-Item -Path $outputDir -Recurse
}
$releaseDirectory = New-Item -ItemType "Directory" -Path ".\" -Name $outputDir
$files = Get-ChildItem -Path $baseDir
foreach($file in $files) {
if($file.Name -in $ignoredFiles) {
continue
}
$content = Get-Content -Path $file.FullName
$output = $content | ForEach-Object {
$line = $_
# inline include
if($line -match "^\s*\.\s+([^#]+)#\s\[!build-include-inline\]") {
$includeFile = $Matches[1]
if($includeFile.Contains("`$PSScriptRoot")) {
$includeFile = $includeFile.Replace("`$PSScriptRoot", ".")
}
if($includeFile.StartsWith(".\")) {
$includeFile = $includeFile.Substring(2)
}
$includeFile = Join-Path -Path $baseDir -ChildPath $includeFile
if(-not (Test-Path -Path $includeFile)) {
throw "Unable to include requested script ($includeFile)"
}
$line = Get-Content -Path $includeFile
}
# special variable populated with current version
if($line -match '^\s*\$wslabVersion') {
$line = $line -replace '\$wslabVersion\s*=\s*"[^"]*"', "`$wslabVersion = `"$Version`""
}
$line
}
$outFile = Join-Path -Path $releaseDirectory -ChildPath $file.Name
Set-Content -Path $outFile -Value $output
}
Compress-Archive -Path "$($releaseDirectory.FullName)\*" -DestinationPath $outputFile -CompressionLevel Optimal -Force