bluebase 0.0.2 → 1.0.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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +1 -0
  3. data/README.md +67 -12
  4. data/Rakefile +7 -1
  5. data/bin/bluebase +13 -0
  6. data/bin/bundler +16 -0
  7. data/bin/rake +16 -0
  8. data/bin/rspec +16 -0
  9. data/bluebase.gemspec +1 -0
  10. data/lib/bluebase.rb +3 -6
  11. data/lib/bluebase/actions.rb +25 -0
  12. data/lib/bluebase/app_builder.rb +356 -0
  13. data/lib/bluebase/generators/app_generator.rb +129 -0
  14. data/lib/bluebase/version.rb +1 -1
  15. data/spec/fakes/bin/heroku +5 -0
  16. data/spec/fakes/bin/hub +5 -0
  17. data/spec/features/github_spec.rb +10 -0
  18. data/spec/features/heroku_spec.rb +24 -0
  19. data/spec/features/new_project_spec.rb +68 -0
  20. data/spec/spec_helper.rb +24 -0
  21. data/spec/support/bluebase.rb +49 -0
  22. data/spec/support/fake_github.rb +21 -0
  23. data/spec/support/fake_heroku.rb +32 -0
  24. data/templates/.envrc +1 -0
  25. data/templates/.hound.yml +4 -0
  26. data/templates/.rspec +2 -0
  27. data/templates/.rubocop.yml +20 -0
  28. data/templates/.travis.yml.erb +12 -0
  29. data/templates/Gemfile.erb +74 -0
  30. data/templates/Guardfile +43 -0
  31. data/templates/README.md.erb +30 -0
  32. data/templates/app/_fb_meta_tags.html.slim +6 -0
  33. data/templates/app/_flash.html.slim +2 -0
  34. data/templates/app/_ga_boiler.html.slim +8 -0
  35. data/templates/app/application.css.scss +12 -0
  36. data/templates/app/application.html.slim +23 -0
  37. data/templates/bin/setup +28 -0
  38. data/templates/bluebase_gitignore +18 -0
  39. data/templates/config/application.yml.sample.erb +26 -0
  40. data/templates/config/bluebase_secrets.yml +14 -0
  41. data/templates/config/database.yml.sample.erb +15 -0
  42. data/templates/config/database.yml.travis.erb +4 -0
  43. data/templates/config/devise.rb +298 -0
  44. data/templates/config/en.yml.erb +19 -0
  45. data/templates/config/figaro.rb +2 -0
  46. data/templates/config/i18n-tasks.yml +93 -0
  47. data/templates/config/smtp.rb +9 -0
  48. data/templates/config/staging.rb.erb +9 -0
  49. data/templates/spec/action_mailer.rb +5 -0
  50. data/templates/spec/database_cleaner_and_factory_girl_lint.rb +26 -0
  51. data/templates/spec/factory_girl.rb +3 -0
  52. data/templates/spec/i18n.rb +3 -0
  53. data/templates/spec/rails_helper.rb +30 -0
  54. data/templates/spec/spec_helper.rb +17 -0
  55. metadata +79 -4
