forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
221 lines (185 loc) · 6.03 KB
/
gulpfile.js
File metadata and controls
221 lines (185 loc) · 6.03 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
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 gulpBrowserify = 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 preprocessify = require('preprocessify');
/** for automated unit testing */
var browserSync = require("browser-sync"),
browserify = require("browserify"),
source = require("vinyl-source-stream"),
mochaPhantomJS = require("gulp-mocha-phantomjs");
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', function(cb) {
del([releaseDir + '']);
cb();
});
gulp.task('codeQuality', ['jshint', 'jscs'], function() {});
gulp.task('default', ['build'], function() {});
gulp.task('serve', ['build-dev', 'watch', 'browser-sync'], 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', 'browserify', 'unit-tests'], function () {
gulp.src(['src/prebid.js'])
.pipe(gulpBrowserify({
debug: false
}))
.pipe(header(banner, {
pkg: pkg
}))
.pipe(gulp.dest(releaseDir));
});
gulp.task('build-minify', ['clean-dist', 'quality'], function(cb){
gulp.src(['src/prebid.js'])
.pipe(gulpBrowserify({
transform : preprocessify({ NODE_ENV: 'production'})
}
))
//unminified version:
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest(releaseDir))
//minified version
.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', ['clean-dist', 'quality', 'build-minify', 'zip']);
gulp.task('quality', ['jscs'], function(cb){
cb();
});
gulp.task('watch', function () {
// gulp.watch(['src/**/*.js'], ['build-dev']);
gulp.watch(["test/tests.js", "src/*","test/spec/*.js"], ["browserify", "unit-tests"]);
});
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', 'build-minify'], function () {
return gulp.src(['dist/*', 'integrationExamples/gpt/*'])
.pipe(zip(packageNameVersion + '.zip'))
.pipe(gulp.dest('./'));
});
gulp.task("browser-sync", function () {
"use strict";
browserSync({
server: {
//serve tests and the root as base dirs
baseDir: ["./test/", "./"],
//make tests.html the index file
index: "automatedRunnner.html"
}
});
});
//see http://fettblog.eu/gulp-browserify-multiple-bundles/
gulp.task("browserify", function() {
"use strict";
var files =[
"./test/test.js",
"./test/spec/api_spec.js",
"./test/spec/utils_spec.js",
"./test/spec/adUnits_spec.js",
"./test/spec/aliasBidder_spec.js"
];
return browserify({ entries: [files] })
.bundle()
.on("error", function (err) {
console.log(err.toString());
this.emit("end");
})
.pipe(source("tests-browserify.js"))
.pipe(gulp.dest("test/"))
.pipe(browserSync.reload({stream:true}));
});
gulp.task("unit-tests", function () {
"use strict";
return gulp.src("./test/automatedRunnner.html")
.pipe(mochaPhantomJS());
});