-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
102 lines (83 loc) · 2.27 KB
/
gulpfile.js
File metadata and controls
102 lines (83 loc) · 2.27 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
"use strict";
var fs = require("fs");
var gulp = require("gulp");
var jscs = require("gulp-jscs");
var jshint = require("gulp-jshint");
var lab = require("gulp-lab");
var path = require("path");
var Q = require("q");
var stylish = require("jshint-stylish");
var _ = require("lodash");
var paths = {
jscs : path.join(__dirname, ".jscsrc"),
jshint : {
source : path.join(__dirname, ".jshintrc"),
test : path.join(__dirname, "test", ".jshintrc")
},
source : [
path.join(__dirname, "*.js"),
path.join(__dirname, "lib", "**", "*.js")
],
test : [
path.join(__dirname, "test", "**", "*_spec.js")
]
};
function lint (options, files) {
return gulp.src(files)
.pipe(jshint(options))
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter("fail"));
}
function loadOptions (path) {
return Q.ninvoke(fs, "readFile", path, { encoding : "utf8" })
.then(function (contents) {
return JSON.parse(contents);
});
}
function promisefy (stream) {
var deferred = Q.defer();
stream.once("finish", deferred.resolve.bind(deferred));
stream.once("error", deferred.reject.bind(deferred));
return deferred.promise;
}
function style (options, files) {
return gulp.src(files).pipe(jscs(options));
}
gulp.task("coverage", function () {
var options = {
args : "-p -r html -o " + path.join(__dirname, "coverage.html"),
opts : { emitLabError : false }
};
return gulp.src(paths.test).pipe(lab(options));
});
gulp.task("default", [ "test" ]);
gulp.task("lint", [ "lint-source", "lint-test" ]);
gulp.task("lint-source", function () {
return loadOptions(paths.jshint.source)
.then(function (options) {
return promisefy(lint(options, paths.source));
});
});
gulp.task("lint-test", function () {
return Q.all([
loadOptions(paths.jshint.source),
loadOptions(paths.jshint.test)
])
.spread(function (source, test) {
var options = _.merge(source, test);
return promisefy(lint(options, paths.test));
});
});
gulp.task("style", function () {
return loadOptions(paths.jscs)
.then(function (options) {
return promisefy(style(options, paths.source.concat(paths.test)));
});
});
gulp.task("test", [ "lint", "style" ], function () {
var options = {
args : "-p -t 100",
opts : { emitLabError : true }
};
return gulp.src(paths.test).pipe(lab(options));
});