Skip to content

Commit a11f1f9

Browse files
snapwichjbAdyoulike
authored andcommitted
Modules (prebid#1177)
* initial implementation of module system * express module * conversion of rubicon adapter to module system * use var instead of let in node scripts * example of using modules for concatenation through webpack code-splitting * fixes for webpack code-splitting * changes including config through setConfig and getConfig callback * external modules working, but node_modules in project still needs babel-laoder fix * gulp watch bundle building * fix for babel-loader node_modules exclusion and bundle only * updated express module to work in new webpack module format * gulp default, don't bundle * updated rubicon adapter to latest * added appnexus and appnexusAst to modules. added support for native and video registering * added logging for files getting bundled * fixed bug in bundling external modules * aardvark bid adapter converted to module * upadte appnexus bid adpater names and get ride of mocha loader tests * adblade bid adapter converted to module * adblund bid adapter converted to module * adbutler bid adapter converted to module * adequant bid adapter converted to module * adform bid adapter converted to module * adkernel bid adapter converted to module * admedia bid adapter converted to module * admixer bid adapter converted to module * fix pbjs global for tests so load order doesn't matter * adsuppply bid adpater converted to module * use $$PREBID_GLOBAL$$ rather than pbjs in test files * adyoulike bid adapter converted to module * fixed adapter location in some adapters * aol bid adapter converted to module * atomx bid adapter converted to module * audienceNetwork bid adapter converted to module * beachfront bid adapter converted to module * bidfluence bid adapter converted to module * brightcom bid adapter converted to module * centro bid adapter converted to module * rubicon spec file name changed * conversant bid adapter converted to module * criteo bid adapter converted to module * districtmDMX bid adapter converted to module * fidelity bid adapter converted to module * getintent bid adapter converted to module * gumgum bid adapter converted to module * hiromedia bid adapter converted to module * huddledmasses bid adapter converted to module * indexExchange bid adapter converted to module * inneractive bid adapter converted to module * innity bid adapter converted to module * jcm bid adapter converted to module * komoona bid adapter converted to module * kruxlink bid adapter converted to module * lifestreet bid adapter converted to module * mantis bid adapter converted to module * memeglobal bid adapter converted to module * nginad bid adapter converted to module * openx bid adapter converted to module * piximedia bid adapter converted to module * prebidServer bid adapter converted to module * pubgears bid adapter converted to module * pubmatic bid adapter converted to module * pulsepoint and pulsepointLite bid adapter converted to module * quantcast bid adapter converted to module * rhythmone bid adapter converted to module * added adkernel alias to headbidding to adkernalBidAdapter module * roxot bid adapter converted to module * sekindoUM bid adapter converted to module * remove baseAdapter * serverbid bid adapter converted to module * sharethrough bid adapter converted to module * smartyads bid adapter converted to module * update conversantBidAdapter to support video * get rubiconBidAdapter latest * move rubicon adapter to module properly * sonobi bid adapter converted to module * sovrn bid adapter converted to module * springserve bid adpater converted to module * stickyadstv bid adapter converted to module (and removed console logs) * convert tapsense bid adapter to module * thoughtleadr bid adapter converted to module * trion bid adapter converted to module * triplelift bid adapter converted to module * twenga bid adapter converted to module * underdogmedia bid adapter converted to module * vertamedia bid adapter converted to module * vertoz bid adapter converted to module * wideorbit bid adapter converted to module * widespace bid adapter converted to module * xhb bid adapter converted to module * yieldbot converted from bid adapter to module * smartadserver bid adapter converted to module * remove old adapter class in adapter folder * converted analytics adapters to modules * removed loaders from build * added plugin to remove file manifest and jsonp code from webpack runtime * cox bid adapter converted to module * carambola bid adapter converted to module * eplanning bid adapter converted to module * --modules arg allows .json file as parameter * removing config module for now * don't bundle AnalyticsAdapter.js in common chunk * unruly bid adapter converted to module * fixed case-sensitivity in including webpack plugin * can't use class keyword, updated to constructor function for plugin * added jsdoc to express and new webpack plugin * fixed sourcemaps for concat step in bundle * use external sourcemap for bundle instead of inline * rename prebid.js to prebid-core.js and main bundle outputs prebid.js now * updated README.md to be module specific * added filter to ignore hidden files in modules directory
1 parent bc85855 commit a11f1f9

File tree

183 files changed

+3393
-2718
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+3393
-2718
lines changed

README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,11 @@ This runs some code quality checks, starts a web server at `http://localhost:999
5151

5252
### Build Optimization
5353

54-
The standard build output contains all the available bidder adapters listed in `adapters.json`.
54+
The standard build output contains all the available modules from within the `modules` folder.
5555

56-
You might want to exclude some/most of them from the final bundle. To make sure the build only includes the adapters you want, you can make your own adapters file.
56+
You might want to exclude some/most of them from the final bundle. To make sure the build only includes the modules you want, you can specify the modules to be included with the `--modules` CLI argument.
5757

58-
For example, in `path/to/your/list-of-adapters.json`, write:
59-
60-
[
61-
"openx",
62-
"rubicon",
63-
"sovrn"
64-
]
58+
For example, when running the serve command: `gulp serve --modules=openxBidAdapter,rubiconBidAdapter,sovrnBidAdapter`
6559

6660
Building with just these adapters will result in a smaller bundle which should allow your pages to load faster.
6761

@@ -71,26 +65,35 @@ Prebid now supports the `yarn` npm client. This is an alternative to using `npm`
7165
For more info about yarn see https://yarnpkg.com
7266

7367
- Clone the repo, run `yarn install`
74-
- Duplicate `adapters.json` to e.g. `list-of-adapters.json`
75-
- Remove the unnecessary adapters from `list-of-adapters.json`
7668
- Then run the build:
7769

78-
$ gulp build --adapters path/to/your/list-of-adapters.json
70+
$ gulp build --modules=openxBidAdapter,rubiconBidAdapter,sovrnBidAdapter
71+
72+
Alternatively, a `.json` file can be specified that contains a list of modules you would like to include.
73+
74+
$ gulp build --modules=modules.json
75+
76+
With `modules.json` containing the following
77+
```json modules.json
78+
[
79+
"openxBidAdapter",
80+
"rubiconBidAdapter",
81+
"sovrnBidAdapter"
82+
]
83+
```
7984

8085
**Build prebid.js using Yarn for bundling**
8186

8287
In case you'd like to explicitly show that your project uses `prebid.js` and want a reproducible build, consider adding it as an `yarn` dependency.
8388

8489
- Add `prebid.js` as a `yarn` dependency of your project: `yarn add prebid.js`
85-
- Duplicate `node_modules/prebid.js/adapters.json` to under your project path, e.g. `path/to/your/list-of-adapters.json`
86-
- Remove the unnecessary adapters
8790
- Run the `prebid.js` build under the `node_modules/prebid.js/` folder
8891

89-
$ gulp build --adapters path/to/your/list-of-adapters.json
92+
$ gulp build --modules=path/to/your/list-of-modules.json
9093

9194
Most likely your custom `prebid.js` will only change when there's:
9295

93-
- A change in your list of adapters
96+
- A change in your list of modules
9497
- A new release of `prebid.js`
9598

9699
Having said that, you are probably safe to check your custom bundle into your project. You can also generate it in your build process.
@@ -156,7 +159,7 @@ Our PR review process can be found [here](https://github.com/prebid/Prebid.js/tr
156159

157160
### Add a Bidder Adapter
158161

159-
To add a bidder adapter, see the instructions in [How to add a bidder adaptor](http://prebid.org/dev-docs/bidder-adaptor.html).
162+
To add a bidder adapter module, see the instructions in [How to add a bidder adaptor](http://prebid.org/dev-docs/bidder-adaptor.html).
160163

161164
Please **do NOT load Prebid.js inside your adapter**. If you do this, we will reject or remove your adapter as appropriate.
162165

adapters.json

Lines changed: 0 additions & 161 deletions
This file was deleted.

analytics.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

gulpHelpers.js

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ const path = require('path');
44
const argv = require('yargs').argv;
55
const MANIFEST = 'package.json';
66
const exec = require('child_process').exec;
7+
const through = require('through2');
8+
const _ = require('lodash');
9+
const gutil = require('gulp-util');
10+
11+
const MODULE_PATH = './modules';
12+
const BUILD_PATH = './build/dist';
13+
const DEV_PATH = './build/dev';
14+
15+
16+
// get only subdirectories that contain package.json with 'main' property
17+
function isModuleDirectory(filePath) {
18+
try {
19+
const manifestPath = path.join(filePath, MANIFEST);
20+
if (fs.statSync(manifestPath).isFile()) {
21+
const module = require(manifestPath);
22+
return module && module.main;
23+
}
24+
}
25+
catch (error) {}
26+
}
727

828
module.exports = {
929
parseBrowserArgs: function (argv) {
@@ -20,6 +40,85 @@ module.exports = {
2040
.replace(/<\//g, '<\\/')
2141
.replace(/\/>/g, '\\/>');
2242
},
43+
getArgModules() {
44+
var modules = (argv.modules || '').split(',').filter(module => !!module);
45+
46+
try {
47+
if (modules.length === 1 && path.extname(modules[0]).toLowerCase() === '.json') {
48+
var moduleFile = modules[0];
49+
50+
modules = JSON.parse(
51+
fs.readFileSync(moduleFile, 'utf8')
52+
);
53+
}
54+
} catch(e) {
55+
throw new gutil.PluginError({
56+
plugin: 'modules',
57+
message: 'failed reading: ' + argv.modules
58+
});
59+
}
60+
61+
return modules;
62+
},
63+
getModules: _.memoize(function(externalModules) {
64+
externalModules = externalModules || [];
65+
var internalModules;
66+
try {
67+
internalModules = fs.readdirSync(MODULE_PATH)
68+
.filter(file => !(/(^|\/)\.[^\/\.]/g).test(file))
69+
.reduce((memo, file) => {
70+
var moduleName = file.split(new RegExp('[.' + path.sep + ']'))[0];
71+
var filePath = path.join(MODULE_PATH, file);
72+
var modulePath = path.join(__dirname, filePath)
73+
if (fs.lstatSync(filePath).isDirectory()) {
74+
modulePath = path.join(__dirname, filePath, "index.js")
75+
}
76+
memo[modulePath] = moduleName;
77+
return memo;
78+
}, {});
79+
} catch(err) {
80+
internalModules = {};
81+
}
82+
return Object.assign(externalModules.reduce((memo, module) => {
83+
try {
84+
var modulePath = require.resolve(module);
85+
memo[modulePath] = module;
86+
} catch(err) {
87+
// do something
88+
}
89+
return memo;
90+
}, internalModules));
91+
}),
92+
93+
getBuiltModules: function(dev, externalModules) {
94+
var modules = this.getModuleNames(externalModules);
95+
if(Array.isArray(externalModules)) {
96+
modules = _.intersection(modules, externalModules);
97+
}
98+
return modules.map(name => path.join(__dirname, dev ? DEV_PATH : BUILD_PATH, name + '.js'));
99+
},
100+
101+
getBuiltPrebidCoreFile: function(dev) {
102+
return path.join(__dirname, dev ? DEV_PATH : BUILD_PATH, 'prebid-core' + '.js');
103+
},
104+
105+
getModulePaths: function(externalModules) {
106+
var modules = this.getModules(externalModules);
107+
return Object.keys(modules);
108+
},
109+
110+
getModuleNames: function(externalModules) {
111+
return _.values(this.getModules(externalModules));
112+
},
113+
114+
nameModules: function(externalModules) {
115+
var modules = this.getModules(externalModules);
116+
return through.obj(function(file, enc, done) {
117+
file.named = modules[file.path] ? modules[file.path] : 'prebid';
118+
this.push(file);
119+
done();
120+
})
121+
},
23122

24123
/*
25124
* Get source files for analytics subdirectories in top-level `analytics`
@@ -37,18 +136,6 @@ module.exports = {
37136
const module = require(path.join(directory, moduleDirectory, MANIFEST));
38137
return path.join(directory, moduleDirectory, module.main);
39138
});
40-
41-
// get only subdirectories that contain package.json with 'main' property
42-
function isModuleDirectory(filePath) {
43-
try {
44-
const manifestPath = path.join(filePath, MANIFEST);
45-
if (fs.statSync(manifestPath).isFile()) {
46-
const module = require(manifestPath);
47-
return module && module.main;
48-
}
49-
}
50-
catch (error) {}
51-
}
52139
},
53140

54141
createEnd2EndTestReport : function(targetDestinationDir) {

0 commit comments

Comments
 (0)