rsg 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +44 -3
  3. data/Gemfile.lock +5 -4
  4. data/README.md +13 -6
  5. data/exe/rsg +1 -1
  6. data/lib/rsg/generators/actions.rb +39 -5
  7. data/lib/rsg/generators/app/app_builder.rb +23 -36
  8. data/lib/rsg/generators/app/app_generator.rb +62 -67
  9. data/lib/rsg/generators/base.rb +2 -0
  10. data/lib/rsg/generators/dotenv/install_generator.rb +14 -20
  11. data/lib/rsg/generators/logging/common_generator.rb +17 -23
  12. data/lib/rsg/generators/logging/lograge_generator.rb +14 -24
  13. data/lib/rsg/generators/logging/templates/{initializer_lograge.rb → initializer_lograge.rb.tt} +0 -0
  14. data/lib/rsg/generators/misc/misc_generator.rb +47 -38
  15. data/lib/rsg/generators/misc/templates/{puma.rb → puma.rb.tt} +0 -0
  16. data/lib/rsg/generators/orm/active_record_generator.rb +38 -32
  17. data/lib/rsg/generators/orm/templates/{db.rake → db.rake.tt} +0 -0
  18. data/lib/rsg/generators/orm/templates/{samples.rb → samples.rb.tt} +0 -0
  19. data/lib/rsg/generators/orm/templates/{seeds.rb → seeds.rb.tt} +0 -0
  20. data/lib/rsg/generators/testing/rspec_generator.rb +19 -25
  21. data/lib/rsg/generators/webpacker/bootstrap_generator.rb +27 -0
  22. data/lib/rsg/generators/webpacker/install_generator.rb +37 -47
  23. data/lib/rsg/generators/webpacker/templates/bootstrap/application.sass +40 -0
  24. data/lib/rsg/generators/webpacker/templates/bootstrap/landing.html.erb +18 -0
  25. data/lib/rsg/generators/webpacker/templates/bootstrap/layout.html.erb +35 -0
  26. data/lib/rsg/generators/webpacker/templates/landing_controller.rb.erb +1 -1
  27. data/lib/rsg/version.rb +1 -1
  28. data/lib/rsg.rb +6 -15
  29. data/rsg.gemspec +4 -0
  30. data/templates/rsg-bootstrap.rb +7 -0
  31. data/templates/rsg-default.rb +10 -3
  32. metadata +26 -12
  33. data/lib/rsg/generators/gemfile/cleanup_generator.rb +0 -28
  34. data/lib/rsg/generators/install/install_generator.rb +0 -13
  35. data/lib/rsg/generators/orm/templates/active_record/mysql.yml +0 -59
  36. data/lib/rsg/generators/orm/templates/active_record/postgresql.yml +0 -86
  37. data/lib/rsg/generators/orm/templates/active_record/sqlite3.yml +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49abbdf2e54f937084ca700c8cf3dbb09a2f9f2cb691f4c06d4fd9996c600a65
4
- data.tar.gz: 3cf5638be1c8d1039c310ecdd4f3cc3687a984dd88cc3c86c494d23839081d70
3
+ metadata.gz: dde28f50b96b413bafb73508dfd480e7af42d5d4ed88f4d4096e99c050f7e836
4
+ data.tar.gz: 78534e115a388404d72ba986ecbf722ed42bb6e408072a564d0f319e434942db
5
5
  SHA512:
6
- metadata.gz: ed4c80320bf9939dbe762024bea33810e33f971dd469665e9d81803cf1b48c2a7cd67f3e4d0f952b3979cf6a04015dd20de5f399fd5458d3b91f907928eabf30
7
- data.tar.gz: b34f4042d78ed407d13acc8d92d930201691b9c93f7f1e473161997e24e1ed4cc02aa00e44dbba4cad0bf75b5c2702d847e3e62f355e92c664a6273824210772
6
+ metadata.gz: de019ee6ea332c40f99d5d8481418a74db3b7ef50ea2c83d618104923154c4cfe27e48b06d2163b9bdb1fda787c059b83054253e810dc95e4d6ab6bc254861d8
7
+ data.tar.gz: b761b6d6fe1609a8f386b8841b8ba256f522d251f362c3675662b4cc20bb76931608f2af87bc98976f9965ea41c62fbb2a51e88331f373498fe1c77d26de4f3c
data/.circleci/config.yml CHANGED
@@ -2,12 +2,53 @@ version: 2.1
2
2
  jobs:
