welsonjs/bootstrap.ps1
Namhyeon, Go 1530c8bff9 Add iex-compatible branch parsing
Remove the param block and rename DefaultBranch to $defaultBranch. Add argument parsing for iex-compatible invocations (e.g. `iex -dev main`, `iex main`, or no args) by inspecting $args and selecting the branch accordingly, then log the chosen branch. Simplify branch handling and build the GitHub ZIP download URL using the resolved branch. Small cleanup and reordering of steps to accommodate the new parsing logic.
2026-04-18 17:28:47 +09:00

117 lines
3.1 KiB
PowerShell

# WelsonJS One-Click Bootstrap (bootstrap.ps1)
# Copyright 2019-2025, Namhyeon Go <gnh1201@catswords.re.kr> and the WelsonJS contributors.
# SPDX-License-Identifier: GPL-3.0-or-later
# https://github.com/gnh1201/welsonjs
#
# Usage:
# irm https://catswords.blob.core.windows.net/welsonjs/bootstrap.ps1 | iex
# irm https://catswords.blob.core.windows.net/welsonjs/bootstrap.ps1 | iex -dev main
# irm https://catswords.blob.core.windows.net/welsonjs/bootstrap.ps1 | iex -dev dev
# irm https://catswords.blob.core.windows.net/welsonjs/bootstrap.ps1 | iex main
#
# Central default branch configuration for this install script.
# Update this value if the repository's default branch changes.
$defaultBranch = "master"
$ErrorActionPreference = "Stop"
function Write-Step($msg) {
Write-Host "[*] $msg" -ForegroundColor Cyan
}
function Write-Ok($msg) {
Write-Host "[+] $msg" -ForegroundColor Green
}
function Write-Err($msg) {
Write-Host "[!] $msg" -ForegroundColor Red
}
try {
# Step 0: Parse arguments (iex-compatible)
# Supports:
# iex -dev main
# iex main
# iex
$branch = $defaultBranch
for ($i = 0; $i -lt $args.Count; $i++) {
$arg = $args[$i]
if ($arg -eq "-dev" -and ($i + 1) -lt $args.Count) {
$branch = $args[$i + 1]
break
}
elseif ($arg -notmatch "^-") {
$branch = $arg
}
}
Write-Step "Using branch: $branch"
# Step 1: Create a temporary working directory using a UUID
Write-Step "Creating temporary workspace..."
$uuid = [guid]::NewGuid().ToString()
$tempDir = Join-Path $env:TEMP $uuid
New-Item -ItemType Directory -Path $tempDir | Out-Null
Write-Ok "Temp directory: $tempDir"
$repo = "gnh1201/welsonjs"
$zipPath = Join-Path $tempDir "package.zip"
# Step 2: Build download URL
$downloadUrl = "https://github.com/$repo/archive/refs/heads/$branch.zip"
Write-Ok "Download URL: $downloadUrl"
# Step 3: Download the ZIP package
Write-Step "Downloading package..."
irm $downloadUrl -OutFile $zipPath
Write-Ok "Downloaded: $zipPath"
# Step 4: Extract the ZIP archive
Write-Step "Extracting package..."
Expand-Archive -Path $zipPath -DestinationPath $tempDir
Write-Ok "Extraction completed"
# Step 5: Locate bootstrap.bat within extracted files
Write-Step "Locating bootstrap.bat..."
$bootstrap = Get-ChildItem -Path $tempDir -Recurse -Filter "bootstrap.bat" | Select-Object -First 1
if (-not $bootstrap) {
throw "bootstrap.bat not found"
}
Write-Ok "Found: $($bootstrap.FullName)"
# Step 6: Execute bootstrap.bat via cmd.exe for compatibility
Write-Step "Executing bootstrap..."
$proc = Start-Process -FilePath "cmd.exe" `
-ArgumentList "/c `"$($bootstrap.FullName)`"" `
-Wait -PassThru
if ($proc.ExitCode -ne 0) {
throw "bootstrap failed with exit code $($proc.ExitCode)"
}
Write-Ok "Bootstrap executed successfully"
# Step 7: Final message
Write-Host ""
Write-Host "WelsonJS installation completed!" -ForegroundColor Green
Write-Host ""
}
catch {
Write-Err $_
exit 1
}