UNPKG

1.05 kBJavaScriptView Raw
1'use strict';
2
3var path = require('path');
4var pluginError = require('plugin-error');
5var log = require('plugin-log');
6var through = require('through2');
7var bump = require('bump-regex');
8var semver = require('semver');
9
10var PLUGIN_NAME = 'gulp-bump';
11
12module.exports = function(opts) {
13
14 opts = opts || {};
15 if (!opts.type || !semver.inc('0.0.1', opts.type)) {
16 opts.type = 'patch';
17 }
18
19 return through.obj(function(file, enc, cb) {
20
21 if (file.isNull()) {
22 return cb(null, file);
23 }
24 if (file.isStream()) {
25 return cb(new pluginError(PLUGIN_NAME, 'Streaming not supported'));
26 }
27
28 opts.str = String(file.contents);
29 bump(opts, function(err, res) {
30 if (err) {
31 return cb(new pluginError(PLUGIN_NAME, err));
32 }
33 file.contents = new Buffer(res.str);
34
35 if (!opts.quiet) {
36 log('Bumped', log.colors.cyan(res.prev),
37 'to', log.colors.magenta(res.new),
38 'with type:', log.colors.cyan(res.type));
39 }
40 file.bumpData = res;
41 cb(null, file);
42 });
43 });
44};