-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.rb
241 lines (193 loc) · 5.17 KB
/
template.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
git :init
git add: "."
git commit: "-a -m 'Initial commit'"
gem_group :development, :test do
gem "bundler-audit", require: false
gem "dotenv-rails"
gem "pronto-brakeman", require: false
gem "pronto-fasterer", require: false
gem "pronto-flay", require: false
gem "pronto-rails_best_practices", require: false
gem "pronto-reek", require: false
gem "pronto-rubocop", require: false
gem "pronto-simplecov", require: false
gem "pronto", require: false
gem "pry-rails"
gem "ruby_audit", require: false
end
gem_group :development do
gem "bullet"
gem "letter_opener_web"
end
gem_group :test do
gem "minitest-ci"
gem "simplecov", require: false
end
gem "ar-uuid"
# pry-rails gem
file ".pryrc", <<-CODE
if defined?(PryRails::RAILS_PROMPT)
Pry.config.prompt = PryRails::RAILS_PROMPT
end
CODE
# bullet gem
environment nil, env: "development" do
<<-CODE
config.after_initialize do
Bullet.enable = true
Bullet.alert = true
Bullet.bullet_logger = true
Bullet.console = true
Bullet.rails_logger = true
Bullet.add_footer = true
end
CODE
end
# dotenv-rails gem
file ".env", ""
file ".env.development", ""
file ".env.local", ""
file ".env.test", ""
run "echo '.env.local' >> .gitignore"
# minitest-ci gem
run "echo '/test/reports' >> .gitignore"
# letter_opener_web gem
environment "config.action_mailer.delivery_method = :letter_opener_web",
env: "development"
route <<-CODE
mount LetterOpenerWeb::Engine, at: '/sent_emails' if Rails.env.development?
CODE
file ".rubocop.yml", <<-CODE
Metrics/BlockLength:
Exclude:
- 'config/environments/development.rb'
Metrics/LineLength:
Max: 130
Style/ClassAndModuleChildren:
Exclude:
- 'test/test_helper.rb'
Style/Documentation:
Exclude:
- 'app/helpers/application_helper.rb'
- 'app/mailers/application_mailer.rb'
- 'app/models/application_record.rb'
- 'config/application.rb'
- 'spec/**/*'
- 'test/**/*'
- 'vendor/**/*'
Style/MixinUsage:
Exclude:
- 'bin/setup'
- 'bin/update'
CODE
# simplecov gem
run "echo 'coverage' >> .gitignore"
prepend_to_file "test/test_helper.rb", "require 'simplecov'\n"
file ".simplecov", <<-CODE
SimpleCov.start 'rails' do
# any custom configs like groups and filters can be here at a central place
end
CODE
# rvm
file ".ruby-gemset", "#{app_name}"
run "rvm gemset create #{app_name}"
# CircleCI
file ".circleci/config.yml", <<-CODE
version: 2
jobs:
build:
parallelism: 1
docker:
- image: circleci/ruby:2.5.1-node-browsers
- image: circleci/postgres:9.6.9-alpine-ram
environment:
RAILS_ENV: "test"
PGHOST: "localhost"
PGUSER: "postgres"
steps:
- checkout
- restore_cache:
keys:
- gem-cache-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- gem-cache-{{ checksum "Gemfile.lock" }}
- gem-cache
# For rugged gem (pronto gem dependency)
- run: sudo apt-get install cmake
- run:
name: Bundle Install
command: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
- run:
name: Ruby Audit
command: bundle exec ruby-audit check
- run:
name: Bundle Audit
command: bundle exec bundle-audit check --update
- run:
name: Brakeman
command: bundle exec brakeman
- run:
name: Rubocop
command: bundle exec rubocop
# Store bundle cache
- save_cache:
key: gem-cache-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- save_cache:
key: gem-cache-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- save_cache:
key: gem-cache
paths:
- vendor/bundle
- run:
name: Set up DB
command: bundle exec rails db:setup
- run:
name: Rails Test
command: bundle exec rake test
- store_test_results:
path: test/reports
destination: test-results/rails
- store_artifacts:
path: test/reports
destination: test-results/MiniTest
- store_artifacts:
path: coverage
destination: coverage
CODE
# README
file "README.md", <<-CODE
## Getting Started
1. Install [Homebrew](https://brew.sh/):
```sh
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```
2. Install OpenSSL libraries:
```sh
brew install openssl
```
3. Install RVM and Ruby:
```sh
curl -sSL https://get.rvm.io | bash -s stable
# In a new session (restart your terminal or open new tab):
rvm install 2.5.1 --default --with-openssl-dir=`brew --prefix openssl`
```
4. Set up RVM gemset:
```sh
rvm gemset create #{app_name}
rvm use 2.5.1@#{app_name}
gem update --system
gem update bundler
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=`xcrun --show-sdk-path`/usr/include/libxml2
```
CODE
after_bundle do
run "bundle install"
rails_command("db:create")
rails_command("db:migrate")
run "rubocop -a"
git add: "."
git commit: "-a -m 'Set up development environment'"
end