UNPKG

@atomist/sdm-pack-aspect

Version:

an Atomist SDM Extension Pack for visualizing drift across an organization

101 lines 4.24 kB
"use strict"; /* * Copyright © 2019 Atomist, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const sdm_pack_fingerprint_1 = require("@atomist/sdm-pack-fingerprint"); const fileUtils_1 = require("../../util/fileUtils"); exports.NoLicense = "None"; exports.LicenseType = "license"; function hasNoLicense(ld) { return ld.classification === exports.NoLicense; } exports.hasNoLicense = hasNoLicense; function isLicenseFingerprint(fp) { return fp.type === exports.LicenseType && !!fp.data.classification; } exports.isLicenseFingerprint = isLicenseFingerprint; const defaultClassifier = content => content.trim().split("\n")[0].trim(); /** * License aspect. Every repository gets a license fingerprint, which may have unknown * as a license. * @param opts provides classifier function, taking the license content and returning * a classificiation */ function license(opts = { classifier: defaultClassifier }) { return { name: exports.LicenseType, displayName: "License", baseOnly: true, extract: (p) => __awaiter(this, void 0, void 0, function* () { const licenseFile = yield fileUtils_1.firstFileFound(p, "LICENSE", "LICENSE.txt", "license.txt", "LICENSE.md"); let classification = exports.NoLicense; let content; if (!!licenseFile) { content = yield licenseFile.getContent(); classification = opts.classifier(content); } const data = { classification, path: licenseFile ? licenseFile.path : undefined }; return sdm_pack_fingerprint_1.fingerprintOf({ type: exports.LicenseType, data, }); }), toDisplayableFingerprintName: () => "License", toDisplayableFingerprint: fp => { return fp.data.classification === exports.NoLicense ? "None" : `${fp.data.path}:${fp.data.classification}`; }, stats: { defaultStatStatus: { entropy: false, }, }, }; } exports.license = license; exports.LicensePresenceType = "license-presence"; /** * Does this repository have a license? * Works with data from the license aspect. */ exports.LicensePresence = { name: exports.LicensePresenceType, displayName: "License presence", extract: () => __awaiter(void 0, void 0, void 0, function* () { return []; }), consolidate: (fps) => __awaiter(void 0, void 0, void 0, function* () { const lfp = fps.find(isLicenseFingerprint); const present = !!lfp && !hasNoLicense(lfp.data); const data = { present }; return { name: exports.LicensePresenceType, type: exports.LicensePresenceType, data, sha: sdm_pack_fingerprint_1.sha256(JSON.stringify(data)), }; }), toDisplayableFingerprint: fp => fp.data.present ? "Yes" : "No", }; //# sourceMappingURL=license.js.map