hugopl/reviewit

View on GitHub
bin/setup

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby

require 'bundler/setup'
require 'fileutils'
require 'securerandom'
require 'pathname'
require 'rake'
require 'webpush'

def main
  Bundler.setup

  app_root = Pathname.new File.expand_path('../../',  __FILE__)
  Dir.chdir(app_root) do
    create_database_yml
    create_reviewit_yml
  end
  run_rake_tasks
end

def run_rake_tasks
  rake = Rake.application
  rake.init
  rake.load_rakefile
  rake['db:create'].invoke
  rake['db:schema:load'].invoke
  rake['build_cli_gem'].invoke
end

def create_database_yml
  return if File.exist?('config/database.yml')
  File.open('config/database.yml', 'w') do |file|
    file.write <<eos
production:
  adapter: postgresql
  encoding: UTF8
  database: reviewit
development:
  adapter: postgresql
  encoding: UTF8
  database: reviewit_dev
test:
  adapter: postgresql
  encoding: UTF8
  database: reviewit_test
eos
  end

end

def create_reviewit_yml
  return if File.exist?('config/reviewit.yml')

  vapid_key = Webpush.generate_key
  File.open('config/reviewit.yml', 'w') do |file|
    file.write <<eos
# Changing this key will render invalid all existing confirmation,
# reset password and unlock tokens in the database.
secret_key: #{SecureRandom.hex(64)}
# E-mail configuration, for more info see:
# http://edgeguides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration
mail:
  sender: foo@bar.com
  host: foo.bar.com
  delivery_method: file
  address:
  port:
  domain:
  authentication:
  user_name:
  password:
  openssl_verify_mode:
  enable_starttls_auto:
  store_location: /tmp/mails
webpush_public_key: #{vapid_key.public_key}
webpush_private_key: #{vapid_key.private_key}
eos
  end
end

main if __FILE__ == $PROGRAM_NAME