suspenders-ocs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +11 -0
  5. data/CONTRIBUTING.md +51 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +21 -0
  8. data/NEWS.md +486 -0
  9. data/README.md +233 -0
  10. data/RELEASING.md +19 -0
  11. data/Rakefile +8 -0
  12. data/bin/rake +16 -0
  13. data/bin/rspec +16 -0
  14. data/bin/setup +13 -0
  15. data/bin/suspenders +23 -0
  16. data/lib/suspenders.rb +5 -0
  17. data/lib/suspenders/actions.rb +33 -0
  18. data/lib/suspenders/adapters/heroku.rb +125 -0
  19. data/lib/suspenders/app_builder.rb +523 -0
  20. data/lib/suspenders/generators/app_generator.rb +269 -0
  21. data/lib/suspenders/version.rb +5 -0
  22. data/spec/adapters/heroku_spec.rb +52 -0
  23. data/spec/fakes/bin/heroku +5 -0
  24. data/spec/fakes/bin/hub +5 -0
  25. data/spec/features/github_spec.rb +15 -0
  26. data/spec/features/heroku_spec.rb +93 -0
  27. data/spec/features/new_project_spec.rb +234 -0
  28. data/spec/spec_helper.rb +20 -0
  29. data/spec/support/fake_github.rb +21 -0
  30. data/spec/support/fake_heroku.rb +53 -0
  31. data/spec/support/suspenders.rb +58 -0
  32. data/suspenders.gemspec +34 -0
  33. data/templates/Gemfile.erb +63 -0
  34. data/templates/Procfile +2 -0
  35. data/templates/README.md.erb +28 -0
  36. data/templates/_analytics.html.erb +7 -0
  37. data/templates/_css_overrides.html.erb +8 -0
  38. data/templates/_flashes.html.erb +7 -0
  39. data/templates/_javascript.html.erb +12 -0
  40. data/templates/action_mailer.rb +5 -0
  41. data/templates/app.json.erb +42 -0
  42. data/templates/application.scss +9 -0
  43. data/templates/bin_deploy +12 -0
  44. data/templates/bin_setup +21 -0
  45. data/templates/bin_setup_review_app.erb +19 -0
  46. data/templates/browserslist +3 -0
  47. data/templates/bundler_audit.rake +12 -0
  48. data/templates/capybara_webkit.rb +5 -0
  49. data/templates/circle.yml.erb +6 -0
  50. data/templates/config_locales_en.yml.erb +19 -0
  51. data/templates/database_cleaner_rspec.rb +21 -0
  52. data/templates/dev.rake +12 -0
  53. data/templates/disable_xml_params.rb +1 -0
  54. data/templates/dotfiles/.ctags +2 -0
  55. data/templates/dotfiles/.env +13 -0
  56. data/templates/errors.rb +34 -0
  57. data/templates/factories.rb +2 -0
  58. data/templates/factory_girl_rspec.rb +3 -0
  59. data/templates/flashes_helper.rb +5 -0
  60. data/templates/hound.yml +14 -0
  61. data/templates/i18n.rb +3 -0
  62. data/templates/json_encoding.rb +1 -0
  63. data/templates/newrelic.yml.erb +34 -0
  64. data/templates/postgresql_database.yml.erb +21 -0
  65. data/templates/puma.rb +28 -0
  66. data/templates/rack_mini_profiler.rb +5 -0
  67. data/templates/rails_helper.rb +22 -0
  68. data/templates/secrets.yml +14 -0
  69. data/templates/shoulda_matchers_config_rspec.rb +6 -0
  70. data/templates/smtp.rb +9 -0
  71. data/templates/spec_helper.rb +29 -0
  72. data/templates/staging.rb +5 -0
  73. data/templates/suspenders_gitignore +13 -0
  74. data/templates/suspenders_layout.html.erb.erb +22 -0
  75. metadata +204 -0
