boring_generators 0.3.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +12 -0
  3. data/.github/workflows/ci.yml +23 -0
  4. data/CHANGELOG.md +31 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +150 -0
  7. data/README.md +47 -7
  8. data/Rakefile +1 -0
  9. data/boring_generators.gemspec +2 -0
  10. data/exe/boring +5 -0
  11. data/lib/boring_generators.rb +1 -0
  12. data/lib/boring_generators/cli.rb +26 -0
  13. data/lib/boring_generators/version.rb +1 -1
  14. data/lib/generators/boring/bootstrap/install/install_generator.rb +2 -2
  15. data/lib/generators/boring/ci/circleci/install/install_generator.rb +31 -0
  16. data/lib/generators/boring/ci/circleci/install/templates/config.psql.yml.tt +48 -0
  17. data/lib/generators/boring/ci/circleci/install/templates/config.sql.yml.tt +48 -0
  18. data/lib/generators/boring/ci/circleci/install/templates/database.yml.ci.tt +14 -0
  19. data/lib/generators/boring/ci/github_action/install/install_generator.rb +45 -0
  20. data/lib/generators/boring/ci/github_action/install/templates/ci.yml.tt +49 -0
  21. data/lib/generators/boring/ci/travisci/install/install_generator.rb +23 -0
  22. data/lib/generators/boring/ci/travisci/install/templates/.travis.yml.tt +35 -0
  23. data/lib/generators/boring/devise/install/install_generator.rb +75 -0
  24. data/lib/generators/boring/favicon/build/build_generator.rb +120 -0
  25. data/lib/generators/boring/favicon/build/templates/favicon.html.erb.tt +19 -0
  26. data/lib/generators/boring/graphql/install/install_generator.rb +51 -0
  27. data/lib/generators/boring/graphql/install/templates/base_resolver.rb +2 -0
  28. data/lib/generators/boring/graphql/install/templates/hello_world_resolver.rb +11 -0
  29. data/lib/generators/boring/oauth/base_generator.rb +63 -0
  30. data/lib/generators/boring/oauth/facebook/install/install_generator.rb +42 -0
  31. data/lib/generators/boring/oauth/facebook/install/templates/README +20 -0
  32. data/lib/generators/boring/oauth/facebook/install/templates/omniauth.rb +3 -0
  33. data/lib/generators/boring/oauth/facebook/install/templates/omniauth_callbacks_controller.rb +21 -0
  34. data/lib/generators/boring/oauth/github/install/install_generator.rb +42 -0
  35. data/lib/generators/boring/oauth/github/install/templates/README +20 -0
  36. data/lib/generators/boring/oauth/github/install/templates/omniauth_callbacks_controller.rb +21 -0
  37. data/lib/generators/boring/oauth/google/install/install_generator.rb +36 -0
  38. data/lib/generators/boring/oauth/google/install/templates/README +20 -0
  39. data/lib/generators/boring/oauth/google/install/templates/omniauth_callbacks_controller.rb +21 -0
  40. data/lib/generators/boring/oauth/twitter/install/install_generator.rb +36 -0
  41. data/lib/generators/boring/oauth/twitter/install/templates/README +20 -0
  42. data/lib/generators/boring/oauth/twitter/install/templates/omniauth_callbacks_controller.rb +21 -0
  43. data/lib/generators/boring/pundit/install/install_generator.rb +85 -0
  44. data/lib/generators/boring/rubocop/install/install_generator.rb +37 -0
  45. data/lib/generators/boring/rubocop/install/templates/.rubocop.yml.tt +262 -0
  46. data/lib/generators/boring/simple_form/install/install_generator.rb +44 -0
  47. data/lib/generators/boring/tailwind/install/install_generator.rb +13 -12
  48. data/lib/generators/boring/tailwind/install/templates/README +13 -0
  49. data/lib/generators/boring/twilio/install/install_generator.rb +30 -0
  50. data/lib/generators/boring/twilio/install/templates/README +11 -0
  51. data/lib/generators/boring/twilio/install/templates/twilio.rb +4 -0
  52. metadata +2525 -5
  53. data/.travis.yml +0 -6
