@@ -30,7 +30,7 @@ var Project = function () {
30
30
cwd : this . cwd
31
31
} ) [ 0 ] || '' ;
32
32
this . extendConfig = this . configFile && this . configFile . match ( / y k i t \. ( [ \w \. ] + ) \. j s / ) && this . configFile . match ( / y k i t \. ( [ \w \. ] + ) \. j s / ) [ 1 ] && this . configFile . match ( / y k i t \. ( [ \w \. ] + ) \. j s / ) [ 1 ] . replace ( / \. / g, '-' ) ;
33
- this . ignores = [ "node_modules/**/*" , "bower_components/**/*" , "dev/**/*" , "prd/**/*" ] ;
33
+ this . ignores = [ "node_modules/**/*" , "bower_components/**/*" , "dev/**/*" , "prd/**/*" , ".ykit_cache/**/*" ] ;
34
34
this . cachePath = this . _isCacheDirExists ( cwd ) || '' ;
35
35
36
36
this . readConfig ( ) ;
@@ -48,6 +48,16 @@ var Project = function () {
48
48
this . commands = this . commands . concat ( nextCommands ) ;
49
49
}
50
50
}
51
+ } , {
52
+ key : 'setEslintConfig' ,
53
+ value : function setEslintConfig ( projectEslintConfig ) {
54
+ extend ( true , this . eslintConfig , projectEslintConfig ) ;
55
+ }
56
+ } , {
57
+ key : 'setStylelintConfig' ,
58
+ value : function setStylelintConfig ( projectStylelintConfig ) {
59
+ extend ( true , this . stylelintConfig , projectStylelintConfig ) ;
60
+ }
51
61
} , {
52
62
key : 'readConfig' ,
53
63
value : function readConfig ( options ) {
@@ -64,6 +74,8 @@ var Project = function () {
64
74
setGroupExports : this . config . setGroupExports . bind ( this . config ) ,
65
75
setSync : this . config . setSync . bind ( this . config ) ,
66
76
setCommands : this . setCommands . bind ( this ) ,
77
+ setEslintConfig : this . setEslintConfig . bind ( this ) ,
78
+ setStylelintConfig : this . setStylelintConfig . bind ( this ) ,
67
79
config : this . config . getConfig ( ) ,
68
80
commands : this . commands ,
69
81
middlewares : this . middlewares ,
@@ -222,16 +234,22 @@ var Project = function () {
222
234
} , {
223
235
key : 'lint' ,
224
236
value : function lint ( dir , callback ) {
237
+ warn ( 'Linting JS Files ...' ) ;
238
+
225
239
var CLIEngine = require ( 'eslint' ) . CLIEngine ;
226
240
227
- warn ( 'Linting JS Files ...' ) ;
228
- this . eslintConfig . useEslintrc = false ;
241
+ // 如果有本地eslint优先使用本地eslint
242
+ if ( requireg ( sysPath . join ( this . cwd , 'node_modules/' , 'eslint' ) ) ) {
243
+ CLIEngine = requireg ( sysPath . join ( this . cwd , 'node_modules/' , 'eslint' ) ) . CLIEngine ;
244
+ }
229
245
230
- extend ( true , this . eslintConfig , this . config . _config . eslintConfig ) ;
246
+ // prepare eslint config file
247
+ var configFilePath = sysPath . join ( __dirname , '../../cache' , '.eslintrc.json' ) ;
248
+ fs . writeFileSync ( configFilePath , JSON . stringify ( this . eslintConfig ) ) ;
249
+ this . eslintConfig . useEslintrc = false ;
250
+ this . eslintConfig . configFile = configFilePath ;
231
251
232
- var cliengine = this . eslintConfig . linter || CLIEngine ,
233
- // 优先使用项目配置的linter
234
- cli = new cliengine ( this . eslintConfig ) ,
252
+ var cli = new CLIEngine ( this . eslintConfig ) ,
235
253
report = cli . executeOnFiles ( this . _getLintFiles ( dir , 'js' ) ) ,
236
254
formatter = cli . getFormatter ( ) ;
237
255
0 commit comments