@@ -7,11 +7,34 @@ $APP_NAME = @{
77$INSTALL_DIR = " C:\$ ( $APP_NAME.CASED ) "
88$EXE_PATH = Join-Path - Path $INSTALL_DIR - ChildPath " $ ( $APP_NAME.CLI ) .exe"
99
10- Function Remove-IfNeeded () {
11- if ($null -ne $args [0 ] -as [double ]) {
12- Stop-Process - Id $args [0 ] - Force
10+ # DETACH PROCESS
11+ if ($args [1 ] -ne " NA" ) {
12+ # powershell path (pwsh on PS Core, powershell on Windows PS)
13+ $exe = if ($PSVersionTable.PSEdition -eq " Core" ) { " pwsh" } else { " powershell" }
14+ $script = $PSCommandPath
15+
16+ Start-Process - FilePath $exe - ArgumentList " -NoProfile -ExecutionPolicy Bypass -File `" $script `" _ NA"
17+ # quit parent
18+ exit
19+ }
20+
21+ Start-Sleep - Seconds 1
22+ Write-Output " (Check... DETACHED $PID )"
23+
24+ Function Remove-IfNeeded {
25+ if ($args.Count -eq 1 ) {
26+ $procId = $args [0 ] -as [int ]
27+ }
28+ else {
29+ $proc = Get-Process - Name $APP_NAME.CLI - ErrorAction SilentlyContinue | Select-Object - First 1
30+ if ($proc ) { $procId = $proc.Id }
31+ }
32+
33+ if ($procId ) {
34+ Write-Output " FuckingNode found to be running. Removing existing install (PID $procId ) for updating."
35+ Stop-Process - Id $procId - Force
1336 Remove-Item $EXE_PATH - Force
14- }
37+ }
1538}
1639
1740# get latest release URL
@@ -49,7 +72,7 @@ Function Get-LatestReleaseUrl {
4972# creates a .bat shortcut to allow for fknode to exist alongside fuckingnode in the CLI
5073Function New-Shortcuts {
5174 try {
52- Write-Host " Creating shortcuts for CLI..."
75+ Write-Output " Creating shortcuts for CLI..."
5376
5477 # all aliases should be
5578 # (appName).exe <a command> [ANY ARGS PASSED]
@@ -86,7 +109,7 @@ Function New-Shortcuts {
86109 $batContent = " @echo off`n %~dp0$ ( $appName ) .exe $cmd %*"
87110 $batPath = Join-Path - Path $INSTALL_DIR - ChildPath " $name .bat"
88111 Set-Content - Path $batPath - Value $batContent - Encoding ASCII
89- Write-Host " Shortcut created successfully at $batPath "
112+ Write-Output " Shortcut created successfully at $batPath "
90113 }
91114 }
92115 catch {
@@ -101,17 +124,17 @@ Function Install-App {
101124 [string ]$url
102125 )
103126 try {
104- Write-Host " Downloading from $url ..."
127+ Write-Output " Downloading from $url ..."
105128
106129 if (-not (Test-Path $INSTALL_DIR )) {
107130 New-Item - ItemType Directory - Path $INSTALL_DIR | Out-Null
108131 }
109132
110133 Invoke-WebRequest - Uri $url - OutFile $EXE_PATH
111- Write-Host " Downloaded successfully to $EXE_PATH "
134+ Write-Output " Downloaded successfully to $EXE_PATH "
112135 }
113136 catch {
114- Throw " Failed to download or save the file : $_ "
137+ Throw " Failed to download fuckingnode.exe : $_ "
115138 }
116139}
117140
@@ -176,7 +199,7 @@ function Get-Env {
176199# Function: Add App to PATH
177200Function Add-AppToPath {
178201 try {
179- Write-Host " Adding shorthand to PATH..."
202+ Write-Output " Adding shorthand to PATH..."
180203
181204 if ([string ]::IsNullOrWhiteSpace($INSTALL_DIR )) {
182205 Throw " Install DIR is undefined or empty."
@@ -189,10 +212,10 @@ Function Add-AppToPath {
189212 $Path += $INSTALL_DIR
190213 Write-Env - Key ' Path' - Value ($Path -join ' ;' )
191214 $env: PATH = $Path -join ' ;'
192- Write-Host " Added $INSTALL_DIR to PATH"
215+ Write-Output " Added $INSTALL_DIR to PATH"
193216 }
194217 else {
195- Write-Host " '${INSTALL_DIR} ' is already in your PATH."
218+ Write-Output " '${INSTALL_DIR} ' is already in your PATH."
196219 }
197220 }
198221 catch {
@@ -203,23 +226,23 @@ Function Add-AppToPath {
203226
204227Function Installer {
205228 try {
206- Write-Host " Hi! We'll install $ ( $APP_NAME.CASED ) for you. Just a sec!"
229+ Write-Output " Hi! We'll install $ ( $APP_NAME.CASED ) for you. Just a sec!"
207230 Remove-IfNeeded
208231 Install-App - url (Get-LatestReleaseUrl )
209232 Add-AppToPath
210- Write-Host " You may have seen our documentation mention shortcuts like 'fknode', 'fkn', 'fkclean'..."
211- Write-Host " These are made by creating a bunch of scripts (fknode.bat, fkn.bat...) next to the main installation."
212- Write-Host " We highly recommend them, but JUST IN CASE they conflicted with any other local command, we let you choose."
233+ Write-Output " You may have seen our documentation mention shortcuts like 'fknode', 'fkn', 'fkclean'..."
234+ Write-Output " These are made by creating a bunch of scripts (fknode.bat, fkn.bat...) next to the main installation."
235+ Write-Output " We highly recommend them, but JUST IN CASE they conflicted with any other local command, we let you choose."
213236
214237 $response = Read-Host " Do you wish to create these shortcuts? [Y/N]"
215238
216239 if ($response -match ' ^[Yy]$' ) {
217240 New-Shortcuts
218241 }
219242 else {
220- Write-Host " Okay, we WON'T create shortcuts. Beware, as documentation and help menus might still use them to refer to commands."
243+ Write-Output " Okay, we WON'T create shortcuts. Beware, as documentation and help menus might still use them to refer to commands."
221244 }
222- Write-Host " Installed successfully! Restart your terminal for it to work."
245+ Write-Output " Installed successfully! Restart your terminal for it to work."
223246 }
224247 catch {
225248 Write-Error $_
0 commit comments