22# Copyright 2019-2025, Namhyeon Go <gnh1201@catswords.re.kr> and the WelsonJS contributors.
33# SPDX-License-Identifier: GPL-3.0-or-later
44# https://github.com/gnh1201/welsonjs
5- #
5+ #
66# Usage:
7+ #
8+ # Quick start (no arguments):
79# irm https://catswords.blob.core.windows.net/welsonjs/bootstrap.ps1 | iex
8- # irm https://catswords.blob.core.windows.net/welsonjs/bootstrap.ps1 | iex -dev main
9- # irm https://catswords.blob.core.windows.net/welsonjs/bootstrap.ps1 | iex -dev dev
10- # irm https://catswords.blob.core.windows.net/welsonjs/bootstrap.ps1 | iex main
11- #
12- # Central default branch configuration for this install script.
13- # Update this value if the repository's default branch changes.
14- $defaultBranch = " master"
10+ #
11+ # With arguments (recommended):
12+ # irm https://catswords.blob.core.windows.net/welsonjs/bootstrap.ps1 -OutFile bootstrap.ps1
13+ # .\bootstrap.ps1 -dev main
14+ # .\bootstrap.ps1 -file test.js
1515
16+ $defaultBranch = " master"
1617$ErrorActionPreference = " Stop"
1718
1819function Write-Step ($msg ) {
@@ -29,27 +30,36 @@ function Write-Err($msg) {
2930
3031try {
3132 # Step 0: Parse arguments (iex-compatible)
32- # Supports:
33- # iex -dev main
34- # iex main
35- # iex
3633 $branch = $defaultBranch
34+ $fileArg = $null
3735
3836 for ($i = 0 ; $i -lt $args.Count ; $i ++ ) {
3937 $arg = $args [$i ]
4038
4139 if ($arg -eq " -dev" -and ($i + 1 ) -lt $args.Count ) {
4240 $branch = $args [$i + 1 ]
43- break
41+ $i ++
42+ }
43+ elseif ($arg -eq " -file" -and ($i + 1 ) -lt $args.Count ) {
44+ $fileArg = $args [$i + 1 ]
45+ $i ++
4446 }
4547 elseif ($arg -notmatch " ^-" ) {
4648 $branch = $arg
4749 }
4850 }
4951
52+ # Auto-append .js if no extension
53+ if ($fileArg -and -not ($fileArg -match " \." )) {
54+ $fileArg = " $fileArg .js"
55+ }
56+
5057 Write-Step " Using branch: $branch "
58+ if ($fileArg ) {
59+ Write-Step " File argument: $fileArg "
60+ }
5161
52- # Step 1: Create a temporary working directory using a UUID
62+ # Step 1: Create temporary workspace
5363 Write-Step " Creating temporary workspace..."
5464
5565 $uuid = [guid ]::NewGuid().ToString()
@@ -62,56 +72,65 @@ try {
6272 $repo = " gnh1201/welsonjs"
6373 $zipPath = Join-Path $tempDir " package.zip"
6474
65- # Step 2: Build download URL
75+ # Step 2: Download from branch
6676 $downloadUrl = " https://github.com/$repo /archive/refs/heads/$branch .zip"
6777
6878 Write-Ok " Download URL: $downloadUrl "
6979
70- # Step 3: Download the ZIP package
7180 Write-Step " Downloading package..."
72-
7381 irm $downloadUrl - OutFile $zipPath
74-
7582 Write-Ok " Downloaded: $zipPath "
7683
77- # Step 4 : Extract the ZIP archive
84+ # Step 3 : Extract
7885 Write-Step " Extracting package..."
79-
8086 Expand-Archive - Path $zipPath - DestinationPath $tempDir
81-
8287 Write-Ok " Extraction completed"
8388
84- # Step 5: Locate bootstrap.bat within extracted files
85- Write-Step " Locating bootstrap.bat..."
89+ if ($fileArg ) {
90+ # Step 4A: Run cscript via cmd (with visible console)
91+ Write-Step " Locating app.js..."
8692
87- $bootstrap = Get-ChildItem - Path $tempDir - Recurse - Filter " bootstrap.bat " | Select-Object - First 1
93+ $app = Get-ChildItem - Path $tempDir - Recurse - Filter " app.js " | Select-Object - First 1
8894
89- if (-not $bootstrap ) {
90- throw " bootstrap.bat not found"
91- }
95+ if (-not $app ) {
96+ throw " app.js not found"
97+ }
9298
93- Write-Ok " Found: $ ( $bootstrap .FullName ) "
99+ Write-Ok " Found: $ ( $app .FullName ) "
94100
95- # Step 6: Execute bootstrap.bat via cmd.exe for compatibility
96- Write-Step " Executing bootstrap..."
101+ Write-Step " Executing via cscript (interactive)..."
97102
98- $proc = Start-Process - FilePath " cmd.exe" `
99- - ArgumentList " /c `" $ ( $bootstrap.FullName ) `" " `
100- - Wait - PassThru
103+ Start-Process " cmd.exe" `
104+ - ArgumentList " /k cscript `" $ ( $app.FullName ) `" `" $fileArg `" "
101105
102- if ($proc.ExitCode -ne 0 ) {
103- throw " bootstrap failed with exit code $ ( $proc.ExitCode ) "
106+ Write-Ok " cscript launched (interactive console)"
104107 }
108+ else {
109+ # Step 4B: Default bootstrap (non-blocking)
110+ Write-Step " Locating bootstrap.bat..."
111+
112+ $bootstrap = Get-ChildItem - Path $tempDir - Recurse - Filter " bootstrap.bat" | Select-Object - First 1
113+
114+ if (-not $bootstrap ) {
115+ throw " bootstrap.bat not found"
116+ }
105117
106- Write-Ok " Bootstrap executed successfully"
118+ Write-Ok " Found: $ ( $bootstrap.FullName ) "
119+
120+ Write-Step " Executing bootstrap (non-blocking)..."
121+
122+ Start-Process " cmd.exe" `
123+ - ArgumentList " /c `" $ ( $bootstrap.FullName ) `" "
124+
125+ Write-Ok " Bootstrap launched"
126+ }
107127
108- # Step 7: Final message
109128 Write-Host " "
110- Write-Host " WelsonJS installation completed !" - ForegroundColor Green
129+ Write-Host " WelsonJS execution started !" - ForegroundColor Green
111130 Write-Host " "
112131
113132}
114133catch {
115134 Write-Err $_
116135 exit 1
117- }
136+ }
0 commit comments