-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake.ps1
More file actions
83 lines (65 loc) · 1.9 KB
/
make.ps1
File metadata and controls
83 lines (65 loc) · 1.9 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
76
77
78
79
80
81
82
83
#!/usr/bin/env pwsh
param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$CommandArgs
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function Remove-ProviderPrefix {
param([string]$PathValue)
if ($null -eq $PathValue) {
return ''
}
return ($PathValue -replace '^Microsoft\.PowerShell\.Core\\FileSystem::', '')
}
function Quote-BashArg {
param([string]$Value)
if ($null -eq $Value -or $Value.Length -eq 0) {
return "''"
}
return "'" + ($Value -replace "'", "'\"'\"'") + "'"
}
$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$scriptRoot = Remove-ProviderPrefix $scriptRoot
$indexScript = Join-Path $scriptRoot 'scripts/index.js'
if (-not (Test-Path -LiteralPath $indexScript)) {
Write-Error "Cannot find script entry point: $indexScript"
}
$uncPattern = '^\\\\(?:wsl\.localhost|wsl\$)\\([^\\]+)\\(.+)$'
$wslMatch = [regex]::Match($scriptRoot, $uncPattern)
if ($wslMatch.Success) {
if (-not (Get-Command wsl.exe -ErrorAction SilentlyContinue)) {
Write-Error 'wsl.exe was not found. Install/enable WSL or run from a local Windows path.'
}
$distro = $wslMatch.Groups[1].Value
$distroPath = $wslMatch.Groups[2].Value
$linuxRoot = '/' + ($distroPath -replace '\\', '/')
$bashCommandParts = @(
'cd',
(Quote-BashArg $linuxRoot),
'&&',
'node',
'scripts/index.js'
)
foreach ($arg in $CommandArgs) {
$bashCommandParts += (Quote-BashArg $arg)
}
$bashCommand = $bashCommandParts -join ' '
& wsl.exe -d $distro -- bash -lc $bashCommand
$exitCode = $LASTEXITCODE
} else {
if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
Write-Error 'Node.js is required but was not found in PATH.'
}
Push-Location -LiteralPath $scriptRoot
try {
& node $indexScript @CommandArgs
$exitCode = $LASTEXITCODE
} finally {
Pop-Location
}
}
if ($null -eq $exitCode) {
$exitCode = 0
}
exit $exitCode