forked from node-gh/gh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
153 lines (133 loc) · 3.46 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
150
151
152
153
'use strict';
var paths,
fs = require('fs'),
gulp = require('gulp'),
jshint = require('gulp-jshint'),
jscs = require('gulp-jscs'),
mocha = require('gulp-mocha'),
istanbul = require('gulp-istanbul'),
complexity = require('gulp-complexity'),
runSequence = require('run-sequence'),
open = require('open'),
help = require('./tasks/help'),
exec = require('./lib/exec');
paths = {
lint: [
'lib/**/*.js', 'test/**/*.js', 'bin/**/*.js', 'tasks/**/*.js', '*.js'
],
complexity: ['lib/**/*.js', 'test/**/*.js', 'tasks/**/*.js', '*.js'],
plato: 'lib',
cover: ['lib/**/*.js'],
unit: ['test/**/*.js', '!test/fixture/*.js'],
watch: ['lib/**/*.js'],
'coverage-report-directory': 'reports/coverage',
'coverage-report': 'reports/coverage/lcov-report/index.html',
'plato-report-directory': 'reports/complexity',
'plato-report': 'reports/complexity/index.html'
};
function lintTask() {
return gulp.src(paths.lint)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'))
.pipe(jscs());
}
function platoTask() {
exec.spawnSyncStream('node_modules/plato/bin/plato', [
'--dir',
paths['plato-report-directory'],
'--recurse',
'--title',
'Node GH',
'--jshint',
'test/.jshintrc',
'lib',
'test',
'bin',
'tasks',
'gulpfile.js'
]);
}
function complexityTask() {
return gulp.src(paths.complexity)
.pipe(complexity({
halstead: 29,
cyclomatic: 17
}));
}
function coverTask() {
return gulp.src(paths.cover)
.pipe(istanbul({includeUntested: true}))
.pipe(istanbul.hookRequire());
}
function mochaTest() {
return gulp.src(paths.unit)
.pipe(mocha());
}
function unitTask() {
return mochaTest()
.pipe(istanbul.writeReports({
reporters: ['lcov', 'json'],
dir: paths['coverage-report-directory']
}));
}
function unitCiTask() {
return mochaTest()
.pipe(istanbul.writeReports({
dir: paths['coverage-report-directory']
}));
}
function testTask(done) {
return runSequence(
'lint',
'plato',
'complexity',
'unit',
done
);
}
function ciTask(done) {
return runSequence(
'lint',
'plato',
'complexity',
'unit-ci',
done
);
}
function coverageReportTask() {
var file = paths['coverage-report'];
if (!fs.existsSync(file)) {
console.error('Run gulp test first.');
return;
}
open(file);
}
function platoReportTask() {
var file = paths['plato-report'];
if (!fs.existsSync(file)) {
console.error('Run gulp test first.');
return;
}
open(file);
}
function watchTask() {
return gulp.watch(paths.watch, ['test']);
}
function ciReportsTask() {
open('https://node-gh.github.io/reports/');
}
gulp.task('default', help);
gulp.task('help', help);
gulp.task('lint', lintTask);
gulp.task('plato', platoTask);
gulp.task('complexity', complexityTask);
gulp.task('test-cover', coverTask);
gulp.task('unit', ['test-cover'], unitTask);
gulp.task('unit-ci', ['test-cover'], unitCiTask);
gulp.task('test', testTask);
gulp.task('ci', ciTask);
gulp.task('coverage-report', coverageReportTask);
gulp.task('plato-report', platoReportTask);
gulp.task('watch', watchTask);
gulp.task('ci-reports', ciReportsTask);