-
Notifications
You must be signed in to change notification settings - Fork 26
/
gulpfile.js
84 lines (71 loc) · 1.97 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
var gulp = require('gulp'),
uglify = require('gulp-uglify'),
changed = require('gulp-changed'),
concat = require('gulp-concat'),
sourcemaps = require('gulp-sourcemaps'),
download = require("gulp-download"),
del = require('del'),
header = require('gulp-header'),
runSequence = require('run-sequence'),
rename = require('gulp-rename'),
browserSync = require('browser-sync'),
injector = require('gulp-injector');
var pkg = require('./package.json'),
paths = {
src: [ 'src/main.js'],
dist: 'dist'
},
scripts = 'src/*.js',
specs = 'spec/*.js',
uncompressedJs = 'json_query.js',
compressedJs = 'json_query.min.js';
var banner = [
'/*',
' * <%= pkg.title || pkg.name %>',
' * <%= pkg.version %> (<%= new Date().toISOString().slice(0, 10) %>)',
' *',
' * Released under the MIT license',
' * http://opensource.org/licenses/MIT',
' *',
' * Copyright 2011-<%= new Date().getFullYear() %> <%= pkg.author.name %>[<%= pkg.author.email %>]',
' *',
' */',
' ',
' ' ].join('\n');
gulp.task('clean', function(cb) {
del([paths.dist], cb);
});
gulp.task('scripts', function() {
return gulp.src(paths.src)
.pipe(concat(uncompressedJs))
.pipe(injector())
.pipe(header(banner, { pkg: pkg } ))
.pipe(gulp.dest(paths.dist))
.pipe(sourcemaps.init())
.pipe(uglify({preserveComments: 'all'}))
.pipe(rename(compressedJs))
.pipe(gulp.dest(paths.dist))
});
gulp.task('watch', function() {
gulp.watch(scripts, function(cb){
runSequence('scripts', browserSync.reload)
});
gulp.watch(specs, [browserSync.reload])
});
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: "./spec",
index: 'SpecRunner.html',
routes: {
'/dist/json_query.js': './dist/json_query.js'
}
}
});
});
gulp.task('build', function(cb){
runSequence('clean', 'scripts', cb)
});
gulp.task('default', function(cb){
runSequence('clean', 'scripts', 'watch', 'browser-sync')
});