Class: Komponent::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/komponent/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#append_to_application_configurationObject



46
47
48
49
# File 'lib/generators/komponent/install_generator.rb', line 46

def append_to_application_configuration
  application "config.autoload_paths << config.root.join('#{relative_path_from_rails}/components')"
  application "config.i18n.load_path += Dir[config.root.join('#{relative_path_from_rails}/components/**/*.yml')]"
end

#append_to_application_packObject



51
52
53
# File 'lib/generators/komponent/install_generator.rb', line 51

def append_to_application_pack
  append_to_file(application_pack_path, "import 'components';")
end

#check_webpacker_dependencyObject



8
9
10
11
12
13
14
# File 'lib/generators/komponent/install_generator.rb', line 8

def check_webpacker_dependency
  return if komponent_already_installed?

  unless File.exist?(webpacker_configuration_file) and File.directory?(webpacker_default_structure)
    raise Thor::Error, dependencies_not_met_error_message
  end
end

#create_komponent_default_structureObject



32
33
34
35
36
37
# File 'lib/generators/komponent/install_generator.rb', line 32

def create_komponent_default_structure
  return if File.exist?(components_directory.join("index.js"))

  empty_directory(components_directory)
  create_file(components_directory.join("index.js"))
end

#create_root_directoryObject



16
17
18
19
20
# File 'lib/generators/komponent/install_generator.rb', line 16

def create_root_directory
  return if File.directory?(komponent_root_directory)

  empty_directory(komponent_root_directory)
end

#create_stimulus_fileObject



39
40
41
42
43
44
# File 'lib/generators/komponent/install_generator.rb', line 39

def create_stimulus_file
  return if File.exist?(stimulus_application_path)
  return unless stimulus?

  create_file(stimulus_application_path, stimulus_application_template)
end

#install_stimulusObject



55
56
57
58
59
60
61
# File 'lib/generators/komponent/install_generator.rb', line 55

def install_stimulus
  if stimulus?
    in_root do
      run("yarn add stimulus")
    end
  end
end

#modify_webpacker_configurationObject



22
23
24
# File 'lib/generators/komponent/install_generator.rb', line 22

def modify_webpacker_configuration
  gsub_file(webpacker_configuration_file, /source_path: app\/javascript$/, "source_path: #{relative_path_from_rails}")
end

#move_webpacker_default_structureObject



26
27
28
29
30
# File 'lib/generators/komponent/install_generator.rb', line 26

def move_webpacker_default_structure
  return if File.directory?(komponent_root_directory)

  run("mv #{webpacker_default_structure}/* #{komponent_root_directory}")
end