Init.
This commit is contained in:
commit
a40d71d8d4
9 changed files with 344 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
23
README.md
Normal file
23
README.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# regar
|
||||
|
||||
File watcher development utility.
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
Usage: regar <command> [files...]
|
||||
|
||||
Description:
|
||||
|
||||
File watcher development utility.
|
||||
|
||||
Options:
|
||||
|
||||
-h, --help - Show this help.
|
||||
-r, --hard - Ends the child process by killing it.
|
||||
-s, --soft - Ends the child process by sending an interuption and waiting for it to shut
|
||||
down.
|
||||
-w, --wait - Wait for the child process to complete without terminating it. (default)
|
||||
-e, --extensions <extentions> - Comma separated whitelist of extensions to whatch.
|
||||
-c, --clear - Clear the terminal on restart
|
||||
```
|
7
build.sh
Executable file
7
build.sh
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/bash
|
||||
set -e
|
||||
cd "$(dirname "$(realpath "$0")")"
|
||||
|
||||
|
||||
mkdir -p target
|
||||
deno compile --allow-all --output target/regar regar.ts
|
13
demo/broken.py
Executable file
13
demo/broken.py
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env -S python3
|
||||
|
||||
from time import sleep, time
|
||||
from signal import signal, SIGINT, pause
|
||||
from sys import exit
|
||||
|
||||
def main():
|
||||
print("Now is", time())
|
||||
signal(SIGINT, lambda *_: print("Received sigint, NOT stopping."))
|
||||
print("Waiting for sigint.")
|
||||
pause()
|
||||
|
||||
main()
|
8
demo/simple.py
Executable file
8
demo/simple.py
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env -S python3
|
||||
|
||||
from time import time
|
||||
|
||||
def main():
|
||||
print("Now is", time())
|
||||
|
||||
main()
|
13
demo/slow.py
Executable file
13
demo/slow.py
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env -S python3
|
||||
|
||||
from time import sleep, time
|
||||
from signal import signal, SIGINT, pause
|
||||
from sys import exit
|
||||
|
||||
def main():
|
||||
print("Now is", time())
|
||||
signal(SIGINT, lambda *_: (print("Received sigint, stopping in 5s ..."), sleep(5), exit(0)))
|
||||
print("Waiting for sigint.")
|
||||
pause()
|
||||
|
||||
main()
|
3
deno.json
Normal file
3
deno.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"fmt": { "useTabs": true, "lineWidth": 120 }
|
||||
}
|
116
deno.lock
generated
Normal file
116
deno.lock
generated
Normal file
|
@ -0,0 +1,116 @@
|
|||
{
|
||||
"version": "3",
|
||||
"remote": {
|
||||
"https://deno.land/std@0.221.0/assert/assert.ts": "bec068b2fccdd434c138a555b19a2c2393b71dfaada02b7d568a01541e67cdc5",
|
||||
"https://deno.land/std@0.221.0/assert/assertion_error.ts": "9f689a101ee586c4ce92f52fa7ddd362e86434ffdf1f848e45987dc7689976b8",
|
||||
"https://deno.land/std@0.221.0/console/_data.json": "cf2cc9d039a192b3adbfe64627167c7e6212704c888c25c769fc8f1709e1e1b8",
|
||||
"https://deno.land/std@0.221.0/console/_run_length.ts": "7da8642a0f4f41ac27c0adb1364e18886be856c1d08c5cce6c6b5c00543c8722",
|
||||
"https://deno.land/std@0.221.0/console/unicode_width.ts": "d92f085c0ab9c7ab171e4e7862dfd9d3a36ffd369939be5d3e1140ec58bc820f",
|
||||
"https://deno.land/std@0.221.0/fmt/colors.ts": "d239d84620b921ea520125d778947881f62c50e78deef2657073840b8af9559a",
|
||||
"https://deno.land/std@0.221.0/text/closest_string.ts": "8a91ee8b6d69ff96addcb7c251dad53b476ac8be9c756a0ef786abe9e13a93a5",
|
||||
"https://deno.land/std@0.221.0/text/levenshtein_distance.ts": "24be5cc88326bbba83ca7c1ea89259af0050cffda2817ff3a6d240ad6495eae2",
|
||||
"https://deno.land/std@0.224.0/assert/_constants.ts": "a271e8ef5a573f1df8e822a6eb9d09df064ad66a4390f21b3e31f820a38e0975",
|
||||
"https://deno.land/std@0.224.0/assert/assert.ts": "09d30564c09de846855b7b071e62b5974b001bb72a4b797958fe0660e7849834",
|
||||
"https://deno.land/std@0.224.0/assert/assert_almost_equals.ts": "9e416114322012c9a21fa68e187637ce2d7df25bcbdbfd957cd639e65d3cf293",
|
||||
"https://deno.land/std@0.224.0/assert/assert_array_includes.ts": "14c5094471bc8e4a7895fc6aa5a184300d8a1879606574cb1cd715ef36a4a3c7",
|
||||
"https://deno.land/std@0.224.0/assert/assert_equals.ts": "3bbca947d85b9d374a108687b1a8ba3785a7850436b5a8930d81f34a32cb8c74",
|
||||
"https://deno.land/std@0.224.0/assert/assert_exists.ts": "43420cf7f956748ae6ed1230646567b3593cb7a36c5a5327269279c870c5ddfd",
|
||||
"https://deno.land/std@0.224.0/assert/assert_false.ts": "3e9be8e33275db00d952e9acb0cd29481a44fa0a4af6d37239ff58d79e8edeff",
|
||||
"https://deno.land/std@0.224.0/assert/assert_greater.ts": "5e57b201fd51b64ced36c828e3dfd773412c1a6120c1a5a99066c9b261974e46",
|
||||
"https://deno.land/std@0.224.0/assert/assert_greater_or_equal.ts": "9870030f997a08361b6f63400273c2fb1856f5db86c0c3852aab2a002e425c5b",
|
||||
"https://deno.land/std@0.224.0/assert/assert_instance_of.ts": "e22343c1fdcacfaea8f37784ad782683ec1cf599ae9b1b618954e9c22f376f2c",
|
||||
"https://deno.land/std@0.224.0/assert/assert_is_error.ts": "f856b3bc978a7aa6a601f3fec6603491ab6255118afa6baa84b04426dd3cc491",
|
||||
"https://deno.land/std@0.224.0/assert/assert_less.ts": "60b61e13a1982865a72726a5fa86c24fad7eb27c3c08b13883fb68882b307f68",
|
||||
"https://deno.land/std@0.224.0/assert/assert_less_or_equal.ts": "d2c84e17faba4afe085e6c9123a63395accf4f9e00150db899c46e67420e0ec3",
|
||||
"https://deno.land/std@0.224.0/assert/assert_match.ts": "ace1710dd3b2811c391946954234b5da910c5665aed817943d086d4d4871a8b7",
|
||||
"https://deno.land/std@0.224.0/assert/assert_not_equals.ts": "78d45dd46133d76ce624b2c6c09392f6110f0df9b73f911d20208a68dee2ef29",
|
||||
"https://deno.land/std@0.224.0/assert/assert_not_instance_of.ts": "3434a669b4d20cdcc5359779301a0588f941ffdc2ad68803c31eabdb4890cf7a",
|
||||
"https://deno.land/std@0.224.0/assert/assert_not_match.ts": "df30417240aa2d35b1ea44df7e541991348a063d9ee823430e0b58079a72242a",
|
||||
"https://deno.land/std@0.224.0/assert/assert_not_strict_equals.ts": "37f73880bd672709373d6dc2c5f148691119bed161f3020fff3548a0496f71b8",
|
||||
"https://deno.land/std@0.224.0/assert/assert_object_match.ts": "411450fd194fdaabc0089ae68f916b545a49d7b7e6d0026e84a54c9e7eed2693",
|
||||
"https://deno.land/std@0.224.0/assert/assert_rejects.ts": "4bee1d6d565a5b623146a14668da8f9eb1f026a4f338bbf92b37e43e0aa53c31",
|
||||
"https://deno.land/std@0.224.0/assert/assert_strict_equals.ts": "b4f45f0fd2e54d9029171876bd0b42dd9ed0efd8f853ab92a3f50127acfa54f5",
|
||||
"https://deno.land/std@0.224.0/assert/assert_string_includes.ts": "496b9ecad84deab72c8718735373feb6cdaa071eb91a98206f6f3cb4285e71b8",
|
||||
"https://deno.land/std@0.224.0/assert/assert_throws.ts": "c6508b2879d465898dab2798009299867e67c570d7d34c90a2d235e4553906eb",
|
||||
"https://deno.land/std@0.224.0/assert/assertion_error.ts": "ba8752bd27ebc51f723702fac2f54d3e94447598f54264a6653d6413738a8917",
|
||||
"https://deno.land/std@0.224.0/assert/equal.ts": "bddf07bb5fc718e10bb72d5dc2c36c1ce5a8bdd3b647069b6319e07af181ac47",
|
||||
"https://deno.land/std@0.224.0/assert/fail.ts": "0eba674ffb47dff083f02ced76d5130460bff1a9a68c6514ebe0cdea4abadb68",
|
||||
"https://deno.land/std@0.224.0/assert/mod.ts": "48b8cb8a619ea0b7958ad7ee9376500fe902284bb36f0e32c598c3dc34cbd6f3",
|
||||
"https://deno.land/std@0.224.0/assert/unimplemented.ts": "8c55a5793e9147b4f1ef68cd66496b7d5ba7a9e7ca30c6da070c1a58da723d73",
|
||||
"https://deno.land/std@0.224.0/assert/unreachable.ts": "5ae3dbf63ef988615b93eb08d395dda771c96546565f9e521ed86f6510c29e19",
|
||||
"https://deno.land/std@0.224.0/fmt/colors.ts": "508563c0659dd7198ba4bbf87e97f654af3c34eb56ba790260f252ad8012e1c5",
|
||||
"https://deno.land/std@0.224.0/fs/exists.ts": "3d38cb7dcbca3cf313be343a7b8af18a87bddb4b5ca1bd2314be12d06533b50f",
|
||||
"https://deno.land/std@0.224.0/internal/diff.ts": "6234a4b493ebe65dc67a18a0eb97ef683626a1166a1906232ce186ae9f65f4e6",
|
||||
"https://deno.land/std@0.224.0/internal/format.ts": "0a98ee226fd3d43450245b1844b47003419d34d210fa989900861c79820d21c2",
|
||||
"https://deno.land/std@0.224.0/internal/mod.ts": "534125398c8e7426183e12dc255bb635d94e06d0f93c60a297723abe69d3b22e",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/_argument_types.ts": "ab269dacea2030f865a07c2a1e953ec437a64419a05bad1f1ddaab3f99752ead",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/_errors.ts": "d78e1b4d69d84b8b476b5f3c0b028e3906d48f21b8f1ca1d36d5abe9ccfe48bc",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/_spread.ts": "0cc6eb70a6df97b5d7d26008822d39f3e8a1232ee0a27f395aa19e68de738245",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/_type_utils.ts": "820004a59bc858e355b11f80e5b3ff1be2c87e66f31f53f253610170795602f0",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/_utils.ts": "fa0e88cc4215b18554a7308e8e2ae3a12be0fb91c54d1473c54c530dbd4adfcb",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/command.ts": "83cbece11c1459d5bc5add32c3cad0bf49e92c4ddd3ef00f22f80efdae30994e",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/completions/_bash_completions_generator.ts": "0c6cb1df4d378d22f001155781d97a9c3519fd10c48187a198fef2cc63b0f84a",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/completions/_fish_completions_generator.ts": "8ba4455f7f76a756e05c3db4ce35332b2951af65a2891f2750b530e06880f495",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/completions/_zsh_completions_generator.ts": "9df79fbac17a32b9645d01628c41a2bfd295d7976b87b0ae235f50a9c8975fbc",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/completions/bash.ts": "53fe78994eb2359110dc4fa79235bdd86800a38c1d6b1c4fe673c81756f3a0e2",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/completions/complete.ts": "58df61caa5e6220ff2768636a69337923ad9d4b8c1932aeb27165081c4d07d8b",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/completions/completions_command.ts": "506f97f1c6b0b1c3e9956e5069070028b818942310600d4157f64c9b644d3c49",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/completions/fish.ts": "6f0b44b4067740b2931c9ec8863b6619b1d3410fea0c5a3988525a4c53059197",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/completions/mod.ts": "8dda715ca25f3f66d5ec232b76d7c9a96dd4c64b5029feff91738cc0c9586fb1",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/completions/zsh.ts": "f1263c3946975e090d4aadc8681db811d86b52a8ae680f246e03248025885c21",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/deprecated.ts": "bbe6670f1d645b773d04b725b8b8e7814c862c9f1afba460c4d599ffe9d4983c",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/deps.ts": "a58ea2fa4e2ed9b39bb8dd8c35dd0498c74f05392517ff230a9a4d04c4c766b7",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/help/_help_generator.ts": "98619da83ff25523280a6fdcad89af3f13a6fafefc81b71f8230f3344b5ff2c5",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/help/help_command.ts": "fbbf0c0827dd21d3cec7bcc68c00c20b55f53e2b621032891b9d23ac4191231c",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/help/mod.ts": "8369b292761dcc9ddaf41f2d34bfb06fb6800b69efe80da4fc9752c3b890275b",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/mod.ts": "4b708df1b97152522bee0e3828f06abbbc1d2250168910e5cf454950d7b7404b",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/type.ts": "f588f5d9635b79100044e62aced4b00e510e75b83801f9b089c40c2d98674de2",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/types.ts": "bc9ff7459b9cc1079eeb95ff101690a51b4b4afa4af5623340076ee361d08dbb",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/types/action_list.ts": "33c98d449617c7a563a535c9ceb3741bde9f6363353fd492f90a74570c611c27",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/types/boolean.ts": "3879ec16092b4b5b1a0acb8675f8c9250c0b8a972e1e4c7adfba8335bd2263ed",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/types/child_command.ts": "f1fca390c7fbfa7a713ca15ef55c2c7656bcbb394d50e8ef54085bdf6dc22559",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/types/command.ts": "325d0382e383b725fd8d0ef34ebaeae082c5b76a1f6f2e843fee5dbb1a4fe3ac",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/types/enum.ts": "8a7cd2898e03089234083bb78c8b1d9b7172254c53c32d4710321638165a48ec",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/types/file.ts": "8618f16ac9015c8589cbd946b3de1988cc4899b90ea251f3325c93c46745140e",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/types/integer.ts": "29864725fd48738579d18123d7ee78fed37515e6dc62146c7544c98a82f1778d",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/types/number.ts": "aeba96e6f470309317a16b308c82e0e4138a830ec79c9877e4622c682012bc1f",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/types/string.ts": "e4dadb08a11795474871c7967beab954593813bb53d9f69ea5f9b734e43dc0e0",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/upgrade/_check_version.ts": "6cfa7dc26bc0dc46381500e8d4b130fb224f4c5456152dada15bd3793edca89b",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/upgrade/mod.ts": "4eff69c489467be17dea27fb95a795396111ee385d170ac0cbcc82f0ea38156c",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/upgrade/provider.ts": "c23253334097dc4b8a147ccdeb3aa44f5a95aa953a6386cb5396f830d95d77a5",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/upgrade/provider/deno_land.ts": "24f8d82e38c51e09be989f30f8ad21f9dd41ac1bb1973b443a13883e8ba06d6d",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/upgrade/provider/github.ts": "99e1b133dd446c6aa79f69e69c46eb8bc1c968dd331c2a7d4064514a317c7b59",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/upgrade/provider/nest_land.ts": "0e07936cea04fa41ac9297f32d87f39152ea873970c54cb5b4934b12fee1885e",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/command/upgrade/upgrade_command.ts": "27191f4b1ce93581b6d5ee2fff6003fe4fca437f476ecb98b6eae92f2b4d0716",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/flags/_errors.ts": "f1fbb6bfa009e7950508c9d491cfb4a5551027d9f453389606adb3f2327d048f",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/flags/_utils.ts": "25e519ce1f35acc8b43c75d1ca1c4ab591e7dab08327b7b408705b591e27d8bd",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/flags/_validate_flags.ts": "e60b9038c0136ab7e6bd1baf0e993a07bf23f18afbfb6e12c59adf665a622957",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/flags/deprecated.ts": "a72a35de3cc7314e5ebea605ca23d08385b218ef171c32a3f135fb4318b08126",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/flags/deps.ts": "bed26afff36eeb25509440edec9d5d141b3411e08cc7a90e38a370969b5166bb",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/flags/flags.ts": "3e62c4a9756b5705aada29e7e94847001356b3a83cd18ad56f4207387a71cf51",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/flags/types.ts": "9e2f75edff2217d972fc711a21676a59dfd88378da2f1ace440ea84c07db1dcc",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/flags/types/boolean.ts": "4c026dd66ec9c5436860dc6d0241427bdb8d8e07337ad71b33c08193428a2236",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/flags/types/integer.ts": "b60d4d590f309ddddf066782d43e4dc3799f0e7d08e5ede7dc62a5ee94b9a6d9",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/flags/types/number.ts": "610936e2d29de7c8c304b65489a75ebae17b005c6122c24e791fbed12444d51e",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/flags/types/string.ts": "e89b6a5ce322f65a894edecdc48b44956ec246a1d881f03e97bbda90dd8638c5",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/table/_layout.ts": "73a9bcb8a87b3a6817c4c9d2a31a21b874a7dd690ade1c64c9a1f066d628d626",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/table/_utils.ts": "13390db3f11977b7a4fc1202fa8386be14696b475a7f46a65178354f9a6640b7",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/table/border.ts": "5c6e9ef5078c6930169aacb668b274bdbb498461c724a7693ac9270fe9d3f5d5",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/table/cell.ts": "65e3ee699c3cebeb4d4d44e8f156e37a8532a0f317359d73178a95724d3f9267",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/table/column.ts": "cf14009f2cb14bad156f879946186c1893acdc6a2fee6845db152edddb6a2714",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/table/consume_words.ts": "369d065dbf7f15c664ea8523e0ef750fb952aea6d88e146c375e64aec9503052",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/table/deps.ts": "cbb896e8d7a6b5e3c2b9dda7d16638c202d9b46eb738c2dae1fa9480d8091486",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/table/row.ts": "79eb1468aafdd951e5963898cdafe0752d4ab4c519d5f847f3d8ecb8fe857d4f",
|
||||
"https://deno.land/x/cliffy@v1.0.0-rc.4/table/table.ts": "298671e72e61f1ab18b42ae36643181993f79e29b39dc411fdc6ffd53aa04684",
|
||||
"https://git.barnulf.net/mb/barnulf_ts/raw/branch/master/mod.ts": "bc9436bcf45f3204ebcd0b2559f53e5d38162195fc48ac6d435cf8ca38c77ae3",
|
||||
"https://git.barnulf.net/mb/barnulf_ts/raw/branch/master/src/lib.ts": "e57cadb5af319d04522155e356c5c021ecc5ea57563d1f989243ec4905c26daf",
|
||||
"https://git.barnulf.net/mb/barnulf_ts/raw/branch/master/src/lib/AsyncPool.ts": "eb1e87bca9c92bf7fea43f061c8f4d102b46b22ca5fbd8d6ca9bf20b07ea7f51",
|
||||
"https://git.barnulf.net/mb/barnulf_ts/raw/branch/master/src/lib/Chain.ts": "93b39dbb22ebe8f6770880f9547fca1d9e6488b299c7eb86ca5328b3ad7660d8",
|
||||
"https://git.barnulf.net/mb/barnulf_ts/raw/branch/master/src/lib/Channel.ts": "6b34d312316a6b7800337c807aa59c6e71a53ee4f78343060665ada75a2ec56b",
|
||||
"https://git.barnulf.net/mb/barnulf_ts/raw/branch/master/src/lib/Event.ts": "c0406f3e0980665d7377491536e33249e98c7a63c3a292c7d0d15670ba0074d0",
|
||||
"https://git.barnulf.net/mb/barnulf_ts/raw/branch/master/src/lib/Range.ts": "3f697d4520c86a60d697e85047eb291ec12177c13cbabbe47516ae1021ec1d67",
|
||||
"https://git.barnulf.net/mb/barnulf_ts/raw/branch/master/src/lib/iter.ts": "1d56290564a24a87a945a7376c4d9f3610a8384be64d249ec8427bdeb1caa6f2",
|
||||
"https://git.barnulf.net/mb/barnulf_ts/raw/branch/master/src/lib/types.ts": "205e0a638be527f4753acbbda445434e8134b4afe4cc22469739745a2bc40ef6",
|
||||
"https://git.barnulf.net/mb/barnulf_ts/raw/branch/master/src/lib/utils.ts": "d19e8ebc3c786461fe2601335018d2069bbb387969359e2d4c27ccdec12c9f6a"
|
||||
}
|
||||
}
|
160
regar.ts
Executable file
160
regar.ts
Executable file
|
@ -0,0 +1,160 @@
|
|||
#!/usr/bin/env -S deno run -A
|
||||
|
||||
import { exists } from "https://deno.land/std@0.224.0/fs/exists.ts";
|
||||
import { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.4/command/mod.ts";
|
||||
import { Channel } from "https://git.barnulf.net/mb/barnulf_ts/raw/branch/master/mod.ts";
|
||||
|
||||
async function main() {
|
||||
const { do_clear, command, extensions, files, strategy } = await parse_args();
|
||||
const channel = new Channel<Event>();
|
||||
files.map((path) => new Watcher(path, extensions).spin(channel));
|
||||
new Runner(command, strategy, do_clear).spin(channel);
|
||||
}
|
||||
|
||||
async function parse_args() {
|
||||
const { args, options } = await new Command()
|
||||
.name("regar")
|
||||
.description("File watcher development utility.")
|
||||
.arguments("<command> [...files]")
|
||||
.option("-r, --hard", "Ends the child process by killing it.")
|
||||
.option("-s, --soft", "Ends the child process by sending an interuption and waiting for it to shut down.")
|
||||
.option("-w, --wait", "Wait for the child process to complete without terminating it. (default)")
|
||||
.option("-e, --extensions <extentions>", "Comma separated whitelist of extensions to whatch.")
|
||||
.option("-c, --clear", "Clear the terminal on restart").parse();
|
||||
const [command, ...files] = args;
|
||||
let strategy: ShutdownStrategy = new WaitStrategy();
|
||||
if (options.soft) strategy = new SoftStrategy();
|
||||
if (options.hard) strategy = new HardStrategy();
|
||||
if (options.wait) strategy = new WaitStrategy();
|
||||
const extensions = options.extensions?.split(",");
|
||||
const do_clear = options.clear ?? false;
|
||||
return { command, files, strategy, extensions, do_clear };
|
||||
}
|
||||
|
||||
class Watcher {
|
||||
public constructor(
|
||||
private path: string,
|
||||
private extension_whitelist: string[] | undefined,
|
||||
) {}
|
||||
|
||||
public async spin(channel: Channel<Event>) {
|
||||
const relevant_events: Deno.FsEvent["kind"][] = ["create", "modify", "remove", "rename"];
|
||||
for await (const event of Deno.watchFs(this.path, { recursive: true })) {
|
||||
if (!relevant_events.includes(event.kind)) continue;
|
||||
if (!this.matches_whitelist(event.paths[0])) continue;
|
||||
for (const path of event.paths) channel.send(new Event(path, Date.now()));
|
||||
}
|
||||
}
|
||||
|
||||
private matches_whitelist(path: string) {
|
||||
if (this.extension_whitelist === undefined) return true;
|
||||
for (const ext of this.extension_whitelist) if (path.endsWith(ext)) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class Runner {
|
||||
public constructor(
|
||||
private command: string,
|
||||
private strategy: ShutdownStrategy,
|
||||
private do_clear: boolean,
|
||||
) {}
|
||||
|
||||
public async spin(channel: Channel<Event>) {
|
||||
this.could_clear();
|
||||
let process = this.launch();
|
||||
while (true) {
|
||||
const event = await channel.receive();
|
||||
if (this.debouncing(event)) continue;
|
||||
const shotdown = await this.strategy.shutdown(process);
|
||||
if (!shotdown) continue;
|
||||
this.could_clear();
|
||||
log("changed", event.path);
|
||||
process = this.launch();
|
||||
}
|
||||
}
|
||||
|
||||
private launch() {
|
||||
const args = ["-c", this.command];
|
||||
log("running", this.command);
|
||||
const process = new Deno.Command("sh", { args }).spawn();
|
||||
process.status.then(this.on_end());
|
||||
return process;
|
||||
}
|
||||
|
||||
private could_clear() {
|
||||
const clear_term_sequence = "\x1bc";
|
||||
if (this.do_clear) console.log(clear_term_sequence);
|
||||
}
|
||||
|
||||
private last_event_date_ms = 0;
|
||||
private debouncing(event: Event) {
|
||||
const delay_ms = event.date_ms - this.last_event_date_ms;
|
||||
const threshold_ms = 100;
|
||||
if (delay_ms < threshold_ms) return true;
|
||||
this.last_event_date_ms = event.date_ms;
|
||||
return false;
|
||||
}
|
||||
|
||||
private on_end() {
|
||||
const start_ms = Date.now();
|
||||
return () => {
|
||||
const end_ms = Date.now();
|
||||
const time_ms = end_ms - start_ms;
|
||||
const secs = time_ms / 1000;
|
||||
log("terminated", `${secs} s`);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
interface ShutdownStrategy {
|
||||
// Returns wether the child has been shutdown.
|
||||
shutdown(process_: Deno.ChildProcess): Promise<boolean>;
|
||||
}
|
||||
|
||||
class WaitStrategy implements ShutdownStrategy {
|
||||
async shutdown(process_: Deno.ChildProcess) {
|
||||
if (await process_exists(process_.pid)) return false;
|
||||
else return true;
|
||||
}
|
||||
}
|
||||
|
||||
class SoftStrategy implements ShutdownStrategy {
|
||||
async shutdown(process_: Deno.ChildProcess) {
|
||||
Deno.kill(process_.pid, "SIGINT");
|
||||
await process_.output();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class HardStrategy implements ShutdownStrategy {
|
||||
async shutdown(process_: Deno.ChildProcess) {
|
||||
Deno.kill(process_.pid, "SIGKILL");
|
||||
return await true;
|
||||
}
|
||||
}
|
||||
|
||||
class Event {
|
||||
constructor(
|
||||
public path: string,
|
||||
public date_ms: number,
|
||||
) {}
|
||||
}
|
||||
|
||||
async function process_exists(pid: number) {
|
||||
return await exists(`/proc/${pid}`);
|
||||
}
|
||||
|
||||
function log(verb: string, value: unknown) {
|
||||
const yellow = "\x1b[0;33m";
|
||||
const bold = "\x1b[1m";
|
||||
const reset = "\x1b[0m";
|
||||
console.log(
|
||||
`` +
|
||||
`${yellow}${bold}${verb.padStart(12)}${reset}` +
|
||||
` ` +
|
||||
`${yellow}${value}${reset}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (import.meta.main) await main();
|
Loading…
Add table
Add a link
Reference in a new issue