3
3
  build:
4
4
  docker:
5
- - image: ruby:3.0.0
5
+ - image: cimg/ruby:3.0
6
6
  steps:
7
7
  - checkout
8
+
8
9
  - run:
9
- name: Run the default task
10
+ name: "Configure git client"
10
11
  command: |
11
- gem install bundler -v 2.2.7
12
+ git config --global user.name "CircleCI"
13
+ git config --global user.email "circle@example.com"
14
+
15
+ - restore_cache:
16
+ keys:
17
+ - v1-{{ .Branch }}-{{ checksum "Gemfile.lock" }}-{{ .Revision }}
18
+ - v1-{{ .Branch }}-{{ checksum "Gemfile.lock" }}-
19
+ - v1-{{ .Branch }}-
20
+ - v1-master-
21
+
22
+ - run:
23
+ name: Install dependencies
24
+ command: |
25
+ bundle install
26
+
27
+ - run:
28
+ name: Test scaffold of basic application, with no extras
29
+ command: |
30
+ ./exe/rsg --path `pwd` --template ./spec/acceptance/fixtures/basic-template.rb /tmp/basic-app
31
+ cd /tmp/basic-app
32
+ bundle install
33
+ bundle exec rake
34
+ if [[ $(git log --oneline | wc -l) -le 1 ]]; then
35
+ echo "No commits found"
36
+ exit 1
37
+ fi
38
+
39
+ - run:
40
+ name: Test scaffold of basic API application, with no extras
41
+ command: |
42
+ ./exe/rsg --api --path `pwd` --template ./spec/acceptance/fixtures/basic-template.rb /tmp/basic-api
43
+ cd /tmp/basic-api
12
44
  bundle install
13
45
  bundle exec rake
46
+ if [[ $(git log --oneline | wc -l) -le 1 ]]; then
47
+ echo "No commits found"
48
+ exit 1
49
+ fi
50
+
51
+ - save_cache:
52
+ key: v1-{{ .Branch }}-{{ checksum "Gemfile.lock" }}-{{ .Revision }}
53
+ paths:
54
+ - ~/.rubygems
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsg (0.0.1)
4
+ rsg (0.1.0)
5
5
  rails (~> 6.1.4)
6
+ zeitwerk
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -161,9 +162,9 @@ GEM
161
162
  sprockets (4.0.2)
162
163
  concurrent-ruby (~> 1.0)
163
164
  rack (> 1, < 3)
164
- sprockets-rails (3.2.2)
165
- actionpack (>= 4.0)
166
- activesupport (>= 4.0)
165
+ sprockets-rails (3.4.0)
166
+ actionpack (>= 5.2)
167
+ activesupport (>= 5.2)
167
168
  sprockets (>= 3.0.0)
168
169
  thor (1.1.0)
169
170
  tzinfo (2.0.4)
data/README.md CHANGED
@@ -103,7 +103,7 @@ git clone https://github.com/doximity/rsg && cd rsg
103
103
  ./exe/rsg --path="../../" --api tmp/sample-api
104
104
  ```
105
105
 
106
- ### Upgrading to newer rails releases
106
+ ### Upgrading rsg to scaffold apps for newer Rails releases
107
107
 
108
108
  ```
109
109
  TODO: Document
@@ -114,6 +114,7 @@ TODO: Document
114
114
  * Link to rails diff to inspect what changed
115
115
  * https://railsdiff.org/6.0.4.1/6.1.4.1
116
116
  * Update RAILS_VERSION
117
+ * Look into `rails upgrade --pretend`
117
118
 
118
119
  -->
119
120
 
