forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
266 lines (229 loc) · 7.56 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
'use strict';
var argv = require('yargs').argv;
var gulp = require('gulp');
var gutil = require('gulp-util');
var connect = require('gulp-connect');
var webpack = require('webpack-stream');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var clean = require('gulp-clean');
var karma = require('gulp-karma');
var mocha = require('gulp-mocha');
var opens = require('open');
var webpackConfig = require('./webpack.conf.js');
var helpers = require('./gulpHelpers');
var del = require('del');
var gulpJsdoc2md = require('gulp-jsdoc-to-markdown');
var concat = require('gulp-concat');
var jscs = require('gulp-jscs');
var header = require('gulp-header');
var zip = require('gulp-zip');
var replace = require('gulp-replace');
var shell = require('gulp-shell');
var optimizejs = require('gulp-optimize-js');
var CI_MODE = process.env.NODE_ENV === 'ci';
var prebid = require('./package.json');
var dateString = 'Updated : ' + (new Date()).toISOString().substring(0, 10);
var packageNameVersion = prebid.name + '_' + prebid.version;
var banner = '/* <%= prebid.name %> v<%= prebid.version %>\n' + dateString + ' */\n';
var analyticsDirectory = '../analytics';
var port = 9999;
// Tasks
gulp.task('default', ['clean', 'quality', 'webpack']);
gulp.task('serve', ['clean', 'quality', 'devpack', 'webpack', 'watch', 'test']);
gulp.task('serve-nw', ['clean', 'quality', 'devpack', 'webpack', 'watch', 'e2etest']);
gulp.task('run-tests', ['clean', 'quality', 'webpack', 'test', 'mocha']);
gulp.task('build', ['webpack']);
gulp.task('clean', function () {
return gulp.src(['build'], {
read: false
})
.pipe(clean());
});
gulp.task('devpack', function () {
webpackConfig.devtool = 'source-map';
const analyticsSources = helpers.getAnalyticsSources(analyticsDirectory);
return gulp.src([].concat(analyticsSources, 'src/prebid.js'))
.pipe(webpack(webpackConfig))
.pipe(replace('$prebid.version$', prebid.version))
.pipe(gulp.dest('build/dev'))
.pipe(connect.reload());
});
gulp.task('webpack', function () {
// change output filename if argument --tag given
if (argv.tag && argv.tag.length) {
webpackConfig.output.filename = 'prebid.' + argv.tag + '.js';
}
webpackConfig.devtool = null;
const analyticsSources = helpers.getAnalyticsSources(analyticsDirectory);
return gulp.src([].concat(analyticsSources, 'src/prebid.js'))
.pipe(webpack(webpackConfig))
.pipe(replace('$prebid.version$', prebid.version))
.pipe(uglify())
.pipe(header(banner, { prebid: prebid }))
.pipe(optimizejs())
.pipe(gulp.dest('build/dist'))
.pipe(connect.reload());
});
//zip up for release
gulp.task('zip', ['jscs', 'clean', 'webpack'], function () {
return gulp.src(['build/dist/*', 'integrationExamples/gpt/*'])
.pipe(zip(packageNameVersion + '.zip'))
.pipe(gulp.dest('./'));
});
// Karma Continuous Testing
// Pass your browsers by using --browsers=chrome,firefox,ie9
// Run CI by passing --watch
gulp.task('test', function () {
var defaultBrowsers = CI_MODE ? ['PhantomJS'] : ['Chrome'];
var browserArgs = helpers.parseBrowserArgs(argv).map(helpers.toCapitalCase);
if (process.env.TRAVIS) {
browserArgs = ['Chrome_travis_ci'];
}
if (argv.browserstack) {
browserArgs = [
'bs_ie_13_windows_10',
'bs_ie_11_windows_10',
'bs_firefox_46_windows_10',
'bs_chrome_51_windows_10',
'bs_ie_11_windows_8.1',
'bs_firefox_46_windows_8.1',
'bs_chrome_51_windows_8.1',
'bs_ie_10_windows_8',
'bs_firefox_46_windows_8',
'bs_chrome_51_windows_8',
'bs_ie_11_windows_7',
'bs_ie_10_windows_7',
'bs_ie_9_windows_7',
'bs_firefox_46_windows_7',
'bs_chrome_51_windows_7',
'bs_safari_9.1_mac_elcapitan',
'bs_firefox_46_mac_elcapitan',
'bs_chrome_51_mac_elcapitan',
'bs_safari_8_mac_yosemite',
'bs_firefox_46_mac_yosemite',
'bs_chrome_51_mac_yosemite',
'bs_safari_7.1_mac_mavericks',
'bs_firefox_46_mac_mavericks',
'bs_chrome_49_mac_mavericks',
'bs_ios_7',
'bs_ios_8',
'bs_ios_9',
];
}
return gulp.src('lookAtKarmaConfJS')
.pipe(karma({
browsers: (browserArgs.length > 0) ? browserArgs : defaultBrowsers,
configFile: 'karma.conf.js',
action: (argv.watch) ? 'watch' : 'run'
}));
});
gulp.task('mocha', ['webpack'], function() {
return gulp.src(['test/spec/loaders/**/*.js'], { read: false })
.pipe(mocha({
reporter: 'spec',
globals: {
expect: require('chai').expect
}
}))
.on('error', gutil.log);
});
// Small task to load coverage reports in the browser
gulp.task('coverage', function (done) {
var coveragePort = 1999;
connect.server({
port: 1999,
root: 'build/coverage',
livereload: false
});
opens('http://localhost:' + coveragePort + '/coverage/');
done();
});
gulp.task('coveralls', ['test'], function() { // 2nd arg is a dependency: 'test' must be finished
// first send results of istanbul's test coverage to coveralls.io.
return gulp.src('gulpfile.js', { read: false }) // You have to give it a file, but you don't
// have to read it.
.pipe(shell('cat build/coverage/lcov/lcov.info | node_modules/coveralls/bin/coveralls.js'));
});
// Watch Task with Live Reload
gulp.task('watch', function () {
gulp.watch([
'src/**/*.js',
'test/spec/**/*.js',
'!test/spec/loaders/**/*.js'
], ['quality', 'webpack', 'devpack', 'test']);
gulp.watch([
'loaders/**/*.js',
'test/spec/loaders/**/*.js'
], ['quality', 'mocha']);
gulp.watch(['integrationExamples/gpt/*.html'], ['test']);
connect.server({
https: argv.https,
port: port,
root: './',
livereload: true
});
});
gulp.task('quality', ['hint', 'jscs']);
gulp.task('hint', function () {
return gulp.src('src/**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
gulp.task('jscs', function () {
return gulp.src('src/**/*.js')
.pipe(jscs({
configPath: '.jscsrc'
}))
.pipe(jscs.reporter());
});
gulp.task('clean-docs', function () {
del(['docs']);
});
gulp.task('docs', ['clean-docs'], function () {
return gulp.src('src/prebid.js')
.pipe(concat('readme.md'))
.pipe(gulpJsdoc2md())
.on('error', function (err) {
gutil.log('jsdoc2md failed:', err.message);
})
.pipe(gulp.dest('docs'));
});
gulp.task('e2etest', function() {
var cmdQueue = [];
if(argv.browserstack) {
var browsers = require('./browsers.json');
delete browsers['bs_ie_9_windows_7'];
var cmdStr = ' --config nightwatch.conf.js';
if (argv.group) {
cmdStr = cmdStr + ' --group ' + argv.group;
}
cmdStr = cmdStr + ' --reporter ./test/spec/e2e/custom-reporter/pbjs-html-reporter.js';
var startWith = 'bs';
Object.keys(browsers).filter(function(v){
return v.substring(0, startWith.length) === startWith && browsers[v].browser !== 'iphone';
}).map(function(v,i,arr) {
var newArr = (i%2 === 0) ? arr.slice(i,i+2) : null;
if(newArr) {
var cmd = 'nightwatch --env ' + newArr.join(',') + cmdStr;
cmdQueue.push(cmd);
}
});
}
return gulp.src('')
.pipe(shell(cmdQueue.join(';')));
});
gulp.task('e2etest-report', function() {
var reportPort = 9010;
var targetDestinationDir = './e2etest-report';
helpers.createEnd2EndTestReport(targetDestinationDir);
connect.server({
port: reportPort,
root: './',
livereload: true
});
setTimeout(function() {
opens('http://localhost:' + reportPort + '/' + targetDestinationDir.slice(2) + '/results.html');
}, 5000);
});