1
1
#!/usr/bin/env node
2
2
3
-
4
3
var yargs = require ( 'yargs' )
5
4
. usage ( 'Usage: check <file> [options]' )
6
5
. describe ( 'v' , 'Verbose flag. Will print statements.' )
7
6
. describe ( 'r' , 'Recrusive flag. Will recursively check required files.' )
8
- . describe ( 'o' , 'Output flag. Will output ast into ASTOutput.js.' ) ;
9
- yargs . check ( function ( fn ) {
10
- if ( ! fn . _ [ 0 ] ) {
11
- yargs . showHelp ( ) ;
12
- process . exit ( ) ;
13
- }
14
- } ) ;
7
+ . describe ( 'o' , 'Output flag. Will output ast into ASTOutput.js.' )
8
+ . showHelpOnFail ( false ) ;
15
9
16
- var argv = yargs . argv ;
10
+ var check = require ( '../check.js' ) ,
11
+ colors = require ( 'colors' ) ,
12
+ fs = require ( 'fs' ) ,
13
+ path = require ( 'path' ) ,
14
+ file = fs . realpathSync ( process . argv [ 2 ] ) ;
17
15
18
- if ( argv . h ) {
16
+ if ( ! file ) {
19
17
yargs . showHelp ( ) ;
20
18
process . exit ( ) ;
19
+ } else if ( ! fs . existsSync ( file ) ) {
20
+ console . error ( fn . _ [ 0 ] , 'doesn\'t exist.' ) ;
21
+ process . exit ( ) ;
21
22
}
22
23
23
- var check = require ( '../check.js' ) ,
24
- colors = require ( 'colors' ) ,
25
- fs = require ( 'fs' ) ,
26
- file = process . argv [ 2 ] ;
27
-
24
+ var argv = yargs . argv ;
28
25
29
- if ( ! fs . existsSync ( file ) ) {
30
- console . error ( file , 'does not exist.' ) ;
26
+ if ( argv . h ) {
27
+ yargs . showHelp ( ) ;
31
28
process . exit ( ) ;
32
29
}
33
30
34
-
35
31
var sinks = module . exports . sinks = require ( '../danger.json' ) . sinks ;
36
32
var sources = module . exports . sources = require ( '../danger.json' ) . sources ;
37
33
@@ -45,4 +41,5 @@ var scope = new check.Scope({
45
41
file : file
46
42
} ) ;
47
43
44
+ console . log ( ) ;
48
45
check . traverse ( check . astFromFile ( scope . file , argv . o ) , scope ) ;
0 commit comments