@@ -165,20 +166,27 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/doximi
165
166
  - [x] `git commit` after each generator
166
167
  - [x] Application template that calls generators
167
168
  - [x] Accept a template, set a default
168
- - [ ] Automated releases
169
169
  - [x] Basic documentation with placeholders of content to write later
170
- - [ ] Test coverage, can start with a simple test that runs the command and boots the app
170
+ - [x] Smoke test app generation in CI
171
+ - [ ] Switch to Rails 7 beta
172
+ - [ ] Ability to output a consolidated after install message from multiple generators
173
+ - [ ] Automated releases
171
174
  - [ ] Generators
172
175
  - [x] webpacker for all the things, including SASS
173
176
  - [x] Productiong grade logging
174
177
  - [x] `rspec-rails`
175
178
  - [x] `dotenv-rails`
179
+ - [x] Bootstrap
180
+ - [ ] postcss to remove unused CSS (optional)
181
+ - [ ] i18n
182
+ - [ ] CI with GitHub Actions
183
+ - [ ] standardrb
184
+ - [ ] docker-compose
176
185
  - [ ] `slim-rails`
177
186
  - [ ] `factory_bot`
178
- - [ ] docker-compose
187
+ - [ ] `letter_opener_web`
179
188
  - [ ] robots.txt
180
189
  - [ ] Code coverage for rspec
181
- - [ ] CI with GitHub Actions
182
190
  - [ ] CI with CircleCI
183
191
  - [ ] Sidekiq with opt in support for sidekiq-pro and sidekiq-enterprise
184
192
  - [ ] `action_cable`
@@ -189,4 +197,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/doximi
189
197
  - [x] `active_record`
190
198
  - [ ] `active_storage`
191
199
  - [ ] `test_unit`
192
- - [x] Overview of the project, including some background
data/exe/rsg CHANGED
@@ -19,4 +19,4 @@ elsif ["-v", "--version"].include? ARGV[0]
19
19
  exit 0
20
20
  end
21
21
 
22
- Rsg::AppGenerator.start
22
+ Rsg::Generators::App::AppGenerator.start
@@ -1,25 +1,55 @@
1
+ require "bundler"
1
2
  require "json"
2
3
  require "shellwords"
3
4
 
4
5
  module Rsg
5
6
  module Generators
6
7
  module Actions
8
+ def rsg_options
9
+ @rsg_options ||= {}
10
+ end
11
+
12
+ def rsg_state
13
+ @rsg_state ||= {generators: []}
14
+ end
15
+
7
16
  def rsg_install
8
17
  append_gem "rsg",
9
18
  within_group: %i(development test),
10
19
  install: false,
11
- path: options[:path]
20
+ path: options["path"]
21
+ end
22
+
23
+ def rsg_skip_or_confirm(option_key, prompt, &block)
24
+ if rsg_options.key?(option_key)
25
+ return if [false, :skip].include?(rsg_options[option_key])
26
+ else
27
+ return unless confirm?(prompt)
28
+ end
29
+
30
+ self.instance_eval(&block)
12
31
  end
13
32
 
14
- def rsg_generate(name, quiet: false)
33
+ def rsg_generate(name, generator_opts = {}, quiet: false)
15
34
  cmd = "generate #{name}"
16
35
  cmd << " -q" if quiet
17
36
 
18
- rails_command cmd
37
+ if generator_opts.is_a?(Hash)
38
+ generator_opts.each do |opt, value|
39
+ cmd << " --#{opt.to_s.dasherize}=#{Shellwords.escape(value)}"
40
+ end
41
+ end
42
+
43
+ rsg_state[:generators] << name
44
+
45
+ # FIXME: abort_on_failure is not working as expected, because `rails generate <invalid-generator>`
46
+ # does not return an exit code != 0
47
+ run("rails #{cmd}", abort_on_failure: true)
19
48
  git_add_commit "RSG Generator executed: #{name}"
20
49
  end
21
50
 
22
- def rsg_apply_default!
51
+ def rsg_apply_default!(rsg_options = {})
52
+ @rsg_options = rsg_options
23
53
  rsg_apply "rsg-default"
