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
100 lines (83 loc) · 2.51 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
var parser = require('./lib/parser');
var regex = require('./lib/regex');
var through = require('through2');
var _ = require('lodash');
function assignOpts(options) {
options = _.extend({
headerPattern: /^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
headerCorrespondence: ['type', 'scope', 'subject'],
referenceActions: [
'close',
'closes',
'closed',
'fix',
'fixes',
'fixed',
'resolve',
'resolves',
'resolved'
],
issuePrefixes: ['#'],
noteKeywords: ['BREAKING CHANGE'],
fieldPattern: /^-(.*?)-$/,
revertPattern: /^Revert\s"([\s\S]*)"\s*This reverts commit (\w*)\./,
revertCorrespondence: ['header', 'hash'],
warn: function() {},
mergePattern: null,
mergeCorrespondence: null
}, options);
if (typeof options.headerPattern === 'string') {
options.headerPattern = new RegExp(options.headerPattern);
}
if (typeof options.headerCorrespondence === 'string') {
options.headerCorrespondence = options.headerCorrespondence.split(',');
}
if (typeof options.referenceActions === 'string') {
options.referenceActions = options.referenceActions.split(',');
}
if (typeof options.issuePrefixes === 'string') {
options.issuePrefixes = options.issuePrefixes.split(',');
}
if (typeof options.noteKeywords === 'string') {
options.noteKeywords = options.noteKeywords.split(',');
}
if (typeof options.fieldPattern === 'string') {
options.fieldPattern = new RegExp(options.fieldPattern);
}
if (typeof options.revertPattern === 'string') {
options.revertPattern = new RegExp(options.revertPattern);
}
if (typeof options.revertCorrespondence === 'string') {
options.revertCorrespondence = options.revertCorrespondence.split(',');
}
if (typeof options.mergePattern === 'string') {
options.mergePattern = new RegExp(options.mergePattern);
}
return options;
}
function conventionalCommitsParser(options) {
options = assignOpts(options);
var reg = regex(options);
return through.obj(function(data, enc, cb) {
var commit;
try {
commit = parser(data.toString(), options, reg);
cb(null, commit);
} catch (err) {
if (options.warn === true) {
cb(err);
} else {
options.warn(err.toString());
cb(null, '');
}
}
});
}
function sync(commit, options) {
options = assignOpts(options);
var reg = regex(options);
return parser(commit, options, reg);
}
module.exports = conventionalCommitsParser;
module.exports.sync = sync;