yupi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) 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 +33 -0
  6. data/Gemfile +3 -0
  7. data/Gemfile.lock +139 -0
  8. data/LICENSE +21 -0
  9. data/NEWS.md +8 -0
  10. data/README.md +72 -0
  11. data/Rakefile +11 -0
  12. data/bin/rake +16 -0
  13. data/bin/rspec +16 -0
  14. data/bin/setup +9 -0
  15. data/bin/yupi +13 -0
  16. data/lib/yupi.rb +4 -0
  17. data/lib/yupi/actions.rb +33 -0
  18. data/lib/yupi/app_builder.rb +368 -0
  19. data/lib/yupi/generators/app_generator.rb +201 -0
  20. data/lib/yupi/version.rb +5 -0
  21. data/spec/features/new_project_spec.rb +135 -0
  22. data/spec/spec_helper.rb +24 -0
  23. data/spec/support/yupi.rb +51 -0
  24. data/templates/Gemfile.erb +52 -0
  25. data/templates/Procfile +2 -0
  26. data/templates/README.md.erb +32 -0
  27. data/templates/assets/application.css.scss +4 -0
  28. data/templates/assets/application.js +3 -0
  29. data/templates/bin/setup.erb +23 -0
  30. data/templates/config/application.yml.sample +4 -0
  31. data/templates/config/i18n_tasks.yml +13 -0
  32. data/templates/config/initializers/disable_xml_params.rb +3 -0
  33. data/templates/config/initializers/errors.rb +34 -0
  34. data/templates/config/initializers/json_encoding.rb +1 -0
  35. data/templates/config/initializers/mail_interceptor.rb +3 -0
  36. data/templates/config/initializers/rack_timeout.rb +1 -0
  37. data/templates/config/locales_en.yml.erb +19 -0
  38. data/templates/config/newrelic.yml.erb +30 -0
  39. data/templates/config/postgresql_database.yml.erb +12 -0
  40. data/templates/config/rails_secrets.yml +11 -0
  41. data/templates/config/smtp.rb +9 -0
  42. data/templates/dot_gitignore +15 -0
  43. data/templates/spec/rails_helper.rb +23 -0
  44. data/templates/spec/spec_helper.rb +17 -0
  45. data/templates/spec/support/action_mailer.rb +5 -0
  46. data/templates/spec/support/database_cleaner_rspec.rb +21 -0
  47. data/templates/spec/support/factory_girl_rspec.rb +3 -0
  48. data/templates/spec/support/i18n.rb +3 -0
  49. data/templates/tasks/bundler_audit.rake +12 -0
  50. data/templates/tasks/development_seeds.rake +12 -0
  51. data/templates/views/application/_analytics.html.erb +7 -0
  52. data/templates/views/application/_flashes.html.erb +6 -0
  53. data/templates/views/application/_footer.html.erb +17 -0
  54. data/templates/views/application/_javascript.html.erb +12 -0
  55. data/templates/views/application/_navigation.html.erb +18 -0
  56. data/templates/views/application/_navigation_links.html.erb +2 -0
  57. data/templates/views/layouts/application.html.erb.erb +43 -0
  58. data/templates/views/pages/home.html.erb +1 -0
  59. data/yupi.gemspec +36 -0
  60. metadata +187 -0
