initiate 0.1.0

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.
Files changed (60) 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 +48 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +21 -0
  8. data/NEWS.md +444 -0
  9. data/README.md +129 -0
  10. data/Rakefile +8 -0
  11. data/bin/initiate +18 -0
  12. data/bin/rake +16 -0
  13. data/bin/rspec +16 -0
  14. data/bin/setup +13 -0
  15. data/lib/initiate.rb +6 -0
  16. data/lib/initiate/actions.rb +33 -0
  17. data/lib/initiate/app_builder.rb +341 -0
  18. data/lib/initiate/config.rb +9 -0
  19. data/lib/initiate/generators/app_generator.rb +174 -0
  20. data/lib/initiate/version.rb +5 -0
  21. data/spec/features/new_project_spec.rb +131 -0
  22. data/spec/spec_helper.rb +14 -0
  23. data/spec/support/initiate.rb +51 -0
  24. data/suspenders.gemspec +35 -0
  25. data/templates/Gemfile.erb +53 -0
  26. data/templates/Procfile +2 -0
  27. data/templates/README.md.erb +18 -0
  28. data/templates/_flashes.html.erb +7 -0
  29. data/templates/_javascript.html.erb +6 -0
  30. data/templates/action_mailer.rb +5 -0
  31. data/templates/annotate.rake +4 -0
  32. data/templates/application.html.slim.erb +10 -0
  33. data/templates/application.scss +1 -0
  34. data/templates/bin_setup.erb +32 -0
  35. data/templates/browserslist +4 -0
  36. data/templates/bugsnag.rb +5 -0
  37. data/templates/bundler_audit.rake +12 -0
  38. data/templates/capybara_webkit.rb +5 -0
  39. data/templates/config_i18n_tasks.yml +13 -0
  40. data/templates/config_locales_en.yml.erb +19 -0
  41. data/templates/database_cleaner_rspec.rb +21 -0
  42. data/templates/deploy.rb +95 -0
  43. data/templates/dev.rake +12 -0
  44. data/templates/disable_xml_params.rb +1 -0
  45. data/templates/errors.rb +34 -0
  46. data/templates/factories.rb +2 -0
  47. data/templates/factory_girl_rspec.rb +3 -0
  48. data/templates/flashes_helper.rb +5 -0
  49. data/templates/i18n.rb +3 -0
  50. data/templates/json_encoding.rb +1 -0
  51. data/templates/postgresql_database.yml.erb +23 -0
  52. data/templates/rails_helper.rb +22 -0
  53. data/templates/sample.env +9 -0
  54. data/templates/secrets.yml +15 -0
  55. data/templates/shoulda_matchers_config_rspec.rb +6 -0
  56. data/templates/smtp.rb +9 -0
  57. data/templates/spec_helper.rb +23 -0
  58. data/templates/staging.rb +9 -0
  59. data/templates/suspenders_gitignore +13 -0
  60. metadata +167 -0