24
54
  end
25
55
 
@@ -64,11 +94,15 @@ module Rsg
64
94
  append_gem_line(match, gem_line, after)
65
95
  end
66
96
 
67
- run("bundle install", capture: true) if install
97
+ run("bundle install") if install
68
98
  end
69
99
 
70
100
  private
71
101
 
102
+ def run(*)
103
+ Bundler.with_unbundled_env { super }
104
+ end
105
+
72
106
  def append_gem_line(code, gem_line, after)
73
107
  code_lines = code.split("\n")
74
108
  index = code_lines.length
@@ -1,42 +1,29 @@
1
- # frozen_string_literal: true
1
+ require "rails/generators/rails/app/app_generator"
2
2
 
3
- module Rsg
4
- # The application builder allows you to override elements of the application
5
- # generator without being forced to reverse the operations of the default
6
- # generator.
7
- #
8
- # This allows you to override entire operations, like the creation of the
9
- # Gemfile, README, or JavaScript files, without needing to know exactly
10
- # what those operations do so you can create another template action.
11
- #
12
- # For Rails 6.1, you can check out https://github.com/rails/rails/blob/6-1-stable/railties/lib/rails/generators/rails/app/app_generator.rb#L44
13
- class AppBuilder < ::Rails::AppBuilder
14
- def master_key
15
- gsub_file "config/application.rb",
16
- /^(\s*)(config\.load_defaults[^\n]+)\n$/,
17
- "\\1\\2\n\n\\1# We don't use Rails encrypted secrets\n"\
18
- "\\1config.require_master_key = false\n" \
19
- "\\1config.active_support.use_authenticated_message_encryption = false\n"
20
- end
3
+ # The application builder allows you to override elements of the application
4
+ # generator without being forced to reverse the operations of the default
5
+ # generator.
6
+ #
7
+ # This allows you to override entire operations, like the creation of the
8
+ # Gemfile, README, or JavaScript files, without needing to know exactly
9
+ # what those operations do so you can create another template action.
10
+ #
11
+ # For Rails 6.1, you can check out https://github.com/rails/rails/blob/6-1-stable/railties/lib/rails/generators/rails/app/app_generator.rb#L44
12
+ class Rsg::Generators::App::AppBuilder < ::Rails::AppBuilder
13
+ ###########################################################################
14
+ # Simple template overwrites
15
+ ###########################################################################
21
16
 
22
- ###########################################################################
23
- # Simple template overwrites
24
- ###########################################################################
25
-
26
- def readme
27
- template "README.md.erb", "README.md"
28
- end
29
-
30
- ###########################################################################
31
- # Things to skip since we don't care about them
32
- ###########################################################################
17
+ def readme
18
+ template "README.md.erb", "README.md"
19
+ end
33
20
 
34
- def ruby_version
35
- # NOOP since we have the ruby version in Gemfile
36
- end
21
+ ###########################################################################
22
+ # Things to skip since we don't care about them
23
+ ###########################################################################
37
24
 
38
- def credentials
39
- # NOOP since we store env vars / secrets elsewhere
40
- end
25
+ def ruby_version
26
+ # NOOP since we have the ruby version in Gemfile and want it to be the
27
+ # single source of truth
41
28
  end
42
29
  end
@@ -1,80 +1,75 @@
1
- # require "rails/generators"
2
1
  require "rails/generators/rails/app/app_generator"
3
2
 
4
- require_relative "app_builder"
3
+ # AppGenerator is the entrypoint for generation of new apps which builds on top
4
+ # of the core `rails new` command
5
+ class Rsg::Generators::App::AppGenerator < Rails::Generators::AppGenerator
6
+ include Rsg::Generators::Actions
5
7
 
6
- module Rsg
7
- # AppGenerator is the entrypoint for generation of new apps which builds on
8
- # top of the core `rails new` command
9
- class AppGenerator < Rails::Generators::AppGenerator
10
- include Generators::Actions
8
+ hide!
11
9
 
