Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules #1177

Merged
merged 111 commits into from
Jun 26, 2017
Merged

Modules #1177

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
fc90487
initial implementation of module system
snapwich Apr 26, 2017
83902ac
express module
snapwich May 2, 2017
3ec0738
conversion of rubicon adapter to module system
snapwich May 4, 2017
5c4fa28
use var instead of let in node scripts
snapwich May 5, 2017
a3ebda2
example of using modules for concatenation through webpack code-split…
snapwich May 17, 2017
53485de
fixes for webpack code-splitting
snapwich May 25, 2017
86008bb
changes including config through setConfig and getConfig callback
snapwich May 31, 2017
135730d
external modules working, but node_modules in project still needs bab…
snapwich Jun 2, 2017
627bc28
gulp watch bundle building
snapwich Jun 5, 2017
851c50e
fix for babel-loader node_modules exclusion and bundle only
snapwich Jun 6, 2017
eeb20c4
updated express module to work in new webpack module format
snapwich Jun 6, 2017
3860810
gulp default, don't bundle
snapwich Jun 6, 2017
24cd944
updated rubicon adapter to latest
snapwich Jun 6, 2017
83af09e
added appnexus and appnexusAst to modules. added support for native …
snapwich Jun 7, 2017
1416459
added logging for files getting bundled
snapwich Jun 7, 2017
126c9a5
fixed bug in bundling external modules
snapwich Jun 7, 2017
68507ff
aardvark bid adapter converted to module
snapwich Jun 8, 2017
269922b
upadte appnexus bid adpater names and get ride of mocha loader tests
snapwich Jun 8, 2017
c2cf3fa
adblade bid adapter converted to module
snapwich Jun 8, 2017
2bbb28f
adblund bid adapter converted to module
snapwich Jun 8, 2017
4ffd8a1
adbutler bid adapter converted to module
snapwich Jun 8, 2017
2ea4c7a
adequant bid adapter converted to module
snapwich Jun 8, 2017
7dec65b
adform bid adapter converted to module
snapwich Jun 8, 2017
73ac2ff
adkernel bid adapter converted to module
snapwich Jun 8, 2017
86673d2
admedia bid adapter converted to module
snapwich Jun 8, 2017
9df8bb4
admixer bid adapter converted to module
snapwich Jun 8, 2017
6dcf410
fix pbjs global for tests so load order doesn't matter
snapwich Jun 9, 2017
2c9f572
adsuppply bid adpater converted to module
snapwich Jun 9, 2017
8eac710
use $$PREBID_GLOBAL$$ rather than pbjs in test files
snapwich Jun 9, 2017
524fdd9
adyoulike bid adapter converted to module
snapwich Jun 9, 2017
9830c81
fixed adapter location in some adapters
snapwich Jun 9, 2017
14d81a0
aol bid adapter converted to module
snapwich Jun 9, 2017
a1853ee
atomx bid adapter converted to module
snapwich Jun 9, 2017
2a9bfd5
audienceNetwork bid adapter converted to module
snapwich Jun 9, 2017
3aa893d
beachfront bid adapter converted to module
snapwich Jun 9, 2017
e6f37db
bidfluence bid adapter converted to module
snapwich Jun 9, 2017
7614fc3
brightcom bid adapter converted to module
snapwich Jun 9, 2017
80a75ff
centro bid adapter converted to module
snapwich Jun 9, 2017
3973994
rubicon spec file name changed
snapwich Jun 9, 2017
3ecde27
conversant bid adapter converted to module
snapwich Jun 9, 2017
7183325
criteo bid adapter converted to module
snapwich Jun 9, 2017
b662394
districtmDMX bid adapter converted to module
snapwich Jun 9, 2017
dcd118a
fidelity bid adapter converted to module
snapwich Jun 9, 2017
ad1d6cd
getintent bid adapter converted to module
snapwich Jun 9, 2017
fc9d31e
gumgum bid adapter converted to module
snapwich Jun 12, 2017
c249da4
hiromedia bid adapter converted to module
snapwich Jun 12, 2017
c080a9b
huddledmasses bid adapter converted to module
snapwich Jun 12, 2017
b921e95
indexExchange bid adapter converted to module
snapwich Jun 12, 2017
d8106b9
inneractive bid adapter converted to module
snapwich Jun 12, 2017
63cb70d
innity bid adapter converted to module
snapwich Jun 12, 2017
73f0b55
jcm bid adapter converted to module
snapwich Jun 12, 2017
e0ab8d9
komoona bid adapter converted to module
snapwich Jun 12, 2017
0a9acdd
kruxlink bid adapter converted to module
snapwich Jun 12, 2017
5e4da44
lifestreet bid adapter converted to module
snapwich Jun 12, 2017
3db67a5
mantis bid adapter converted to module
snapwich Jun 12, 2017
fbfa8ee
memeglobal bid adapter converted to module
snapwich Jun 12, 2017
53c3996
nginad bid adapter converted to module
snapwich Jun 12, 2017
26d8cf6
openx bid adapter converted to module
snapwich Jun 12, 2017
49b32fe
piximedia bid adapter converted to module
snapwich Jun 12, 2017
1b6186b
prebidServer bid adapter converted to module
snapwich Jun 12, 2017
6118aac
pubgears bid adapter converted to module
snapwich Jun 12, 2017
d601de1
pubmatic bid adapter converted to module
snapwich Jun 12, 2017
26aabc9
pulsepoint and pulsepointLite bid adapter converted to module
snapwich Jun 12, 2017
5ca71c6
quantcast bid adapter converted to module
snapwich Jun 12, 2017
c0d8172
rhythmone bid adapter converted to module
snapwich Jun 12, 2017
f1d9317
added adkernel alias to headbidding to adkernalBidAdapter module
snapwich Jun 12, 2017
12990f3
roxot bid adapter converted to module
snapwich Jun 12, 2017
f87d5e1
sekindoUM bid adapter converted to module
snapwich Jun 12, 2017
6d5fe5f
remove baseAdapter
snapwich Jun 12, 2017
b849a44
serverbid bid adapter converted to module
snapwich Jun 12, 2017
660dcf2
sharethrough bid adapter converted to module
snapwich Jun 12, 2017
5f254d9
smartyads bid adapter converted to module
snapwich Jun 12, 2017
d7eecab
update conversantBidAdapter to support video
snapwich Jun 12, 2017
aad0771
get rubiconBidAdapter latest
snapwich Jun 12, 2017
6d2b977
move rubicon adapter to module properly
snapwich Jun 12, 2017
c3c199a
sonobi bid adapter converted to module
snapwich Jun 12, 2017
5a457f9
sovrn bid adapter converted to module
snapwich Jun 12, 2017
d9a3db6
springserve bid adpater converted to module
snapwich Jun 12, 2017
98445de
stickyadstv bid adapter converted to module (and removed console logs)
snapwich Jun 12, 2017
29398af
convert tapsense bid adapter to module
snapwich Jun 12, 2017
b90fe13
thoughtleadr bid adapter converted to module
snapwich Jun 12, 2017
f605c7f
trion bid adapter converted to module
snapwich Jun 12, 2017
d8a6be1
triplelift bid adapter converted to module
snapwich Jun 12, 2017
cea7e59
twenga bid adapter converted to module
snapwich Jun 12, 2017
09eedf9
underdogmedia bid adapter converted to module
snapwich Jun 12, 2017
a479984
vertamedia bid adapter converted to module
snapwich Jun 12, 2017
a7c3586
vertoz bid adapter converted to module
snapwich Jun 12, 2017
3a79b15
wideorbit bid adapter converted to module
snapwich Jun 12, 2017
4f9f3c4
widespace bid adapter converted to module
snapwich Jun 12, 2017
9710e0b
xhb bid adapter converted to module
snapwich Jun 12, 2017
800f6ae
yieldbot converted from bid adapter to module
snapwich Jun 13, 2017
8a41018
smartadserver bid adapter converted to module
snapwich Jun 13, 2017
b819030
remove old adapter class in adapter folder
snapwich Jun 13, 2017
32dd129
converted analytics adapters to modules
snapwich Jun 13, 2017
90a40bd
removed loaders from build
snapwich Jun 13, 2017
f281a07
added plugin to remove file manifest and jsonp code from webpack runtime
snapwich Jun 13, 2017
821f27c
cox bid adapter converted to module
snapwich Jun 14, 2017
07cd422
carambola bid adapter converted to module
snapwich Jun 14, 2017
8e039f2
eplanning bid adapter converted to module
snapwich Jun 14, 2017
9e8267f
--modules arg allows .json file as parameter
snapwich Jun 14, 2017
f3de01e
removing config module for now
snapwich Jun 15, 2017
dba8d52
don't bundle AnalyticsAdapter.js in common chunk
snapwich Jun 15, 2017
6edd771
unruly bid adapter converted to module
snapwich Jun 15, 2017
997534e
fixed case-sensitivity in including webpack plugin
snapwich Jun 15, 2017
569c76c
can't use class keyword, updated to constructor function for plugin
snapwich Jun 15, 2017
6713303
added jsdoc to express and new webpack plugin
snapwich Jun 19, 2017
a2c5c1f
fixed sourcemaps for concat step in bundle
snapwich Jun 23, 2017
1dbd41d
use external sourcemap for bundle instead of inline
snapwich Jun 23, 2017
50e9bff
rename prebid.js to prebid-core.js and main bundle outputs prebid.js now
snapwich Jun 26, 2017
1e2d6e5
updated README.md to be module specific
snapwich Jun 26, 2017
15e8565
added filter to ignore hidden files in modules directory
snapwich Jun 26, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,11 @@ This runs some code quality checks, starts a web server at `http://localhost:999

### Build Optimization

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

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.
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.

For example, in `path/to/your/list-of-adapters.json`, write:

[
"openx",
"rubicon",
"sovrn"
]
For example, when running the serve command: `gulp serve --modules=openxBidAdapter,rubiconBidAdapter,sovrnBidAdapter`

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

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

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

$ gulp build --adapters path/to/your/list-of-adapters.json
$ gulp build --modules=openxBidAdapter,rubiconBidAdapter,sovrnBidAdapter

Alternatively, a `.json` file can be specified that contains a list of modules you would like to include.

$ gulp build --modules=modules.json

With `modules.json` containing the following
```json modules.json
[
"openxBidAdapter",
"rubiconBidAdapter",
"sovrnBidAdapter"
]
```

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

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.

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

$ gulp build --adapters path/to/your/list-of-adapters.json
$ gulp build --modules=path/to/your/list-of-modules.json

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

- A change in your list of adapters
- A change in your list of modules
- A new release of `prebid.js`

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

### Add a Bidder Adapter

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

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

Expand Down
161 changes: 0 additions & 161 deletions adapters.json

This file was deleted.

1 change: 0 additions & 1 deletion analytics.json

This file was deleted.

111 changes: 99 additions & 12 deletions gulpHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ const path = require('path');
const argv = require('yargs').argv;
const MANIFEST = 'package.json';
const exec = require('child_process').exec;
const through = require('through2');
const _ = require('lodash');
const gutil = require('gulp-util');

const MODULE_PATH = './modules';
const BUILD_PATH = './build/dist';
const DEV_PATH = './build/dev';


// get only subdirectories that contain package.json with 'main' property
function isModuleDirectory(filePath) {
try {
const manifestPath = path.join(filePath, MANIFEST);
if (fs.statSync(manifestPath).isFile()) {
const module = require(manifestPath);
return module && module.main;
}
}
catch (error) {}
}

module.exports = {
parseBrowserArgs: function (argv) {
Expand All @@ -20,6 +40,85 @@ module.exports = {
.replace(/<\//g, '<\\/')
.replace(/\/>/g, '\\/>');
},
getArgModules() {
var modules = (argv.modules || '').split(',').filter(module => !!module);

try {
if (modules.length === 1 && path.extname(modules[0]).toLowerCase() === '.json') {
var moduleFile = modules[0];

modules = JSON.parse(
fs.readFileSync(moduleFile, 'utf8')
);
}
} catch(e) {
throw new gutil.PluginError({
plugin: 'modules',
message: 'failed reading: ' + argv.modules
});
}

return modules;
},
getModules: _.memoize(function(externalModules) {
externalModules = externalModules || [];
var internalModules;
try {
internalModules = fs.readdirSync(MODULE_PATH)
.filter(file => !(/(^|\/)\.[^\/\.]/g).test(file))
.reduce((memo, file) => {
var moduleName = file.split(new RegExp('[.' + path.sep + ']'))[0];
var filePath = path.join(MODULE_PATH, file);
var modulePath = path.join(__dirname, filePath)
if (fs.lstatSync(filePath).isDirectory()) {
modulePath = path.join(__dirname, filePath, "index.js")
}
memo[modulePath] = moduleName;
return memo;
}, {});
} catch(err) {
internalModules = {};
}
return Object.assign(externalModules.reduce((memo, module) => {
try {
var modulePath = require.resolve(module);
memo[modulePath] = module;
} catch(err) {
// do something
}
return memo;
}, internalModules));
}),

getBuiltModules: function(dev, externalModules) {
var modules = this.getModuleNames(externalModules);
if(Array.isArray(externalModules)) {
modules = _.intersection(modules, externalModules);
}
return modules.map(name => path.join(__dirname, dev ? DEV_PATH : BUILD_PATH, name + '.js'));
},

getBuiltPrebidCoreFile: function(dev) {
return path.join(__dirname, dev ? DEV_PATH : BUILD_PATH, 'prebid-core' + '.js');
},

getModulePaths: function(externalModules) {
var modules = this.getModules(externalModules);
return Object.keys(modules);
},

getModuleNames: function(externalModules) {
return _.values(this.getModules(externalModules));
},

nameModules: function(externalModules) {
var modules = this.getModules(externalModules);
return through.obj(function(file, enc, done) {
file.named = modules[file.path] ? modules[file.path] : 'prebid';
this.push(file);
done();
})
},

/*
* Get source files for analytics subdirectories in top-level `analytics`
Expand All @@ -37,18 +136,6 @@ module.exports = {
const module = require(path.join(directory, moduleDirectory, MANIFEST));
return path.join(directory, moduleDirectory, module.main);
});

// get only subdirectories that contain package.json with 'main' property
function isModuleDirectory(filePath) {
try {
const manifestPath = path.join(filePath, MANIFEST);
if (fs.statSync(manifestPath).isFile()) {
const module = require(manifestPath);
return module && module.main;
}
}
catch (error) {}
}
},

createEnd2EndTestReport : function(targetDestinationDir) {
Expand Down
Loading