-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage-platform.ps1
More file actions
75 lines (69 loc) · 3.19 KB
/
Copy pathpackage-platform.ps1
File metadata and controls
75 lines (69 loc) · 3.19 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
[CmdletBinding()]
param(
[string]$OutputRoot,
[ValidateSet('Windows', 'macOS', 'WSL2')]
[string[]]$Platforms = @('Windows', 'macOS', 'WSL2')
)
$ErrorActionPreference = 'Stop'
$sourceRoot = $PSScriptRoot
if ([string]::IsNullOrWhiteSpace($OutputRoot)) {
$OutputRoot = Join-Path $sourceRoot 'dist'
}
$version = (Get-Content -LiteralPath (Join-Path $sourceRoot 'package.json') -Raw | ConvertFrom-Json).version
function Copy-RuntimeFiles {
param([Parameter(Mandatory)][string]$Stage)
Copy-Item -LiteralPath (Join-Path $sourceRoot 'ccm.js') -Destination (Join-Path $Stage 'ccm.js') -Force
Copy-Item -LiteralPath (Join-Path $sourceRoot 'package.json') -Destination (Join-Path $Stage 'package.json') -Force
Copy-Item -LiteralPath (Join-Path $sourceRoot 'lib') -Destination (Join-Path $Stage 'lib') -Recurse -Force
foreach ($document in @('LICENSE', 'CHANGELOG.md')) {
$documentPath = Join-Path $sourceRoot $document
if (Test-Path -LiteralPath $documentPath) {
Copy-Item -LiteralPath $documentPath -Destination (Join-Path $Stage $document) -Force
}
}
}
function New-PlatformPackage {
param(
[Parameter(Mandatory)][string]$Name,
[Parameter(Mandatory)][string]$Readme,
[Parameter(Mandatory)][scriptblock]$AddInstaller
)
$stage = Join-Path $env:TEMP ("ccm-package-$Name-" + [guid]::NewGuid().ToString('N'))
$archive = Join-Path $OutputRoot ("CCM-$Name-v$version.zip")
if (Test-Path -LiteralPath $archive) {
throw "Refusing to overwrite existing archive: $archive"
}
New-Item -ItemType Directory -Path $stage | Out-Null
try {
Copy-RuntimeFiles -Stage $stage
Copy-Item -LiteralPath (Join-Path $sourceRoot $Readme) -Destination (Join-Path $stage 'README.md') -Force
& $AddInstaller $stage
$entries = Get-ChildItem -LiteralPath $stage -Force | Select-Object -ExpandProperty Name
tar.exe -a -c -f $archive -C $stage @entries
Get-FileHash -LiteralPath $archive -Algorithm SHA256 | Select-Object @{Name='Package';Expression={$Name}},Algorithm,Hash,Path
} finally {
if (Test-Path -LiteralPath $stage) {
Remove-Item -LiteralPath $stage -Recurse -Force
}
}
}
New-Item -ItemType Directory -Force -Path $OutputRoot | Out-Null
if ($Platforms -contains 'Windows') {
New-PlatformPackage -Name 'Windows' -Readme 'README.windows.md' -AddInstaller {
param($stage)
Copy-Item -LiteralPath (Join-Path $sourceRoot 'install.ps1') -Destination (Join-Path $stage 'install.ps1') -Force
Copy-Item -LiteralPath (Join-Path $sourceRoot 'Install-CCM.cmd') -Destination (Join-Path $stage 'Install-CCM.cmd') -Force
}
}
if ($Platforms -contains 'macOS') {
New-PlatformPackage -Name 'macOS' -Readme 'README.macos.md' -AddInstaller {
param($stage)
Copy-Item -LiteralPath (Join-Path $sourceRoot 'install.sh') -Destination (Join-Path $stage 'install.sh') -Force
}
}
if ($Platforms -contains 'WSL2') {
New-PlatformPackage -Name 'WSL2' -Readme 'README.wsl2.md' -AddInstaller {
param($stage)
Copy-Item -LiteralPath (Join-Path $sourceRoot 'install.sh') -Destination (Join-Path $stage 'install.sh') -Force
}
}