forked from haltu/muuri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
215 lines (191 loc) · 5.06 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
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
const fs = require('fs');
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const karma = require('karma');
const size = require('gulp-size');
const rimraf = require('rimraf');
const argv = require('yargs').argv;
const dotenv = require('dotenv');
const replace = require('gulp-replace');
const exec = require('child_process').exec;
const pkg = require('./package.json');
const karmaDefaults = require('./karma.defaults.js');
const patchedUMD = `(function (global, factory) {
if (typeof exports === 'object' && typeof module !== 'undefined') {
var Hammer;
try { Hammer = require('hammerjs') } catch (e) {}
module.exports = factory(Hammer);
} else {
global.Muuri = factory(global.Hammer);
}
}(this, (function (Hammer) {
'use strict';`;
if (fs.existsSync('./.env')) dotenv.load();
gulp.task('lint', () => {
return gulp
.src('./src/**/*.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('size', () => {
const mainPath = './' + pkg.main;
const minifiedPath = mainPath.replace('.js', '.min.js');
return gulp
.src([mainPath, minifiedPath])
.pipe(
size({
showFiles: true,
showTotal: false
})
)
.pipe(
size({
showFiles: true,
showTotal: false,
title: 'gzipped',
gzip: true
})
);
});
gulp.task('clean', cb => {
rimraf('./*.log', cb);
});
gulp.task('test-local', done => {
// Setup browsers.
const browsers = [];
argv.chrome && browsers.push('Chrome');
argv.firefox && browsers.push('Firefox');
argv.safari && browsers.push('Safari');
argv.edge && browsers.push('Edge');
if (!browsers.length) browsers.push('Chrome');
new karma.Server(
{
configFile: __dirname + '/karma.conf.js',
action: 'run',
browsers
},
exitCode => {
done(exitCode);
}
).start();
});
gulp.task('test-local-min', done => {
// Setup browsers.
const browsers = [];
argv.chrome && browsers.push('Chrome');
argv.firefox && browsers.push('Firefox');
argv.safari && browsers.push('Safari');
argv.edge && browsers.push('Edge');
if (!browsers.length) browsers.push('Chrome');
// Replace main file with minified version.
const mainPath = './' + pkg.main;
const minifiedPath = mainPath.replace('.js', '.min.js');
const files = karmaDefaults.files.map(path => {
if (path === mainPath) return minifiedPath;
return path;
});
new karma.Server(
{
configFile: __dirname + '/karma.conf.js',
action: 'run',
browsers,
files
},
exitCode => {
done(exitCode);
}
).start();
});
gulp.task('test-sauce', done => {
// Setup browsers.
const browsers = [];
argv.chrome && browsers.push('slChrome');
argv.firefox && browsers.push('slFirefox');
argv.safari && browsers.push('slSafari');
argv.edge && browsers.push('slEdge');
if (!browsers.length) browsers.push('slChrome', 'slFirefox', 'slSafari');
new karma.Server(
{
configFile: __dirname + '/karma.conf.js',
action: 'run',
browsers
},
exitCode => {
done(exitCode);
}
).start();
});
gulp.task('test-sauce-min', done => {
// Setup browsers.
const browsers = [];
argv.chrome && browsers.push('slChrome');
argv.firefox && browsers.push('slFirefox');
argv.safari && browsers.push('slSafari');
argv.edge && browsers.push('slEdge');
if (!browsers.length) browsers.push('slChrome', 'slFirefox', 'slSafari');
// Replace main file with minified version.
const mainPath = './' + pkg.main;
const minifiedPath = mainPath.replace('.js', '.min.js');
const files = karmaDefaults.files.map(path => {
if (path === mainPath) return minifiedPath;
return path;
});
new karma.Server(
{
configFile: __dirname + '/karma.conf.js',
action: 'run',
browsers,
files
},
exitCode => {
done(exitCode);
}
).start();
});
gulp.task('format-test', cb => {
exec('npm run format-test', (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('bundle', cb => {
exec('npm run bundle', (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('fix-umd', () => {
const mainPath = './' + pkg.main;
return gulp
.src(mainPath, { base: './' })
.pipe(replace(/\(function([\s\S]*?)Hammer;/, patchedUMD))
.pipe(gulp.dest('./'));
});
gulp.task('minify', cb => {
exec('npm run minify', (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task(
'build',
gulp.series('bundle', 'fix-umd', 'minify', done => {
done();
})
);
gulp.task(
'pre-commit',
gulp.series('lint', 'format-test', done => {
done();
})
);
gulp.task(
'test',
gulp.series('lint', 'format-test', 'test-sauce', 'test-sauce-min', 'clean', done => {
done();
})
);