@@ -7,48 +7,57 @@ const forked = fork(path.join(__dirname, './worker.js'));
77const projectProject = require ( path . join ( '..' , 'package.json' ) ) ;
88const userProjectPackage = require ( path . join ( process . cwd ( ) , 'package.json' ) ) ;
99
10- const defaultStats = {
11- decorators : true ,
12- classes : true ,
13- interfaces : true ,
14- imports : true ,
15- exports : true ,
16- specs : true ,
17- loc : true ,
18- files : true
19- } ;
10+ const AVAILABLE_STATS = [ 'decorators' , 'classes' , 'interfaces' , 'imports' , 'exports' , 'specs' , 'loc' , 'files' ] ;
2011
2112program
2213 . version ( projectProject . version , '-v, --version' )
23- . option ( '-p, --tsconfig <tsconfig>' , 'TypeScript "tsconfig.json" file' , 'tsconfig.json' )
14+ . option ( '-p, --tsconfig <tsconfig>' , 'TypeScript "tsconfig.json" file' , 'tsconfig.json' ) ;
15+
16+ program
2417 . option ( '-l, --loc' , 'Lines of code' )
2518 . option ( '-f, --files' , 'Files' )
2619 . option ( '-d, --decorators' , 'Decorators' )
2720 . option ( '-c, --classes' , 'Classes' )
2821 . option ( '-i, --interfaces' , 'Interfaces' )
2922 . option ( '-m, --imports' , 'Imports' )
3023 . option ( '-e, --exports' , 'Exports' )
31- . option ( '-s, --specs' , 'Specs' )
24+ . option ( '-s, --specs' , 'Specs' ) ;
25+ // .option('--no-files', `Don't include Files`)
26+ // .option('--no-decorators', `Don't include Decorators`)
27+ // .option('--no-classes', `Don't include Classes`)
28+ // .option('--no-interfaces', `Don't include Interfaces`)
29+ // .option('--no-imports', `Don't include Imports`)
30+ // .option('--no-exports', `Don't include Exports`)
31+ // .option('--no-specs', `Don't include Specs`)
32+
33+ program
3234 . on ( '--help' , ( ) => {
3335 console . log ( `
3436 Examples:
37+ $ ts-stats -p src/tsconfig.app.json <boolean>
3538 $ ts-stats --loc --classes
36- $ ts-stats --loc --classes
39+ $ ts-stats --no-loc
3740 $ ts-stats -i -m
3841 ` ) ;
3942 } )
4043 . parse ( process . argv ) ;
4144
4245const tsConfigFilePath = path . join ( process . cwd ( ) , program . tsconfig ) ;
4346const options = process . argv . slice ( 2 ) ;
44- if ( options . length === 0 || program . tsconfig ) {
45- // no options given, set from defaults
46- for ( let opt in defaultStats ) {
47- if ( defaultStats [ opt ] ) {
48- program [ opt ] = true ;
49- }
47+
48+ // if --loc ==> only run loc
49+ // if --loc && --specs ==> only run loc and specs
50+ // if (empty) ==> run all defaults
51+ let userStats = [ ] ;
52+ for ( let k in program ) {
53+ if ( program [ k ] && AVAILABLE_STATS . includes ( k ) ) {
54+ // only keep options that are "stats"
55+ userStats . push ( k ) ;
5056 }
5157}
58+ if ( userStats . length === 0 ) {
59+ userStats = AVAILABLE_STATS ;
60+ }
5261
5362if ( ! fs . existsSync ( tsConfigFilePath ) ) {
5463 console . warn ( `"${ tsConfigFilePath } " file not found. Abort.` ) ;
@@ -63,7 +72,6 @@ spinner.color = 'yellow';
6372spinner . text = `Scanning project${ userProjectPackage ? ': ' + userProjectPackage . name : ' ...' } ` ;
6473spinner . start ( ) ;
6574
66- let userStats = Object . keys ( program ) . filter ( k => k in defaultStats ) ;
6775forked . send ( { tsConfigFilePath, stats : userStats } ) ;
6876
6977forked . on ( 'message' , done => {
0 commit comments