Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/master' into contrib/a…
Browse files Browse the repository at this point in the history
…ol-adapter-aliases

# Conflicts:
#	modules/aolBidAdapter.js
  • Loading branch information
vzhukovsky committed Jul 26, 2017
2 parents d26fdc0 + 180854a commit bef0125
Show file tree
Hide file tree
Showing 131 changed files with 4,474 additions and 2,229 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -23,6 +23,7 @@ module.exports = {
"camelcase": "off",
"eqeqeq": "off",
"import/first": "off",
"new-cap": "off",
"no-control-regex": "off",
"no-mixed-operators": "off",
"no-multiple-empty-lines": "off",
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
@@ -1 +1 @@
5.1
7.0
14 changes: 4 additions & 10 deletions .travis.yml
@@ -1,23 +1,17 @@
sudo: required
dist: trusty

language: node_js

node_js:
- "5.1"
- "7.0"

# See https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-the-Chrome-addon-in-the-headless-mode
addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
chrome: stable

before_install:
- npm install -g gulp
- export CHROME_BIN=google-chrome
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &

script:
- gulp run-tests
43 changes: 31 additions & 12 deletions README.md
Expand Up @@ -28,10 +28,12 @@ Working examples can be found in [the developer docs](http://prebid.org/dev-docs
$ cd Prebid.js
$ yarn install

Prebid also supports the `yarn` npm client. This is an alternative to using `npm` for package management, though `npm` will continue to work as before.
Prebid supports the `yarn` npm client. This is an alternative to using `npm` for package management, though `npm install` will continue to work as before.

For more info, see [the Yarn documentation](https://yarnpkg.com).

*Note:* You need to have `NodeJS` 4.x or greater installed.

<a name="Build"></a>

## Build for Development
Expand All @@ -47,8 +49,6 @@ This runs some code quality checks, starts a web server at `http://localhost:999
+ `./build/dist/prebid.js` - Minified production code
+ `./prebid.js_<version>.zip` - Distributable zip archive

*Note:* You need to have `node.js` 4.x or greater installed to be able to run the `gulp build` commands.

### Build Optimization

The standard build output contains all the available modules from within the `modules` folder.
Expand Down Expand Up @@ -102,7 +102,26 @@ Having said that, you are probably safe to check your custom bundle into your pr

## Test locally

To configure Prebid.js to run locally, edit the example file `./integrationExamples/gpt/pbjs_example_gpt.html`:
To lint the code:

```bash
gulp lint
```

To run the unit tests:

```bash
gulp test
```

To generate and view the code coverage reports:

```bash
gulp test-coverage
gulp view-coverage
```

For end-to-end testing, edit the example file `./integrationExamples/gpt/pbjs_example_gpt.html`:

1. Change `{id}` values appropriately to set up ad units and bidders
2. Set the path to Prebid.js in your example file as shown below (see `pbs.src`).
Expand Down Expand Up @@ -131,21 +150,21 @@ For deployment:
})();
```

To run the project locally, use:
Build and run the project locally with:

$ gulp serve
```bash
gulp serve
```

This runs code quality checks, generates all the necessary files and starts a web server at `http://localhost:9999` serving from the project root. Navigate to your example implementation to test, and if your `prebid.js` file is sourced from the `./build/dev` directory you will have sourcemaps available in your browser's developer tools.
This runs `lint` and `test`, then starts a web server at `http://localhost:9999` serving from the project root.
Navigate to your example implementation to test, and if your `prebid.js` file is sourced from the `./build/dev`
directory you will have sourcemaps available in your browser's developer tools.

To run the example file, go to:

+ `http://localhost:9999/integrationExamples/gpt/pbjs_example_gpt.html`

To view a test coverage report, go to:

+ `http://localhost:9999/build/coverage/karma_html/report`

A watch is also in place that will run continuous tests in the terminal as you edit code and tests.
As you make code changes, the bundles will be rebuilt and the page reloaded automatically.

<a name="Contribute"></a>

Expand Down
4 changes: 0 additions & 4 deletions browsers.json
Expand Up @@ -214,9 +214,5 @@
"browser": "iphone",
"device": "iPhone 6S",
"browser_version": null
},
"Chrome_travis_ci": {
"base": "Chrome",
"flags": ["--no-sandbox"]
}
}
1 change: 1 addition & 0 deletions governance.md
Expand Up @@ -20,3 +20,4 @@ This document describes the governance model for the Prebid project. The Prebid
- @jaiminpanchal27
- @snapwich
- @harpere
- @dbemiller
125 changes: 57 additions & 68 deletions gulpfile.js
Expand Up @@ -3,15 +3,17 @@
var _ = require('lodash');
var argv = require('yargs').argv;
var gulp = require('gulp');
var argv = require('yargs').argv;
var gutil = require('gulp-util');
var connect = require('gulp-connect');
var webpack = require('webpack-stream');
var path = require('path');
var webpack = require('webpack');
var webpackStream = require('webpack-stream');
var uglify = require('gulp-uglify');
var clean = require('gulp-clean');
var karma = require('gulp-karma');
var KarmaServer = require('karma').Server;
var karmaConfMaker = require('./karma.conf.maker');
var opens = require('open');
var webpackConfig = require('./webpack.conf.js');
var webpackConfig = require('./webpack.conf');
var helpers = require('./gulpHelpers');
var del = require('del');
var gulpJsdoc2md = require('gulp-jsdoc-to-markdown');
Expand All @@ -26,10 +28,8 @@ var gulpif = require('gulp-if');
var sourcemaps = require('gulp-sourcemaps');
var fs = require('fs');

var CI_MODE = process.env.NODE_ENV === 'ci';
var prebid = require('./package.json');
var dateString = 'Updated : ' + (new Date()).toISOString().substring(0, 10);
var packageNameVersion = prebid.name + '_' + prebid.version;
var banner = '/* <%= prebid.name %> v<%= prebid.version %>\n' + dateString + ' */\n';
var analyticsDirectory = '../analytics';
var port = 9999;
Expand All @@ -41,7 +41,7 @@ gulp.task('serve', ['lint', 'build-bundle-dev', 'watch', 'test']);

gulp.task('serve-nw', ['lint', 'watch', 'e2etest']);

gulp.task('run-tests', ['lint', 'test']);
gulp.task('run-tests', ['lint', 'test-coverage']);

gulp.task('build', ['build-bundle-prod']);

Expand Down Expand Up @@ -86,33 +86,47 @@ function bundle(dev) {
.pipe(gulp.dest('build/' + (dev ? 'dev' : 'dist')));
}

// Workaround for incompatibility between Karma & gulp callbacks.
// See https://github.com/karma-runner/gulp-karma/issues/18 for some related discussion.
function newKarmaCallback(done) {
return function (exitCode) {
if (exitCode) {
done(new Error('Karma tests failed with exit code ' + exitCode));
} else {
done();
}
}
}

gulp.task('build-bundle-dev', ['devpack'], bundle.bind(null, true));
gulp.task('build-bundle-prod', ['webpack'], bundle.bind(null, false));
gulp.task('bundle', bundle.bind(null, false)); // used for just concatenating pre-built files with no build step

gulp.task('devpack', ['clean'], function () {
webpackConfig.devtool = 'source-map';
var cloned = _.cloneDeep(webpackConfig);
cloned.devtool = 'source-map';
var externalModules = helpers.getArgModules();

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

return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpack(webpackConfig))
.pipe(webpackStream(cloned, webpack))
.pipe(replace('$prebid.version$', prebid.version))
.pipe(gulp.dest('build/dev'))
.pipe(connect.reload());
});

