@@ -13,7 +13,7 @@ const argv = yargs.usage('Usage: $0 [options]').option('fix', {
13
13
function scanFor ( file , maxDepth = 3 ) {
14
14
let pathToFile = path . join ( process . cwd ( ) , file )
15
15
while ( pathToFile . length > file . length + 1 && ! fs . existsSync ( pathToFile ) && maxDepth >= 0 ) {
16
- const parentDir = path . dirname ( path . dirname ( pathToFile ) )
16
+ const parentDir = path . dirname ( pathToFile . substr ( 0 , pathToFile . length - file . length ) )
17
17
pathToFile = path . join ( parentDir , file )
18
18
maxDepth --
19
19
}
@@ -22,9 +22,21 @@ function scanFor(file, maxDepth = 3) {
22
22
}
23
23
24
24
const TSCONFIG_PATH = scanFor ( 'tsconfig.json' )
25
+ const TSLINT_PATH = scanFor ( 'node_modules/.bin/tslint' )
26
+ const ESLINT_PATH = scanFor ( 'node_modules/.bin/eslint' )
27
+ const PRETTIER_PATH = scanFor ( 'node_modules/.bin/prettier' )
28
+ const TSLINTRC_PATH = scanFor ( 'tslint.json' )
25
29
const ESLINTRC_PATH = scanFor ( '.eslintrc' )
26
30
27
- if ( ! TSCONFIG_PATH && ! ESLINTRC_PATH ) {
31
+ if ( ! TSLINT_PATH && ! ESLINT_PATH ) {
32
+ throw new Error ( 'Must have either eslint or tslint installed' )
33
+ }
34
+
35
+ if ( ! PRETTIER_PATH ) {
36
+ throw new Error ( 'Must have prettier installed' )
37
+ }
38
+
39
+ if ( ! TSLINTRC_PATH && ! ESLINTRC_PATH ) {
28
40
throw new Error ( 'Must have either eslint or tslint config' )
29
41
}
30
42
@@ -42,9 +54,10 @@ const directories = `{packages/*/,./}{src/**/,lib/**/,bin/**/,test/**/,}`
42
54
43
55
const lintFixArg = argv . fix ? '--fix' : ''
44
56
const lintCommand = TSCONFIG_PATH
45
- ? `tslint --project . -c ${ TSCONFIG_PATH } `
46
- : `eslint -c ${ ESLINTRC_PATH } '${ directories } *.js'`
57
+ ? `${ TSLINT_PATH } --project . -c ${ TSLINTRC_PATH } `
58
+ : `${ ESLINT_PATH } -c ${ ESLINTRC_PATH } '${ directories } *.js'`
47
59
const lintPassed = exec ( `${ lintCommand } ${ lintFixArg } ` )
48
60
const prettierFixArg = argv . fix ? '--write' : '--list-different'
49
- const prettierPassed = exec ( `prettier ${ prettierFixArg } '${ directories } *.{ts,css,scss,md}'` )
61
+ const prettierFiles = `${ directories } *.{ts,css,scss,md,json}`
62
+ const prettierPassed = exec ( `${ PRETTIER_PATH } ${ prettierFixArg } '${ prettierFiles } '` )
50
63
process . exit ( lintPassed && prettierPassed ? 0 : 1 )
0 commit comments