Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rolemodel_rails (0.24.5)
rolemodel_rails (0.25.0)
rails (> 7.1)

GEM
Expand Down
2 changes: 1 addition & 1 deletion example_rails7/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
rolemodel_rails (0.24.5)
rolemodel_rails (0.25.0)
rails (> 7.1)

GEM
Expand Down
4 changes: 2 additions & 2 deletions example_rails8/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
rolemodel_rails (0.24.5)
rolemodel_rails (0.25.0)
rails (> 7.1)

GEM
Expand Down Expand Up @@ -521,7 +521,7 @@ CHECKSUMS
regexp_parser (2.11.3) sha256=ca13f381a173b7a93450e53459075c9b76a10433caadcb2f1180f2c741fc55a4
reline (0.6.3) sha256=1198b04973565b36ec0f11542ab3f5cfeeec34823f4e54cebde90968092b1835
rexml (3.4.4) sha256=19e0a2c3425dfbf2d4fc1189747bdb2f849b6c5e74180401b15734bc97b5d142
rolemodel_rails (0.24.5)
rolemodel_rails (0.25.0)
rubocop (1.84.1) sha256=14cc626f355141f5a2ef53c10a68d66b13bb30639b26370a76559096cc6bcc1a
rubocop-ast (1.49.0) sha256=49c3676d3123a0923d333e20c6c2dbaaae2d2287b475273fddee0c61da9f71fd
rubocop-performance (1.26.1) sha256=cd19b936ff196df85829d264b522fd4f98b6c89ad271fa52744a8c11b8f71834
Expand Down
35 changes: 0 additions & 35 deletions lib/generators/bundler_helpers.rb

This file was deleted.

27 changes: 0 additions & 27 deletions lib/generators/replace_content_helper.rb

This file was deleted.

19 changes: 17 additions & 2 deletions lib/generators/rolemodel.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
require 'rails'
require 'pathname'
require 'rails/generators/bundle_helper'
require_relative 'rolemodel/replace_content_helper'

module Rolemodel
RUBY_VERSION = Pathname.pwd.join('.ruby-version').read.strip
NODE_VERSION = Pathname.pwd.join('.node-version').read.strip

autoload :BundlerHelpers, File.expand_path('./bundler_helpers', __dir__)
autoload :ReplaceContentHelper, File.expand_path('./replace_content_helper', __dir__)
class BaseGenerator < Rails::Generators::Base
include Rails::Generators::BundleHelper
include ReplaceContentHelper

private
# based on https://github.com/rails/rails/blob/main/railties/lib/rails/generators/app_base.rb#L713
def run_bundle
bundle_command("install --quiet", "BUNDLE_IGNORE_MESSAGES" => "1")
end
end

Dir['lib/generators/rolemodel/**/*.rb'].each do |file|
load file if file.end_with?('_generator.rb')
end
end
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/all_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Rolemodel
class AllGenerator < Rails::Generators::Base
class AllGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def run_all_the_generators
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/editors/editors_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Rolemodel
# Add standard editorconfig and any extensions to enable it
class EditorsGenerator < Rails::Generators::Base
class EditorsGenerator < BaseGenerator
include Rolemodel::VSCodeHelpers