@@ -0,0 +1,129 @@
1
+ require "rails/generators"
2
+ require "rails/generators/rails/app/app_generator"
3
+
4
+ module Bluebase
5
+ class AppGenerator < Rails::Generators::AppGenerator
6
+ class_option :database, type: :string, aliases: "-d", default: "postgresql",
7
+ desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})"
8
+
9
+ class_option :heroku, type: :boolean, aliases: "-H", default: false,
10
+ desc: "Create staging and production Heroku apps"
11
+
12
+ class_option :skip_git, type: :boolean, default: false, desc: "Skip git init"
13
+
14
+ class_option :skip_bundle, type: :boolean, default: true, desc: "Don't run bundle install"
15
+
16
+ class_option :github, type: :string, aliases: "-G", default: nil,
17
+ desc: "Create Github repository and add remote origin pointed to repo"
18
+
19
+ class_option :skip_test_unit, type: :boolean, aliases: "-T", default: true,
20
+ desc: "Skip Test::Unit files"
21
+
22
+ # Invoked after Rails generates app
23
+ def finish_template
24
+ invoke :bluebase_customization
25
+ super
26
+ end
27
+
28
+ def bluebase_customization
29
+ invoke :customize_root_files
30
+ invoke :customize_app_files
31
+ invoke :customize_bin_files
32
+ invoke :customize_config_files
33
+ invoke :customize_spec_files
34
+ invoke :setup_git_and_github
35
+ invoke :setup_heroku_apps
36
+ invoke :outro
37
+ end
38
+
39
+ def customize_root_files
40
+ build :replace_gemfile
41
+ build :add_envrc
42
+ build :replace_gitignore
43
+ build :add_rubocop_and_hound_config
44
+ build :add_rvm_config
45
+ build :add_travis_config
46
+ build :add_guardfile
47
+ build :add_dot_rspec
48
+ end
49
+
50
+ def customize_app_files
51
+ build :add_vendor_dirs
52
+ build :replace_application_css_with_scss
53
+ build :add_application_folder_and_files_to_views
54
+ build :replace_application_erb_with_slim
55
+ end
56
+
57
+ def customize_bin_files
58
+ build :add_setup_to_bin
59
+ end
60
+
61
+ def customize_config_files
62
+ build :configure_application_environment
63
+ build :configure_development_environment
64
+ build :configure_test_environment
65
+ build :configure_production_environment
66
+ build :add_staging_environment
67
+ build :add_devise_config
68
+ build :add_figaro_config
69
+ build :replace_en_yml
70
+ build :add_application_yml
71
+ build :add_database_yml if options[:database] == 'postgresql'
72
+ build :add_travis_database_yml
73
+ build :add_i18n_tasks_yml
74
+ build :replace_secrets_yml
75
+ build :add_smtp_settings
76
+ build :remove_routes_comment_lines
77
+ end
78
+
79
+ def customize_spec_files
80
+ build :add_spec_dirs
81
+ build :configure_rspec
82
+ build :configure_factorygirl
83
+ build :configure_actionmailer
84
+ build :configure_i18n
85
+ build :configure_database_cleaner
86
+ end
87
+
88
+ def setup_git_and_github
89
+ if !options[:skip_git]
90
+ say "Initializing git"
91
+ build :git_init
92
+ if options[:github]
93
+ say "Creating github repo"
94
+ build :create_github_repo, options[:github]
95
+ end
96
+ end
97
+ end
98
+
99
+ def setup_heroku_apps
100
+ if options[:heroku]
101
+ say "Creating heroku apps"
102
+ build :create_heroku_apps
103
+ build :set_heroku_remotes
104
+ build :set_heroku_env_variables
105
+ build :add_heroku_addons
106
+ build :set_memory_management_variable
107
+ end
108
+ end
109
+
110
+ def outro
111
+ say "Your bluebase is complete!"
112
+ say "Remember to set:"
113
+ say "- Your database settings in config/database.yml"
114
+ say "- Your env variables in config/application.yml"
115
+ say "- Your Code Climate token in .travis.yml"
116
+ say "Afterward, you can now run bin/setup in your project directory to set up the app."
117
+ end
118
+
119
+ def run_bundle
120
+ # We'll run it ourselves
121
+ end
122
+
123
+ private
124
+
125
+ def get_builder_class
126
+ Bluebase::AppBuilder
127
+ end
128
+ end
129
+ end
@@ -1,5 +1,5 @@
1
1
  module Bluebase
2
2
  RAILS_VERSION = "4.1.7"
3
3
  RUBY_VERSION = IO.read("#{File.dirname(__FILE__)}/../../.ruby-version").strip
