@@ -8,12 +8,15 @@ exports.usage = "代码质量检测";
8
8
exports . setOptions = function ( optimist ) {
9
9
optimist . alias ( 'd' , 'dir' ) ;
10
10
optimist . describe ( 'd' , '检测特定目录/文件' ) ;
11
+ optimist . alias ( 't' , 'type' ) ;
12
+ optimist . describe ( 't' , '检测特定目录/文件' ) ;
11
13
} ;
12
14
13
15
exports . run = function ( options ) {
14
16
var cwd = options . cwd ,
15
17
project = this . project ,
16
- dir = options . d || options . dir ;
18
+ dir = options . d || options . dir ,
19
+ lintType = options . t || options . type ;
17
20
18
21
var isGoingToContinue = true ;
19
22
@@ -48,12 +51,26 @@ exports.run = function (options) {
48
51
} ) ;
49
52
}
50
53
51
- if ( isGoingToContinue ) {
52
- async . series ( [ function ( callback ) {
54
+ // lint type
55
+ var lintFileTypes = [ 'js' , 'css' ] ;
56
+ if ( lintType ) {
57
+ if ( lintFileTypes . indexOf ( lintType ) > - 1 ) {
58
+ lintFileTypes = [ lintType ] ;
59
+ } else {
60
+ error ( 'lintType只能为"js"或"css"' ) ;
61
+ process . exit ( 1 ) ;
62
+ }
63
+ }
64
+ var lintFuncs = lintFileTypes . map ( function ( lintFileTypeItem ) {
65
+ return lintFileTypeItem === 'js' ? function ( callback ) {
53
66
return project . lint ( dir , callback ) ;
54
- } , function ( callback ) {
67
+ } : function ( callback ) {
55
68
return project . lintCss ( dir , callback ) ;
56
- } ] , function ( err , results ) {
69
+ } ;
70
+ } ) ;
71
+
72
+ if ( isGoingToContinue ) {
73
+ async . series ( lintFuncs , function ( err , results ) {
57
74
if ( ! err ) {
58
75
if ( results [ 0 ] && results [ 1 ] ) {
59
76
success ( 'All files complete without error.' ) ;
0 commit comments