-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
126 lines (99 loc) · 2.51 KB
/
gulpfile.js
File metadata and controls
126 lines (99 loc) · 2.51 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"use strict";
var gulp = require('gulp');
var $ = require('gulp-load-plugins')({
pattern: '*',
rename: {
'vinyl-source-stream' : 'source',
'vinyl-buffer': 'buffer'
}
});
var paths = {
jssrc: './lib/*.js',
test: './test/',
testspecs: './test/spec/*.js',
dist: './dist'
};
var pkg = require('./package.json');
var today = new Date().toString();
var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @license <%= pkg.license %>',
' * '+'"'+today+'"',
' */',
].join('\n');
gulp.task('server', function(){
return gulp.src([paths.dist, paths.test])
.pipe($.webserver({
port: 8001
}));
});
gulp.task('jshint', function(){
return gulp.src([paths.jssrc])
.pipe($.jshint('.jshintrc'))
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.jshint.reporter('fail'));
});
gulp.task('browserify', ['jshint'], function(){
// Just for the sake of globbing
var bundledStream = $.through2();
bundledStream
.pipe($.source('reversebuffer.js'))
.pipe($.buffer())
.on('error', $.util.log)
.pipe(gulp.dest(paths.dist));
$.globby(paths.jssrc, function(err, entries){
if(err){
bundledStream.emit('error', err);
return;
}
var b = $.browserify({
entries: entries
});
b.bundle().pipe(bundledStream);
});
return bundledStream;
});
gulp.task('jshint:test', function(){
return gulp.src([paths.testspecs])
.pipe($.jshint('.jshintrc'))
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.jshint.reporter('fail'));
});
gulp.task('browserify:test', ['jshint:test'], bundle);
function bundle() {
// Just for the sake of globbing
var bundledStream = $.through2();
bundledStream
.pipe($.source('test.js'))
.pipe($.buffer())
.on('error', $.util.log)
.pipe(gulp.dest(paths.test));
$.globby([paths.testspecs], function(err, entries){
if(err){
bundledStream.emit('error', err);
return;
}
var b = $.browserify({
entries: entries
});
b.bundle().pipe(bundledStream);
});
return bundledStream;
}
gulp.task('clean', function(){
$.del([paths.dist+'/*.min.js']);
});
gulp.task('releasejs', ['clean'], function(){
return gulp.src([paths.dist+'/reversebuffer.js'])
.pipe($.uglify())
.pipe($.rename({extname: '.min.js'}))
.pipe($.header(banner, {pkg : pkg}))
.pipe(gulp.dest(paths.dist));
});
gulp.task('watch', function(){
gulp.watch(paths.jssrc, ['browserify']);
gulp.watch(paths.testspecs, ['browserify:test']);
});
gulp.task('default', ['jshint', 'browserify:test', 'watch', 'server']);
gulp.task('makerelease', ['releasejs']);