forked from SteveSanderson/knockout.mapping
-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
62 lines (53 loc) · 1.94 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
'use strict';
/*jshint node:true*/
var gulp = require('gulp');
var del = require('del');
var qunit = require('gulp-qunit');
var plumber = require('gulp-plumber');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var replace = require('gulp-replace');
var rename = require('gulp-rename');
var header = require('gulp-header');
var sourceMaps = require('gulp-sourcemaps');
var buildConfig = {
outputPath: 'dist',
pkg: require('./package.json'),
banner: [
'/*!',
' * Knockout Mapping plugin v<%= pkg.version %>',
' * (c) 2013 Steven Sanderson, Roy Jacobs - http://knockoutjs.com/',
' * License: MIT (http://www.opensource.org/licenses/mit-license.php)',
' */\n'
].join('\n')
};
gulp.task('clear', function () {
return del('*', {cwd: 'dist'});
});
gulp.task('build', function () {
return gulp.src('knockout.mapping.js')
.pipe(plumber({errorHandler: process.env.NODE_ENV === 'development'}))
.pipe(jshint()).pipe(jshint.reporter('jshint-stylish'))
.pipe(header(buildConfig.banner, {pkg: buildConfig.pkg}))
.pipe(gulp.dest(buildConfig.outputPath))
.pipe(rename('knockout.mapping.min.js'))
.pipe(replace(/(:?var\s*?DEBUG\s*?=\s*?true)/, 'var DEBUG=false'))
.pipe(sourceMaps.init())
.pipe(uglify())
.pipe(sourceMaps.write('./'))
.pipe(gulp.dest(buildConfig.outputPath));
});
gulp.task('jshint', function () {
return gulp.src(['knockout.mapping.js', 'spec/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('test', gulp.series('build', 'jshint', function() {
return gulp.src(process.env.CI ? 'spec/spec-runner-*.htm' : 'spec/spec-runner.htm')
.pipe(plumber({errorHandler: process.env.NODE_ENV === 'development'}))
.pipe(qunit({timeout: 30}));
}));
gulp.task('default', gulp.series('clear', 'test'));
gulp.task('watch', function () {
gulp.watch(['knockout.mapping.js', 'spec/spec-runner.htm', 'spec/*.js'], gulp.series('clear', 'test'));
});