kazan 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +8 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +21 -0
  8. data/README.md +92 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/kazan +30 -0
  12. data/bin/setup +8 -0
  13. data/kazan.gemspec +32 -0
  14. data/lib/kazan/actions.rb +33 -0
  15. data/lib/kazan/app_builder.rb +308 -0
  16. data/lib/kazan/generators/app_generator.rb +177 -0
  17. data/lib/kazan/generators/clockwork_generator.rb +7 -0
  18. data/lib/kazan/generators/sidekiq_generator.rb +7 -0
  19. data/lib/kazan/version.rb +5 -0
  20. data/lib/kazan.rb +5 -0
  21. data/spec/kazan_spec.rb +21 -0
  22. data/spec/project_spec.rb +222 -0
  23. data/spec/spec_helper.rb +7 -0
  24. data/spec/support/hooks.rb +15 -0
  25. data/spec/support/kazan_spec_helpers.rb +71 -0
  26. data/templates/Gemfile.api.erb +53 -0
  27. data/templates/Gemfile.erb +68 -0
  28. data/templates/Procfile.erb +1 -0
  29. data/templates/README.md.erb +16 -0
  30. data/templates/_flashes.html.erb +7 -0
  31. data/templates/_javascript.html.erb +12 -0
  32. data/templates/_styles.html.erb +7 -0
  33. data/templates/action_mailer.rb +5 -0
  34. data/templates/application.html.erb +17 -0
  35. data/templates/application.scss +9 -0
  36. data/templates/browserslist +3 -0
  37. data/templates/bullet.rb +6 -0
  38. data/templates/bundler_audit.rake +12 -0
  39. data/templates/database.yml.erb +31 -0
  40. data/templates/database_cleaner.rb +21 -0
  41. data/templates/envs/.env.development.example +21 -0
  42. data/templates/envs/.env.production +24 -0
  43. data/templates/errors.rb +33 -0
  44. data/templates/factory_girl.rb +3 -0
  45. data/templates/flashes_helper.rb +5 -0
  46. data/templates/gitignore +14 -0
  47. data/templates/i18n.rb +3 -0
  48. data/templates/json_encoding.rb +2 -0
  49. data/templates/puma.rb +14 -0
  50. data/templates/rack_mini_profiler.rb +6 -0
  51. data/templates/rails_helper.rb +21 -0
  52. data/templates/rollbar.rb +57 -0
  53. data/templates/settings.yml.erb +0 -0
  54. data/templates/shoulda_matchers.rb +6 -0
  55. data/templates/smtp.rb +14 -0
  56. data/templates/spec_helper.rb +24 -0
  57. metadata +164 -0
