Module: RailsVite::Tasks

Extended by:
Tasks
Included in:
Tasks
Defined in:
lib/rails_vite/tasks.rb

Constant Summary collapse

BUN_CMD =
defined?(Bundlebun) ? Bundlebun::Runner.binstub_or_binary_path : "bun"
COMMANDS =
{
  bun: {install: "#{BUN_CMD} install", add: "#{BUN_CMD} add -D", dev: "#{BUN_CMD} run vite", build: "#{BUN_CMD} run vite build"},
  yarn: {install: "yarn install", add: "yarn add -D", dev: "yarn vite", build: "yarn vite build"},
  pnpm: {install: "pnpm install", add: "pnpm add -D", dev: "pnpm vite", build: "pnpm vite build"},
  npm: {install: "npm install", add: "npm install -D", dev: "npx vite", build: "npx vite build"}
}.freeze
LOCKFILES =
{
  bun: %w[bun.lockb bun.lock],
  yarn: %w[yarn.lock],
  pnpm: %w[pnpm-lock.yaml],
  npm: %w[package-lock.json]
}.freeze

Instance Method Summary collapse

Instance Method Details

#add_command(*packages) ⇒ Object



25
26
27
# File 'lib/rails_vite/tasks.rb', line 25

def add_command(*packages)
  "#{command_for(:add)} #{packages.join(" ")}"
end

#build_commandObject



33
34
35
36
37
# File 'lib/rails_vite/tasks.rb', line 33

def build_command
  cmd = command_for(:build)
  cmd += " --mode test" if Rails.env.test?
  cmd
end

#dev_commandObject



29
30
31
# File 'lib/rails_vite/tasks.rb', line 29

def dev_command
  command_for(:dev)
end

#install_commandObject



21
22
23
# File 'lib/rails_vite/tasks.rb', line 21

def install_command
  command_for(:install)
end

#toolObject



39
40
41
# File 'lib/rails_vite/tasks.rb', line 39

def tool
  tool_determined_by_lockfile || tool_determined_by_executable
end