-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathbootstrap.ps1
More file actions
136 lines (103 loc) · 3.55 KB
/
bootstrap.ps1
File metadata and controls
136 lines (103 loc) · 3.55 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# 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:
#
# Quick start (no arguments):
# irm https://catswords.blob.core.windows.net/welsonjs/bootstrap.ps1 | iex
#
# With arguments (recommended):
# irm https://catswords.blob.core.windows.net/welsonjs/bootstrap.ps1 -OutFile bootstrap.ps1
# .\bootstrap.ps1 -dev main
# .\bootstrap.ps1 -file test.js
$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)
$branch = $defaultBranch
$fileArg = $null
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]
$i++
}
elseif ($arg -eq "-file" -and ($i + 1) -lt $args.Count) {
$fileArg = $args[$i + 1]
$i++
}
elseif ($arg -notmatch "^-") {
$branch = $arg
}
}
# Auto-append .js if no extension
if ($fileArg -and -not ($fileArg -match "\.")) {
$fileArg = "$fileArg.js"
}
Write-Step "Using branch: $branch"
if ($fileArg) {
Write-Step "File argument: $fileArg"
}
# Step 1: Create temporary workspace
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: Download from branch
$downloadUrl = "https://github.com/$repo/archive/refs/heads/$branch.zip"
Write-Ok "Download URL: $downloadUrl"
Write-Step "Downloading package..."
irm $downloadUrl -OutFile $zipPath
Write-Ok "Downloaded: $zipPath"
# Step 3: Extract
Write-Step "Extracting package..."
Expand-Archive -Path $zipPath -DestinationPath $tempDir
Write-Ok "Extraction completed"
if ($fileArg) {
# Step 4A: Run cscript via cmd (with visible console)
Write-Step "Locating app.js..."
$app = Get-ChildItem -Path $tempDir -Recurse -Filter "app.js" | Select-Object -First 1
if (-not $app) {
throw "app.js not found"
}
Write-Ok "Found: $($app.FullName)"
Write-Step "Executing via cscript (interactive)..."
Start-Process "cmd.exe" `
-ArgumentList "/k cscript `"$($app.FullName)`" `"$fileArg`""
Write-Ok "cscript launched (interactive console)"
}
else {
# Step 4B: Default bootstrap (non-blocking)
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)"
Write-Step "Executing bootstrap (non-blocking)..."
Start-Process "cmd.exe" `
-ArgumentList "/c `"$($bootstrap.FullName)`""
Write-Ok "Bootstrap launched"
}
Write-Host ""
Write-Host "WelsonJS execution started!" -ForegroundColor Green
Write-Host ""
}
catch {
Write-Err $_
exit 1
}