@@ -0,0 +1,201 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/rails/app/app_generator'
3
+
4
+ module Yupi
5
+ class AppGenerator < Rails::Generators::AppGenerator
6
+ class_option :database, type: :string, aliases: "-d", default: "postgresql",
7
+ desc: "Configure for selected database (options: #{DATABASES.join("/")})"
8
+
9
+ class_option :heroku_flags, type: :string, default: "",
10
+ desc: "Set extra Heroku flags"
11
+
12
+ class_option :skip_test_unit, type: :boolean, aliases: "-T", default: true,
13
+ desc: "Skip Test::Unit files"
14
+
15
+ class_option :skip_turbolinks, type: :boolean, default: true,
16
+ desc: "Skip turbolinks gem"
17
+
18
+ class_option :skip_bundle, type: :boolean, aliases: "-B", default: true,
19
+ desc: "Don't run bundle install"
20
+
21
+ def finish_template
22
+ invoke :yupi_customization
23
+ super
24
+ invoke :run_bin_setup
25
+ end
26
+
27
+ def yupi_customization
28
+ invoke :customize_gemfile
29
+ invoke :setup_secret_token
30
+ invoke :create_yupi_views
31
+ invoke :configure_app
32
+ invoke :setup_development_environment
33
+ invoke :setup_test_environment
34
+ invoke :setup_production_environment
35
+ invoke :setup_assets
36
+ invoke :copy_miscellaneous_files
37
+ invoke :customize_error_pages
38
+ invoke :remove_routes_comment_lines
39
+ invoke :add_root_route
40
+ invoke :setup_git
41
+ invoke :setup_database
42
+ invoke :setup_bundler_audit
43
+ invoke :outro
44
+ end
45
+
46
+ def customize_gemfile
47
+ build :replace_gemfile
48
+ build :set_ruby_to_version_being_used
49
+
50
+ bundle_command 'install'
51
+ end
52
+
53
+ def setup_database
54
+ say 'Setting up database'
55
+
56
+ if 'postgresql' == options[:database]
57
+ build :use_postgres_config_template
58
+ end
59
+
60
+ build :create_database
61
+ end
62
+
63
+ def setup_development_environment
64
+ say 'Setting up the development environment'
65
+ build :raise_on_delivery_errors
66
+ build :set_test_delivery_method
67
+ build :raise_on_unpermitted_parameters
68
+ build :provide_setup_script
69
+ build :provide_dev_prime_task
70
+ build :configure_generators
71
+ build :configure_i18n_for_missing_translations
72
+ end
73
+
74
+ def setup_test_environment
75
+ say 'Setting up the test environment'
76
+ build :set_up_factory_girl_for_rspec
77
+ build :generate_rspec
78
+ build :configure_rspec
79
+ build :configure_background_jobs_for_rspec
80
+ build :enable_database_cleaner
81
+ build :configure_spec_support_features
82
+ build :configure_i18n_for_test_environment
83
+ build :configure_i18n_tasks
84
+ build :configure_action_mailer_in_specs
85
+ end
86
+
87
+ def setup_production_environment
88
+ say 'Setting up the production environment'
89
+ build :configure_newrelic
90
+ build :configure_smtp
91
+ build :enable_rack_deflater
92
+ build :setup_asset_host
93
+ end
94
+
95
+ def setup_staging_environment
96
+ say 'Setting up the staging environment'
97
+ build :setup_staging_environment
98
+ end
99
+
100
+ def setup_secret_token
101
+ say 'Moving secret token out of version control'
102
+ build :setup_secret_token
103
+ end
104
+
105
+ def create_yupi_views
106
+ say 'Creating yupi views'
107
+ build :create_partials
108
+ build :create_application_layout
109
+ build :create_home_page
110
+ end
111
+
112
+ def configure_app
113
+ say 'Configuring app'
114
+ build :setup_figaro
115
+ build :configure_action_mailer
116
+ build :configure_active_job
117
+ build :configure_time_formats
118
+ build :configure_rack_timeout
119
+ build :configure_simple_form
120
+ build :disable_xml_params
121
+ build :fix_i18n_deprecation_warning
122
+ build :setup_default_rake_task
123
+ build :configure_puma
124
+ build :setup_foreman
125
+ end
126
+
127
+ def setup_assets
128
+ say 'Set up assets'
129
+ build :setup_stylesheets
130
+ build :setup_javascripts
131
+ end
132
+
133
+ def setup_git
134
+ if !options[:skip_git]
135
+ say 'Initializing git'
136
+ invoke :setup_gitignore
137
+ invoke :init_git
138
+ end
139
+ end
140
+
141
+ def create_heroku_apps
142
+ if options[:heroku]
143
+ say "Creating Heroku apps"
144
+ build :create_heroku_apps, options[:heroku_flags]
145
+ build :set_heroku_serve_static_files
146
+ build :set_heroku_remotes
147
+ build :set_heroku_rails_secrets
148
+ build :provide_deploy_script
149
+ end
150
+ end
151
+
152
+ def setup_gitignore
153
+ build :gitignore_files
154
+ end
155
+
156
+ def setup_bundler_audit
157
+ say "Setting up bundler-audit"
158
+ build :setup_bundler_audit
159
+ end
160
+
161
+ def init_git
162
+ build :init_git
163
+ end
164
+
165
+ def copy_miscellaneous_files
166
+ say 'Copying miscellaneous support files'
167
+ build :copy_miscellaneous_files
168
+ end
169
+
170
+ def customize_error_pages
171
+ say 'Customizing the 500/404/422 pages'
172
+ build :customize_error_pages
173
+ end
174
+
175
+ def remove_routes_comment_lines
176
+ build :remove_routes_comment_lines
177
+ end
178
+
179
+ def add_root_route
180
+ build :add_root_route
181
+ end
182
+
183
+ def run_bin_setup
184
+ build :run_bin_setup
185
+ end
186
+
187
+ def outro
188
+ say 'Congratulations! Now start creating a great app.'
189
+ end
190
+
191
+ protected
192
+
193
+ def get_builder_class
194
+ Yupi::AppBuilder
195
+ end
196
+
197
+ def using_active_record?
198
+ !options[:skip_active_record]
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,5 @@
1
+ module Yupi
2
+ RAILS_VERSION = "4.2.1"
3
+ RUBY_VERSION = IO.read("#{File.dirname(__FILE__)}/../../.ruby-version").strip
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Build a new project with default configuration' do
4
+ scenario 'specs pass', :smoke do
5
+ run_yupi
6
+
7
+ Dir.chdir(project_path) do
8
+ Bundler.with_clean_env do
9
+ expect(`rake`).to include('0 failures')
10
+ end
11
+ end
12
+ end
13
+
14
+ scenario 'generated .ruby-version is pulled from Yupi .ruby-version' do
15
+ run_yupi
16
+
17
+ ruby_version_file = IO.read("#{project_path}/.ruby-version")
18
+
19
+ expect(ruby_version_file).to eq "#{RUBY_VERSION}\n"
20
+ end
21
+
22
+ scenario 'secrets.yml reads secret from env' do
23
+ run_yupi
24
+
25
+ secrets_file = IO.read("#{project_path}/config/secrets.yml")
26
+
27
+ expect(secrets_file).to match(/secret_key_base: <%= ENV\["SECRET_KEY_BASE"\] %>/)
28
+ end
29
+
30
+ scenario 'action mailer support file is added' do
31
+ run_yupi
32
+
33
+ expect(File).to exist("#{project_path}/spec/support/action_mailer.rb")
34
+ end
35
+
36
+ scenario "i18n support file is added" do
37
+ run_yupi
38
+
39
+ expect(File).to exist("#{project_path}/spec/support/i18n.rb")
40
+ end
41
+
42
+ scenario 'newrelic.yml reads NewRelic license from env' do
43
+ run_yupi
44
+
45
+ newrelic_file = IO.read("#{project_path}/config/newrelic.yml")
46
+
47
+ expect(newrelic_file).to match(
48
+ /license_key: "<%= ENV\["NEW_RELIC_LICENSE_KEY"\] %>"/
49
+ )
50
+ end
51
+
52
+ scenario 'records pageviews through Segment if ENV variable set' do
53
+ run_yupi
54
+
55
+ expect(analytics_partial).
56
+ to include(%{<% if ENV["SEGMENT_KEY"] %>})
57
+ expect(analytics_partial).
58
+ to include(%{window.analytics.load("<%= ENV["SEGMENT_KEY"] %>");})
59
+ end
60
+
61
+ scenario "raises on unpermitted parameters in all environments" do
62
+ run_yupi
63
+
64
+ result = IO.read("#{project_path}/config/application.rb")
65
+
66
+ expect(result).to match(
67
+ /^ +config.action_controller.action_on_unpermitted_parameters = :raise$/
68
+ )
69
+ end
70
+
71
+ scenario "raises on missing translations in development and test" do
72
+ run_yupi
73
+
74
+ %w[development test].each do |environment|
75
+ environment_file =
76
+ IO.read("#{project_path}/config/environments/#{environment}.rb")
77
+ expect(environment_file).to match(
78
+ /^ +config.action_view.raise_on_missing_translations = true$/
79
+ )
80
+ end
81
+ end
82
+
83
+ scenario "specs for missing or unused translations" do
84
+ run_yupi
85
+
86
+ expect(File).to exist("#{project_path}/spec/i18n_spec.rb")
87
+ end
88
+
89
+ scenario "config file for i18n tasks" do
90
+ run_yupi
91
+
92
+ expect(File).to exist("#{project_path}/config/i18n-tasks.yml")
93
+ end
94
+
95
+ scenario "generated en.yml is evaluated" do
96
+ run_yupi
97
+
98
+ locales_en_file = IO.read("#{project_path}/config/locales/en.yml")
99
+ app_name = YupiTestHelpers::APP_NAME
100
+
101
+ expect(locales_en_file).to match(/application: #{app_name.humanize}/)
102
+ end
103
+
104
+ scenario "config simple_form" do
105
+ run_yupi
106
+
107
+ expect(File).to exist("#{project_path}/config/initializers/simple_form.rb")
108
+ end
109
+
110
+ scenario "config :test email delivery method for development" do
111
+ run_yupi
112
+
113
+ dev_env_file = IO.read("#{project_path}/config/environments/development.rb")
114
+ expect(dev_env_file).
115
+ to match(/^ +config.action_mailer.delivery_method = :test$/)
116
+ end
117
+
118
+ scenario "config active job queue adapter" do
119
+ run_yupi
120
+
121
+ application_config = IO.read("#{project_path}/config/application.rb")
122
+ test_config = IO.read("#{project_path}/config/environments/test.rb")
123
+
124
+ expect(application_config).to match(
125
+ /^ +config.active_job.queue_adapter = :delayed_job$/
126
+ )
127
+ expect(test_config).to match(
128
+ /^ +config.active_job.queue_adapter = :inline$/
129
+ )
130
+ end
131
+
132
+ def analytics_partial
133
+ IO.read("#{project_path}/app/views/application/_analytics.html.erb")
134
+ end
135
+ end
@@ -0,0 +1,24 @@
1
+ require 'capybara/rspec'
2
+ require 'bundler/setup'
3
+
4
+ Bundler.require(:default, :test)
5
+
6
+ require (Pathname.new(__FILE__).dirname + '../lib/yupi').expand_path
7
+
8
+ Dir['./spec/support/**/*.rb'].each { |file| require file }
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.include YupiTestHelpers
13
+
14
+ config.before(:all) do
15
+ drop_dummy_database
16
+ recreate_tmp_directory
17
+ end
18
+
19
+ config.before(:each) do
20
+ drop_dummy_database
21
+ remove_project_directory
22
+ end
23
+
24
+ end
@@ -0,0 +1,51 @@
1
+ module YupiTestHelpers
2
+ APP_NAME = "dummy_app"
3
+
4
+ def remove_project_directory
5
+ FileUtils.rm_rf(project_path)
6
+ end
7
+
8
+ def recreate_tmp_directory
9
+ FileUtils.rm_rf(project_path)
10
+ FileUtils.mkdir_p(tmp_path)
11
+ end
12
+
13
+ def run_yupi(arguments = nil)
14
+ Dir.chdir(tmp_path) do
15
+ Bundler.with_clean_env do
16
+ ENV['TESTING'] = '1'
17
+
18
+ %x(#{yupi_bin} #{APP_NAME} #{arguments})
19
+ fail 'Application generation failed' unless $?.exitstatus == 0
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 yupi_bin
45
+ File.join(root_path, 'bin', 'yupi')
46
+ end
47
+
48
+ def root_path
49
+ File.expand_path('../../../', __FILE__)
50
+ end
51
+ end
@@ -0,0 +1,52 @@
1
+ source "https://rubygems.org"
2
+
3
+ ruby "<%= Yupi::RUBY_VERSION %>"
4
+
5
+ gem "bootstrap-sass", "~> 3.3.4"
6
+ gem "coffee-rails", "~> 4.1.0"
7
+ gem "delayed_job_active_record"
8
+ gem "email_validator"
9
+ gem "high_voltage"
10
+ gem "i18n-tasks"
11
+ gem "jquery-rails"
12
+ gem "newrelic_rpm", ">= 3.9.8"
13
+ gem "pg"
14
+ gem "rack-timeout"
15
+ gem "rails", "<%= Yupi::RAILS_VERSION %>"
16
+ gem "recipient_interceptor"
17
+ gem "sass-rails", "~> 5.0"
18
+ gem "simple_form"
19
+ gem "title"
20
+ gem "uglifier"
21
+ gem "puma"
22
+ gem "figaro"
23
+
24
+ group :development do
25
+ gem "spring"
26
+ gem "spring-commands-rspec"
27
+ gem "web-console"
28
+ end
29
+
30
+ group :development, :test do
31
+ gem "awesome_print"
32
+ gem "bundler-audit", require: false
33
+ gem "byebug"
34
+ gem "dotenv-rails"
35
+ gem "factory_girl_rails"
36
+ gem "pry-rails"
37
+ gem "rspec-rails", "~> 3.1.0"
38
+ end
39
+
40
+ group :test do
41
+ gem "poltergeist"
42
+ gem "database_cleaner"
43
+ gem "formulaic"
44
+ gem "launchy"
45
+ gem "shoulda-matchers", require: false
46
+ gem "timecop"
47
+ gem "webmock"
48
+ end
49
+
50
+ group :production do
51
+ gem "rails_12factor"
52
+ end