forked from PubMatic/OpenWrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
316 lines (280 loc) · 9.73 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
'use strict';
console.time("Loading plugins");
var argv = require('yargs').argv;
var gulp = require('gulp');
var concat = require('gulp-concat');
var replace = require('gulp-replace-task');
var config = require("./src_new/config.js");
// var replace = require('gulp-replace');
// var insert = require('gulp-insert');
// var uglify = require('gulp-uglify');
// var jshint = require('gulp-jshint');
// var jscs = require('gulp-jscs');
// var karma = require('gulp-karma');
// var mocha = require('gulp-mocha');
// var gutil = require('gulp-util');
// var opens = require('open');
// var webserver = require('gulp-webserver');
// var webpack = require('webpack-stream');
// var webpackConfig = require('./webpack.config.js');
// var replace = require('gulp-replace');
// var optimizejs = require('gulp-optimize-js');
// var stripCode = require('gulp-strip-code');
var eslint = require('gulp-eslint');
// var karmaServer = require('karma').Server;
// var stripComments = require('gulp-strip-comments');
console.timeEnd("Loading plugins");
var CI_MODE = (argv.mode === 'test-build') ? true : false;
var isIdentityOnly = config.isIdentityOnly();
console.log("argv ==>", argv);
var prebidRepoPath = argv.prebidpath || "../Prebid.js/";
gulp.task('clean', ['update-adserver'], function() {
var clean = require('gulp-clean');
return gulp.src(['dist/**/*.js', 'build/'], {
read: false,
allowEmpty: true
})
.pipe(clean());
});
// What all processing needs to be done ?
gulp.task('webpack', ['clean'], function() {
console.log("Executing webpack");
var connect = require('gulp-connect');
var uglify = require('gulp-uglify');
var webpack = require('webpack-stream');
var webpackConfig = require('./webpack.config.js');
var optimizejs = require('gulp-optimize-js');
var fsCache = require('gulp-fs-cache');
var jsFsCache = fsCache('.tmp/jscache');
webpackConfig.devtool = null;
return gulp.src('src_new/owt.js')
.pipe(webpack(webpackConfig))
.pipe(jsFsCache)
.pipe(uglify())
.pipe(optimizejs())
.pipe(jsFsCache.restore)
.pipe(gulp.dest('build/dist'))
.pipe(connect.reload())
;
});
// Run below task to create owt.js for creative
gulp.task('webpack-creative', ['clean'], function() {
var connect = require('gulp-connect');
var uglify = require('gulp-uglify');
var webpack = require('webpack-stream');
var webpackConfig = require('./webpack.config.js');
var optimizejs = require('gulp-optimize-js');
webpackConfig.devtool = null;
return gulp.src('src_new/creative/owCreativeRenderer.js')
.pipe(webpack(webpackConfig))
.pipe(uglify())
.pipe(optimizejs())
.pipe(gulp.dest('build/dist'))
.pipe(connect.reload())
;
});
gulp.task('devpack', ['clean'],function () {
var connect = require('gulp-connect');
var webpack = require('webpack-stream');
var webpackConfig = require('./webpack.config.js');
webpackConfig.devtool = 'source-map';
return gulp.src('src_new/owt.js')
.pipe(webpack(webpackConfig))
.pipe(gulp.dest('build/dev'))
.pipe(connect.reload());
});
// Test all code without private functions
gulp.task('test', ['unexpose'], function (done) {
var karma = require('gulp-karma');
var karmaServer = require('karma').Server;
var defaultBrowsers = CI_MODE ? ['PhantomJS'] : ['Chrome'];
new karmaServer({
browsers: defaultBrowsers,
basePath: './temp',
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function (exitCode) {
console.log("exitCode ==>", exitCode);
gulp.src('temp', {
read: true
})
.pipe(clean())
.pipe(function () {
if (exitCode != 0) {
process.exit(exitCode);
}
});
}).start();
});
// Test all code including private functions
gulp.task('testall', function (done) {
var karma = require('gulp-karma');
var karmaServer = require('karma').Server;
var defaultBrowsers = CI_MODE ? ['PhantomJS'] : ['Chrome'];
new karmaServer({
browsers: defaultBrowsers,
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function (exitCode) {
console.log("exitCode ==>", exitCode);
if (exitCode != 0) {
process.exit(exitCode);
}
}).start();
});
// Small task to load coverage reports in the browser
gulp.task('coverage', function (done) {
var connect = require('gulp-connect');
var opens = require('open');
var coveragePort = 1999;
connect.server({
port: 1999,
root: 'build',
livereload: false
});
opens('http://localhost:' + coveragePort + '/coverage/');
done();
});
// Task to remove privately exposed functions as well as remove test cases which test private functions
gulp.task('unexpose', function() {
var stripCode = require('gulp-strip-code');
return gulp
.src([
'src_new/**/*.js',
'test/**/*.js'
],
{ base: './' }
)
.pipe(stripCode({
start_comment: "start-test-block",
end_comment: "end-test-block"
}))
.pipe(gulp.dest('./temp/'));
});
// Code linting with eslint
gulp.task('lint', () => {
return gulp.src([
'src_new/**/*.js',
'test/**/*.js'
])
.pipe(eslint())
.pipe(eslint.format('stylish'))
.pipe(eslint.failAfterError());
});
gulp.task('change-prebid-keys', () => {
// Note: we have to execute this only when we have to use PubMatic OW keys
// todo: add gulp-json-editor entry in package.json and in backend build job?
var prebidConstantsPath = prebidRepoPath + '/src';
var jeditor = require("gulp-json-editor");
return gulp.src(prebidConstantsPath + '/constants.json')
.pipe(jeditor(function(json) {
json.TARGETING_KEYS.BIDDER = "pwtpid"; // hb_bidder
json.TARGETING_KEYS.AD_ID = "pwtsid"; // hb_adid
json.TARGETING_KEYS.PRICE_BUCKET = "pwtecp"; // hb_pb
json.TARGETING_KEYS.SIZE = "pwtsz"; // hb_size
json.TARGETING_KEYS.DEAL = "pwtdeal"; // hb_deal
json.TARGETING_KEYS.SOURCE = ""; // hb_source
json.TARGETING_KEYS.FORMAT = "pwtplt"; // hb_format
json.TARGETING_KEYS.UUID = ""; // hb_uuids
json.TARGETING_KEYS.CACHE_ID = "pwtcid"; // hb_cache_id
json.TARGETING_KEYS.CACHE_HOST = ""; // hb_cache_host
return json;
}))
.pipe(gulp.dest(prebidConstantsPath));
});
// Task to build minified version of owt.js
gulp.task('bundle', ['update-adserver'], function () {
console.log("Executing build");
return gulp.src([prebidRepoPath + '/build/dist/prebid.js', './build/dist/owt.js'])
.pipe(concat('owt.min.js'))
.pipe(gulp.dest('build'));
});
gulp.task('bundle-pb-keys', function(){
return gulp.src('./build/owt.min.js')
.pipe(replace({
patterns: [
{
match: /"%%TG_KEYS%%"/g,
replacement: {
"BIDDER": "hb_bidder",
"AD_ID": "hb_adid",
"PRICE_BUCKET": "hb_pb",
"SIZE": "hb_size",
"DEAL": "hb_deal",
"SOURCE": "hb_source",
"FORMAT": "hb_format",
"UUID": "hb_uuid",
"CACHE_ID": "hb_cache_id",
"CACHE_HOST": "hb_cache_host",
"ADOMAIN" : "hb_adomain"
}
}
]
}))
.pipe(gulp.dest('build'));
});
gulp.task('bundle-pwt-keys', function(){
return gulp.src('./build/owt.min.js')
.pipe(replace({
patterns: [
{
match: /"%%TG_KEYS%%"/g,
replacement: {
"STATUS": "pwtbst",
"BIDDER": "pwtpid",
"AD_ID": "pwtsid",
"PRICE_BUCKET": "pwtecp",
"SIZE": "pwtsz",
"DEAL": "pwtdeal",
"DEAL_ID": "pwtdid",
"SOURCE": "",
"FORMAT": "pwtplt",
"UUID": "pwtuuid",
"CACHE_ID": "pwtcid",
"CACHE_HOST": "pwtcurl",
"ADOMAIN" : "pwtadomain"
}
}
]
}))
.pipe(gulp.dest('build'));
});
// Task to build minified version of owt.js
gulp.task('bundle-creative', function () {
console.log("Executing creative-build");
return gulp.src(['./build/dist/owt.js'])
.pipe(concat('owt.min.js'))
.pipe(gulp.dest('build'));
});
// Task to build non-minified version of owt.js
gulp.task('devbundle',['devpack'], function () {
console.log("Executing Dev Build");
return gulp.src([prebidRepoPath + '/build/dev/prebid.js', './build/dev/owt.js'])
.pipe(concat('owt.js'))
.pipe(gulp.dest('build'));
});
gulp.task('bundle-prod',['webpack'], function () {
console.log("Executing bundling");
return gulp.src([prebidRepoPath + '/build/dist/prebid.js', './build/dist/owt.js'])
.pipe(concat('owt.min.js'))
.pipe(gulp.dest('build'));
});
gulp.task('update-adserver', function(){
console.log("In update-adserver isIdentityOnly = " + isIdentityOnly);
if (isIdentityOnly) {
console.log("Executing update-adserver - START");
var result = gulp.src(['./src_new/conf.js'])
.pipe(replace({
patterns: [
{
match: /['"]*adserver['"]*:[\s]*['"]*DFP['"]*/,
replacement: '"adserver": "IDHUB"'
}
]
}))
.pipe(gulp.dest('./src_new/'));
console.log("Executing update-adserver - END");
return result;
}
});
gulp.task('build-gpt-prod',[''])