12
- hide!
10
+ class_option :version, type: :boolean, aliases: "-v", group: :rsg, desc: "Show RSG version number and quit"
11
+ class_option :help, type: :boolean, aliases: "-h", group: :rsg, desc: "Show this help message and quit"
12
+ class_option :path, type: :string, default: nil, desc: "Path to the RSG gem"
13
+ class_option :template, aliases: "-m", type: :string, default: "rsg-default", desc: "Path to some application template (can be a filesystem path or URL)"
13
14
 
14
- class_option :version, type: :boolean, aliases: "-v", group: :rsg, desc: "Show RSG version number and quit"
15
- class_option :help, type: :boolean, aliases: "-h", group: :rsg, desc: "Show this help message and quit"
16
- class_option :path, type: :string, default: nil, desc: "Path to the RSG gem"
17
- class_option :template, aliases: "-m", type: :string, default: "rsg-default", desc: "Path to some application template (can be a filesystem path or URL)"
15
+ # --minimal might take care of some of these, but not all, we change all defaults here regardless since
16
+ # --minimal is subject to change with new releases. We also hide them all, and re-add things as necessary
17
+ # based on user input as generators kick in
18
+ class_option :skip_action_cable, type: :boolean, default: true, desc: "Skip Action Cable files", hide: true
19
+ class_option :skip_action_mailbox, type: :boolean, default: true, desc: "Skip Action Mailbox files", hide: true
20
+ class_option :skip_action_mailer, type: :boolean, default: true, desc: "Skip Action Mailer files", hide: true
21
+ class_option :skip_action_text, type: :boolean, default: true, desc: "Skip Action Text files", hide: true
22
+ class_option :skip_active_job, type: :boolean, default: true, desc: "Skip Active Job files", hide: true
23
+ class_option :skip_active_record, type: :boolean, default: true, desc: "Skip Active Record files", hide: true
24
+ class_option :skip_active_storage, type: :boolean, default: true, desc: "Skip Active Storage files", hide: true
25
+ class_option :skip_bundle, type: :boolean, default: true, desc: "Don't run bundle install", hide: true
26
+ class_option :skip_javascript, type: :boolean, default: true, desc: "Skip JavaScript files", hide: true
27
+ class_option :skip_jbuilder, type: :boolean, default: true, desc: "Skip jbuilder gem", hide: true
28
+ class_option :skip_keeps, type: :boolean, default: true, desc: "Skip Puma", hide: true
29
+ class_option :skip_spring, type: :boolean, default: true, desc: "Don't install Spring application preloader", hide: true
30
+ class_option :skip_sprockets, type: :boolean, default: true, desc: "Skip Sprockets files", hide: true
31
+ class_option :skip_system_test, type: :boolean, default: true, desc: "Skip system test files", hide: true
32
+ class_option :skip_test, type: :boolean, default: true, desc: "Skip Test Unit", hide: true
33
+ class_option :skip_turbolinks, type: :boolean, default: true, desc: "Skip turbolinks gem", hide: true
34
+ class_option :skip_webpack_install, type: :boolean, default: true, desc: "Don't run webpack install", hide: true
18
35
 
