-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.rb
134 lines (103 loc) · 3.26 KB
/
base.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# encoding: utf-8
if options['skip_gemfile']
puts 'You can not use this template without gemfile, sorry...'
exit 1
end
if options['skip_git']
puts 'R U MAD? NO GIT? GET OUT OF HERE!'
exit 1
end
def remove_comments_for(filename)
gsub_file filename, /^\s*#.*\n/, ''
end
if yes?("Do you want to create a RVM gemset for #{app_name}")
run "/bin/bash -lc 'rvm #{ENV['RUBY_VERSION']}@#{app_name} --create --ruby-version'"
end
git :init
append_file '.gitignore', "/.ruby-*\n"
append_file '.gitignore', "/config/*.yml\n"
Dir['./config/*.yml'].each do |filename|
FileUtils.cp filename, "#{filename}.sample"
end
git add: '.'
git commit: '-m "Rails app base"'
if yes?('Force a Ruby version?')
ruby_version = ask('Which Ruby version:')
gsub_file 'Gemfile', /^(source.*)$/, "\\1\n\nruby " + ruby_version.inspect
end
uncomment_lines 'Gemfile', 'bcrypt' if yes?('Use BCrypt?')
uncomment_lines 'Gemfile', 'unicorn' if yes?('Use Unicorn?')
uncomment_lines 'Gemfile', 'capistrano' if yes?('Use Capistrano?')
comment_lines 'Gemfile', 'coffee'
remove_comments_for 'Gemfile'
gem_group :development do
gem 'brakeman'
gem 'foreman'
gem 'mailcatcher'
gem 'rubocop'
end
gem_group :development, :test do
gem 'dotenv-rails'
gem 'guard-rspec'
gem 'byebug'
gem 'rspec-rails'
end
gem_group :production do
# enable gzip compression on heroku, but don't compress images.
gem 'heroku-deflater' if yes?('Use heroku-deflater?')
# heroku injects it if it's not in there already
gem 'rails_12factor'
gem 'newrelic_rpm' if yes?('Use Newrelic?')
end
run 'bundle install'
git add: '.'
git commit: '-m "gems installed"'
create_file '.env', "SECRET_KEY_BASE=#{`rake secret`}"
generate 'rspec:install'
create_file '.rspec', <<-RSPEC_OPTIONS
--color
--require spec_helper
--format doc
--profile
RSPEC_OPTIONS
run 'guard init rspec'
gsub_file 'Guardfile', 'guard :rspec do', <<-EOF
rspec_options = {
notification: false
}
guard :rspec, options: rspec_options do
EOF
environment 'config.action_mailer.delivery_method = :smtp', env: 'development'
environment 'config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }', env: 'development'
create_file 'Procfile.development', <<-PROCFILE
#worker: sidekiq
#postgres: postgres -D /usr/local/var/postgres
#elastichsearch: elasticsearch --config=/usr/local/opt/elasticsearch/config/elasticsearch.yml
#redis: redis-server /usr/local/etc/redis.conf
mailcatcher: mailcatcher --foreground --verbose
#web: rails server
PROCFILE
git add: '.'
git commit: '-m "Setup development and test gems"'
if yes?('Do you want Home controller?')
generate :controller, :home, 'index --no-view-specs --skip-routes --no-helper --no-assets'
route "root to: 'home#index'"
git add: '.'
git commit: '-m "Home controller created!"'
end
unless options['skip_active_record']
rake 'db:create'
rake 'db:migrate'
rake 'spec' if yes?('Is rspec working?')
end if yes?('Create database?')
if yes?('Remove comments for routes file?')
remove_comments_for 'config/routes.rb'
git add: '.'
git commit: '-m "Removed routes comments"'
end
puts 'TODO:'
puts '- Edit README file'
puts '- Override bin/setup file from https://gist.github.com/tinogomes/5aee18de24ba1115a1f2afdb959187c4'
puts '- Check Procfile.development file'
puts '- Check .env file'
puts '- Go work!'