improve piston shell script
- fix portability & using piston within a symlink - only install cli npm modules on update or first use - allow building packages with custom builder - fix all shellchecks except SC2164
This commit is contained in:
parent
90945d1621
commit
198d8ff061
29
piston
29
piston
|
@ -1,7 +1,10 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
cd "$(dirname "$0")"
|
|
||||||
|
|
||||||
PISTON_ENV=$(cat .piston_env || echo dev)
|
EXECUTION_PATH="$PWD"
|
||||||
|
PISTON_PATH="$(dirname "$(realpath "$0")")"
|
||||||
|
|
||||||
|
cd "$PISTON_PATH"
|
||||||
|
PISTON_ENV=$(cat .piston_env 2> /dev/null || echo dev)
|
||||||
|
|
||||||
docker_compose(){
|
docker_compose(){
|
||||||
if [ -f "docker-compose.$PISTON_ENV.yaml" ]; then
|
if [ -f "docker-compose.$PISTON_ENV.yaml" ]; then
|
||||||
|
@ -32,11 +35,12 @@ case $1 in
|
||||||
echo
|
echo
|
||||||
echo "Development Commands:"
|
echo "Development Commands:"
|
||||||
|
|
||||||
if [ $PISTON_ENV == dev ]; then
|
if [ "$PISTON_ENV" == dev ]; then
|
||||||
|
|
||||||
echo " clean-pkgs Clean any package build artifacts on disk"
|
echo " clean-pkgs Clean any package build artifacts on disk"
|
||||||
echo " clean-repo Remove all packages from local repo"
|
echo " clean-repo Remove all packages from local repo"
|
||||||
echo " build-pkg <package> <version> Build a package"
|
echo " list-pkgs Lists all packages that can be built"
|
||||||
|
echo " build-pkg <package> <version> [builder] Build a package [with desired builder image]"
|
||||||
echo " rebuild Build and restart the docker container"
|
echo " rebuild Build and restart the docker container"
|
||||||
echo " lint Lint the codebase using prettier"
|
echo " lint Lint the codebase using prettier"
|
||||||
|
|
||||||
|
@ -56,7 +60,7 @@ case $1 in
|
||||||
restart) docker_compose restart ;;
|
restart) docker_compose restart ;;
|
||||||
start)
|
start)
|
||||||
rm -f .git/hooks/pre-commit
|
rm -f .git/hooks/pre-commit
|
||||||
ln -s $(realpath $(dirname "$0"))/pre-commit .git/hooks/pre-commit
|
ln -s "$PISTON_PATH/pre-commit" "$PISTON_PATH/.git/hooks/pre-commit"
|
||||||
docker_compose up -d
|
docker_compose up -d
|
||||||
;;
|
;;
|
||||||
stop) docker_compose down ;;
|
stop) docker_compose down ;;
|
||||||
|
@ -66,6 +70,7 @@ case $1 in
|
||||||
|
|
||||||
update)
|
update)
|
||||||
git pull
|
git pull
|
||||||
|
cd cli && npm i > /dev/null && cd -
|
||||||
docker_compose pull
|
docker_compose pull
|
||||||
docker_compose up -d
|
docker_compose up -d
|
||||||
;;
|
;;
|
||||||
|
@ -73,12 +78,15 @@ case $1 in
|
||||||
clean-pkgs) git clean -fqXd packages ;;
|
clean-pkgs) git clean -fqXd packages ;;
|
||||||
clean-repo) git clean -fqXd repo ;;
|
clean-repo) git clean -fqXd repo ;;
|
||||||
|
|
||||||
|
list-pkgs) find packages -depth 2 | awk -F/ '$2 && $3{ print $2 "-" $3 }' | column ;;
|
||||||
|
|
||||||
build-pkg)
|
build-pkg)
|
||||||
PKGSLUG="$2-$3"
|
PKGSLUG="$2-$3"
|
||||||
|
BUILDER="${4:-piston-repo-builder}"
|
||||||
echo "Building $PKGSLUG"
|
echo "Building $PKGSLUG"
|
||||||
echo "Ensuring latest builder image"
|
echo "Ensuring latest builder image"
|
||||||
docker build repo -t piston-repo-builder
|
docker build repo -t "$BUILDER"
|
||||||
docker run --rm -v "$(realpath $(dirname "$0")):/piston" piston-repo-builder --no-server $PKGSLUG
|
docker run --rm -v "$PWD:/piston" "$BUILDER" --no-server "$PKGSLUG"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
lint)
|
lint)
|
||||||
|
@ -86,9 +94,8 @@ case $1 in
|
||||||
npx prettier --ignore-unknown --write .
|
npx prettier --ignore-unknown --write .
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
cd cli
|
[ -d ./cli/node_modules ] || npm i > /dev/null
|
||||||
npm i > /dev/null
|
cd "$EXECUTION_PATH"
|
||||||
cd ../
|
node "${PISTON_PATH}/cli/index.js" "$@"
|
||||||
node cli/index.js "$@"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in New Issue