-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
65 lines (56 loc) · 1.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
'use strict';
var fs = require('fs');
var gulp = require('gulp');
var karma = require('karma').server;
var jshint = require('gulp-jshint');
var header = require('gulp-header');
var rename = require('gulp-rename');
var del = require('del');
var uglify = require('gulp-uglify');
var plumber = require('gulp-plumber');
var config = {
pkg : JSON.parse(fs.readFileSync('./package.json')),
banner:
'/*!\n' +
' * <%= pkg.name %>\n' +
' * <%= pkg.homepage %>\n' +
' * Version: <%= pkg.version %> - <%= timestamp %>\n' +
' * License: <%= pkg.license %>\n' +
' */\n\n\n'
};
gulp.task('default', ['build','test']);
gulp.task('build', ['scripts']);
gulp.task('test', ['build', 'karma']);
gulp.task('watch', ['build','karma-watch'], function() {
gulp.watch(['src/**/*.{js,html}'], ['build']);
});
gulp.task('clean', function(cb) {
del(['dist'], cb);
});
gulp.task('scripts', ['clean'], function() {
gulp.src(['src/itvalidate.js'])
.pipe(plumber({
errorHandler: handleError
}))
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'))
.pipe(header(config.banner, {
timestamp: (new Date()).toISOString(), pkg: config.pkg
}))
.pipe(gulp.dest('dist'))
.pipe(uglify({preserveComments: 'some'}))
.pipe(rename('itvalidate.min.js'))
.pipe(gulp.dest('dist'));
});
gulp.task('karma', ['build'], function() {
karma.start({configFile : __dirname +'/karma.conf.js', singleRun: true});
});
gulp.task('karma-watch', ['build'], function() {
karma.start({configFile : __dirname +'/karma.conf.js', singleRun: false});
});
function handleError(err) {
console.log(err.toString());
/*jshint validthis:true */
this.emit('end');
}