gulp.task('webpack', ['clean'], function () {
var cloned = _.cloneDeep(webpackConfig);

// change output filename if argument --tag given
if (argv.tag && argv.tag.length) {
webpackConfig.output.filename = 'prebid.' + argv.tag + '.js';
cloned.output.filename = 'prebid.' + argv.tag + '.js';
}

webpackConfig.devtool = null;
delete cloned.devtool;

var externalModules = helpers.getArgModules();

Expand All @@ -121,89 +135,59 @@ gulp.task('webpack', ['clean'], function () {

return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpack(webpackConfig))
.pipe(webpackStream(cloned, webpack))
.pipe(replace('$prebid.version$', prebid.version))
.pipe(uglify())
.pipe(gulpif(file => file.basename === 'prebid.js', header(banner, { prebid: prebid })))
.pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid })))
.pipe(optimizejs())
.pipe(gulp.dest('build/dist'))
.pipe(connect.reload());
});

// Karma Continuous Testing
// Pass your browsers by using --browsers=chrome,firefox,ie9
// Run CI by passing --watch
gulp.task('test', ['clean'], function () {
var defaultBrowsers = CI_MODE ? ['PhantomJS'] : ['Chrome'];
var browserArgs = helpers.parseBrowserArgs(argv).map(helpers.toCapitalCase);

if (process.env.TRAVIS) {
browserArgs = ['Chrome_travis_ci'];
// Run the unit tests.
//
// By default, this runs in headless chrome.
//
// If --watch is given, the task will re-run unit tests whenever the source code changes
// If --browserstack is given, it will run the full suite of currently supported browsers.
// If --browsers is given, browsers can be chosen explicitly. e.g. --browsers=chrome,firefox,ie9
gulp.task('test', ['clean'], function (done) {
var karmaConf = karmaConfMaker(false, argv.browserstack, argv.watch);

var browserOverride = helpers.parseBrowserArgs(argv).map(helpers.toCapitalCase);
if (browserOverride.length > 0) {
karmaConf.browsers = browserOverride;
}

if (argv.browserstack) {
browserArgs = [
'bs_ie_13_windows_10',
'bs_ie_11_windows_10',
'bs_firefox_46_windows_10',
'bs_chrome_51_windows_10',
'bs_ie_11_windows_8.1',
'bs_firefox_46_windows_8.1',
'bs_chrome_51_windows_8.1',
'bs_ie_10_windows_8',
'bs_firefox_46_windows_8',
'bs_chrome_51_windows_8',
'bs_ie_11_windows_7',
'bs_ie_10_windows_7',
'bs_ie_9_windows_7',
'bs_firefox_46_windows_7',
'bs_chrome_51_windows_7',
'bs_safari_9.1_mac_elcapitan',
'bs_firefox_46_mac_elcapitan',
'bs_chrome_51_mac_elcapitan',
'bs_safari_8_mac_yosemite',
'bs_firefox_46_mac_yosemite',
'bs_chrome_51_mac_yosemite',
'bs_safari_7.1_mac_mavericks',
'bs_firefox_46_mac_mavericks',
'bs_chrome_49_mac_mavericks',
'bs_ios_7',
'bs_ios_8',
'bs_ios_9',
];
}
new KarmaServer(karmaConf, newKarmaCallback(done)).start();
});

return gulp.src('lookAtKarmaConfJS')
.pipe(karma({
browsers: (browserArgs.length > 0) ? browserArgs : defaultBrowsers,
configFile: 'karma.conf.js',
action: (argv.watch) ? 'watch' : 'run'
}));
gulp.task('test-coverage', ['clean'], function(done) {
new KarmaServer(karmaConfMaker(true, false), newKarmaCallback(done)).start();
});

// Small task to load coverage reports in the browser
gulp.task('coverage', function (done) {
// View the code coverage report in the browser.
gulp.task('view-coverage', function (done) {
var coveragePort = 1999;

connect.server({
port: 1999,
root: 'build/coverage',
port: coveragePort,
root: 'build/coverage/karma_html',
livereload: false
});
opens('http://localhost:' + coveragePort + '/coverage/');
opens('http://localhost:' + coveragePort);
done();
});

gulp.task('coveralls', ['test'], function() { // 2nd arg is a dependency: 'test' must be finished
gulp.task('coveralls', ['test-coverage'], function() { // 2nd arg is a dependency: 'test' must be finished
// first send results of istanbul's test coverage to coveralls.io.
return gulp.src('gulpfile.js', { read: false }) // You have to give it a file, but you don't
// have to read it.
.pipe(shell('cat build/coverage/lcov/lcov.info | node_modules/coveralls/bin/coveralls.js'));
.pipe(shell('cat build/coverage/lcov.info | node_modules/coveralls/bin/coveralls.js'));
});

// Watch Task with Live Reload
gulp.task('watch', function () {

gulp.watch([
'src/**/*.js',
'modules/**/*.js',
Expand All @@ -223,7 +207,7 @@ gulp.task('watch', function () {
});

gulp.task('lint', () => {
return gulp.src(['src/**/*.js', 'test/**/*.js'])
return gulp.src(['src/**/*.js', 'modules/**/*.js', 'test/**/*.js'])
.pipe(eslint())
.pipe(eslint.format('stylish'))
.pipe(eslint.failAfterError());
Expand Down Expand Up @@ -285,5 +269,10 @@ gulp.task('e2etest-report', function() {
setTimeout(function() {
opens('http://localhost:' + reportPort + '/' + targetDestinationDir.slice(2) + '/results.html');
}, 5000);
});

gulp.task('build-postbid', function() {
return gulp.src('./integrationExamples/postbid/oas/postbid.js')
.pipe(uglify())
.pipe(gulp.dest('build/dist'));
});

0 comments on commit bef0125

Please sign in to comment.