Stuff stuff stuff #44

Merged
PouuleT merged 24 commits from update-node into master 2021-08-30 12:59:08 +00:00
Showing only changes of commit b382223b1a - Show all commits

106
dev.sh
View File

@ -18,35 +18,35 @@ MIGRATION_SCHEMA=./migrations
DOCKER_COMPOSE_FILE=./docker/docker-compose.yml DOCKER_COMPOSE_FILE=./docker/docker-compose.yml
_usage() { _usage() {
prog=$(basename "$0") prog=$(basename "$0")
echo "Usage:" echo "Usage:"
echo " $prog back" echo " $prog back"
echo " Apply the migrations, build and run the backend" echo " Apply the migrations, build and run the backend"
echo "" echo ""
echo " $prog front" echo " $prog front"
echo " Install the JS packages and run the frontend" echo " Install the JS packages and run the frontend"
echo "" echo ""
echo " $prog migrate [args]" echo " $prog migrate [args]"
echo " Runs the migrate command with the given parameters" echo " Runs the migrate command with the given parameters"
echo "" echo ""
echo " $prog db-shell" echo " $prog db-shell"
echo " Get a psql shell on the database" echo " Get a psql shell on the database"
echo "" echo ""
echo " $prog db-init" echo " $prog db-init"
echo " Refresh the informations (imdb / movies / shows) needed" echo " Refresh the informations (imdb / movies / shows) needed"
echo " before the first run" echo " before the first run"
echo "" echo ""
echo " $prog docker-db [up|up -d|down|other docker-compose options...]" echo " $prog docker-db [up|up -d|down|other docker-compose options...]"
echo " Setup the database in a docker" echo " Setup the database in a docker"
exit 1 exit 1
} }
_log_info() { _log_info() {
printf "$(tput setaf 5)-->$(tput setaf 2) %s$(tput sgr0)\n" "$@" printf "$(tput setaf 5)-->$(tput setaf 2) %s$(tput sgr0)\n" "$@"
} }
_log_error() { _log_error() {
printf "$(tput setaf 6)-->$(tput setaf 9) %s$(tput sgr0)\n" "$@" printf "$(tput setaf 6)-->$(tput setaf 9) %s$(tput sgr0)\n" "$@"
} }
_check_command() { _check_command() {
@ -86,37 +86,37 @@ _check_command fresh || {
} }
canape_call() { canape_call() {
method=$1 method=$1
resource=$2 resource=$2
_log_info "Calling: $method $resource ..." _log_info "Calling: $method $resource ..."
response=$(curl --silent --show-error \ response=$(curl --silent --show-error \
-X "$method" \ -X "$method" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-H "Authorization: $TOKEN" \ -H "Authorization: $TOKEN" \
"http://localhost:3000/$resource") "http://localhost:3000/$resource")
[ -n "$response" ] && echo "$response" [ -n "$response" ] && echo "$response"
_log_info "Done" _log_info "Done"
} }
canape_login() { canape_login() {
# Skip if the user defined its own token # Skip if the user defined its own token
[ -n "$CANAPE_TOKEN" ] && return [ -n "$CANAPE_TOKEN" ] && return
_log_info "Logging in ..." _log_info "Logging in ..."
json_data=$(jq -n -c --arg username "$CANAPE_USERNAME" \ json_data=$(jq -n -c --arg username "$CANAPE_USERNAME" \
--arg password "$CANAPE_PASS" \ --arg password "$CANAPE_PASS" \
'{username: $username,password: $password}') '{username: $username,password: $password}')
TOKEN=$(curl --silent --show-error -X POST \ TOKEN=$(curl --silent --show-error -X POST \
-d "$json_data" \ -d "$json_data" \
http://localhost:3000/users/login | jq -r .data.token ) http://localhost:3000/users/login | jq -r .data.token )
_log_info "Logged in" _log_info "Logged in"
} }
canape_logout() { canape_logout() {
# Skip if the user defined its own token # Skip if the user defined its own token
[ -n "$CANAPE_TOKEN" ] && return [ -n "$CANAPE_TOKEN" ] && return
_log_info "Disconnecting ..." _log_info "Disconnecting ..."
canape_call DELETE "users/tokens/$TOKEN" canape_call DELETE "users/tokens/$TOKEN"
_log_info "Disconnected" _log_info "Disconnected"
} }
case $1 in case $1 in
@ -147,15 +147,15 @@ case $1 in
(cd frontend && npm install && npm run-script start) (cd frontend && npm install && npm run-script start)
;; ;;
db-init) db-init)
_ensure_command jq _ensure_command jq
canape_login canape_login
canape_call POST ratings/refresh canape_call POST ratings/refresh
canape_call POST movies/refresh canape_call POST movies/refresh
canape_call POST shows/refresh canape_call POST shows/refresh
canape_logout canape_logout
;; ;;
*) *)
_log_error "Unknown command $1" _log_error "Unknown command $1"
_usage _usage
;; ;;
esac esac