-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
145 lines (131 loc) · 3.68 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var gulp = require('gulp'),
path = require('path'),
jshintReporter = require('jshint-stylish'),
plugins = require('gulp-load-plugins')({
config: path.join(__dirname, 'package.json')
}),
pkg = require('./package.json'),
fs = require('fs');
var config = {
src: {
files: 'src/**/*.js',
release: 'releases/br-masks.js'
},
test: {
files: 'test/**/*.test.js'
}
};
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([\'string-mask\'], 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(require(\'string-mask\'));',
' } else {',
' // Browser globals (root is window)',
' root.BrM = factory(root.StringMask);',
' }',
'}(this, function (StringMask) {',
' /* istanbul ignore if */',
' if (!StringMask) {',
' throw new Error(\'StringMask not found\');',
' }',
''].join('\n');
var footer = ['',
' return {',
' ie: IE,',
' cpf: CPF,',
' cnpj: CNPJ,',
' cnpjBase: CNPJBASE,',
' phone: PHONE,',
' cep: CEP,',
' finance: FINANCE,',
' nfeAccessKey: NFEACCESSKEY,',
' cpfCnpj: CPFCNPJ',
' };',
'}));'].join('\n');
gulp.task('build:lib', function() {
return gulp.src([
config.src.files
])
.pipe(plugins.concat('br-masks.js'))
.pipe(plugins.header(header, {pkg: pkg}))
.pipe(plugins.footer(footer))
.pipe(gulp.dest('./releases'))
.pipe(plugins.uglify())
.pipe(plugins.concat('br-masks.min.js'))
.pipe(gulp.dest('./releases'));
});
gulp.task('build:standalone', ['build:lib'], function() {
return gulp.src([
'bower_components/string-mask/src/string-mask.js',
'releases/br-masks.js'
])
.pipe(plugins.concat('br-masks-standalone.js'))
.pipe(gulp.dest('./releases'))
.pipe(plugins.uglify())
.pipe(plugins.concat('br-masks-standalone.min.js'))
.pipe(gulp.dest('./releases'));
});
gulp.task('build', ['build:standalone']);
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', 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();
}
});
});
});