Module: Vitepress::Rails::Tasks

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

Instance Method Summary collapse

Instance Method Details

#add_package_command(package) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/vitepress/rails/tasks.rb', line 38

def add_package_command(package)
  case tool
  when :bun then "bun add -D #{package}"
  when :yarn then "yarn add -D #{package}"
  when :pnpm then "pnpm add -D #{package}"
  when :npm then "npm install -D #{package}"
  else raise "vitepress-rails: No suitable tool found for adding packages"
  end
end

#build_commandObject



28
29
30
31
32
33
34
35
36
# File 'lib/vitepress/rails/tasks.rb', line 28

def build_command
  case tool
  when :bun then "bun run docs:build"
  when :yarn then "yarn docs:build"
  when :pnpm then "pnpm docs:build"
  when :npm then "npm run docs:build"
  else raise "vitepress-rails: No suitable tool found for building JavaScript"
  end
end

#dev_commandObject



18
19
20
21
22
23
24
25
26
# File 'lib/vitepress/rails/tasks.rb', line 18

def dev_command
  case tool
  when :bun then "bun run docs:dev"
  when :yarn then "yarn docs:dev"
  when :pnpm then "pnpm docs:dev"
  when :npm then "npm run docs:dev"
  else raise "vitepress-rails: No suitable tool found for dev command"
  end
end

#install_commandObject



8
9
10
11
12
13
14
15
16
# File 'lib/vitepress/rails/tasks.rb', line 8

def install_command
  case tool
  when :bun then "bun install"
  when :yarn then "yarn install"
  when :pnpm then "pnpm install"
  when :npm then "npm install"
  else raise "vitepress-rails: No suitable tool found for installing JavaScript dependencies"
  end
end

#toolObject



48
49
50
# File 'lib/vitepress/rails/tasks.rb', line 48

def tool
  tool_determined_by_lock_file || tool_determined_by_executable
end

#tool_determined_by_executableObject



66
67
68
69
70
# File 'lib/vitepress/rails/tasks.rb', line 66

def tool_determined_by_executable
  [:bun, :yarn, :pnpm, :npm].each do |exe|
    return exe if system "command -v #{exe} > /dev/null"
  end
end

#tool_determined_by_lock_fileObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/vitepress/rails/tasks.rb', line 52

def tool_determined_by_lock_file
  if File.exist?("bun.lockb")
    :bun
  elsif File.exist?("bun.lock")
    :bun
  elsif File.exist?("yarn.lock")
    :yarn
  elsif File.exist?("pnpm-lock.yaml")
    :pnpm
  elsif File.exist?("package-lock.json")
    :npm
  end
end