-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
99 lines (89 loc) · 3.89 KB
/
install.ps1
File metadata and controls
99 lines (89 loc) · 3.89 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
function Print-Banner {
@"
██████╗ ██╗ ██╗███╗ ███╗███████╗╔██████╗██╗ ██╗
██╔══██╗██║ ██║████╗ ████║██╔══██║║██╔═══╝██║ ██║
██║ ██║██║ ██║██╔████╔██║███████║║██║ ██║ ██║
██║ ██║██║ ██║██║╚██╔╝██║██╔══██║║██║ ██║ ██║
██████╔╝╚██████╔╝██║ ╚═╝ ██║███████║╚██████╗███████╗██║
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝╚══════╝╚═╝
"@ | Write-Host -ForegroundColor Cyan
Write-Host ' The "Dumb" Way to Manage Smart Commands'
Write-Host ""
}
Print-Banner
Write-Host "DumbCLI Installer"
Write-Host "Preparing to install or update DumbCLI...`n"
# 🖥️ OS detection (intelligent display)
$osInfo = Get-CimInstance Win32_OperatingSystem
$osCaption = $osInfo.Caption
$osVersion = $osInfo.Version
Write-Host "Detected OS: $osCaption ($osVersion)"
# 🧪 Check requirements
$requirements = @("git", "node", "npm")
foreach ($req in $requirements) {
if (-not (Get-Command $req -ErrorAction SilentlyContinue)) {
Write-Error "Error: $req is not installed. Please install it first."
exit
}
}
# ⚠️ Node.js version check
$nodeVersion = (node -v).TrimStart("v")
$maxVersion = "23.9.0"
if ($nodeVersion -gt $maxVersion) {
Write-Warning "Warning: Node.js v$nodeVersion may be too new. Use v$maxVersion or below."
}
# 📁 Install or Update (permanent install dir)
$installDir = Join-Path $env:LOCALAPPDATA "DumbCLI"
Write-Host "Install directory: $installDir"
if (-not (Test-Path $installDir)) {
New-Item -ItemType Directory -Path $installDir | Out-Null
}
if (Test-Path (Join-Path $installDir ".git")) {
Write-Host "Update detected. Pulling latest changes..."
Set-Location $installDir
$gitStatus = git status --porcelain --untracked-files=no
if ($gitStatus) {
if ($gitStatus -eq " M package-lock.json") {
Write-Host "Note: package-lock.json has local changes. Resetting it for update..."
git checkout -- package-lock.json
} else {
Write-Warning "Error: Local changes found in $installDir. Please commit or stash before updating."
git status --porcelain
exit 1
}
}
git pull --ff-only origin main
Write-Host "Updating dependencies..."
} else {
$hasFiles = Get-ChildItem -LiteralPath $installDir -Force | Where-Object { $_.Name -notin @(".", "..") }
if ($hasFiles) {
Write-Warning "Error: $installDir is not empty and not a git repo."
Write-Host "Please delete it or move its contents, then re-run the installer."
exit 1
}
Write-Host "First-time install. Cloning DumbCLI into $installDir..."
git clone https://github.com/S488U/dumbcli.git $installDir
Set-Location $installDir
Write-Host "Installing dependencies..."
}
# 📦 NPM install
npm install
# 🔗 Global link (auto-fix old global link if needed)
Write-Host "Linking DumbCLI globally..."
$existingDumb = Get-Command dumb -ErrorAction SilentlyContinue
if ($existingDumb -and $existingDumb.Source) {
$resolvedDumb = $existingDumb.Source
if ($resolvedDumb -notlike "$installDir*") {
Write-Host "Found existing global 'dumb' at $resolvedDumb"
Write-Host "Removing old link..."
npm unlink -g cli 2>$null
npm unlink -g dumbcli 2>$null
}
}
npm link
# ✅ Done
Write-Host ""
Write-Host "Done. DumbCLI is ready to use."
Write-Host "Run: dumb (or: d)"
Write-Host "Docs & GitHub: https://github.com/S488U/dumbcli"
Write-Host ""