@@ -14,6 +14,7 @@ const relative = require('relative');
14
14
const ts = require ( 'gulp-typescript' ) ;
15
15
const watch = require ( 'gulp-watch' ) ;
16
16
const cp = require ( 'child_process' ) ;
17
+ const colors = require ( 'colors/safe' ) ;
17
18
18
19
/**
19
20
* Hygiene works by creating cascading subsets of all our files and
@@ -179,7 +180,7 @@ const hygiene = exports.hygiene = (some, options) => {
179
180
}
180
181
} ;
181
182
}
182
- const tsProject = ts . createProject ( 'tsconfig.json' , { strict : true } ) ;
183
+ const tsProject = ts . createProject ( 'tsconfig.json' , { strict : true , noImplicitAny : false } ) ;
183
184
const reporter = customReporter ( ) ;
184
185
return tsProject ( reporter ) ;
185
186
}
@@ -203,7 +204,7 @@ const hygiene = exports.hygiene = (some, options) => {
203
204
return typescript
204
205
. pipe ( es . through ( null , function ( ) {
205
206
if ( errorCount > 0 ) {
206
- this . emit ( 'error' , 'Hygiene failed with ' + errorCount + ' errors. Check \'gulpfile.js\'.' ) ;
207
+ this . emit ( 'error' , 'Hygiene failed with ' + errorCount + ' errors 👎 . Check \'gulpfile.js\'.' ) ;
207
208
} else {
208
209
this . emit ( 'end' ) ;
209
210
}
@@ -214,18 +215,23 @@ gulp.task('hygiene', () => hygiene());
214
215
215
216
gulp . task ( 'hygiene-watch' , function ( ) {
216
217
return watch ( all , function ( ) {
218
+ console . clear ( ) ;
219
+ console . log ( 'Checking hygiene...' ) ;
217
220
run ( true , true ) ;
218
221
} ) ;
219
222
} ) ;
220
223
221
224
function run ( lintOnlyModifiedFiles , doNotExit ) {
222
225
function exitProcessOnError ( ex ) {
223
226
console . error ( ) ;
224
- console . error ( ex ) ;
227
+ console . error ( colors . red ( ex ) ) ;
225
228
if ( ! doNotExit ) {
226
229
process . exit ( 1 ) ;
227
230
}
228
- }
231
+ if ( lintOnlyModifiedFiles && doNotExit ) {
232
+ console . log ( 'Watching for changes...' ) ;
233
+ }
234
+ }
229
235
process . on ( 'unhandledRejection' , ( reason , p ) => {
230
236
console . log ( 'Unhandled Rejection at: Promise' , p , 'reason:' , reason ) ;
231
237
exitProcessOnError ( ) ;
@@ -239,20 +245,62 @@ function run(lintOnlyModifiedFiles, doNotExit) {
239
245
} ) . on ( 'error' , exitProcessOnError ) ;
240
246
}
241
247
242
- const cmd = lintOnlyModifiedFiles ? 'git diff --name-only' : 'git diff --cached --name-only' ;
243
- cp . exec ( cmd , {
248
+ let filesPromise ;
249
+ if ( lintOnlyModifiedFiles ) {
250
+ filesPromise = Promise . all ( [ getCachedFiles ( ) , getModifiedFiles ( ) ] ) . then ( filesList => {
251
+ const files1 = filesList [ 0 ] ;
252
+ const files2 = filesList [ 1 ] ;
253
+ files2 . forEach ( file => {
254
+ if ( files1 . indexOf ( file ) === - 1 ) {
255
+ files1 . push ( file ) ;
256
+ }
257
+ } ) ;
258
+ return files1 ;
259
+ } ) ;
260
+ } else {
261
+ filesPromise = getCachedFiles ( ) ;
262
+ }
263
+ filesPromise . then ( files => {
264
+ hygiene ( files , {
265
+ skipEOL : skipEOL
266
+ } )
267
+ . on ( 'end' , ( ) => {
268
+ if ( lintOnlyModifiedFiles && doNotExit ) {
269
+ console . log ( colors . green ( 'Hygiene passed with 0 errors 👍.' ) ) ;
270
+ console . log ( 'Watching for changes...' ) ;
271
+ }
272
+ } )
273
+ . on ( 'error' , exitProcessOnError ) ;
274
+ } ) . catch ( exitProcessOnError ) ;
275
+ } ) ;
276
+ }
277
+ function getCachedFiles ( ) {
278
+ return new Promise ( resolve => {
279
+ cp . exec ( 'git diff --cached --name-only' , {
244
280
maxBuffer : 2000 * 1024
245
281
} , ( err , out ) => {
246
282
if ( err ) {
247
- exitProcessOnError ( err ) ;
283
+ return reject ( err ) ;
248
284
}
249
285
const some = out
250
286
. split ( / \r ? \n / )
251
287
. filter ( l => ! ! l ) ;
252
-
253
- hygiene ( some , {
254
- skipEOL : skipEOL
255
- } ) . on ( 'error' , exitProcessOnError ) ;
288
+ resolve ( some ) ;
289
+ } ) ;
290
+ } ) ;
291
+ }
292
+ function getModifiedFiles ( ) {
293
+ return new Promise ( resolve => {
294
+ cp . exec ( 'git diff --name-only' , {
295
+ maxBuffer : 2000 * 1024
296
+ } , ( err , out ) => {
297
+ if ( err ) {
298
+ return reject ( err ) ;
299
+ }
300
+ const some = out
301
+ . split ( / \r ? \n / )
302
+ . filter ( l => ! ! l ) ;
303
+ resolve ( some ) ;
256
304
} ) ;
257
305
} ) ;
258
306
}
0 commit comments