File tree Expand file tree Collapse file tree 5 files changed +32
-35
lines changed Expand file tree Collapse file tree 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");
55import path = require( "path" ) ;
66
77import lib = require( "./index" ) ;
8+ import utils = require( "./utils" ) ;
89
910var packageJson = JSON . parse ( fs . readFileSync ( __dirname + "/../package.json" ) . toString ( ) ) ;
1011
@@ -41,8 +42,13 @@ var root = commandpost
4142 var tsfmt = ! ! opts . tsfmt ;
4243
4344 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+ }
4652 }
4753
4854 if ( files . length === 0 && ! opts . stdin ) {
@@ -54,6 +60,7 @@ var root = commandpost
5460 console . log ( "replace: " + ( replace ? "ON" : "OFF" ) ) ;
5561 console . log ( "verify: " + ( verify ? "ON" : "OFF" ) ) ;
5662 console . log ( "stdin: " + ( stdin ? "ON" : "OFF" ) ) ;
63+ console . log ( "tsconfig: " + ( useTsconfig ? "ON" : "OFF" ) ) ;
5764 console . log ( "tslint: " + ( tslint ? "ON" : "OFF" ) ) ;
5865 console . log ( "editorconfig: " + ( editorconfig ? "ON" : "OFF" ) ) ;
5966 console . log ( "tsfmt: " + ( tsfmt ? "ON" : "OFF" ) ) ;
Original file line number Diff line number Diff line change @@ -5,21 +5,7 @@ import ts = require("typescript");
55import path = require( "path" ) ;
66import fs = require( "fs" ) ;
77
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" ) ;
239
2410interface TsfmtSettings {
2511 // from FormatCodeOptions
@@ -50,7 +36,7 @@ interface TsfmtSettings {
5036export function makeFormatCodeOptions ( fileName : string , options : ts . FormatCodeOptions ) : ts . FormatCodeOptions {
5137 "use strict" ;
5238
53- var configFileName = getConfigFileName ( path . resolve ( fileName ) , "tsfmt.json" ) ;
39+ var configFileName = utils . getConfigFileName ( path . dirname ( path . resolve ( fileName ) ) , "tsfmt.json" ) ;
5440 if ( ! configFileName ) {
5541 return options ;
5642 }
Original file line number Diff line number Diff line change @@ -5,21 +5,7 @@ import ts = require("typescript");
55import path = require( "path" ) ;
66import fs = require( "fs" ) ;
77
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" ) ;
239
2410interface TslintSettings {
2511 rules : {
@@ -42,7 +28,7 @@ interface TslintSettings {
4228export function makeFormatCodeOptions ( fileName : string , options : ts . FormatCodeOptions ) : ts . FormatCodeOptions {
4329 "use strict" ;
4430
45- var configFileName = getConfigFileName ( path . resolve ( fileName ) , "tslint.json" ) ;
31+ var configFileName = utils . getConfigFileName ( path . dirname ( path . resolve ( fileName ) ) , "tslint.json" ) ;
4632 if ( ! configFileName ) {
4733 return options ;
4834 }
Original file line number Diff line number Diff line change 22
33import ts = require( "typescript" ) ;
44
5+ import fs = require( "fs" ) ;
6+ import path = require( "path" ) ;
7+
58export function createDefaultFormatCodeOptions ( ) : ts . FormatCodeOptions {
69 "use strict" ;
710
@@ -21,3 +24,18 @@ export function createDefaultFormatCodeOptions(): ts.FormatCodeOptions {
2124 PlaceOpenBraceOnNewLineForControlBlocks : false
2225 } ;
2326}
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 4141 " ./typings/power-assert/power-assert.d.ts" ,
4242 " ./node_modules/typescript/lib/lib.es6.d.ts"
4343 ]
44- }
44+ }
You can’t perform that action at this time.
0 commit comments