-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathgulpfile.js
108 lines (100 loc) · 3.21 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
var pkg = require("./package.json"),
gulp = require("gulp"),
rollup = require("gulp-rollup"),
rename = require("gulp-rename"),
banner = require("gulp-banner"),
ending = require("gulp-line-ending-corrector"),
uglify = require("gulp-uglify"),
replace = require("gulp-replace"),
less = require("gulp-less"),
gulpif = require("gulp-if"),
karma = require("karma").Server,
cleanCss = require("gulp-clean-css"),
SRC_DIR = "./src/",
LESS_SRC_DIR = "./less/",
DIST_DIR = "./dist/",
TEST_DIR = "/test/",
devMode = false,
comment = [
"/**",
" <%= pkg.description %>, version <%= pkg.version %>",
"",
" <%= pkg.description %> is freely distributable under the terms of MIT-style license",
" Built on DevBridge Autocomplete for jQuery (https://github.com/devbridge/jQuery-Autocomplete)",
" For details, see <%= pkg.homepage %>",
"/\n"
].join("\n *");
function buildScript() {
return gulp
.src(SRC_DIR + "**/*.js")
.pipe(gulpif(!devMode, ending({ eolc: "LF" })))
.pipe(gulpif(!devMode, gulp.dest(SRC_DIR)))
.pipe(
rollup({
input: SRC_DIR + "main.js",
output: {
format: "umd",
globals: {
jquery: "jQuery"
}
},
external: ["jquery"]
})
)
.pipe(rename("jquery.suggestions.js"))
.pipe(banner(comment, { pkg: pkg }))
.pipe(replace("%VERSION%", pkg.version))
.pipe(ending({ eolc: "LF" }))
.pipe(gulp.dest(DIST_DIR + "js"))
.pipe(uglify({ mangle: true }))
.pipe(rename("jquery.suggestions.min.js"))
.pipe(gulp.dest(DIST_DIR + "js"));
}
function buildStyle() {
return gulp
.src(LESS_SRC_DIR + "**/*")
.pipe(gulpif(!devMode, ending({ eolc: "LF" })))
.pipe(gulpif(!devMode, gulp.dest(LESS_SRC_DIR)))
.pipe(less({ javascriptEnabled: true }))
.pipe(gulp.dest(DIST_DIR + "css"))
.pipe(cleanCss({ compatibility: "ie8" }))
.pipe(rename("suggestions.min.css"))
.pipe(gulp.dest(DIST_DIR + "css"));
}
function testPrepare() {
return gulp
.src(TEST_DIR + "specs/*.js")
.pipe(ending())
.pipe(gulp.dest("test/specs"));
}
function testFull(callback) {
new karma(
{
configFile: __dirname + TEST_DIR + "karma.full.js",
singleRun: true
},
callback
).start();
}
function testMinified(callback) {
new karma(
{
configFile: __dirname + TEST_DIR + "karma.minified.js",
singleRun: true
},
callback
).start();
}
function setDevMode(callback) {
devMode = true;
callback();
}
gulp.task("watch", function() {
gulp.watch([SRC_DIR + "**/*"], buildScript);
gulp.watch([LESS_SRC_DIR + "**/*"], buildStyle);
});
exports.build = gulp.series(buildScript, buildStyle);
exports.test = gulp.series(testPrepare, testFull);
exports.testall = gulp.series(exports.test, testMinified);
exports.dev = gulp.series(setDevMode, exports.build, "watch");
exports.default = gulp.series(exports.build, exports.testall);