-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgulpfile.js
103 lines (88 loc) · 2.54 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
/*jshint latedef: nofunc */
'use strict';
var path = require('path');
var fs = require('fs');
var gulp = require('gulp');
var $ = require('gulp-load-plugins')({lazy: false});
var pkg = require('./package.json');
var dateformat = require('dateformat');
var rimraf = require('rimraf');
var karma = require('karma').server;
var karmaConfPath = path.join(__dirname, 'karma.conf.js');
var paths = require('./paths.conf')();
var shell = require('shelljs');
gulp.task('test', ['lint'], function (done) {
karma.start({
configFile: karmaConfPath,
singleRun: true
}, done);
});
gulp.task('test-ci', function (done) {
karma.start({
configFile: karmaConfPath
}, done);
});
gulp.task('lint', function () {
return gulp.src([paths.src.all, paths.test.all, paths.gulpfile])
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'));
});
gulp.task('coverage-report', ['test'], function (done) {
shell.exec('rm -rf ' + paths.reports.coverage);
shell.exec('mkdir ' + paths.reports.coverage);
shell.exec('cp -r ' + paths.coverage + '**/* ' + paths.reports.coverage);
done();
});
gulp.task('plato', function () {
return gulp.src(paths.src.all)
.pipe($.plato(paths.reports.plato, {
jshint: JSON.parse(fs.readFileSync(paths.src.jshintrc))
}));
});
gulp.task('reports', ['coverage-report', 'plato']);
gulp.task('clean', function (done) {
rimraf(paths.dist, done);
});
gulp.task('committers', function () {
$.gitCommitters({email: true})
.pipe(gulp.dest('CONTRIBUTORS.txt'));
});
gulp.task('default', ['build']);
gulp.task('build', ['clean'], function () {
var h = header();
gulp.src(paths.src.files)
.pipe($.concat(pkg.name + '.js'))
.pipe($.header(h.long, h))
.pipe(gulp.dest('dist'))
.pipe($.sourcemaps.init())
.pipe($.uglify())
.pipe($.header(h.short, h))
.pipe($.rename({extname: '.min.js'}))
.pipe($.sourcemaps.write('../' + paths.dist))
.pipe(gulp.dest(paths.dist));
});
function header() {
var date = new Date();
pkg.date = dateformat(date, 'yyyy-MM-dd');
pkg.year = date.getFullYear();
var long = [
'/*!',
'* <%= pkg.name %> v<%= pkg.version %> - <%= pkg.date %>',
'* <%= pkg.homepage %>',
'* Copyright (c) <%= pkg.year %> <%= pkg.author %>',
'* Released under the <%= pkg.licenses[0].type %> license',
'* <%= pkg.licenses[0].url %>',
'*/',
''
].join('\n');
var short = [
'/*! <%= pkg.name %> v<%= pkg.version %>',
'<%= pkg.homepage %>',
'<%= pkg.licenses[0].url %> */\n'
].join(' | ');
return {
long: long,
short: short,
pkg: pkg
};
}