forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
193 lines (166 loc) · 5.71 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
'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 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 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';
// Tasks
gulp.task('default', ['clean', 'quality', 'webpack']);
gulp.task('serve', ['clean', 'quality', 'devpack', 'webpack', 'watch', 'test']);
gulp.task('run-tests', ['clean', 'quality', 'webpack', 'test']);
gulp.task('build', ['clean', 'quality', 'webpack', 'devpack', 'zip']);
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(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'
];
}
return gulp.src('lookAtKarmaConfJS')
.pipe(karma({
browsers: (browserArgs.length > 0) ? browserArgs : defaultBrowsers,
configFile: 'karma.conf.js',
action: (argv.watch) ? 'watch' : 'run'
}));
});
// 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(['test/spec/**/*.js'], ['quality', 'webpack', 'devpack', 'test']);
gulp.watch(['integrationExamples/gpt/*.html'], ['test']);
gulp.watch(['src/**/*.js'], ['quality', 'webpack', 'devpack', 'test']);
connect.server({
port: 9999,
root: './',
livereload: true
});
});
gulp.task('quality', ['hint', 'jscs']);
gulp.task('hint', function () {
return gulp.src('src/**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.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'));
});