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+ } ;
339var __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"));
844var path_1 = __importDefault ( require ( "path" ) ) ;
945var fs_1 = __importDefault ( require ( "fs" ) ) ;
1046var 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 ) ;
1164var 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 ) ;
0 commit comments