This repository has been archived by the owner on Nov 21, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
60 lines (52 loc) · 1.58 KB
/
index.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
'use strict';
var addStream = require('add-stream');
var assign = require('object-assign');
var concat = require('concat-stream');
var conventionalChangelog = require('conventional-changelog');
var gutil = require('gulp-util');
var through = require('through2');
module.exports = function(opts, context, gitRawCommitsOpts, parserOpts, writerOpts) {
opts = assign({
// TODO: remove this when gulp get's a real logger with levels
verbose: process.argv.indexOf('--verbose') !== -1
}, opts);
if (opts.verbose) {
opts.debug = gutil.log;
}
return through.obj(function(file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
var stream = conventionalChangelog(opts, context, gitRawCommitsOpts, parserOpts, writerOpts)
.on('error', function(err) {
cb(new gutil.PluginError('gulp-conventional-changelog', err));
});
if (file.isStream()) {
if (opts.releaseCount === 0) {
file.contents = stream;
} else if (opts.append) {
file.contents = file.contents
.pipe(addStream(stream));
} else {
file.contents = stream
.pipe(addStream(file.contents));
}
cb(null, file);
return;
}
stream
.pipe(concat({
encoding: 'buffer'
}, function(data) {
if (opts.releaseCount === 0) {
file.contents = data;
} else if (opts.append) {
file.contents = Buffer.concat([file.contents, data]);
} else {
file.contents = Buffer.concat([data, file.contents]);
}
cb(null, file);
}));
});
};