-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
52 lines (44 loc) · 1.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
'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');
const extra = require('./composer.json').extra;
/**
* Creates bump task.
*
* @param {string} type a semver type.
*
* @return {Function} A bump task.
*/
function bumpTaskFactory(type) {
return () => {
const packages = [];
const plugin = (pkg.main) ? [path.normalize(pkg.main)] : [];
const loader = (extra && extra['installer-loader']) ? [path.normalize(extra['installer-loader'])] : [];
const plugins = plugin.concat(loader);
const target = packages.concat(plugins);
const packageFilter = filter(packages, {restore: true});
const pluginFilter = filter(plugins, {restore: true});
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');
const pluginRegExp = new RegExp('^([ \\t\\/*#@]*Version:)\\s*' + versionPattern + '\\s*$', 'mg');
gulp.src(target, {base: './'})
.pipe(packageFilter)
.pipe(replace(packageRegExp, '$1 "' + newVersion + '"$2'))
.pipe(packageFilter.restore)
.pipe(pluginFilter)
.pipe(replace(pluginRegExp, '$1 ' + newVersion))
.pipe(pluginFilter.restore)
.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'));