forked from ljharb/eslint-plugin-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
88 lines (74 loc) · 2.17 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var gulp = require('gulp')
, changed = require('gulp-changed')
, babel = require('gulp-babel')
, mocha = require('gulp-mocha')
, path = require('path')
, glob = require('glob')
, fs = require('fs')
var SRC = 'src/**/*.js'
, DEST = 'lib'
gulp.task('src', function () {
return gulp.src(SRC)
.pipe(changed(DEST))
.pipe(babel())
.pipe(gulp.dest(DEST))
})
/**
* Delete any file under `dest` that has no corresponding file in `src`.
* I.E. remove generated files that have been orphaned via deletion of their source.
* @param {string} src
* @param {string} dest
* @param {Function} done - callback upon completion
*/
function wipeExtras(src, dest, done) {
// glob into 'lib' and delete whatever isn't there
glob(dest + '/**/*.js', function (err, files) {
if (err) {
done(err); return
}
function checkFile(index) {
if (index >= files.length) {
done(); return
}
var libFilename = files[index]
, srcFilename = path.resolve(src, path.relative(path.resolve(dest), libFilename))
fs.stat(srcFilename, function (err) {
if (err) {
fs.unlink(libFilename, function () {
checkFile(index + 1)
})
} else {
checkFile(index + 1)
}
})
}
checkFile(0)
})
}
gulp.task('wipe-extras', function (done) {
var unfinished = 2
function megadone(err) {
if (err) { done(err); return }
if (--unfinished === 0) done()
}
wipeExtras('src', DEST, megadone)
wipeExtras('tests/src', 'tests/lib', megadone)
})
gulp.task('prepublish', ['src', 'wipe-extras'])
gulp.task('tests', function () {
return gulp.src('tests/src/**/*.js')
.pipe(changed('tests/lib'))
.pipe(babel())
.pipe(gulp.dest('tests/lib'))
})
// used externally by Istanbul, too
gulp.task('pretest', ['src', 'tests', 'wipe-extras'])
gulp.task('test', ['pretest'], function () {
return gulp.src('tests/lib/**/*.js', { read: false })
.pipe(mocha({ reporter: 'dot', grep: process.env.TEST_GREP }))
// NODE_PATH=./lib mocha --recursive --reporter dot tests/lib/
})
gulp.task('watch-test', function () {
gulp.watch(SRC, ['test'])
gulp.watch('tests/' + SRC, ['test'])
})