@@ -1,26 +1,72 @@
|
||||
#!/usr/bin/env ruby
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
|
||||
require "mkmf"
|
||||
def system!(*args) system(*args, exception: true) end
|
||||
# Prefer app executables
|
||||
app_root="$(cd "$(dirname "$0")/.."; pwd)"
|
||||
export PATH="$app_root/bin:$PATH"
|
||||
|
||||
puts "\n== Installing Ruby and Node =="
|
||||
system("mise install -y")
|
||||
# Install gum if needed
|
||||
if ! command -v gum &> /dev/null; then
|
||||
echo
|
||||
echo "▸ Installing gum"
|
||||
if command -v pacman &> /dev/null; then
|
||||
sudo pacman -S --noconfirm gum
|
||||
elif command -v brew &> /dev/null; then
|
||||
brew install gum
|
||||
else
|
||||
echo "Please install gum: https://github.com/charmbracelet/gum"
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
fi
|
||||
|
||||
puts "\n== Installing dependencies =="
|
||||
if MakeMakefile.find_executable0("pacman")
|
||||
packages = "imagemagick openslide"
|
||||
system("pacman -Q #{packages} || sudo pacman -S --noconfirm --needed #{packages}")
|
||||
end
|
||||
system("gem install bundler --conservative")
|
||||
system("bundle config set --local auto_install true")
|
||||
system("bundle check") || system!("bundle install")
|
||||
step() {
|
||||
local no_spin=false
|
||||
if [[ "$1" == "--no-spin" ]]; then
|
||||
no_spin=true
|
||||
shift
|
||||
fi
|
||||
|
||||
puts "\n== Preparing database =="
|
||||
if ARGV.include?("--reset")
|
||||
system! "bin/rails db:drop db:create db:schema:load db:prepare db:seed"
|
||||
local step_name="$1"
|
||||
shift
|
||||
|
||||
gum style --foreground 33 --bold "▸ $step_name"
|
||||
gum style --foreground 240 "$*"
|
||||
|
||||
if $no_spin; then
|
||||
"$@"
|
||||
else
|
||||
gum spin --spinner dot --title "" --show-output -- "$@"
|
||||
fi
|
||||
|
||||
local exit_code=$?
|
||||
echo
|
||||
return $exit_code
|
||||
}
|
||||
|
||||
echo
|
||||
gum style --foreground 153 " ˚ ∘ ∘ ˚ "
|
||||
gum style --foreground 111 --bold " ∘˚˳°∘° 𝒻𝒾𝓏𝓏𝓎 °∘°˳˚∘ "
|
||||
echo
|
||||
|
||||
step --no-spin "Installing Ruby" mise install --yes
|
||||
|
||||
if which pacman >/dev/null 2>&1; then
|
||||
packages=(imagemagick openslide)
|
||||
if ! pacman -Q "${packages[@]}" >/dev/null 2>&1; then
|
||||
step "Installing packages" sudo pacman -S --noconfirm --needed "${packages[@]}"
|
||||
fi
|
||||
fi
|
||||
|
||||
bundle config set --local auto_install true
|
||||
step "Installing RubyGems" bundle install
|
||||
|
||||
if [[ $* == *--reset* ]]; then
|
||||
step "Resetting the database" rails db:reset
|
||||
else
|
||||
system! "bin/rails db:prepare"
|
||||
end
|
||||
step "Preparing the database" rails db:prepare
|
||||
fi
|
||||
|
||||
puts "\n== Removing old logs and tempfiles =="
|
||||
system! "bin/rails log:clear tmp:clear"
|
||||
step "Cleaning up logs and tempfiles" rails log:clear tmp:clear
|
||||
|
||||
gum style --foreground 46 "✓ Done (${SECONDS} sec)"
|
||||
|
||||
Reference in New Issue
Block a user