Created
May 25, 2018 03:53
-
-
Save yurenju/23f3b468e06dc6ec2f9c824a0a35bdd0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const fetch = require('isomorphic-fetch'); | |
const toml = require('toml'); | |
async function getLine(package) { | |
const [owner, repo] = package.name.split('/').slice(-2); | |
try { | |
const licenseApiUrl = `https://api.github.com/repos/${owner}/${repo}/license`; | |
const options = { | |
headers: { | |
'Authorization': 'token <YOUR_GITHUB_PERSONAL_TOKEN>' | |
} | |
}; | |
const json = await fetch(licenseApiUrl, options).then(res => res.json()); | |
console.log(` * [${owner}/${repo}](https://github.com/${owner}/${repo}): ${json.license ? json.license.name : 'Unknown'}`); | |
} catch (e) { | |
console.log(e); | |
} | |
} | |
(async function() { | |
if (process.argv.length >= 3) { | |
const url = process.argv[2]; | |
const content = await fetch(url).then(res => res.text()); | |
const parsed = toml.parse(content); | |
const lines = ['Dependencies']; | |
if (parsed.constraint) { | |
parsed.constraint.forEach(getLine); | |
} | |
if (parsed.override) { | |
parsed.override.forEach(getLine); | |
} | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment