#!/usr/bin/env ruby

def system!(*args) system(*args, exception: true) end

puts "== Installing dependencies =="
system("gem install bundler --conservative")
system("bundle check") || system!("bundle install")

puts "\n== Preparing database =="
system! "bin/rails db:prepare"
system! "bin/rails db:reset" if ARGV.include?("--reset")

puts "\n== Removing old logs and tempfiles =="
system! "bin/rails log:clear tmp:clear"
