-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
89 lines (71 loc) · 1.88 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
const exec = require('child_process').exec;
const fs = require('fs');
const git = require('gulp-git'),
gitStatus = require('git-get-status'),
gulp = require('gulp'),
jshint = require('gulp-jshint'),
prompt = require('gulp-prompt');
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-choice', (cb) => {
const processor = prompt.prompt({
type: 'list',
name: 'bump',
message: 'What type of bump would you like to do?',
choices: ['patch', 'minor', 'major'],
}, (res) => {
global.bump = res.bump;
return cb();
});
return gulp.src(['./package.json']).pipe(processor);
});
gulp.task('bump-version', (cb) => {
exec(`npm version ${global.bump || 'patch'} --no-git-tag-version`, {
cwd: './'
}, (error) => {
if (error) {
cb(error);
}
cb();
});
});
gulp.task('commit-changes', () => {
return gulp.src(['./', './package.json' ])
.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, function (error) {
if (error) {
return cb(error);
}
git.push('origin', 'master', {args: '--tags'}, cb);
});
});
gulp.task('release', gulp.series(
'ensure-clean-working-directory',
'bump-choice',
'bump-version',
'commit-changes',
'push-changes',
'create-tag'
));
gulp.task('lint', () => {
return gulp.src(['./lib/**/*.js', './scripts/**/*.js', './test/specs/**/*.js'])
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
gulp.task('default', gulp.series('lint'));