Class: Phlex::Stimulus::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
GeneratorMixin
Defined in:
lib/generators/phlex/stimulus/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_filesObject



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
# File 'lib/generators/phlex/stimulus/install/install_generator.rb', line 33

def create_files
  copy_template 'app/components.rb'
  copy_template 'app/components/base.rb'
  copy_template 'app/components/controller.rb'
  copy_template 'app/components/chain_controller.rb'
  copy_template 'app/components/controller_template.rb'
  copy_template 'app/components/controller_chain.rb'
  copy_template 'app/components/classlist_controller.rb'
  copy_template 'app/components/log_controller.rb'
  copy_template 'app/components/sleep_controller.rb'

  remove_file File.join(destination_root, 'app/javascript/application.js')
  copy_template 'app/javascript/application.ts'

  remove_file File.join(destination_root, 'app/javascript/controllers/application.js')
  copy_template 'app/javascript/controllers/application.ts'

  remove_file File.join(destination_root, 'app/javascript/controllers/index.js')
  copy_template 'app/javascript/controllers/index.ts'

  copy_template 'app/javascript/controllers/typed_controller.ts'
  copy_template 'app/javascript/controllers/chain_controller.ts'
  copy_template 'app/javascript/controllers/chainable_controller.ts'
  copy_template 'app/javascript/controllers/log_controller.ts'
  copy_template 'app/javascript/controllers/sleep_controller.ts'
  copy_template 'app/javascript/controllers/classlist_controller.ts'

  copy_template 'app/javascript/utils/misc.ts'
  copy_template 'app/javascript/utils/template.ts'
end

#install_jsbundling_unless_presentObject



19
20
21
22
23
24
# File 'lib/generators/phlex/stimulus/install/install_generator.rb', line 19

def install_jsbundling_unless_present
  return if jsbundling_installed?

  say 'Installing jsbundling-rails (esbuild)', :yellow
  install_jsbundling_with_esbuild
end

#install_stimulusObject



26
27
28
29
30
31
# File 'lib/generators/phlex/stimulus/install/install_generator.rb', line 26

def install_stimulus
  say 'Installing stimulus', :yellow
  gem 'stimulus-rails'
  Bundler.with_original_env { run 'bundle install' }
  rails_command 'stimulus:install'
end

#remove_importmap_if_presentObject



12
13
14
15
16
17
# File 'lib/generators/phlex/stimulus/install/install_generator.rb', line 12

def remove_importmap_if_present
  return unless importmap_installed?

  say 'Importmap detected — removing it', :yellow
  remove_importmap
end