gulpfile.js
2.9 KB
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
var gulp = require("gulp");
var istanbul = require("gulp-istanbul");
var mocha = require("gulp-mocha");
var plumber = require("gulp-plumber");
var jshint = require("gulp-jshint");
var uglify = require("gulp-uglify");
var jscs = require("gulp-jscs");
var coveralls = require("gulp-coveralls");
var rename = require("gulp-rename");
var options = require("yargs").argv;
var pkg = require("./package");
/**
*/
var paths = {
testFiles : ["test/**/*-test.js"],
appFiles : ["sift.js"],
allFiles : ["test/**/*-test.js", "sift.js"]
};
/**
*/
var mochaOptions = {
bail : options.bail !== 'false',
reporter : options.reporter || 'dot',
grep : options.grep || options.only,
timeout : 500
}
/**
*/
gulp.task("test-coverage", function (complete) {
gulp.
src(paths.appFiles).
pipe(istanbul()).
pipe(istanbul.hookRequire()).
on("finish", function () {
gulp.
src(paths.testFiles).
pipe(plumber()).
pipe(mocha(mochaOptions)).
pipe(istanbul.writeReports({
reporters: ["text","text-summary", "lcov"]
})).
on("end", complete);
});
});
/**
*/
gulp.task("test-coveralls", ["test-coverage"], function () {
return gulp.
src("coverage/**/lcov.info").
pipe(coveralls());
});
/**
*/
gulp.task("minify", function() {
return gulp.
src("./" + pkg.name + ".js").
pipe(uglify()).
pipe(rename(function(path) {
path.basename += ".min";
})).
pipe(gulp.dest("./"));
});
/**
*/
gulp.task("lint", function() {
return gulp.run(["jshint", "jscs"]);
});
/**
*/
gulp.task("jscs", function() {
return gulp.
src(paths.allFiles).
pipe(jscs({
"preset": "google",
"requireParenthesesAroundIIFE": true,
"maximumLineLength": 200,
"validateLineBreaks": "LF",
"validateIndentation": 2,
"validateQuoteMarks": "\"",
"disallowKeywords": ["with"],
"disallowSpacesInsideObjectBrackets": null,
"disallowImplicitTypeConversion": ["string"],
"requireCurlyBraces": [],
"safeContextKeyword": "self"
}));
});
/**
*/
gulp.task("jshint", function() {
return gulp.
src(paths.allFiles).
pipe(jshint({
es3: true,
evil: true
})).
pipe(jshint.reporter('default'));
});
/**
*/
gulp.task("test", function (complete) {
gulp.
src(paths.testFiles, { read: false }).
pipe(plumber()).
pipe(mocha(mochaOptions)).
on("error", complete).
on("end", complete);
});
var iofwatch = process.argv.indexOf("watch");
/**
* runs previous tasks (1 or more)
*/
gulp.task("watch", function () {
gulp.watch(paths.allFiles, process.argv.slice(2, iofwatch));
});
/**
*/
gulp.task("default", function () {
return gulp.run("test-coverage");
});
/**
*/
gulp.doneCallback = function (err) {
// a bit hacky, but fixes issue with testing where process
// doesn't exist process. Also fixes case where timeout / interval are set (CC)
if (!~iofwatch) process.exit(err ? 1 : 0);
};