summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-05-19 11:42:07 -0600
committermo khan <mo.khan@gmail.com>2020-05-19 11:42:07 -0600
commit0f1db0d60c61a6db1c5389fc0ddb2d984789b330 (patch)
tree0a93685e673cf43b8c61ad9e251a1722f5460796 /lib
parentea84a8f5badf153744486c51a75b1f492763fdfd (diff)
Add --allow-root option to install step
Diffstat (limited to 'lib')
-rw-r--r--lib/license/finder/ext.rb1
-rw-r--r--lib/license/finder/ext/bower.rb55
2 files changed, 56 insertions, 0 deletions
diff --git a/lib/license/finder/ext.rb b/lib/license/finder/ext.rb
index 3d8a463..3c56c7a 100644
--- a/lib/license/finder/ext.rb
+++ b/lib/license/finder/ext.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
+require 'license/finder/ext/bower'
require 'license/finder/ext/go_modules'
require 'license/finder/ext/gradle'
require 'license/finder/ext/license'
diff --git a/lib/license/finder/ext/bower.rb b/lib/license/finder/ext/bower.rb
new file mode 100644
index 0000000..3c6ba6f
--- /dev/null
+++ b/lib/license/finder/ext/bower.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+module LicenseFinder
+ class Bower < PackageManager
+ def prepare
+ shell.execute([:bower, :install, '--allow-root'])
+ end
+
+ def current_packages
+ bower_output.map do |bower_module|
+ map_from(bower_module)
+ end
+ end
+
+ def possible_package_paths
+ [project_path.join('bower.json')]
+ end
+
+ private
+
+ def bower_output
+ stdout, _stderr, status = Dir.chdir(project_path) do
+ shell.execute([:bower, :list, '--json', '-l', 'action', '--allow-root'])
+ end
+ return [] unless status.success?
+
+ json = JSON.parse(stdout)
+ json.fetch('dependencies', {}).values
+ end
+
+ def map_from(bower_module)
+ spec = bower_module.fetch('pkgMeta', {})
+
+ if spec.empty?
+ endpoint = bower_module.fetch('endpoint', {})
+ Package.new(
+ endpoint['name'],
+ endpoint['target'],
+ install_path: bower_module['canonicalDir'],
+ )
+ else
+ Package.new(
+ spec['name'],
+ spec['version'],
+ summary: spec['description'],
+ description: spec['readme'],
+ homepage: spec['homepage'],
+ spec_licenses: Package.license_names_from_standard_spec(spec),
+ install_path: bower_module['canonicalDir'],
+ )
+ end
+ end
+ end
+end
+