Class: Importmap::Commands
- Inherits:
-
Thor
- Object
- Thor
- Importmap::Commands
- Includes:
- Thor::Actions
- Defined in:
- lib/importmap/commands.rb
Class Method Summary collapse
Instance Method Summary collapse
- #audit ⇒ Object
- #json ⇒ Object
- #outdated ⇒ Object
- #packages ⇒ Object
- #pin(*packages) ⇒ Object
- #pristine ⇒ Object
- #unpin(*packages) ⇒ Object
- #update ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
8 9 10 |
# File 'lib/importmap/commands.rb', line 8 def self.exit_on_failure? false end |
Instance Method Details
#audit ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/importmap/commands.rb', line 60 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 |
#json ⇒ Object
54 55 56 57 |
# File 'lib/importmap/commands.rb', line 54 def json require Rails.root.join("config/environment") puts Rails.application.importmap.to_json(resolver: ActionController::Base.helpers) end |
#outdated ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/importmap/commands.rb', line 81 def outdated if (outdated_packages = npm.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
106 107 108 |
# File 'lib/importmap/commands.rb', line 106 def packages puts npm.packages_with_versions.map { |x| x.join(' ') } end |
#pin(*packages) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/importmap/commands.rb', line 16 def pin(*packages) for_each_import(packages, env: [:env], from: [:from]) do |package, url| puts %(Pinning "#{package}" to #{packager.vendor_path}/#{package}.js via download from #{url}) packager.download(package, url) pin = packager.vendored_pin_for(package, url, [:preload]) update_importmap_with_pin(package, pin) end end |
#pristine ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/importmap/commands.rb', line 43 def pristine packages = prepare_packages_with_versions for_each_import(packages, env: [:env], from: [:from]) do |package, url| puts %(Downloading "#{package}" to #{packager.vendor_path}/#{package}.js from #{url}) packager.download(package, url) end end |
#unpin(*packages) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/importmap/commands.rb', line 31 def unpin(*packages) for_each_import(packages, env: [:env], from: [:from]) do |package, url| if packager.packaged?(package) puts %(Unpinning and removing "#{package}") packager.remove(package) end end end |
#update ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/importmap/commands.rb', line 97 def update if (outdated_packages = npm.outdated_packages).any? pin(*outdated_packages.map(&:name)) else puts "No outdated packages found" end end |