-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.babel.js
118 lines (98 loc) · 2.79 KB
/
gulpfile.babel.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
import fs from 'fs';
import minimist from 'minimist';
import gulp from 'gulp';
import babel from 'gulp-babel';
import bump from 'gulp-bump';
import changelog from 'gulp-conventional-changelog';
import connect from 'gulp-connect';
import eslint from 'gulp-eslint';
import git from 'gulp-git';
import test from 'gulp-mocha';
import notify from 'gulp-notify';
import open from 'gulp-open';
import rename from 'gulp-rename';
import uglify from 'gulp-uglify';
import gutil from 'gulp-util';
const argv = minimist(process.argv.slice(2));
gulp.task('bump-version', () => {
let type;
if (argv.major) type = 'major';
else if (argv.minor) type = 'minor';
else type = 'patch';
return gulp.src(['./package.json'])
.pipe(bump({type}).on('error', gutil.log))
.pipe(gulp.dest('./'));
});
gulp.task('changelog', () =>
gulp.src('CHANGELOG.md')
.pipe(changelog({preset: 'angular'}))
.pipe(gulp.dest('./'))
);
gulp.task('commit-changes', () =>
gulp.src('.')
.pipe(git.add())
.pipe(git.commit('[Prerelease] Bumped version number'))
);
gulp.task('create-new-tag', (cb) => {
var version = getPackageJsonVersion();
git.tag(`v${version}`, 'Created Tag for version: ' + version, (error) => {
if (error) return cb(error);
cb();
// git.push('origin', 'master', {args: '--tags'}, cb);
});
});
gulp.task('lint', () =>
gulp.src(['./index.js', './test/index.spec.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
);
gulp.task('test', () => {
if (argv['skip-tests']) return gutil.log('Tests skipped via --skip-tests argument');
return gulp.src('./test/*')
.pipe(test({
require: '@babel/register',
reporter: 'spec',
}));
});
gulp.task('full-checkup', gulp.series('lint', 'test'));
gulp.task('bundle', () =>
gulp.src('index.js')
.pipe(rename('knockout-undoredo.js'))
.pipe(babel())
.pipe(gulp.dest('dist'))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist'))
);
gulp.task('build', gulp.series('full-checkup', 'bundle'));
gulp.task('serve-demo', () => {
connect.server({
port: 8888,
root: '.'
});
gulp.src(__filename)
.pipe(open({
uri: 'http://localhost:8888/demo/'
}));
});
gulp.task('do-release', gulp.series(
'build',
'bump-version',
'changelog',
'commit-changes',
'create-new-tag',
)
);
function getPackageJsonVersion() {
// We parse the json file instead of using require because require caches
// multiple calls so the version number won't be updated
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
}
function handleErrors(...args) {
notify.onError({
title: 'Compile Error',
message: '<%= error.message %>'
}).apply(this, args);
this.emit('end'); // Keep gulp from hanging on this task
}