19
- # --minimal might take care of some of these, but not all, we change all defaults here regardless since
20
- # --minimal is subject to change with new releases. We also hide them all, and re-add things as necessary
21
- # based on user input as generators kick in
22
- class_option :skip_action_cable, type: :boolean, default: true, desc: "Skip Action Cable files", hide: true
23
- class_option :skip_action_mailbox, type: :boolean, default: true, desc: "Skip Action Mailbox files", hide: true
24
- class_option :skip_action_mailer, type: :boolean, default: true, desc: "Skip Action Mailer files", hide: true
25
- class_option :skip_action_text, type: :boolean, default: true, desc: "Skip Action Text files", hide: true
26
- class_option :skip_active_job, type: :boolean, default: true, desc: "Skip Active Job files", hide: true
27
- class_option :skip_active_record, type: :boolean, default: true, desc: "Skip Active Record files", hide: true
28
- class_option :skip_active_storage, type: :boolean, default: true, desc: "Skip Active Storage files", hide: true
29
- class_option :skip_bundle, type: :boolean, default: true, desc: "Don't run bundle install", hide: true
30
- class_option :skip_javascript, type: :boolean, default: true, desc: "Skip JavaScript files", hide: true
31
- class_option :skip_jbuilder, type: :boolean, default: true, desc: "Skip jbuilder gem", hide: true
32
- class_option :skip_keeps, type: :boolean, default: true, desc: "Skip Puma", hide: true
33
- class_option :skip_spring, type: :boolean, default: true, desc: "Don't install Spring application preloader", hide: true
34
- class_option :skip_sprockets, type: :boolean, default: true, desc: "Skip Sprockets files", hide: true
35
- class_option :skip_system_test, type: :boolean, default: true, desc: "Skip system test files", hide: true
36
- class_option :skip_test, type: :boolean, default: true, desc: "Skip Test Unit", hide: true
37
- class_option :skip_turbolinks, type: :boolean, default: true, desc: "Skip turbolinks gem", hide: true
38
- class_option :skip_webpack_install, type: :boolean, default: true, desc: "Don't run webpack install", hide: true
36
+ # Hide other flags, but leave their defaults untouched
37
+ class_option :database, type: :string, default: "sqlite3", desc: "Configure for selected database (options: #{DATABASES.join("/")})", hide: true
38
+ class_option :dev, type: :boolean, default: false, desc: "Set up the application with Gemfile pointing to your Rails checkout", hide: true
39
+ class_option :edge, type: :boolean, default: false, desc: "Set up the application with Gemfile pointing to Rails repository", hide: true
40
+ class_option :master, type: :boolean, default: false, desc: "Preconfigure a minimal rails app", hide: true
41
+ class_option :minimal, type: :boolean, default: false, desc: "Preconfigure a minimal rails app", hide: true
42
+ class_option :skip_bootsnap, type: :boolean, default: false, desc: "Skip bootsnap gem", hide: true
43
+ class_option :skip_collision_check, type: :boolean, default: false, desc: "Skip collision check", hide: true
44
+ class_option :skip_gemfile, type: :boolean, default: false, desc: "Don't create a Gemfile", hide: true
45
+ class_option :skip_git, type: :boolean, default: false, desc: "Skip .gitignore file", hide: true
46
+ class_option :skip_listen, type: :boolean, default: false, desc: "Don't generate configuration that depends on the listen gem", hide: true
47
+ class_option :skip_namespace, type: :boolean, default: false, desc: "Skip namespace (affects only isolated engines)", hide: true
48
+ class_option :skip_puma, type: :boolean, default: false, desc: "Skip Puma related files", hide: true
49
+ class_option :webpack, type: :string, desc: "Preconfigure Webpack with a particular framework (options: react, vue, angular, elm, stimulus)", hide: true
39
50
 
40
- # Hide other flags, but leave their defaults untouched
41
- class_option :database, type: :string, default: "sqlite3", desc: "Configure for selected database (options: #{DATABASES.join("/")})", hide: true
42
- class_option :dev, type: :boolean, default: false, desc: "Set up the application with Gemfile pointing to your Rails checkout", hide: true
43
- class_option :edge, type: :boolean, default: false, desc: "Set up the application with Gemfile pointing to Rails repository", hide: true
44
- class_option :master, type: :boolean, default: false, desc: "Preconfigure a minimal rails app", hide: true
45
- class_option :minimal, type: :boolean, default: false, desc: "Preconfigure a minimal rails app", hide: true
46
- class_option :skip_bootsnap, type: :boolean, default: false, desc: "Skip bootsnap gem", hide: true
47
- class_option :skip_collision_check, type: :boolean, default: false, desc: "Skip collision check", hide: true
48
- class_option :skip_gemfile, type: :boolean, default: false, desc: "Don't create a Gemfile", hide: true
49
- class_option :skip_git, type: :boolean, default: false, desc: "Skip .gitignore file", hide: true
50
- class_option :skip_listen, type: :boolean, default: false, desc: "Don't generate configuration that depends on the listen gem", hide: true
51
- class_option :skip_namespace, type: :boolean, default: false, desc: "Skip namespace (affects only isolated engines)", hide: true
52
- class_option :skip_puma, type: :boolean, default: false, desc: "Skip Puma related files", hide: true
53
- class_option :webpack, type: :string, desc: "Preconfigure Webpack with a particular framework (options: react, vue, angular, elm, stimulus)", hide: true
54
-
55
- def self.banner
56
- "rsg #{arguments.map(&:usage).join(" ")} [options]"
57
- end
51
+ def self.banner
52
+ "rsg #{arguments.map(&:usage).join(" ")} [options]"
53
+ end
58
54
 
