cosmit-suspenders 1.36.0

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