-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
93 lines (80 loc) · 2.11 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
(function() {
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var karma = require('karma');
var del = require('del');
var root = __dirname;
var version;
var startKarma = function(config, done) {
new karma.Server({
configFile: __dirname + '/karma.conf.js',
singleRun: (typeof config.singleRun !== 'undefined' ? config.singleRun : true),
autoWatch: (typeof config.autoWatch !== 'undefined' ? config.autoWatch : false)
}, done).start();
};
var getVersion = function(callback) {
var rl = require('readline').createInterface({
input: require('fs').createReadStream('CHANGELOG.md')
});
if (version) {
callback(version);
} else {
rl.on('line', function(line) {
if (!version) {
version = line.trim();
rl.close();
}
});
rl.on('close', function() {
if (!version) {
version = '1.0.0';
}
callback(version);
});
}
};
gulp.task('default', ['tdd']);
gulp.task('test', function(done) {
startKarma({
singleRun: true,
autoWatch: false
}, done);
});
gulp.task('tdd', function(done) {
startKarma({
singleRun: false,
autoWatch: true
}, done);
});
gulp.task('jshint', function() {
return gulp.src('lib/*.js')
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.jshint.reporter('fail'));
});
gulp.task('clean', function() {
return del(['dist/*'], { force: true });
});
gulp.task('dist', function() {
return gulp.src('lib/*.js')
.pipe($.uglify())
.pipe($.rename(function(path) {
path.basename += '.min';
}))
.pipe(gulp.dest(require('path').join(root, '/dist')));
});
gulp.task('build', function(done) {
require('run-sequence')(['clean', 'updateVersion', 'test'], 'dist', done);
});
gulp.task('updateVersion', function(done) {
getVersion(function(version) {
gulp.src('package.json')
.pipe($.bump({
version: version
}))
.pipe(gulp.dest(root));
done();
});
});
})();