Class: Importmap::CLI
- Inherits:
-
Command
show all
- Includes:
- Thor::Actions
- Defined in:
- lib/importmap/cli.rb,
lib/importmap/cli/help.rb
Defined Under Namespace
Modules: Help
Instance Method Summary
collapse
Methods inherited from Command
alter_command_description, command_help, dispatch, exit_on_failure?, website
Instance Method Details
#audit ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/importmap/cli.rb', line 61
def audit
vulnerable_packages = npm.vulnerable_packages
if vulnerable_packages.any?
table = [["Package", "Severity", "Vulnerable versions", "Vulnerability"]]
vulnerable_packages.each { |p| table << [p.name, p.severity, p.vulnerable_versions, p.vulnerability] }
puts_table(table)
vulnerabilities = 'vulnerability'.pluralize(vulnerable_packages.size)
severities = vulnerable_packages.map(&:severity).tally.sort_by(&:last).reverse
.map { |severity, count| "#{count} #{severity}" }
.join(", ")
puts " #{vulnerable_packages.size} #{vulnerabilities} found: #{severities}"
exit 1
else
puts "No vulnerable packages found"
end
end
|
#completion(*params) ⇒ Object
106
107
108
|
# File 'lib/importmap/cli.rb', line 106
def completion(*params)
Completer.new(CLI, *params).run
end
|
#completion_script ⇒ Object
112
113
114
|
# File 'lib/importmap/cli.rb', line 112
def completion_script
Completer::Script.generate
end
|
#json ⇒ Object
55
56
57
58
|
# File 'lib/importmap/cli.rb', line 55
def json
Importmap.framework_boot
puts Importmap.framework.application.importmap.to_json(resolver: ActionController::Base.helpers)
end
|
#outdated ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/importmap/cli.rb', line 82
def outdated
outdated_packages = npm.outdated_packages
if outdated_packages.any?
table = [["Package", "Current", "Latest"]]
outdated_packages.each { |p| table << [p.name, p.current_version, p.latest_version || p.error] }
puts_table(table)
packages = 'package'.pluralize(outdated_packages.size)
puts " #{outdated_packages.size} outdated #{packages} found"
exit 1
else
puts "No outdated packages found"
end
end
|
#packages ⇒ Object
100
101
102
|
# File 'lib/importmap/cli.rb', line 100
def packages
puts npm.packages_with_versions.map { |x| x.join(' ') }
end
|
#pin(*packages) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/importmap/cli.rb', line 9
def pin(*packages)
if imports = packager.import(*packages, env: options[:env], from: options[:from])
imports.each do |package, url|
if options[:download]
puts %(Pinning "#{package}" to #{packager.vendor_path}/#{package}.js via download from #{url})
packager.download(package, url)
pin = packager.vendored_pin_for(package, url)
else
puts %(Pinning "#{package}" to #{url})
pin = packager.pin_for(package, url)
end
if packager.packaged?(package)
gsub_file("config/importmap.rb", /^pin "#{package}".*$/, pin, verbose: false)
else
append_to_file("config/importmap.rb", "#{pin}\n", verbose: false)
end
end
else
puts "Couldn't find any packages in #{packages.inspect} on #{options[:from]}"
end
end
|
#unpin(*packages) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/importmap/cli.rb', line 36
def unpin(*packages)
if imports = packager.import(*packages, env: options[:env], from: options[:from])
imports.each do |package, url|
if packager.packaged?(package)
if options[:download]
puts %(Unpinning and removing "#{package}")
else
puts %(Unpinning "#{package}")
end
packager.remove(package)
end
end
else
puts "Couldn't find any packages in #{packages.inspect} on #{options[:from]}"
end
end
|
#version ⇒ Object
117
118
119
|
# File 'lib/importmap/cli.rb', line 117
def version
puts Importmap::VERSION
end
|