Class: Inertia::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/generators/inertia/install/install_generator.rb

Constant Summary collapse

FRAMEWORKS =
YAML.load_file(File.expand_path('./frameworks.yml', __dir__))

Instance Method Summary collapse

Methods included from Helpers

#ask, #file?, #file_path, #js_destination_path, #js_destination_root, #js_file_path, #update_package_json, #yes?

Instance Method Details

#installObject



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
74
75
76
77
78
79
# File 'lib/generators/inertia/install/install_generator.rb', line 49

def install
  say "Installing Inertia's Rails adapter"

  install_vite unless ruby_vite_installed?

  install_typescript if typescript?

  install_tailwind if install_tailwind?

  install_inertia

  install_example_page if options[:example_page]

  say 'Copying bin/dev'
  copy_file 'dev', 'bin/dev'
  chmod 'bin/dev', 0o755, verbose: verbose?

  if install_vite?
    say 'Adding redirect to localhost'
    routing_code = <<~RUBY
      \n  # Redirect to localhost from 127.0.0.1 to use same IP address with Vite server
        constraints(host: "127.0.0.1") do
          get "(*path)", to: redirect { |params, req| "\#{req.protocol}localhost:\#{req.port}/\#{params[:path]}" }
        end
    RUBY

    route routing_code
  end

  say "Inertia's Rails adapter successfully installed", :green
end