HabitatMap/AirCasting

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) || abort("\n== Command #{args} failed ==")
end

def brew!(formula)
  system! "brew ls --versions #{formula} > /dev/null || brew install #{formula}"
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.

  puts '== Installing dependencies =='
  system! 'gem install bundler:2.3.4'
  brew!('gsl')
  brew!('imagemagick')
  brew!('redis')
  brew!('postgresql')
  brew!('yarn')

  system('bundle check') || system!('bundle install')
  system! 'gem install foreman'

  # Install JavaScript dependencies
  system! 'yarn install'

  puts "\n== Copying sample files =="
  if File.exist?('config/database.yml.example') && !File.exist?('config/database.yml')
    config_content = File.read('config/database.yml.example')

    updated_config = config_content.gsub(/username: .*/, "username: #{ENV['USER']}")

    File.open('config/database.yml', 'w') { |file| file.write(updated_config) }

    puts '== Updated database.yml with the current system username (postgres installed through brew sets it up this way) =='
  end

  unless File.exist?('config/configuration.yml')
    puts "\n== ⚠️  Make sure to copy in config/configuration.yml the correct secrets (e.g., Playing-Zone) ⚠️  =="
    system('cp config/configuration.yml.example config/configuration.yml')
  end

  puts "\n== Preparing database =="
  system! 'bin/rails db: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== Done! Get back to the readme to see how to run the application =="
end