forked from sockjs/sockjs-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
132 lines (115 loc) · 3.31 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* eslint camelcase: 0 */
'use strict';
var util = require('util')
, gulp = require('gulp')
, browserify = require('browserify')
, uglify = require('gulp-uglify')
, sourcemaps = require('gulp-sourcemaps')
, source = require('vinyl-source-stream')
, buffer = require('vinyl-buffer')
, envify = require('envify/custom')
, mocha = require('gulp-mocha')
, eslint = require('gulp-eslint')
, rename = require('gulp-rename')
, header = require('gulp-header')
, pkg = require('./package.json')
, fs = require('fs')
;
var libName = 'sockjs-' + pkg.version
, browserifyOptions = {
entries: './lib/entry.js'
, standalone: 'SockJS'
, insertGlobalVars: {
process: function () {
return '{ env: {} }';
}
}
}
;
var banner = '/* sockjs-client v<%= pkg.version %> | http://sockjs.org | MIT license */\n';
gulp.task('test', function () {
gulp.src('tests/node.js', {read: false})
.pipe(mocha());
});
gulp.task('eslint', function () {
gulp.src([
'lib/**/*.js',
'tests/lib/**/*.js',
'tests/support/**/*.js',
'tests/*.js'
])
.pipe(eslint())
.pipe(eslint.format());
});
gulp.task('watch', function () {
gulp.watch('tests/*.js', ['test']);
});
gulp.task('write-version', function () {
fs.writeFileSync('./lib/version.js', "module.exports = '" + pkg.version + "';\n");
});
gulp.task('testbundle', ['browserify:min'], function() {
return gulp.src('./build/' + libName + '.min.js')
.pipe(rename('sockjs.js'))
.pipe(gulp.dest('./tests/html/lib/'));
});
gulp.task('testbundle-debug', ['browserify'], function() {
gulp.src('./build/sockjs.js')
.pipe(rename('sockjs.js'))
.pipe(gulp.dest('./tests/html/lib/'));
return gulp.src('./build/sockjs.js.map')
.pipe(rename('sockjs.js.map'))
.pipe(gulp.dest('./tests/html/lib/'));
});
gulp.task('browserify', ['write-version'], function () {
return browserify(util._extend({
debug: true
}, browserifyOptions))
.bundle()
.pipe(source('sockjs.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(header(banner, { pkg: pkg }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./build/'))
;
});
gulp.task('browserify:min', ['write-version'], function () {
return browserify(browserifyOptions)
.exclude('debug')
.transform(envify({
NODE_ENV: 'production'
}))
.bundle()
.pipe(source(libName + '.min.js'))
.pipe(buffer())
.pipe(uglify({
compress: {
// remove debug statements from output entirely
pure_funcs: ['debug']
}
}))
.pipe(header(banner, { pkg: pkg }))
.pipe(gulp.dest('./build/'))
;
});
gulp.task('release', ['browserify', 'browserify:min'], function () {
// sockjs-{version}.min.js
gulp.src('./build/' + libName + '.min.js')
.pipe(gulp.dest('./dist/'));
// sockjs-{version}.js
gulp.src('./build/sockjs.js')
.pipe(rename(libName + '.js'))
.pipe(gulp.dest('./dist/'));
gulp.src('./build/sockjs.js.map')
.pipe(gulp.dest('./dist/'));
});
gulp.task('stable-release', ['release'], function () {
// sockjs.min.js
gulp.src('./build/' + libName + '.min.js')
.pipe(rename('sockjs.min.js'))
.pipe(gulp.dest('./dist/'));
// sockjs.js
gulp.src('./build/sockjs.js')
.pipe(rename('sockjs.js'))
.pipe(gulp.dest('./dist/'));
});