@@ -0,0 +1,523 @@
1
+ require "forwardable"
2
+
3
+ module Suspenders
4
+ class AppBuilder < Rails::AppBuilder
5
+ include Suspenders::Actions
6
+ extend Forwardable
7
+
8
+ def_delegators :heroku_adapter,
9
+ :create_heroku_pipelines_config_file,
10
+ :create_heroku_pipeline,
11
+ :create_production_heroku_app,
12
+ :create_staging_heroku_app,
13
+ :provide_review_apps_setup_script,
14
+ :set_heroku_rails_secrets,
15
+ :set_heroku_remotes,
16
+ :set_heroku_serve_static_files,
17
+ :set_up_heroku_specific_gems
18
+
19
+ def readme
20
+ template 'README.md.erb', 'README.md'
21
+ end
22
+
23
+ def gitignore
24
+ copy_file "suspenders_gitignore", ".gitignore"
25
+ end
26
+
27
+ def gemfile
28
+ template "Gemfile.erb", "Gemfile"
29
+ end
30
+
31
+ def setup_rack_mini_profiler
32
+ copy_file(
33
+ "rack_mini_profiler.rb",
34
+ "config/initializers/rack_mini_profiler.rb",
35
+ )
36
+ end
37
+
38
+ def raise_on_missing_assets_in_test
39
+ inject_into_file(
40
+ "config/environments/test.rb",
41
+ "\n config.assets.raise_runtime_errors = true",
42
+ after: "Rails.application.configure do",
43
+ )
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.quiet_assets = 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_dev_prime_task
98
+ copy_file 'dev.rake', 'lib/tasks/dev.rake'
99
+ end
100
+
101
+ def configure_generators
102
+ config = <<-RUBY
103
+
104
+ config.generators do |generate|
105
+ generate.helper false
106
+ generate.javascript_engine false
107
+ generate.request_specs false
108
+ generate.routing_specs false
109
+ generate.stylesheets false
110
+ generate.test_framework :rspec
111
+ generate.view_specs false
112
+ end
113
+
114
+ RUBY
115
+
116
+ inject_into_class 'config/application.rb', 'Application', config
117
+ end
118
+
119
+ def set_up_factory_girl_for_rspec
120
+ copy_file 'factory_girl_rspec.rb', 'spec/support/factory_girl.rb'
121
+ end
122
+
123
+ def generate_factories_file
124
+ copy_file "factories.rb", "spec/factories.rb"
125
+ end
126
+
127
+ def set_up_hound
128
+ copy_file "hound.yml", ".hound.yml"
129
+ end
130
+
131
+ def configure_newrelic
132
+ template 'newrelic.yml.erb', 'config/newrelic.yml'
133
+ end
134
+
135
+ def configure_smtp
136
+ copy_file 'smtp.rb', 'config/smtp.rb'
137
+
138
+ prepend_file 'config/environments/production.rb',
139
+ %{require Rails.root.join("config/smtp")\n}
140
+
141
+ config = <<-RUBY
142
+
143
+ config.action_mailer.delivery_method = :smtp
144
+ config.action_mailer.smtp_settings = SMTP_SETTINGS
145
+ RUBY
146
+
147
+ inject_into_file 'config/environments/production.rb', config,
148
+ after: "config.action_mailer.raise_delivery_errors = false"
149
+ end
150
+
151
+ def enable_rack_canonical_host
152
+ config = <<-RUBY
153
+
154
+ if ENV.fetch("HEROKU_APP_NAME", "").include?("staging-pr-")
155
+ ENV["APPLICATION_HOST"] = ENV["HEROKU_APP_NAME"] + ".herokuapp.com"
156
+ end
157
+
158
+ # Ensure requests are only served from one, canonical host name
159
+ config.middleware.use Rack::CanonicalHost, ENV.fetch("APPLICATION_HOST")
160
+ RUBY
161
+
162
+ inject_into_file(
163
+ "config/environments/production.rb",
164
+ config,
165
+ after: "Rails.application.configure do",
166
+ )
167
+ end
168
+
169
+ def enable_rack_deflater
170
+ config = <<-RUBY
171
+
172
+ # Enable deflate / gzip compression of controller-generated responses
173
+ config.middleware.use Rack::Deflater
174
+ RUBY
175
+
176
+ inject_into_file(
177
+ "config/environments/production.rb",
178
+ config,
179
+ after: serve_static_files_line
180
+ )
181
+ end
182
+
183
+ def setup_asset_host
184
+ replace_in_file 'config/environments/production.rb',
185
+ "# config.action_controller.asset_host = 'http://assets.example.com'",
186
+ 'config.action_controller.asset_host = ENV.fetch("ASSET_HOST", ENV.fetch("APPLICATION_HOST"))'
187
+
188
+ replace_in_file 'config/initializers/assets.rb',
189
+ "config.assets.version = '1.0'",
190
+ 'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")'
191
+
192
+ inject_into_file(
193
+ "config/environments/production.rb",
194
+ ' config.static_cache_control = "public, max-age=#{1.year.to_i}"',
195
+ after: serve_static_files_line
196
+ )
197
+ end
198
+
199
+ def setup_staging_environment
200
+ staging_file = 'config/environments/staging.rb'
201
+ copy_file 'staging.rb', staging_file
202
+
203
+ config = <<-RUBY
204
+
205
+ Rails.application.configure do
206
+ # ...
207
+ end
208
+ RUBY
209
+
210
+ append_file staging_file, config
211
+ end
212
+
213
+ def setup_secret_token
214
+ template 'secrets.yml', 'config/secrets.yml', force: true
215
+ end
216
+
217
+ def disallow_wrapping_parameters
218
+ remove_file "config/initializers/wrap_parameters.rb"
219
+ end
220
+
221
+ def create_partials_directory
222
+ empty_directory 'app/views/application'
223
+ end
224
+
225
+ def create_shared_flashes
226
+ copy_file "_flashes.html.erb", "app/views/application/_flashes.html.erb"
227
+ copy_file "flashes_helper.rb", "app/helpers/flashes_helper.rb"
228
+ end
229
+
230
+ def create_shared_javascripts
231
+ copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb'
232
+ end
233
+
234
+ def create_shared_css_overrides
235
+ copy_file(
236
+ "_css_overrides.html.erb",
237
+ "app/views/application/_css_overrides.html.erb",
238
+ )
239
+ end
240
+
241
+ def create_application_layout
242
+ template 'suspenders_layout.html.erb.erb',
243
+ 'app/views/layouts/application.html.erb',
244
+ force: true
245
+ end
246
+
247
+ def use_postgres_config_template
248
+ template 'postgresql_database.yml.erb', 'config/database.yml',
249
+ force: true
250
+ end
251
+
252
+ def create_database
253
+ bundle_command 'exec rake db:create db:migrate'
254
+ end
255
+
256
+ def set_ruby_to_version_being_used
257
+ create_file '.ruby-version', "#{Suspenders::RUBY_VERSION}\n"
258
+ end
259
+
260
+ def enable_database_cleaner
261
+ copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
262
+ end
263
+
264
+ def provide_shoulda_matchers_config
265
+ copy_file(
266
+ "shoulda_matchers_config_rspec.rb",
267
+ "spec/support/shoulda_matchers.rb"
268
+ )
269
+ end
270
+
271
+ def configure_spec_support_features
272
+ empty_directory_with_keep_file 'spec/features'
273
+ empty_directory_with_keep_file 'spec/support/features'
274
+ end
275
+
276
+ def configure_rspec
277
+ remove_file "spec/rails_helper.rb"
278
+ remove_file "spec/spec_helper.rb"
279
+ copy_file "rails_helper.rb", "spec/rails_helper.rb"
280
+ copy_file "spec_helper.rb", "spec/spec_helper.rb"
281
+ end
282
+
283
+ def configure_ci
284
+ template "circle.yml.erb", "circle.yml"
285
+ end
286
+
287
+ def configure_i18n_for_test_environment
288
+ copy_file "i18n.rb", "spec/support/i18n.rb"
289
+ end
290
+
291
+ def configure_i18n_for_missing_translations
292
+ raise_on_missing_translations_in("development")
293
+ raise_on_missing_translations_in("test")
294
+ end
295
+
296
+ def configure_background_jobs_for_rspec
297
+ run 'rails g delayed_job:active_record'
298
+ end
299
+
300
+ def configure_action_mailer_in_specs
301
+ copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb'
302
+ end
303
+
304
+ def configure_capybara_webkit
305
+ copy_file "capybara_webkit.rb", "spec/support/capybara_webkit.rb"
306
+ end
307
+
308
+ def configure_time_formats
309
+ remove_file "config/locales/en.yml"
310
+ template "config_locales_en.yml.erb", "config/locales/en.yml"
311
+ end
312
+
313
+ def configure_rack_timeout
314
+ rack_timeout_config = <<-RUBY
315
+ Rack::Timeout.timeout = (ENV["RACK_TIMEOUT"] || 10).to_i
316
+ RUBY
317
+
318
+ append_file "config/environments/production.rb", rack_timeout_config
319
+ end
320
+
321
+ def configure_simple_form
322
+ bundle_command "exec rails generate simple_form:install"
323
+ end
324
+
325
+ def configure_action_mailer
326
+ action_mailer_host "development", %{"localhost:3000"}
327
+ action_mailer_host "test", %{"www.example.com"}
328
+ action_mailer_host "production", %{ENV.fetch("APPLICATION_HOST")}
329
+ end
330
+
331
+ def configure_active_job
332
+ configure_application_file(
333
+ "config.active_job.queue_adapter = :delayed_job"
334
+ )
335
+ configure_environment "test", "config.active_job.queue_adapter = :inline"
336
+ end
337
+
338
+ def generate_rspec
339
+ generate 'rspec:install'
340
+ end
341
+
342
+ def configure_puma
343
+ copy_file "puma.rb", "config/puma.rb"
344
+ end
345
+
346
+ def set_up_forego
347
+ copy_file "Procfile", "Procfile"
348
+ end
349
+
350
+ def setup_stylesheets
351
+ remove_file "app/assets/stylesheets/application.css"
352
+ copy_file "application.scss",
353
+ "app/assets/stylesheets/application.scss"
354
+ end
355
+
356
+ def install_refills
357
+ generate "refills:import", "flashes"
358
+ remove_dir "app/views/refills"
359
+ end
360
+
361
+ def install_bitters
362
+ run "bitters install --path app/assets/stylesheets"
363
+ end
364
+
365
+ def setup_default_directories
366
+ [
367
+ 'app/views/pages',
368
+ 'spec/lib',
369
+ 'spec/controllers',
370
+ 'spec/helpers',
371
+ 'spec/support/matchers',
372
+ 'spec/support/mixins',
373
+ 'spec/support/shared_examples'
374
+ ].each do |dir|
375
+ empty_directory_with_keep_file dir
376
+ end
377
+ end
378
+
379
+ def copy_dotfiles
380
+ directory("dotfiles", ".")
381
+ end
382
+
383
+ def init_git
384
+ run 'git init'
385
+ end
386
+
387
+ def create_heroku_apps(flags)
388
+ create_staging_heroku_app(flags)
389
+ create_production_heroku_app(flags)
390
+ end
391
+
392
+ def provide_deploy_script
393
+ copy_file "bin_deploy", "bin/deploy"
394
+
395
+ instructions = <<-MARKDOWN
396
+
397
+ ## Deploying
398
+
399
+ If you have previously run the `./bin/setup` script,
400
+ you can deploy to staging and production with:
401
+
402
+ $ ./bin/deploy staging
403
+ $ ./bin/deploy production
404
+ MARKDOWN
405
+
406
+ append_file "README.md", instructions
407
+ run "chmod a+x bin/deploy"
408
+ end
409
+
410
+ def configure_automatic_deployment
411
+ deploy_command = <<-YML.strip_heredoc
412
+ deployment:
413
+ staging:
414
+ branch: master
415
+ commands:
416
+ - bin/deploy staging
417
+ YML
418
+
419
+ append_file "circle.yml", deploy_command
420
+ end
421
+
422
+ def create_github_repo(repo_name)
423
+ run "hub create #{repo_name}"
424
+ end
425
+
426
+ def setup_segment
427
+ copy_file '_analytics.html.erb',
428
+ 'app/views/application/_analytics.html.erb'
429
+ end
430
+
431
+ def setup_bundler_audit
432
+ copy_file "bundler_audit.rake", "lib/tasks/bundler_audit.rake"
433
+ append_file "Rakefile", %{\ntask default: "bundler:audit"\n}
434
+ end
435
+
436
+ def setup_spring
437
+ bundle_command "exec spring binstub --all"
438
+ end
439
+
440
+ def copy_miscellaneous_files
441
+ copy_file "browserslist", "browserslist"
442
+ copy_file "errors.rb", "config/initializers/errors.rb"
443
+ copy_file "json_encoding.rb", "config/initializers/json_encoding.rb"
444
+ end
445
+
446
+ def customize_error_pages
447
+ meta_tags =<<-EOS
448
+ <meta charset="utf-8" />
449
+ <meta name="ROBOTS" content="NOODP" />
450
+ <meta name="viewport" content="initial-scale=1" />
451
+ EOS
452
+
453
+ %w(500 404 422).each do |page|
454
+ inject_into_file "public/#{page}.html", meta_tags, after: "<head>\n"
455
+ replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
456
+ end
457
+ end
458
+
459
+ def remove_config_comment_lines
460
+ config_files = [
461
+ "application.rb",
462
+ "environment.rb",
463
+ "environments/development.rb",
464
+ "environments/production.rb",
465
+ "environments/test.rb",
466
+ ]
467
+
468
+ config_files.each do |config_file|
469
+ path = File.join(destination_root, "config/#{config_file}")
470
+
471
+ accepted_content = File.readlines(path).reject do |line|
472
+ line =~ /^.*#.*$/ || line =~ /^$\n/
473
+ end
474
+
475
+ File.open(path, "w") do |file|
476
+ accepted_content.each { |line| file.puts line }
477
+ end
478
+ end
479
+ end
480
+
481
+ def remove_routes_comment_lines
482
+ replace_in_file 'config/routes.rb',
483
+ /Rails\.application\.routes\.draw do.*end/m,
484
+ "Rails.application.routes.draw do\nend"
485
+ end
486
+
487
+ def disable_xml_params
488
+ copy_file 'disable_xml_params.rb', 'config/initializers/disable_xml_params.rb'
489
+ end
490
+
491
+ def setup_default_rake_task
492
+ append_file 'Rakefile' do
493
+ <<-EOS
494
+ task(:default).clear
495
+ task default: [:spec]
496
+
497
+ if defined? RSpec
498
+ task(:spec).clear
499
+ RSpec::Core::RakeTask.new(:spec) do |t|
500
+ t.verbose = false
501
+ end
502
+ end
503
+ EOS
504
+ end
505
+ end
506
+
507
+ private
508
+
509
+ def raise_on_missing_translations_in(environment)
510
+ config = 'config.action_view.raise_on_missing_translations = true'
511
+
512
+ uncomment_lines("config/environments/#{environment}.rb", config)
513
+ end
514
+
515
+ def heroku_adapter
516
+ @heroku_adapter ||= Adapters::Heroku.new(self)
517
+ end
518
+
519
+ def serve_static_files_line
520
+ "config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?\n"
521
+ end
522
+ end
523
+ end