This repository has been archived by the owner on Feb 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
78 lines (70 loc) · 2.59 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
var gitRawCommits = require('git-raw-commits');
var conventionalCommitsParser = require('conventional-commits-parser');
var conventionalChangelogWriter = require('conventional-changelog-writer');
var stream = require('stream');
var through = require('through2');
var mergeConfig = require('./lib/merge-config');
function conventionalChangelog(options, context, gitRawCommitsOpts, parserOpts, writerOpts) {
writerOpts = writerOpts || {};
var readable = new stream.Readable({
objectMode: writerOpts.includeDetails
});
readable._read = function() {};
mergeConfig(options, context, gitRawCommitsOpts, parserOpts, writerOpts)
.then(function(data) {
options = data.options;
context = data.context;
gitRawCommitsOpts = data.gitRawCommitsOpts;
parserOpts = data.parserOpts;
writerOpts = data.writerOpts;
gitRawCommits(gitRawCommitsOpts)
.on('error', function(err) {
err.message = 'Error in git-raw-commits: ' + err.message;
setImmediate(readable.emit.bind(readable), 'error', err);
})
.pipe(conventionalCommitsParser(parserOpts))
.on('error', function(err) {
err.message = 'Error in conventional-commits-parser: ' + err.message;
setImmediate(readable.emit.bind(readable), 'error', err);
})
// it would be better if `gitRawCommits` could spit out better formatted data
// so we don't need to transform here
.pipe(through.obj(function(chunk, enc, cb) {
try {
options.transform.call(this, chunk, cb);
} catch (err) {
cb(err);
}
}))
.on('error', function(err) {
err.message = 'Error in options.transform: ' + err.message;
setImmediate(readable.emit.bind(readable), 'error', err);
})
.pipe(conventionalChangelogWriter(context, writerOpts))
.on('error', function(err) {
err.message = 'Error in conventional-changelog-writer: ' + err.message;
setImmediate(readable.emit.bind(readable), 'error', err);
})
.pipe(through({
objectMode: writerOpts.includeDetails
}, function(chunk, enc, cb) {
try {
readable.push(chunk);
} catch (err) {
setImmediate(function() {
throw err;
});
}
cb();
}, function(cb) {
readable.push(null);
cb();
}));
})
.catch(function(err) {
setImmediate(readable.emit.bind(readable), 'error', err);
});
return readable;
}
module.exports = conventionalChangelog;