-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
100 lines (81 loc) · 2.35 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
const gulp = require('gulp');
const browserify = require('browserify'),
buffer = require('vinyl-buffer'),
bump = require('gulp-bump'),
git = require('gulp-git'),
gitStatus = require('git-get-status'),
glob = require('glob'),
jasmine = require('gulp-jasmine'),
jshint = require('gulp-jshint'),
source = require('vinyl-source-stream');
const fs = require('fs');
function getVersionFromPackage() {
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
}
gulp.task('ensure-clean-working-directory', (cb) => {
gitStatus((err, status) => {
if (err, !status.clean) {
throw new Error('Unable to proceed, your working directory is not clean.');
}
cb();
});
});
gulp.task('bump-version', () => {
return gulp.src(['./package.json'])
.pipe(bump({type: 'patch'}))
.pipe(gulp.dest('./'));
});
gulp.task('commit-changes', () => {
return gulp.src([ './', './package.json', './index.js', './test/SpecRunner.js' ])
.pipe(git.add())
.pipe(git.commit('Release. Bump version number'));
});
gulp.task('push-changes', (cb) => {
git.push('origin', 'master', cb);
});
gulp.task('create-tag', (cb) => {
const version = getVersionFromPackage();
git.tag(version, 'Release ' + version, (error) => {
if (error) {
return cb(error);
}
git.push('origin', 'master', { args: '--tags' }, cb);
});
});
gulp.task('build-browser-tests', () => {
return browserify({ entries: glob.sync('test/specs/**/*.js') })
.bundle()
.pipe(source('SpecRunner.js'))
.pipe(buffer())
.pipe(gulp.dest('./test/'));
});
gulp.task('execute-browser-tests', () => {
return gulp.src('test/SpecRunner.js')
.pipe(jasmine());
});
gulp.task('execute-node-tests', () => {
return gulp.src(['index.js', 'test/specs/**/*.js'])
.pipe(jasmine());
});
gulp.task('execute-tests', gulp.series(
'build-browser-tests',
'execute-browser-tests',
'execute-node-tests'
));
gulp.task('release', gulp.series(
'ensure-clean-working-directory',
'build-browser-tests',
'execute-browser-tests',
'execute-node-tests',
'bump-version',
'commit-changes',
'push-changes',
'create-tag'
));
gulp.task('lint', () => {
return gulp.src([ './**/*.js', './test/specs/**/*.js', '!./node_modules/**', '!./dist/**', '!./test/SpecRunner.js' ])
.pipe(jshint({'esversion': 6}))
.pipe(jshint.reporter('default'));
});
gulp.task('test', gulp.series('execute-tests'));
gulp.task('default', gulp.series('lint'));