Skip to content

Commit 09d4c53

Browse files
committed
fix: normalize paths in sheriff dump
1 parent 8da81d9 commit 09d4c53

25 files changed

Lines changed: 879 additions & 184 deletions

backend/detective-0.0.1.tgz

518 KB
Binary file not shown.

backend/dist/express.js

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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+
}

backend/dist/index.js

Lines changed: 16 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,31 @@
11
#!/usr/bin/env node
22
"use strict";
3-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5-
return new (P || (P = Promise))(function (resolve, reject) {
6-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9-
step((generator = generator.apply(thisArg, _arguments || [])).next());
10-
});
11-
};
12-
var __generator = (this && this.__generator) || function (thisArg, body) {
13-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
14-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
15-
function verb(n) { return function (v) { return step([n, v]); }; }
16-
function step(op) {
17-
if (f) throw new TypeError("Generator is already executing.");
18-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
19-
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;
20-
if (y = 0, t) op = [op[0] & 2, t.value];
21-
switch (op[0]) {
22-
case 0: case 1: t = op; break;
23-
case 4: _.label++; return { value: op[1], done: false };
24-
case 5: _.label++; y = op[1]; op = [0]; continue;
25-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
26-
default:
27-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
28-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
29-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
30-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
31-
if (t[2]) _.ops.pop();
32-
_.trys.pop(); continue;
33-
}
34-
op = body.call(thisArg, _);
35-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
36-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37-
}
38-
};
39-
var __importDefault = (this && this.__importDefault) || function (mod) {
40-
return (mod && mod.__esModule) ? mod : { "default": mod };
41-
};
423
Object.defineProperty(exports, "__esModule", { value: true });
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");
484
var parse_options_1 = require("./options/parse-options");
49-
var validate_options_1 = require("./options/validate-options");
50-
var folders_1 = require("./services/folders");
51-
var module_info_1 = require("./services/module-info");
52-
var team_alignment_1 = require("./services/team-alignment");
53-
var open_1 = require("./utils/open");
545
var config_1 = require("./infrastructure/config");
6+
var deps_1 = require("./infrastructure/deps");
7+
var git_1 = require("./infrastructure/git");
8+
var open_1 = require("./utils/open");
9+
var express_1 = require("./express");
5510
var options = (0, parse_options_1.parseOptions)(process.argv.slice(2));
5611
if (options.path) {
5712
process.chdir(options.path);
5813
}
59-
if (!(0, validate_options_1.validateOptions)(options)) {
60-
console.log("Usage: forensic [sheriff-dump] [--port port] [--config path]");
14+
(0, config_1.ensureConfig)(options);
15+
if (!(0, deps_1.inferDeps)(options)) {
16+
console.error("No entry points found. Tried:", (0, deps_1.getEntryGlobs)(options).join(", "));
17+
console.error("\nPlease configured your entry points in .detective/config.json");
6118
process.exit(1);
6219
}
63-
(0, config_1.ensureConfig)(options);
64-
var app = (0, express_1.default)();
65-
app.use(express_1.default.json());
66-
// Route für /api/config - Liefert eine statische JSON-Datei
67-
app.get("/api/config", function (req, res) {
68-
res.sendFile(path_1.default.join((0, process_1.cwd)(), options.config));
69-
});
70-
app.post("/api/config", function (req, res) {
71-
var newConfig = req.body;
72-
var configPath = path_1.default.join((0, process_1.cwd)(), options.config);
73-
fs_1.default.writeFile(configPath, JSON.stringify(newConfig, null, 2), "utf8", function (error) {
74-
if (error) {
75-
return res.status(500).json({ error: error });
76-
}
77-
res.json({});
78-
});
79-
});
80-
app.get("/api/modules", function (req, res) {
81-
try {
82-
var result = (0, module_info_1.calcModuleInfo)(options);
83-
res.json(result);
84-
}
85-
catch (e) {
86-
res.status(500).json(e);
87-
}
88-
});
89-
app.get("/api/folders", function (req, res) {
90-
try {
91-
var result = (0, folders_1.getFolders)();
92-
res.json(result);
93-
}
94-
catch (e) {
95-
res.status(500).json(e);
96-
}
97-
});
98-
app.get("/api/coupling", function (req, res) {
99-
try {
100-
var result = (0, coupling_1.calcCoupling)(options);
101-
res.json(result);
102-
}
103-
catch (e) {
104-
res.status(500).json(e);
105-
}
106-
});
107-
app.get("/api/team-alignment", function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
108-
var byUser, result, e_1;
109-
return __generator(this, function (_a) {
110-
switch (_a.label) {
111-
case 0:
112-
byUser = Boolean(req.query.byUser);
113-
_a.label = 1;
114-
case 1:
115-
_a.trys.push([1, 3, , 4]);
116-
return [4 /*yield*/, (0, team_alignment_1.calcTeamAlignment)(byUser, options)];
117-
case 2:
118-
result = _a.sent();
119-
res.json(result);
120-
return [3 /*break*/, 4];
121-
case 3:
122-
e_1 = _a.sent();
123-
console.log('error', e_1);
124-
res.status(500).json(e_1);
125-
return [3 /*break*/, 4];
126-
case 4: return [2 /*return*/];
127-
}
128-
});
129-
}); });
130-
app.use(express_1.default.static(path_1.default.join(__dirname, '..', 'public')));
131-
app.get("*", function (req, res) {
132-
res.sendFile(path_1.default.join(__dirname, "..", "public", "index.html"));
133-
});
20+
if (!(0, git_1.isRepo)()) {
21+
console.warn("This does not seem to be a git repository.");
22+
console.warn("Most diagrams provided by detective do not work without git!");
23+
}
24+
var app = (0, express_1.setupExpress)(options);
13425
app.listen(options.port, function () {
13526
var url = "http://localhost:".concat(options.port);
13627
console.log("Detective runs at ".concat(url));
137-
(0, open_1.openSync)(url);
28+
if (options.open) {
29+
(0, open_1.openSync)(url);
30+
}
13831
});

backend/dist/infrastructure/config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ exports.ensureConfig = ensureConfig;
88
var path_1 = __importDefault(require("path"));
99
var process_1 = require("process");
1010
var fs_1 = __importDefault(require("fs"));
11+
var DETECTIVE_DIR = '.detective';
1112
var initConfig = {
1213
"scopes": [],
1314
"groups": [],
15+
"--entries-comment": "Define custom entry points here",
16+
"--entries": [],
1417
"--teams": {
1518
"--comment": "Add a teams node with this structure",
1619
"alpha": [
@@ -30,7 +33,13 @@ function loadConfig(options) {
3033
}
3134
function ensureConfig(options) {
3235
var configPath = path_1.default.join((0, process_1.cwd)(), options.config);
36+
ensureDetectiveDir();
3337
if (!fs_1.default.existsSync(configPath)) {
3438
fs_1.default.writeFileSync(configPath, JSON.stringify(initConfig, null, 2), 'utf-8');
3539
}
3640
}
41+
function ensureDetectiveDir() {
42+
if (!fs_1.default.existsSync(DETECTIVE_DIR)) {
43+
fs_1.default.mkdirSync(DETECTIVE_DIR);
44+
}
45+
}

0 commit comments

Comments
 (0)