Skip to content

Commit

Permalink
Code Quality and Style Standards
Browse files Browse the repository at this point in the history
Define jscs and jshint settings to report on code quality and style standards. Updates code files to standards.
In some cases adapters were also updated, while some jshint options are set to be ignored.
This is not set to enforce quality at commit or build time ... yet. We will want to set that in place soon.
Also, add support for babel and es6 syntax. See the file `test/helpers/pbjs-test-only.js` for an example of
an ES6 module. This file is imported using ES6 syntax in the `test/spec/aliasBidder_spec.js` file and required
the ES5 way in `test/spec/adUnits_spec.js`.
  • Loading branch information
protonate committed Feb 23, 2016
1 parent db38f6a commit 858aadc
Show file tree
Hide file tree
Showing 40 changed files with 4,849 additions and 4,707 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "presets": ["es2015"] }
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Built Files
node_modules/
build/coverage
build

# Test Files
test/app
Expand Down
6 changes: 6 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"maxErrors": 5000,
"esnext": true,
"requireTrailingComma": false,
"requireCamelCaseOrUpperCaseIdentifiers": false
}
13 changes: 9 additions & 4 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
{
"bitwise": true,
"bitwise": false,
"browser": true,
"curly": false,
"devel": true,
"eqeqeq": true,
"es3": true,
"freeze": true,
"immed": true,
"maxdepth": 5,
"newcap": true,
"noarg": true,
"node": true,
"notypeof": true,
"esnext": true,
"trailing": true,
"undef": true,
"unused": true,
"strict": false,
"scripturl": true,
"globals": {
"before": true,
"after": true,
"exports": true,
"pbjs": true,
"pbjsTestOnly": true,
"assert": false,
"mediation": false,
"expect": false,
"dump": false,
"describe": false,
Expand All @@ -28,6 +33,6 @@
"sinon": false,
"beforeEach": false,
"afterEach": false,
"APN": false
"JSON": true
}
}
28 changes: 15 additions & 13 deletions gulpHelpers.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module.exports = {
parseBrowserArgs: function(argv) {
return (argv.browsers) ? argv.browsers.split(',') : [];
},
toCapitalCase: function(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
},
jsonifyHTML: function(str) {
console.log(arguments);
return str.replace(/\n/g, '')
.replace(/<\//g, '<\\/')
.replace(/\/>/g, '\\/>');
}
};
parseBrowserArgs: function (argv) {
return (argv.browsers) ? argv.browsers.split(',') : [];
},

toCapitalCase: function (str) {
return str.charAt(0).toUpperCase() + str.slice(1);
},

jsonifyHTML: function (str) {
console.log(arguments);
return str.replace(/\n/g, '')
.replace(/<\//g, '<\\/')
.replace(/\/>/g, '\\/>');
}
};
160 changes: 82 additions & 78 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var fs = require('fs');
var argv = require('yargs').argv;
var gulp = require('gulp');
var gutil = require('gulp-util');
Expand All @@ -8,18 +7,16 @@ var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var clean = require('gulp-clean');
var karma = require('gulp-karma');
var replace = require('gulp-replace');
var rename = require('gulp-rename');
var opens = require('open');
var webpackConfig = require('./webpack.conf.js');
var helpers = require('./gulpHelpers');
var path = require('path');
var del = require('del');
var gulpJsdoc2md = require("gulp-jsdoc-to-markdown");
var concat = require("gulp-concat");
var gulpJsdoc2md = require('gulp-jsdoc-to-markdown');
var concat = require('gulp-concat');
var jscs = require('gulp-jscs');
var header = require('gulp-header');
var zip = require('gulp-zip');
var babel = require('gulp-babel');

var CI_MODE = process.env.NODE_ENV === 'ci';
var prebidSrcLocation = './src/prebid.js';
Expand All @@ -35,103 +32,110 @@ gulp.task('serve', ['clean', 'quality', 'webpack', 'watch', 'test']);

gulp.task('build', ['clean', 'quality', 'webpack', 'zip']);

gulp.task('clean', function() {
return gulp.src(['build', 'test/app/**/*.js', 'test/app/index.html'], {
read: false
})
.pipe(clean());
gulp.task('clean', function () {
return gulp.src(['build', 'test/app/**/*.js', 'test/app/index.html'], {
read: false
})
.pipe(clean());
});

gulp.task('webpack', function() {

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

return gulp.src('src/*.js')
.pipe(webpack(webpackConfig))
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest('build/dev'))
.pipe(uglify())
.pipe(gulp.dest('build/dist'))
.pipe(connect.reload());
gulp.task('webpack', function () {

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

return gulp.src('src/**/*.js')
.pipe(header(banner, { pkg: pkg }))
.pipe(webpack(webpackConfig))
.pipe(babel({
presets: ['es2015']
}))
.pipe(gulp.dest('build/dev'))
.pipe(uglify())
.pipe(gulp.dest('build/dist'))
.pipe(connect.reload());
});

//zip up for release
gulp.task('zip', ['jscs', 'clean', 'webpack'], function () {
return gulp.src(['build/dist/*', 'integrationExamples/gpt/*'])
.pipe(zip(packageNameVersion + '.zip'))
.pipe(gulp.dest('./'));
return gulp.src(['build/dist/*', 'integrationExamples/gpt/*'])
.pipe(zip(packageNameVersion + '.zip'))
.pipe(gulp.dest('./'));
});

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

return gulp.src('lookAtKarmaConfJS')
.pipe(karma({
browsers: (browserArgs.length > 0) ? browserArgs : defaultBrowsers,
configFile: 'karma.conf.js',
action: (argv.watch) ? 'watch' : 'run'
}));
gulp.task('test', function () {
var defaultBrowsers = CI_MODE ? ['PhantomJS'] : ['Chrome'];
var browserArgs = helpers.parseBrowserArgs(argv).map(helpers.toCapitalCase);

return gulp.src('lookAtKarmaConfJS')
.pipe(babel({
presets: ['es2015']
}))
.pipe(karma({
browsers: (browserArgs.length > 0) ? browserArgs : defaultBrowsers,
configFile: 'karma.conf.js',
action: (argv.watch) ? 'watch' : 'run'
}));
});

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

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

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

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

gulp.watch(['test/spec/**/*.js'], ['webpack', 'test']);
gulp.watch(['integrationExamples/gpt/*.html'], ['test']);
gulp.watch(['src/**/*.js'], ['webpack', 'test']);
connect.server({
port: 9999,
root: './',
livereload: true
});
gulp.task('watch', function () {

gulp.watch(['test/spec/**/*.js'], ['webpack', 'test']);
gulp.watch(['integrationExamples/gpt/*.html'], ['test']);
gulp.watch(['src/**/*.js'], ['webpack', 'test']);
connect.server({
port: 9999,
root: './',
livereload: true
});
});

gulp.task('quality', ['hint', 'jscs'], function() {});
gulp.task('quality', ['hint', 'jscs'], function () {
});

gulp.task('hint', function() {
return gulp.src('src/**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'));
gulp.task('hint', function () {
return gulp.src('src/**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'));
});

gulp.task('jscs', function() {
return gulp.src(prebidSrcLocation)
.pipe(jscs({
'configPath': 'styleRules.jscs.json'
}));
gulp.task('jscs', function () {
return gulp.src('src/**/*.js')
.pipe(jscs({
configPath: '.jscsrc'
}));
});

gulp.task('clean-docs', function(){
del(['docs']);
gulp.task('clean-docs', function () {
del(['docs']);
});

gulp.task("docs", ['clean-docs'], function() {
return gulp.src("src/prebid.js")
.pipe(concat("readme.md"))
.pipe(gulpJsdoc2md())
.on("error", function(err){
gutil.log("jsdoc2md failed:", err.message);
})
.pipe(gulp.dest("docs"));
gulp.task('docs', ['clean-docs'], function () {
return gulp.src('src/prebid.js')
.pipe(concat('readme.md'))
.pipe(gulpJsdoc2md())
.on('error', function (err) {
gutil.log('jsdoc2md failed:', err.message);
})
.pipe(gulp.dest('docs'));
});

Loading

0 comments on commit 858aadc

Please sign in to comment.