1 | "use strict";
|
2 |
|
3 | const Handlebars = require("handlebars");
|
4 |
|
5 |
|
6 | const pkgNamePath = pkgParts =>
|
7 | pkgParts.reduce((m, part) => `${m}${m ? " -> " : ""}{cyan-fg}${part.name}{/}@${part.range}`, "");
|
8 |
|
9 | Handlebars.registerHelper("skew", function(options) {
|
10 |
|
11 | return pkgNamePath(options.fn(this));
|
12 | });
|
13 |
|
14 | const 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 |
|
31 | function formatVersions(versions) {
|
32 | const haveSkews = !!Object.keys((versions || {}).packages || {}).length;
|
33 | return haveSkews ? template(versions) : "";
|
34 | }
|
35 |
|
36 | module.exports = formatVersions;
|