59
- def self.source_paths
60
- @__source_paths ||= [
61
- Rails::Generators::AppGenerator.source_root,
62
- Pathname.new(__FILE__).dirname.join("templates").expand_path
63
- ]
64
- end
55
+ def self.source_paths
56
+ @__source_paths ||= [
57
+ ::Rails::Generators::AppGenerator.source_root,
58
+ Pathname.new(__FILE__).dirname.join("templates").expand_path
59
+ ]
60
+ end
65
61
 
66
- def set_default_accessors!
67
- bundled_template = Rsg.lookup_app_template(options[:template])
68
- super
69
- self.rails_template = bundled_template if bundled_template
70
- end
62
+ def set_default_accessors!
63
+ bundled_template = Rsg.lookup_app_template(options[:template])
64
+ super
65
+ self.rails_template = bundled_template if bundled_template
66
+ end
71
67
 
72
- protected
68
+ protected
73
69
 
74
- # rubocop:disable Naming/AccessorMethodName
75
- def get_builder_class
76
- Rsg::AppBuilder
77
- end
78
- # rubocop:enable Naming/AccessorMethodName
70
+ # rubocop:disable Naming/AccessorMethodName
71
+ def get_builder_class
72
+ Rsg::Generators::App::AppBuilder
79
73
  end
74
+ # rubocop:enable Naming/AccessorMethodName
80
75
  end
@@ -1,11 +1,13 @@
1
1
  require "pathname"
2
2
  require "rails/generators"
3
+ require "rails/generators/app_name"
3
4
 
4
5
  module Rsg
5
6
  module Generators
6
7
  class Base < Rails::Generators::Base
7
8
  include Actions
8
9
  include Options
10
+ include Rails::Generators::AppName
9
11
 
10
12
  def self.inherited(base)
11
13
  super
@@ -1,24 +1,18 @@
1
- require_relative "../base"
2
-
3
- module Rsg
4
- module Dotenv
5
- class InstallGenerator < Rsg::Generators::Base
6
- def banner
7
- say "Configuring dotent-rails in development and test environments"
8
- end
1
+ class Rsg::Generators::Dotenv::InstallGenerator < Rsg::Generators::Base
2
+ def banner
3
+ say "Configuring dotenv-rails in development and test environments"
4
+ end
9
5
 
10
- def add_dotenv
11
- append_gem "dotenv-rails",
12
- version: "< 3",
13
- after: "rails",
14
- group: [:development, :test],
15
- require: "dotenv/rails-now"
16
- end
6
+ def add_dotenv
7
+ append_gem "dotenv-rails",
8
+ version: "< 3",
9
+ after: "rails",
10
+ group: [:development, :test],
11
+ require: "dotenv/rails-now"
12
+ end
17
13
 
18
- def configure_dotenv
19
- copy_file "env.development", ".env.development"
20
- copy_file "env.test", ".env.test"
21
- end
22
- end
14
+ def configure_dotenv
15
+ copy_file "env.development", ".env.development"
16
+ copy_file "env.test", ".env.test"
23
17
  end
24
18
  end
@@ -1,40 +1,34 @@
1
- require_relative "../base"
2
-
3
- module Rsg
4
- module Logging
5
- class CommonGenerator < Rsg::Generators::Base
6
- def banner
7
- say "Improving basic logging configs"
8
- end
1
+ class Rsg::Generators::Logging::CommonGenerator < Rsg::Generators::Base
2
+ def banner
3
+ say "Improving basic logging configs"
4
+ end
9
5
 
