-
Notifications
You must be signed in to change notification settings - Fork 165
/
metadata.ps1
68 lines (55 loc) · 2.36 KB
/
metadata.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
param(
[string] $Architecture = "x64",
[string] $Version = "1.0.0",
[switch] $Dev
)
$ErrorActionPreference = "Stop";
$build = "build";
$starward = "$build/Starward";
if ($Dev) {
$metadata = "$build/metadata/dev";
$package = "$build/release/package/dev";
$separate = "$build/release/separate_files/dev";
}
else {
$metadata = "$build/metadata/v1";
$package = "$build/release/package";
$separate = "$build/release/separate_files";
}
$null = New-Item -Path $package -ItemType Directory -Force;
$null = New-Item -Path $separate -ItemType Directory -Force;
$null = New-Item -Path $metadata -ItemType Directory -Force;
if (!(Get-Module -Name 7Zip4Powershell -ListAvailable)) {
Install-Module -Name 7Zip4Powershell -Force;
}
$portableName = "Starward_Portable_$($Version)_$($Architecture).7z";
$portableFile = "$package/$portableName";
if (!(Test-Path $portableFile)) {
Compress-7Zip -ArchiveFileName $portableName -Path $starward -OutputPath $package -CompressionLevel Ultra -PreserveDirectoryRoot;
}
$release = @{
Version = $Version
Architecture = $Architecture
BuildTime = Get-Date
DisableAutoUpdate = $false
Install = $null
InstallSize = 0
InstallHash = $null
Portable = "https://starward.scighost.com/release/package/$portableName"
PortableSize = (Get-Item $portableFile).Length
PortableHash = (Get-FileHash $portableFile).Hash
SeparatePrefix = "https://starward.scighost.com/release/separate_files/"
};
if ($Dev) {
$release.Portable = "https://starward.scighost.com/release/package/dev/$portableName";
$release.SeparatePrefix = "https://starward.scighost.com/release/separate_files/dev/";
}
Out-File -Path "$metadata/version_preview_$Architecture.json" -InputObject (ConvertTo-Json $release);
$path = @{l = "Path"; e = { [System.IO.Path]::GetRelativePath($starward, $_.FullName) } };
$size = @{l = "Size"; e = { $_.Length } };
$hash = @{l = "Hash"; e = { (Get-FileHash $_).Hash } };
$release.SeparateFiles = Get-ChildItem -Path $starward -File -Recurse | Select-Object -Property $path, $size, $hash;
Out-File -Path "$metadata/release_preview_$Architecture.json" -InputObject (ConvertTo-Json $release);
foreach ($file in $release.SeparateFiles) {
Move-Item -Path "$starward/$($file.Path)" -Destination "$separate/$($file.Hash)" -Force;
}