forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
173 lines (141 loc) · 4.59 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var header = require('gulp-header');
var del = require('del');
var ecstatic = require('ecstatic');
var browserify = require('gulp-browserify');
var gutil = require("gulp-util");
var gulpJsdoc2md = require("gulp-jsdoc-to-markdown");
var concat = require("gulp-concat");
var zip = require('gulp-zip');
var mocha = require('gulp-mocha');
var releaseDir = './dist/';
var csaSrcLocation = './src/prebid.js';
var pkg = require('./package.json');
var dateString = 'Updated : ' + (new Date()).toISOString().substring(0, 10);
var packageNameVersion = pkg.name + '_' + pkg.version;
var banner = '/* <%= pkg.name %> v<%= pkg.version %> \n' + dateString + ' */\n';
//basic/quick tests go here, to be run on every build
gulp.task('runBasicTests', function() {
return gulp.src('test/*', {read: false})
.pipe(mocha());
});
gulp.task('jscs', function() {
return gulp.src(csaSrcLocation)
.pipe(jscs({
'configPath': 'styleRules.jscs.json'
}));
});
//run code quality checks here
gulp.task('jshint', function() {
gulp.src(['./src/*.js', './src/adapters/*.js'])
.pipe(jshint({
'bitwise': 'true',
'curly': 'true',
'scripturl': 'false',
//'enforceall':'false',
//since we are never orriding Prootype (we control all this code)
//I am ok letting this be false in the name of faster code execution
'forin': false,
'eqeqeq': true,
//'es3':true,
//'es5':true,
'freeze': true,
'futurehostile': true,
'latedef': true,
'maxerr': '1000',
'noarg': true,
'nocomma': true,
'nonbsp': true,
'nonew': true,
'notypeof': true,
//excessive parens are ok as long as they increase code readability
//and help to prevent errors, especially when helping to provide
//structure to long conditonal statements
'singleGroups': false,
'undef': true,
'unused': true,
'globals': {
'require': false,
'module' : true,
'exports' : true,
'pbjs' : true,
'googletag': true,
'ActiveXObject': true
},
'browser': true,
'devel': true
}))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
gulp.task('clean-dist', ['quality'], function(cb) {
//del([releaseDir + '']);
cb();
});
//longer tests go here, to be run only when specfcifcally testing
gulp.task('runAdvancedTests', function() {
});
gulp.task('codeQuality', ['jshint', 'jscs'], function() {});
gulp.task('testAll', ['runBasicTests', 'runAdvancedTests'], function() {});
gulp.task('default', ['build'], function() {});
gulp.task('serve', ['build-dev', 'watch'], function () {
var port = 9999;
require('http').createServer(ecstatic({
root: __dirname
})).listen(port);
console.log('Server started at http://localhost:' + port + '/');
});
gulp.task('build-dev', ['jscs', 'clean-dist'], function () {
gulp.src(['src/prebid.js'])
.pipe(browserify({
debug: false
}))
.pipe(header(banner, {
pkg: pkg
}))
.pipe(gulp.dest(releaseDir));
});
gulp.task('minify', ['quality', 'clean-dist', 'build-dev'], function(cb){
gulp.src(['src/prebid.js'])
.pipe(browserify())
.pipe(uglify())
.pipe(header(banner, {
pkg: pkg
}))
.pipe(rename({
basename: 'prebid.min',
extname: '.js'
}))
.pipe(gulp.dest(releaseDir));
//notify that release is ready
cb();
});
gulp.task('build', ['quality', 'clean-dist', 'minify', 'zip']);
gulp.task('quality', ['jscs'], function(cb){
cb();
});
gulp.task('watch', function () {
gulp.watch(['src/**/*.js'], ['build-dev']);
});
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"));
});
//zip up for release
gulp.task('zip', ['quality', 'clean-dist', 'minify'], function () {
return gulp.src(['dist/*', 'integrationExamples/gpt/*'])
.pipe(zip(packageNameVersion + '.zip'))
.pipe(gulp.dest('./'));
});