@@ -0,0 +1,177 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/rails/app/app_generator'
3
+
4
+ module Kazan
5
+ class AppGenerator < Rails::Generators::AppGenerator
6
+ hide!
7
+
8
+ class_option :database, type: :string, aliases: '-d', default: 'postgresql',
9
+ desc: "Configure for selected database (options: #{DATABASES.join("/")})"
10
+
11
+ class_option :skip_test, type: :string, default: '--skip-test-unit'
12
+ class_option :skip_action_cable, type: :string, default: '--skip-action-cable'
13
+
14
+ class_option :sidekiq, type: :string, default: ''
15
+ class_option :clockwork, type: :string, default: ''
16
+ class_option :static, type: :string, default: ''
17
+
18
+ def finish_template
19
+ invoke :customization
20
+ super
21
+ end
22
+
23
+ def customization
24
+ invoke :setup_ruby
25
+ invoke :setup_gems
26
+ invoke :setup_secrets
27
+ invoke :setup_puma
28
+ invoke :setup_development_environment
29
+ invoke :setup_test_environment
30
+ invoke :setup_production_environment
31
+ invoke :setup_database
32
+
33
+ unless options[:api]
34
+ invoke :setup_assets
35
+ invoke :setup_helpers
36
+ end
37
+
38
+ invoke :setup_clockwork if options[:clockwork]
39
+ invoke :setup_sidekiq if options[:sidekiq]
40
+ invoke :setup_static if options[:static]
41
+
42
+ invoke :setup_error_pages
43
+ invoke :setup_bundler_audit
44
+ invoke :setup_spring
45
+ invoke :setup_empty_directories
46
+ invoke :setup_project_repository
47
+ invoke :outro
48
+ end
49
+
50
+ def setup_ruby
51
+ say 'Setup ruby'
52
+ build :ruby_version
53
+ end
54
+
55
+ def setup_gems
56
+ say 'Setup gems'
57
+ build :gemfile_api if options[:api]
58
+ end
59
+
60
+ def setup_secrets
61
+ say 'Setup secrets'
62
+ build :dotenvs
63
+ build :settings
64
+ end
65
+
66
+ def setup_puma
67
+ say 'Setup puma'
68
+ build :puma_config
69
+ end
70
+
71
+ def setup_development_environment
72
+ say 'Setup development environment'
73
+ build :exception_on_delivery_errors
74
+ build :exception_on_unpermitted_parameters
75
+ build :exception_on_missing_translations
76
+ build :letter_opener_config
77
+ build :bullet_config
78
+ build :foreman_config
79
+ build :rails_generators_config
80
+
81
+ unless options[:api]
82
+ build :quiet_assets_config
83
+ end
84
+ end
85
+
86
+ def setup_test_environment
87
+ say 'Setup test environment'
88
+ build :exception_on_missing_assets_in_test
89
+ build :spec_translations_config
90
+ build :spec_action_mailer_config
91
+ build :spec_database_cleaner_config
92
+ build :spec_shoulda_matchers_config
93
+ build :spec_factory_girl_config
94
+ build :rspec_config
95
+ build :rspec_replace_config
96
+ end
97
+
98
+ def setup_production_environment
99
+ say 'Setup production environment'
100
+ build :smtp_config
101
+ build :rack_timeout_config
102
+ build :rack_canonical_host_config
103
+ build :rack_deflater_config
104
+ build :rollbar_config
105
+ end
106
+
107
+ def setup_database
108
+ say 'Setup database'
109
+ build :postgres_config if options[:database] == 'postgresql'
110
+ build :database_tables
111
+ end
112
+
113
+ def setup_assets
114
+ say 'Setup assets'
115
+ build :shared_views_directory
116
+ build :shared_flash
117
+ build :shared_javascript
118
+ build :shared_styles
119
+ build :assets_config
120
+ end
121
+
122
+ def setup_helpers
123
+ build :simple_form_config
124
+ build :rack_mini_profiler_config
125
+ end
126
+
127
+ def setup_clockwork
128
+ end
129
+
130
+ def setup_sidekiq
131
+ end
132
+
133
+ def setup_static
134
+ say 'Setup static'
135
+
136
+ build :stylesheets_gems
137
+ build :stylesheets_manifest
138
+ build :refils
139
+ build :bitters
140
+ end
141
+
142
+ def setup_error_pages
143
+ say 'Customizing the 500/404/422 pages'
144
+ build :static_pages
145
+ end
146
+
147
+ def setup_bundler_audit
148
+ say 'Setup bundler audit'
149
+ build :bundler_audit_config
150
+ end
151
+
152
+ def setup_spring
153
+ say 'Setup spring binstubs'
154
+ build :spring
155
+ end
156
+
157
+ def setup_empty_directories
158
+ say 'Setup empty directories'
159
+ build :empty_directories
160
+ end
161
+
162
+ def setup_project_repository
163
+ say 'Setup git reposirory'
164
+ build :init_commit
165
+ end
166
+
167
+ def outro
168
+ say 'Last preparation'
169
+ end
170
+
171
+ protected
172
+
173
+ def get_builder_class
174
+ Kazan::AppBuilder
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails/generators'
2
+
3
+ module Kazan
4
+ class ClockworkGenerator < Rails::Generators::Base
5
+
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails/generators'
2
+
3
+ module Kazan
4
+ class SidekiqGenerator < Rails::Generators::Base
5
+
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Kazan
2
+ VERSION = '0.1.0'.freeze
3
+ RAILS_VERSION = '~> 5.0.0'.freeze
4
+ RUBY_PROJECT_VERSION = IO.read("#{File.dirname(__FILE__)}/../../.ruby-version").strip.freeze
5
+ end
data/lib/kazan.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "kazan/version"
2
+ require "kazan/generators/app_generator"
3
+ require "kazan/actions"
4
+ require "kazan/app_builder"
5
+
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kazan do
4
+ describe 'version' do
5
+ subject { Kazan::VERSION }
6
+
7
+ it { is_expected.not_to be_nil }
8
+ end
9
+
10
+ describe 'rails version' do
11
+ subject { Kazan::RUBY_PROJECT_VERSION }
12
+
13
+ it { is_expected.not_to be nil }
14
+ end
15
+
16
+ describe 'ruby version' do
17
+ subject { Kazan::RAILS_VERSION }
18
+
19
+ it { is_expected.not_to be_nil }
20
+ end
21
+ end
@@ -0,0 +1,222 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Project with configuration' do
4
+ before(:all) do
5
+ setup_app_dependencies
6
+ run_app_generator
7
+ end
8
+
9
+ after(:all) do
10
+ drop_app_database
11
+ end
12
+
13
+ BINSTUBS = [
14
+ 'rake',
15
+ 'rails',
16
+ 'rspec'
17
+ ]
18
+
19
+ SETTINGS = [
20
+ 'Gemfile',
21
+ 'Procfile',
22
+ 'README.md',
23
+ # 'browserList',
24
+ '.ruby-version',
25
+ '.gitignore',
26
+ '.env.development.example',
27
+ '.env.production',
28
+ ]
29
+
30
+ CONFIGS = [
31
+ 'database.yml',
32
+ 'database.yml.example',
33
+ 'puma.rb',
34
+ 'settings.yml',
35
+ 'smtp.rb'
36
+ ]
37
+
38
+ INITIALIZERS = [
39
+ 'bullet.rb',
40
+ 'errors.rb',
41
+ 'json_encoding.rb',
42
+ 'rollbar.rb'
43
+ ]
44
+
45
+ GEMS = [
46
+ 'annotate',
47
+ 'autoprefixer-rails',
48
+ 'awesome_print',
49
+ 'better_errors',
50
+ 'bullet',
51
+ 'bundler-audit',
52
+ 'capybara',
53
+ 'config',
54
+ 'database_cleaner',
55
+ 'dotenv',
56
+ 'factory_girl_rails',
57
+ 'faker',
58
+ 'flutie',
59
+ 'foreman',
60
+ 'formulaic',
61
+ 'jquery-rails',
62
+ 'launchy',
63
+ 'letter_opener',
64
+ 'normalize-rails',
65
+ 'pg',
66
+ 'pry-byebug',
67
+ 'pry-rails',
68
+ 'puma',
69
+ 'rack-mini-profiler',
70
+ 'rack-canonical-host',
71
+ 'rack-timeout',
72
+ 'recipient_interceptor',
73
+ 'rails',
74
+ 'rails-i18n',
75
+ 'rollbar',
76
+ 'rspec-rails',
77
+ 'sass-rails',
78
+ 'simplecov',
79
+ 'shoulda-matchers',
80
+ 'sprockets', '>= 3.0.0',
81
+ 'sprockets-es6',
82
+ 'timecop',
83
+ 'webmock',
84
+ 'web-console',
85
+ 'uglifier'
86
+ ]
87
+
88
+ RSPEC = [
89
+ 'rails_helper.rb',
90
+ 'spec_helper.rb'
91
+ ]
92
+
93
+ SUPPORTS = [
94
+ 'action_mailer.rb',
95
+ 'database_cleaner.rb',
96
+ 'i18n.rb',
97
+ 'shoulda_matchers.rb'
98
+ ]
99
+
100
+ VIEWS = [
101
+ '_flashes.html.erb',
102
+ '_javascript.html.erb',
103
+ '_styles.html.erb'
104
+ ]
105
+
106
+ describe 'spring bin' do
107
+ subject { File }
108
+
109
+ it { is_expected.to exist("#{project_path}/bin/spring") }
110
+ end
111
+
112
+ BINSTUBS.each do |bin_stub|
113
+ describe bin_stub do
114
+ subject { IO.read("#{project_path}/bin/#{bin_stub}") }
115
+
116
+ it { is_expected.to match(/spring/) }
117
+ end
118
+ end
119
+
120
+ SETTINGS.each do |config|
121
+ describe config do
122
+ subject { load_file config }
123
+
124
+ it { is_expected.to be_truthy}
125
+ end
126
+ end
127
+
128
+ CONFIGS.each do |config|
129
+ describe config do
130
+ subject { load_file "config/#{config}" }
131
+
132
+ it { is_expected.to be_truthy }
133
+ end
134
+ end
135
+
136
+ INITIALIZERS.each do |initializer|
137
+ describe initializer do
138
+ subject { load_file "config/initializers/#{initializer}" }
139
+
140
+ it { is_expected.to be_truthy }
141
+ end
142
+ end
143
+
144
+ # describe 'simple_from.rb' do
145
+ # subject { load_file 'config/initializers/simple_form.rb' }
146
+
147
+ # it { is_expected.to be_truthy }
148
+ # end
149
+
150
+ RSPEC.each do |helper|
151
+ describe helper do
152
+ subject { load_file "spec/#{helper}" }
153
+
154
+ it { is_expected.to be_truthy }
155
+ end
156
+ end
157
+
158
+ SUPPORTS.each do |support|
159
+ describe support do
160
+ subject { load_file "spec/support/#{support}" }
161
+
162
+ it { is_expected.to be_truthy }
163
+ end
164
+ end
165
+
166
+ VIEWS.each do |view|
167
+ describe view do
168
+ subject { load_file "app/views/layouts/shared/#{view}" }
169
+
170
+ it { is_expected.to be_truthy }
171
+ end
172
+ end
173
+
174
+ describe 'Gemfile' do
175
+ subject { load_file 'Gemfile' }
176
+
177
+ GEMS.each do |gem|
178
+ it { is_expected.to include gem }
179
+ end
180
+ end
181
+
182
+ describe 'Rakefile' do
183
+ subject { load_file 'Rakefile' }
184
+
185
+ it { is_expected.to match(/bundler:audit/) }
186
+ end
187
+
188
+ describe 'application.rb' do
189
+ subject { load_file 'config/application.rb' }
190
+
191
+ it { is_expected.to match(/action_on_unpermitted_parameters = :raise/) }
192
+ it { is_expected.to match(/config.generators/) }
193
+ it { is_expected.to match(/config.assets.quiet = true/) }
194
+ end
195
+
196
+ describe 'environments/development.rb' do
197
+ subject { load_file 'config/environments/development.rb' }
198
+
199
+ it { is_expected.to be_truthy }
200
+ it { is_expected.to match(/raise_delivery_errors = true/) }
201
+ it { is_expected.to match(/action_mailer.default_url_options/) }
202
+ it { is_expected.to match(/action_mailer.delivery_method/) }
203
+ it { is_expected.to match(/raise_on_missing_translations = true/) }
204
+ end
205
+
206
+ describe 'environments/test.rb' do
207
+ subject { load_file 'config/environments/test.rb' }
208
+
209
+ it { is_expected.to be_truthy }
210
+ it { is_expected.to match(/config.assets.raise_runtime_errors = true/) }
211
+ it { is_expected.to match(/raise_on_missing_translations = true/) }
212
+ end
213
+
214
+ describe 'environments/staging.rb' do
215
+ end
216
+
217
+ describe 'environments/production.rb' do
218
+ subject { load_file 'config/environments/production.rb' }
219
+
220
+ it { is_expected.to be_truthy }
221
+ end
222
+ end
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+
3
+ Dir['./spec/support/**/*.rb'].each { |file| require file }
4
+
5
+ RSpec.configure do |config|
6
+ config.include KazanSpecHelpers
7
+ end
@@ -0,0 +1,15 @@
1
+ RSpec.configure do |config|
2
+ config.before(:all) do
3
+ create_temp_directory
4
+ end
5
+
6
+ config.before(:each) do
7
+ end
8
+
9
+ config.after(:each) do
10
+ end
11
+
12
+ config.after(:all) do
13
+ remove_temp_project_directory
14
+ end
15
+ end
@@ -0,0 +1,71 @@
1
+ require 'rails'
2
+
3
+ module KazanSpecHelpers
4
+ APP_NAME = 'kazan_spec_app'
5
+
6
+ def create_temp_directory
7
+ FileUtils.mkdir_p(temp_path)
8
+ end
9
+
10
+ def remove_temp_project_directory
11
+ FileUtils.rm_rf(project_path)
12
+ end
13
+
14
+ def run_app_generator(arguments = nil)
15
+ arguments = "--path=#{root_path} #{arguments}"
16
+ Dir.chdir(temp_path) do
17
+ Bundler.with_clean_env do
18
+ `
19
+ #{bin_path} #{APP_NAME} #{arguments}
20
+ `
21
+ end
22
+ end
23
+ end
24
+
25
+ def setup_app_dependencies
26
+ if File.exist?(project_path)
27
+ Dir.chdir(project_path) do
28
+ Bundler.with_clean_env do
29
+ `bundle check || bundle install`
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ def drop_app_database
36
+ if File.exist?(project_path)
37
+ Dir.chdir(project_path) do
38
+ Bundler.with_clean_env do
39
+ `rake db:drop`
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ def project_path
46
+ @temp_project_path ||= Pathname.new("#{temp_path}/#{APP_NAME}")
47
+ end
48
+
49
+ def temp_project_name
50
+ APP_NAME.humanize
51
+ end
52
+
53
+ def load_file(file_name)
54
+ IO.read("#{project_path}/#{file_name}")
55
+ end
56
+
57
+ private
58
+
59
+ def temp_path
60
+ @temp_path ||= Pathname.new("#{root_path}/temp")
61
+ end
62
+
63
+ def bin_path
64
+ File.join(root_path, 'bin', 'kazan')
65
+ end
66
+
67
+ def root_path
68
+ File.expand_path('../../../', __FILE__)
69
+ end
70
+ end
71
+
@@ -0,0 +1,53 @@
1
+ source "https://rubygems.org"
2
+ ruby "<%= Kazan::RUBY_PROJECT_VERSION %>"
3
+
4
+ gem 'rails', "<%= Kazan::RAILS_VERSION %>"
5
+ gem 'rails-i18n'
6
+ gem 'dotenv-rails'
7
+ gem 'config'
8
+
9
+ gem 'pg'
10
+
11
+ gem 'rollbar'
12
+
13
+ gem 'recipient_interceptor'
14
+ gem 'rack-canonical-host'
15
+ gem 'puma'
16
+
17
+ group :development do
18
+ gem 'annotate'
19
+ gem 'better_errors'
20
+ gem 'foreman', '~> 0.78.0'
21
+ gem 'letter_opener'
22
+ gem 'listen'
23
+ gem 'spring'
24
+ gem 'spring-commands-rspec'
25
+ gem 'web-console'
26
+ end
27
+
28
+ group :development, :test do
29
+ gem 'awesome_print'
30
+ gem 'bullet'
31
+ gem 'bundler-audit', '>= 0.5.0', require: false
32
+ gem 'faker'
33
+ gem 'factory_girl_rails'
34
+ gem 'pry-byebug'
35
+ gem 'pry-rails'
36
+ gem 'rspec-rails', '~> 3.5.0.beta4'
37
+ end
38
+
39
+ group :test do
40
+ gem 'database_cleaner'
41
+ gem 'shoulda-matchers'
42
+ gem 'simplecov', require: false
43
+ gem 'timecop'
44
+ gem 'webmock'
45
+ end
46
+
47
+ group :development, :staging do
48
+ gem 'rack-mini-profiler', require: false
49
+ end
50
+
51
+ group :staging, :production do
52
+ gem 'rack-timeout'
53
+ end
@@ -0,0 +1,68 @@
1
+ source 'https://rubygems.org'
2
+ ruby "<%= Kazan::RUBY_PROJECT_VERSION %>"
3
+
4
+ gem 'rails', "<%= Kazan::RAILS_VERSION %>"
5
+ gem 'rails-i18n'
6
+ gem 'dotenv-rails'
7
+ gem 'config'
8
+
9
+ gem 'pg'
10
+
11
+ gem 'autoprefixer-rails'
12
+ gem 'normalize-rails', '~> 3.0.0'
13
+ gem 'sass-rails', '~> 5.0'
14
+
15
+ gem 'jquery-rails'
16
+ gem 'sprockets', '>= 3.0.0'
17
+ gem 'sprockets-es6'
18
+ gem 'uglifier'
19
+
20
+ gem 'flutie'
21
+ gem 'simple_form'
22
+
23
+ gem 'rollbar'
24
+
25
+ gem 'recipient_interceptor'
26
+ gem 'rack-canonical-host'
27
+ gem 'puma'
28
+
29
+ group :development do
30
+ gem 'annotate'
31
+ gem 'better_errors'
32
+ gem 'foreman', '~> 0.78.0'
33
+ gem 'letter_opener'
34
+ gem 'listen'
35
+ gem 'spring'
36
+ gem 'spring-commands-rspec'
37
+ gem 'web-console'
38
+ end
39
+
40
+ group :development, :test do
41
+ gem 'awesome_print'
42
+ gem 'bullet'
43
+ gem 'bundler-audit', '>= 0.5.0', require: false
44
+ gem 'faker'
45
+ gem 'factory_girl_rails'
46
+ gem 'pry-byebug'
47
+ gem 'pry-rails'
48
+ gem 'rspec-rails', '~> 3.5.0.beta4'
49
+ end
50
+
51
+ group :test do
52
+ gem 'capybara'
53
+ gem 'database_cleaner'
54
+ gem 'formulaic'
55
+ gem 'launchy'
56
+ gem 'shoulda-matchers'
57
+ gem 'simplecov', require: false
58
+ gem 'timecop'
59
+ gem 'webmock'
60
+ end
61
+
62
+ group :development, :staging do
63
+ gem 'rack-mini-profiler', require: false
64
+ end
65
+
66
+ group :staging, :production do
67
+ gem 'rack-timeout'
68
+ end
@@ -0,0 +1 @@
1
+ server: rails server
@@ -0,0 +1,16 @@
1
+ <%= app_name.humanize %>
2
+
3
+ ## Requirements
4
+
5
+ Ensure that you have installed:
6
+
7
+ - Ruby "<%= Kazan::RUBY_PROJECT_VERSION %>"
8
+ - Rails "<%= Kazan::RAILS_VERSION %>"
9
+
10
+ ## Getting started
11
+
12
+ After you have cloned this repo, run this setup script to set up your machine
13
+ with the necessary dependencies to run and test this app:
14
+
15
+ $ ./bin/setup
16
+
@@ -0,0 +1,7 @@
1
+ <% if flash.any? %>
2
+ <div class="flashes">
3
+ <% user_facing_flashes.each do |key, value| -%>
4
+ <div class="flash-<%= key %>"><%= value %></div>
5
+ <% end -%>
6
+ </div>
7
+ <% end %>