UNPKG

851 BJavaScriptView Raw
1"use strict";
2
3const Handlebars = require("handlebars");
4
5// From inspectpack.
6const pkgNamePath = pkgParts =>
7 pkgParts.reduce((m, part) => `${m}${m ? " -> " : ""}{cyan-fg}${part.name}{/}@${part.range}`, "");
8
9Handlebars.registerHelper("skew", function(options) {
10 // eslint-disable-next-line no-invalid-this
11 return pkgNamePath(options.fn(this));
12});
13
14const template = Handlebars.compile(
15 `{yellow-fg}{underline}Version skews{/}
16
17{{#each packages}}
18{yellow-fg}{bold}{{@key}}{/}
19 {{#each this}}
20 {green-fg}{{@key}}{/}
21 {{#each this}}
22 {{#each skews}}
23 {{#skew}}{{{this}}}{{/skew}}
24 {{/each}}
25 {{/each}}
26 {{/each}}
27{{/each}}
28`
29);
30
31function formatVersions(versions) {
32 const haveSkews = !!Object.keys((versions || {}).packages || {}).length;
33 return haveSkews ? template(versions) : "";
34}
35
36module.exports = formatVersions;