npm 없으면 설치
This commit is contained in:
1 parent
51cfb95b81
commit
eb52bbd9d3
2 files changed
+76
-1
No files matched your search
+31
-1
@@ -79,7 +79,37 @@ function ErrExit { Write-Host "[ERROR] $args" -ForegroundColor Red; exit 1 }
|
|||||||
Info "Platform: $([System.Environment]::OSVersion.Platform) ($([System.Environment]::GetEnvironmentVariable('PROCESSOR_ARCHITECTURE')))"
|
Info "Platform: $([System.Environment]::OSVersion.Platform) ($([System.Environment]::GetEnvironmentVariable('PROCESSOR_ARCHITECTURE')))"
|
||||||
|
|
||||||
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
|
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
|
||||||
ErrExit "npm is required. Install Node.js 18+: https://nodejs.org/"
|
Info "npm is not installed. Installing Node.js (includes npm) via winget..."
|
||||||
|
|
||||||
|
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
|
||||||
|
ErrExit "Neither npm nor winget is available. Install Node.js 18+ manually: https://nodejs.org/"
|
||||||
|
}
|
||||||
|
|
||||||
|
winget install --id OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements 2>&1 | Out-Null
|
||||||
|
|
||||||
|
# Refresh PATH and verify npm is now available
|
||||||
|
$env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'User') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
|
||||||
|
|
||||||
|
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
|
||||||
|
# Search common Node.js install paths
|
||||||
|
$nodePaths = @(
|
||||||
|
(Join-Path $env:ProgramFiles 'nodejs'),
|
||||||
|
(Join-Path $env:ProgramFiles(x86) 'nodejs'),
|
||||||
|
(Join-Path $env:LOCALAPPDATA 'Programs\nodejs')
|
||||||
|
)
|
||||||
|
foreach ($np in $nodePaths) {
|
||||||
|
if ((Test-Path $np) -and ($env:Path -notlike "*$np*")) {
|
||||||
|
$env:Path = "$np;$env:Path"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
|
||||||
|
ErrExit "Node.js installation completed but npm not found. Please restart your terminal and run this script again."
|
||||||
|
}
|
||||||
|
|
||||||
|
Success "Node.js installed via winget"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ────────────────────────────────────────────
|
# ────────────────────────────────────────────
|
||||||
|
|||||||
@@ -58,6 +58,51 @@ for cmd in curl; do
|
|||||||
command -v "$cmd" &>/dev/null || error "'$cmd' is required."
|
command -v "$cmd" &>/dev/null || error "'$cmd' is required."
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Check for Node.js (npm) — install if missing
|
||||||
|
if ! command -v npm &>/dev/null; then
|
||||||
|
info "npm is not installed. Installing Node.js..."
|
||||||
|
case "$OS" in
|
||||||
|
Darwin)
|
||||||
|
if command -v brew &>/dev/null; then
|
||||||
|
brew install node
|
||||||
|
success "Node.js installed via Homebrew"
|
||||||
|
else
|
||||||
|
error "Homebrew (brew) is required to install Node.js on macOS. Install it from https://brew.sh/"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
Linux)
|
||||||
|
if command -v apt-get &>/dev/null; then
|
||||||
|
sudo apt-get update -y && sudo apt-get install -y nodejs npm
|
||||||
|
success "Node.js installed via apt-get"
|
||||||
|
elif command -v dnf &>/dev/null; then
|
||||||
|
sudo dnf install -y nodejs
|
||||||
|
success "Node.js installed via dnf"
|
||||||
|
elif command -v yum &>/dev/null; then
|
||||||
|
sudo yum install -y nodejs
|
||||||
|
success "Node.js installed via yum"
|
||||||
|
elif command -v zypper &>/dev/null; then
|
||||||
|
sudo zypper -n install nodejs npm
|
||||||
|
success "Node.js installed via zypper"
|
||||||
|
elif command -v pacman &>/dev/null; then
|
||||||
|
sudo pacman -S --noconfirm nodejs npm
|
||||||
|
success "Node.js installed via pacman"
|
||||||
|
else
|
||||||
|
error "No supported package manager found. Install Node.js 18+ manually: https://nodejs.org/"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
error "Cannot auto-install Node.js on this OS. Install Node.js 18+ manually: https://nodejs.org/"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Verify npm is now available
|
||||||
|
if ! command -v npm &>/dev/null; then
|
||||||
|
error "Node.js installation completed but npm not found. Install Node.js 18+ manually: https://nodejs.org/"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "npm is available: $(command -v npm)"
|
||||||
|
|
||||||
# ────────────────────────────────────────────
|
# ────────────────────────────────────────────
|
||||||
# Detect OS / Architecture
|
# Detect OS / Architecture
|
||||||
# ────────────────────────────────────────────
|
# ────────────────────────────────────────────
|
||||||
|
|||||||
Reference in new issue
Block a user