Module: Inertia::Generators::Helpers

Included in:
InstallGenerator
Defined in:
lib/generators/inertia/install/helpers.rb

Instance Method Summary collapse

Instance Method Details

#askObject

Interactivity Helpers



44
45
46
47
48
49
50
51
# File 'lib/generators/inertia/install/helpers.rb', line 44

def ask(*)
  unless options[:interactive]
    say_error 'Specify all options when running the generator non-interactively.', :red
    exit(1)
  end

  super
end

#file?(*relative_path) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/generators/inertia/install/helpers.rb', line 26

def file?(*relative_path)
  File.file?(file_path(*relative_path))
end

#file_path(*relative_path) ⇒ Object



30
31
32
# File 'lib/generators/inertia/install/helpers.rb', line 30

def file_path(*relative_path)
  File.join(destination_root, *relative_path)
end

#js_destination_pathObject

FS Helpers



7
8
9
10
11
12
13
14
15
16
# File 'lib/generators/inertia/install/helpers.rb', line 7

def js_destination_path
  return ViteRuby.config.source_code_dir if defined?(ViteRuby)

  if file?('config/vite.json')
    source_code_dir = JSON.parse(File.read(file_path('config/vite.json'))).dig('all', 'sourceCodeDir')
    return source_code_dir if source_code_dir
  end

  'app/frontend'
end

#js_destination_rootObject



18
19
20
# File 'lib/generators/inertia/install/helpers.rb', line 18

def js_destination_root
  file_path(js_destination_path)
end

#js_file_path(*relative_path) ⇒ Object



22
23
24
# File 'lib/generators/inertia/install/helpers.rb', line 22

def js_file_path(*relative_path)
  File.join(js_destination_root, *relative_path)
end

#update_package_json {|package_json| ... } ⇒ Object

Yields:

  • (package_json)


34
35
36
37
38
39
40
41
# File 'lib/generators/inertia/install/helpers.rb', line 34

def update_package_json
  package_json_path = file_path('package.json')
  package_json = JSON.parse(File.read(package_json_path))

  yield package_json

  File.write(package_json_path, "#{JSON.pretty_generate(package_json)}\n")
end

#yes?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'lib/generators/inertia/install/helpers.rb', line 53

def yes?(*)
  return false unless options[:interactive]

  super
end