forked from toshisam/virgilio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
111 lines (97 loc) · 2.79 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var fs = require('fs');
var del = require('del');
var gulp = require('gulp');
var gutil = require('gulp-util');
var mocha = require('gulp-mocha');
var docco = require('gulp-docco');
var eslint = require('gulp-eslint');
var istanbul = require('gulp-istanbul');
var vinylPaths = require('vinyl-paths');
var exampleToTest = require('gulp-example-to-test');
var replace = require('gulp-replace');
var insert = require('gulp-insert');
var runSequence = require('run-sequence');
function onError(error) {
gutil.log(error);
process.exit(1);
}
// Help module
require('gulp-help')(gulp);
var newVirgilioRegex = /^(.*Virgilio\()(.*)(\).*)$/m;
var exampleTestHeader = fs.readFileSync('./helpers/example-test-header.js');
gulp.task('test', function(callback) {
runSequence(
'lint',
'unit-tests',
'example-tests',
callback
);
});
gulp.task('example-tests', function(callback) {
runSequence(
'clean-example-tests',
'generate-example-tests',
'run-example-tests',
callback
);
});
gulp.task('run-example-tests', function() {
return gulp.src('./example-tests/*.js')
.pipe(mocha({
ui: 'qunit',
reporter: 'spec'
}));
});
gulp.task('generate-example-tests', function() {
return gulp.src('./examples/!(generators).js')
.pipe(exampleToTest())
.pipe(insert.prepend(exampleTestHeader))
.pipe(replace(/Virgilio\(\)/, 'Virgilio({})'))
.pipe(replace(newVirgilioRegex, '$1_.extend(loggerConfig, $2)$3'))
.on('error', onError)
.pipe(gulp.dest('./example-tests'));
});
gulp.task('clean-example-tests', function() {
return gulp.src('./example-tests', { read: false })
.pipe(vinylPaths(del));
});
gulp.task('unit-tests', function() {
// Modules used in tests must be loaded in this task
require('must');
return gulp.src(['./tests/**/*.test.js'])
.pipe(mocha({
reporter: 'spec'
}));
});
gulp.task('coverage', function(callback) {
runSequence(
'setup-istanbul',
'test',
'report-istanbul',
callback
);
});
gulp.task('setup-istanbul', function(callback) {
gulp.src(['lib/**/*.js', 'index.js'])
.pipe(istanbul())
.on('finish', callback);
});
gulp.task('report-istanbul', function() {
return gulp.src(['lib/**/*.js', 'index.js'])
.pipe(istanbul.writeReports());
});
gulp.task('docs', 'Build the documentation', function() {
gulp.src('lib/virgilio.js')
.pipe(docco())
.pipe(gulp.dest('./documentation'));
});
gulp.task('lint', 'Lint the code', function () {
return gulp.src([
'lib/**/*.js',
'examples/**/*.js',
'!examples/generators.js'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});