This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
136 lines (118 loc) · 3.17 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
var gulp = require('gulp');
// build
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var uglify = require('gulp-uglify');
var saveLicense = require('uglify-save-license');
var fs = require('fs');
var karmaServer = require('karma').Server;
var path = {
distribution: {
folder: 'dist',
filename: 'jquery-addthis'
},
copyright: 'src/copyright.js',
source: 'src/**/*.js'
};
gulp.task('make-folders', function () {
var folders = [path.distribution.folder];
folders.forEach(function(folder) {
try {
fs.mkdirSync(folder);
}
catch(err) {
if (err.code !== 'EEXIST') {
console.warn(err);
}
}
});
});
gulp.task('clean-distribution', function() {
var files = path.distribution.folder + '/*';
return gulp.src(files, {read: false}).pipe(clean());
});
gulp.task('concat', ['make-folders'], function() {
var files = [].concat(
[path.copyright],
path.source
);
return gulp.src(files)
.pipe(concat(path.distribution.filename + '.js'))
.pipe(gulp.dest(path.distribution.folder));
});
gulp.task('minify', ['make-folders'], function() {
var files = [].concat(
[path.copyright],
path.source
);
return gulp.src(files)
.pipe(concat(path.distribution.filename + '.min.js'))
.pipe(uglify({
mangle: false,
output: {
comments: saveLicense
}
}))
.pipe(gulp.dest(path.distribution.folder));
});
gulp.task('build', ['jslint', 'clean-distribution'], function(){
return gulp.start(
'minify',
'concat'
);
});
gulp.task('jslint', function() {
return gulp.src([path.source, 'test/src/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail'));
});
gulp.task('src-unit-test', function(done) {
new karmaServer({
configFile: __dirname + '/test/src.karma.unit.conf.js',
singleRun: true
}, done).start();
});
gulp.task('src-e2e-test', function(done) {
new karmaServer({
configFile: __dirname + '/test/src.karma.e2e.conf.js',
singleRun: true
}, done).start();
});
gulp.task('examples-e2e-test', function(done) {
new karmaServer({
configFile: __dirname + '/test/examples.karma.e2e.conf.js',
singleRun: true
}, done).start();
});
gulp.task('examples-unit-test', function(done) {
new karmaServer({
configFile: __dirname + '/test/examples.karma.unit.conf.js',
singleRun: true
}, done).start();
});
gulp.task('unit-test', function() {
return gulp.start(
'src-unit-test',
'examples-unit-test'
);
});
gulp.task('e2e-test', function() {
return gulp.start(
'src-e2e-test',
'examples-e2e-test'
);
});
gulp.task('test', function() {
return gulp.start(
'src-unit-test',
'src-e2e-test',
'examples-unit-test',
'examples-e2e-test'
);
});
gulp.task('watch', ['build'], function() {
gulp.watch(path.source, ['build']);
});