@@ -0,0 +1,9 @@
1
+ module Initiate
2
+ class Config
3
+ mattr_accessor :use_bootstrap
4
+
5
+ class << self
6
+ alias_method :use_bootstrap?, :use_bootstrap
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,174 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/rails/app/app_generator'
3
+
4
+ # TODO: test setup
5
+ # TODO: Devise
6
+ # TODO: introspect
7
+ module Initiate
8
+ class AppGenerator < Rails::Generators::AppGenerator
9
+ def finish_template
10
+ invoke :initiate_customization
11
+ super
12
+ end
13
+
14
+ def initiate_customization
15
+ invoke :customize_gemfile
16
+ invoke :setup_database
17
+ invoke :setup_bugsang
18
+ invoke :setup_development_environment
19
+ invoke :setup_test_environment
20
+ invoke :setup_production_environment
21
+ invoke :setup_staging_environment
22
+ invoke :create_initiate_views
23
+ invoke :configure_app
24
+ invoke :setup_stylesheets
25
+ invoke :copy_miscellaneous_files
26
+ invoke :remove_routes_comment_lines
27
+ invoke :setup_git
28
+ invoke :setup_bundler_audit
29
+ invoke :setup_annotate
30
+ invoke :setup_spring
31
+ invoke :setup_secret_token
32
+ invoke :outro
33
+ end
34
+
35
+ def customize_gemfile
36
+ build :replace_gemfile
37
+ build :set_ruby_to_version_being_used
38
+ bundle_command 'install'
39
+ end
40
+
41
+ def setup_database
42
+ say 'Setting up database'
43
+ build :use_postgres_config_template
44
+ build :create_database
45
+ end
46
+
47
+ def setup_bugsang
48
+ say 'Setting up Bugsnag'
49
+ build :generate_bugsnag
50
+ end
51
+
52
+ def setup_development_environment
53
+ say 'Setting up the development environment'
54
+ build :setup_development_mailer
55
+ build :raise_on_unpermitted_parameters
56
+ build :provide_bin_setup_script
57
+ build :provide_dev_prime_task
58
+ build :configure_generators
59
+ build :configure_i18n_for_missing_translations
60
+ build :configure_quiet_assets
61
+ end
62
+
63
+ def setup_test_environment
64
+ say 'Setting up the test environment'
65
+ build :set_up_factory_girl_for_rspec
66
+ build :generate_factories_file
67
+ build :generate_rspec
68
+ build :configure_rspec
69
+ build :configure_background_jobs_for_rspec
70
+ build :enable_database_cleaner
71
+ build :provide_shoulda_matchers_config
72
+ build :configure_spec_support_features
73
+ build :configure_i18n_for_test_environment
74
+ build :configure_i18n_tasks
75
+ build :configure_action_mailer_in_specs
76
+ build :configure_capybara_webkit
77
+ end
78
+
79
+ def setup_production_environment
80
+ say 'Setting up the production environment'
81
+ build :configure_smtp
82
+ build :enable_rack_deflater
83
+ build :setup_asset_host
84
+ end
85
+
86
+ def setup_staging_environment
87
+ say 'Setting up the staging environment'
88
+ build :setup_staging_environment
89
+ end
90
+
91
+ def setup_secret_token
92
+ say 'Moving secret token out of version control'
93
+ build :setup_secret_token
94
+ end
95
+
96
+ def create_initiate_views
97
+ say 'Creating initiate views'
98
+ build :create_partials_directory
99
+ build :create_shared_flashes
100
+ build :create_shared_javascripts
101
+ build :create_application_layout
102
+ end
103
+
104
+ def configure_app
105
+ say 'Configuring app'
106
+ build :configure_action_mailer
107
+ build :configure_active_job
108
+ build :configure_time_formats
109
+ build :configure_simple_form
110
+ build :disable_xml_params
111
+ build :fix_i18n_deprecation_warning
112
+ build :setup_default_rake_task
113
+ end
114
+
115
+ def setup_stylesheets
116
+ say 'Set up stylesheets'
117
+ build :setup_stylesheets
118
+ end
119
+
120
+ def setup_git
121
+ say 'Initializing git'
122
+ invoke :setup_gitignore
123
+ invoke :init_git
124
+ end
125
+
126
+ def setup_gitignore
127
+ build :gitignore_files
128
+ end
129
+
130
+ def setup_bundler_audit
131
+ say "Setting up bundler-audit"
132
+ build :setup_bundler_audit
133
+ end
134
+
135
+ def setup_annotate
136
+ say "Setting up annotate"
137
+ build :setup_annotate
138
+ end
139
+
140
+ def setup_spring
141
+ say "Springifying binstubs"
142
+ build :setup_spring
143
+ end
144
+
145
+ def init_git
146
+ build :init_git
147
+ end
148
+
149
+ def copy_miscellaneous_files
150
+ say 'Copying miscellaneous support files'
151
+ build :copy_miscellaneous_files
152
+ end
153
+
154
+ def remove_routes_comment_lines
155
+ build :remove_routes_comment_lines
156
+ end
157
+
158
+ def outro
159
+ say '*************************************'
160
+ say 'Remember to add your BUGSNAG API key.'
161
+ say '*************************************'
162
+ end
163
+
164
+ private
165
+
166
+ def get_builder_class
167
+ Initiate::AppBuilder
168
+ end
169
+
170
+ def using_active_record?
171
+ !options[:skip_active_record]
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,5 @@
1
+ module Initiate
2
+ RAILS_VERSION = "~> 4.2.0"
3
+ RUBY_VERSION = IO.read("#{File.dirname(__FILE__)}/../../.ruby-version").strip
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ RSpec.describe "Suspend a new project with default configuration" do
5
+ before(:all) do
6
+ drop_dummy_database
7
+ remove_project_directory
8
+ run_initiate
9
+ end
10
+
11
+ it "ensures project specs pass" do
12
+ Dir.chdir(project_path) do
13
+ Bundler.with_clean_env do
14
+ expect(`rake`).to include('0 failures')
15
+ end
16
+ end
17
+ end
18
+
19
+ it "inherits staging config from production" do
20
+ staging_file = IO.read("#{project_path}/config/environments/staging.rb")
21
+ config_stub = "Rails.application.configure do"
22
+
23
+ expect(staging_file).to match(/^require_relative "production"/)
24
+ expect(staging_file).to match(/#{config_stub}/), staging_file
25
+ end
26
+
27
+ it "creates .ruby-version from Initiate .ruby-version" do
28
+ ruby_version_file = IO.read("#{project_path}/.ruby-version")
29
+
30
+ expect(ruby_version_file).to eq "#{RUBY_VERSION}\n"
31
+ end
32
+
33
+ it "loads secret_key_base from env" do
34
+ secrets_file = IO.read("#{project_path}/config/secrets.yml")
35
+
36
+ expect(secrets_file).to match(/secret_key_base: <%= ENV.fetch\('SECRET_KEY_BASE'\) %>/)
37
+ end
38
+
39
+ it "adds support file for action mailer" do
40
+ expect(File).to exist("#{project_path}/spec/support/action_mailer.rb")
41
+ end
42
+
43
+ it "configures capybara-webkit" do
44
+ expect(File).to exist("#{project_path}/spec/support/capybara_webkit.rb")
45
+ end
46
+
47
+ it "adds support file for i18n" do
48
+ expect(File).to exist("#{project_path}/spec/support/i18n.rb")
49
+ end
50
+
51
+ it "raises on unpermitted parameters in all environments" do
52
+ result = IO.read("#{project_path}/config/application.rb")
53
+
54
+ expect(result).to match(
55
+ /^ +config.action_controller.action_on_unpermitted_parameters = :raise$/
56
+ )
57
+ end
58
+
59
+ it "adds explicit quiet_assets configuration" do
60
+ result = IO.read("#{project_path}/config/application.rb")
61
+
62
+ expect(result).to match(
63
+ /^ +config.quiet_assets = true$/
64
+ )
65
+ end
66
+
67
+ it "raises on missing translations in development and test" do
68
+ %w[development test].each do |environment|
69
+ environment_file =
70
+ IO.read("#{project_path}/config/environments/#{environment}.rb")
71
+ expect(environment_file).to match(
72
+ /^ +config.action_view.raise_on_missing_translations = true$/
73
+ )
74
+ end
75
+ end
76
+
77
+ it "adds specs for missing or unused translations" do
78
+ expect(File).to exist("#{project_path}/spec/i18n_spec.rb")
79
+ end
80
+
81
+ it "configs i18n-tasks" do
82
+ expect(File).to exist("#{project_path}/config/i18n-tasks.yml")
83
+ end
84
+
85
+ it "evaluates en.yml.erb" do
86
+ locales_en_file = IO.read("#{project_path}/config/locales/en.yml")
87
+ app_name = InitiateTestHelpers::APP_NAME
88
+
89
+ expect(locales_en_file).to match(/application: #{app_name.humanize}/)
90
+ end
91
+
92
+ it "configs simple_form" do
93
+ expect(File).to exist("#{project_path}/config/initializers/simple_form.rb")
94
+ end
95
+
96
+ it "configs :letter_opener email delivery method for development" do
97
+ dev_env_file = IO.read("#{project_path}/config/environments/development.rb")
98
+ expect(dev_env_file).
99
+ to match(/^ +config.action_mailer.delivery_method = :letter_opener$/)
100
+ end
101
+
102
+ it "configs active job queue adapter" do
103
+ application_config = IO.read("#{project_path}/config/application.rb")
104
+ test_config = IO.read("#{project_path}/config/environments/test.rb")
105
+
106
+ expect(application_config).to match(
107
+ /^ +config.active_job.queue_adapter = :delayed_job$/
108
+ )
109
+ expect(test_config).to match(
110
+ /^ +config.active_job.queue_adapter = :inline$/
111
+ )
112
+ end
113
+
114
+ it "adds spring to binstubs" do
115
+ expect(File).to exist("#{project_path}/bin/spring")
116
+
117
+ spring_line = /^ +load File.expand_path\("\.\.\/spring", __FILE__\)$/
118
+ bin_stubs = %w(rake rails rspec)
119
+ bin_stubs.each do |bin_stub|
120
+ expect(IO.read("#{project_path}/bin/#{bin_stub}")).to match(spring_line)
121
+ end
122
+ end
123
+
124
+ it "copies factories.rb" do
125
+ expect(File).to exist("#{project_path}/spec/factories.rb")
126
+ end
127
+
128
+ def analytics_partial
129
+ IO.read("#{project_path}/app/views/application/_analytics.html.erb")
130
+ end
131
+ end
@@ -0,0 +1,14 @@
1
+ require 'bundler/setup'
2
+
3
+ Bundler.require(:default, :test)
4
+
5
+ require (Pathname.new(__FILE__).dirname + '../lib/initiate').expand_path
6
+
7
+ Dir['./spec/support/**/*.rb'].each { |file| require file }
8
+
9
+ RSpec.configure do |config|
10
+ config.include InitiateTestHelpers
11
+ config.before(:all) do
12
+ create_tmp_directory
13
+ end
14
+ end
@@ -0,0 +1,51 @@
1
+ module InitiateTestHelpers
2
+ APP_NAME = "dummy_app"
3
+
4
+ def remove_project_directory
5
+ FileUtils.rm_rf(project_path)
6
+ end
7
+
8
+ def create_tmp_directory
9
+ FileUtils.mkdir_p(tmp_path)
10
+ end
11
+
12
+ def run_initiate(arguments = nil)
13
+ Dir.chdir(tmp_path) do
14
+ Bundler.with_clean_env do
15
+ ENV['TESTING'] = '1'
16
+ ENV['SECRET_KEY_BASE'] = '3b9ed53546e0f1bc9b45694b82143e6e4079543d77yy55wd5f7ccdd162a0382ZeD50dfeb40c21ada7b69808eb1faa900cdc4d523e6752348283a6558030122a6'
17
+ ENV['BUGSNAG_API_KEY'] = '6b5ab9ff1c7ba4eea039f5d4dd497c8e'
18
+
19
+ `#{initiate_bin} #{APP_NAME} #{arguments}`
20
+ end
21
+ end
22
+ end
23
+
24
+ def drop_dummy_database
25
+ if File.exist?(project_path)
26
+ Dir.chdir(project_path) do
27
+ Bundler.with_clean_env do
28
+ `rake db:drop`
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ def project_path
35
+ @project_path ||= Pathname.new("#{tmp_path}/#{APP_NAME}")
36
+ end
37
+
38
+ private
39
+
40
+ def tmp_path
41
+ @tmp_path ||= Pathname.new("#{root_path}/tmp")
42
+ end
43
+
44
+ def initiate_bin
45
+ File.join(root_path, 'bin', 'initiate')
46
+ end
47
+
48
+ def root_path
49
+ File.expand_path('../../../', __FILE__)
50
+ end
51
+ end
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'initiate/version'
4
+ require 'date'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.required_ruby_version = ">= #{Initiate::RUBY_VERSION}"
8
+ s.authors = ['thoughtbot']
9
+ s.date = Date.today.strftime('%Y-%m-%d')
10
+
11
+ s.description = <<-HERE
12
+ Initiate is a base Rails project that you can upgrade. It is used by
13
+ thoughtbot to get a jump start on a working app. Use Initiate 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 = 'support@thoughtbot.com'
18
+ s.executables = ['initiate']
19
+ s.extra_rdoc_files = %w[README.md LICENSE]
20
+ s.files = `git ls-files`.split("\n")
21
+ s.homepage = 'http://github.com/thoughtbot/initiate'
22
+ s.license = 'MIT'
23
+ s.name = 'initiate'
24
+ s.rdoc_options = ['--charset=UTF-8']
25
+ s.require_paths = ['lib']
26
+ s.summary = "Generate a Rails app using thoughtbot's best practices."
27
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
+ s.version = Initiate::VERSION
29
+
30
+ s.add_dependency 'bundler', '~> 1.3'
31
+ s.add_dependency 'rails', Initiate::RAILS_VERSION
32
+
33
+ s.add_development_dependency 'rspec', '~> 3.2'
34
+ s.add_development_dependency 'pry'
35
+ end
@@ -0,0 +1,53 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "autoprefixer-rails"
4
+ gem "bugsnag"
5
+ gem "delayed_job_active_record"
6
+ gem "flutie"
7
+ gem "jquery-rails"
8
+ gem "mina", require: false
9
+ gem "pg"
10
+ gem "rails", "<%= Initiate::RAILS_VERSION %>"
11
+ gem "recipient_interceptor"
12
+ gem "sass-rails", "~> 5.0"
13
+ gem "simple_form"
14
+ gem "slim-rails"
15
+ gem "title"
16
+ gem "uglifier"
17
+ gem "turbolinks"
18
+ gem "jquery-turbolinks"
19
+
20
+ group :development do
21
+ gem "quiet_assets"
22
+ gem "spring"
23
+ gem "spring-commands-rspec"
24
+ gem "better_errors"
25
+ gem "binding_of_caller"
26
+ gem 'quiet_assets'
27
+ gem "bullet"
28
+ gem "traceroute"
29
+ gem "letter_opener"
30
+ gem "annotate"
31
+ end
32
+
33
+ group :development, :test do
34
+ gem "awesome_print"
35
+ gem "bundler-audit", require: false
36
+ gem "byebug"
37
+ gem "dotenv-rails"
38
+ gem "factory_girl_rails"
39
+ gem "i18n-tasks"
40
+ gem "pry-rails"
41
+ gem "rspec-rails", "~> 3.3.0"
42
+ end
43
+
44
+ group :test do
45
+ gem "capybara-webkit"
46
+ gem "database_cleaner"
47
+ gem "formulaic"
48
+ gem "launchy"
49
+ gem "shoulda-matchers", require: false
50
+ gem "simplecov", require: false
51
+ gem "timecop"
52
+ gem "webmock"
53
+ end