add deno for Windows 10
authorAJ ONeal <aj@therootcompany.com>
Mon, 13 Jul 2020 20:18:01 +0000 (20:18 +0000)
committerAJ ONeal <aj@therootcompany.com>
Mon, 13 Jul 2020 20:23:14 +0000 (20:23 +0000)
deno/install.ps1 [new file with mode: 0644]

diff --git a/deno/install.ps1 b/deno/install.ps1
new file mode 100644 (file)
index 0000000..46c7669
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/bin/env pwsh
+
+# Fetch archive
+IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"))
+{
+    # TODO: arch detection
+    echo "Downloading $Env:PKG_NAME from $Env:WEBI_PKG_URL to $Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+    #Invoke-WebRequest https://nodejs.org/dist/v12.16.2/node-v12.16.2-win-x64.zip -OutFile node-v12.16.2-win-x64.zip
+    & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE.part"
+    & move "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE.part" "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+}
+
+IF (!(Test-Path -Path "$Env:USERPROFILE\.local\opt\$Env:PKG_NAME-v$Env:WEBI_VERSION"))
+{
+    echo "Installing $Env:PKG_NAME"
+    # TODO: temp directory
+
+    # Enter opt
+    pushd .local\tmp
+
+        # Remove any leftover tmp cruft
+        Remove-Item -Path "deno-v*" -Recurse -ErrorAction Ignore
+
+        # Unpack archive
+        # Windows BSD-tar handles zip. Imagine that.
+        echo "Unpacking $Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+        & tar xf "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+
+        # Settle unpacked archive into place
+        echo "New Name: $Env:PKG_NAME-v$Env:WEBI_VERSION"
+        Get-ChildItem "deno*" | Select -f 1 | Rename-Item -NewName "$Env:PKG_NAME-v$Env:WEBI_VERSION.exe"
+        echo "New Location: $Env:USERPROFILE\.local\opt\$Env:PKG_NAME-v$Env:WEBI_VERSION.exe"
+        Move-Item -Path "$Env:PKG_NAME-v$Env:WEBI_VERSION.exe" -Destination "$Env:USERPROFILE\.local\opt"
+
+    # Exit tmp
+    popd
+}
+
+echo "Copying into '$Env:USERPROFILE\.local\bin\$Env:PKG_NAME.exe' from '$Env:USERPROFILE\.local\opt\$Env:PKG_NAME-v$Env:WEBI_VERSION.exe'"
+Remove-Item -Path "$Env:USERPROFILE\.local\bin\$Env:PKG_NAME.exe" -Recurse -ErrorAction Ignore
+Copy-Item -Path "$Env:USERPROFILE\.local\opt\$Env:PKG_NAME-v$Env:WEBI_VERSION.exe" -Destination "$Env:USERPROFILE\.local\bin\$Env:PKG_NAME.exe" -Recurse
+
+# Add to path
+& "$Env:USERPROFILE\.local\bin\pathman.exe" add ~/.local/bin