underlay 1.50.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.rubocop.yml +87 -0
- data/.ruby-version +1 -0
- data/CONTRIBUTING.md +46 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +218 -0
- data/RELEASING.md +16 -0
- data/Rakefile +10 -0
- data/USAGE +13 -0
- data/bin/rake +18 -0
- data/bin/rspec +18 -0
- data/bin/setup +13 -0
- data/bin/underlay +29 -0
- data/circle.yml +3 -0
- data/lib/underlay/actions.rb +41 -0
- data/lib/underlay/adapters/heroku.rb +133 -0
- data/lib/underlay/app_builder.rb +556 -0
- data/lib/underlay/generators/app_generator.rb +280 -0
- data/lib/underlay/generators/enforce_ssl_generator.rb +14 -0
- data/lib/underlay/generators/initialize_active_job_generator.rb +21 -0
- data/lib/underlay/generators/static_generator.rb +12 -0
- data/lib/underlay/generators/stylesheet_base_generator.rb +36 -0
- data/lib/underlay/version.rb +10 -0
- data/lib/underlay.rb +11 -0
- data/spec/adapters/heroku_spec.rb +78 -0
- data/spec/fakes/bin/heroku +9 -0
- data/spec/fakes/bin/hub +9 -0
- data/spec/features/cli_help_spec.rb +38 -0
- data/spec/features/github_spec.rb +18 -0
- data/spec/features/heroku_spec.rb +72 -0
- data/spec/features/new_project_spec.rb +308 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/fake_github.rb +26 -0
- data/spec/support/fake_heroku.rb +58 -0
- data/spec/support/underlay.rb +100 -0
- data/templates/Gemfile.erb +81 -0
- data/templates/Procfile +2 -0
- data/templates/README.md.erb +21 -0
- data/templates/_analytics.html.slim +10 -0
- data/templates/_css_overrides.html.slim +5 -0
- data/templates/_flashes.html.slim +8 -0
- data/templates/_flashes.scss +21 -0
- data/templates/_javascript.html.slim +10 -0
- data/templates/action_mailer.rb +7 -0
- data/templates/active_job.rb +15 -0
- data/templates/app.json.erb +45 -0
- data/templates/application.example.yml +19 -0
- data/templates/application.scss +5 -0
- data/templates/bin_deploy +12 -0
- data/templates/bin_rake +12 -0
- data/templates/bin_setup +31 -0
- data/templates/bin_setup_review_app.erb +22 -0
- data/templates/bin_update +26 -0
- data/templates/browserslist +3 -0
- data/templates/bundler_audit.rake +6 -0
- data/templates/capybara.rb +22 -0
- data/templates/circle.yml.erb +38 -0
- data/templates/config_locales_en.yml.erb +19 -0
- data/templates/database_cleaner_rspec.rb +23 -0
- data/templates/dev.rake +14 -0
- data/templates/dvelp_gitignore +18 -0
- data/templates/dvelp_layout.html.slim +17 -0
- data/templates/errors.rb +36 -0
- data/templates/factories.rb +4 -0
- data/templates/factory_bot_rspec.rb +5 -0
- data/templates/flashes_helper.rb +7 -0
- data/templates/i18n.rb +5 -0
- data/templates/json_encoding.rb +3 -0
- data/templates/lograge.rb +11 -0
- data/templates/postgresql_database.yml.erb +19 -0
- data/templates/puma.rb +14 -0
- data/templates/rack_mini_profiler.rb +7 -0
- data/templates/rails_helper.rb +27 -0
- data/templates/rubocop.yml.erb +85 -0
- data/templates/scss-lint.yml.erb +167 -0
- data/templates/secrets.yml +8 -0
- data/templates/sentry.rb +6 -0
- data/templates/shoulda_matchers_config_rspec.rb +8 -0
- data/templates/sidekiq.yml +3 -0
- data/templates/slim-lint.yml.erb +28 -0
- data/templates/smtp.rb +15 -0
- data/templates/spec_helper.rb +35 -0
- data/underlay.gemspec +33 -0
- metadata +187 -0
@@ -0,0 +1,133 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Underlay
|
4
|
+
module Adapters
|
5
|
+
class Heroku
|
6
|
+
def initialize(app_builder)
|
7
|
+
@app_builder = app_builder
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_heroku_remotes
|
11
|
+
remotes = <<~SHELL
|
12
|
+
#{command_to_join_heroku_app('staging')}
|
13
|
+
#{command_to_join_heroku_app('production')}
|
14
|
+
|
15
|
+
git config heroku.remote staging
|
16
|
+
SHELL
|
17
|
+
|
18
|
+
app_builder.append_file 'bin/setup', remotes
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_staging_heroku_app(flags)
|
22
|
+
app_name = heroku_app_name_for('staging')
|
23
|
+
|
24
|
+
run_toolbelt_command "create #{app_name} #{flags}", 'staging'
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_production_heroku_app(flags)
|
28
|
+
app_name = heroku_app_name_for('production')
|
29
|
+
|
30
|
+
run_toolbelt_command "create #{app_name} #{flags}", 'production'
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_heroku_rails_secrets
|
34
|
+
%w[staging production].each do |environment|
|
35
|
+
run_toolbelt_command(
|
36
|
+
"config:add SECRET_KEY_BASE=#{generate_secret}",
|
37
|
+
environment
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_heroku_backup_schedule
|
43
|
+
%w[staging production].each do |environment|
|
44
|
+
run_toolbelt_command(
|
45
|
+
"pg:backups:schedule DATABASE_URL --at '10:00 UTC'",
|
46
|
+
environment
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_review_apps_setup_script
|
52
|
+
app_builder.template(
|
53
|
+
'bin_setup_review_app.erb',
|
54
|
+
'bin/setup_review_app',
|
55
|
+
force: true
|
56
|
+
)
|
57
|
+
app_builder.run 'chmod a+x bin/setup_review_app'
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_heroku_application_manifest_file
|
61
|
+
app_builder.template 'app.json.erb', 'app.json'
|
62
|
+
end
|
63
|
+
|
64
|
+
def create_heroku_pipeline
|
65
|
+
pipelines_plugin = `heroku help | grep pipelines`
|
66
|
+
if pipelines_plugin.empty?
|
67
|
+
puts(
|
68
|
+
'You need heroku pipelines plugin.' \
|
69
|
+
'Run: brew upgrade heroku-toolbelt'
|
70
|
+
)
|
71
|
+
exit 1
|
72
|
+
end
|
73
|
+
|
74
|
+
run_toolbelt_command(
|
75
|
+
"pipelines:create #{heroku_app_name} \
|
76
|
+
-a #{heroku_app_name}-staging --stage staging",
|
77
|
+
'staging'
|
78
|
+
)
|
79
|
+
|
80
|
+
run_toolbelt_command(
|
81
|
+
"pipelines:add #{heroku_app_name} \
|
82
|
+
-a #{heroku_app_name}-production --stage production",
|
83
|
+
'production'
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
def set_heroku_application_host
|
88
|
+
%w[staging production].each do |environment|
|
89
|
+
run_toolbelt_command(
|
90
|
+
"config:add APPLICATION_HOST=#{heroku_app_name}-#{environment}"\
|
91
|
+
'.herokuapp.com',
|
92
|
+
environment
|
93
|
+
)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
attr_reader :app_builder
|
100
|
+
|
101
|
+
def command_to_join_heroku_app(environment)
|
102
|
+
heroku_app_name = heroku_app_name_for(environment)
|
103
|
+
<<~SHELL
|
104
|
+
|
105
|
+
if heroku join --app #{heroku_app_name} > /dev/null 2>&1; then
|
106
|
+
git remote add #{environment} git@heroku.com:#{heroku_app_name}.git || true
|
107
|
+
printf 'You are a collaborator on the "#{heroku_app_name}" Heroku app\n'
|
108
|
+
else
|
109
|
+
printf 'Ask for access to the "#{heroku_app_name}" Heroku app\n'
|
110
|
+
fi
|
111
|
+
SHELL
|
112
|
+
end
|
113
|
+
|
114
|
+
def heroku_app_name
|
115
|
+
app_builder.app_name.dasherize
|
116
|
+
end
|
117
|
+
|
118
|
+
def heroku_app_name_for(environment)
|
119
|
+
"#{heroku_app_name}-#{environment}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def generate_secret
|
123
|
+
SecureRandom.hex(64)
|
124
|
+
end
|
125
|
+
|
126
|
+
def run_toolbelt_command(command, environment)
|
127
|
+
app_builder.run(
|
128
|
+
"heroku #{command} --remote #{environment}"
|
129
|
+
)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,556 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module Underlay
|
6
|
+
class AppBuilder < Rails::AppBuilder
|
7
|
+
include Underlay::Actions
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def_delegators(
|
11
|
+
:heroku_adapter,
|
12
|
+
:create_heroku_application_manifest_file,
|
13
|
+
:create_heroku_pipeline,
|
14
|
+
:create_production_heroku_app,
|
15
|
+
:create_review_apps_setup_script,
|
16
|
+
:create_staging_heroku_app,
|
17
|
+
:set_heroku_application_host,
|
18
|
+
:set_heroku_backup_schedule,
|
19
|
+
:set_heroku_rails_secrets,
|
20
|
+
:set_heroku_remotes
|
21
|
+
)
|
22
|
+
|
23
|
+
def readme
|
24
|
+
template 'README.md.erb', 'README.md'
|
25
|
+
end
|
26
|
+
|
27
|
+
def gitignore
|
28
|
+
copy_file 'dvelp_gitignore', '.gitignore'
|
29
|
+
end
|
30
|
+
|
31
|
+
def gemfile
|
32
|
+
template 'Gemfile.erb', 'Gemfile'
|
33
|
+
end
|
34
|
+
|
35
|
+
def setup_rack_mini_profiler
|
36
|
+
copy_file(
|
37
|
+
'rack_mini_profiler.rb',
|
38
|
+
'config/initializers/rack_mini_profiler.rb'
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def raise_on_missing_assets_in_test
|
43
|
+
configure_environment 'test', 'config.assets.raise_runtime_errors = true'
|
44
|
+
end
|
45
|
+
|
46
|
+
def raise_on_delivery_errors
|
47
|
+
replace_in_file 'config/environments/development.rb',
|
48
|
+
'raise_delivery_errors = false', 'raise_delivery_errors = true'
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_test_delivery_method
|
52
|
+
inject_into_file(
|
53
|
+
'config/environments/development.rb',
|
54
|
+
"\n config.action_mailer.delivery_method = :file",
|
55
|
+
after: 'config.action_mailer.raise_delivery_errors = true'
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_bullet_gem_configuration
|
60
|
+
config = <<-RUBY
|
61
|
+
config.after_initialize do
|
62
|
+
Bullet.enable = true
|
63
|
+
Bullet.bullet_logger = true
|
64
|
+
Bullet.rails_logger = true
|
65
|
+
end
|
66
|
+
|
67
|
+
RUBY
|
68
|
+
|
69
|
+
inject_into_file(
|
70
|
+
'config/environments/development.rb',
|
71
|
+
config,
|
72
|
+
after: "config.action_mailer.raise_delivery_errors = true\n"
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def raise_on_unpermitted_parameters
|
77
|
+
config = <<-RUBY
|
78
|
+
config.action_controller.action_on_unpermitted_parameters = :raise
|
79
|
+
RUBY
|
80
|
+
|
81
|
+
inject_into_class 'config/application.rb', 'Application', config
|
82
|
+
end
|
83
|
+
|
84
|
+
def configure_quiet_assets
|
85
|
+
config = <<-RUBY
|
86
|
+
config.assets.quiet = true
|
87
|
+
RUBY
|
88
|
+
|
89
|
+
inject_into_class 'config/application.rb', 'Application', config
|
90
|
+
end
|
91
|
+
|
92
|
+
def provide_setup_script
|
93
|
+
template 'bin_setup', 'bin/setup', force: true
|
94
|
+
run 'chmod a+x bin/setup'
|
95
|
+
end
|
96
|
+
|
97
|
+
def provide_rake_script
|
98
|
+
template 'bin_rake', 'bin/rake', force: true
|
99
|
+
run 'chmod a+x bin/rake'
|
100
|
+
end
|
101
|
+
|
102
|
+
def provide_update_script
|
103
|
+
template 'bin_setup', 'bin/update', force: true
|
104
|
+
run 'chmod a+x bin/update'
|
105
|
+
end
|
106
|
+
|
107
|
+
def provide_dev_prime_task
|
108
|
+
copy_file 'dev.rake', 'lib/tasks/dev.rake'
|
109
|
+
end
|
110
|
+
|
111
|
+
def configure_generators
|
112
|
+
config = <<-RUBY
|
113
|
+
|
114
|
+
config.generators do |generate|
|
115
|
+
generate.helper false
|
116
|
+
generate.javascripts false
|
117
|
+
generate.request_specs false
|
118
|
+
generate.routing_specs false
|
119
|
+
generate.stylesheets false
|
120
|
+
generate.test_framework :rspec
|
121
|
+
generate.view_specs false
|
122
|
+
end
|
123
|
+
|
124
|
+
RUBY
|
125
|
+
|
126
|
+
inject_into_class 'config/application.rb', 'Application', config
|
127
|
+
end
|
128
|
+
|
129
|
+
def set_up_factory_bot_for_rspec
|
130
|
+
copy_file 'factory_bot_rspec.rb', 'spec/support/factory_bot.rb'
|
131
|
+
end
|
132
|
+
|
133
|
+
def generate_factories_file
|
134
|
+
copy_file 'factories.rb', 'spec/factories.rb'
|
135
|
+
end
|
136
|
+
|
137
|
+
def configure_smtp
|
138
|
+
copy_file 'smtp.rb', 'config/smtp.rb'
|
139
|
+
|
140
|
+
prepend_file 'config/environments/production.rb',
|
141
|
+
%{require Rails.root.join('config', 'smtp')\n}
|
142
|
+
|
143
|
+
config = <<-RUBY
|
144
|
+
|
145
|
+
config.action_mailer.delivery_method = :smtp
|
146
|
+
config.action_mailer.smtp_settings = SMTP_SETTINGS
|
147
|
+
RUBY
|
148
|
+
|
149
|
+
inject_into_file 'config/environments/production.rb', config,
|
150
|
+
after: 'config.action_mailer.raise_delivery_errors = false'
|
151
|
+
end
|
152
|
+
|
153
|
+
def enable_rack_canonical_host
|
154
|
+
config = <<-RUBY
|
155
|
+
|
156
|
+
if ENV.fetch("HEROKU_APP_NAME", "").include?("staging-pr-")
|
157
|
+
ENV["APPLICATION_HOST"] = ENV["HEROKU_APP_NAME"] + ".herokuapp.com"
|
158
|
+
end
|
159
|
+
|
160
|
+
config.middleware.use Rack::CanonicalHost, ENV.fetch("APPLICATION_HOST")
|
161
|
+
RUBY
|
162
|
+
|
163
|
+
configure_environment 'production', config
|
164
|
+
end
|
165
|
+
|
166
|
+
def enable_rack_deflater
|
167
|
+
configure_environment 'production', 'config.middleware.use Rack::Deflater'
|
168
|
+
end
|
169
|
+
|
170
|
+
def setup_asset_host
|
171
|
+
replace_in_file 'config/environments/production.rb',
|
172
|
+
"# config.action_controller.asset_host = 'http://assets.example.com'",
|
173
|
+
'config.action_controller.asset_host = ' \
|
174
|
+
"ENV.fetch(\n 'ASSET_HOST',\n" \
|
175
|
+
" ENV.fetch('APPLICATION_HOST'\n)\n )"
|
176
|
+
|
177
|
+
replace_in_file 'config/initializers/assets.rb',
|
178
|
+
"config.assets.version = '1.0'",
|
179
|
+
'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")'
|
180
|
+
|
181
|
+
config = <<~HERE
|
182
|
+
config.public_file_server.headers = {
|
183
|
+
"Cache-Control" => "public, max-age=31557600",
|
184
|
+
}
|
185
|
+
HERE
|
186
|
+
|
187
|
+
configure_environment('production', config)
|
188
|
+
end
|
189
|
+
|
190
|
+
def setup_secret_token
|
191
|
+
template 'secrets.yml', 'config/secrets.yml', force: true
|
192
|
+
end
|
193
|
+
|
194
|
+
def disallow_wrapping_parameters
|
195
|
+
remove_file 'config/initializers/wrap_parameters.rb'
|
196
|
+
end
|
197
|
+
|
198
|
+
def create_partials_directory
|
199
|
+
empty_directory 'app/views/application'
|
200
|
+
end
|
201
|
+
|
202
|
+
def create_shared_flashes
|
203
|
+
copy_file '_flashes.html.slim', 'app/views/application/_flashes.html.slim'
|
204
|
+
copy_file 'flashes_helper.rb', 'app/helpers/flashes_helper.rb'
|
205
|
+
end
|
206
|
+
|
207
|
+
def create_shared_javascripts
|
208
|
+
copy_file(
|
209
|
+
'_javascript.html.slim',
|
210
|
+
'app/views/application/_javascript.html.slim'
|
211
|
+
)
|
212
|
+
end
|
213
|
+
|
214
|
+
def create_shared_css_overrides
|
215
|
+
copy_file(
|
216
|
+
'_css_overrides.html.slim',
|
217
|
+
'app/views/application/_css_overrides.html.slim'
|
218
|
+
)
|
219
|
+
end
|
220
|
+
|
221
|
+
def create_application_layout
|
222
|
+
template 'dvelp_layout.html.slim',
|
223
|
+
'app/views/layouts/application.html.slim',
|
224
|
+
force: true
|
225
|
+
|
226
|
+
remove_file 'app/views/layouts/application.html.erb'
|
227
|
+
end
|
228
|
+
|
229
|
+
def use_postgres_config_template
|
230
|
+
template 'postgresql_database.yml.erb', 'config/database.yml',
|
231
|
+
force: true
|
232
|
+
end
|
233
|
+
|
234
|
+
def create_database
|
235
|
+
bundle_command 'exec rails db:create db:migrate'
|
236
|
+
end
|
237
|
+
|
238
|
+
def replace_gemfile(path)
|
239
|
+
template 'Gemfile.erb', 'Gemfile', force: true do |content|
|
240
|
+
if path
|
241
|
+
content.gsub(/gem .underlay./) { |s| %(#{s}, path: "#{path}") }
|
242
|
+
else
|
243
|
+
content
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
def set_ruby_to_version_being_used
|
249
|
+
create_file '.ruby-version', "#{Underlay::RUBY_VERSION}\n"
|
250
|
+
end
|
251
|
+
|
252
|
+
def enable_database_cleaner
|
253
|
+
copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
|
254
|
+
end
|
255
|
+
|
256
|
+
def provide_shoulda_matchers_config
|
257
|
+
copy_file(
|
258
|
+
'shoulda_matchers_config_rspec.rb',
|
259
|
+
'spec/support/shoulda_matchers.rb'
|
260
|
+
)
|
261
|
+
end
|
262
|
+
|
263
|
+
def configure_spec_support_features
|
264
|
+
empty_directory_with_keep_file 'spec/features'
|
265
|
+
empty_directory_with_keep_file 'spec/support/features'
|
266
|
+
end
|
267
|
+
|
268
|
+
def configure_rspec
|
269
|
+
remove_file 'spec/rails_helper.rb'
|
270
|
+
remove_file 'spec/spec_helper.rb'
|
271
|
+
copy_file 'rails_helper.rb', 'spec/rails_helper.rb'
|
272
|
+
copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
|
273
|
+
end
|
274
|
+
|
275
|
+
def configure_ci
|
276
|
+
template 'circle.yml.erb', 'circle.yml'
|
277
|
+
end
|
278
|
+
|
279
|
+
def configure_rubocop
|
280
|
+
template 'rubocop.yml.erb', '.rubocop.yml'
|
281
|
+
end
|
282
|
+
|
283
|
+
def configure_linters
|
284
|
+
template 'scss-lint.yml.erb', '.scss-lint.yml'
|
285
|
+
template 'slim-lint.yml.erb', '.slim-lint.yml'
|
286
|
+
end
|
287
|
+
|
288
|
+
def configure_i18n_for_test_environment
|
289
|
+
copy_file 'i18n.rb', 'spec/support/i18n.rb'
|
290
|
+
end
|
291
|
+
|
292
|
+
def configure_i18n_for_missing_translations
|
293
|
+
raise_on_missing_translations_in('development')
|
294
|
+
raise_on_missing_translations_in('test')
|
295
|
+
end
|
296
|
+
|
297
|
+
def configure_action_mailer_in_specs
|
298
|
+
copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb'
|
299
|
+
end
|
300
|
+
|
301
|
+
def configure_capybara
|
302
|
+
copy_file 'capybara.rb', 'spec/support/capybara.rb'
|
303
|
+
end
|
304
|
+
|
305
|
+
def configure_time_formats
|
306
|
+
remove_file 'config/locales/en.yml'
|
307
|
+
template 'config_locales_en.yml.erb', 'config/locales/en.yml'
|
308
|
+
end
|
309
|
+
|
310
|
+
def configure_rack_timeout
|
311
|
+
rack_timeout_config = <<~RUBY
|
312
|
+
Rack::Timeout.timeout = (ENV["RACK_TIMEOUT"] || 10).to_i
|
313
|
+
RUBY
|
314
|
+
|
315
|
+
append_file 'config/environments/production.rb', rack_timeout_config
|
316
|
+
end
|
317
|
+
|
318
|
+
def configure_simple_form
|
319
|
+
bundle_command 'exec rails generate simple_form:install'
|
320
|
+
end
|
321
|
+
|
322
|
+
def configure_action_mailer
|
323
|
+
action_mailer_host 'development', %("localhost:3000")
|
324
|
+
action_mailer_asset_host 'development', %("http://localhost:3000")
|
325
|
+
action_mailer_host 'test', %("www.example.com")
|
326
|
+
action_mailer_asset_host 'test', %("http://www.example.com")
|
327
|
+
action_mailer_host 'production', "ENV['APPLICATION_HOST']"
|
328
|
+
action_mailer_asset_host(
|
329
|
+
'production',
|
330
|
+
"ENV.fetch(\n 'ASSET_HOST',\n" \
|
331
|
+
" ENV.fetch('APPLICATION_HOST'\n)\n )"
|
332
|
+
)
|
333
|
+
end
|
334
|
+
|
335
|
+
def configure_active_job
|
336
|
+
configure_application_file(
|
337
|
+
'config.active_job.queue_adapter = :sidekiq'
|
338
|
+
)
|
339
|
+
configure_environment 'test', 'config.active_job.queue_adapter = :inline'
|
340
|
+
copy_file 'sidekiq.yml', 'config/sidekiq.yml', force: true
|
341
|
+
end
|
342
|
+
|
343
|
+
def generate_rspec
|
344
|
+
generate 'rspec:install'
|
345
|
+
end
|
346
|
+
|
347
|
+
def replace_default_puma_configuration
|
348
|
+
copy_file 'puma.rb', 'config/puma.rb', force: true
|
349
|
+
end
|
350
|
+
|
351
|
+
def set_up_forego
|
352
|
+
copy_file 'Procfile', 'Procfile'
|
353
|
+
end
|
354
|
+
|
355
|
+
def setup_default_directories
|
356
|
+
[
|
357
|
+
'app/views/pages',
|
358
|
+
'spec/lib',
|
359
|
+
'spec/controllers',
|
360
|
+
'spec/helpers',
|
361
|
+
'spec/support/matchers',
|
362
|
+
'spec/support/mixins',
|
363
|
+
'spec/support/shared_examples'
|
364
|
+
].each do |dir|
|
365
|
+
empty_directory_with_keep_file dir
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
def copy_figaro_files
|
370
|
+
copy_file 'application.example.yml', 'config/application.example.yml'
|
371
|
+
copy_file 'application.example.yml', 'config/application.yml'
|
372
|
+
end
|
373
|
+
|
374
|
+
def create_heroku_apps(flags)
|
375
|
+
create_staging_heroku_app(flags)
|
376
|
+
create_production_heroku_app(flags)
|
377
|
+
end
|
378
|
+
|
379
|
+
def create_deploy_script
|
380
|
+
copy_file 'bin_deploy', 'bin/deploy'
|
381
|
+
|
382
|
+
instructions = <<~MARKDOWN
|
383
|
+
|
384
|
+
## Deploying
|
385
|
+
|
386
|
+
If you have previously run the `./bin/setup` script,
|
387
|
+
you can deploy to staging and production with:
|
388
|
+
|
389
|
+
% ./bin/deploy staging
|
390
|
+
% ./bin/deploy production
|
391
|
+
MARKDOWN
|
392
|
+
|
393
|
+
append_file 'README.md', instructions
|
394
|
+
run 'chmod a+x bin/deploy'
|
395
|
+
end
|
396
|
+
|
397
|
+
def configure_automatic_deployment
|
398
|
+
deploy_command = <<-YML.strip_heredoc
|
399
|
+
deployment:
|
400
|
+
staging:
|
401
|
+
branch: master
|
402
|
+
commands:
|
403
|
+
- bin/deploy staging
|
404
|
+
YML
|
405
|
+
|
406
|
+
append_file 'circle.yml', deploy_command
|
407
|
+
end
|
408
|
+
|
409
|
+
def create_github_repo(repo_name)
|
410
|
+
run "hub create #{repo_name} -p"
|
411
|
+
end
|
412
|
+
|
413
|
+
def setup_google_tag_manager
|
414
|
+
copy_file '_analytics.html.slim',
|
415
|
+
'app/views/application/_analytics.html.slim'
|
416
|
+
end
|
417
|
+
|
418
|
+
def setup_bundler_audit
|
419
|
+
copy_file 'bundler_audit.rake', 'lib/tasks/bundler_audit.rake'
|
420
|
+
append_file 'Rakefile', %(\ntask default: "bundle:audit"\n)
|
421
|
+
end
|
422
|
+
|
423
|
+
def setup_spring
|
424
|
+
bundle_command 'exec spring binstub --all'
|
425
|
+
end
|
426
|
+
|
427
|
+
def copy_miscellaneous_files
|
428
|
+
copy_file 'browserslist', 'browserslist'
|
429
|
+
copy_file 'errors.rb', 'config/initializers/errors.rb'
|
430
|
+
copy_file 'json_encoding.rb', 'config/initializers/json_encoding.rb'
|
431
|
+
copy_file 'lograge.rb', 'config/initializers/lograge.rb'
|
432
|
+
copy_file 'sentry.rb', 'config/initializers/sentry.rb'
|
433
|
+
end
|
434
|
+
|
435
|
+
def customize_error_pages
|
436
|
+
meta_tags = <<-HERE
|
437
|
+
<meta charset="utf-8" />
|
438
|
+
<meta name="ROBOTS" content="NOODP" />
|
439
|
+
<meta name="viewport" content="initial-scale=1" />
|
440
|
+
HERE
|
441
|
+
|
442
|
+
%w[500 404 422].each do |page|
|
443
|
+
inject_into_file "public/#{page}.html", meta_tags, after: "<head>\n"
|
444
|
+
replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
def remove_config_comment_lines
|
449
|
+
config_files = [
|
450
|
+
'application.rb',
|
451
|
+
'initializers/backtrace_silencers.rb',
|
452
|
+
'initializers/wrap_parameters.rb',
|
453
|
+
'../db/seeds.rb',
|
454
|
+
'environment.rb',
|
455
|
+
'environments/development.rb',
|
456
|
+
'environments/production.rb',
|
457
|
+
'environments/test.rb',
|
458
|
+
'../Rakefile'
|
459
|
+
] + mode_dependent_files
|
460
|
+
|
461
|
+
config_files.each do |config_file|
|
462
|
+
path = File.join(destination_root, "config/#{config_file}")
|
463
|
+
|
464
|
+
accepted_content = File.readlines(path).reject do |line|
|
465
|
+
line =~ /^.*#.*$/ || line =~ /^$\n/
|
466
|
+
end
|
467
|
+
|
468
|
+
File.open(path, 'w') do |file|
|
469
|
+
accepted_content.each { |line| file.puts line }
|
470
|
+
end
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
def remove_routes_comment_lines
|
475
|
+
replace_in_file 'config/routes.rb',
|
476
|
+
/Rails\.application\.routes\.draw do.*end/m,
|
477
|
+
"Rails.application.routes.draw do\nend"
|
478
|
+
end
|
479
|
+
|
480
|
+
def setup_default_rake_task
|
481
|
+
append_file 'Rakefile' do
|
482
|
+
<<~HERE
|
483
|
+
task(:default).clear
|
484
|
+
task default: [:spec]
|
485
|
+
|
486
|
+
if defined? RSpec
|
487
|
+
task(:spec).clear
|
488
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
489
|
+
t.verbose = false
|
490
|
+
end
|
491
|
+
end
|
492
|
+
HERE
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
def rubocop_autocorrect
|
497
|
+
run 'bundle exec rubocop -a'
|
498
|
+
end
|
499
|
+
|
500
|
+
def manual_code_correct
|
501
|
+
replace_in_file(
|
502
|
+
'config/environments/development.rb',
|
503
|
+
"if Rails.root.join('tmp/caching-dev.txt').exist?",
|
504
|
+
"if Rails.root.join('tmp', 'caching-dev.txt').exist?"
|
505
|
+
)
|
506
|
+
|
507
|
+
simple_form_corrections unless options[:api]
|
508
|
+
end
|
509
|
+
|
510
|
+
def non_api_files_removal
|
511
|
+
remove_file 'app.json'
|
512
|
+
remove_file 'browserslist'
|
513
|
+
remove_file 'config/cable.yml'
|
514
|
+
run 'rm -r -f app/channels'
|
515
|
+
run 'rm -r -f app/views/pages'
|
516
|
+
end
|
517
|
+
|
518
|
+
private
|
519
|
+
|
520
|
+
def raise_on_missing_translations_in(environment)
|
521
|
+
config = 'config.action_view.raise_on_missing_translations = true'
|
522
|
+
|
523
|
+
uncomment_lines("config/environments/#{environment}.rb", config)
|
524
|
+
end
|
525
|
+
|
526
|
+
def heroku_adapter
|
527
|
+
@heroku_adapter ||= Adapters::Heroku.new(self)
|
528
|
+
end
|
529
|
+
|
530
|
+
def simple_form_corrections
|
531
|
+
replace_in_file(
|
532
|
+
'config/initializers/simple_form.rb',
|
533
|
+
'config.wrappers :default, class: :input,',
|
534
|
+
'config.wrappers :default,'
|
535
|
+
)
|
536
|
+
replace_in_file(
|
537
|
+
'config/initializers/simple_form.rb',
|
538
|
+
' hint_class: :field_with_hint, ' \
|
539
|
+
'error_class: :field_with_errors, '\
|
540
|
+
'valid_class: :field_without_errors do |b|',
|
541
|
+
" class: :input,\n"\
|
542
|
+
" hint_class: :field_with_hint,\n" \
|
543
|
+
" error_class: :field_with_errors,\n" \
|
544
|
+
' valid_class: :field_without_errors do |b|'
|
545
|
+
)
|
546
|
+
end
|
547
|
+
|
548
|
+
def mode_dependent_files
|
549
|
+
if options[:api]
|
550
|
+
['initializers/cors.rb']
|
551
|
+
else
|
552
|
+
['initializers/simple_form.rb']
|
553
|
+
end
|
554
|
+
end
|
555
|
+
end
|
556
|
+
end
|