adds a foodsoft:setup_development rake task
This commit is contained in:
parent
2fb7797c12
commit
21c7fa40c1
4 changed files with 180 additions and 11 deletions
41
config/database.yml.MySQL_SAMPLE
Normal file
41
config/database.yml.MySQL_SAMPLE
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# MySQL. Versions 4.1 and 5.0 are recommended.
|
||||||
|
#
|
||||||
|
# Install the MYSQL driver
|
||||||
|
# gem install mysql2
|
||||||
|
#
|
||||||
|
# Ensure the MySQL gem is defined in your Gemfile
|
||||||
|
# gem 'mysql2'
|
||||||
|
#
|
||||||
|
# And be sure to use new-style password hashing:
|
||||||
|
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
|
||||||
|
development:
|
||||||
|
adapter: mysql2
|
||||||
|
encoding: utf8
|
||||||
|
reconnect: false
|
||||||
|
database: foodsoft_development
|
||||||
|
pool: 5
|
||||||
|
host: localhost
|
||||||
|
# socket: /tmp/mysql.sock
|
||||||
|
|
||||||
|
# Warning: The database defined as "test" will be erased and
|
||||||
|
# re-generated from your development database when you run "rake".
|
||||||
|
# Do not set this db to the same as development or production.
|
||||||
|
test:
|
||||||
|
adapter: mysql2
|
||||||
|
encoding: utf8
|
||||||
|
reconnect: false
|
||||||
|
database: foodsoft_test
|
||||||
|
pool: 5
|
||||||
|
host: localhost
|
||||||
|
# socket: /tmp/mysql.sock
|
||||||
|
|
||||||
|
production:
|
||||||
|
adapter: mysql2
|
||||||
|
encoding: utf8
|
||||||
|
reconnect: false
|
||||||
|
database: foodsoft_production
|
||||||
|
pool: 5
|
||||||
|
host: localhost
|
||||||
|
username: root
|
||||||
|
password: password
|
||||||
|
# socket: /tmp/mysql.sock
|
|
@ -5,16 +5,6 @@ development:
|
||||||
pool: 5
|
pool: 5
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
|
|
||||||
# Mysql config instead
|
|
||||||
# database: foodsoft_development
|
|
||||||
# username: root
|
|
||||||
# password:
|
|
||||||
# host: localhost
|
|
||||||
# encoding: utf8
|
|
||||||
# Define a socket, if youre not using standard linux socket, like lampp..
|
|
||||||
# socket: /opt/lampp/var/mysql/mysql.sock
|
|
||||||
|
|
||||||
|
|
||||||
# Warning: The database defined as "test" will be erased and
|
# Warning: The database defined as "test" will be erased and
|
||||||
# re-generated from your development database when you run "rake".
|
# re-generated from your development database when you run "rake".
|
||||||
# Do not set this db to the same as development or production.
|
# Do not set this db to the same as development or production.
|
|
@ -1,6 +1,5 @@
|
||||||
# put in here all foodsoft tasks
|
# put in here all foodsoft tasks
|
||||||
# => :environment loads the environment an gives easy access to the application
|
# => :environment loads the environment an gives easy access to the application
|
||||||
|
|
||||||
namespace :foodsoft do
|
namespace :foodsoft do
|
||||||
desc "Notify users of upcoming tasks"
|
desc "Notify users of upcoming tasks"
|
||||||
task :notify_upcoming_tasks => :environment do
|
task :notify_upcoming_tasks => :environment do
|
||||||
|
|
139
lib/tasks/foodsoft_setup.rake
Normal file
139
lib/tasks/foodsoft_setup.rake
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
# put in here all foodsoft tasks
|
||||||
|
# => :environment loads the environment an gives easy access to the application
|
||||||
|
|
||||||
|
module Colors
|
||||||
|
def colorize(text, color_code)
|
||||||
|
"\033[#{color_code}m#{text}\033[0m"
|
||||||
|
end
|
||||||
|
|
||||||
|
{
|
||||||
|
:black => 30,
|
||||||
|
:red => 31,
|
||||||
|
:green => 32,
|
||||||
|
:yellow => 33,
|
||||||
|
:blue => 34,
|
||||||
|
:magenta => 35,
|
||||||
|
:cyan => 36,
|
||||||
|
:white => 37
|
||||||
|
}.each do |key, color_code|
|
||||||
|
define_method key do |text|
|
||||||
|
colorize(text, color_code)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
include Colors
|
||||||
|
|
||||||
|
require 'stringio'
|
||||||
|
|
||||||
|
namespace :foodsoft do
|
||||||
|
desc "Setup foodsoft"
|
||||||
|
task :setup_development do
|
||||||
|
puts yellow "This task will help you get your foodcoop running in development."
|
||||||
|
setup_bundler
|
||||||
|
setup_app_config
|
||||||
|
setup_development
|
||||||
|
setup_database
|
||||||
|
setup_secret_token
|
||||||
|
puts yellow "All done! Your foodcoft should be running smoothly."
|
||||||
|
start_server
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup_bundler
|
||||||
|
puts "Installing bundler if not installed..."
|
||||||
|
%x( if [ -z `which bundle` ]; then gem install bundler --no-rdoc --no-ri; fi )
|
||||||
|
puts "Executing bundle install..."
|
||||||
|
%x( bundle install )
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup_database
|
||||||
|
file = 'config/database.yml'
|
||||||
|
return nil if skip?(file)
|
||||||
|
|
||||||
|
database = ask("What kind of database do you use?\nOptions:\n(1) MySQL\n(2) SQLite", ["1","2"])
|
||||||
|
if database == "1"
|
||||||
|
puts yellow "Using MySQL..."
|
||||||
|
%x( cp #{Rails.root.join("#{file}.MySQL_SAMPLE")} #{Rails.root.join(file)} )
|
||||||
|
elsif database == "2"
|
||||||
|
puts yellow "Using SQLite..."
|
||||||
|
%x( cp #{Rails.root.join("#{file}.SQLite_SAMPLE")} #{Rails.root.join(file)} )
|
||||||
|
end
|
||||||
|
|
||||||
|
reminder(file)
|
||||||
|
|
||||||
|
puts blue "Setup your database before you continue!"
|
||||||
|
finished = ask("Finished?\nOptions:\n(y) Yes", ["y"])
|
||||||
|
if finished
|
||||||
|
Rake::Task["db:setup"].reenable
|
||||||
|
db_setup = capture_stdout { Rake::Task["db:setup"].invoke }
|
||||||
|
puts db_setup
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup_app_config
|
||||||
|
file = 'config/app_config.yml'
|
||||||
|
return nil if skip?(file)
|
||||||
|
|
||||||
|
puts yellow "Copying #{file}..."
|
||||||
|
%x( cp #{Rails.root.join("#{file}.SAMPLE")} #{Rails.root.join(file)} )
|
||||||
|
reminder(file)
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup_development
|
||||||
|
file = 'config/environments/development.rb'
|
||||||
|
return nil if skip?(file)
|
||||||
|
|
||||||
|
puts yellow "Copying #{file}..."
|
||||||
|
%x( cp #{Rails.root.join("#{file}.SAMPLE")} #{Rails.root.join(file)} )
|
||||||
|
reminder(file)
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup_secret_token
|
||||||
|
file = 'config/initializers/secret_token.rb'
|
||||||
|
return nil if skip?(file)
|
||||||
|
|
||||||
|
puts yellow "Generating secret_token and writing to #{file}..."
|
||||||
|
Rake::Task["secret"].reenable
|
||||||
|
secret = capture_stdout { Rake::Task["secret"].invoke }
|
||||||
|
%x( touch #{Rails.root.join("#{file}")}; echo 'Foodsoft::Application.config.secret_token = "#{secret.chomp}"' > #{Rails.root.join("#{file}")} )
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_server
|
||||||
|
puts blue "Starting server..."
|
||||||
|
%x( bundle exec rails s )
|
||||||
|
if $?.to_i === 0
|
||||||
|
puts blue "visit http://localhost:3000"
|
||||||
|
else
|
||||||
|
puts red "starting server failed!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def ask(question, answers = false)
|
||||||
|
puts question
|
||||||
|
input = STDIN.gets.chomp
|
||||||
|
if input.blank? or (answers and !answers.include?(input))
|
||||||
|
puts red "Your Input is not valid. Try again!"
|
||||||
|
input = ask(question, answers)
|
||||||
|
end
|
||||||
|
input
|
||||||
|
end
|
||||||
|
|
||||||
|
def skip?(file)
|
||||||
|
output = false
|
||||||
|
skip = ask(cyan("We found #{file}!\nOptions:\n(1) Skip step\n(2) Force rewrite"), ["1","2"]) if File.exists?(Rails.root.join(file))
|
||||||
|
output = true if skip == "1"
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
|
def reminder(file)
|
||||||
|
puts blue "don't forget to edit #{file}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def capture_stdout
|
||||||
|
s = StringIO.new
|
||||||
|
$stdout = s
|
||||||
|
yield
|
||||||
|
s.string
|
||||||
|
ensure
|
||||||
|
$stdout = STDOUT
|
||||||
|
end
|
Loading…
Reference in a new issue