-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
113 lines (98 loc) · 2.91 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
/* Dev-Dependencies */
var
gulp = require('gulp'),
sourcemaps = require('gulp-sourcemaps'),
babel = require('gulp-babel'),
mocha = require('gulp-spawn-mocha'),
jshint = require('gulp-jshint'),
beautify = require('gulp-jsbeautify'),
shell = require('gulp-shell'),
ghPages = require('gulp-gh-pages'),
rimraf = require('rimraf'),
config = require('./config'),
semver = require('semver'),
version = require('node-version').long,
isHarmony = !semver.lt(version.toString(), '0.11.0'),
changelog = require('gulp-changelog');
/** Backs up the files in case of emergency! */
gulp.task('backup', function () {
return gulp
.src('src/**/**/**.js')
.pipe(gulp.dest('./.backup'));
});
gulp.task('recover', function () {
return gulp
.src('./.backup/**/**/*.js')
.pipe(gulp.dest('src/'));
});
/* Formats the files */
gulp.task('beautify', ['backup'], function () {
return gulp.src('./src/**/**/*.js')
.pipe(beautify(config.beautify))
.pipe(gulp.dest('./src'));
});
/*
* Clean the docs themes folder
*/
gulp.task('clean-docs', ['gh-pages'], function (cb) {
rimraf('./docs/', cb);
});
/*
* Create the gh-pages branch - wont push automatically
*/
gulp.task('gh-pages', ['doc'], function () {
return gulp.src('./docs/**/*')
.pipe(ghPages());
});
/* Checks the coding style and builds from ES6 to ES5*/
gulp.task('src', ['beautify'], function () {
return gulp.src('./src/**/**/*.js')
.pipe(jshint(config.jshint))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'))
.pipe(sourcemaps.init())
.pipe(babel({
"presets": ["es2015"],
"plugins":["transform-regenerator"]
}))
.pipe(sourcemaps.write('./source maps/'))
.pipe(gulp.dest('./'));
});
/* Watches for changes and applies the build task*/
gulp.task('watch', function () {
return gulp.watch('./src/**/**/*.js', ['build']);
});
/* Runs tests */
gulp.task('test', ['src'], function (cb) {
if (isHarmony)
return gulp.src('./tests/**/*.js')
.pipe(shell(['mocha --harmony <%= file.path %>']));
else return gulp.src([
'./tests/express/index.js',
'./tests/hapi/index.js'
]).pipe(mocha());
});
gulp.task('changelog', function (cb) {
changelog(require('./package.json')).then(function (stream) {
stream.pipe(gulp.dest('./')).on('end', cb);
});
});
/*
* Runs the doxx command and builds the docs
* Install other themes here, generate docs for each.
*/
gulp.task('doc', ['build'], shell.task([
(function(){
var doc = 'node_modules/mr-doc/bin/mr-doc',
cmd = {
source: ' -s src/',
output: ' -o docs/',
name:' -n "gengo.js/accept"',
theme:' -t cayman'
};
return doc + cmd.source + cmd.output + cmd.name + cmd.theme;
})()
]));
gulp.task('default', ['backup', 'beautify', 'src', 'watch']);
gulp.task('build', ['backup', 'beautify', 'src', 'test']);
gulp.task('docs', ['build', 'doc', 'gh-pages', 'clean-docs']);