forked from bumbu/svg-pan-zoom
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
100 lines (92 loc) · 2.1 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
/**
* Modules
*/
var gulp = require("gulp"),
uglify = require("gulp-uglify"),
browserify = require("browserify"),
source = require("vinyl-source-stream"),
rename = require("gulp-rename"),
qunit = require("gulp-qunit"),
eslint = require("gulp-eslint"),
gulpIf = require("gulp-if"),
header = require("gulp-header"),
buffer = require("vinyl-buffer"),
pkg = require("./package.json"),
banner =
"// svg-pan-zoom v<%= pkg.version %>" +
"\n" +
"// https://github.com/ariutta/svg-pan-zoom" +
"\n";
function isFixed(file) {
// TODO: why is file.eslint undefined?
return typeof file.eslint === "object" && file.eslint.fixed;
}
/**
* Build script
*/
function compile() {
return browserify({ entries: "./src/stand-alone.js" })
.bundle()
.on("error", function(err) {
console.log(err.toString());
this.emit("end");
})
.pipe(source("svg-pan-zoom.js"))
.pipe(buffer())
.pipe(header(banner, { pkg: pkg }))
.pipe(gulp.dest("./dist/"))
.pipe(rename("svg-pan-zoom.min.js"))
.pipe(uglify())
.pipe(header(banner, { pkg: pkg }))
.pipe(gulp.dest("./dist/"));
}
/**
* Watch script
*/
function watch() {
return gulp.watch("./src/**/*.js", gulp.series("compile"));
}
/**
* Test task
*/
function test() {
return gulp.src("./tests/index.html").pipe(qunit());
}
/**
* Check
*/
function check() {
return (
gulp
.src([
"./**/*.js",
"!./dist/**/*.js",
"!./demo/**/*.js",
"!./tests/assets/**/*.js",
"!./src/uniwheel.js" // Ignore uniwheel
])
// NOTE: this runs prettier via eslint-plugin-prettier
.pipe(
eslint({
configFile: "./.eslintrc.json",
fix: true
})
)
.pipe(eslint.format())
.pipe(gulpIf(isFixed, gulp.dest("./")))
// uncomment to stop on error
.pipe(eslint.failAfterError())
);
}
exports.compile = compile;
exports.watch = watch;
exports.test = test;
exports.check = check;
/**
* Build
*/
exports.build = gulp.series([check, compile, test]);
/**
* Default task
*/
exports.default = gulp.series([compile, watch]);