22/* eslint-disable max-len */
33import yargs from 'yargs' ;
44import { hideBin } from 'yargs/helpers' ;
5- import * as fs from 'fs' ;
6- import { configFile , setConfigFile , validate } from './src/config/file' ;
5+ import { existsSync } from 'fs' ;
6+ import { configFile , setConfigFile , loadConfig } from './src/config/file' ;
77import proxy from './src/proxy' ;
88import service from './src/service' ;
99
@@ -13,37 +13,45 @@ const argv = yargs(hideBin(process.argv))
1313 validate : {
1414 description :
1515 'Check the proxy.config.json file in the current working directory for validation errors.' ,
16- required : false ,
1716 alias : 'v' ,
1817 type : 'boolean' ,
1918 } ,
2019 config : {
2120 description : 'Path to custom git-proxy configuration file.' ,
22- default : 'proxy.config.json' ,
23- required : false ,
2421 alias : 'c' ,
2522 type : 'string' ,
23+ default : 'proxy.config.json' ,
2624 } ,
2725 } )
2826 . strict ( )
2927 . parseSync ( ) ;
3028
31- setConfigFile ( argv . c as string || "" ) ;
29+ setConfigFile ( argv . config ) ;
3230
33- if ( argv . v ) {
34- if ( ! fs . existsSync ( configFile ) ) {
31+ if ( argv . validate ) {
32+ if ( ! existsSync ( configFile ) ) {
3533 console . error (
36- `Config file ${ configFile } doesn't exist, nothing to validate! Did you forget -c/--config?` ,
34+ `✖ Config file ${ configFile } doesn't exist, nothing to validate! Did you forget -c/--config?` ,
3735 ) ;
3836 process . exit ( 1 ) ;
3937 }
4038
41- validate ( ) ;
42- console . log ( `${ configFile } is valid` ) ;
43- process . exit ( 0 ) ;
39+ try {
40+ loadConfig ( ) ;
41+ console . log ( `✔️ ${ configFile } is valid` ) ;
42+ process . exit ( 0 ) ;
43+ } catch ( err : any ) {
44+ console . error ( '✖ Validation Error:' , err . message ) ;
45+ process . exit ( 1 ) ;
46+ }
4447}
4548
46- validate ( ) ;
49+ try {
50+ loadConfig ( ) ;
51+ } catch ( err : any ) {
52+ console . error ( '✖ Errore di validazione:' , err . message ) ;
53+ process . exit ( 1 ) ;
54+ }
4755
4856proxy . start ( ) ;
4957service . start ( ) ;
0 commit comments