UNPKG

@atomist/sdm-pack-aspect

Version:

an Atomist SDM Extension Pack for visualizing drift across an organization

88 lines 4.36 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. */ Object.defineProperty(exports, "__esModule", { value: true }); const sdm_1 = require("@atomist/sdm"); const sdm_core_1 = require("@atomist/sdm-core"); const array_1 = require("@atomist/sdm-core/lib/util/misc/array"); const sdm_pack_fingerprints_1 = require("@atomist/sdm-pack-fingerprints"); const analyzeCommand_1 = require("../analysis/offline/spider/analyzeCommand"); const DefaultAspectRegistry_1 = require("../aspect/DefaultAspectRegistry"); const api_1 = require("../routes/api"); const webAppRoutes_1 = require("../routes/web-app/webAppRoutes"); const machine_1 = require("./machine"); exports.DefaultVirtualProjectFinder = sdm_pack_fingerprints_1.cachingVirtualProjectFinder(sdm_pack_fingerprints_1.fileNamesVirtualProjectFinder("package.json", "pom.xml", "build.gradle", "requirements.txt")); exports.DefaultScoreWeightings = { // Weight this to penalize projects with few other scorers anchor: 3, }; function aspectSupport(options) { return Object.assign({}, sdm_1.metadata(), { configure: sdm => { const cfg = sdm.configuration; if (sdm_core_1.isInLocalMode()) { const analyzer = machine_1.createAnalyzer(array_1.toArray(options.aspects), options.virtualProjectFinder || exports.DefaultVirtualProjectFinder); sdm.addCommand(analyzeCommand_1.analyzeGitHubCommandRegistration(analyzer)); sdm.addCommand(analyzeCommand_1.analyzeLocalCommandRegistration(analyzer)); const { customizers, routesToSuggestOnStartup } = orgVisualizationEndpoints(machine_1.sdmConfigClientFactory(cfg), cfg.http.client.factory, options); cfg.http.customizers.push(...customizers); routesToSuggestOnStartup.forEach(rtsos => { cfg.logging.banner.contributors.push(suggestRoute(rtsos)); }); } else { if (!!options.pushImpactGoal) { sdm.addExtensionPacks(sdm_pack_fingerprints_1.fingerprintSupport({ pushImpactGoal: options.pushImpactGoal, aspects: options.aspects, })); } } } }); } exports.aspectSupport = aspectSupport; function suggestRoute({ title, route }) { return cfg => ({ title, body: `http://localhost:${cfg.http.port}${route}`, }); } function orgVisualizationEndpoints(dbClientFactory, httpClientFactory, options) { const resultStore = machine_1.analysisResultStore(dbClientFactory); const aspectRegistry = new DefaultAspectRegistry_1.DefaultAspectRegistry({ idealStore: resultStore, problemStore: resultStore, aspects: array_1.toArray(options.aspects || []), undesirableUsageChecker: options.undesirableUsageChecker, scorers: array_1.toArray(options.scorers || []), scoreWeightings: options.weightings || exports.DefaultScoreWeightings, }) .withTaggers(...array_1.toArray(options.taggers || [])) .withCombinationTaggers(...array_1.toArray(options.combinationTaggers || [])); const aboutTheApi = api_1.api(resultStore, aspectRegistry); if (!sdm_core_1.isInLocalMode()) { return { routesToSuggestOnStartup: aboutTheApi.routesToSuggestOnStartup, customizers: [aboutTheApi.customizer], }; } const aboutStaticPages = webAppRoutes_1.addWebAppRoutes(aspectRegistry, resultStore, httpClientFactory); return { routesToSuggestOnStartup: [...aboutStaticPages.routesToSuggestOnStartup, ...aboutTheApi.routesToSuggestOnStartup], customizers: [aboutStaticPages.customizer, aboutTheApi.customizer], }; } //# sourceMappingURL=aspectSupport.js.map