Class: Panda::Core::Generators::DevToolsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/panda/core/dev_tools_generator.rb

Constant Summary collapse

VERSION_FILE =
".panda-dev-tools-version"
CURRENT_VERSION =
"1.0.0"

Instance Method Summary collapse

Instance Method Details

#add_development_dependenciesObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/generators/panda/core/dev_tools_generator.rb', line 57

def add_development_dependencies
  say "Adding development dependencies to gemspec..."

  if File.exist?("Gemfile")
    append_to_file "Gemfile" do
      <<~RUBY
        
        group :development, :test do
          # Panda Core development tools
          gem "standard"
          gem "brakeman"
          gem "bundler-audit"
          gem "yamllint"
        end
      RUBY
    end
  end
end

#add_rake_tasksObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/generators/panda/core/dev_tools_generator.rb', line 103

def add_rake_tasks
  say "Adding Panda Core rake tasks..."

  append_to_file "Rakefile" do
    <<~RUBY
      
      # Panda Core development tasks
      namespace :panda do
        desc "Run all linters"
        task :lint do
          sh "bundle exec standardrb"
          sh "yamllint -c .yamllint ."
        end
        
        desc "Run security checks"
        task :security do
          sh "bundle exec brakeman --quiet"
          sh "bundle exec bundle-audit --update"
        end
        
        desc "Run all quality checks"
        task quality: [:lint, :security]
      end
    RUBY
  end
end

#check_for_updatesObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/generators/panda/core/dev_tools_generator.rb', line 21

def check_for_updates
  if File.exist?(VERSION_FILE)
    installed_version = File.read(VERSION_FILE).strip
    if installed_version != CURRENT_VERSION
      say "Updating Panda Core dev tools from #{installed_version} to #{CURRENT_VERSION}", :yellow
      @updating = true
    else
      say "Panda Core dev tools are up to date (#{CURRENT_VERSION})", :green
      unless options[:force]
        say "Use --force to reinstall anyway"
        nil
      end
    end
  else
    say "Installing Panda Core dev tools #{CURRENT_VERSION}", :green
    @updating = false
  end
end

#copy_github_workflowsObject



48
49
50
51
# File 'lib/generators/panda/core/dev_tools_generator.rb', line 48

def copy_github_workflows
  say "Copying GitHub Actions workflows..."
  directory ".github", ".github", force: options[:force] || @updating
end

#copy_linting_configsObject



40
41
42
43
44
45
46
# File 'lib/generators/panda/core/dev_tools_generator.rb', line 40

def copy_linting_configs
  say "Copying linting configurations..."
  copy_file ".standard.yml", force: options[:force] || @updating
  copy_file ".yamllint", force: options[:force] || @updating
  copy_file ".rspec", force: options[:force] || @updating
  copy_file "lefthook.yml", force: options[:force] || @updating
end

#create_spec_helperObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/generators/panda/core/dev_tools_generator.rb', line 76

def create_spec_helper
  say "Creating spec helper with Panda Core testing configuration..."

  create_file "spec/support/panda_core_helpers.rb" do
    <<~RUBY
      # frozen_string_literal: true
      
      require 'panda/core/testing/rspec_config'
      require 'panda/core/testing/omniauth_helpers'
      require 'panda/core/testing/capybara_config'
      
      RSpec.configure do |config|
        # Apply Panda Core RSpec configuration
        Panda::Core::Testing::RSpecConfig.configure(config)
        Panda::Core::Testing::RSpecConfig.setup_matchers
        
        # Configure Capybara
        Panda::Core::Testing::CapybaraConfig.configure
        
        # Include helpers
        config.include Panda::Core::Testing::OmniAuthHelpers, type: :system
        config.include Panda::Core::Testing::CapybaraConfig::Helpers, type: :system
      end
    RUBY
  end
end

#create_version_fileObject



53
54
55
# File 'lib/generators/panda/core/dev_tools_generator.rb', line 53

def create_version_file
  create_file VERSION_FILE, CURRENT_VERSION, force: true
end

#display_instructionsObject



130
131
132
133
134
135
136
137
138
139
# File 'lib/generators/panda/core/dev_tools_generator.rb', line 130

def display_instructions
  say "\n✅ Panda Core development tools have been set up!", :green
  say "\nNext steps:"
  say "  1. Run 'bundle install' to install new dependencies"
  say "  2. Run 'bundle exec rake panda:quality' to check code quality"
  say "  3. Customize .github/workflows for your gem's needs"
  say "  4. Add 'require' statements to your spec_helper.rb or rails_helper.rb:"
  say "     require 'support/panda_core_helpers'"
  say "\nFor more information, see: docs/development_tools.md"
end