-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathgulpfile.js
149 lines (126 loc) · 4.5 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
var gulp = require("gulp");
var gulpif = require("gulp-if");
var gutil = require("gulp-util");
var pkg = require("./package.json");
var compile = require("./task/compile");
var babel = require("gulp-babel");
var template = require("gulp-template");
var jshint = require("gulp-jshint");
var argv = require("yargs").argv;
var jsdoc = require("gulp-jsdoc3");
var clean = require("gulp-clean");
var uglify = require("gulp-uglify");
var rename = require("gulp-rename");
var deploy = require("gulp-gh-pages");
var replace = require("gulp-replace");
var concat = require("gulp-concat");
var plumber = require("gulp-plumber");
var header = require("gulp-header");
var bump = require("gulp-bump");
var karma = require("karma");
var karmaConfig = require.resolve("./conf/karma.conf");
var banner = [
"/**",
" * <%= name %>: <%= description %>",
" * @version <%= version %> <%= new Date().toUTCString() %>",
" * @link <%= homepage %>",
" * @copyright <%= new Date().getFullYear() %> <%= author %>",
" * @license <%= license %>",
" */"
].join("\n");
if (process.env.npm_package_version) {
pkg.version = process.env.npm_package_version;
}
gulp.task("lint-test", function() {
return gulp.src(["test/spec/**/*.js"])
.pipe(jshint(require("./conf/jshintrc-test")))
.pipe(jshint.reporter("jshint-stylish"))
.pipe(gulpif(process.env.TRAVIS_JOB_NUMBER, jshint.reporter("fail")));
});
gulp.task("compile", function() {
return gulp.src(["**/*.js"], {cwd: "./src"})
.pipe(gulpif(!process.env.TRAVIS_JOB_NUMBER, plumber()))
.pipe(jshint(".jshintrc"))
.pipe(jshint.reporter("jshint-stylish"))
.pipe(jshint.reporter("fail"))
.pipe(compile("better-dom.js", pkg))
.pipe(babel())
.pipe(header(banner + "\n", pkg))
.pipe(gulp.dest("build/"));
});
gulp.task("test", ["compile", "lint-test"], function(done) {
var config = {preprocessors: []};
if (process.env.TRAVIS_JOB_NUMBER) {
config = {
reporters: ["coverage", "dots", "coveralls"],
coverageReporter: {
type: "lcovonly",
dir: "coverage/"
}
};
}
config.configFile = karmaConfig;
new karma.Server(config, function(resultCode) {
done(resultCode ? new gutil.PluginError("karma", "Tests failed") : null);
}).start();
});
gulp.task("browsers", ["compile", "lint-test"], function(done) {
var config = {preprocessors: []};
if (argv.ie10 || argv.ie11) {
config.browsers = ["IE" + (argv.ie10 ? "10" : "11") + " - Win7"];
} else {
config.browsers = ["Chrome", "Safari", "Firefox"];
}
config.configFile = karmaConfig;
new karma.Server(config, function(resultCode) {
done(resultCode ? new gutil.PluginError("karma", "Tests failed") : null);
}).start();
});
gulp.task("dev", ["compile", "lint-test"], function() {
gulp.watch(["src/**/*.js"], ["compile"]);
gulp.watch(["test/spec/**/*.js"], ["lint-test"]);
new karma.Server({
configFile: karmaConfig,
reporters: ["coverage", "progress"],
background: true,
singleRun: false
}).start();
});
gulp.task("sauce", function(done) {
new karma.Server({
configFile: require.resolve("./conf/karma.conf-ci.js")
}, function() {
// always return success result for this task
done(null);
}).start();
});
gulp.task("clean-jsdoc", function() {
return gulp.src("docs", {read: false}).pipe(clean());
});
gulp.task("build-jsdoc", ["clean-jsdoc"], function(done) {
const config = require("./conf/jsdoc.json");
gulp.src(["./src/**/*.js"], {read: false})
.pipe(jsdoc(config, done));
});
gulp.task("gh-pages", ["build-jsdoc"], function() {
// var lib = require.resolve("./build/better-dom");
return gulp.src("./docs/**/*")
// remove absolute paths from jsdocs
// .pipe(replace(lib, "better-dom.js"))
.pipe(deploy({message: "v" + pkg.version}));
});
gulp.task("bower", function() {
return gulp.src("./bower.json")
.pipe(bump({version: pkg.version}))
.pipe(gulp.dest("./"));
});
gulp.task("dist", ["browsers", "bower"], function() {
return gulp.src("build/better-dom.js")
// clienup multiline comments: jsdocs, directives etc.
.pipe(replace(/\/\*([\s\S]*?)\*\/\s+/gm, ""))
.pipe(header(banner + "\n", pkg))
.pipe(gulp.dest("dist/"))
.pipe(uglify({preserveComments: "license"}))
.pipe(rename({extname: ".min.js"}))
.pipe(gulp.dest("dist/"));
});