10
- def log_level_env_var
11
- inject_into_file "config/application.rb", <<-CODE, before: /^ end$/
6
+ def log_level_env_var
7
+ inject_into_file "config/application.rb", <<-CODE, before: /^ end$/
12
8
  \n # Sane default log levels per env, but able to tweak with env var
13
9
  # NOTE: Settings on config/environments/*.rb take precedence over this
14
10
  config.log_level = ENV.fetch('LOG_LEVEL') { Rails.env.development? ? 'debug' : 'info' }.to_sym
15
11
 
16
12
  # Log to stdout most of the time and allow use of JSON logs in dev by using an env var
17
13
  config.x.log_to_stdout = %w[1 true yes].include?(ENV.fetch('RAILS_LOG_TO_STDOUT', '1'))
18
- CODE
19
- end
14
+ CODE
15
+ end
20
16
 
21
- def stdout_logging_in_dev
22
- inject_into_file "config/environments/development.rb", <<-CODE, before: /^end$/
17
+ def stdout_logging_in_dev
18
+ inject_into_file "config/environments/development.rb", <<-CODE, before: /^end$/
23
19
  \n # Configure stdout logging in dev as well
24
20
  if config.x.log_to_stdout
25
21
  logger = ActiveSupport::Logger.new(STDOUT)
26
22
  logger.formatter = config.log_formatter
27
23
  config.logger = ActiveSupport::TaggedLogging.new(logger)
28
24
  end
29
- CODE
30
- end
25
+ CODE
26
+ end
31
27
 
32
- def adjust_prod
33
- comment_lines "config/environments/production.rb", /^(\s*)(config\.log_level .+)$/
34
- gsub_file "config/environments/production.rb",
35
- 'ENV["RAILS_LOG_TO_STDOUT"].present?',
36
- "config.x.log_to_stdout"
37
- end
38
- end
28
+ def adjust_prod
29
+ comment_lines "config/environments/production.rb", /^(\s*)(config\.log_level .+)$/
30
+ gsub_file "config/environments/production.rb",
31
+ 'ENV["RAILS_LOG_TO_STDOUT"].present?',
32
+ "config.x.log_to_stdout"
39
33
  end
40
34
  end
@@ -1,31 +1,21 @@
1
- require_relative "../base"
2
-
3
- module Rsg
4
- module Logging
5
- class LogrageGenerator < Rsg::Generators::Base
6
- def self.source_root
7
- Pathname.new(__FILE__).dirname.join("templates").expand_path
8
- end
9
-
10
- def banner
11
- say "Configuring lograge with JSON logging"
12
- end
1
+ class Rsg::Generators::Logging::LogrageGenerator < Rsg::Generators::Base
2
+ def banner
3
+ say "Configuring lograge with JSON logging"
4
+ end
13
5
 
14
- def add_lograge
15
- append_gem "lograge", install: false
16
- append_gem "logstash-event", after: "lograge"
17
- end
6
+ def add_lograge
7
+ append_gem "lograge", install: false
8
+ append_gem "logstash-event", after: "lograge"
9
+ end
18
10
 
19
- def initializer
20
- copy_file "initializer_lograge.rb", "config/initializers/logging.rb"
21
- end
11
+ def initializer
12
+ copy_file "initializer_lograge.rb", "config/initializers/logging.rb"
13
+ end
22
14
 
23
- def json_logs_env_var
24
- inject_into_file "config/application.rb", <<-CODE, before: /^ end$/
15
+ def json_logs_env_var
16
+ inject_into_file "config/application.rb", <<-CODE, before: /^ end$/
25
17
  \n # Enable JSON logs with lograge
26
18
  config.x.json_logs = Rails.env.production? || %w[1 true yes].include?(ENV.fetch('JSON_LOGS', '0'))
27
- CODE
28
- end
29
- end
19
+ CODE
30
20
  end
31
21
  end