forked from voltace/browser-cookies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (65 loc) · 2.15 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
var gulp = require('gulp');
var karma = require('karma');
var rename = require('gulp-rename');
var size = require('gulp-size');
var uglify = require('gulp-uglify');
var util = require('util');
var wrap = require('gulp-wrap');
// Defines
var FILENAME_DEV = 'src/browser-cookies.js';
var FILENAME_MIN = 'browser-cookies.min.js';
var FILENAME_TST = 'browser-cookies.test.js';
// Base Karma configuration, contains everything needed for a local test run
// The config is extended by gulp tasks below to add coverage/etc
var karmaConfig = {
basePath: '',
frameworks: ['jasmine'],
files: ['dist/' + FILENAME_TST, 'test/spec.js'],
reporters: ['progress', 'spec'],
port: 9876,
colors: true,
autoWatch: false,
singleRun: true,
preprocessors: {},
browsers: ['PhantomJS'],
//logLevel: 'DEBUG'
};
gulp.task('build:production', function (done) {
return gulp.src(FILENAME_DEV)
.pipe(size({gzip: false, title: FILENAME_DEV + ' size:'}))
.pipe(uglify())
.pipe(rename(FILENAME_MIN))
.pipe(size({gzip: false, title: FILENAME_MIN + ' size:'}))
.pipe(size({gzip: true, title: FILENAME_MIN + ' size:'}))
.pipe(gulp.dest('dist'));
});
gulp.task('build:test', function (done) {
return gulp.src(FILENAME_DEV)
.pipe(rename(FILENAME_TST))
.pipe(wrap('function requireCookies(document, Date, exports) { <%= contents %> }'))
.pipe(gulp.dest("dist"));
});
gulp.task('karma:local', function (done) {
// Copy the Karma config
var config = util._extend({}, karmaConfig);
// Run Karma
new karma.Server(config, done).start();
});
gulp.task('karma:coverage', function (done) {
// Copy the Karma config
var config = util._extend({}, karmaConfig);
// Enable code coverage
config.reporters.push('coverage');
config.preprocessors['dist/' + FILENAME_TST] = ['coverage'];
config.coverageReporter = {
dir: 'coverage/',
reporters: [
{type: 'lcovonly', subdir: '.' }
]
};
// Run Karma
new karma.Server(config, done).start();
});
gulp.task('build', gulp.series(['build:production', 'build:test']));
gulp.task('coverage', gulp.series(['build:test', 'karma:coverage']));
gulp.task('localtest', gulp.series(['build:test', 'karma:local']));