1 | 'use strict';
|
2 |
|
3 | var path = require('path');
|
4 | var pluginError = require('plugin-error');
|
5 | var log = require('plugin-log');
|
6 | var through = require('through2');
|
7 | var bump = require('bump-regex');
|
8 | var semver = require('semver');
|
9 |
|
10 | var PLUGIN_NAME = 'gulp-bump';
|
11 |
|
12 | module.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 | };
|