-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
121 lines (100 loc) · 2.64 KB
/
gulpfile.js
File metadata and controls
121 lines (100 loc) · 2.64 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
"use strict";
var Bluebird = require("bluebird");
var Enforcer = require("gulp-istanbul-enforcer");
var FS = require("fs");
var Gulp = require("gulp");
var Istanbul = require("gulp-istanbul");
var JSCS = require("gulp-jscs");
var JSHint = require("gulp-jshint");
var Mocha = require("gulp-mocha");
var Path = require("path");
var Stylish = require("jshint-stylish");
var consume = require("stream-consume");
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")
]
};
var readFile = Bluebird.promisify(FS.readFile, FS);
function lint (options, files) {
return Gulp.src(files)
.pipe(new JSHint(options))
.pipe(JSHint.reporter(Stylish))
.pipe(JSHint.reporter("fail"));
}
function loadOptions (path) {
return readFile(path, { encoding : "utf8" })
.then(function (contents) {
return JSON.parse(contents);
});
}
function promisefy (stream) {
return new Bluebird(function (resolve, reject) {
stream.once("finish", resolve);
stream.once("error", reject);
consume(stream);
});
}
function style (options, files) {
return Gulp.src(files).pipe(JSCS(options));
}
Gulp.task("coverage", [ "test" ], function () {
var options = {
thresholds : {
statements : 100,
branches : 100,
lines : 100,
functions : 100
},
coverageDirectory : "coverage",
rootDirectory : ""
};
return Gulp.src(".").pipe(new Enforcer(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 Bluebird.join(
loadOptions(paths.jshint.source),
loadOptions(paths.jshint.test),
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 (done) {
var stream = Gulp.src(paths.source)
.pipe(new Istanbul())
.on("finish", function () {
var stream = Gulp.src(paths.test)
.pipe(new Mocha())
.pipe(Istanbul.writeReports())
.on("end", done)
.on("error", done);
consume(stream);
});
consume(stream);
});