add new info field to output

Fixes: https://github.com/silverwind/updates/issues/10
Fixes: https://github.com/silverwind/updates/pull/11
This commit is contained in:
Jonas Gierer 2018-11-20 13:17:19 +01:00 committed by silverwind
parent b427cf3f73
commit 0dcd094643
Signed by: silverwind
GPG Key ID: 2E62B41C93869443
2 changed files with 16 additions and 4 deletions

@ -30,6 +30,7 @@
"chalk": "2.4.1",
"escape-string-regexp": "1.0.5",
"find-up": "3.0.0",
"hosted-git-info": "^2.7.1",
"make-fetch-happen": "4.0.1",
"minimist": "1.2.0",
"semver": "5.6.0",

@ -168,6 +168,15 @@ const get = async name => {
return fetch(registry + name).then(r => r.json());
};
const getInfoUrl = ({repository, homepage}) => {
if (repository) {
const gitUrl = typeof repository === "string" ? repository : repository.url;
return require("hosted-git-info").fromUrl(gitUrl).browse();
}
return homepage || "";
};
Promise.all(Object.keys(deps).map(name => get(name))).then(dati => {
for (const data of dati) {
const useGreatest = typeof greatest === "boolean" ? greatest : greatest.includes(data.name);
@ -180,6 +189,7 @@ Promise.all(Object.keys(deps).map(name => get(name))).then(dati => {
delete deps[data.name];
} else {
deps[data.name].new = newRange;
deps[data.name].info = getInfoUrl(data);
}
}
@ -263,11 +273,12 @@ function highlightDiff(a, b, added) {
}
function formatDeps() {
const arr = [["NAME", "OLD", "NEW"]];
for (const [name, versions] of Object.entries(deps)) arr.push([
const arr = [["NAME", "OLD", "NEW", "INFO"]];
for (const [name, data] of Object.entries(deps)) arr.push([
name,
highlightDiff(versions.old, versions.new, false),
highlightDiff(versions.new, versions.old, true),
highlightDiff(data.old, data.new, false),
highlightDiff(data.new, data.old, true),
data.info
]);
return require("text-table")(arr, {
hsep: " ".repeat(4),