-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.ps1
112 lines (98 loc) · 3.64 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
$files = Get-ChildItem $PSScriptRoot -Filter '*.cab';
$nugetTemplate = "$PSScriptRoot\Template.nuspec";
$webClient = New-Object System.Net.WebClient;
$cabRegex = [Regex] '"http[^"]*(?<version>Runtime.[0-9.]*)\.[^"]*\.cab"';
$webViewVersion = [Version] ('1.0');
$downloadManually = 0
$checkNugetVersion = 0
$publish = 0
if ($args -match "-FetchVersionFromNuget")
{
$checkNugetVersion = 1
}
# Download .cab files manually if no one in build directory
if ($files.Count -eq 0)
{
Write-Output "WebView2 .cab files not found, trying to download it automatically"
$downloadPage = $webClient.DownloadString("https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section");
$cabFiles = $cabRegex.Matches($downloadPage);
# First we need get all versions from page and find latest
foreach ($version in $cabFiles)
{
$v = $version.Groups[1].Value.Replace('Runtime.', '');
$vv = [Version] ($v);
if ($vv -gt $webViewVersion)
{
$webViewVersion = $vv;
}
}
Write-Output "Select version: $webViewVersion"
foreach ($file in $cabFiles)
{
$url = $file.Value.Replace('"', '');
$url = $url.Replace('\u002F', '/');
if (!$url.Contains($webViewVersion))
{
continue;
}
$fileName = [System.IO.Path]::GetFileName($url);
Write-Output "Package: $fileName"
if ($checkNugetVersion -eq 1)
{
Write-Output "Checking nuget version"
$name_split = $fileName.Split('.');
$arch = $name_split[$name_split.Length - 2].ToUpper();
$packageName = "WebView2.Runtime.$arch";
$nugetOutput = & "$PSScriptRoot\Utils\nuget.exe" "list" "$packageName";
$nugetPackagesInfo = $nugetOutput | Select-String -Pattern $packageName | Select-Object -Last 1;
$nugetVersion = $nugetPackagesInfo.ToString().Split(' ')[1];
Write-Output "Nuget version: $nugetVersion";
if ([Version] $nugetVersion -ge [Version] $webViewVersion)
{
Write-Output "Nuget version >= microsoft website version, skipping";
continue;
}
}
Write-Output "Downloading: $fileName"
$webClient.DownloadFile($url, "$PSScriptRoot\$fileName");
}
$downloadManually = 1
}
$files = Get-ChildItem $PSScriptRoot -Filter '*.cab';
foreach ($file in $files)
{
$name_split = $file.Name.Split('.');
$arch = $name_split[$name_split.Length - 2].ToUpper();
$output_path = "$PSScriptRoot\WebView2.Runtime.$arch";
$output_folder = "WebView2.Runtime.$arch";
# Remove exists directory
if (Test-Path $output_path) { Remove-Item $output_path -Recurse -Force; }
New-Item -ItemType Directory -Force -Path "$output_path\contentFiles\any\any\";
# Unpack cab
cmd.exe /c "$PSScriptRoot\Utils\expand.exe -F:* $($file.FullName) $output_path\contentFiles\any\any\";
# Now we need rename folder in content directory
Get-ChildItem "$output_path\contentFiles\any\any\" -Directory | Rename-Item -NewName "WebView2";
#Parse version from manifest
$version_file = Get-ChildItem "$output_path\contentFiles\" -Filter "*.manifest" -Recurse;
$webViewVersion = $version_file[0].Name.Replace(".manifest", "");
# Copy nuspec and replace vars
(Get-Content $nugetTemplate).Replace('%NAME%', $output_folder).Replace('%VERSION%', $webViewVersion) | Set-Content "$output_path\$output_folder.nuspec";
# Copy license file
Copy-Item "$PSScriptRoot\LICENSE.txt" -Destination "$output_path\LICENSE.txt";
# Compile nupkg
cmd.exe /c "$PSScriptRoot\Utils\nuget.exe pack $output_path\$output_folder.nuspec";
Remove-Item $output_path -Recurse -Force;
}
# Remove downloaded files
if ($downloadManually -eq 1)
{
foreach ($file in $files)
{
Remove-Item $file -Force;
}
}
$files = Get-ChildItem $PSScriptRoot -Filter "*$webViewVersion.nupkg";
if ($args -match "-Publish")
{
powershell.exe -File "$PSScriptRoot\publish.ps1";
}