boring_generators 0.11.0 → 0.13.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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -2
- data/.github/workflows/codeql-analysis.yml +70 -0
- data/.gitignore +3 -0
- data/CHANGELOG.md +18 -1
- data/CONTRIBUTING.md +17 -0
- data/Gemfile.lock +9 -11
- data/README.md +15 -1
- data/lib/boring_generators/version.rb +1 -1
- data/lib/generators/boring/bootstrap/install/install_generator.rb +15 -1
- data/lib/generators/boring/factory_bot/install/install_generator.rb +46 -0
- data/lib/generators/boring/factory_bot/install/templates/users.rb +8 -0
- data/lib/generators/boring/faker/install/install_generator.rb +17 -0
- data/lib/generators/boring/flipper/install/install_generator.rb +37 -0
- data/lib/generators/boring/flipper/install/templates/initializer.rb.tt +19 -0
- data/lib/generators/boring/letter_opener/install/install_generator.rb +39 -0
- data/lib/generators/boring/overcommit/base_generator.rb +45 -0
- data/lib/generators/boring/overcommit/pre_commit/rubocop/install/install_generator.rb +62 -0
- data/lib/generators/boring/rspec/install/install_generator.rb +50 -0
- data/lib/generators/boring/rswag/install/install_generator.rb +166 -0
- data/lib/generators/boring/rswag/install/templates/README +10 -0
- data/lib/generators/boring/rubocop/install/install_generator.rb +32 -6
- data/lib/generators/boring/rubocop/install/templates/.rubocop.yml.tt +6 -3
- data/lib/generators/boring/webmock/install/install_generator.rb +86 -0
- data/lib/generators/boring/whenever/install/install_generator.rb +25 -0
- data/tmp/templates/app_template/.ruby-version +1 -1
- data/tmp/templates/app_template/Gemfile +1 -1
- data/tmp/templates/app_template/config/boot.rb +1 -1
- data/tmp/templates/app_template/yarn.lock +61 -91
- metadata +17 -4
- data/tmp/templates/app_template/log/development.log +0 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3e2cf89c148c10914b919c1f9be41275681aa3ba8eaed7a22df5beb6adbef55
|
4
|
+
data.tar.gz: '083314c373aeb284b779aba16629fa36cbbeb9f60521161d0f1de081b7c1f99a'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2f943d1a4fdda23f2a1905a3491f11e5aa8adde05371b24f91c20daa3dc7355a4d1a51e9d82243b642c2ddb5e738a5885369b034c79e87f801078186cf645b5
|
7
|
+
data.tar.gz: 4b1f672d170a27bd8782e423b228a45974ad5c6a2e8262adbfe91a109cc29b10f449d20176c8113201db119363fa3b035ce7707a71365ecfb391ee1a18a77cb8
|
data/.github/workflows/ci.yml
CHANGED
@@ -10,11 +10,11 @@ jobs:
|
|
10
10
|
- name: Set up Ruby
|
11
11
|
uses: ruby/setup-ruby@v1
|
12
12
|
with:
|
13
|
-
ruby-version: 2.7.
|
13
|
+
ruby-version: 2.7.3
|
14
14
|
bundler-cache: true
|
15
15
|
- name: Install Imagemagick
|
16
16
|
run: |
|
17
|
-
wget https://raw.githubusercontent.com/discourse/discourse_docker/
|
17
|
+
wget https://raw.githubusercontent.com/discourse/discourse_docker/main/image/base/install-imagemagick
|
18
18
|
chmod +x install-imagemagick
|
19
19
|
sudo ./install-imagemagick
|
20
20
|
- name: Install gems
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
2
|
+
# to commit it to your repository.
|
3
|
+
#
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
+
# or to provide custom queries or build logic.
|
6
|
+
#
|
7
|
+
# ******** NOTE ********
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
+
# supported CodeQL languages.
|
11
|
+
#
|
12
|
+
name: "CodeQL"
|
13
|
+
|
14
|
+
on:
|
15
|
+
push:
|
16
|
+
branches: [ main ]
|
17
|
+
pull_request:
|
18
|
+
# The branches below must be a subset of the branches above
|
19
|
+
branches: [ main ]
|
20
|
+
schedule:
|
21
|
+
- cron: '41 1 * * 3'
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
analyze:
|
25
|
+
name: Analyze
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
permissions:
|
28
|
+
actions: read
|
29
|
+
contents: read
|
30
|
+
security-events: write
|
31
|
+
|
32
|
+
strategy:
|
33
|
+
fail-fast: false
|
34
|
+
matrix:
|
35
|
+
language: [ 'javascript', 'ruby' ]
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
37
|
+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout repository
|
41
|
+
uses: actions/checkout@v2
|
42
|
+
|
43
|
+
# Initializes the CodeQL tools for scanning.
|
44
|
+
- name: Initialize CodeQL
|
45
|
+
uses: github/codeql-action/init@v1
|
46
|
+
with:
|
47
|
+
languages: ${{ matrix.language }}
|
48
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
49
|
+
# By default, queries listed here will override any specified in a config file.
|
50
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
51
|
+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
52
|
+
|
53
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
54
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
55
|
+
- name: Autobuild
|
56
|
+
uses: github/codeql-action/autobuild@v1
|
57
|
+
|
58
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
59
|
+
# 📚 https://git.io/JvXDl
|
60
|
+
|
61
|
+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
62
|
+
# and modify them (or add more) to build your code if your project
|
63
|
+
# uses a compiled language
|
64
|
+
|
65
|
+
#- run: |
|
66
|
+
# make bootstrap
|
67
|
+
# make release
|
68
|
+
|
69
|
+
- name: Perform CodeQL Analysis
|
70
|
+
uses: github/codeql-action/analyze@v1
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,11 +2,26 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.13.0 (March 26th, 2024)
|
6
|
+
* Adds Letter Opener generator. ([@coolprobn][])
|
7
|
+
* Adds Whenever generator. ([@aadil][])
|
8
|
+
* Adds Rswag generator. ([@coolprobn][])
|
9
|
+
* Adds Webmock generator. ([@aadil][])
|
10
|
+
|
11
|
+
## 0.12.0 (May 8th, 2023)
|
12
|
+
* Adds Flipper generator. ([@abhaynikam][])
|
13
|
+
* Adds FactoryBot generator. ([@abhaynikam][])
|
14
|
+
* Adds Faker generator. ([@abhaynikam][])
|
15
|
+
* Adds RSpec generator. ([@abhaynikam][])
|
16
|
+
* Update default node-version for GitHub Action generator and fixes PG setup issues. ([@abhaynikam][])
|
17
|
+
* Updates Bootstrap generator for supporting Bootstrap 5 with popper.js. ([@abhaynikam][])
|
18
|
+
* Adds Overcommit generator for RuboCop. ([@coolprobn][])
|
19
|
+
* Updates RuboCop generator to add rubocop-rake extension and support test frameworks ([@coolprobn][])
|
20
|
+
|
5
21
|
## 0.11.0 (June 23rd, 2021)
|
6
22
|
* Adds Stimulus generator. ([@abhaynikam][])
|
7
23
|
* Adds Rails Admin generator. ([@abhaynikam][])
|
8
24
|
* Adds Paper Trail generator. ([@abhaynikam][])
|
9
|
-
* Update default node-version for GitHub Action generator and fixes PG setup issues. ([@abhaynikam][])
|
10
25
|
|
11
26
|
## 0.10.0 (May 26th, 2021)
|
12
27
|
* Updates Stripe payment generator. ([@abhaynikam][])
|
@@ -67,3 +82,5 @@
|
|
67
82
|
[@CiTroNaK]: https://github.com/CiTroNaK
|
68
83
|
[@jamesglover]: https://github.com/JamesGlover
|
69
84
|
[@luathn]: https://github.com/luathn
|
85
|
+
[@coolprobn]: https://github.com/coolprobn
|
86
|
+
[@aadil]: https://github.com/AdilRT
|
data/CONTRIBUTING.md
CHANGED
@@ -18,3 +18,20 @@ Push to your fork. Write a [good commit message][commit]. Submit a pull request.
|
|
18
18
|
|
19
19
|
Please do not self reject your thoughts. Let's discuss even smallest feature request as well and make
|
20
20
|
this package better for everybody's use.
|
21
|
+
|
22
|
+
## Notes for Local Development of the Gem
|
23
|
+
|
24
|
+
### While running Tests
|
25
|
+
|
26
|
+
When running tests, we normally do `bundle exec ruby -w -I test test/generators/rswag_install_generator_test.rb` to run a single test where "rswag_install_generator_test.rb" is the file name of the test we want to run.
|
27
|
+
|
28
|
+
And if your global ruby version is not the same as the "tmp/templates/app_template" where we run tests and make changes, tests might fail due to mismatch of ruby version and required gems not being installed correctly.
|
29
|
+
|
30
|
+
To tackle this issue you can add `.ruby-version` to the gem root by specifying the ruby version app_template is using. If you use rbenv this can be done with `rbenv local 2.7.0` where "2.7.0" is the app_template ruby-version at the moment.
|
31
|
+
|
32
|
+
We shouldn't commit this ".ruby-version" file to git since it's only intended for running tests. So to ignore this file from the git just for you, you can do the following:
|
33
|
+
|
34
|
+
- Open the git exclude file `nano .git/info/exclude`
|
35
|
+
- Add the file name ".ruby-version" to the end of the file and save it.
|
36
|
+
|
37
|
+
Now .ruby-version will be ignored by the git in your local machine just for this project.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
boring_generators (0.
|
4
|
+
boring_generators (0.12.0)
|
5
5
|
railties
|
6
6
|
|
7
7
|
GEM
|
@@ -71,7 +71,7 @@ GEM
|
|
71
71
|
activesupport (>= 4.2.0)
|
72
72
|
i18n (1.8.10)
|
73
73
|
concurrent-ruby (~> 1.0)
|
74
|
-
loofah (2.
|
74
|
+
loofah (2.20.0)
|
75
75
|
crass (~> 1.0.2)
|
76
76
|
nokogiri (>= 1.5.9)
|
77
77
|
mail (2.7.1)
|
@@ -79,14 +79,12 @@ GEM
|
|
79
79
|
marcel (1.0.1)
|
80
80
|
method_source (1.0.0)
|
81
81
|
mini_mime (1.1.0)
|
82
|
-
mini_portile2 (2.
|
82
|
+
mini_portile2 (2.4.0)
|
83
83
|
minitest (5.14.4)
|
84
84
|
nio4r (2.5.7)
|
85
|
-
nokogiri (1.
|
86
|
-
mini_portile2 (~> 2.
|
87
|
-
|
88
|
-
racc (1.5.2)
|
89
|
-
rack (2.2.3)
|
85
|
+
nokogiri (1.10.10)
|
86
|
+
mini_portile2 (~> 2.4.0)
|
87
|
+
rack (2.2.6.4)
|
90
88
|
rack-test (1.1.0)
|
91
89
|
rack (>= 1.0, < 3)
|
92
90
|
rails (6.0.3.6)
|
@@ -107,8 +105,8 @@ GEM
|
|
107
105
|
rails-dom-testing (2.0.3)
|
108
106
|
activesupport (>= 4.2.0)
|
109
107
|
nokogiri (>= 1.6)
|
110
|
-
rails-html-sanitizer (1.
|
111
|
-
loofah (~> 2.
|
108
|
+
rails-html-sanitizer (1.5.0)
|
109
|
+
loofah (~> 2.19, >= 2.19.1)
|
112
110
|
railties (6.0.3.6)
|
113
111
|
actionpack (= 6.0.3.6)
|
114
112
|
activesupport (= 6.0.3.6)
|
@@ -126,7 +124,7 @@ GEM
|
|
126
124
|
sqlite3 (1.4.2)
|
127
125
|
thor (1.1.0)
|
128
126
|
thread_safe (0.3.6)
|
129
|
-
tzinfo (1.2.
|
127
|
+
tzinfo (1.2.10)
|
130
128
|
thread_safe (~> 0.1)
|
131
129
|
websocket-driver (0.7.3)
|
132
130
|
websocket-extensions (>= 0.1.0)
|
data/README.md
CHANGED
@@ -37,9 +37,14 @@ And then you can use it this way:
|
|
37
37
|
$ boring generate boring:simple_form:install --css_framework=<css_framework>
|
38
38
|
$ boring g boring:pry:install
|
39
39
|
|
40
|
+
To see options provided by each generator with their descriptions and accepted values, you can hit the following command for example:
|
41
|
+
|
42
|
+
$ boring generate boring:simple_form:install --help
|
43
|
+
|
40
44
|
## Usage
|
41
45
|
|
42
46
|
The boring generator introduces following generators:
|
47
|
+
|
43
48
|
- [Install Tailwind CSS](https://www.boringgenerators.com/blog/2020-10-18-install-tailwind/): `rails generate boring:tailwind:install`
|
44
49
|
- [Install Bootstrap](https://www.boringgenerators.com/blog/2020-11-15-install-bootstrap/): `rails generate boring:bootstrap:install`
|
45
50
|
- Install JQuery: `rails generate boring:jquery:install`
|
@@ -54,7 +59,7 @@ The boring generator introduces following generators:
|
|
54
59
|
- [Install CircleCI](https://www.boringgenerators.com/blog/2021-01-02-configure-circleci/): `rails generate boring:ci:circleci:install --repository_name=<name> --ruby_version=<version>`
|
55
60
|
- [Install GitHub Actions](https://www.boringgenerators.com/blog/2020-12-17-configure-github-actions/): `rails generate boring:ci:github_action:install --repository_name=<name> --ruby_version=<version>`
|
56
61
|
- Install Travis CI: `rails generate boring:ci:travisci:install --ruby_version=<version>`
|
57
|
-
- Install Rubocop: `rails generate boring:rubocop:install --ruby_version=<version>`
|
62
|
+
- Install Rubocop: `rails generate boring:rubocop:install --ruby_version=<version> --test_gem=<test_framework_name>`
|
58
63
|
- Build Favicon: `rails generate boring:favicon:build --application_name=<application_name> --favico_letter=<favico_letter> --primary_color=<color>`
|
59
64
|
- Install Pundit: `rails generate boring:pundit:install`
|
60
65
|
- Install GraphQL: `rails generate boring:graphql:install`
|
@@ -70,6 +75,15 @@ The boring generator introduces following generators:
|
|
70
75
|
- Install Stimulus: `rails generate boring:stimulus:install`
|
71
76
|
- Install Rails Admin: `rails generate boring:rails_admin:install`
|
72
77
|
- Install Paper Trail: `rails generate boring:paper_trail:install`
|
78
|
+
- Install Flipper: `rails generate boring:flipper:install`
|
79
|
+
- Install RSpec: `rails generate boring:rspec:install`
|
80
|
+
- Install FactoryBot: `rails generate boring:factory_bot:install`
|
81
|
+
- Install Faker: `rails generate boring:faker:install`
|
82
|
+
- Install Overcommit with RuboCop: `rails generate boring:overcommit:pre_commit:rubocop:install`
|
83
|
+
- Install Letter Opener: `rails generate boring:letter_opener:install`
|
84
|
+
- Install Whenever: `rails generate boring:whenever:install`
|
85
|
+
- Install Rswag: `rails generate boring:rswag:install --rails_port=<rails_app_port> --authentication_type=<api_authentication_type> --skip_api_authentication=<skip_api_authentication> --api_authentication_options=<api_authentication_options> --enable_swagger_ui_authentication=<enable_swagger_ui_authentication>`
|
86
|
+
- Install Webmock: `rails generate boring:webmock:install --app_test_framework=<test_framework>`
|
73
87
|
|
74
88
|
## Screencasts
|
75
89
|
|
@@ -8,7 +8,7 @@ module Boring
|
|
8
8
|
|
9
9
|
def add_bootstrap_package
|
10
10
|
say "Adding bootstrap packages", :green
|
11
|
-
run "yarn add bootstrap jquery
|
11
|
+
run "yarn add bootstrap jquery @popperjs/core"
|
12
12
|
end
|
13
13
|
|
14
14
|
def add_jquery_plugin_provider_to_webpack_environment
|
@@ -48,6 +48,20 @@ module Boring
|
|
48
48
|
\n
|
49
49
|
import "bootstrap"
|
50
50
|
import "stylesheets/application"
|
51
|
+
import { Tooltip, Popover } from "bootstrap"
|
52
|
+
|
53
|
+
document.addEventListener("turbolinks:load", () => {
|
54
|
+
// Both of these are from the Bootstrap 5 docs
|
55
|
+
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
|
56
|
+
var tooltipList = tooltipTriggerList.map(function(tooltipTriggerEl) {
|
57
|
+
return new Tooltip(tooltipTriggerEl)
|
58
|
+
})
|
59
|
+
|
60
|
+
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
|
61
|
+
var popoverList = popoverTriggerList.map(function(popoverTriggerEl) {
|
62
|
+
return new Popover(popoverTriggerEl)
|
63
|
+
})
|
64
|
+
})
|
51
65
|
RUBY
|
52
66
|
append_to_file "app/javascript/packs/application.js", application_js_content
|
53
67
|
else
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boring
|
4
|
+
module FactoryBot
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Adds FactoryBot to the application"
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
class_option :skip_factory, type: :boolean, aliases: "-s",
|
10
|
+
desc: "Skips adding sample factory"
|
11
|
+
class_option :skip_faker, type: :boolean, aliases: "-s",
|
12
|
+
desc: "Skips faker install"
|
13
|
+
|
14
|
+
def add_factory_bot_gem
|
15
|
+
log :adding, "FactoryBot"
|
16
|
+
Bundler.with_unbundled_env do
|
17
|
+
run "bundle add factory_bot_rails --group='developement,test'"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_sample_factory
|
22
|
+
return if options[:skip_factory]
|
23
|
+
|
24
|
+
log :adding, "Sample users factory"
|
25
|
+
copy_file "users.rb", "test/factories/users.rb"
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_factory_bot_helper_method
|
29
|
+
log :adding, "factory_bot helper"
|
30
|
+
data = <<~RUBY
|
31
|
+
include FactoryBot::Syntax::Methods
|
32
|
+
RUBY
|
33
|
+
|
34
|
+
inject_into_file "test/test_helper.rb", optimize_indentation(data, 2),
|
35
|
+
after: /ActiveSupport::TestCase*\n/,
|
36
|
+
verbose: false
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_faker_gem
|
40
|
+
return if options[:skip_faker]
|
41
|
+
|
42
|
+
Rails::Command.invoke :generate, ["boring:faker:install"]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boring
|
4
|
+
module Faker
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Adds Faker to the application"
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
def add_faker_gem
|
10
|
+
log :adding, "faker"
|
11
|
+
Bundler.with_unbundled_env do
|
12
|
+
run "bundle add faker --group='developement,test'"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boring
|
4
|
+
module Flipper
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Adds Active Record Flipper to the application"
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
def add_flipper_gem
|
10
|
+
say "Adding Flipper gem", :green
|
11
|
+
Bundler.with_unbundled_env do
|
12
|
+
run "bundle add flipper-active_record flipper-ui"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def run_flipper_active_record_generator
|
17
|
+
say "Running Active Record Flipper generator", :green
|
18
|
+
Bundler.with_unbundled_env do
|
19
|
+
run "bundle exec rails generate flipper:active_record"
|
20
|
+
run "bundle exec rails db:migrate"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_flipper_initializer
|
25
|
+
say "Adding Flipper initializer", :green
|
26
|
+
copy_file "initializer.rb", "config/initializers/flipper.rb"
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_flipper_routes
|
30
|
+
say "Adding Flipper UI routes", :green
|
31
|
+
route <<~ROUTE
|
32
|
+
mount Flipper::UI.app(Flipper) => '/admins/flipper'
|
33
|
+
ROUTE
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'flipper/ui'
|
2
|
+
require "flipper/adapters/active_record"
|
3
|
+
|
4
|
+
Flipper::UI.configure do |config|
|
5
|
+
if Rails.env.production?
|
6
|
+
config.banner_text = "Production Environment"
|
7
|
+
else
|
8
|
+
config.banner_text = "Non-Production Environment"
|
9
|
+
config.banner_class = "primary"
|
10
|
+
end
|
11
|
+
|
12
|
+
config.fun = false
|
13
|
+
config.cloud_recommendation = false
|
14
|
+
end
|
15
|
+
|
16
|
+
# - Define All Actor here -
|
17
|
+
Flipper.register(:admins) do |actor, context|
|
18
|
+
actor.respond_to?(:admin?) && actor.admin?
|
19
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boring
|
4
|
+
module LetterOpener
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Adds letter_opener gem for previewing email in development environment"
|
7
|
+
|
8
|
+
def add_letter_opener_gem
|
9
|
+
say "Adding letter_opener gem", :green
|
10
|
+
|
11
|
+
gem_content = <<~RUBY
|
12
|
+
\t# Preview email in the default browser instead of sending it to real mailbox
|
13
|
+
\tgem "letter_opener"
|
14
|
+
RUBY
|
15
|
+
|
16
|
+
insert_into_file "Gemfile", gem_content, after: /group :development do/
|
17
|
+
|
18
|
+
Bundler.with_unbundled_env do
|
19
|
+
run "bundle install"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure_letter_opener
|
24
|
+
say "Configuring letter_opener", :green
|
25
|
+
|
26
|
+
configuration_content = <<~RUBY.chomp
|
27
|
+
\n\t# Preview email in the browser instead of sending it
|
28
|
+
\tconfig.action_mailer.delivery_method = :letter_opener
|
29
|
+
\tconfig.action_mailer.perform_deliveries = true
|
30
|
+
end
|
31
|
+
RUBY
|
32
|
+
|
33
|
+
gsub_file "config/environments/development.rb",
|
34
|
+
/end\Z/,
|
35
|
+
configuration_content
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
module Boring
|
6
|
+
module Overcommit
|
7
|
+
class BaseGenerator < Rails::Generators::Base
|
8
|
+
desc "Adds and configures overcommit gem in the application"
|
9
|
+
|
10
|
+
class_option :skip_configuration,
|
11
|
+
type: :boolean, aliases: "-s",
|
12
|
+
desc: "Skips adding overcommit development configuration"
|
13
|
+
|
14
|
+
def add_overcommit_gem
|
15
|
+
say "Adding overcommit gem", :green
|
16
|
+
|
17
|
+
if overcommit_gem_exists?
|
18
|
+
say "Overcommit gem is already installed!", :yellow
|
19
|
+
else
|
20
|
+
Bundler.with_unbundled_env do
|
21
|
+
run "bundle add overcommit --group development,test"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_git_hooks_with_overcommit
|
27
|
+
return if options[:skip_configuration]
|
28
|
+
|
29
|
+
say "\nInstalling git hooks to your project", :green
|
30
|
+
|
31
|
+
Bundler.with_unbundled_env do
|
32
|
+
run "bundle exec overcommit --install"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def overcommit_gem_exists?
|
39
|
+
gem_file_content_array = File.readlines("Gemfile")
|
40
|
+
|
41
|
+
gem_file_content_array.any? { |line| line.include?("overcommit") }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "generators/boring/overcommit/base_generator"
|
4
|
+
|
5
|
+
module Boring
|
6
|
+
module Overcommit
|
7
|
+
module PreCommit
|
8
|
+
module Rubocop
|
9
|
+
class InstallGenerator < Boring::Overcommit::BaseGenerator
|
10
|
+
DEFAULT_RUBY_VERSION = "2.7.1"
|
11
|
+
|
12
|
+
class_option :ruby_version, type: :string, aliases: "-v",
|
13
|
+
desc: "Tell us the ruby version you use for the application. Defaults to Ruby #{DEFAULT_RUBY_VERSION}"
|
14
|
+
|
15
|
+
def check_and_install_rubocop
|
16
|
+
return if rubocop_gem_exists?
|
17
|
+
|
18
|
+
say "\nRuboCop gem is not installed. Running the generator to install it!\n", :red
|
19
|
+
|
20
|
+
ruby_version = options[:ruby_version].presence || DEFAULT_RUBY_VERSION
|
21
|
+
|
22
|
+
run "bundle exec rails generate boring:rubocop:install --ruby_version=#{ruby_version}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def configure_rubocop
|
26
|
+
say "\nAdding configurations for running RuboCop on pre-commit", :green
|
27
|
+
|
28
|
+
uncomment_lines(".overcommit.yml", /PreCommit:/)
|
29
|
+
|
30
|
+
gsub_file(".overcommit.yml", /PreCommit:/) do
|
31
|
+
<<~YAML
|
32
|
+
PreCommit:
|
33
|
+
RuboCop:
|
34
|
+
enabled: true
|
35
|
+
on_warn: fail # Treat all warnings as failures
|
36
|
+
problem_on_unmodified_line: ignore # run RuboCop only on modified code'
|
37
|
+
YAML
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def enable_overcommit_configurations
|
42
|
+
say "\nEnabling new configurations", :green
|
43
|
+
|
44
|
+
run "git add .overcommit.yml"
|
45
|
+
|
46
|
+
Bundler.with_unbundled_env do
|
47
|
+
run "bundle exec overcommit --sign"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def rubocop_gem_exists?
|
54
|
+
gem_file_content_array = File.readlines("Gemfile")
|
55
|
+
|
56
|
+
gem_file_content_array.any? { |line| line.include?("rubocop") }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boring
|
4
|
+
module Rspec
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Adds RSpec to the application"
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
class_option :skip_factory_bot, type: :boolean, aliases: "-sfb",
|
10
|
+
desc: "Skips installing factory bot"
|
11
|
+
class_option :skip_faker, type: :boolean, aliases: "-sf",
|
12
|
+
desc: "Skips faker install"
|
13
|
+
|
14
|
+
def add_rspec_gem
|
15
|
+
log :adding, "rspec-rails"
|
16
|
+
Bundler.with_unbundled_env do
|
17
|
+
run "bundle add rspec-rails --group='developement,test'"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_rspec_active_record_generator
|
22
|
+
log :running, "rspec generator"
|
23
|
+
Bundler.with_unbundled_env do
|
24
|
+
run "rails generate rspec:install"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_rspec_initializer
|
29
|
+
log :override, "test_framework to rspec"
|
30
|
+
environment <<~end_of_config
|
31
|
+
config.generators do |g|
|
32
|
+
g.test_framework :rspec
|
33
|
+
end
|
34
|
+
end_of_config
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_factory_bot
|
38
|
+
return if options[:skip_factory_bot]
|
39
|
+
|
40
|
+
Rails::Command.invoke :generate, ["boring:factory_bot:install"]
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_faker_gem
|
44
|
+
return if options[:skip_faker]
|
45
|
+
|
46
|
+
Rails::Command.invoke :generate, ["boring:faker:install"]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|