boring_generators 0.1.0 → 0.6.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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +12 -0
  3. data/.github/PULL_REQUEST_TEMPLATE.md +11 -0
  4. data/.github/workflows/ci.yml +17 -0
  5. data/CHANGELOG.md +36 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +148 -0
  8. data/README.md +52 -6
  9. data/boring_generators.gemspec +3 -1
  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/active_storage/aws/install/install_generator.rb +48 -0
  15. data/lib/generators/boring/active_storage/azure/install/install_generator.rb +48 -0
  16. data/lib/generators/boring/active_storage/google/install/install_generator.rb +48 -0
  17. data/lib/generators/boring/audit/install/install_generator.rb +22 -0
  18. data/lib/generators/boring/bootstrap/install/install_generator.rb +67 -0
  19. data/lib/generators/boring/bootstrap/install/templates/application.scss +1 -0
  20. data/lib/generators/boring/bullet/install/install_generator.rb +31 -0
  21. data/lib/generators/boring/bullet/install/templates/bullet.rb +8 -0
  22. data/lib/generators/boring/ci/circleci/install/install_generator.rb +31 -0
  23. data/lib/generators/boring/ci/circleci/install/templates/config.psql.yml.tt +48 -0
  24. data/lib/generators/boring/ci/circleci/install/templates/config.sql.yml.tt +48 -0
  25. data/lib/generators/boring/ci/circleci/install/templates/database.yml.ci.tt +14 -0
  26. data/lib/generators/boring/ci/github_action/install/install_generator.rb +45 -0
  27. data/lib/generators/boring/ci/github_action/install/templates/ci.yml.tt +49 -0
  28. data/lib/generators/boring/ci/travisci/install/install_generator.rb +23 -0
  29. data/lib/generators/boring/ci/travisci/install/templates/.travis.yml.tt +35 -0
  30. data/lib/generators/boring/devise/install/install_generator.rb +75 -0
  31. data/lib/generators/boring/favicon/build/build_generator.rb +120 -0
  32. data/lib/generators/boring/favicon/build/templates/favicon.html.erb.tt +19 -0
  33. data/lib/generators/boring/font_awesome/ruby_gem/install/install_generator.rb +42 -0
  34. data/lib/generators/boring/font_awesome/yarn/install/install_generator.rb +53 -0
  35. data/lib/generators/boring/font_awesome/yarn/install/templates/application.scss +1 -0
  36. data/lib/generators/boring/graphql/install/install_generator.rb +51 -0
  37. data/lib/generators/boring/graphql/install/templates/base_resolver.rb +2 -0
  38. data/lib/generators/boring/graphql/install/templates/hello_world_resolver.rb +11 -0
  39. data/lib/generators/boring/jquery/install/install_generator.rb +32 -0
  40. data/lib/generators/boring/oauth/facebook/install/install_generator.rb +91 -0
  41. data/lib/generators/boring/oauth/facebook/install/templates/README +24 -0
  42. data/lib/generators/boring/oauth/facebook/install/templates/omniauth.rb +3 -0
  43. data/lib/generators/boring/oauth/facebook/install/templates/omniauth_callbacks_controller.rb +21 -0
  44. data/lib/generators/boring/pry/install/install_generator.rb +29 -0
  45. data/lib/generators/boring/pry/install/templates/pryrc +24 -0
  46. data/lib/generators/boring/pundit/install/install_generator.rb +85 -0
  47. data/lib/generators/boring/rubocop/install/install_generator.rb +37 -0
  48. data/lib/generators/boring/rubocop/install/templates/.rubocop.yml.tt +262 -0
  49. data/lib/generators/boring/simple_form/install/install_generator.rb +44 -0
  50. data/lib/generators/boring/tailwind/install/install_generator.rb +28 -20
  51. metadata +2527 -6
  52. data/.travis.yml +0 -6
@@ -0,0 +1,48 @@
1
+ module Boring
2
+ module ActiveStorage
3
+ module Azure
4
+ class InstallGenerator < Rails::Generators::Base
5
+ desc "Adds ActiveStorage Mircosoft Azure 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_azure_to_the_application
18
+ say "Adding mircosoft azure gem", :green
19
+ azure_gem_content = <<~RUBY
20
+ \n
21
+ # for Azure Service
22
+ gem "azure-storage-blob", require: false
23
+ RUBY
24
+ append_to_file "Gemfile", azure_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 = :microsoft"
32
+ end
33
+
34
+ def add_azure_storage_configuration
35
+ microsoft_storage_config_content = <<~RUBY
36
+ microsoft:
37
+ service: AzureStorage
38
+ storage_account_name: your_account_name
39
+ storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
40
+ container: your_container_name
41
+ RUBY
42
+
43
+ append_to_file "config/storage.yml", microsoft_storage_config_content
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -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
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boring
4
+ module Bootstrap
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc "Adds Bootstrap to the application"
7
+ source_root File.expand_path("templates", __dir__)
8
+
9
+ def add_bootstrap_package
10
+ say "Adding bootstrap packages", :green
11
+ run "yarn add bootstrap jquery popper.js"
12
+ end
13
+
14
+ def add_jquery_plugin_provider_to_webpack_environment
15
+ say "Adding jQuery and popper JS plugin in the webpack", :green
16
+ if File.exist?("config/webpack/environment.js")
17
+ insert_into_file "config/webpack/environment.js", <<~RUBY, after: /@rails\/webpacker.*\n/
18
+ const webpack = require("webpack")
19
+
20
+ environment.plugins.append("Provide", new webpack.ProvidePlugin({
21
+ $: 'jquery',
22
+ jQuery: 'jquery',
23
+ Popper: ['popper.js', 'default']
24
+ }))
25
+ RUBY
26
+ else
27
+ say <<~WARNING, :red
28
+ ERROR: Looks like the webpacker installation is incomplete. Could not find environment.js in config/webpack.
29
+ WARNING
30
+ end
31
+ end
32
+
33
+ def add_or_import_stylesheet_for_bootstrap
34
+ if File.exist?("app/javascript/stylesheets/application.scss")
35
+ say "Add bootstrap imports to the application.scss", :green
36
+ append_to_file "app/javascript/stylesheets/application.scss" do
37
+ '@import "~bootstrap/scss/bootstrap";'
38
+ end
39
+ else
40
+ say "Copying application.scss with bootstrap imports", :green
41
+ template("application.scss", "app/javascript/stylesheets/application.scss")
42
+ end
43
+ end
44
+
45
+ def insert_stylesheet_in_the_application
46
+ if File.exist?("app/javascript/packs/application.js")
47
+ application_js_content = <<~RUBY
48
+ \n
49
+ import "bootstrap"
50
+ import "stylesheets/application"
51
+ RUBY
52
+ append_to_file "app/javascript/packs/application.js", application_js_content
53
+ else
54
+ say <<~WARNING, :red
55
+ ERROR: Looks like the webpacker installation is incomplete. Could not find application.js in app/javascript/packs.
56
+ WARNING
57
+ end
58
+ end
59
+
60
+ def insert_stylesheet_packs_tag
61
+ insert_into_file "app/views/layouts/application.html.erb", <<~RUBY, after: /stylesheet_link_tag.*\n/
62
+ \t\t<%= stylesheet_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
63
+ RUBY
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1 @@
1
+ @import "~bootstrap/scss/bootstrap";
@@ -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.