UNPKG

@atomist/sdm-pack-aspect

Version:

an Atomist SDM Extension Pack for visualizing drift across an organization

92 lines 4.47 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()); }); }; var __asyncValues = (this && this.__asyncValues) || function (o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; Object.defineProperty(exports, "__esModule", { value: true }); const astUtils_1 = require("@atomist/automation-client/lib/tree/ast/astUtils"); const sdm_pack_fingerprint_1 = require("@atomist/sdm-pack-fingerprint"); const FileMatchType = "file-match"; function isFileMatchFingerprint(fp) { const maybe = fp.data; return !!maybe && maybe.kind === FileMatchType && maybe.kind === "file-match" && !!maybe.glob; } exports.isFileMatchFingerprint = isFileMatchFingerprint; /** * Check for presence of a match within the AST of files matching the glob. * Always return something, but may have an empty path. */ function fileMatchAspect(config) { return Object.assign(Object.assign({ toDisplayableFingerprintName: name => `File match '${config.glob}'`, toDisplayableFingerprint: fp => fp.data.matches.length === 0 ? "None" : fp.data.matches .map(m => m.matchValue) .join(), stats: { defaultStatStatus: { entropy: false, }, } }, config), { extract: (p) => __awaiter(this, void 0, void 0, function* () { var e_1, _a; const matches = []; const it = astUtils_1.fileHitIterator(p, { parseWith: config.parseWith, pathExpression: config.pathExpression, globPatterns: config.glob, }); try { for (var it_1 = __asyncValues(it), it_1_1; it_1_1 = yield it_1.next(), !it_1_1.done;) { const match = it_1_1.value; matches.push({ filePath: match.file.path, pathExpression: config.pathExpression, matchValue: match.matches[0].$value, }); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (it_1_1 && !it_1_1.done && (_a = it_1.return)) yield _a.call(it_1); } finally { if (e_1) throw e_1.error; } } const data = { kind: FileMatchType, matches, glob: config.glob, }; return sdm_pack_fingerprint_1.fingerprintOf({ type: config.name, data, }); }) }); } exports.fileMatchAspect = fileMatchAspect; //# sourceMappingURL=fileMatchAspect.js.map