rsg 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +44 -3
- data/Gemfile.lock +5 -4
- data/README.md +13 -6
- data/exe/rsg +1 -1
- data/lib/rsg/generators/actions.rb +39 -5
- data/lib/rsg/generators/app/app_builder.rb +23 -36
- data/lib/rsg/generators/app/app_generator.rb +62 -67
- data/lib/rsg/generators/base.rb +2 -0
- data/lib/rsg/generators/dotenv/install_generator.rb +14 -20
- data/lib/rsg/generators/logging/common_generator.rb +17 -23
- data/lib/rsg/generators/logging/lograge_generator.rb +14 -24
- data/lib/rsg/generators/logging/templates/{initializer_lograge.rb → initializer_lograge.rb.tt} +0 -0
- data/lib/rsg/generators/misc/misc_generator.rb +47 -38
- data/lib/rsg/generators/misc/templates/{puma.rb → puma.rb.tt} +0 -0
- data/lib/rsg/generators/orm/active_record_generator.rb +38 -32
- data/lib/rsg/generators/orm/templates/{db.rake → db.rake.tt} +0 -0
- data/lib/rsg/generators/orm/templates/{samples.rb → samples.rb.tt} +0 -0
- data/lib/rsg/generators/orm/templates/{seeds.rb → seeds.rb.tt} +0 -0
- data/lib/rsg/generators/testing/rspec_generator.rb +19 -25
- data/lib/rsg/generators/webpacker/bootstrap_generator.rb +27 -0
- data/lib/rsg/generators/webpacker/install_generator.rb +37 -47
- data/lib/rsg/generators/webpacker/templates/bootstrap/application.sass +40 -0
- data/lib/rsg/generators/webpacker/templates/bootstrap/landing.html.erb +18 -0
- data/lib/rsg/generators/webpacker/templates/bootstrap/layout.html.erb +35 -0
- data/lib/rsg/generators/webpacker/templates/landing_controller.rb.erb +1 -1
- data/lib/rsg/version.rb +1 -1
- data/lib/rsg.rb +6 -15
- data/rsg.gemspec +4 -0
- data/templates/rsg-bootstrap.rb +7 -0
- data/templates/rsg-default.rb +10 -3
- metadata +26 -12
- data/lib/rsg/generators/gemfile/cleanup_generator.rb +0 -28
- data/lib/rsg/generators/install/install_generator.rb +0 -13
- data/lib/rsg/generators/orm/templates/active_record/mysql.yml +0 -59
- data/lib/rsg/generators/orm/templates/active_record/postgresql.yml +0 -86
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dde28f50b96b413bafb73508dfd480e7af42d5d4ed88f4d4096e99c050f7e836
|
4
|
+
data.tar.gz: 78534e115a388404d72ba986ecbf722ed42bb6e408072a564d0f319e434942db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
5
|
+
- image: cimg/ruby:3.0
|
6
6
|
steps:
|
7
7
|
- checkout
|
8
|
+
|
8
9
|
- run:
|
9
|
-
name:
|
10
|
+
name: "Configure git client"
|
10
11
|
command: |
|
11
|
-
|
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
|
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.
|
165
|
-
actionpack (>=
|
166
|
-
activesupport (>=
|
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
|
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
|
-
- [
|
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
|
-
- [ ]
|
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
@@ -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[
|
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
|
-
|
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"
|
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
|
-
|
1
|
+
require "rails/generators/rails/app/app_generator"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
21
|
+
###########################################################################
|
22
|
+
# Things to skip since we don't care about them
|
23
|
+
###########################################################################
|
37
24
|
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
68
|
+
protected
|
73
69
|
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
data/lib/rsg/generators/base.rb
CHANGED
@@ -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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
11
|
-
|
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
|
-
|
19
|
-
|
14
|
+
CODE
|
15
|
+
end
|
20
16
|
|
21
|
-
|
22
|
-
|
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
|
-
|
30
|
-
|
25
|
+
CODE
|
26
|
+
end
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
def add_lograge
|
7
|
+
append_gem "lograge", install: false
|
8
|
+
append_gem "logstash-event", after: "lograge"
|
9
|
+
end
|
18
10
|
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
def initializer
|
12
|
+
copy_file "initializer_lograge.rb", "config/initializers/logging.rb"
|
13
|
+
end
|
22
14
|
|
23
|
-
|
24
|
-
|
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
|
-
|
28
|
-
end
|
29
|
-
end
|
19
|
+
CODE
|
30
20
|
end
|
31
21
|
end
|
data/lib/rsg/generators/logging/templates/{initializer_lograge.rb → initializer_lograge.rb.tt}
RENAMED
File without changes
|