4
4
console . error ( "typescript is required. please try 'npm install -g typescript'\n" ) ;
5
5
}
6
6
7
+ import * as ts from "typescript" ;
8
+
7
9
import * as fs from "fs" ;
8
10
import * as path from "path" ;
9
11
import * as commandpost from "commandpost" ;
10
12
11
13
import * as lib from "./" ;
12
14
import { getConfigFileName , readFilesFromTsconfig } from "./utils" ;
13
15
14
- let packageJson = JSON . parse ( fs . readFileSync ( __dirname + "/ ../package.json") . toString ( ) ) ;
16
+ const packageJson = JSON . parse ( fs . readFileSync ( path . join ( __dirname , " ../package.json") ) . toString ( ) ) ;
15
17
16
18
interface RootOptions {
17
19
replace : boolean ;
@@ -27,6 +29,7 @@ interface RootOptions {
27
29
useTslint : string [ ] ;
28
30
useTsfmt : string [ ] ;
29
31
verbose : boolean ;
32
+ version : boolean ;
30
33
}
31
34
32
35
interface RootArguments {
@@ -35,7 +38,6 @@ interface RootArguments {
35
38
36
39
let root = commandpost
37
40
. create < RootOptions , RootArguments > ( "tsfmt [files...]" )
38
- . version ( packageJson . version , "-v, --version" )
39
41
. option ( "-r, --replace" , "replace .ts file" )
40
42
. option ( "--verify" , "checking file format" )
41
43
. option ( "--baseDir <path>" , "config file lookup from <path>" )
@@ -49,6 +51,7 @@ let root = commandpost
49
51
. option ( "--useTslint <path>" , "using specified config file insteaf of tslint.json" )
50
52
. option ( "--useTsfmt <path>" , "using specified config file insteaf of tsfmt.json" )
51
53
. option ( "--verbose" , "makes output more verbose" )
54
+ . option ( "-v, --version" , "output the version number" )
52
55
. action ( ( opts , args ) => {
53
56
let replace = ! ! opts . replace ;
54
57
let verify = ! ! opts . verify ;
@@ -63,6 +66,13 @@ let root = commandpost
63
66
let tslintFile = opts . useTslint [ 0 ] ? path . join ( process . cwd ( ) , opts . useTslint [ 0 ] ) : null ;
64
67
let tsfmtFile = opts . useTsfmt [ 0 ] ? path . join ( process . cwd ( ) , opts . useTsfmt [ 0 ] ) : null ;
65
68
let verbose = ! ! opts . verbose ;
69
+ let version = ! ! opts . version ;
70
+
71
+ if ( version ) {
72
+ console . log ( `tsfmt : ${ packageJson . version } ` ) ;
73
+ console . log ( `tsc : ${ ts . version } ` ) ;
74
+ return ;
75
+ }
66
76
67
77
let files = args . files ;
68
78
let useTsconfig = false ;
0 commit comments