add PowerShell for Mac and Linux
authorAJ ONeal <aj@therootcompany.com>
Tue, 30 Jun 2020 06:15:43 +0000 (06:15 +0000)
committerAJ ONeal <aj@therootcompany.com>
Tue, 30 Jun 2020 06:16:01 +0000 (06:16 +0000)
_webi/normalize.js
powershell/README.md [new file with mode: 0644]
powershell/install.sh [new file with mode: 0644]
powershell/releases.js [new file with mode: 0644]

index cd9c6246c3a73d98e01117fdd4a0c2ac9330946d..5672bca8a42dda202396e6c642d538e6803e210a 100644 (file)
@@ -2,7 +2,7 @@
 
 // this may need customizations between packages
 var osMap = {
-  macos: /(\b|_)(apple|mac|darwin|iPhone|iOS|iPad)/i,
+  macos: /(\b|_)(apple|os\s?x\b|mac|darwin|iPhone|iOS|iPad)/i,
   linux: /(\b|_)(linux)/i,
   freebsd: /(\b|_)(freebsd)/i,
   windows: /(\b|_)(win|microsoft|msft)/i,
diff --git a/powershell/README.md b/powershell/README.md
new file mode 100644 (file)
index 0000000..b0215b6
--- /dev/null
@@ -0,0 +1,17 @@
+---
+title: Microsoft PowerShell
+homepage: https://docs.microsoft.com/en-us/powershell/
+tagline: |
+  PowerShell Core is a cross-platform (Windows, Linux, and macOS) automation and configuration tool/framework.
+description: |
+  PowerShell is the default shell on Windows 10. Since `curl.exe | powershell` is effectively as convenient as `curl | bash` for users, and since Windows 10 also includes tar, curl.exe, and ssh, among others, you can use fairly simple PowerShell to make a variety of tasks simple for Windows developers.
+---
+
+For example, if you wanted to install Node.js with powershell and
+webinstall.dev, you can:
+
+```cmd
+curl.exe -s -A "MS" https://webinstall.dev/node@lts | powershell
+```
+
+<!-- TODO if, pipe, function -->
diff --git a/powershell/install.sh b/powershell/install.sh
new file mode 100644 (file)
index 0000000..ac1a36c
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+{
+    set -e
+    set -u
+
+    pkg_cmd_name="pwsh"
+    # no ./bin prefix
+    pkg_src_cmd="$HOME/.local/opt/pwsh-v$WEBI_VERSION/pwsh"
+    pkg_dst_cmd="$HOME/.local/opt/pwsh/pwsh"
+
+    pkg_get_current_version() {
+        # 'pwsh --version' has output in this format:
+        #       PowerShell 7.0.2
+        # This trims it down to just the version number:
+        #       7.0.2
+        echo "$(pwsh --version 2>/dev/null | head -n 1 | cut -d' ' -f2)"
+    }
+
+    pkg_install() {
+        # mv ./* "$HOME/.local/opt/pwsh-v7.0.2"
+        mkdir -p "$pkg_src"
+        mv ./* "$pkg_src"
+
+        # symlink powershell to pwsh
+        pushd "$pkg_src" >/dev/null
+            ln -s pwsh powershell
+        popd >/dev/null
+    }
+
+    pkg_link() {
+        # rm -f "$HOME/.local/opt/pwsh"
+        rm -f "$pkg_dst"
+
+        # ln -s "$HOME/.local/opt/pwsh-v7.0.2" "$HOME/.local/opt/pwsh"
+        ln -s "$pkg_src" "$pkg_dst"
+    }
+
+    pkg_done_message() {
+        echo "Installed 'pwsh' at $pkg_dst"
+    }
+}
diff --git a/powershell/releases.js b/powershell/releases.js
new file mode 100644 (file)
index 0000000..7f43815
--- /dev/null
@@ -0,0 +1,22 @@
+'use strict';
+
+var github = require('../_common/github.js');
+var owner = 'powershell';
+var repo = 'powershell';
+
+module.exports = function (request) {
+  return github(request, owner, repo).then(function (all) {
+    // remove checksums and .deb
+    all.releases = all.releases.filter(function (rel) {
+      return !/(alpine)|(fxdependent)|(\.deb)|(\.pkg)|(\.rpm)$/i.test(rel.name);
+    });
+    return all;
+  });
+};
+
+if (module === require.main) {
+  module.exports(require('@root/request')).then(function (all) {
+    all = require('../_webi/normalize.js')(all);
+    console.info(JSON.stringify(all));
+  });
+}