Class: Spree::DummyGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/spree/dummy/dummy_generator.rb

Constant Summary collapse

SPREE_GEMS =
%w(spree_admin spree_storefront spree_api spree_emails).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



102
103
104
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 102

def database
  @database
end

#lib_nameObject (readonly)

Returns the value of attribute lib_name.



101
102
103
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 101

def lib_name
  @lib_name
end

Class Method Details

.source_pathsObject



17
18
19
20
21
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 17

def self.source_paths
  paths = superclass.source_paths
  paths << File.expand_path('templates', __dir__)
  paths.flatten
end

Instance Method Details

#clean_upObject



23
24
25
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 23

def clean_up
  remove_directory_if_exists(dummy_path)
end

#generate_test_dummyObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 27

def generate_test_dummy
  puts 'Generating dummy Rails application...'
  puts "Options: #{options.inspect}"

  args = [File.expand_path(dummy_path, destination_root)]

  # Database
  args << "--database=#{options[:database].presence || 'sqlite3'}"

  # CSS framework (e.g., tailwind)
  args << "--css=#{options[:css]}" if options[:css].present?

  # JavaScript
  args << '--skip-javascript' unless options[:javascript]

  # Skip asset pipeline if no javascript or css is required
  args << '--skip-asset-pipeline' unless options[:javascript] || options[:css].present?

  # Skip options
  args << '--force'
  args << '--skip-bundle'
  args << '--skip-git'
  args << '--skip-keeps'
  args << '--skip-rc'
  args << '--skip-spring'
  args << '--skip-test'
  args << '--skip-bootsnap'
  args << '--skip-docker'
  args << '--skip-rubocop'
  args << '--skip-brakeman'
  args << '--skip-ci'
  args << '--skip-kamal'
  args << '--skip-devcontainer'
  args << '--skip-solid'
  args << '--skip-thruster'
  args << '--skip-bundler-audit'
  args << '--skip-dev-gems'
  args << '--skip-action-mailbox'
  args << '--skip-jbuilder'

  # API mode (implies skip-asset-pipeline, skip-javascript, skip-hotwire)
  args << '--api' if options[:api]

  puts "Rails app generator args: #{args.inspect}"
  Rails::Generators.invoke('app', args)
  inject_yaml_permitted_classes
end

#test_dummy_configObject



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 75

def test_dummy_config
  @lib_name = options[:lib_name]
  @database = options[:database]

  template 'rails/database.yml', "#{dummy_path}/config/database.yml", force: true
  template 'rails/boot.rb', "#{dummy_path}/config/boot.rb", force: true
  template 'rails/application.rb', "#{dummy_path}/config/application.rb", force: true
  template 'rails/routes.rb', "#{dummy_path}/config/routes.rb", force: true
  template 'rails/test.rb', "#{dummy_path}/config/environments/test.rb", force: true
  template "app/assets/config/manifest.js", "#{dummy_path}/app/assets/config/manifest.js", force: true unless options[:api]
end

#test_dummy_inject_extension_requirementsObject



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 87

def test_dummy_inject_extension_requirements
  if DummyGeneratorHelper.inject_extension_requirements
    SPREE_GEMS.each do |gem|
      begin
        require "#{gem}"
        inside dummy_path do
          inject_require_for(gem)
        end
      rescue StandardError, LoadError
      end
    end
  end
end