forked from liabru/jquery-match-height
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
217 lines (195 loc) · 6 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// TODO: add more test specs (see matchHeight.spec.js)
// TODO: travis CI
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var header = require('gulp-header');
var eslint = require('gulp-eslint');
var gulpBump = require('gulp-bump');
var changelog = require('gulp-conventional-changelog');
var tag = require('gulp-tag-version');
var sequence = require('run-sequence');
var gutil = require('gulp-util');
var replace = require('gulp-replace');
var webdriver = require('gulp-webdriver');
var webserver = require('gulp-webserver');
var selenium = require('selenium-standalone');
var ngrok = require('ngrok');
var staticTransform = require('connect-static-transform');
var privateConfig = require('./test/conf/private.conf.js').config;
var pkg = require('./package.json');
var extend = require('util')._extend;
var server;
gulp.task('release', function(callback) {
var type = process.argv[4] || 'minor';
sequence('lint', 'test', 'build', 'bump:' + type, 'changelog', 'tag', callback);
});
gulp.task('build', function() {
build = extend(pkg)
build.version = process.argv[4] || pkg.version;
return gulp.src(pkg.main)
.pipe(replace("version = 'master'", "version = '" + build.version + "'"))
.pipe(uglify({ output: { max_line_len: 500 } }))
.pipe(header(banner, { build: build }))
.pipe(rename({ suffix: '-min' }))
.pipe(gulp.dest('.'));
});
gulp.task('lint', function() {
return gulp.src(pkg.main)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
var bump = function(options) {
return gulp.src(['package.json', 'bower.json'])
.pipe(gulpBump(options))
.pipe(gulp.dest('.'));
};
gulp.task('bump:patch', function() {
return bump({ type: 'patch' });
});
gulp.task('bump:minor', function() {
return bump({ type: 'minor' });
});
gulp.task('bump:major', function() {
return bump({ type: 'major' });
});
gulp.task('tag', function() {
return gulp.src('package.json')
.pipe(tag({ prefix: '' }));
});
gulp.task('changelog', function () {
return gulp.src('CHANGELOG.md')
.pipe(changelog())
.pipe(gulp.dest('.'));
});
gulp.task('serve', function() {
process.on('uncaughtException', function(err) {
if (err.errno === 'EADDRINUSE') {
gutil.log('Server already running (or port is otherwise in use)');
}
});
server = gulp.src('.')
.pipe(webserver({
host: '0.0.0.0',
//livereload: true,
directoryListing: true,
middleware: function(req, res, next) {
var ieMode = (req._parsedUrl.query || '').replace('=','');
if (ieMode in emulateIEMiddleware) {
emulateIEMiddleware[ieMode](req, res, next);
} else {
next();
}
}
}));
});
gulp.task('selenium', function(done) {
gutil.log('Setting up Selenium server...');
selenium.install({
logger: function(message) { gutil.log(message); }
}, function(err) {
if (err) {
done(err);
return;
}
gutil.log('Starting Selenium server...');
selenium.start(function(err, child) {
gutil.log('Selenium server started');
selenium.child = child;
done(err);
});
});
});
gulp.task('test', ['lint', 'serve', 'selenium'], function(done) {
var error;
gutil.log('Starting webdriver...');
var finish = function(err) {
gutil.log('Webdriver stopped');
selenium.child.kill();
gutil.log('Selenium server stopped');
if (server) {
try {
server.emit('kill');
} catch(e) {}
gutil.log('Web server stopped');
}
done(error || err);
};
gulp.src('test/conf/local.conf.js')
.pipe(webdriver({
baseUrl: 'http://localhost:8000'
}))
.on('error', function(err) { error = err; })
.on('finish', finish);
});
gulp.task('test:cloud', ['lint', 'serve'], function(done) {
ngrok.connect({
authtoken: null,
port: 8000
}, function (err, url) {
gutil.log('Tunnel started', url);
gulp.src('test/conf/cloud.conf.js')
.pipe(webdriver({
baseUrl: url
}))
.on('finish', function(err) {
if (server) {
try {
server.emit('kill');
} catch(e) {}
ngrok.disconnect();
ngrok.kill();
gutil.log('Tunnel stopped');
gutil.log('Web server stopped');
}
done(err);
});
});
});
gulp.task('test:cloud:all', ['lint', 'serve'], function(done) {
ngrok.connect({
authtoken: null,
port: 8000
}, function (err, url) {
gutil.log('Tunnel started', url);
gulp.src('test/conf/cloud-all.conf.js')
.pipe(webdriver({
baseUrl: url
}))
.on('finish', function(err) {
if (server) {
try {
server.emit('kill');
} catch(e) {}
ngrok.disconnect();
ngrok.kill();
gutil.log('Tunnel stopped');
gutil.log('Web server stopped');
}
done(err);
});
});
});
var banner = [
'/*',
'* <%= build.name %> <%= build.version %> by @liabru',
'* <%= build.homepage %>',
'* License <%= build.license %>',
'*/',
''
].join('\n');
var emulateIEMiddlewareFactory = function(version) {
return staticTransform({
root: __dirname,
match: /(.+)\.html/,
transform: function (path, text, send) {
send(text.replace('content="IE=edge,chrome=1"', 'content="IE=' + version + '"'));
}
});
};
var emulateIEMiddleware = {
'ie8': emulateIEMiddlewareFactory(8),
'ie9': emulateIEMiddlewareFactory(9),
'ie10': emulateIEMiddlewareFactory(10)
};