Added watchexec + cheat sheets
authorAnurag sati <anuragsati7@gmail.com>
Fri, 25 Sep 2020 19:52:48 +0000 (01:22 +0530)
committerAJ ONeal <coolaj86@gmail.com>
Sat, 26 Sep 2020 20:52:30 +0000 (14:52 -0600)
watchexec/README.md [new file with mode: 0644]
watchexec/install.ps1 [new file with mode: 0644]
watchexec/install.sh [new file with mode: 0644]
watchexec/releases.js [new file with mode: 0644]

diff --git a/watchexec/README.md b/watchexec/README.md
new file mode 100644 (file)
index 0000000..782bbeb
--- /dev/null
@@ -0,0 +1,57 @@
+---
+title: watchexec
+homepage: https://github.com/watchexec/watchexec
+tagline: |
+  watchexec is a simple, standalone tool that watches a path and runs a command whenever it detects modifications.
+---
+
+### Updating `watchexec`
+
+`webi watchexec@stable`
+
+Use the `@beta` tag for pre-releases.
+
+## Cheat Sheet
+
+Watch all JavaScript, CSS and HTML files in the current directory and all
+subdirectories for changes, running `make` when a change is detected:
+
+    $ watchexec --exts js,css,html make
+
+Call `make test` when any file changes in this directory/subdirectory, except
+for everything below `target`:
+
+    $ watchexec -i target make test
+
+Call `ls -la` when any file changes in this directory/subdirectory:
+
+    $ watchexec -- ls -la
+
+Call/restart `python server.py` when any Python file in the current directory
+(and all subdirectories) changes:
+
+    $ watchexec -e py -r python server.py
+
+Call/restart `my_server` when any file in the current directory (and all
+subdirectories) changes, sending `SIGKILL` to stop the child process:
+
+    $ watchexec -r -s SIGKILL my_server
+
+Send a SIGHUP to the child process upon changes (Note: with using
+`-n | --no-shell` here, we're executing `my_server` directly, instead of
+wrapping it in a shell:
+
+    $ watchexec -n -s SIGHUP my_server
+
+Run `make` when any file changes, using the `.gitignore` file in the current
+directory to filter:
+
+    $ watchexec make
+
+Run `make` when any file in `lib` or `src` changes:
+
+    $ watchexec -w lib -w src make
+
+Run `bundle install` when the `Gemfile` changes:
+
+    $ watchexec -w Gemfile bundle install
diff --git a/watchexec/install.ps1 b/watchexec/install.ps1
new file mode 100644 (file)
index 0000000..7e53bb5
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/env pwsh
+
+#####################
+# Install watchexec #
+#####################
+
+# Every package should define these variables
+$pkg_cmd_name = "watchexec"
+
+$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\watchexec.exe"
+$pkg_dst = "$pkg_dst_cmd"
+
+$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\watchexec-v$Env:WEBI_VERSION\bin\watchexec.exe"
+$pkg_src_bin = "$Env:USERPROFILE\.local\opt\watchexec-v$Env:WEBI_VERSION\bin"
+$pkg_src_dir = "$Env:USERPROFILE\.local\opt\watchexec-v$Env:WEBI_VERSION"
+$pkg_src = "$pkg_src_cmd"
+
+$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+
+# Fetch archive
+IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"))
+{
+    # TODO: arch detection
+    echo "Downloading watchexec from $Env:WEBI_PKG_URL to $pkg_download"
+    & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
+    & move "$pkg_download.part" "$pkg_download"
+}
+
+IF (!(Test-Path -Path "$pkg_src_cmd"))
+{
+    echo "Installing watchexec"
+
+    # TODO: create package-specific temp directory
+    # Enter tmp
+    pushd .local\tmp
+
+        # Remove any leftover tmp cruft 
+        Remove-Item -Path ".\watchexec-v*" -Recurse -ErrorAction Ignore
+        Remove-Item -Path ".\watchexec.exe" -Recurse -ErrorAction Ignore
+
+        echo "Unpacking $pkg_download"
+        & tar xf "$pkg_download"
+      
+        # Settle unpacked archive into place
+        echo "Install Location: $pkg_src_cmd"
+        New-Item "$pkg_src_bin" -ItemType Directory
+        Move-Item -Path ".\watchexec-*\watchexec.exe" -Destination "$pkg_src_bin"
+
+    # Exit tmp
+    popd
+}
+
+echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
+Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore
+Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
diff --git a/watchexec/install.sh b/watchexec/install.sh
new file mode 100644 (file)
index 0000000..b4b92d3
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+{
+    set -e
+    set -u
+
+    #####################
+    # Install watchexec #
+    #####################
+
+    # Every package should define these 6 variables
+    pkg_cmd_name="watchexec"
+
+    pkg_dst_cmd="$HOME/.local/bin/watchexec"
+    pkg_dst="$pkg_dst_cmd"
+
+    pkg_src_cmd="$HOME/.local/opt/watchexec-v$WEBI_VERSION/bin/watchexec"
+    pkg_src_dir="$HOME/.local/opt/watchexec-v$WEBI_VERSION"
+    pkg_src="$pkg_src_cmd"
+
+    # pkg_install must be defined by every package
+    pkg_install() {
+        # ~/.local/opt/watchexec-v0.99.9/bin
+        mkdir -p "$(dirname $pkg_src_cmd)"
+
+        # mv ./watchexec-*/watchexec ~/.local/opt/watchexec-v0.99.9/bin/watchexec
+        mv ./watchexec-*/watchexec "$pkg_src_cmd"
+    }
+
+    # pkg_get_current_version is recommended, but (soon) not required
+    pkg_get_current_version() {
+        # 'watchexec --version' has output in this format:
+        #       watchexec 0.99.9 (rev abcdef0123)
+        # This trims it down to just the version number:
+        #       0.99.9
+        echo $(watchexec --version 2>/dev/null | head -n 1 | cut -d ' ' -f 2)
+    }
+
+}
diff --git a/watchexec/releases.js b/watchexec/releases.js
new file mode 100644 (file)
index 0000000..7784ad0
--- /dev/null
@@ -0,0 +1,20 @@
+'use strict';
+
+var github = require('../_common/github.js');
+var owner = 'watchexec';
+var repo = 'watchexec';
+
+module.exports = function (request) {
+  return github(request, owner, repo).then(function (all) {
+    return all;
+  });
+};
+
+if (module === require.main) {
+  module.exports(require('@root/request')).then(function (all) {
+    all = require('../_webi/normalize.js')(all);
+    // just select the first 5 for demonstration
+    all.releases = all.releases.slice(0, 5);
+    console.info(JSON.stringify(all, null, 2));
+  });
+}