forked from dsx42/UnattendTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
76 lines (59 loc) · 2.14 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
Clear-Host
Set-Location -Path $PSScriptRoot
$ProductJsonPath = "$PSScriptRoot\product.json"
if (!(Test-Path -Path $ProductJsonPath -PathType Leaf)) {
Write-Warning -Message ("$ProductJsonPath 不存在")
[System.Environment]::Exit(0)
}
$ProductInfo = $null
try {
$ProductInfo = Get-Content -Path $ProductJsonPath | ConvertFrom-Json
}
catch {
Write-Warning -Message ("$ProductJsonPath 解析失败")
[System.Environment]::Exit(0)
}
if (!$ProductInfo -or $ProductInfo -isNot [PSCustomObject]) {
Write-Warning -Message ("$ProductJsonPath 解析失败")
[System.Environment]::Exit(0)
}
$Version = $ProductInfo.'version'
if (!$Version) {
Write-Warning -Message ("$ProductJsonPath 不存在 version 信息")
[System.Environment]::Exit(0)
}
$ProjectName = $ProductInfo.'name'
if (!$ProjectName) {
Write-Warning -Message ("$ProductJsonPath 不存在 name 信息")
[System.Environment]::Exit(0)
}
$Files = $ProductInfo.'files'
if (!$Files -or $Files -isNot [System.Array] -or $Files.Count -le 0) {
Write-Warning -Message ("$ProductJsonPath 不存在 files 信息")
[System.Environment]::Exit(0)
}
$CopyFiles = @()
foreach ($File in $Files) {
$CopyFiles += "$PSScriptRoot\$File"
}
$Output = 'target'
$OutputPath = "$PSScriptRoot\$Output"
$OutputProjectPath = "$OutputPath\${ProjectName}"
$OutputFileName = "${ProjectName}_v$Version"
$ZipFilePath = "$OutputPath\$OutputFileName.zip"
$Sha256FilePath = "$OutputPath\$OutputFileName.sha256"
if (Test-Path -Path $OutputPath -PathType Container) {
Remove-Item -Path $OutputPath -Recurse -Force
}
New-Item -Path $OutputProjectPath -ItemType Directory -Force | Out-Null
Copy-Item -Path $CopyFiles -Destination $OutputProjectPath -Force -Recurse
Compress-Archive -Path $OutputProjectPath -DestinationPath $ZipFilePath -Force
$Hash = Get-FileHash -Path $ZipFilePath -Algorithm SHA256
$Checksum = $Hash.Hash + " $OutputFileName.zip"
Add-Content -Path $Sha256FilePath -Value $Checksum
Write-Host -Object ''
Write-Host -Object ('Path: ' + $Hash.Path)
Write-Host -Object ''
Write-Host -Object ('SHA256: ' + $Hash.Hash)
Write-Host -Object ''
Read-Host -Prompt '按回车键关闭此窗口'