Skip to content

Commit 7ab78fd

Browse files
committed
feat: small improvements for v0.0.1
1 parent a1f26c1 commit 7ab78fd

48 files changed

Lines changed: 1028 additions & 124 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/.detective/config.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"scopes": [
3+
"src/infrastructure",
4+
"src/model",
5+
"src/options"
6+
],
7+
"groups": [
8+
"src"
9+
],
10+
"teams": {
11+
"alpha": [
12+
"Manfred Steyer"
13+
],
14+
"beta": [
15+
"Hugo"
16+
]
17+
}
18+
}

backend/.forensic/config.json

Lines changed: 0 additions & 30 deletions
This file was deleted.

backend/detective-0.0.1.tgz

2.74 MB
Binary file not shown.

backend/dist/index.js

Lines changed: 112 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
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+
};
339
var __importDefault = (this && this.__importDefault) || function (mod) {
440
return (mod && mod.__esModule) ? mod : { "default": mod };
541
};
@@ -8,37 +44,95 @@ var express_1 = __importDefault(require("express"));
844
var path_1 = __importDefault(require("path"));
945
var fs_1 = __importDefault(require("fs"));
1046
var coupling_1 = require("./services/coupling");
47+
var process_1 = require("process");
48+
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");
54+
var config_1 = require("./infrastructure/config");
55+
var options = (0, parse_options_1.parseOptions)(process.argv.slice(2));
56+
if (options.path) {
57+
process.chdir(options.path);
58+
}
59+
if (!(0, validate_options_1.validateOptions)(options)) {
60+
console.log("Usage: forensic [sheriff-dump] [--port port] [--config path]");
61+
process.exit(1);
62+
}
63+
(0, config_1.ensureConfig)(options);
1164
var app = (0, express_1.default)();
65+
app.use(express_1.default.json());
1266
// Route für /api/config - Liefert eine statische JSON-Datei
13-
app.get('/api/config', function (req, res) {
14-
res.sendFile(path_1.default.join(__dirname, 'data', 'config.json'));
67+
app.get("/api/config", function (req, res) {
68+
res.sendFile(path_1.default.join((0, process_1.cwd)(), options.config));
1569
});
16-
app.post('/api/config', function (req, res) {
70+
app.post("/api/config", function (req, res) {
1771
var newConfig = req.body;
18-
var configPath = path_1.default.join(__dirname, 'data', 'config.json');
19-
fs_1.default.writeFile(configPath, JSON.stringify(newConfig, null, 2), 'utf8', function (err) {
20-
if (err) {
21-
return res.status(500).json({ error: 'Fehler beim Speichern der Konfiguration' });
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 });
2276
}
23-
res.json({ message: 'Konfiguration erfolgreich aktualisiert' });
77+
res.json({});
2478
});
2579
});
26-
app.get('/api/coupling', function (req, res) {
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) {
2799
try {
28-
var result = (0, coupling_1.calcCoupling)();
100+
var result = (0, coupling_1.calcCoupling)(options);
29101
res.json(result);
30102
}
31103
catch (e) {
32104
res.status(500).json(e);
33105
}
34106
});
35-
// Route für / - Liefert eine index.html-Datei
36-
app.get('/', function (req, res) {
37-
res.sendFile(path_1.default.join(__dirname, '..', 'public', 'index.html'));
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"));
38133
});
39-
// Server starten
40-
var PORT = process.env.PORT || 3000;
41-
app.listen(PORT, function () {
42-
console.log("Server l\u00E4uft auf http://localhost:".concat(PORT));
134+
app.listen(options.port, function () {
135+
var url = "http://localhost:".concat(options.port);
136+
console.log("Detective runs at ".concat(url));
137+
(0, open_1.openSync)(url);
43138
});
44-
console.log('env', process.env.NODE_ENV);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.loadConfig = loadConfig;
7+
exports.ensureConfig = ensureConfig;
8+
var path_1 = __importDefault(require("path"));
9+
var process_1 = require("process");
10+
var fs_1 = __importDefault(require("fs"));
11+
var initConfig = {
12+
"scopes": [],
13+
"groups": [],
14+
"--teams": {
15+
"--comment": "Add a teams node with this structure",
16+
"alpha": [
17+
"John Doe",
18+
"Jane Doe"
19+
],
20+
"beta": [
21+
"Max Muster",
22+
"Susi Sorglos",
23+
]
24+
}
25+
};
26+
function loadConfig(options) {
27+
var configPath = path_1.default.join((0, process_1.cwd)(), options.config);
28+
var config = JSON.parse(fs_1.default.readFileSync(configPath, "utf-8"));
29+
return config;
30+
}
31+
function ensureConfig(options) {
32+
var configPath = path_1.default.join((0, process_1.cwd)(), options.config);
33+
if (!fs_1.default.existsSync(configPath)) {
34+
fs_1.default.writeFileSync(configPath, JSON.stringify(initConfig, null, 2), 'utf-8');
35+
}
36+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.loadDeps = loadDeps;
7+
var path_1 = __importDefault(require("path"));
8+
var process_1 = require("process");
9+
var fs_1 = __importDefault(require("fs"));
10+
function loadDeps(options) {
11+
var depsPath = path_1.default.join((0, process_1.cwd)(), options.sheriffDump);
12+
var deps = JSON.parse(fs_1.default.readFileSync(depsPath, "utf-8"));
13+
return deps;
14+
}

backend/dist/infrastructure/git.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.getGitLog = getGitLog;
4+
var spawn = require("child_process").spawn;
5+
function getGitLog() {
6+
return new Promise(function (resolve, reject) {
7+
try {
8+
var subprocess = spawn("git", ["log", '--numstat', '--pretty=format:"%an <%ae>,%ad"']);
9+
var text_1 = "";
10+
var error_1 = "";
11+
subprocess.stdout.on("data", function (data) {
12+
text_1 += data;
13+
});
14+
subprocess.stderr.on("data", function (data) {
15+
error_1 += data;
16+
});
17+
subprocess.on("exit", function (code) {
18+
if (code || error_1) {
19+
reject('Error running git: ' + error_1);
20+
}
21+
else {
22+
resolve(text_1);
23+
}
24+
});
25+
}
26+
catch (e) {
27+
reject('Error running git: ' + e);
28+
}
29+
});
30+
}

backend/dist/options/options.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.defaultOptions = void 0;
4+
exports.defaultOptions = {
5+
sheriffDump: '.detective/deps.json',
6+
config: '.detective/config.json',
7+
path: '',
8+
port: 3334
9+
};

0 commit comments

Comments
 (0)