File tree 5 files changed +32
-35
lines changed
5 files changed +32
-35
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import commandpost = require("commandpost");
5
5
import path = require( "path" ) ;
6
6
7
7
import lib = require( "./index" ) ;
8
+ import utils = require( "./utils" ) ;
8
9
9
10
var packageJson = JSON . parse ( fs . readFileSync ( __dirname + "/../package.json" ) . toString ( ) ) ;
10
11
@@ -41,8 +42,13 @@ var root = commandpost
41
42
var tsfmt = ! ! opts . tsfmt ;
42
43
43
44
var files = args . files ;
44
- if ( files . length === 0 && fs . existsSync ( "tsconfig.json" ) ) {
45
- files = readFilesFromTsconfig ( "tsconfig.json" ) ;
45
+ var useTsconfig = false ;
46
+ if ( files . length === 0 ) {
47
+ var configFileName = utils . getConfigFileName ( process . cwd ( ) , "tsconfig.json" ) ;
48
+ if ( configFileName ) {
49
+ files = readFilesFromTsconfig ( configFileName ) ;
50
+ useTsconfig = true ;
51
+ }
46
52
}
47
53
48
54
if ( files . length === 0 && ! opts . stdin ) {
@@ -54,6 +60,7 @@ var root = commandpost
54
60
console . log ( "replace: " + ( replace ? "ON" : "OFF" ) ) ;
55
61
console . log ( "verify: " + ( verify ? "ON" : "OFF" ) ) ;
56
62
console . log ( "stdin: " + ( stdin ? "ON" : "OFF" ) ) ;
63
+ console . log ( "tsconfig: " + ( useTsconfig ? "ON" : "OFF" ) ) ;
57
64
console . log ( "tslint: " + ( tslint ? "ON" : "OFF" ) ) ;
58
65
console . log ( "editorconfig: " + ( editorconfig ? "ON" : "OFF" ) ) ;
59
66
console . log ( "tsfmt: " + ( tsfmt ? "ON" : "OFF" ) ) ;
Original file line number Diff line number Diff line change @@ -5,21 +5,7 @@ import ts = require("typescript");
5
5
import path = require( "path" ) ;
6
6
import fs = require( "fs" ) ;
7
7
8
- function getConfigFileName ( baseFileName : string , configFileName : string ) : string {
9
- "use strict" ;
10
-
11
- var baseDir = path . dirname ( baseFileName ) ;
12
-
13
- if ( fs . existsSync ( baseDir + path . sep + configFileName ) ) {
14
- return baseDir + path . sep + configFileName ;
15
- }
16
-
17
- if ( baseDir . length === path . dirname ( baseDir ) . length ) {
18
- return null ;
19
- }
20
-
21
- return getConfigFileName ( baseDir , configFileName ) ;
22
- }
8
+ import utils = require( "../utils" ) ;
23
9
24
10
interface TsfmtSettings {
25
11
// from FormatCodeOptions
@@ -50,7 +36,7 @@ interface TsfmtSettings {
50
36
export function makeFormatCodeOptions ( fileName : string , options : ts . FormatCodeOptions ) : ts . FormatCodeOptions {
51
37
"use strict" ;
52
38
53
- var configFileName = getConfigFileName ( path . resolve ( fileName ) , "tsfmt.json" ) ;
39
+ var configFileName = utils . getConfigFileName ( path . dirname ( path . resolve ( fileName ) ) , "tsfmt.json" ) ;
54
40
if ( ! configFileName ) {
55
41
return options ;
56
42
}
Original file line number Diff line number Diff line change @@ -5,21 +5,7 @@ import ts = require("typescript");
5
5
import path = require( "path" ) ;
6
6
import fs = require( "fs" ) ;
7
7
8
- function getConfigFileName ( baseFileName : string , configFileName : string ) : string {
9
- "use strict" ;
10
-
11
- var baseDir = path . dirname ( baseFileName ) ;
12
-
13
- if ( fs . existsSync ( baseDir + path . sep + configFileName ) ) {
14
- return baseDir + path . sep + configFileName ;
15
- }
16
-
17
- if ( baseDir . length === path . dirname ( baseDir ) . length ) {
18
- return null ;
19
- }
20
-
21
- return getConfigFileName ( baseDir , configFileName ) ;
22
- }
8
+ import utils = require( "../utils" ) ;
23
9
24
10
interface TslintSettings {
25
11
rules : {
@@ -42,7 +28,7 @@ interface TslintSettings {
42
28
export function makeFormatCodeOptions ( fileName : string , options : ts . FormatCodeOptions ) : ts . FormatCodeOptions {
43
29
"use strict" ;
44
30
45
- var configFileName = getConfigFileName ( path . resolve ( fileName ) , "tslint.json" ) ;
31
+ var configFileName = utils . getConfigFileName ( path . dirname ( path . resolve ( fileName ) ) , "tslint.json" ) ;
46
32
if ( ! configFileName ) {
47
33
return options ;
48
34
}
Original file line number Diff line number Diff line change 2
2
3
3
import ts = require( "typescript" ) ;
4
4
5
+ import fs = require( "fs" ) ;
6
+ import path = require( "path" ) ;
7
+
5
8
export function createDefaultFormatCodeOptions ( ) : ts . FormatCodeOptions {
6
9
"use strict" ;
7
10
@@ -21,3 +24,18 @@ export function createDefaultFormatCodeOptions(): ts.FormatCodeOptions {
21
24
PlaceOpenBraceOnNewLineForControlBlocks : false
22
25
} ;
23
26
}
27
+
28
+ export function getConfigFileName ( baseDir : string , configFileName : string ) : string {
29
+ "use strict" ;
30
+
31
+ var configFilePath = path . resolve ( baseDir , configFileName ) ;
32
+ if ( fs . existsSync ( configFilePath ) ) {
33
+ return configFilePath ;
34
+ }
35
+
36
+ if ( baseDir . length === path . dirname ( baseDir ) . length ) {
37
+ return null ;
38
+ }
39
+
40
+ return getConfigFileName ( path . resolve ( baseDir , "../" ) , configFileName ) ;
41
+ }
Original file line number Diff line number Diff line change 41
41
" ./typings/power-assert/power-assert.d.ts" ,
42
42
" ./node_modules/typescript/lib/lib.es6.d.ts"
43
43
]
44
- }
44
+ }
You can’t perform that action at this time.
0 commit comments