Sha256: d1744e1ba8caec8ad3b731afbd799521e189cb5536c0e8d582e11ffe891e04b5

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

class ViteRuby::CLI::Build < Dry::CLI::Command
  CURRENT_ENV = ENV['RACK_ENV'] || ENV['RAILS_ENV']
  DEFAULT_ENV = CURRENT_ENV || 'production'

  def self.shared_options
    option(:mode, default: self::DEFAULT_ENV, values: %w[development production], aliases: ['m'], desc: 'The build mode for Vite')
    option(:debug, desc: 'Run Vite in verbose mode, printing all debugging output', aliases: ['verbose'], type: :boolean)
    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

  desc 'Bundle all entrypoints using Vite.'
  shared_options
  option(:force, desc: 'Force the build even if assets have not changed', type: :boolean)

  def call(mode:, args: [], **boolean_opts)
    ViteRuby.env['VITE_RUBY_MODE'] = mode
    boolean_opts.map { |name, value| args << "--#{ name }" if value }
    block_given? ? yield(args) : ViteRuby.commands.build_from_task(*args)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vite_ruby-1.1.2 lib/vite_ruby/cli/build.rb
vite_ruby-1.1.1 lib/vite_ruby/cli/build.rb
vite_ruby-1.1.0 lib/vite_ruby/cli/build.rb