tangled
alpha
login
or
join now
ducky.ws
/
playground
1
fork
atom
Monorepo for @ducky.ws's experiments and scripts
ducky.ws
1
fork
atom
overview
issues
pulls
pipelines
various
ducky.ws
2 months ago
0583e9a2
16b72cdf
+65
-3
6 changed files
expand all
collapse all
unified
split
code
bash
.gitkeep
deno
lastfm-to-tealfm.ts
shared
util.ts
dotnet
.gitkeep
html
.gitkeep
run.sh
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
4
+
_runtime_dir="$_me_dir/runtimes"
4
5
_platform="$1"
5
6
_script="$2"
6
7
8
8
+
set -o errtrace
9
9
+
10
10
+
function check_path_exists() {
11
11
+
local path="$1"
12
12
+
local path_rel="./$(realpath --relative-to="$_me_dir" "$path")"
13
13
+
14
14
+
if [[ "$path" == *"/" ]]; then
15
15
+
[[ ! -d "$path" ]] && die "Path '$path_rel' does not exist"
16
16
+
else
17
17
+
[[ ! -f "$path" ]] && die "Path '$path_rel' does not exist"
18
18
+
fi
19
19
+
}
20
20
+
21
21
+
function check_prog() {
22
22
+
local prog="$1"
23
23
+
local asdf_plugin="$2"
24
24
+
25
25
+
local is_asdf_installed="$([ -x "$(command -v "asdf")" ] && echo 1 || echo 0)"
26
26
+
local is_prog_installed="$([ -x "$(command -v "$prog")" ] && echo 1 || echo 0)"
27
27
+
[[ -z "$asdf_plugin" ]] && asdf_plugin="$prog"
28
28
+
29
29
+
if [[ $is_prog_installed == 0 ]]; then
30
30
+
if [[ $is_asdf_installed == 1 ]]; then
31
31
+
asdf plugin add $asdf_plugin
32
32
+
asdf install $asdf_plugin latest
33
33
+
[[ $? != 0 ]] && die "Unable to install '$prog'"
34
34
+
asdf set -u $asdf_plugin "$(asdf latest $asdf_plugin)"
35
35
+
echo "---" >&1
36
36
+
else
37
37
+
die "'asdf' not installed, cannot install '$prog'"
38
38
+
fi
39
39
+
else
40
40
+
return 1
41
41
+
fi
42
42
+
}
43
43
+
44
44
+
function die() {
45
45
+
echo -e "\033[1;31mError: $1\033[0m" >&2
46
46
+
exit 225
47
47
+
}
48
48
+
49
49
+
function get_code_path() {
50
50
+
local platform="$1"
51
51
+
local script="$2"
52
52
+
local suffix="$3"
53
53
+
54
54
+
echo "$_me_dir/code/$platform/$script$suffix"
55
55
+
}
56
56
+
7
57
function run_deno() {
8
8
-
script_path="$1"
58
58
+
local path="$(get_code_path "deno" "$1" ".ts")"
59
59
+
check_path_exists "$path"
60
60
+
check_prog "deno"
9
61
10
10
-
deno run -A "$script_path"
62
62
+
deno run -A "$path"
63
63
+
}
64
64
+
65
65
+
function run_html() {
66
66
+
local path="$(get_code_path "html" "$1" "/")"
67
67
+
check_path_exists "$path"
68
68
+
check_prog "caddy"
69
69
+
70
70
+
caddy file-server --browse --listen 0.0.0.0:8080 -root "$path"
71
71
+
#xdg-open "http://0.0.0.0:8080"
11
72
}
12
73
13
74
case "$_platform" in
14
14
-
"deno") run_deno "$_me_dir/deno/$_script.ts"
75
75
+
"deno") run_deno "$_script" ;;
76
76
+
"html") run_html "$_script" ;;
15
77
esac