forked from haltu/muuri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
78 lines (61 loc) · 1.63 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
var package = require('./package.json');
var fs = require('fs');
var gulp = require('gulp');
var jscs = require('gulp-jscs');
var karma = require('karma');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var size = require('gulp-size');
var rimraf = require('rimraf');
var runSequence = require('run-sequence');
var fileExists = function (filePath) {
try {
return fs.statSync(filePath).isFile();
} catch (err) {
return false;
}
};
// Load environment variables if .env file exists
if (fileExists('./.env')) {
require('dotenv').load();
}
gulp.task('validate', function () {
return gulp
.src(package.main)
.pipe(jscs())
.pipe(jscs.reporter());
});
gulp.task('compress', function() {
var mainMinified = package.main.replace('./', '').replace('.js', '.min.js');
return gulp
.src(package.main)
.pipe(size({title: 'development'}))
.pipe(uglify({
preserveComments: 'some'
}))
.pipe(size({title: 'minified'}))
.pipe(size({title: 'gzipped', gzip: true}))
.pipe(rename(mainMinified))
.pipe(gulp.dest('./'));
});
gulp.task('test', function (done) {
(new karma.Server({
configFile: __dirname + '/karma.conf.js',
action: 'run'
}, function (exitCode) {
done(exitCode);
})).start();
});
gulp.task('clean', function (cb) {
rimraf('./*.log', function () {
rimraf('./coverage', cb);
});
});
gulp.task('default', function (done) {
if (process.env.CI) {
runSequence('validate', 'compress', 'test', 'clean', done);
}
else {
runSequence('validate', 'compress', 'test', done);
}
});