-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgulpfile.js
More file actions
132 lines (103 loc) · 3.42 KB
/
gulpfile.js
File metadata and controls
132 lines (103 loc) · 3.42 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
"use strict";
const
del = require("del"),
fs = require("fs"),
gulp = require("gulp"),
issueHandler = require("./lib/index.js"),
loadPlugins = require("gulp-load-plugins"),
path = require("path"),
runSequence = require("run-sequence");
const // jscs: ignore requireMultipleVarDecl
$ = loadPlugins(),
paths = {
lint: [
"gulpfile.js",
"lib/*.js",
"test/**/*.js",
"!coverage/**/*.js"
],
test: ["test/*.js"],
fixtures: "test/fixtures",
cleanFixtures: "test/fixtures/**/*.{json,txt}",
generateFixtures: ["test/fixtures/*.js", "!test/fixtures/_*.js"],
coverage: ["lib/**/*.js"]
};
// Cleaning
gulp.task("clean-fixtures", () => del(paths.cleanFixtures));
// Linting
gulp.task("lint:eslint", () =>
gulp.src(paths.lint)
.pipe($.eslint({ rulePaths: ["node_modules/eslint-config-cappuccino/lib/rules"] }))
.pipe($.eslint.format("node_modules/eslint-clang-formatter"))
.pipe($.eslint.failAfterError())
);
gulp.task("lint:jscs", () =>
gulp.src(paths.lint)
.pipe($.jscs())
.pipe($.jscs.reporter("node_modules/jscs-clang-reporter"))
.pipe($.jscs.reporter("fail"))
);
gulp.task("lint", cb => runSequence("lint:eslint", "lint:jscs", cb));
// Fixtures
gulp.task("generate-fixtures", () =>
{
function generateFixture(file, encoding, cb)
{
const code = require(file.path);
console.log(file.relative);
const
issues = new issueHandler.IssueList(),
name = path.basename(file.path);
let options;
switch (name)
{
case "no-color.js":
options = false;
break;
case "options.js":
options = JSON.parse(fs.readFileSync("test/fixtures/.clangformatterrc"));
break;
default:
break;
}
code.run(issues);
file.contents = new Buffer(issues.render(options));
// In case the code changed the color map
issueHandler.resetColorMap();
if (name === "clangformatterrc.js")
fs.unlinkSync("./.clangformatterrc");
cb(null, file);
}
const through = require("through2").obj;
gulp.src(paths.generateFixtures)
.pipe($.changed(paths.fixtures, { extension: ".txt" }))
.pipe(through(generateFixture))
.pipe($.rename({ extname: ".txt" }))
.pipe(gulp.dest(paths.fixtures));
});
gulp.task("regenerate-fixtures", cb => runSequence("clean-fixtures", "generate-fixtures", cb));
// Tests
function mochaTask(reporter)
{
return function()
{
return gulp.src(paths.test)
.pipe($.mocha({ reporter: reporter || "spec" }));
};
}
gulp.task("$coverage-setup", () =>
gulp.src(paths.coverage)
.pipe($.istanbul())
.pipe($.istanbul.hookRequire())
);
gulp.task("$coverage-mocha", ["$coverage-setup"], mochaTask("dot"));
gulp.task("$coverage-report", ["$coverage-mocha"], () =>
gulp.src(paths.test)
.pipe($.istanbul.writeReports({ reporters: ["text", "html"] }))
.pipe($.istanbul.enforceThresholds({ thresholds: { global: 100 }}))
);
gulp.task("mocha", mochaTask("spec"));
gulp.task("mocha-dot", mochaTask("dot"));
gulp.task("coverage", ["$coverage-report"], cb => cb());
gulp.task("test", cb => runSequence("lint", "coverage", cb));
gulp.task("default", ["test"]);