|
| 1 | +"use strict"; |
| 2 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 3 | + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 4 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 5 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 6 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 7 | + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 8 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 9 | + }); |
| 10 | +}; |
| 11 | +var __generator = (this && this.__generator) || function (thisArg, body) { |
| 12 | + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; |
| 13 | + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; |
| 14 | + function verb(n) { return function (v) { return step([n, v]); }; } |
| 15 | + function step(op) { |
| 16 | + if (f) throw new TypeError("Generator is already executing."); |
| 17 | + while (g && (g = 0, op[0] && (_ = 0)), _) try { |
| 18 | + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; |
| 19 | + if (y = 0, t) op = [op[0] & 2, t.value]; |
| 20 | + switch (op[0]) { |
| 21 | + case 0: case 1: t = op; break; |
| 22 | + case 4: _.label++; return { value: op[1], done: false }; |
| 23 | + case 5: _.label++; y = op[1]; op = [0]; continue; |
| 24 | + case 7: op = _.ops.pop(); _.trys.pop(); continue; |
| 25 | + default: |
| 26 | + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } |
| 27 | + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } |
| 28 | + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } |
| 29 | + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } |
| 30 | + if (t[2]) _.ops.pop(); |
| 31 | + _.trys.pop(); continue; |
| 32 | + } |
| 33 | + op = body.call(thisArg, _); |
| 34 | + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } |
| 35 | + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; |
| 36 | + } |
| 37 | +}; |
| 38 | +var __importDefault = (this && this.__importDefault) || function (mod) { |
| 39 | + return (mod && mod.__esModule) ? mod : { "default": mod }; |
| 40 | +}; |
| 41 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 42 | +exports.setupExpress = setupExpress; |
| 43 | +var express_1 = __importDefault(require("express")); |
| 44 | +var path_1 = __importDefault(require("path")); |
| 45 | +var fs_1 = __importDefault(require("fs")); |
| 46 | +var coupling_1 = require("./services/coupling"); |
| 47 | +var process_1 = require("process"); |
| 48 | +var folders_1 = require("./services/folders"); |
| 49 | +var module_info_1 = require("./services/module-info"); |
| 50 | +var team_alignment_1 = require("./services/team-alignment"); |
| 51 | +var hotspot_1 = require("./services/hotspot"); |
| 52 | +var change_coupling_1 = require("./services/change-coupling"); |
| 53 | +function setupExpress(options) { |
| 54 | + var _this = this; |
| 55 | + var app = (0, express_1.default)(); |
| 56 | + app.use(express_1.default.json()); |
| 57 | + app.get("/api/config", function (req, res) { |
| 58 | + res.sendFile(path_1.default.join((0, process_1.cwd)(), options.config)); |
| 59 | + }); |
| 60 | + app.post("/api/config", function (req, res) { |
| 61 | + var newConfig = req.body; |
| 62 | + var configPath = path_1.default.join((0, process_1.cwd)(), options.config); |
| 63 | + fs_1.default.writeFile(configPath, JSON.stringify(newConfig, null, 2), "utf8", function (error) { |
| 64 | + if (error) { |
| 65 | + return res.status(500).json({ error: error }); |
| 66 | + } |
| 67 | + res.json({}); |
| 68 | + }); |
| 69 | + }); |
| 70 | + app.get("/api/modules", function (req, res) { |
| 71 | + try { |
| 72 | + var result = (0, module_info_1.calcModuleInfo)(options); |
| 73 | + res.json(result); |
| 74 | + } |
| 75 | + catch (e) { |
| 76 | + console.log("error", e); |
| 77 | + res.status(500).json({ message: e.message }); |
| 78 | + } |
| 79 | + }); |
| 80 | + app.get("/api/folders", function (req, res) { |
| 81 | + try { |
| 82 | + var result = (0, folders_1.inferFolders)(options); |
| 83 | + res.json(result); |
| 84 | + } |
| 85 | + catch (e) { |
| 86 | + console.log("error", e); |
| 87 | + res.status(500).json({ message: e.message }); |
| 88 | + } |
| 89 | + }); |
| 90 | + app.get("/api/coupling", function (req, res) { |
| 91 | + try { |
| 92 | + var result = (0, coupling_1.calcCoupling)(options); |
| 93 | + res.json(result); |
| 94 | + } |
| 95 | + catch (e) { |
| 96 | + console.log("error", e); |
| 97 | + res.status(500).json({ message: e.message }); |
| 98 | + } |
| 99 | + }); |
| 100 | + app.get("/api/change-coupling", function (req, res) { return __awaiter(_this, void 0, void 0, function () { |
| 101 | + var limits, result, e_1; |
| 102 | + return __generator(this, function (_a) { |
| 103 | + switch (_a.label) { |
| 104 | + case 0: |
| 105 | + limits = getLimits(req); |
| 106 | + _a.label = 1; |
| 107 | + case 1: |
| 108 | + _a.trys.push([1, 3, , 4]); |
| 109 | + return [4 /*yield*/, (0, change_coupling_1.calcChangeCoupling)(limits, options)]; |
| 110 | + case 2: |
| 111 | + result = _a.sent(); |
| 112 | + res.json(result); |
| 113 | + return [3 /*break*/, 4]; |
| 114 | + case 3: |
| 115 | + e_1 = _a.sent(); |
| 116 | + console.log("error", e_1); |
| 117 | + res.status(500).json({ message: e_1.message }); |
| 118 | + return [3 /*break*/, 4]; |
| 119 | + case 4: return [2 /*return*/]; |
| 120 | + } |
| 121 | + }); |
| 122 | + }); }); |
| 123 | + app.get("/api/team-alignment", function (req, res) { return __awaiter(_this, void 0, void 0, function () { |
| 124 | + var byUser, limits, result, e_2; |
| 125 | + return __generator(this, function (_a) { |
| 126 | + switch (_a.label) { |
| 127 | + case 0: |
| 128 | + byUser = Boolean(req.query.byUser); |
| 129 | + limits = getLimits(req); |
| 130 | + _a.label = 1; |
| 131 | + case 1: |
| 132 | + _a.trys.push([1, 3, , 4]); |
| 133 | + return [4 /*yield*/, (0, team_alignment_1.calcTeamAlignment)(byUser, limits, options)]; |
| 134 | + case 2: |
| 135 | + result = _a.sent(); |
| 136 | + res.json(result); |
| 137 | + return [3 /*break*/, 4]; |
| 138 | + case 3: |
| 139 | + e_2 = _a.sent(); |
| 140 | + console.log("error", e_2); |
| 141 | + res.status(500).json({ message: e_2.message }); |
| 142 | + return [3 /*break*/, 4]; |
| 143 | + case 4: return [2 /*return*/]; |
| 144 | + } |
| 145 | + }); |
| 146 | + }); }); |
| 147 | + app.get("/api/hotspots/aggregated", function (req, res) { return __awaiter(_this, void 0, void 0, function () { |
| 148 | + var minScore, criteria, limits, result, e_3; |
| 149 | + return __generator(this, function (_a) { |
| 150 | + switch (_a.label) { |
| 151 | + case 0: |
| 152 | + minScore = Number(req.query.minScore) || -1; |
| 153 | + criteria = { minScore: minScore, module: "" }; |
| 154 | + limits = getLimits(req); |
| 155 | + _a.label = 1; |
| 156 | + case 1: |
| 157 | + _a.trys.push([1, 3, , 4]); |
| 158 | + return [4 /*yield*/, (0, hotspot_1.aggregateHotspots)(criteria, limits, options)]; |
| 159 | + case 2: |
| 160 | + result = _a.sent(); |
| 161 | + res.json(result); |
| 162 | + return [3 /*break*/, 4]; |
| 163 | + case 3: |
| 164 | + e_3 = _a.sent(); |
| 165 | + console.log("error", e_3); |
| 166 | + res.status(500).json({ message: e_3.message }); |
| 167 | + return [3 /*break*/, 4]; |
| 168 | + case 4: return [2 /*return*/]; |
| 169 | + } |
| 170 | + }); |
| 171 | + }); }); |
| 172 | + app.get("/api/hotspots", function (req, res) { return __awaiter(_this, void 0, void 0, function () { |
| 173 | + var minScore, module, criteria, limits, result, e_4; |
| 174 | + return __generator(this, function (_a) { |
| 175 | + switch (_a.label) { |
| 176 | + case 0: |
| 177 | + minScore = Number(req.query.minScore) || -1; |
| 178 | + module = req.query.module ? String(req.query.module) : ""; |
| 179 | + criteria = { minScore: minScore, module: module }; |
| 180 | + limits = getLimits(req); |
| 181 | + _a.label = 1; |
| 182 | + case 1: |
| 183 | + _a.trys.push([1, 3, , 4]); |
| 184 | + return [4 /*yield*/, (0, hotspot_1.findHotspotFiles)(criteria, limits, options)]; |
| 185 | + case 2: |
| 186 | + result = _a.sent(); |
| 187 | + res.json(result); |
| 188 | + return [3 /*break*/, 4]; |
| 189 | + case 3: |
| 190 | + e_4 = _a.sent(); |
| 191 | + console.log("error", e_4); |
| 192 | + res.status(500).json({ message: e_4.message }); |
| 193 | + return [3 /*break*/, 4]; |
| 194 | + case 4: return [2 /*return*/]; |
| 195 | + } |
| 196 | + }); |
| 197 | + }); }); |
| 198 | + app.use(express_1.default.static(path_1.default.join(__dirname, "..", "public"))); |
| 199 | + app.get("*", function (req, res) { |
| 200 | + res.sendFile(path_1.default.join(__dirname, "..", "public", "index.html")); |
| 201 | + }); |
| 202 | + return app; |
| 203 | +} |
| 204 | +function getLimits(req) { |
| 205 | + return { |
| 206 | + limitCommits: parseInt("" + req.query.limitCommits) || null, |
| 207 | + limitMonths: parseInt("" + req.query.limitMonths) || null, |
| 208 | + }; |
| 209 | +} |
0 commit comments