boring_generators 0.4.0 → 0.9.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/FUNDING.yml +12 -0
- data/.github/workflows/ci.yml +8 -2
- data/CHANGELOG.md +27 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +94 -21
- data/README.md +32 -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/ahoy/install/install_generator.rb +31 -0
- data/lib/generators/boring/ahoy/install/templates/README +10 -0
- data/lib/generators/boring/bootstrap/install/install_generator.rb +2 -2
- data/lib/generators/boring/ci/github_action/install/install_generator.rb +18 -4
- data/lib/generators/boring/ci/github_action/install/templates/ci.yml.tt +1 -11
- data/lib/generators/boring/devise/install/install_generator.rb +75 -0
- data/lib/generators/boring/favicon/build/build_generator.rb +120 -0
- data/lib/generators/boring/favicon/build/templates/favicon.html.erb.tt +19 -0
- data/lib/generators/boring/graphql/install/install_generator.rb +51 -0
- data/lib/generators/boring/graphql/install/templates/base_resolver.rb +2 -0
- data/lib/generators/boring/graphql/install/templates/hello_world_resolver.rb +11 -0
- data/lib/generators/boring/oauth/base_generator.rb +63 -0
- data/lib/generators/boring/oauth/facebook/install/install_generator.rb +42 -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 +42 -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 +44 -0
- data/lib/generators/boring/payments/stripe/install/templates/README +14 -0
- data/lib/generators/boring/payments/stripe/install/templates/controllers/charges_controller.rb +38 -0
- data/lib/generators/boring/payments/stripe/install/templates/stripe.rb +6 -0
- data/lib/generators/boring/payments/stripe/install/templates/views/charges.html.erb +7 -0
- data/lib/generators/boring/payments/stripe/install/templates/views/create.html.erb +1 -0
- data/lib/generators/boring/payments/stripe/install/templates/views/new.html.erb +19 -0
- data/lib/generators/boring/pundit/install/install_generator.rb +85 -0
- data/lib/generators/boring/simple_form/install/install_generator.rb +44 -0
- 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 +30 -0
- data/lib/generators/boring/twilio/install/templates/README +11 -0
- data/lib/generators/boring/twilio/install/templates/twilio.rb +4 -0
- metadata +42 -665
- data/.travis.yml +0 -6
@@ -7,16 +7,18 @@ 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
|
-
desc: "Tell us the node version which you use for the application. Default to
|
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",
|
19
|
-
desc: "Tell us the repository name to be used as database name on
|
21
|
+
desc: "Tell us the repository name to be used as database name on GitHub Actions. Defaults to #{DEFAULT_REPOSITORY_NAME}"
|
20
22
|
|
21
23
|
def add_github_actions_configuration
|
22
24
|
@ruby_version = options[:ruby_version] ? options[:ruby_version] : DEFAULT_RUBY_VERSION
|
@@ -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:
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boring
|
4
|
+
module Devise
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Adds devise to the application"
|
7
|
+
|
8
|
+
DEFAULT_DEVISE_MODEL_NAME = "User"
|
9
|
+
|
10
|
+
class_option :model_name, type: :string, aliases: "-m",
|
11
|
+
desc: "Tell us the user model name which will be used for authentication. Defaults to #{DEFAULT_DEVISE_MODEL_NAME}"
|
12
|
+
class_option :skip_devise_view, type: :boolean, aliases: "-sv",
|
13
|
+
desc: "Skip generating devise views"
|
14
|
+
class_option :skip_devise_model, type: :boolean, aliases: "-sm",
|
15
|
+
desc: "Skip generating devise model"
|
16
|
+
|
17
|
+
def add_devise_gem
|
18
|
+
say "Adding devise gem", :green
|
19
|
+
devise_gem = <<~RUBY
|
20
|
+
\n
|
21
|
+
# for authentication
|
22
|
+
gem 'devise', '~> 4.7'
|
23
|
+
RUBY
|
24
|
+
append_to_file "Gemfile", devise_gem
|
25
|
+
Bundler.with_unbundled_env do
|
26
|
+
run "bundle install"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def generating_devise_defaults
|
31
|
+
say "Generating devise defaults", :green
|
32
|
+
Bundler.with_unbundled_env do
|
33
|
+
run "DISABLE_SPRING=1 bundle exec rails generate devise:install"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_devise_action_mailer_development_config
|
38
|
+
say "Adding devise Action Mailer development configuration", :green
|
39
|
+
insert_into_file "config/environments/development.rb", <<~RUBY, after: /Rails.application.configure do/
|
40
|
+
\n
|
41
|
+
\tconfig.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
42
|
+
RUBY
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_devise_user_model
|
46
|
+
return if options[:skip_devise_model]
|
47
|
+
|
48
|
+
say "Adding devise user model", :green
|
49
|
+
model_name = options[:model_name] || DEFAULT_DEVISE_MODEL_NAME
|
50
|
+
|
51
|
+
Bundler.with_unbundled_env do
|
52
|
+
run "DISABLE_SPRING=1 bundle exec rails generate devise #{model_name}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_devise_authentication_filter_to_application_controller
|
57
|
+
insert_into_file "app/controllers/application_controller.rb", <<~RUBY, after: /class ApplicationController < ActionController::Base/
|
58
|
+
\n
|
59
|
+
\tbefore_action :authenticate_user!
|
60
|
+
RUBY
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_devise_views
|
64
|
+
return if options[:skip_devise_view]
|
65
|
+
|
66
|
+
say "Adding devise views", :green
|
67
|
+
model_name = options[:model_name] || DEFAULT_DEVISE_MODEL_NAME
|
68
|
+
|
69
|
+
Bundler.with_unbundled_env do
|
70
|
+
run "DISABLE_SPRING=1 bundle exec rails generate devise:views #{model_name.pluralize}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boring
|
4
|
+
module Favicon
|
5
|
+
class BuildGenerator < Rails::Generators::Base
|
6
|
+
desc "Build favicons for all platforms"
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
ICO_SIZES = %w(16 32)
|
10
|
+
APPLE_SIZES = %w(57 60 72 76 114 120 129 144 152)
|
11
|
+
APPLE_PRECOMPOSED_SIZES = %w(120 129 152)
|
12
|
+
SMALL_BREAK = 50
|
13
|
+
LARGE_BREAK = 150
|
14
|
+
MS_TILE_SIZES = %w(144)
|
15
|
+
FAVICON_DIR = "favicons"
|
16
|
+
FILE_FAVICO_DIR = "app/assets/images/#{FAVICON_DIR}"
|
17
|
+
DEFAULT_PRIMARY_COLOR = "#082472"
|
18
|
+
DEFAULT_FAVICON_LETTER = "B" # B for boring_generators :)
|
19
|
+
DEFAULT_IMAGE_PATH = "#{FILE_FAVICO_DIR}/template.png"
|
20
|
+
|
21
|
+
class_option :primary_color, type: :string, aliases: "-color",
|
22
|
+
desc: "Tell us the primary color to build favicon. Default to primary: #{DEFAULT_PRIMARY_COLOR}"
|
23
|
+
class_option :favico_letter, type: :string, aliases: "-letter",
|
24
|
+
desc: "Tell us the favicon letter to build favicon. Default to primary: #{DEFAULT_FAVICON_LETTER}"
|
25
|
+
class_option :font_file_path, type: :string, aliases: "-fp",
|
26
|
+
desc: "Tell us the font to be used generate favicon."
|
27
|
+
class_option :application_name, type: :string, aliases: "-app_name",
|
28
|
+
desc: "Tell us the application name to be used in favicon partial."
|
29
|
+
|
30
|
+
def build_favicon
|
31
|
+
@application_name = options[:application_name]
|
32
|
+
@primary_color = options[:primary_color]
|
33
|
+
|
34
|
+
unless /Version/m =~ (`convert -version`)
|
35
|
+
say <<~WARNING, :red
|
36
|
+
ERROR: You do not have ImageMagick installed.
|
37
|
+
WARNING
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_favicon_directory
|
42
|
+
unless File.exists?(FILE_FAVICO_DIR)
|
43
|
+
Dir.mkdir FILE_FAVICO_DIR
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def build_favicon_for_existing_template_image
|
48
|
+
return unless File.exist?(DEFAULT_IMAGE_PATH)
|
49
|
+
|
50
|
+
say "Converting template image to favicons..."
|
51
|
+
template_name = "#{FILE_FAVICO_DIR}/template.png"
|
52
|
+
template_small_name = "#{FILE_FAVICO_DIR}/template-small.png"
|
53
|
+
template_large_name = "#{FILE_FAVICO_DIR}/template-large.png"
|
54
|
+
template_small_name = template_name unless File.file?(template_small_name)
|
55
|
+
template_large_name = template_name unless File.file?(template_large_name)
|
56
|
+
ICO_SIZES.each do |size|
|
57
|
+
ico_template = template_name
|
58
|
+
ico_template = template_small_name if size.to_i <= SMALL_BREAK
|
59
|
+
ico_template = template_small_name if size.to_i >= LARGE_BREAK
|
60
|
+
(`convert #{ico_template} -resize #{size}x#{size} #{FILE_FAVICO_DIR}/favicon-#{size}x#{size}.ico`)
|
61
|
+
end
|
62
|
+
APPLE_SIZES.each do |size|
|
63
|
+
ico_template = template_name
|
64
|
+
ico_template = template_small_name if size.to_i <= SMALL_BREAK
|
65
|
+
ico_template = template_small_name if size.to_i >= LARGE_BREAK
|
66
|
+
(`convert #{ico_template} -resize #{size}x#{size} #{FILE_FAVICO_DIR}/apple-touch-icon-#{size}x#{size}.png`)
|
67
|
+
end
|
68
|
+
APPLE_PRECOMPOSED_SIZES.each do |size|
|
69
|
+
ico_template = template_name
|
70
|
+
ico_template = template_small_name if size.to_i <= SMALL_BREAK
|
71
|
+
ico_template = template_small_name if size.to_i >= LARGE_BREAK
|
72
|
+
(`convert #{ico_template} -resize #{size}x#{size} #{FILE_FAVICO_DIR}/apple-touch-icon-#{size}x#{size}-precomposed.png`)
|
73
|
+
end
|
74
|
+
MS_TILE_SIZES.each do |size|
|
75
|
+
ico_template = template_name
|
76
|
+
ico_template = template_small_name if size.to_i <= SMALL_BREAK
|
77
|
+
ico_template = template_small_name if size.to_i >= LARGE_BREAK
|
78
|
+
(`convert #{ico_template} -resize #{size}x#{size} #{FILE_FAVICO_DIR}/mstile-#{size}x#{size}.png`)
|
79
|
+
end
|
80
|
+
ico_template = template_name
|
81
|
+
ico_template = template_small_name if 152 <= SMALL_BREAK
|
82
|
+
ico_template = template_small_name if 152 >= LARGE_BREAK
|
83
|
+
(`convert #{ico_template} -resize 152x152 #{FILE_FAVICO_DIR}/apple-touch-icon.png`)
|
84
|
+
(`convert #{ico_template} -resize 152x152 #{FILE_FAVICO_DIR}/apple-touch-icon-precomposed.png`)
|
85
|
+
end
|
86
|
+
|
87
|
+
def generate_new_favicon_using_favico_letter
|
88
|
+
return if File.exist?(DEFAULT_IMAGE_PATH)
|
89
|
+
say "Creating favicons from application...", :green
|
90
|
+
|
91
|
+
favico_letter = options[:favico_letter] || @application_name.try(:first) || DEFAULT_FAVICON_LETTER
|
92
|
+
font_file_path = options[:font_file_path]
|
93
|
+
favicon_color = options[:primary_color] || DEFAULT_PRIMARY_COLOR
|
94
|
+
|
95
|
+
ICO_SIZES.each do |size|
|
96
|
+
(`convert -background "#{favicon_color}" -fill white -size #{size}x#{size} -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/favicon-#{size}x#{size}.ico`)
|
97
|
+
end
|
98
|
+
APPLE_SIZES.each do |size|
|
99
|
+
(`convert -background "#{favicon_color}" -fill white -size #{size}x#{size} -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/apple-touch-icon-#{size}x#{size}.png`)
|
100
|
+
end
|
101
|
+
APPLE_PRECOMPOSED_SIZES.each do |size|
|
102
|
+
(`convert -background "#{favicon_color}" -fill white -size #{size}x#{size} -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/apple-touch-icon-#{size}x#{size}-precomposed.png`)
|
103
|
+
end
|
104
|
+
MS_TILE_SIZES.each do |size|
|
105
|
+
(`convert -background "#{favicon_color}" -fill white -size #{size}x#{size} -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/mstile-#{size}x#{size}.png`)
|
106
|
+
end
|
107
|
+
(`convert -background "#{favicon_color}" -fill white -size 152x152 -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/apple-touch-icon.png`)
|
108
|
+
(`convert -background "#{favicon_color}" -fill white -size 152x152 -gravity center #{font_file_path ? "-font #{font_file_path}" : ""} label:#{favico_letter} #{FILE_FAVICO_DIR}/apple-touch-icon-precomposed.png`)
|
109
|
+
end
|
110
|
+
|
111
|
+
def add_favicon_partial
|
112
|
+
say "Copying favicon layout partial", :green
|
113
|
+
template("favicon.html.erb", "app/views/layouts/shared/_favicon.html.erb")
|
114
|
+
insert_into_file "app/views/layouts/application.html.erb", <<~RUBY, after: /head.*\n/
|
115
|
+
\t\t<%= render 'layouts/shared/favicon' %>
|
116
|
+
RUBY
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<%%= favicon_link_tag "favicons/favicon-16x16.ico", rel: 'shortcut icon', type: 'image/x-icon' %>
|
2
|
+
<%%= favicon_link_tag "favicons/favicon-32x32.ico", rel: 'shortcut icon', type: 'image/x-icon' %>
|
3
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon-57x57.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "57x57" %>
|
4
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon-60x60.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "60x60" %>
|
5
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon-72x72.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "72x72" %>
|
6
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon-76x76.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "76x76" %>
|
7
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon-114x114.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "114x114" %>
|
8
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon-120x120.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "120x120" %>
|
9
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon-129x129.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "129x129" %>
|
10
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon-144x144.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "144x144" %>
|
11
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon-152x152.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "152x152" %>
|
12
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon.png", rel: 'apple-touch-icon', type: 'image/png' %>
|
13
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon-120x120-precomposed.png", rel: 'apple-touch-icon-precomposed', type: 'image/png', sizes: "120x120" %>
|
14
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon-129x129-precomposed.png", rel: 'apple-touch-icon-precomposed', type: 'image/png', sizes: "129x129" %>
|
15
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon-152x152-precomposed.png", rel: 'apple-touch-icon-precomposed', type: 'image/png', sizes: "152x152" %>
|
16
|
+
<%%= favicon_link_tag "favicons/apple-touch-icon-precomposed.png", rel: 'apple-touch-icon-precomposed', type: 'image/png' %>
|
17
|
+
<meta name="msapplication-TileImage" content="<%%= image_path("favicons/mstile-144x144.png") %>" />
|
18
|
+
<meta name="msapplication-TileColor" content="<%= @primary_color %>" />
|
19
|
+
<meta name="application-name" content="<%= @application_name %>">
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Boring
|
4
|
+
module Graphql
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Adds GraphQL to the application"
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
OPTIONS = %w(relay batch playground no-graphiql schema)
|
10
|
+
|
11
|
+
class_option :skip_resolver_setup, type: :boolean, aliases: "-s",
|
12
|
+
desc: "Skips adding GraphQL resolver setup to the application"
|
13
|
+
|
14
|
+
def add_graphql_gem
|
15
|
+
say "Adding graphql gem", :green
|
16
|
+
graphql_gem = <<~RUBY
|
17
|
+
\n
|
18
|
+
# for building APIs
|
19
|
+
gem 'graphql', '~> 1.11'
|
20
|
+
RUBY
|
21
|
+
append_to_file "Gemfile", graphql_gem
|
22
|
+
run "bundle install"
|
23
|
+
end
|
24
|
+
|
25
|
+
def run_graphql_generator
|
26
|
+
say "Running GraphQL default generator", :green
|
27
|
+
run "bundle exec rails generate graphql:install"
|
28
|
+
run "bundle install"
|
29
|
+
|
30
|
+
graphiql_precompile_assets = <<~RUBY
|
31
|
+
\n
|
32
|
+
if Rails.env.development?
|
33
|
+
Rails.application.config.assets.precompile += %w[graphiql/rails/application.js graphiql/rails/application.css]
|
34
|
+
end
|
35
|
+
RUBY
|
36
|
+
append_to_file "config/initializers/assets.rb", graphiql_precompile_assets
|
37
|
+
end
|
38
|
+
|
39
|
+
def adds_graphql_resolver
|
40
|
+
return if options[:skip_resolver_setup]
|
41
|
+
template("base_resolver.rb", "app/graphql/resolvers/base_resolver.rb")
|
42
|
+
template("hello_world_resolver.rb", "app/graphql/resolvers/hello_world_resolver.rb")
|
43
|
+
|
44
|
+
insert_into_file "app/graphql/types/query_type.rb", <<~RUBY, after: /class QueryType < Types::BaseObject\n/
|
45
|
+
\t\t# TODO: remove me
|
46
|
+
\t\tfield :hello, resolver: Resolvers::HelloWorldResolver
|
47
|
+
RUBY
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -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,42 @@
|
|
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
|
+
facebook_omniauth_gem = <<~RUBY
|
20
|
+
\n
|
21
|
+
# for omniauth facebook
|
22
|
+
gem 'omniauth-facebook', '~> 8.0'
|
23
|
+
RUBY
|
24
|
+
append_to_file "Gemfile", facebook_omniauth_gem
|
25
|
+
Bundler.with_unbundled_env do
|
26
|
+
run "bundle install"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def invoke_common_generator_methods
|
31
|
+
@oauth_name = :facebook
|
32
|
+
add_provider_and_uuid_user_details
|
33
|
+
configure_devise_omniauth
|
34
|
+
add_omniauth_callback_routes
|
35
|
+
add_omniauth_callback_controller
|
36
|
+
configure_and_add_devise_setting_in_user_model
|
37
|
+
show_readme
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|