forked from hotosm/field-tm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJustfile
More file actions
143 lines (122 loc) · 3.92 KB
/
Justfile
File metadata and controls
143 lines (122 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Copyright (c) Humanitarian OpenStreetMap Team
#
# This file is part of Field-TM.
#
# Field-TM is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Field-TM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Field-TM. If not, see <https:#www.gnu.org/licenses/>.
#
set dotenv-load
# Auto-detect nerdctl when docker is not installed (e.g. after `just prep machine`)
docker := env("DOCKER_ALIAS", if `command -v docker >/dev/null 2>&1 && echo found || echo missing` == "found" { "docker" } else { "nerdctl" })
mod start 'tasks/start'
mod stop 'tasks/stop'
mod build 'tasks/build'
mod test 'tasks/test'
mod config 'tasks/config'
mod manage 'tasks/manage'
mod docs 'tasks/docs'
mod i18n 'tasks/i18n'
# List available commands
[private]
default:
just help
# List available commands
help:
just --justfile {{justfile()}} --list
# Prep module from https://github.com/hotosm/justfiles
prep *args:
@curl -sS https://raw.githubusercontent.com/hotosm/justfiles/main/prep.just \
-o {{justfile_directory()}}/tasks/prep.just;
@just --justfile {{justfile_directory()}}/tasks/prep.just {{args}}
# Chart module from https://github.com/hotosm/justfiles
chart *args:
@curl -sS https://raw.githubusercontent.com/hotosm/justfiles/main/chart.just \
-o {{justfile_directory()}}/tasks/chart.just;
@just --justfile {{justfile_directory()}}/tasks/chart.just --set chart_name "field-tm" {{args}}
# Delete local database, S3, and ODK Central data
clean:
{{docker}} compose down -v
# Run pre-commit hooks
lint:
#!/usr/bin/env sh
cd {{justfile_directory()}}/src/backend
uv run pre-commit run --all-files
# Increment field-tm
bump:
#!/usr/bin/env sh
cd {{justfile_directory()}}/src/backend
uv run cz bump --check-consistency
# Increment osm-fieldwork (doesn't work yet!)
bump-osm-fieldwork:
#!/usr/bin/env sh
cd {{justfile_directory()}}/src/backend
uv --project packages/osm-fieldwork --directory packages/osm-fieldwork run cz bump --check-consistency
# Arrow-key selection menu. Draws on stderr, prints chosen item to stdout.
# Usage: chosen=$(just _select-menu "Pick one:" item1 item2 item3)
[no-cd]
_select-menu prompt +items:
#!/usr/bin/env bash
set -e
IFS=' ' read -ra opts <<< "{{ items }}"
count=${#opts[@]}
selected=0
# Print prompt
printf "\033[0;34m%s\033[0m\n" "{{ prompt }}" >&2
# Hide cursor, restore on exit
tput civis >&2 2>/dev/null
trap 'tput cnorm >&2 2>/dev/null' EXIT
draw_menu() {
for i in "${!opts[@]}"; do
tput el >&2 2>/dev/null
if [ "$i" -eq "$selected" ]; then
printf " \033[7m > %s \033[0m\n" "${opts[$i]}" >&2
else
printf " %s\n" "${opts[$i]}" >&2
fi
done
}
draw_menu
while true; do
read -rsn1 key
case "$key" in
$'\x1b')
read -rsn2 rest
case "$rest" in
'[A') ((selected > 0)) && ((selected--)) || true ;;
'[B') ((selected < count - 1)) && ((selected++)) || true ;;
esac
;;
'') # enter
break
;;
esac
printf "\033[%dA" "$count" >&2
draw_menu
done
printf "\n" >&2
echo "${opts[$selected]}"
# Echo to terminal with blue colour
[no-cd]
_echo-blue text:
#!/usr/bin/env sh
printf "\033[0;34m%s\033[0m\n" "{{ text }}"
# Echo to terminal with yellow colour
[no-cd]
_echo-yellow text:
#!/usr/bin/env sh
printf "\033[0;33m%s\033[0m\n" "{{ text }}"
# Echo to terminal with red colour
[no-cd]
_echo-red text:
#!/usr/bin/env sh
printf "\033[0;41m%s\033[0m\n" "{{ text }}"