boring_generators 0.5.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +12 -0
- data/.github/workflows/ci.yml +7 -1
- data/CHANGELOG.md +27 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +94 -21
- data/README.md +27 -6
- data/Rakefile +1 -0
- data/boring_generators.gemspec +1 -1
- data/exe/boring +5 -0
- data/lib/boring_generators.rb +1 -0
- data/lib/boring_generators/cli.rb +26 -0
- data/lib/boring_generators/version.rb +1 -1
- data/lib/generators/boring/active_storage/aws/install/install_generator.rb +10 -8
- data/lib/generators/boring/active_storage/azure/install/install_generator.rb +9 -7
- data/lib/generators/boring/active_storage/google/install/install_generator.rb +9 -7
- data/lib/generators/boring/ahoy/install/install_generator.rb +31 -0
- data/lib/generators/boring/ahoy/install/templates/README +10 -0
- data/lib/generators/boring/audit/install/install_generator.rb +12 -9
- data/lib/generators/boring/bullet/install/install_generator.rb +4 -8
- data/lib/generators/boring/ci/github_action/install/install_generator.rb +16 -2
- data/lib/generators/boring/ci/github_action/install/templates/ci.yml.tt +1 -11
- data/lib/generators/boring/devise/install/install_generator.rb +12 -10
- data/lib/generators/boring/font_awesome/ruby_gem/install/install_generator.rb +3 -8
- data/lib/generators/boring/graphql/install/install_generator.rb +3 -7
- data/lib/generators/boring/oauth/base_generator.rb +63 -0
- data/lib/generators/boring/oauth/facebook/install/install_generator.rb +36 -0
- data/lib/generators/boring/oauth/facebook/install/templates/README +23 -0
- data/lib/generators/boring/oauth/facebook/install/templates/omniauth.rb +3 -0
- data/lib/generators/boring/oauth/facebook/install/templates/omniauth_callbacks_controller.rb +21 -0
- data/lib/generators/boring/oauth/github/install/install_generator.rb +36 -0
- data/lib/generators/boring/oauth/github/install/templates/README +23 -0
- data/lib/generators/boring/oauth/github/install/templates/omniauth_callbacks_controller.rb +21 -0
- data/lib/generators/boring/oauth/google/install/install_generator.rb +36 -0
- data/lib/generators/boring/oauth/google/install/templates/README +23 -0
- data/lib/generators/boring/oauth/google/install/templates/omniauth_callbacks_controller.rb +21 -0
- data/lib/generators/boring/oauth/twitter/install/install_generator.rb +36 -0
- data/lib/generators/boring/oauth/twitter/install/templates/README +23 -0
- data/lib/generators/boring/oauth/twitter/install/templates/omniauth_callbacks_controller.rb +21 -0
- data/lib/generators/boring/payments/stripe/install/install_generator.rb +43 -0
- data/lib/generators/boring/payments/stripe/install/templates/README +21 -0
- data/lib/generators/boring/payments/stripe/install/templates/controllers/stripe/checkouts_controller.rb +63 -0
- data/lib/generators/boring/payments/stripe/install/templates/stripe.rb +1 -0
- data/lib/generators/boring/payments/stripe/install/templates/views/stripe/checkouts/create.js.erb +13 -0
- data/lib/generators/boring/payments/stripe/install/templates/views/stripe/checkouts/show.html.erb +8 -0
- data/lib/generators/boring/pry/install/install_generator.rb +4 -9
- data/lib/generators/boring/pundit/install/install_generator.rb +3 -9
- data/lib/generators/boring/rubocop/install/install_generator.rb +3 -1
- data/lib/generators/boring/simple_form/install/install_generator.rb +4 -8
- data/lib/generators/boring/tailwind/install/install_generator.rb +12 -11
- data/lib/generators/boring/tailwind/install/templates/README +13 -0
- data/lib/generators/boring/twilio/install/install_generator.rb +26 -0
- data/lib/generators/boring/twilio/install/templates/README +11 -0
- data/lib/generators/boring/twilio/install/templates/twilio.rb +4 -0
- metadata +33 -664
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
module Boring
|
6
|
+
module Ahoy
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
desc "Adds Ahoy to the application"
|
9
|
+
source_root File.expand_path("templates", __dir__)
|
10
|
+
|
11
|
+
def add_twitter_omniauth_gem
|
12
|
+
say "Adding Ahoy gem", :green
|
13
|
+
Bundler.with_unbundled_env do
|
14
|
+
run "bundle add ahoy_matey"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def run_ahoy_generator
|
19
|
+
say "Running Ahoy generator", :green
|
20
|
+
Bundler.with_unbundled_env do
|
21
|
+
run "bundle exec rails generate ahoy:install"
|
22
|
+
run "bundle exec rails db:migrate"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def show_readme
|
27
|
+
readme "README"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
===============================================================================
|
2
|
+
|
3
|
+
Some setup you must do manually based on your project requirement:
|
4
|
+
|
5
|
+
1. To prevent Rails actions from tracking visits: `skip_before_action :track_ahoy_visit`
|
6
|
+
2. To associate and add association in the model with ahoy. Add `visitable :ahoy_visit` in the model.
|
7
|
+
|
8
|
+
You could find more configuration options on Ahoy documentation: https://github.com/ankane/ahoy
|
9
|
+
|
10
|
+
===============================================================================
|
@@ -7,15 +7,18 @@ module Boring
|
|
7
7
|
|
8
8
|
def add_bullet_gem
|
9
9
|
say "Adding audit gems", :green
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
|
11
|
+
Bundler.with_unbundled_env do
|
12
|
+
audit_gems_content = <<~RUBY
|
13
|
+
\n
|
14
|
+
\t# Patch-level verification for Bundler. https://github.com/rubysec/bundler-audit
|
15
|
+
\tgem "bundler-audit", require: false
|
16
|
+
\t# vulnerabity checker for Ruby itself. https://github.com/civisanalytics/ruby_audit
|
17
|
+
\tgem "ruby_audit", require: false
|
18
|
+
RUBY
|
19
|
+
insert_into_file "Gemfile", audit_gems_content, after: /group :development do/
|
20
|
+
run "bundle install"
|
21
|
+
end
|
19
22
|
end
|
20
23
|
end
|
21
24
|
end
|
@@ -10,14 +10,10 @@ module Boring
|
|
10
10
|
desc: "Skips adding bullet development configuration"
|
11
11
|
|
12
12
|
def add_bullet_gem
|
13
|
-
say "Adding
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
\tgem "bullet"
|
18
|
-
RUBY
|
19
|
-
insert_into_file "Gemfile", bullet_gem_content, after: /group :development do/
|
20
|
-
run "bundle install"
|
13
|
+
say "Adding bullet gem", :green
|
14
|
+
Bundler.with_unbundled_env do
|
15
|
+
run "bundle add bullet --group development"
|
16
|
+
end
|
21
17
|
end
|
22
18
|
|
23
19
|
def add_bullet_gem_configuration
|
@@ -7,12 +7,14 @@ module Boring
|
|
7
7
|
desc "Adds Github Action to the application"
|
8
8
|
source_root File.expand_path("templates", __dir__)
|
9
9
|
|
10
|
-
|
10
|
+
RUBY_VERSION_FILE = ".ruby-version"
|
11
|
+
|
12
|
+
DEFAULT_RUBY_VERSION = ".ruby-version"
|
11
13
|
DEFAULT_NODE_VERSION = "10.13.0"
|
12
14
|
DEFAULT_REPOSITORY_NAME = "boring_generators"
|
13
15
|
|
14
16
|
class_option :ruby_version, type: :string, aliases: "-v",
|
15
|
-
desc: "Tell us the ruby version which you use for the application. Default to Ruby #{DEFAULT_RUBY_VERSION}"
|
17
|
+
desc: "Tell us the ruby version which you use for the application. Default to Ruby #{DEFAULT_RUBY_VERSION}, which will cause the action to use the version specified in the #{RUBY_VERSION_FILE} file."
|
16
18
|
class_option :node_version, type: :string, aliases: "-v",
|
17
19
|
desc: "Tell us the node version which you use for the application. Default to Node #{DEFAULT_NODE_VERSION}"
|
18
20
|
class_option :repository_name, type: :string, aliases: "-rn",
|
@@ -24,6 +26,18 @@ module Boring
|
|
24
26
|
@repository_name = options[:repository_name] ? options[:repository_name] : DEFAULT_REPOSITORY_NAME
|
25
27
|
|
26
28
|
template("ci.yml", ".github/workflows/ci.yml")
|
29
|
+
|
30
|
+
if @ruby_version == DEFAULT_RUBY_VERSION && !ruby_version_file_exists?
|
31
|
+
say <<~WARNING, :red
|
32
|
+
WARNING: The action was configured to use the ruby version specified in the .ruby-version
|
33
|
+
file, but no such file was present. Either create an appropriate .ruby-version file, or
|
34
|
+
update .github/workflows/ci.yml to use an explicit ruby version.
|
35
|
+
WARNING
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def ruby_version_file_exists?
|
40
|
+
Pathname.new(destination_root).join(RUBY_VERSION_FILE).exist?
|
27
41
|
end
|
28
42
|
end
|
29
43
|
end
|
@@ -20,17 +20,7 @@ jobs:
|
|
20
20
|
uses: ruby/setup-ruby@v1
|
21
21
|
with:
|
22
22
|
ruby-version: <%= @ruby_version %>
|
23
|
-
|
24
|
-
uses: actions/cache@v1
|
25
|
-
with:
|
26
|
-
path: vendor/bundle
|
27
|
-
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
28
|
-
restore-keys: |
|
29
|
-
${{ runner.os }}-gems-
|
30
|
-
- name: Install gems
|
31
|
-
run: |
|
32
|
-
bundle config path vendor/bundle
|
33
|
-
bundle install --jobs 4 --retry 3
|
23
|
+
bundler-cache: true
|
34
24
|
- name: Setup Node
|
35
25
|
uses: actions/setup-node@v1
|
36
26
|
with:
|
@@ -16,18 +16,16 @@ module Boring
|
|
16
16
|
|
17
17
|
def add_devise_gem
|
18
18
|
say "Adding devise gem", :green
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
gem 'devise', '~> 4.7'
|
23
|
-
RUBY
|
24
|
-
append_to_file "Gemfile", devise_gem
|
25
|
-
run "bundle install"
|
19
|
+
Bundler.with_unbundled_env do
|
20
|
+
run "bundle add devise"
|
21
|
+
end
|
26
22
|
end
|
27
23
|
|
28
24
|
def generating_devise_defaults
|
29
25
|
say "Generating devise defaults", :green
|
30
|
-
|
26
|
+
Bundler.with_unbundled_env do
|
27
|
+
run "DISABLE_SPRING=1 bundle exec rails generate devise:install"
|
28
|
+
end
|
31
29
|
end
|
32
30
|
|
33
31
|
def add_devise_action_mailer_development_config
|
@@ -44,7 +42,9 @@ module Boring
|
|
44
42
|
say "Adding devise user model", :green
|
45
43
|
model_name = options[:model_name] || DEFAULT_DEVISE_MODEL_NAME
|
46
44
|
|
47
|
-
|
45
|
+
Bundler.with_unbundled_env do
|
46
|
+
run "DISABLE_SPRING=1 bundle exec rails generate devise #{model_name}"
|
47
|
+
end
|
48
48
|
end
|
49
49
|
|
50
50
|
def add_devise_authentication_filter_to_application_controller
|
@@ -60,7 +60,9 @@ module Boring
|
|
60
60
|
say "Adding devise views", :green
|
61
61
|
model_name = options[:model_name] || DEFAULT_DEVISE_MODEL_NAME
|
62
62
|
|
63
|
-
|
63
|
+
Bundler.with_unbundled_env do
|
64
|
+
run "DISABLE_SPRING=1 bundle exec rails generate devise:views #{model_name.pluralize}"
|
65
|
+
end
|
64
66
|
end
|
65
67
|
end
|
66
68
|
end
|
@@ -8,14 +8,9 @@ module Boring
|
|
8
8
|
|
9
9
|
def add_font_awesome_sass_gem
|
10
10
|
say "Adding font_awesome_sass gem", :green
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# for adding font-awesome icons
|
15
|
-
gem 'font-awesome-sass', '~> 5.13'
|
16
|
-
RUBY
|
17
|
-
append_to_file "Gemfile", font_awesome_sass_gem
|
18
|
-
run "bundle install"
|
11
|
+
Bundler.with_unbundled_env do
|
12
|
+
run "bundle add font-awesome-sass"
|
13
|
+
end
|
19
14
|
end
|
20
15
|
|
21
16
|
def import_font_awesome_stylesheet
|
@@ -13,13 +13,9 @@ module Boring
|
|
13
13
|
|
14
14
|
def add_graphql_gem
|
15
15
|
say "Adding graphql gem", :green
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
gem 'graphql', '~> 1.11'
|
20
|
-
RUBY
|
21
|
-
append_to_file "Gemfile", graphql_gem
|
22
|
-
run "bundle install"
|
16
|
+
Bundler.with_unbundled_env do
|
17
|
+
run "bundle add graphql"
|
18
|
+
end
|
23
19
|
end
|
24
20
|
|
25
21
|
def run_graphql_generator
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
module Boring
|
6
|
+
module Oauth
|
7
|
+
module BaseGenerator
|
8
|
+
def add_provider_and_uuid_user_details
|
9
|
+
say "Adding migration to add provider and uuid columns to users", :green
|
10
|
+
Bundler.with_unbundled_env do
|
11
|
+
run "DISABLE_SPRING=1 bundle exec rails generate migration AddOmniauthToUsers provider:string uid:string"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure_devise_omniauth
|
16
|
+
say "Adding omniauth devise configuration", :green
|
17
|
+
if File.exist?("config/initializers/devise.rb")
|
18
|
+
insert_into_file "config/initializers/devise.rb", <<~RUBY, after: /Devise.setup do \|config\|/
|
19
|
+
\n
|
20
|
+
\tconfig.omniauth :#{@oauth_name}, "APP_ID", "APP_SECRET"
|
21
|
+
RUBY
|
22
|
+
else
|
23
|
+
raise MissingDeviseConfigurationError, <<~ERROR
|
24
|
+
Looks like the devise installation is incomplete. Could not find devise.rb in config/initializers.
|
25
|
+
ERROR
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_omniauth_callback_routes
|
30
|
+
devise_route = '# devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }'.dup
|
31
|
+
route devise_route
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_omniauth_callback_controller
|
35
|
+
say "Copying omniauth_callbacks_controller.rb", :green
|
36
|
+
template("omniauth_callbacks_controller.rb", "app/controllers/users/omniauth_callbacks_controller.rb")
|
37
|
+
end
|
38
|
+
|
39
|
+
def configure_and_add_devise_setting_in_user_model
|
40
|
+
say "Configuring #{@oauth_name.to_s} omniauth for user model", :green
|
41
|
+
insert_into_file "app/models/user.rb", <<~RUBY, after: /class User < ApplicationRecord/
|
42
|
+
\n\tdevise :omniauthable, omniauth_providers: %i[#{@oauth_name}]
|
43
|
+
|
44
|
+
\tdef self.from_omniauth(auth)
|
45
|
+
\twhere(provider: auth.provider, uid: auth.uid).first_or_create do |user|
|
46
|
+
\tuser.email = auth.info.email
|
47
|
+
\tuser.password = Devise.friendly_token[0, 20]
|
48
|
+
\t# user.name = auth.info.name # assuming the user model has a name
|
49
|
+
\t# user.image = auth.info.image # assuming the user model has an image
|
50
|
+
\t# If you are using confirmable and the provider(s) you use validate emails,
|
51
|
+
\t# uncomment the line below to skip the confirmation emails.
|
52
|
+
\t# user.skip_confirmation!
|
53
|
+
\tend
|
54
|
+
\tend
|
55
|
+
RUBY
|
56
|
+
end
|
57
|
+
|
58
|
+
def show_readme
|
59
|
+
readme "README"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
require 'generators/boring/oauth/base_generator'
|
5
|
+
|
6
|
+
module Boring
|
7
|
+
module Oauth
|
8
|
+
module Facebook
|
9
|
+
class InstallGenerator < Rails::Generators::Base
|
10
|
+
include Boring::Oauth::BaseGenerator
|
11
|
+
|
12
|
+
class MissingDeviseConfigurationError < StandardError; end
|
13
|
+
|
14
|
+
desc "Adds facebook OmniAuth to the application"
|
15
|
+
source_root File.expand_path("templates", __dir__)
|
16
|
+
|
17
|
+
def add_facebook_omniauth_gem
|
18
|
+
say "Adding Facebook OmniAuth gem", :green
|
19
|
+
Bundler.with_unbundled_env do
|
20
|
+
run "bundle add omniauth-facebook"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def invoke_common_generator_methods
|
25
|
+
@oauth_name = :facebook
|
26
|
+
add_provider_and_uuid_user_details
|
27
|
+
configure_devise_omniauth
|
28
|
+
add_omniauth_callback_routes
|
29
|
+
add_omniauth_callback_controller
|
30
|
+
configure_and_add_devise_setting_in_user_model
|
31
|
+
show_readme
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
===============================================================================
|
2
|
+
|
3
|
+
Some setup you must do manually if you haven't yet:
|
4
|
+
|
5
|
+
1. Ensure you have overridden or uncommented the routes for generated omniauth callback controllers in your routes.rb.
|
6
|
+
For example:
|
7
|
+
|
8
|
+
Rails.application.routes.draw do
|
9
|
+
devise_for :users, controllers: {
|
10
|
+
omniauth_callbacks: "users/omniauth_callbacks"
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
2. Update the devise facebook omniauth APP_ID and APP_SECRET in "config/initializers/devise.rb"
|
15
|
+
after registering the Rails application on: https://developers.facebook.com/apps/
|
16
|
+
For example:
|
17
|
+
|
18
|
+
config.omniauth :facebook, "APP_ID", "APP_SECRET"
|
19
|
+
|
20
|
+
3. Your omniauth callback URL will be: `<host>/users/auth/facebook/callback`. Please update
|
21
|
+
callback URL in Facebook after registering your omniauth application.
|
22
|
+
|
23
|
+
===============================================================================
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
2
|
+
# See https://github.com/omniauth/omniauth/wiki/FAQ#rails-session-is-clobbered-after-callback-on-developer-strategy
|
3
|
+
skip_before_action :verify_authenticity_token, only: :facebook
|
4
|
+
|
5
|
+
def facebook
|
6
|
+
# You need to implement the method below in your model (e.g. app/models/user.rb)
|
7
|
+
@user = User.from_omniauth(request.env["omniauth.auth"])
|
8
|
+
|
9
|
+
if @user.persisted?
|
10
|
+
sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated
|
11
|
+
set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format?
|
12
|
+
else
|
13
|
+
session["devise.facebook_data"] = request.env["omniauth.auth"].except(:extra) # Removing extra as it can overflow some session stores
|
14
|
+
redirect_to new_user_registration_url
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def failure
|
19
|
+
redirect_to root_path
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
require 'generators/boring/oauth/base_generator'
|
5
|
+
|
6
|
+
module Boring
|
7
|
+
module Oauth
|
8
|
+
module Github
|
9
|
+
class InstallGenerator < Rails::Generators::Base
|
10
|
+
include Boring::Oauth::BaseGenerator
|
11
|
+
|
12
|
+
class MissingDeviseConfigurationError < StandardError; end
|
13
|
+
|
14
|
+
desc "Adds GitHub OmniAuth to the application"
|
15
|
+
source_root File.expand_path("templates", __dir__)
|
16
|
+
|
17
|
+
def add_github_omniauth_gem
|
18
|
+
say "Adding GitHub OmniAuth gem", :green
|
19
|
+
Bundler.with_unbundled_env do
|
20
|
+
run "bundle add omniauth-github"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def invoke_common_generator_methods
|
25
|
+
@oauth_name = :github
|
26
|
+
add_provider_and_uuid_user_details
|
27
|
+
configure_devise_omniauth
|
28
|
+
add_omniauth_callback_routes
|
29
|
+
add_omniauth_callback_controller
|
30
|
+
configure_and_add_devise_setting_in_user_model
|
31
|
+
show_readme
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
===============================================================================
|
2
|
+
|
3
|
+
Some setup you must do manually if you haven't yet:
|
4
|
+
|
5
|
+
1. Ensure you have overridden or uncommented the routes for generated omniauth callback controllers in your routes.rb.
|
6
|
+
For example:
|
7
|
+
|
8
|
+
Rails.application.routes.draw do
|
9
|
+
devise_for :users, controllers: {
|
10
|
+
omniauth_callbacks: "users/omniauth_callbacks"
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
2. Update the devise github omniauth APP_ID and APP_SECRET in "config/initializers/devise.rb"
|
15
|
+
after registering the Rails application on: https://github.com/settings/applications/new
|
16
|
+
For example:
|
17
|
+
|
18
|
+
config.omniauth :github, "APP_ID", "APP_SECRET"
|
19
|
+
|
20
|
+
3. Your omniauth callback URL will be: `<host>/users/auth/github/callback`. Please update
|
21
|
+
callback URL in Github after registering your omniauth application.
|
22
|
+
|
23
|
+
===============================================================================
|