boring_generators 0.2.0 → 0.7.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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +12 -0
  3. data/.github/workflows/ci.yml +17 -0
  4. data/CHANGELOG.md +35 -1
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +148 -0
  7. data/README.md +45 -3
  8. data/boring_generators.gemspec +2 -0
  9. data/exe/boring +5 -0
  10. data/lib/boring_generators.rb +1 -0
  11. data/lib/boring_generators/cli.rb +26 -0
  12. data/lib/boring_generators/version.rb +1 -1
  13. data/lib/generators/boring/active_storage/aws/install/install_generator.rb +48 -0
  14. data/lib/generators/boring/active_storage/azure/install/install_generator.rb +48 -0
  15. data/lib/generators/boring/active_storage/google/install/install_generator.rb +48 -0
  16. data/lib/generators/boring/audit/install/install_generator.rb +22 -0
  17. data/lib/generators/boring/bootstrap/install/install_generator.rb +2 -2
  18. data/lib/generators/boring/bullet/install/install_generator.rb +31 -0
  19. data/lib/generators/boring/bullet/install/templates/bullet.rb +8 -0
  20. data/lib/generators/boring/ci/circleci/install/install_generator.rb +31 -0
  21. data/lib/generators/boring/ci/circleci/install/templates/config.psql.yml.tt +48 -0
  22. data/lib/generators/boring/ci/circleci/install/templates/config.sql.yml.tt +48 -0
  23. data/lib/generators/boring/ci/circleci/install/templates/database.yml.ci.tt +14 -0
  24. data/lib/generators/boring/ci/github_action/install/install_generator.rb +45 -0
  25. data/lib/generators/boring/ci/github_action/install/templates/ci.yml.tt +49 -0
  26. data/lib/generators/boring/ci/travisci/install/install_generator.rb +23 -0
  27. data/lib/generators/boring/ci/travisci/install/templates/.travis.yml.tt +35 -0
  28. data/lib/generators/boring/devise/install/install_generator.rb +75 -0
  29. data/lib/generators/boring/favicon/build/build_generator.rb +120 -0
  30. data/lib/generators/boring/favicon/build/templates/favicon.html.erb.tt +19 -0
  31. data/lib/generators/boring/graphql/install/install_generator.rb +51 -0
  32. data/lib/generators/boring/graphql/install/templates/base_resolver.rb +2 -0
  33. data/lib/generators/boring/graphql/install/templates/hello_world_resolver.rb +11 -0
  34. data/lib/generators/boring/oauth/base_generator.rb +63 -0
  35. data/lib/generators/boring/oauth/facebook/install/install_generator.rb +42 -0
  36. data/lib/generators/boring/oauth/facebook/install/templates/README +20 -0
  37. data/lib/generators/boring/oauth/facebook/install/templates/omniauth.rb +3 -0
  38. data/lib/generators/boring/oauth/facebook/install/templates/omniauth_callbacks_controller.rb +21 -0
  39. data/lib/generators/boring/oauth/github/install/install_generator.rb +42 -0
  40. data/lib/generators/boring/oauth/github/install/templates/README +20 -0
  41. data/lib/generators/boring/oauth/github/install/templates/omniauth_callbacks_controller.rb +21 -0
  42. data/lib/generators/boring/pry/install/install_generator.rb +29 -0
  43. data/lib/generators/boring/pry/install/templates/pryrc +24 -0
  44. data/lib/generators/boring/pundit/install/install_generator.rb +85 -0
  45. data/lib/generators/boring/rubocop/install/install_generator.rb +37 -0
  46. data/lib/generators/boring/rubocop/install/templates/.rubocop.yml.tt +262 -0
  47. data/lib/generators/boring/simple_form/install/install_generator.rb +44 -0
  48. data/lib/generators/boring/tailwind/install/install_generator.rb +13 -12
  49. data/lib/generators/boring/tailwind/install/templates/README +13 -0
  50. metadata +2524 -5
  51. data/.travis.yml +0 -6
