-
Notifications
You must be signed in to change notification settings - Fork 15
/
gulpfile.js
123 lines (109 loc) · 3.07 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
112
113
114
115
116
117
118
119
120
121
122
123
var gulp = require('gulp'),
path = require('path'),
jshintReporter = require('jshint-stylish'),
plugins = require('gulp-load-plugins')({
config: path.join(__dirname, 'package.json')
});
var config = {
src: {
files: 'src/**/*.js',
release: 'releases/br-validations.js'
},
test: {
files: 'test/**/*.test.js'
}
};
gulp.task('build', function(done) {
var pkg = require('./package.json');
var header = ['/**',
' * <%= pkg.name %>',
' * <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
'(function (root, factory) {',
' /* istanbul ignore next */',
' if (typeof define === \'function\' && define.amd) {',
' // AMD. Register as an anonymous module.',
' define([], factory);',
' } else if (typeof exports === \'object\') {',
' // Node. Does not work with strict CommonJS, but',
' // only CommonJS-like environments that support module.exports,',
' // like Node.',
' module.exports = factory();',
' } else {',
' // Browser globals (root is window)',
' root.BrV = factory();',
' }',
'}(this, function () {',
''].join('\n');
var footer = ['',
' return {',
' ie: IE,',
' cpf: CPF,',
' cnpj: CNPJ,',
' pis: PIS',
' };',
'}));'].join('\n');
gulp.src(config.src.files)
.pipe(plugins.concat('br-validations.js'))
.pipe(plugins.header(header, {pkg: pkg}))
.pipe(plugins.footer(footer))
.pipe(plugins.concat('br-validations.js'))
.pipe(gulp.dest('./releases'))
.pipe(plugins.uglify())
.pipe(plugins.concat('br-validations.min.js'))
.pipe(gulp.dest('./releases'));
done();
});
gulp.task('jshint', function(done) {
gulp.src(config.src.files)
.pipe(plugins.jshint('.jshintrc'))
.pipe(plugins.jshint.reporter(jshintReporter));
done();
});
function mochaRunnerFactory(reporter) {
return plugins.mocha({
reporter: reporter || 'spec'
});
}
gulp.task('runtestdot', ['jshint', 'build'], function() {
gulp.src(config.test.files, {read: false})
.pipe(mochaRunnerFactory('dot'))
.on('error', console.warn.bind(console));
});
gulp.task('runtest', ['jshint', 'build'], function() {
gulp.src(config.test.files, {read: false})
.pipe(mochaRunnerFactory())
.on('error', console.warn.bind(console));
});
gulp.task('default', ['jshint', 'build', 'runtestdot'], function() {
gulp.watch(config.src.files, ['jshint', 'build', 'runtestdot']);
});
gulp.task('test', ['jshint', 'build', 'runtest']);
gulp.task('test-watch', ['jshint', 'build', 'runtest'], function() {
gulp.watch(config.src.files, ['jshint', 'build', 'runtest']);
});
gulp.task('test-coverage', ['jshint'], function(done) {
gulp.src(config.src.release)
.pipe(plugins.istanbul())
.pipe(plugins.istanbul.hookRequire())
.on('finish', function() {
gulp.src(config.test.files, {
cwd: process.env.PWD,
read: false
})
.pipe(mochaRunnerFactory('spec'))
.pipe(plugins.istanbul.writeReports())
.on('end', function() {
if (process.env.TRAVIS) {
gulp.src('./coverage/**/lcov.info')
.pipe(plugins.coveralls())
.on('end', done);
} else {
done();
}
});
});
});