fix to use with sveltekit
This commit is contained in:
54
bin/helper/fn
Executable file
54
bin/helper/fn
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
|
||||
abort() {
|
||||
printf "\n \033[31mError: $@\033[0m\n\n" && exit 1
|
||||
}
|
||||
|
||||
ok() {
|
||||
printf "\n \033[32mOk: $@\033[0m\n\n"
|
||||
}
|
||||
|
||||
load_env() {
|
||||
_DIR="$(pwd)"
|
||||
ENVFILE_LOCAL="${2:-$_DIR}/.conf/local.sh"
|
||||
ENVFILE_OPT="${2:-$_DIR}/.conf/${1:-development}.sh"
|
||||
USE_LOCAL_ENV=0
|
||||
|
||||
if test ! -e $ENVFILE_OPT; then
|
||||
abort "Environment file not found"
|
||||
fi
|
||||
|
||||
set -a
|
||||
. ${ENVFILE_OPT}
|
||||
set +a
|
||||
|
||||
if test "${1}" = "development" -o "${1}" = "test"; then
|
||||
USE_LOCAL_ENV=1
|
||||
fi
|
||||
|
||||
if test -e $ENVFILE_LOCAL -a "${USE_LOCAL_ENV:-0}" = "1"; then
|
||||
set -a
|
||||
. ${ENVFILE_LOCAL}
|
||||
set +a
|
||||
fi
|
||||
}
|
||||
|
||||
gen_env() {
|
||||
_DIR="$(cd $(dirname $0) && pwd)"
|
||||
_BIN_DIR="$(cd $DIR/.. && pwd)"
|
||||
GEN_ENV="${2:-$_BIN_DIR}/node/env.js"
|
||||
|
||||
if test -z $1; then
|
||||
abort "Missing output"
|
||||
fi
|
||||
|
||||
if test ! -f "${GEN_ENV}"; then
|
||||
abort "File not found: ${GEN_ENV}"
|
||||
fi
|
||||
|
||||
_DIR_FILE=$(dirname $1)
|
||||
mkdir -p $_DIR_FILE
|
||||
|
||||
$GEN_ENV > $1
|
||||
ok "ENVs generated... ${1}"
|
||||
}
|
||||
32
bin/helper/wait
Executable file
32
bin/helper/wait
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
: ${SLEEP_LENGTH:=2}
|
||||
: ${TIMEOUT_LENGTH:=60}
|
||||
|
||||
DIR="$(cd $(dirname $0) && pwd)"
|
||||
BIN_DIR="$(cd $DIR/.. && pwd)"
|
||||
|
||||
# Import functions
|
||||
. $BIN_DIR/helper/fn
|
||||
|
||||
wait_for() {
|
||||
START="$(date +%s)"
|
||||
echo "Waiting for $1 to listen on $2..."
|
||||
while ! nc -z $1 $2; do
|
||||
if [ $(($(date +%s) - $START)) -gt $TIMEOUT_LENGTH ]; then
|
||||
abort "Service $1:$2 did not start within $TIMEOUT_LENGTH seconds. Aborting..."
|
||||
fi
|
||||
echo "sleeping"
|
||||
sleep $SLEEP_LENGTH
|
||||
done
|
||||
}
|
||||
|
||||
for var in "$@"
|
||||
do
|
||||
host=${var%:*}
|
||||
port=${var#*:}
|
||||
wait_for $host $port
|
||||
ok "Listening ${host}:${port}"
|
||||
done
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user