Skip to content

Commit

Permalink
Merge pull request #458 from PubMatic/UOE-8815
Browse files Browse the repository at this point in the history
Uoe 8815 - cust namespace
  • Loading branch information
pm-nitin-shirsat authored May 29, 2023
2 parents ef7e064 + 962f83e commit 4b2610f
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 29 deletions.
13 changes: 5 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,6 @@ if (task == CREATIVE_TASK) {

shell.cd("../OpenWrap/");

console.log("Executing update-namespace task if identityOnly = 1, => ", config.isIdentityOnly());
if(config.isIdentityOnly()) {
console.log("Updating owpbjs namespace to use ihowpbjs for identity only profiles");
if(shell.exec("time gulp update-namespace").code !== 0) {
shell.echo('Error: Changing owpbjs namespace to use ihowpbjs failed');
shell.exit(1);
}
}

if (argv.mode == "test-build") {
if(shell.exec("gulp testall" + " --mode=" + argv.mode + " --prebidpath=" + prebidRepoPath).code !== 0) {
Expand All @@ -112,6 +104,11 @@ if (task == CREATIVE_TASK) {
shell.echo('Error: wrapper build task failed');
shell.exit(1);
}

if(shell.exec("time gulp update-namespace").code !== 0) {
shell.echo('Error: Changing custom namespace failed');
shell.exit(1);
}
}

console.timeEnd("--------- STARTED");
56 changes: 39 additions & 17 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,37 +395,59 @@ gulp.task('devbundle', gulp.series('devpack', function () {
var concat = require('gulp-concat');
//var prebidFileName = isIdentityOnly ? '/build/dev/prebidIdhub.js' : '/build/dev/prebid.js';
var prebidFileName = '/build/dev/prebid.js';
return gulp.src([prebidRepoPath + prebidFileName, './build/dev/owt.js'], { allowEmpty: true })
var footerFileName = isIdentityOnly ? './src_new/ih_footer.js' : './src_new/ow_footer.js';
return gulp.src([prebidRepoPath + prebidFileName, './build/dev/owt.js', footerFileName], { allowEmpty: true })
.pipe(concat('owt.js'))
.pipe(gulp.dest('build'));
}));


gulp.task('bundle-prod', gulp.series('webpack', function () {
console.log("Executing bundling");
var concat = require('gulp-concat');
//var prebidFileName = isIdentityOnly ? '/build/dist/prebidIdhub.js' : '/build/dist/prebid.js';
var prebidFileName = '/build/dist/prebid.js';
return gulp.src([prebidRepoPath + prebidFileName, './build/dist/owt.js'], { allowEmpty: true })
var footerFileName = isIdentityOnly ? './src_new/ih_footer.js' : './src_new/ow_footer.js';
return gulp.src([prebidRepoPath + prebidFileName, './build/dist/owt.js', footerFileName], { allowEmpty: true })
.pipe(concat('owt.min.js'))
.pipe(gulp.dest('build'));
}));

gulp.task('update-namespace', function(){
console.log("In update-namespace isIdentityOnly = " + isIdentityOnly);
function addPattern(patterns, match, replacement) {
if (replacement) {
patterns.push({
match: match,
replacement: replacement
});
}
}

function getPatternsToReplace() {
const { COMMON, CONFIG } = require('./src_new/constants.js');
var patterns = [];
if (isIdentityOnly) {
addPattern(patterns, /ihowpbjs|owpbjs/g, config.getOverrideNamespace(CONFIG.PB_GLOBAL_VAR_NAMESPACE, COMMON.IH_NAMESPACE, COMMON.IH_NAMESPACE));
addPattern(patterns, /IHPWT/g, config.getOverrideNamespace(CONFIG.OW_GLOBAL_VAR_NAMESPACE, COMMON.IH_OW_NAMESPACE, null));
} else {
// Passing null as we don't want to replace the used value(i.e. PWT) with default value(i.e. PWT) as both are same,
addPattern(patterns, /owpbjs/g, config.getOverrideNamespace(CONFIG.PB_GLOBAL_VAR_NAMESPACE, COMMON.PREBID_NAMESPACE, null));
addPattern(patterns, /PWT/g, config.getOverrideNamespace(CONFIG.OW_GLOBAL_VAR_NAMESPACE, COMMON.OPENWRAP_NAMESPACE, null));
}
return patterns;
}

gulp.task('update-namespace', async function () {
console.log("Executing update-namespace - START => ");
//var prebidFileName = isIdentityOnly ? '/build/dist/prebidIdhub.js' : '/build/dist/prebid.js';
var prebidFileName = '/build/dist/prebid.js';
return gulp.src(prebidRepoPath + prebidFileName)
.pipe(replace({
patterns: [
{
match: /owpbjs/g,
replacement: 'ihowpbjs'
}
]
}))
.pipe(gulp.dest(prebidRepoPath+'/build/dist/'));
var patternsToReplace = getPatternsToReplace();
console.log("Patterns to replace => ", patternsToReplace);
if (patternsToReplace.length > 0) {
return gulp.src('build/*.js')
.pipe(replace({
patterns: patternsToReplace
}))
.pipe(gulp.dest('build/'));
} else {
console.log("default namespaces(owpbjs and PWT) are using.");
}
});

gulp.task('build-gpt-prod');
Expand Down
4 changes: 3 additions & 1 deletion src_new/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ exports.pwt = {
owv:"v21.4.0",
abTestEnabled:"0",
pubAnalyticsAdapter: "0",
reduceCodeSize:1
reduceCodeSize:1,
pbGlobalVarNamespace: "custPbNamespace",
owGlobalVarNamespace: "NIT"
};

// singleImpression is used to enable feature of sending single impression for multiple size ad slot earlier there were multiple impression for multiple sizes
Expand Down
9 changes: 9 additions & 0 deletions src_new/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ exports.getAwc = function () {
return awc === "1";
};

exports.getOverrideNamespace = function(configKey, defaultName, returnValueInCaseMissingNamespace) {
var pbNamespace = config[CONSTANTS.CONFIG.COMMON][configKey];
if (pbNamespace) {
return pbNamespace === defaultName ? returnValueInCaseMissingNamespace : pbNamespace;
} else {
return returnValueInCaseMissingNamespace;
}
}

/* start-test-block */
exports.addPrebidAdapter = addPrebidAdapter;
/* end-test-block */
Expand Down
4 changes: 4 additions & 0 deletions src_new/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ exports.COMMON = {
"BID_ID": "owbidid",
"AD_SERVER_CURRENCY": "adServerCurrency",
"SINGLE_IMPRESSION": "singleImpression",
"OPENWRAP_NAMESPACE": "PWT",
"IH_OW_NAMESPACE": "IHPWT",
"PREBID_NAMESPACE": "owpbjs",
"IH_NAMESPACE": "ihowpbjs",
"ENABLE_USER_ID": "identityEnabled",
Expand Down Expand Up @@ -109,6 +111,8 @@ exports.CONFIG = {
"AB_TEST_ENABLED": "abTestEnabled",
"TIMEOUT_ADJUSTMENT": 50,
"SSO_ENABLED": "ssoEnabled",
"PB_GLOBAL_VAR_NAMESPACE": "pbGlobalVarNamespace",
"OW_GLOBAL_VAR_NAMESPACE": "owGlobalVarNamespace",
"FLOOR_SOURCE": "floorSource"
};

Expand Down
2 changes: 2 additions & 0 deletions src_new/ih_footer.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
if(typeof window.IHPWT === "object" && typeof window.IHPWT.jsLoaded === "function"){
window.IHPWT.jsLoaded();
}
3 changes: 0 additions & 3 deletions src_new/ih_header.js

This file was deleted.

3 changes: 3 additions & 0 deletions src_new/ow_footer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if(typeof window.PWT === "object" && typeof window.PWT.jsLoaded === "function"){
window.PWT.jsLoaded();
}
37 changes: 37 additions & 0 deletions test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2411,4 +2411,41 @@ describe('Config', function() {
done();
});
});

describe('getOverrideNamespace', function() {
var configKey = 'pbGlobalVarNamespace';
var defaultName = 'custPbNamespace';
var returnValueInCaseMissingNamespace = 'returnValue';

beforeEach(function(done) {
CONF.pwt = {
pbGlobalVarNamespace: "custPbNamespace",
}
done();
});
afterEach(function(done) {
CONF.pwt = null;
done();
});

it('is a function', function(done) {
CONFIG.getOverrideNamespace.should.be.a('function');
done();
});

it('should return returnValueInCaseMissingNamespace if configKey/pbNamespace is missing', function() {
var result = CONFIG.getOverrideNamespace("missingKeyName", defaultName, returnValueInCaseMissingNamespace);
expect(result).to.equal(returnValueInCaseMissingNamespace);
});

it('should return returnValueInCaseMissingNamespace if pbNamespace is equal to defaultName', function() {
var result = CONFIG.getOverrideNamespace(configKey, defaultName, returnValueInCaseMissingNamespace);
expect(result).to.equal(returnValueInCaseMissingNamespace);
});

it('should return pbNamespace if pbNamespace is not equal to defaultName', function() {
var result = CONFIG.getOverrideNamespace(configKey, "randomValue", returnValueInCaseMissingNamespace);
expect(result).to.equal(defaultName);
});
});
});

0 comments on commit 4b2610f

Please sign in to comment.