fix error and new docs
This commit is contained in:
@@ -45,6 +45,44 @@ function Write-Fail([string]$text) {
|
||||
Write-Host " [!!] $text" -ForegroundColor Red
|
||||
}
|
||||
|
||||
$FfmpegStaticMirror = 'https://cdn.npmmirror.com/binaries/ffmpeg-static'
|
||||
|
||||
function Test-IsNpmCi([string[]]$NpmArgs) {
|
||||
return ($NpmArgs.Count -eq 1 -and $NpmArgs[0] -eq 'ci')
|
||||
}
|
||||
|
||||
function Invoke-NpmRaw {
|
||||
param(
|
||||
[string[]]$NpmArgs,
|
||||
[string]$WorkingDirectory
|
||||
)
|
||||
Push-Location $WorkingDirectory
|
||||
try {
|
||||
& npm @NpmArgs
|
||||
return $LASTEXITCODE
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-NpmCiWithFfmpegMirror {
|
||||
param(
|
||||
[string]$WorkingDirectory
|
||||
)
|
||||
$prevMirror = $env:FFMPEG_BINARIES_URL
|
||||
$env:FFMPEG_BINARIES_URL = $FfmpegStaticMirror
|
||||
try {
|
||||
Write-Host " > npm ci (retry with FFMPEG_BINARIES_URL=$FfmpegStaticMirror)"
|
||||
return (Invoke-NpmRaw -NpmArgs @('ci') -WorkingDirectory $WorkingDirectory)
|
||||
} finally {
|
||||
if ($null -eq $prevMirror) {
|
||||
Remove-Item Env:\FFMPEG_BINARIES_URL -ErrorAction SilentlyContinue
|
||||
} else {
|
||||
$env:FFMPEG_BINARIES_URL = $prevMirror
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-Npm {
|
||||
param(
|
||||
[string]$Label,
|
||||
@@ -52,14 +90,13 @@ function Invoke-Npm {
|
||||
[string]$WorkingDirectory
|
||||
)
|
||||
Write-Host " > $Label"
|
||||
Push-Location $WorkingDirectory
|
||||
try {
|
||||
& npm @NpmArgs
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "$Label failed (exit $LASTEXITCODE)"
|
||||
}
|
||||
} finally {
|
||||
Pop-Location
|
||||
$exitCode = Invoke-NpmRaw -NpmArgs $NpmArgs -WorkingDirectory $WorkingDirectory
|
||||
if ($exitCode -ne 0 -and (Test-IsNpmCi $NpmArgs)) {
|
||||
Write-Host " [--] npm ci failed (exit $exitCode). Retrying via ffmpeg-static mirror..." -ForegroundColor Yellow
|
||||
$exitCode = Invoke-NpmCiWithFfmpegMirror $WorkingDirectory
|
||||
}
|
||||
if ($exitCode -ne 0) {
|
||||
throw "$Label failed (exit $exitCode)"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user