Class: Discharger::SetupRunner::Commands::YarnCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Discharger::SetupRunner::Commands::YarnCommand
show all
- Defined in:
- lib/discharger/setup_runner/commands/yarn_command.rb
Instance Attribute Summary
Attributes inherited from BaseCommand
#app_root, #config, #logger
Instance Method Summary
collapse
Methods inherited from BaseCommand
#initialize
Instance Method Details
#can_execute? ⇒ Boolean
55
56
57
|
# File 'lib/discharger/setup_runner/commands/yarn_command.rb', line 55
def can_execute?
File.exist?(File.join(app_root, "package.json"))
end
|
#description ⇒ Object
59
60
61
|
# File 'lib/discharger/setup_runner/commands/yarn_command.rb', line 59
def description
"Install JavaScript dependencies"
end
|
#execute ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/discharger/setup_runner/commands/yarn_command.rb', line 9
def execute
log "Installing Node modules"
if File.exist?(File.join(app_root, "yarn.lock"))
if system_quiet("which corepack")
system! "corepack enable"
package_json_path = File.join(app_root, "package.json")
if File.exist?(package_json_path)
begin
require "json"
package_json = JSON.parse(File.read(package_json_path))
if package_json["packageManager"]&.start_with?("yarn@")
yarn_spec = package_json["packageManager"].split("+").first
log "Using #{yarn_spec} from package.json"
system! "corepack use #{yarn_spec}"
else
system! "corepack use yarn@stable"
end
rescue JSON::ParserError => e
log "Warning: Could not parse package.json: #{e.message}"
system! "corepack use yarn@stable"
end
else
system! "corepack use yarn@stable"
end
end
system_quiet("yarn check --check-files > /dev/null 2>&1") || system!("yarn install")
elsif File.exist?(File.join(app_root, "package-lock.json"))
log "Found package-lock.json, using npm"
system! "npm ci"
elsif File.exist?(File.join(app_root, "package.json"))
if system_quiet("which yarn")
system! "yarn install"
else
system! "npm install"
end
end
end
|