22/* eslint-disable max-len */
33import yargs from 'yargs' ;
44import { hideBin } from 'yargs/helpers' ;
5- import { existsSync } from 'fs' ;
6- import { configFile , setConfigFile , loadConfig } from './src/config/file' ;
5+ import * as fs from 'fs' ;
6+ import { configFile , setConfigFile , validate } from './src/config/file' ;
77import proxy from './src/proxy' ;
88import service from './src/service' ;
99
@@ -13,45 +13,37 @@ 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 ,
1617 alias : 'v' ,
1718 type : 'boolean' ,
1819 } ,
1920 config : {
2021 description : 'Path to custom git-proxy configuration file.' ,
22+ default : 'proxy.config.json' ,
23+ required : false ,
2124 alias : 'c' ,
2225 type : 'string' ,
23- default : 'proxy.config.json' ,
2426 } ,
2527 } )
2628 . strict ( )
2729 . parseSync ( ) ;
2830
29- setConfigFile ( argv . config ) ;
31+ setConfigFile ( ( argv . c as string ) || '' ) ;
3032
31- if ( argv . validate ) {
32- if ( ! existsSync ( configFile ) ) {
33+ if ( argv . v ) {
34+ if ( ! fs . existsSync ( configFile ) ) {
3335 console . error (
34- `✖ Config file ${ configFile } doesn't exist, nothing to validate! Did you forget -c/--config?` ,
36+ `Config file ${ configFile } doesn't exist, nothing to validate! Did you forget -c/--config?` ,
3537 ) ;
3638 process . exit ( 1 ) ;
3739 }
3840
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- }
41+ validate ( ) ;
42+ console . log ( `${ configFile } is valid` ) ;
43+ process . exit ( 0 ) ;
4744}
4845
49- try {
50- loadConfig ( ) ;
51- } catch ( err : any ) {
52- console . error ( '✖ Validation Error:' , err . message ) ;
53- process . exit ( 1 ) ;
54- }
46+ validate ( ) ;
5547
5648proxy . start ( ) ;
5749service . start ( ) ;
0 commit comments