Created
June 17, 2016 09:34
-
-
Save mikz/33cf8799ea5cac6c8fc92e04dfa71be9 to your computer and use it in GitHub Desktop.
detect jspm packages licenses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open-uri' | |
require 'json' | |
require 'shellwords' | |
ENV['NODE_PATH'] = '/usr/local/lib/node_modules' | |
# npm install -g licenses | |
data = DATA.read | |
define_method :autodetect do |name| | |
`node -e "#{data}" #{name}`.strip | |
end | |
packages = `jspm inspect`.scan(/\s+(?<repo>\w+):(?<name>\S+)\s(?<version>\d[\.\d\w\-\s]+\S)\n/).map{|(repo, name, versions)| [repo, name, versions.split(' ')] } | |
def each_version(packages, name, &block) | |
packages.select{|(repo,_,_)| repo == name }.each{|(_,name,versions)| versions.each{|v| yield(name, v) } } | |
end | |
each_version(packages, 'github') do |name, version| | |
puts "#{name.split(',').last}@#{version},TODO,https://github.com/#{name}" | |
end | |
each_version(packages, 'npm') do |name, version| | |
url = "http://registry.npmjs.org/#{name}/#{version}" | |
package = JSON.parse open("http://registry.npmjs.org/#{name}").read | |
fallback = autodetect(name) | |
license = package.fetch('license') { fallback.empty? ? 'UNKNOWN' : fallback } | |
puts "#{name}@#{version},#{license},#{url}" | |
end | |
__END__ | |
'use strict'; | |
var licenses = require('licenses'); | |
licenses(process.argv[1], function fetched(err, license) { | |
if (license) { | |
console.log(license.join(',')); | |
process.exit(0); | |
} else { | |
console.error(err); | |
process.exit(1); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment