rubyforgood/casa

View on GitHub
bin/setup

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
require 'fileutils'

# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)

def system!(*args)
  system(*args, exception: true) || abort("\n== Command #{args} failed ==")
end

FileUtils.chdir APP_ROOT do
  # This script is a way to set up or update your development environment automatically.
  # This script is idempotent, so that you can run it at any time and get an expectable outcome.
  # Add necessary setup steps to this file.
  expected_ruby_version = `cat .ruby-version`.chomp
  current_ruby_version = `ruby -v`.chomp
  unless current_ruby_version.include?(expected_ruby_version)
    puts "Ruby version must be #{expected_ruby_version}. You are on #{current_ruby_version}"
    exit
  end

  puts "\n== Installing dependencies =="
  system! 'gem install foreman'
  system! 'gem install bundler --conservative'
  system!('bundle update --bundler --verbose')
  system!('bundle check') || system!('bundle install')

  # puts '\n== Copying sample files =='
  # unless File.exist?('config/database.yml')
  #   FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
  # end

  unless File.exist?('.env')
    puts "\n== Setup .env file from .env.example =="
    system!('cp .env.example .env')
  end

  puts "\n== Preparing database =="
  puts '⚠️  If you use docker to run postgres, make sure your database is running ⚠️'
  system! 'bin/rails db:reset'
  system! 'bin/rails db:test:prepare'

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

  puts "\n== Restarting application server =="
  system! 'bin/rails restart'

  puts "\n== Running post-deployment tasks =="
  system! 'bin/rake after_party:run'

  puts "\n== Installing yarn packages =="
  system!('yarn') || abort('install yarn and try again')

  puts "\n==Building assets =="
  system!('yarn build')
  system!('yarn build:css')

  puts "\n== Done =="
end