This repository has been archived by the owner on May 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.js
111 lines (98 loc) · 2.65 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 pkg = require('./package.json');
var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @author <%= pkg.author.name %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');
var gulp = require('gulp');
var header = require('gulp-header');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var jscs = require('gulp-jscs');
var jshint = require('gulp-jshint');
var karma = require('karma').server;
var coveralls = require('gulp-coveralls');
var paths = {
src: './src/**/*.js'
};
gulp.task('compress', function() {
return gulp.src([ 'src/helper.js', 'src/trie.js', 'src/' + pkg.name ])
.pipe(concat(pkg.name))
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest('./'))
.pipe(uglify())
.pipe(rename(pkg.name.replace('.js', '.min.js')))
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest('./'));
});
gulp.task('jscs', function() {
return gulp.src(paths.src)
.pipe(jscs());
});
gulp.task('lint', function() {
return gulp.src(paths.src)
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'));
});
// Run test once and exit
gulp.task('test', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done);
});
// Watch for file changes and re-run tests on each change
gulp.task('tdd', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js'
}, done);
});
// Run benchmark on the code
gulp.task('benchmark', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true,
browsers: ['PhantomJS', 'Chrome', 'Firefox'],
frameworks: ['benchmark'],
reporters: ['benchmark'],
files: [
'src/helper.js',
'src/trie.js',
'benchmark/helper.js',
'benchmark/**/*.js',
'benchmark/benchmark.js'
]
}, done);
});
// Generate test coverage
gulp.task('coverage', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true,
reporters: ['coverage'],
preprocessors: {
'src/**/*.js': 'coverage'
},
coverageReporter: {
reporters:[
{ type: 'html', dir: './coverage' },
{ type: 'text-summary' },
{ type: 'lcovonly' }
]
}
}, done);
});
gulp.task('coveralls', function() {
gulp.src('coverage/**/lcov.info')
.pipe(coveralls());
});
// Watch file changes
gulp.task('watch', function() {
gulp.watch(paths.src, ['jscs', 'lint']);
});
gulp.task('dev', ['watch', 'tdd']);
gulp.task('build', ['jscs', 'lint', 'test', 'compress']);