# This is bringing in the root from this gem, so we only modify
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/github/github_generator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class GithubGenerator < Rails::Generators::Base
class GithubGenerator < BaseGenerator
# Source root is the project-level .github directory
# This allows us to use the same templates for both the generated app and this gem
source_root File.expand_path('.github')
Expand Down
3 changes: 1 addition & 2 deletions lib/generators/rolemodel/good_job/good_job_generator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class GoodJobGenerator < Rails::Generators::Base
include BundlerHelpers
class GoodJobGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def install_good_job
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/heroku/heroku_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Rolemodel
class HerokuGenerator < Rails::Generators::Base
class HerokuGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def install_app_json
Expand Down
3 changes: 1 addition & 2 deletions lib/generators/rolemodel/kaminari/kaminari_generator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class KaminariGenerator < Rails::Generators::Base
include BundlerHelpers
class KaminariGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def install_kaminari
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/linters/all_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Rolemodel
module Linters
class AllGenerator < Rails::Generators::Base
class AllGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def run_all_the_generators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Rolemodel
module Linters
class EslintGenerator < Rails::Generators::Base
class EslintGenerator < BaseGenerator
include ReplaceContentHelper
source_root File.expand_path('templates', __dir__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
module Rolemodel
module Linters
# Install the standard rubocop and a custom cop
class RubocopGenerator < Rails::Generators::Base
include BundlerHelpers
class RubocopGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def install_rubocop
Expand Down
3 changes: 1 addition & 2 deletions lib/generators/rolemodel/lograge/lograge_generator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class LogrageGenerator < Rails::Generators::Base
include BundlerHelpers
class LogrageGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def install_lograge
Expand Down
3 changes: 1 addition & 2 deletions lib/generators/rolemodel/mailers/mailers_generator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class MailersGenerator < Rails::Generators::Base
include BundlerHelpers
class MailersGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def install_premailer_rails
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/optics/all_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Rolemodel
module Optics
class AllGenerator < Rails::Generators::Base
class AllGenerator < Rolemodel::BaseGenerator
source_root File.expand_path('templates', __dir__)

def run_all_the_generators
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/optics/base/base_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Rolemodel
module Optics
class BaseGenerator < Rails::Generators::Base
class BaseGenerator < Rolemodel::BaseGenerator
source_root File.expand_path('templates', __dir__)

def add_optics_package
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/optics/icons/icons_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Rolemodel
module Optics
# Generates the icon helper and icon builders for the chosen icon library
class IconsGenerator < Rails::Generators::Base
class IconsGenerator < Rolemodel::BaseGenerator
source_root File.expand_path('templates', __dir__)

SUPPORTED_LIBRARIES = {
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/react/react_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Rolemodel
class ReactGenerator < Rails::Generators::Base
class ReactGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def add_npm_packages
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/readme/readme_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Rolemodel
class ReadmeGenerator < Rails::Generators::Base
class ReadmeGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def install_readme
Expand Down
29 changes: 29 additions & 0 deletions lib/generators/rolemodel/replace_content_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Rolemodel
module ReplaceContentHelper
private

def replace_content(relative_path, &block)
source = File.expand_path(relative_path.to_s, destination_root)
content = File.exist?(source) ? File.open(source) { it.binmode.read } : ''

remove_file relative_path
create_file relative_path, yield(content)
end

def modify_json_file(relative_path, &block)
replace_content(relative_path) do |content|
hash = JSON.parse(content.presence || '{}')
yield(hash)
JSON.pretty_generate(hash) + "\n"
end
end

def add_package_json_script(command_name, command)
modify_json_file('package.json') do |hash|
hash['scripts'] ||= {}
hash['scripts'][command_name] = command
hash
end
end
end
end
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/saas/all_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Rolemodel
module Saas
class AllGenerator < Rails::Generators::Base
class AllGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def run_all_the_generators
Expand Down
3 changes: 1 addition & 2 deletions lib/generators/rolemodel/saas/devise/devise_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

module Rolemodel
module Saas
class DeviseGenerator < Rails::Generators::Base
include BundlerHelpers
class DeviseGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def add_organization
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/semaphore/semaphore_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Rolemodel
class SemaphoreGenerator < Rails::Generators::Base
class SemaphoreGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def create_base_semaphore_config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class SimpleFormGenerator < Rails::Generators::Base
include BundlerHelpers
class SimpleFormGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def add_gem
Expand Down
3 changes: 1 addition & 2 deletions lib/generators/rolemodel/slim/slim_generator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class SlimGenerator < Rails::Generators::Base
include BundlerHelpers
class SlimGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def add_slim
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Rolemodel
class SoftDestroyableGenerator < Rails::Generators::Base
class SoftDestroyableGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def add_concern
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class SourceMapGenerator < Rails::Generators::Base
class SourceMapGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def inject_config_for_production
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Rolemodel
class TailoredSelectGenerator < Rails::Generators::Base
class TailoredSelectGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def add_tailored_select_package
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/testing/all_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Rolemodel
module Testing
class AllGenerator < Rails::Generators::Base
class AllGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def run_all_the_generators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

module Rolemodel
module Testing
class FactoryBotGenerator < Rails::Generators::Base
include BundlerHelpers
class FactoryBotGenerator < BaseGenerator
source_root File.expand_path('templates', __dir__)

def install_factory_bot_rails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Rolemodel
module Testing
class JasminePlaywrightGenerator < Rails::Generators::Base
class JasminePlaywrightGenerator < BaseGenerator
include ReplaceContentHelper
source_root File.expand_path('templates', __dir__)
class_option :github_package_token, type: :string, default: ENV['GITHUB_PACKAGES_TOKEN'], desc: 'GitHub Packages token with access to @rolemodel packages'
Expand Down
Loading