snyk-gradle-plugin
Version:
Snyk CLI Gradle plugin
39 lines • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getGradleAttributesPretty = getGradleAttributesPretty;
const tslib_1 = require("tslib");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
function getGradleAttributesPretty(output) {
try {
const lines = output.split('\n');
if (lines === null) {
return undefined;
}
let jsonLine = null;
lines.forEach((l) => {
const line = l.trim();
// Extract attribute information via JSONATTRS marker:
if (/^JSONATTRS /.test(line)) {
if (jsonLine === null) {
jsonLine = line.substr(10);
}
}
});
const jsonAttrs = JSON.parse(jsonLine);
const attrNameWidth = Math.max(...Object.keys(jsonAttrs).map((name) => name.length));
const jsonAttrsPretty = Object.keys(jsonAttrs)
.map((name) => chalk_1.default.whiteBright(leftPad(name, attrNameWidth)) +
': ' +
chalk_1.default.gray(jsonAttrs[name].join(', ')))
.join('\n');
return jsonAttrsPretty;
}
catch {
return undefined;
}
}
// <insert a npm left-pad joke here>
function leftPad(s, n) {
return ' '.repeat(Math.max(n - s.length, 0)) + s;
}
//# sourceMappingURL=gradle-attributes-pretty.js.map