Class: ViteRuby::CLI::Vite

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/vite_ruby/cli/vite.rb

Direct Known Subclasses

Build, Dev, SSR

Constant Summary collapse

CURRENT_ENV =
ENV["RACK_ENV"] || ENV["RAILS_ENV"]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.executable_optionsObject



6
7
8
9
10
11
# File 'lib/vite_ruby/cli/vite.rb', line 6

def self.executable_options
  option(:mode, default: self::DEFAULT_ENV, values: %w[development production test], aliases: ["m"], desc: "The build mode for Vite")
  option(:node_options, desc: "Node options for the Vite executable", aliases: ["node-options"])
  option(:inspect, desc: "Run Vite in a debugging session with node --inspect-brk", aliases: ["inspect-brk"], type: :boolean)
  option(:trace_deprecation, desc: "Run Vite in debugging mode with node --trace-deprecation", aliases: ["trace-deprecation"], type: :boolean)
end

.shared_optionsObject



13
14
15
16
17
# File 'lib/vite_ruby/cli/vite.rb', line 13

def self.shared_options
  executable_options
  option(:debug, desc: "Run Vite in verbose mode, printing all debugging output", aliases: ["verbose"], type: :boolean)
  option(:clobber, desc: "Clear cache and previous builds", type: :boolean, aliases: %w[clean clear])
end

Instance Method Details

#call(mode:, args: [], clobber: false, node_options: nil, inspect: nil, trace_deprecation: nil, **boolean_opts) {|args| ... } ⇒ Object

Yields:

  • (args)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vite_ruby/cli/vite.rb', line 19

def call(mode:, args: [], clobber: false, node_options: nil, inspect: nil, trace_deprecation: nil, **boolean_opts)
  ViteRuby.env["VITE_RUBY_MODE"] = mode
  ViteRuby.commands.clobber if clobber

  node_options = [
    node_options,
    ("--inspect-brk" if inspect),
    ("--trace-deprecation" if trace_deprecation),
  ].compact.join(" ")

  args << %(--node-options="#{node_options}") unless node_options.empty?

  boolean_opts.map { |name, value| args << "--#{name}" if value }

  yield(args)
end