Class: Plug::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_plug_packageObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/plug/install_generator.rb', line 19

def add_plug_package
  package_json_path = 'package.json'

  if File.exist?(package_json_path)
    package_json = JSON.parse(File.read(package_json_path))
    package_json['dependencies'] ||= {}
    package_json['dependencies']['@digitalnz/plug'] ||= "^#{Plug::VERSION}"

    File.write(package_json_path, JSON.pretty_generate(package_json) + "\n")
  else
    say 'package.json not found. Please ensure you are running this generator in the root directory of your Rails project.', :red
  end
end

#copy_initializer_fileObject



7
8
9
# File 'lib/generators/plug/install_generator.rb', line 7

def copy_initializer_file
  copy_file 'plug.rb', 'config/initializers/plug.rb'
end

#mount_engineObject



11
12
13
# File 'lib/generators/plug/install_generator.rb', line 11

def mount_engine
  inject_into_file('config/routes.rb', "\n  mount Plug::Engine => '/plug', as: 'plug'\n\n", before: /^end/)
end

#setup_vite_assetsObject



15
16
17
# File 'lib/generators/plug/install_generator.rb', line 15

def setup_vite_assets
  copy_file 'plug.vite.js', 'app/frontend/entrypoints/plug.js'
end