Skip to content

Commit

Permalink
Create module registry: update build to add installModules array to p…
Browse files Browse the repository at this point in the history
…bjs global (#6601)

* - Remove module list comment on build
- Add pbjs.installedModules with macro to prebid.js
- Update gruntfile to replace macro with module array (if empty array all modules included))

* Removed unused code

* Removed comma

* Recommitting changes

* Updated regex to look for either '|" in macro name. Seems there is a difference between dev/prod
  • Loading branch information
mmoschovas authored and idettman committed May 21, 2021
1 parent 9b88acb commit 3cf41fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 10 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const execa = require('execa');

var prebid = require('./package.json');
var dateString = 'Updated : ' + (new Date()).toISOString().substring(0, 10);
var banner = '/* <%= prebid.name %> v<%= prebid.version %>\n' + dateString + '\nModules: <%= modules %> */\n';
var banner = '/* <%= prebid.name %> v<%= prebid.version %>\n' + dateString + '*/\n';
var port = 9999;
const FAKE_SERVER_HOST = argv.host ? argv.host : 'localhost';
const FAKE_SERVER_PORT = 4444;
Expand Down Expand Up @@ -134,6 +134,12 @@ function watch(done) {
done();
};

function makeModuleList(modules) {
return modules.map(module => {
return '"' + module + '"'
});
}

function makeDevpackPkg() {
var cloned = _.cloneDeep(webpackConfig);
cloned.devtool = 'source-map';
Expand All @@ -145,6 +151,7 @@ function makeDevpackPkg() {
return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(replace(/('|")v\$prebid\.modulesList\$('|")/g, makeModuleList(externalModules)))
.pipe(gulp.dest('build/dev'))
.pipe(connect.reload());
}
Expand All @@ -157,13 +164,13 @@ function makeWebpackPkg() {

const analyticsSources = helpers.getAnalyticsSources();
const moduleSources = helpers.getModulePaths(externalModules);
const modulesString = getModulesListToAddInBanner(externalModules);

return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(uglify())
.pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid, modules: modulesString })))
.pipe(replace(/('|")v\$prebid\.modulesList\$('|")/g, makeModuleList(externalModules)))
.pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid})))
.pipe(gulp.dest('build/dist'));
}

Expand Down
3 changes: 3 additions & 0 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ $$PREBID_GLOBAL$$.libLoaded = true;
$$PREBID_GLOBAL$$.version = 'v$prebid.version$';
utils.logInfo('Prebid.js v$prebid.version$ loaded');

// modules list generated from build
$$PREBID_GLOBAL$$.installedModules = ['v$prebid.modulesList$'];

// create adUnit array
$$PREBID_GLOBAL$$.adUnits = $$PREBID_GLOBAL$$.adUnits || [];

Expand Down

0 comments on commit 3cf41fe

Please sign in to comment.