diff --git a/scripts/_helpers.sh b/scripts/_helpers.sh new file mode 100644 index 00000000..ffb13127 --- /dev/null +++ b/scripts/_helpers.sh @@ -0,0 +1,8 @@ +ensure_working_directory!() { + root_dir="$(git rev-parse --show-toplevel)" + + if [[ "$PWD" != "$root_dir" ]]; then + echo "Please run the script from the root of the repo: $root_dir" + exit + fi +} diff --git a/scripts/dev/console b/scripts/dev/console index bd71fba9..cca8089e 100755 --- a/scripts/dev/console +++ b/scripts/dev/console @@ -4,4 +4,8 @@ set -e +source "$(dirname "$0")/../_helpers.sh" + +ensure_working_directory! + iex -S mix phx.server diff --git a/scripts/dev/fix-translations b/scripts/dev/fix-translations index add014ff..5f14dbf0 100755 --- a/scripts/dev/fix-translations +++ b/scripts/dev/fix-translations @@ -4,6 +4,10 @@ set -e +source "$(dirname "$0")/../_helpers.sh" + +ensure_working_directory! + git co --theirs priv/gettext/default.pot git co --theirs priv/gettext/en/LC_MESSAGES/default.po diff --git a/scripts/dev/lint b/scripts/dev/lint index a2c009d9..739c0c14 100755 --- a/scripts/dev/lint +++ b/scripts/dev/lint @@ -4,4 +4,8 @@ set -e +source "$(dirname "$0")/../_helpers.sh" + +ensure_working_directory! + mix lint diff --git a/scripts/dev/outdated b/scripts/dev/outdated index 6cb36d46..5265dedb 100755 --- a/scripts/dev/outdated +++ b/scripts/dev/outdated @@ -4,6 +4,10 @@ set -e +source "$(dirname "$0")/../_helpers.sh" + +ensure_working_directory! + npm outdated --prefix assets mix do tailwind.check_version, esbuild.check_version, sqlean.check_version diff --git a/scripts/dev/precommit b/scripts/dev/precommit index 2d37de6b..ca2f4c99 100755 --- a/scripts/dev/precommit +++ b/scripts/dev/precommit @@ -4,4 +4,8 @@ set -e +source "$(dirname "$0")/../_helpers.sh" + +ensure_working_directory! + mix precommit diff --git a/scripts/dev/setup b/scripts/dev/setup index 3e215948..35098bcd 100755 --- a/scripts/dev/setup +++ b/scripts/dev/setup @@ -4,6 +4,10 @@ set -e +source "$(dirname "$0")/../_helpers.sh" + +ensure_working_directory! + # Add the Fluxon UI hex source repo mix hex.repo add fluxon https://repo.fluxonui.com \ diff --git a/scripts/dev/update b/scripts/dev/update index e7465f59..3a85e133 100755 --- a/scripts/dev/update +++ b/scripts/dev/update @@ -4,6 +4,10 @@ set -e +source "$(dirname "$0")/../_helpers.sh" + +ensure_working_directory! + npm update --prefix assets mix do tailwind.update_version, esbuild.update_version, sqlean.update_version diff --git a/scripts/prod/backup b/scripts/prod/backup index 0e82c641..c6f76299 100755 --- a/scripts/prod/backup +++ b/scripts/prod/backup @@ -4,6 +4,10 @@ set -e +source "$(dirname "$0")/../_helpers.sh" + +ensure_working_directory! + current_date=$(date +%s) project_dir=$(git rev-parse --show-toplevel) data_dir="$project_dir/data" diff --git a/scripts/prod/deploy b/scripts/prod/deploy index d51213b2..7bfeea6d 100755 --- a/scripts/prod/deploy +++ b/scripts/prod/deploy @@ -5,4 +5,8 @@ set -e +source "$(dirname "$0")/../_helpers.sh" + +ensure_working_directory! + hurl --test --progress-bar scripts/prod/deploy.hurl diff --git a/scripts/prod/prune-backups b/scripts/prod/prune-backups index d3d5f061..f7abc2b1 100755 --- a/scripts/prod/prune-backups +++ b/scripts/prod/prune-backups @@ -5,4 +5,8 @@ set -e +source "$(dirname "$0")/../_helpers.sh" + +ensure_working_directory! + rm data/music_library_prod*