Monorepo for @ducky.ws's experiments and scripts ducky.ws

various

+65 -3
code/bash/.gitkeep

This is a binary file and will not be displayed.

code/dotnet/.gitkeep

This is a binary file and will not be displayed.

code/html/.gitkeep

This is a binary file and will not be displayed.

deno/lastfm-to-tealfm.ts code/deno/lastfm-to-tealfm.ts
deno/shared/util.ts code/deno/shared/util.ts
+65 -3
run.sh
··· 1 1 #!/usr/bin/env bash 2 2 3 3 _me_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 + _runtime_dir="$_me_dir/runtimes" 4 5 _platform="$1" 5 6 _script="$2" 6 7 8 + set -o errtrace 9 + 10 + function check_path_exists() { 11 + local path="$1" 12 + local path_rel="./$(realpath --relative-to="$_me_dir" "$path")" 13 + 14 + if [[ "$path" == *"/" ]]; then 15 + [[ ! -d "$path" ]] && die "Path '$path_rel' does not exist" 16 + else 17 + [[ ! -f "$path" ]] && die "Path '$path_rel' does not exist" 18 + fi 19 + } 20 + 21 + function check_prog() { 22 + local prog="$1" 23 + local asdf_plugin="$2" 24 + 25 + local is_asdf_installed="$([ -x "$(command -v "asdf")" ] && echo 1 || echo 0)" 26 + local is_prog_installed="$([ -x "$(command -v "$prog")" ] && echo 1 || echo 0)" 27 + [[ -z "$asdf_plugin" ]] && asdf_plugin="$prog" 28 + 29 + if [[ $is_prog_installed == 0 ]]; then 30 + if [[ $is_asdf_installed == 1 ]]; then 31 + asdf plugin add $asdf_plugin 32 + asdf install $asdf_plugin latest 33 + [[ $? != 0 ]] && die "Unable to install '$prog'" 34 + asdf set -u $asdf_plugin "$(asdf latest $asdf_plugin)" 35 + echo "---" >&1 36 + else 37 + die "'asdf' not installed, cannot install '$prog'" 38 + fi 39 + else 40 + return 1 41 + fi 42 + } 43 + 44 + function die() { 45 + echo -e "\033[1;31mError: $1\033[0m" >&2 46 + exit 225 47 + } 48 + 49 + function get_code_path() { 50 + local platform="$1" 51 + local script="$2" 52 + local suffix="$3" 53 + 54 + echo "$_me_dir/code/$platform/$script$suffix" 55 + } 56 + 7 57 function run_deno() { 8 - script_path="$1" 58 + local path="$(get_code_path "deno" "$1" ".ts")" 59 + check_path_exists "$path" 60 + check_prog "deno" 9 61 10 - deno run -A "$script_path" 62 + deno run -A "$path" 63 + } 64 + 65 + function run_html() { 66 + local path="$(get_code_path "html" "$1" "/")" 67 + check_path_exists "$path" 68 + check_prog "caddy" 69 + 70 + caddy file-server --browse --listen 0.0.0.0:8080 -root "$path" 71 + #xdg-open "http://0.0.0.0:8080" 11 72 } 12 73 13 74 case "$_platform" in 14 - "deno") run_deno "$_me_dir/deno/$_script.ts" 75 + "deno") run_deno "$_script" ;; 76 + "html") run_html "$_script" ;; 15 77 esac