jetfuel 1.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +11 -0
  5. data/CONTRIBUTING.md +36 -0
  6. data/Gemfile +3 -0
  7. data/Gemfile.lock +131 -0
  8. data/LICENSE +21 -0
  9. data/NEWS.md +246 -0
  10. data/README.md +191 -0
  11. data/Rakefile +8 -0
  12. data/bin/jetfuel +18 -0
  13. data/bin/rake +16 -0
  14. data/bin/rspec +16 -0
  15. data/bin/setup +13 -0
  16. data/jetfuel.gemspec +37 -0
  17. data/lib/jetfuel/actions.rb +25 -0
  18. data/lib/jetfuel/app_builder.rb +400 -0
  19. data/lib/jetfuel/generators/app_generator.rb +227 -0
  20. data/lib/jetfuel/version.rb +5 -0
  21. data/lib/jetfuel.rb +4 -0
  22. data/spec/fakes/bin/heroku +5 -0
  23. data/spec/fakes/bin/hub +5 -0
  24. data/spec/features/github_spec.rb +10 -0
  25. data/spec/features/heroku_spec.rb +19 -0
  26. data/spec/features/new_project_spec.rb +68 -0
  27. data/spec/spec_helper.rb +24 -0
  28. data/spec/support/fake_github.rb +21 -0
  29. data/spec/support/fake_heroku.rb +38 -0
  30. data/spec/support/jetfuel.rb +49 -0
  31. data/templates/Brewfile +2 -0
  32. data/templates/Gemfile.erb +51 -0
  33. data/templates/Procfile +2 -0
  34. data/templates/README.md.erb +25 -0
  35. data/templates/_analytics.html.erb +7 -0
  36. data/templates/_flashes.html.erb +8 -0
  37. data/templates/_javascript.html.erb +12 -0
  38. data/templates/action_mailer.rb +5 -0
  39. data/templates/application.css.scss +7 -0
  40. data/templates/application_helper.rb +9 -0
  41. data/templates/background_jobs_rspec.rb +19 -0
  42. data/templates/bin_setup +32 -0
  43. data/templates/config_locales_en.yml +11 -0
  44. data/templates/database_cleaner_rspec.rb +21 -0
  45. data/templates/development_seeds.rb +13 -0
  46. data/templates/devise.rb +257 -0
  47. data/templates/disable_xml_params.rb +3 -0
  48. data/templates/errors.rb +28 -0
  49. data/templates/factory_girl_rspec.rb +3 -0
  50. data/templates/flashes.css.scss +4 -0
  51. data/templates/i18n.rb +3 -0
  52. data/templates/newrelic.yml.erb +34 -0
  53. data/templates/postgresql_database.yml.erb +12 -0
  54. data/templates/rack_timeout.rb +1 -0
  55. data/templates/sample.env +3 -0
  56. data/templates/secrets.yml +14 -0
  57. data/templates/smtp.rb +9 -0
  58. data/templates/spec_helper.rb +32 -0
  59. data/templates/staging.rb +5 -0
  60. data/templates/suspenders_gitignore +13 -0
  61. data/templates/suspenders_layout.html.erb.erb +16 -0
  62. data/templates/travis.yml.erb +31 -0
  63. data/templates/unicorn.rb +30 -0
  64. metadata +211 -0
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/setup ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env sh
2
+
3
+ # Run this script immediately after cloning the codebase.
4
+
5
+ # Exit if any subcommand fails
6
+ set -e
7
+
8
+ # Set up Ruby dependencies via Bundler
9
+ bundle install
10
+
11
+ # Add binstubs to PATH in ~/.zshenv like this:
12
+ # export PATH=".git/safe/../../bin:$PATH"
13
+ mkdir -p .git/safe
data/jetfuel.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'jetfuel/version'
4
+ require 'date'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.required_ruby_version = ">= #{Jetfuel::RUBY_VERSION}"
8
+ s.authors = ['FlyoverWorks']
9
+ s.date = Date.today.strftime('%Y-%m-%d')
10
+
11
+ s.description = <<-HERE
12
+ Jetfuel is a base Rails project that you can upgrade. It is used by
13
+ FlyoverWorks to get a jump start on a working app. Use Jetfuel if you're in a
14
+ rush to build something amazing; don't use it if you like missing deadlines.
15
+ HERE
16
+
17
+ s.email = 'david@flyoverworks.com'
18
+ s.executables = ['jetfuel']
19
+ s.extra_rdoc_files = %w[README.md LICENSE]
20
+ s.files = `git ls-files`.split("\n")
21
+ s.homepage = 'http://github.com/FlyoverWorks/jetfuel'
22
+ s.license = 'MIT'
23
+ s.name = 'jetfuel'
24
+ s.rdoc_options = ['--charset=UTF-8']
25
+ s.require_paths = ['lib']
26
+ s.summary = "Generate a Rails app using FlyoverWorks' best practices."
27
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
+ s.version = Jetfuel::VERSION
29
+
30
+ s.add_dependency 'bundler', '~> 1.3'
31
+ s.add_dependency 'rails', Jetfuel::RAILS_VERSION
32
+
33
+ s.add_development_dependency 'aruba', '~> 0.5'
34
+ s.add_development_dependency 'cucumber', '~> 1.2'
35
+ s.add_development_dependency 'rspec', '~> 2.0'
36
+ s.add_development_dependency 'capybara', '~> 2.2', '>= 2.2.0'
37
+ end
@@ -0,0 +1,25 @@
1
+ module Jetfuel
2
+ module Actions
3
+ def replace_in_file(relative_path, find, replace)
4
+ path = File.join(destination_root, relative_path)
5
+ contents = IO.read(path)
6
+ unless contents.gsub!(find, replace)
7
+ raise "#{find.inspect} not found in #{relative_path}"
8
+ end
9
+ File.open(path, "w") { |file| file.write(contents) }
10
+ end
11
+
12
+ def action_mailer_host(rails_env, host)
13
+ host_config = "config.action_mailer.default_url_options = { host: '#{host}' }"
14
+ configure_environment(rails_env, host_config)
15
+ end
16
+
17
+ def configure_environment(rails_env, config)
18
+ inject_into_file(
19
+ "config/environments/#{rails_env}.rb",
20
+ "\n\n #{config}",
21
+ before: "\nend"
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,400 @@
1
+ module Jetfuel
2
+ class AppBuilder < Rails::AppBuilder
3
+ include Jetfuel::Actions
4
+
5
+ def readme
6
+ template 'README.md.erb', 'README.md'
7
+ end
8
+
9
+ def raise_on_delivery_errors
10
+ replace_in_file 'config/environments/development.rb',
11
+ 'raise_delivery_errors = false', 'raise_delivery_errors = true'
12
+ end
13
+
14
+ def raise_on_unpermitted_parameters
15
+ action_on_unpermitted_parameters = <<-RUBY
16
+
17
+ # Raise an ActionController::UnpermittedParameters exception when
18
+ # a parameter is not explcitly permitted but is passed anyway.
19
+ config.action_controller.action_on_unpermitted_parameters = :raise
20
+ RUBY
21
+ inject_into_file(
22
+ "config/environments/development.rb",
23
+ action_on_unpermitted_parameters,
24
+ before: "\nend"
25
+ )
26
+ end
27
+
28
+ def provide_setup_script
29
+ copy_file 'bin_setup', 'bin/setup'
30
+ run 'chmod a+x bin/setup'
31
+ end
32
+
33
+ def provide_dev_prime_task
34
+ copy_file 'development_seeds.rb', 'lib/tasks/development_seeds.rake'
35
+ end
36
+
37
+ def configure_generators
38
+ config = <<-RUBY
39
+ config.generators do |generate|
40
+ generate.helper false
41
+ generate.javascript_engine false
42
+ generate.request_specs false
43
+ generate.routing_specs false
44
+ generate.stylesheets false
45
+ generate.test_framework :rspec
46
+ generate.view_specs false
47
+ end
48
+
49
+ RUBY
50
+
51
+ inject_into_class 'config/application.rb', 'Application', config
52
+ end
53
+
54
+ def set_up_factory_girl_for_rspec
55
+ copy_file 'factory_girl_rspec.rb', 'spec/support/factory_girl.rb'
56
+ end
57
+
58
+ def configure_newrelic
59
+ template 'newrelic.yml.erb', 'config/newrelic.yml'
60
+ end
61
+
62
+ def configure_smtp
63
+ copy_file 'smtp.rb', 'config/smtp.rb'
64
+
65
+ prepend_file 'config/environments/production.rb',
66
+ "require Rails.root.join('config/smtp')\n"
67
+
68
+ config = <<-RUBY
69
+
70
+ config.action_mailer.delivery_method = :smtp
71
+ config.action_mailer.smtp_settings = SMTP_SETTINGS
72
+ RUBY
73
+
74
+ inject_into_file 'config/environments/production.rb', config,
75
+ :after => 'config.action_mailer.raise_delivery_errors = false'
76
+ end
77
+
78
+ def enable_rack_deflater
79
+ config = <<-RUBY
80
+
81
+ # Enable deflate / gzip compression of controller-generated responses
82
+ config.middleware.use Rack::Deflater
83
+ RUBY
84
+
85
+ inject_into_file 'config/environments/production.rb', config,
86
+ :after => "config.serve_static_assets = false\n"
87
+ end
88
+
89
+ def setup_asset_host
90
+ replace_in_file 'config/environments/production.rb',
91
+ '# config.action_controller.asset_host = "http://assets.example.com"',
92
+ "config.action_controller.asset_host = ENV.fetch('ASSET_HOST')"
93
+
94
+ replace_in_file 'config/environments/production.rb',
95
+ "config.assets.version = '1.0'",
96
+ "config.assets.version = ENV.fetch('ASSETS_VERSION')"
97
+
98
+ replace_in_file 'config/environments/production.rb',
99
+ 'config.serve_static_assets = false',
100
+ 'config.static_cache_control = "public, max-age=#{1.year.to_i}"'
101
+ end
102
+
103
+ def setup_staging_environment
104
+ staging_file = 'config/environments/staging.rb'
105
+ copy_file 'staging.rb', staging_file
106
+
107
+ config = <<-RUBY
108
+
109
+ Rails.application.configure do
110
+ # ...
111
+ end
112
+ RUBY
113
+
114
+ append_file staging_file, config
115
+ end
116
+
117
+ def setup_secret_token
118
+ template 'secrets.yml', 'config/secrets.yml', force: true
119
+ end
120
+
121
+ def create_partials_directory
122
+ empty_directory 'app/views/application'
123
+ end
124
+
125
+ def create_shared_flashes
126
+ copy_file '_flashes.html.erb', 'app/views/application/_flashes.html.erb'
127
+ end
128
+
129
+ def create_shared_javascripts
130
+ copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb'
131
+ end
132
+
133
+ def create_application_layout
134
+ template 'suspenders_layout.html.erb.erb',
135
+ 'app/views/layouts/application.html.erb',
136
+ force: true
137
+ end
138
+
139
+ def remove_turbolinks
140
+ replace_in_file 'app/assets/javascripts/application.js',
141
+ /\/\/= require turbolinks\n/,
142
+ ''
143
+ end
144
+
145
+ def add_bootstrap_js
146
+ inject_into_file 'app/assets/javascripts/application.js', "//= require bootstrap\n",
147
+ after: /\/\/= require jquery_ujs\n/
148
+ end
149
+
150
+ def use_postgres_config_template
151
+ template 'postgresql_database.yml.erb', 'config/database.yml',
152
+ force: true
153
+ end
154
+
155
+ def create_database
156
+ bundle_command 'exec rake db:create db:migrate'
157
+ end
158
+
159
+ def replace_gemfile
160
+ remove_file 'Gemfile'
161
+ template 'Gemfile.erb', 'Gemfile'
162
+ end
163
+
164
+ def set_ruby_to_version_being_used
165
+ create_file '.ruby-version', "#{Suspenders::RUBY_VERSION}\n"
166
+ end
167
+
168
+ def setup_heroku_specific_gems
169
+ inject_into_file 'Gemfile', "\n\s\sgem 'rails_12factor'",
170
+ after: /group :staging, :production do/
171
+ end
172
+
173
+ def enable_database_cleaner
174
+ copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
175
+ end
176
+
177
+ def configure_spec_support_features
178
+ empty_directory_with_keep_file 'spec/features'
179
+ empty_directory_with_keep_file 'spec/support/features'
180
+ end
181
+
182
+ def configure_rspec
183
+ remove_file 'spec/spec_helper.rb'
184
+ copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
185
+ end
186
+
187
+ def configure_travis
188
+ template 'travis.yml.erb', '.travis.yml'
189
+ end
190
+
191
+ def configure_i18n_in_specs
192
+ copy_file 'i18n.rb', 'spec/support/i18n.rb'
193
+ end
194
+
195
+ def configure_background_jobs_for_rspec
196
+ copy_file 'background_jobs_rspec.rb', 'spec/support/background_jobs.rb'
197
+ run 'bundle exec rails g delayed_job:active_record'
198
+ end
199
+
200
+ def configure_action_mailer_in_specs
201
+ copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb'
202
+ end
203
+
204
+ def configure_time_zone
205
+ config = <<-RUBY
206
+ config.active_record.default_timezone = :utc
207
+
208
+ RUBY
209
+ inject_into_class 'config/application.rb', 'Application', config
210
+ end
211
+
212
+ def configure_time_formats
213
+ remove_file 'config/locales/en.yml'
214
+ copy_file 'config_locales_en.yml', 'config/locales/en.yml'
215
+ end
216
+
217
+ def configure_rack_timeout
218
+ copy_file 'rack_timeout.rb', 'config/initializers/rack_timeout.rb'
219
+ end
220
+
221
+ def configure_action_mailer
222
+ action_mailer_host 'development', "#{app_name}.local"
223
+ action_mailer_host 'test', 'www.example.com'
224
+ action_mailer_host 'staging', "staging.#{app_name}.com"
225
+ action_mailer_host 'production', "#{app_name}.com"
226
+ end
227
+
228
+ def fix_i18n_deprecation_warning
229
+ config = <<-RUBY
230
+ config.i18n.enforce_available_locales = true
231
+
232
+ RUBY
233
+ inject_into_class 'config/application.rb', 'Application', config
234
+ end
235
+
236
+ def generate_rspec
237
+ run 'bundle exec rails g rspec:install'
238
+ end
239
+
240
+ def configure_unicorn
241
+ copy_file 'unicorn.rb', 'config/unicorn.rb'
242
+ end
243
+
244
+ def setup_foreman
245
+ copy_file 'sample.env', '.env'
246
+ replace_in_file ".env", /development_secret/, generate_secret
247
+ copy_file 'Procfile', 'Procfile'
248
+ end
249
+
250
+ def setup_stylesheets
251
+ remove_file 'app/assets/stylesheets/application.css'
252
+ copy_file 'application.css.scss',
253
+ 'app/assets/stylesheets/application.css.scss'
254
+ copy_file 'flashes.css.scss',
255
+ 'app/assets/stylesheets/flashes.css.scss'
256
+ end
257
+
258
+ def install_leather
259
+ run "bundle exec rails g leather:install"
260
+ end
261
+
262
+ def setup_helpers
263
+ remove_file 'app/helpers/application_helper.rb'
264
+ copy_file 'application_helper.rb',
265
+ 'app/helpers/application_helper.rb'
266
+ end
267
+
268
+ def install_devise
269
+ run 'bundle exec rails g devise:install'
270
+ remove_file 'config/initializers/devise.rb'
271
+ copy_file 'devise.rb',
272
+ 'config/initializers/devise.rb'
273
+ end
274
+
275
+ def create_devise_user
276
+ run 'bundle exec rails g devise User'
277
+ run 'rake db:migrate'
278
+ end
279
+
280
+ def gitignore_files
281
+ remove_file '.gitignore'
282
+ copy_file 'suspenders_gitignore', '.gitignore'
283
+ [
284
+ 'app/views/pages',
285
+ 'spec/lib',
286
+ 'spec/controllers',
287
+ 'spec/helpers',
288
+ 'spec/support/matchers',
289
+ 'spec/support/mixins',
290
+ 'spec/support/shared_examples'
291
+ ].each do |dir|
292
+ run "mkdir #{dir}"
293
+ run "touch #{dir}/.keep"
294
+ end
295
+ end
296
+
297
+ def init_git
298
+ run 'git init'
299
+ end
300
+
301
+ def create_heroku_apps
302
+ path_addition = override_path_for_tests
303
+ run "#{path_addition} heroku create #{app_name}-production --remote=production"
304
+ run "#{path_addition} heroku create #{app_name}-staging --remote=staging"
305
+ run "#{path_addition} heroku config:add RACK_ENV=staging RAILS_ENV=staging --remote=staging"
306
+ end
307
+
308
+ def set_heroku_remotes
309
+ remotes = <<-SHELL
310
+
311
+ # Set up staging and production git remotes.
312
+ git remote add staging git@heroku.com:#{app_name}-staging.git || true
313
+ git remote add production git@heroku.com:#{app_name}-production.git || true
314
+
315
+ # Join the staging and production apps.
316
+ #{join_heroku_app('staging')}
317
+ #{join_heroku_app('production')}
318
+ SHELL
319
+
320
+ append_file 'bin/setup', remotes
321
+ end
322
+
323
+ def join_heroku_app(environment)
324
+ heroku_app_name = "#{app_name}-#{environment}"
325
+ <<-SHELL
326
+ if heroku join --app #{heroku_app_name} &> /dev/null; then
327
+ echo 'You are a collaborator on the "#{heroku_app_name}" Heroku app'
328
+ else
329
+ echo 'Ask for access to the "#{heroku_app_name}" Heroku app'
330
+ fi
331
+ SHELL
332
+ end
333
+
334
+ def set_heroku_rails_secrets
335
+ path_addition = override_path_for_tests
336
+ run "#{path_addition} heroku config:add SECRET_KEY_BASE=#{generate_secret} --remote=staging"
337
+ run "#{path_addition} heroku config:add SECRET_KEY_BASE=#{generate_secret} --remote=production"
338
+ end
339
+
340
+ def create_github_repo(repo_name)
341
+ path_addition = override_path_for_tests
342
+ run "#{path_addition} hub create #{repo_name}"
343
+ end
344
+
345
+ def setup_segment_io
346
+ copy_file '_analytics.html.erb',
347
+ 'app/views/application/_analytics.html.erb'
348
+ end
349
+
350
+ def copy_miscellaneous_files
351
+ copy_file 'errors.rb', 'config/initializers/errors.rb'
352
+ end
353
+
354
+ def customize_error_pages
355
+ meta_tags =<<-EOS
356
+ <meta charset='utf-8' />
357
+ <meta name='ROBOTS' content='NOODP' />
358
+ <meta name='viewport' content='initial-scale=1' />
359
+ EOS
360
+
361
+ %w(500 404 422).each do |page|
362
+ inject_into_file "public/#{page}.html", meta_tags, :after => "<head>\n"
363
+ replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
364
+ end
365
+ end
366
+
367
+ def remove_routes_comment_lines
368
+ replace_in_file 'config/routes.rb',
369
+ /Rails\.application\.routes\.draw do.*end/m,
370
+ "Rails.application.routes.draw do\nend"
371
+ end
372
+
373
+ def disable_xml_params
374
+ copy_file 'disable_xml_params.rb', 'config/initializers/disable_xml_params.rb'
375
+ end
376
+
377
+ def setup_default_rake_task
378
+ append_file 'Rakefile' do
379
+ "task(:default).clear\ntask :default => [:spec]\n"
380
+ end
381
+ end
382
+
383
+ private
384
+
385
+ def override_path_for_tests
386
+ if ENV['TESTING']
387
+ support_bin = File.expand_path(File.join('..', '..', 'spec', 'fakes', 'bin'))
388
+ "PATH=#{support_bin}:$PATH"
389
+ end
390
+ end
391
+
392
+ def factories_spec_rake_task
393
+ IO.read find_in_source_paths('factories_spec_rake_task.rb')
394
+ end
395
+
396
+ def generate_secret
397
+ SecureRandom.hex(64)
398
+ end
399
+ end
400
+ end