4
- VERSION = "0.0.2"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join('..', '..', 'support', 'fake_heroku'), File.dirname(__FILE__))
4
+
5
+ FakeHeroku.new(ARGV).run!
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join('..', '..', 'support', 'fake_github'), File.dirname(__FILE__))
4
+
5
+ FakeGithub.new(ARGV).run!
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'GitHub' do
4
+ scenario 'Initialize a project with --github option' do
5
+ repo_name = 'test'
6
+ run_bluebase("--github=#{repo_name}")
7
+
8
+ expect(FakeGithub).to have_created_repo(repo_name)
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Heroku' do
4
+ scenario 'Initialize a project with --heroku=true' do
5
+ run_bluebase('--heroku=true')
6
+
7
+ expect(FakeHeroku).to have_gem_included(project_path, 'rails_12factor')
8
+ expect(FakeHeroku).to have_created_app_for('staging')
9
+ expect(FakeHeroku).to have_created_app_for('production')
10
+
11
+ bin_setup = IO.read("#{project_path}/bin/setup")
12
+ app_name = BluebaseTestHelpers::APP_NAME
13
+
14
+ expect(bin_setup).to include("figaro heroku:set -a #{app_name}-production -e production")
15
+ expect(bin_setup).to include("figaro heroku:set -a #{app_name}-staging -e production")
16
+
17
+ expect(bin_setup).to include("heroku join --app #{app_name}-staging")
18
+ expect(bin_setup).to include("heroku join --app #{app_name}-production")
19
+
20
+ expect(bin_setup).to include("heroku addons:add mandrill --app #{app_name}-production")
21
+ expect(bin_setup).to include("heroku addons:add newrelic:stark --app #{app_name}-production")
22
+ expect(bin_setup).to include("heroku addons:add rollbar --app #{app_name}-production")
23
+ end
24
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Initialize a new project with default configuration' do
4
+ # TODO: Write comprehensive specs
5
+ before { run_bluebase }
6
+
7
+ scenario 'staging config is inherited from production' do
8
+ staging_file = IO.read("#{project_path}/config/environments/staging.rb")
9
+ config_stub = "Rails.application.configure do"
10
+
11
+ expect(staging_file).to match(/^require_relative "production"/)
12
+ expect(staging_file).to match(/#{config_stub}/), staging_file
13
+ end
14
+
15
+ scenario 'generated .ruby-version is pulled from Bluebase .ruby-version' do
16
+ ruby_version_file = IO.read("#{project_path}/.ruby-version")
17
+
18
+ expect(ruby_version_file).to eq "#{RUBY_VERSION}\n"
19
+ end
20
+
21
+ scenario 'secrets.yml reads secret from env' do
22
+ secrets_file = IO.read("#{project_path}/config/secrets.yml")
23
+
24
+ expect(secrets_file).to match(/secret_key_base: <%= ENV\["SECRET_KEY_BASE"\] %>/)
25
+ end
26
+
27
+ scenario 'action mailer support file is added' do
28
+ expect(File).to exist("#{project_path}/spec/support/action_mailer.rb")
29
+ end
30
+
31
+ scenario "i18n support file is added" do
32
+ expect(File).to exist("#{project_path}/spec/support/i18n.rb")
33
+ end
34
+
35
+ scenario "raises on unpermitted parameters in all environments" do
36
+ result = IO.read("#{project_path}/config/application.rb")
37
+
38
+ expect(result).to match(
39
+ /^ +config.action_controller.action_on_unpermitted_parameters = :raise$/
40
+ )
41
+ end
42
+
43
+ scenario "raises on missing translations in development and test" do
44
+ %w[development test].each do |environment|
45
+ environment_file =
46
+ IO.read("#{project_path}/config/environments/#{environment}.rb")
47
+ expect(environment_file).to match(
48
+ /^ +config.action_view.raise_on_missing_translations = true$/
49
+ )
50
+ end
51
+ end
52
+
53
+ scenario "specs for missing or unused translations" do
54
+ bin_setup = IO.read("#{project_path}/bin/setup")
55
+ expect(bin_setup).to include("cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/")
56
+ end
57
+
58
+ scenario "config file for i18n tasks" do
59
+ expect(File).to exist("#{project_path}/config/i18n-tasks.yml")
60
+ end
61
+
62
+ scenario "generated en.yml is evaluated" do
63
+ locales_en_file = IO.read("#{project_path}/config/locales/en.yml")
64
+ app_name = BluebaseTestHelpers::APP_NAME
65
+
66
+ expect(locales_en_file).to match(/application: #{app_name.humanize}/)
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ require 'capybara/rspec'
2
+ require 'bundler/setup'
3
+ require 'pry'
4
+
5
+ Bundler.require(:default, :test)
6
+
7
+ require (Pathname.new(__FILE__).dirname + '../lib/bluebase').expand_path
8
+
9
+ Dir['./spec/support/**/*.rb'].each { |file| require file }
10
+ RSpec.configure do |config|
11
+ config.include BluebaseTestHelpers
12
+
13
+ config.before(:all) do
14
+ create_tmp_directory
15
+ end
16
+
17
+ config.before(:each) do
18
+ drop_dummy_database
19
+ remove_project_directory
20
+
21
+ FakeHeroku.clear!
22
+ FakeGithub.clear!
23
+ end
24
+ end
@@ -0,0 +1,49 @@
1
+ module BluebaseTestHelpers
2
+ APP_NAME = "dummy"
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_bluebase(arguments = nil)
13
+ Dir.chdir(tmp_path) do
14
+ Bundler.with_clean_env do
15
+ ENV["TESTING"] = "1"
16
+
17
+ %x(#{bluebase_bin} #{APP_NAME} #{arguments})
18
+ end
19
+ end
20
+ end
21
+
22
+ def drop_dummy_database
23
+ if File.exist?(project_path)
24
+ Dir.chdir(project_path) do
25
+ Bundler.with_clean_env do
26
+ `rake db:drop`
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ def project_path
33
+ @project_path ||= Pathname.new("#{tmp_path}/#{APP_NAME}")
34
+ end
35
+
36
+ private
37
+
38
+ def tmp_path
39
+ @tmp_path ||= Pathname.new("#{root_path}/tmp")
40
+ end
41
+
42
+ def bluebase_bin
43
+ File.join(root_path, "bin", "bluebase")
44
+ end
45
+
46
+ def root_path
47
+ File.expand_path("../../../", __FILE__)
48
+ end
49
+ end
@@ -0,0 +1,21 @@
1
+ class FakeGithub
2
+ RECORDER = File.expand_path(File.join('..', '..', 'tmp', 'hub_commands'), File.dirname(__FILE__))
3
+
4
+ def initialize(args)
5
+ @args = args
6
+ end
7
+
8
+ def run!
9
+ File.open(RECORDER, 'a') do |file|
10
+ file.write @args.join(' ')
11
+ end
12
+ end
13
+
14
+ def self.clear!
15
+ FileUtils.rm_rf RECORDER
16
+ end
17
+
18
+ def self.has_created_repo?(repo_name)
19
+ File.read(RECORDER) == "create #{repo_name}"
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ class FakeHeroku
2
+ RECORDER = File.expand_path(File.join('..', '..', 'tmp', 'heroku_commands'), File.dirname(__FILE__))
3
+
4
+ def initialize(args)
5
+ @args = args
6
+ end
7
+
8
+ def run!
9
+ File.open(RECORDER, 'a') do |file|
10
+ file.puts @args.join(' ')
11
+ end
12
+ end
13
+
14
+ def self.clear!
15
+ FileUtils.rm_rf RECORDER
16
+ end
17
+
18
+ def self.has_gem_included?(project_path, gem_name)
19
+ gemfile = File.open(File.join(project_path, 'Gemfile'), 'a')
20
+
21
+ File.foreach(gemfile).any? do |line|
22
+ line.match(/#{Regexp.quote(gem_name)}/)
23
+ end
24
+ end
25
+
26
+ def self.has_created_app_for?(remote_name)
27
+ app_name = "#{BluebaseTestHelpers::APP_NAME}-#{remote_name}"
28
+ expected_line = "create #{app_name} --remote #{remote_name}\n"
29
+
30
+ File.foreach(RECORDER).any? { |line| line == expected_line }
31
+ end
32
+ end
data/templates/.envrc ADDED
@@ -0,0 +1 @@
1
+ PATH_add bin
@@ -0,0 +1,4 @@
1
+ inherit_from: ./.rubocop.yml
2
+
3
+ # Show cop names by default; can commment out if needed
4
+ ShowCopNames: true
data/templates/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ Exclude:
3
+ - app/views/**/*
4
+ - app/helpers/ApplicationHelper
5
+ - bin/*
6
+ - config/initializers/*
7
+ - db/schema.rb
8
+ - db/migrate/**/*devise*.rb
9
+ - spec/spec_helper.rb
10
+ - Guardfile
11
+
12
+ Metrics/LineLength:
13
+ Description: 'Limit lines to 110 characters.'
14
+ Max: 110
15
+
16
+ Style/StringLiterals:
17
+ Enabled: false
18
+
19
+ Style/Documentation:
20
+ Enabled: false
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+
3
+ install: bundle install --without development production --deployment --jobs=3 --retry=3
4
+ addons:
5
+ postgresql: "9.3"
6
+ before_script:
7
+ - psql -c 'create database "<%= app_name %>_test";' -U postgres
8
+ - cp config/database.yml.travis config/database.yml
9
+ - cp config/application.yml.travis config/application.yml
10
+
11
+ # Replace YOUR_TOKEN with your Code Climate repo token to get test coverage stats
12
+ script: CODECLIMATE_REPO_TOKEN=YOUR_TOKEN bundle exec rake
@@ -0,0 +1,74 @@
1
+ source "https://rubygems.org"
2
+ ruby "<%= Bluebase::RUBY_VERSION %>"
3
+
4
+ # Core gems
5
+ gem "rails", "<%= Bluebase::RAILS_VERSION %>"
6
+ gem "thin"
7
+ <% if options[:database] == 'postgresql' -%>
8
+ gem "pg"
9
+ <% else -%>
10
+ gem "sqlite3"
11
+ <% end -%>
12
+ gem "figaro"
13
+
14
+ # Components
15
+ gem "turbolinks"
16
+ gem "devise"
17
+ gem "simple_form"
18
+ gem "gon"
19
+ gem "kaminari"
20
+ gem "recipient_interceptor"
21
+
22
+ # Frontend
23
+ gem "sass-rails", "~> 4.0.3"
24
+ gem "coffee-rails"
25
+ gem "jquery-rails"
26
+ gem "uglifier"
27
+ gem "slim-rails"
28
+ gem "autoprefixer-rails"
29
+
30
+ gem "flutie"
31
+ gem "title"
32
+
33
+ # Error logging - requires setup with service
34
+ gem "rollbar"
35
+
36
+ group :development do
37
+ gem "annotate"
38
+ gem "better_errors"
39
+ gem "binding_of_caller"
40
+ gem "quiet_assets"
41
+ gem "spring"
42
+ gem "spring-commands-rspec"
43
+ gem "rubocop"
44
+ gem "guard-rubocop"
45
+ gem "guard-livereload"
46
+ gem "i18n-tasks"
47
+ end
48
+
49
+ group :development, :test do
50
+ gem "awesome_print"
51
+ gem "pry-rails"
52
+ gem "pry-byebug"
53
+
54
+ gem "rspec-rails", "~> 3.1.0"
55
+ gem "factory_girl_rails"
56
+ gem "ffaker"
57
+ end
58
+
59
+ group :test do
60
+ gem "shoulda-matchers", require: false
61
+ gem "database_cleaner"
62
+ gem "capybara"
63
+ gem "launchy"
64
+ gem "guard-rspec"
65
+
66
+ gem "codeclimate-test-reporter", require: nil
67
+ end
68
+
69
+ group :staging, :production do
70
+ gem "rails_12factor"
71
+
72
+ # Analytics - requires setup
73
+ gem "newrelic_rpm"
74
+ end