-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
39 lines (31 loc) · 1.14 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
'use strict';
const path = require('path');
const gulp = require('gulp');
const filter = require('gulp-filter');
const replace = require('gulp-replace');
const semver = require('semver');
const pkg = require('./package.json');
/**
* Creates bump task.
*
* @param {string} type a semver type.
*
* @return {Function} A bump task.
*/
function bumpTaskFactory(type) {
return () => {
const packages = ['package.json'];
const version = pkg.version;
const newVersion = semver.inc(version, type);
const versionPattern = (version + '').replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
const packageRegExp = new RegExp('^(\\s*"version"\\s*:)\\s*"' + versionPattern + '"\\s*(,?)\\s*$', 'mg');
gulp.src(packages, {base: './'})
.pipe(replace(packageRegExp, '$1 "' + newVersion + '"$2'))
.pipe(gulp.dest('./'));
};
}
gulp.task('bump', ['bump:patch']);
gulp.task('bump:patch', bumpTaskFactory('patch'));
gulp.task('bump:minor', bumpTaskFactory('minor'));
gulp.task('bump:major', bumpTaskFactory('major'));
gulp.task('bump:prerelease', bumpTaskFactory('prerelease'));