@@ -0,0 +1,48 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ ruby: circleci/ruby@1.1.1
5
+ <%- unless @skip_node -%>
6
+ node: circleci/node@2
7
+ <%- end -%>
8
+
9
+ jobs:
10
+ test:
11
+ parallelism: 1
12
+ docker:
13
+ - image: cimg/ruby:<%= @ruby_version %>-node
14
+ - image: circleci/postgres:11.2
15
+ environment:
16
+ POSTGRES_USER: postgres
17
+ POSTGRES_DB: <%= "#{@repository_name}_test" %>
18
+ environment:
19
+ BUNDLE_JOBS: "3"
20
+ BUNDLE_RETRY: "3"
21
+ PGHOST: 127.0.0.1
22
+ PGUSER: postgres
23
+ RAILS_ENV: test
24
+ steps:
25
+ - checkout
26
+ - ruby/install-deps
27
+ <%- unless @skip_node -%>
28
+ # Store bundle cache
29
+ - node/install-packages:
30
+ pkg-manager: yarn
31
+ cache-key: "yarn.lock"
32
+ <%- end -%>
33
+ - run: cp config/database.yml.ci config/database.yml
34
+ - run:
35
+ name: Wait for DB
36
+ command: dockerize -wait tcp://localhost:5432 -timeout 1m
37
+ - run:
38
+ name: Database setup
39
+ command: bundle exec rails db:schema:load --trace
40
+ - run:
41
+ name: Run test
42
+ command: bundle exec rails test
43
+
44
+ workflows:
45
+ version: 2
46
+ test:
47
+ jobs:
48
+ - test
@@ -0,0 +1,48 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ ruby: circleci/ruby@1.1.1
5
+ node: circleci/node@2
6
+
7
+ jobs:
8
+ test:
9
+ parallelism: 1
10
+ docker:
11
+ - image: cimg/ruby:<%= @ruby_version %>-node
12
+ environment:
13
+ MYSQL_DATABASE: <%= @test_database_name %>
14
+ environment:
15
+ BUNDLE_JOBS: "3"
16
+ BUNDLE_RETRY: "3"
17
+ RAILS_ENV: test
18
+ steps:
19
+ - checkout
20
+ - run:
21
+ name: Waiting for MySQL to be ready
22
+ command: |
23
+ for i in `seq 1 10`;
24
+ do
25
+ nc -z 127.0.0.1 3306 && echo Success && exit 0
26
+ echo -n .
27
+ sleep 1
28
+ done
29
+ echo Failed waiting for MySQL && exit 1
30
+ - ruby/install-deps
31
+ <%- unless @skip_node -%>
32
+ # Store bundle cache
33
+ - node/install-packages:
34
+ pkg-manager: yarn
35
+ cache-key: "yarn.lock"
36
+ <%- end -%>
37
+ - run:
38
+ name: Database setup
39
+ command: bundle exec rails db:schema:load --trace
40
+ - run:
41
+ name: Run test
42
+ command: bundle exec rails test
43
+
44
+ workflows:
45
+ version: 2
46
+ test:
47
+ jobs:
48
+ - test
@@ -0,0 +1,14 @@
1
+ default: &default
2
+ adapter: postgresql
3
+ host: 127.0.0.1
4
+ encoding: unicode
5
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 10 } %>
6
+
7
+ development:
8
+ <<: *default
9
+ database: <%= "#{@repository_name}_development" %>
10
+
11
+ test:
12
+ <<: *default
13
+ user: postgres
14
+ database: <%= "#{@repository_name}_test" %>
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module Ci
5
+ module GithubAction
6
+ class InstallGenerator < Rails::Generators::Base
7
+ desc "Adds Github Action to the application"
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ RUBY_VERSION_FILE = ".ruby-version"
11
+
12
+ DEFAULT_RUBY_VERSION = ".ruby-version"
13
+ DEFAULT_NODE_VERSION = "10.13.0"
14
+ DEFAULT_REPOSITORY_NAME = "boring_generators"
15
+
16
+ class_option :ruby_version, type: :string, aliases: "-v",
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."
18
+ class_option :node_version, type: :string, aliases: "-v",
19
+ desc: "Tell us the node version which you use for the application. Default to Node #{DEFAULT_NODE_VERSION}"
20
+ class_option :repository_name, type: :string, aliases: "-rn",
21
+ desc: "Tell us the repository name to be used as database name on GitHub Actions. Defaults to #{DEFAULT_REPOSITORY_NAME}"
22
+
23
+ def add_github_actions_configuration
24
+ @ruby_version = options[:ruby_version] ? options[:ruby_version] : DEFAULT_RUBY_VERSION
25
+ @node_version = options[:node_version] ? options[:node_version] : DEFAULT_NODE_VERSION
26
+ @repository_name = options[:repository_name] ? options[:repository_name] : DEFAULT_REPOSITORY_NAME
27
+
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?
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,49 @@
1
+ name: CI
2
+ on: [push]
3
+ jobs:
4
+ test:
5
+ name: Tests
6
+ runs-on: ubuntu-latest
7
+ services:
8
+ postgres:
9
+ image: postgres:11
10
+ env:
11
+ POSTGRES_USER: <%= @repository_name %>
12
+ POSTGRES_DB: <%= "#{@repository_name}_test" %>
13
+ POSTGRES_PASSWORD: ""
14
+ ports: ["5432:5432"]
15
+
16
+ steps:
17
+ - name: Checkout code
18
+ uses: actions/checkout@v2
19
+ - name: <%= "Set up Ruby #{@ruby_version}" %>
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: <%= @ruby_version %>
23
+ bundler-cache: true
24
+ - name: Setup Node
25
+ uses: actions/setup-node@v1
26
+ with:
27
+ node-version: <%= @node_version %>
28
+ - name: Find yarn cache location
29
+ id: yarn-cache
30
+ run: echo "::set-output name=dir::$(yarn cache dir)"
31
+ - name: JS package cache
32
+ uses: actions/cache@v1
33
+ with:
34
+ path: ${{ steps.yarn-cache.outputs.dir }}
35
+ key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
36
+ restore-keys: |
37
+ ${{ runner.os }}-yarn-
38
+ - name: Install packages
39
+ run: |
40
+ yarn install --pure-lockfile
41
+ - name: Setup test database
42
+ env:
43
+ RAILS_ENV: test
44
+ PGHOST: localhost
45
+ PGUSER: <%= @repository_name %>
46
+ run: |
47
+ bin/rails db:setup
48
+ - name: Run tests
49
+ run: bundle exec rails test # TODO: Update the test runner command as per your requirement.
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module Ci
5
+ module Travisci
6
+ class InstallGenerator < Rails::Generators::Base
7
+ desc "Adds Github Action to the application"
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ DEFAULT_RUBY_VERSION = "2.7.1"
11
+
12
+ class_option :ruby_version, type: :string, aliases: "-v",
13
+ desc: "Tell us the ruby version which you use for the application. Default to Ruby #{DEFAULT_RUBY_VERSION}"
14
+
15
+ def add_github_actions_configuration
16
+ @ruby_version = options[:ruby_version] ? options[:ruby_version] : DEFAULT_RUBY_VERSION
17
+
18
+ template(".travis.yml", ".travis.yml")
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - <%= @ruby_version %>
5
+
6
+ services:
7
+ - postgresql
8
+
9
+ cache:
10
+ bundler: true
11
+ directories:
12
+ - node_modules
13
+ yarn: true
14
+
15
+ env:
16
+ global:
17
+ - RAILS_ENV=test
18
+ - NODE_ENV=test
19
+
20
+ before_install:
21
+ - nvm install --lts
22
+
23
+ install:
24
+ - node -v
25
+ - yarn
26
+ - bundle
27
+
28
+ before_script:
29
+ - bundle install --jobs=3 --retry=3
30
+ - bundle exec rails db:create
31
+ - bundle exec rails db:schema:load
32
+
33
+ script:
34
+ - bundle exec rails db:schema:load
35
+ - bundle exec rails test
@@ -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