File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919 "optimist" : " ^0.6.1"
2020 },
2121 "bin" : {
22- "cleanup-package-json " : " ./dist/cli.js"
22+ "cpj " : " ./dist/cli.js"
2323 }
24- }
24+ }
Original file line number Diff line number Diff line change @@ -3,15 +3,15 @@ cleanup-package-json
33
44## Get started
55``` sh
6- $ npm install cleanup-package-json -g
6+ $ npm install cpj -g
77```
88
99## Features
1010- Removes unnecessary parts of ` package.json ` .
1111
1212## Usage
1313``` sh
14- $ cleanup-package-json -h
14+ $ cpj -h
1515```
1616
1717### Examples
@@ -20,12 +20,12 @@ _Default config:_
2020Default config name is ` cpj.config.json ` .
2121
2222``` sh
23- $ cleanup-package-json
23+ $ cpj
2424```
2525
2626_ With custom file config:_
2727``` sh
28- $ cleanup-package-json -c custom-config.json
28+ $ cpj -c custom-config.json
2929```
3030
3131## Config example
Original file line number Diff line number Diff line change @@ -16,16 +16,27 @@ let opt = optimist
1616 alias : 'config' ,
1717 describe : 'Path to config.'
1818 } )
19+ . options ( 'v' , {
20+ alias : 'version' ,
21+ describe : 'Prints version.'
22+ } )
1923 . usage ( 'Usage: cleanup-package-json [options]' )
2024 . boolean ( [ 'h' , 'v' ] )
2125 . string ( [ 'c' ] ) ;
2226
2327class Cli {
28+ private package : Contracts . PackageJSONSkeleton = { } ;
29+
2430 constructor ( opt : optimist . Parser ) {
31+ let packageJSONPath = path . join ( __dirname , '../package.json' ) ;
32+ this . package = JSON . parse ( fs . readFileSync ( packageJSONPath , 'utf8' ) ) ;
2533 let argv = opt . argv as Contracts . Arguments ;
2634
2735 if ( argv . help ) {
36+ this . printVersion ( ) ;
2837 console . info ( opt . help ( ) ) ;
38+ } else if ( argv . version ) {
39+ this . printVersion ( ) ;
2940 } else {
3041 let configFileName = argv . config || DEFAULT_CONFIG_NAME ;
3142 this . main ( configFileName ) ;
@@ -45,7 +56,7 @@ class Cli {
4556 let cleanup = new Cleanup ( config ) ;
4657 cleanup . Clean ( ) ;
4758 console . info ( '[Success] Done cleaning up' ) ;
48- } catch ( e ) {
59+ } catch ( e ) {
4960 this . throwError ( `[Failed] ${ e } ` ) ;
5061 }
5162 } else {
@@ -89,6 +100,10 @@ class Cli {
89100 } ) ;
90101 } ) ;
91102 }
103+
104+ private printVersion ( ) {
105+ console . info ( `Version ${ this . package [ 'version' ] } \n` ) ;
106+ }
92107}
93108
94109new Cli ( opt ) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ export interface Arguments {
22 [ arg : string ] : string | boolean ;
33 config : string ;
44 help : boolean ;
5+ version : boolean ;
56}
67
78export interface ConfigItems {
You can’t perform that action at this time.
0 commit comments