@@ -0,0 +1,48 @@
1
+ module Boring
2
+ module ActiveStorage
3
+ module Google
4
+ class InstallGenerator < Rails::Generators::Base
5
+ desc "Adds ActiveStorage google cloud service the application"
6
+
7
+ class_option :skip_active_storage, type: :boolean, aliases: "-s",
8
+ desc: "Skips running ActiveStorage installer"
9
+
10
+ def add_active_storage
11
+ unless options[:skip_active_storage]
12
+ say "Adding ActiveStorage", :green
13
+ run "bin/rails active_storage:install"
14
+ end
15
+ end
16
+
17
+ def add_google_cloud_storage_to_the_application
18
+ say "Adding google cloud storage gem", :green
19
+ google_cloud_storage_gem_content = <<~RUBY
20
+ \n
21
+ # for Google Cloud Storage Service
22
+ gem "google-cloud-storage", require: false
23
+ RUBY
24
+ append_to_file "Gemfile", google_cloud_storage_gem_content
25
+ run "bundle install"
26
+ end
27
+
28
+ def add_configuration_to_production
29
+ gsub_file "config/environments/production.rb",
30
+ "config.active_storage.service = :local",
31
+ "config.active_storage.service = :google"
32
+ end
33
+
34
+ def add_google_storage_configuration
35
+ google_storage_config_content = <<~RUBY
36
+ google:
37
+ service: GCS
38
+ project: your_project
39
+ credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
40
+ bucket: your_own_bucket
41
+ RUBY
42
+
43
+ append_to_file "config/storage.yml", google_storage_config_content
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module Audit
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc "Adds Audit gems to the application"
7
+
8
+ def add_bullet_gem
9
+ say "Adding audit gems", :green
10
+ audit_gems_content = <<~RUBY
11
+ \n
12
+ \t# Patch-level verification for Bundler. https://github.com/rubysec/bundler-audit
13
+ \tgem "bundler-audit", require: false
14
+ \t# vulnerabity checker for Ruby itself. https://github.com/civisanalytics/ruby_audit
15
+ \tgem "ruby_audit", require: false
16
+ RUBY
17
+ insert_into_file "Gemfile", audit_gems_content, after: /group :development do/
18
+ run "bundle install"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -12,7 +12,7 @@ module Boring
12
12
  end
13
13
 
14
14
  def add_jquery_plugin_provider_to_webpack_environment
15
- say "Initailizing tailwind configuration", :green
15
+ say "Adding jQuery and popper JS plugin in the webpack", :green
16
16
  if File.exist?("config/webpack/environment.js")
17
17
  insert_into_file "config/webpack/environment.js", <<~RUBY, after: /@rails\/webpacker.*\n/
18
18
  const webpack = require("webpack")
@@ -37,7 +37,7 @@ module Boring
37
37
  '@import "~bootstrap/scss/bootstrap";'
38
38
  end
39
39
  else
40
- say "Copying application.scss with tailwind imports", :green
40
+ say "Copying application.scss with bootstrap imports", :green
41
41
  template("application.scss", "app/javascript/stylesheets/application.scss")
42
42
  end
43
43
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module Bullet
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc "Adds Bullet gem to the application"
7
+ source_root File.expand_path("templates", __dir__)
8
+
9
+ class_option :skip_configuration, type: :boolean, aliases: "-s",
10
+ desc: "Skips adding bullet development configuration"
11
+
12
+ def add_bullet_gem
13
+ say "Adding Bullet gem", :green
14
+ bullet_gem_content = <<~RUBY
15
+ \n
16
+ \t# reports N+1 queries
17
+ \tgem "bullet"
18
+ RUBY
19
+ insert_into_file "Gemfile", bullet_gem_content, after: /group :development do/
20
+ run "bundle install"
21
+ end
22
+
23
+ def add_bullet_gem_configuration
24
+ return if options[:skip_configuration]
25
+
26
+ say "Copying bullet.rb configuration to the initializer", :green
27
+ template("bullet.rb", "config/initializers/bullet.rb")
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ if Rails.env.development? && defined?(Bullet)
4
+ Bullet.enable = true
5
+ Bullet.bullet_logger = true
6
+ Bullet.rails_logger = true
7
+ Bullet.unused_eager_loading_enable = true
8
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module Ci
5
+ module Circleci
6
+ class InstallGenerator < Rails::Generators::Base
7
+ desc "Adds Circle CI to the application"
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ DEFAULT_RUBY_VERSION = "2.7.1"
11
+ DEFAULT_REPOSITORY_NAME = "boring_generators"
12
+
13
+ class_option :ruby_version, type: :string, aliases: "-v",
14
+ desc: "Tell us the ruby version to which you use for the application. Default to Ruby #{DEFAULT_RUBY_VERSION}"
15
+ class_option :skip_node, type: :boolean, aliases: "-sn",
16
+ desc: "Skips the node configuration required for webpacker based Rails application."
17
+ class_option :repository_name, type: :string, aliases: "-rn",
18
+ desc: "Tell us the repository name to be used as database name on circleci. Defaults to #{DEFAULT_REPOSITORY_NAME}"
19
+
20
+ def add_circle_ci_configuration
21
+ @skip_node = options[:skip_node]
22
+ @ruby_version = options[:ruby_version] ? options[:ruby_version] : DEFAULT_RUBY_VERSION
23
+ @repository_name = options[:repository_name] ? options[:repository_name] : DEFAULT_REPOSITORY_NAME
24
+
25
+ template("config.psql.yml", ".circleci/config.yml")
26
+ template("database.yml.ci", "config/database.yml.ci")
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -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