ayakael.net/tools/test-server.sh

41 lines
1.2 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
2024-09-17 18:39:10 +00:00
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
for i in node npm git; do
if ! command -v $i &> /dev/null; then
echo ">> $i could not be found, please install"
exit
fi
done
# http-server not pulled, pulling
2024-09-17 18:39:10 +00:00
if [ ! -d "$SCRIPT_DIR/http-server" ]; then
echo ">> This script will pull a lightweight nodejs http-server from https://github.com/http-party/http-server and make ./public avaiable as local http service, are you okay with this?"
read -p "Continue (y/n)?" choice
case "$choice" in
y|Y ) echo "yes";;
n|N ) echo "no";;
* ) echo "invalid";;
esac
git clone https://github.com/http-party/http-server
fi
# http-server depends not pulled, pulling
2024-09-17 18:39:10 +00:00
if [ ! -d "$SCRIPT_DIR/http-server/node_modules/" ]; then
echo ">> http-server dependencies not pulled, pulling"
2024-09-17 18:39:10 +00:00
npm --prefix "$SCRIPT_DIR"/http-server i
fi
# website not built, building
2024-09-17 18:39:10 +00:00
if [ ! -d "$SCRIPT_DIR/../public" ]; then
echo ">> website not build, building"
2024-09-17 18:39:10 +00:00
pushd "$SCRIPT_DIR"/..
ikiwiki --setup ./ikiwiki.setup
2024-09-17 18:39:10 +00:00
popd
fi
# starting server
echo ">> starting http server"
2024-09-17 18:39:10 +00:00
node "$SCRIPT_DIR"/http-server/bin/http-server -c-1 "$SCRIPT_DIR"/../public