conventional-commits-parser 2.1.4 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,7 +3,49 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- <a name="2.1.4"></a>
6
+ <a name="3.0.0"></a>
7
+ # [3.0.0](https://github.com/conventional-changelog/conventional-changelog/compare/conventional-commits-parser@2.1.7...conventional-commits-parser@3.0.0) (2018-05-29)
8
+
9
+
10
+ ### Chores
11
+
12
+ * **package:** set Node requirement to oldest supported LTS ([#329](https://github.com/conventional-changelog/conventional-changelog/issues/329)) ([cae2fe0](https://github.com/conventional-changelog/conventional-changelog/commit/cae2fe0))
13
+
14
+
15
+ ### BREAKING CHANGES
16
+
17
+ * **package:** Set the package's minimum required Node version to be the oldest LTS
18
+ currently supported by the Node Release working group. At this time,
19
+ that is Node 6 (which is in its Maintenance LTS phase).
20
+
21
+
22
+
23
+
24
+ <a name="2.1.7"></a>
25
+ ## [2.1.7](https://github.com/conventional-changelog/conventional-changelog/compare/conventional-commits-parser@2.1.6...conventional-commits-parser@2.1.7) (2018-03-27)
26
+
27
+
28
+
29
+
30
+ **Note:** Version bump only for package conventional-commits-parser
31
+
32
+ <a name="2.1.6"></a>
33
+ ## [2.1.6](https://github.com/conventional-changelog/conventional-changelog/compare/conventional-commits-parser@2.1.5...conventional-commits-parser@2.1.6) (2018-03-22)
34
+
35
+
36
+
37
+
38
+ **Note:** Version bump only for package conventional-commits-parser
39
+
40
+ <a name="2.1.5"></a>
41
+ ## [2.1.5](https://github.com/conventional-changelog/conventional-changelog/compare/conventional-commits-parser@2.1.4...conventional-commits-parser@2.1.5) (2018-02-24)
42
+
43
+
44
+
45
+
46
+ **Note:** Version bump only for package conventional-commits-parser
47
+
48
+ <a name="2.1.4"></a>
7
49
  ## [2.1.4](https://github.com/conventional-changelog/conventional-changelog/compare/conventional-commits-parser@2.1.3...conventional-commits-parser@2.1.4) (2018-02-20)
8
50
 
9
51
 
@@ -11,7 +53,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
11
53
 
12
54
  **Note:** Version bump only for package conventional-commits-parser
13
55
 
14
- <a name="2.1.3"></a>
56
+ <a name="2.1.3"></a>
15
57
  ## [2.1.3](https://github.com/conventional-changelog/conventional-commits-parser/compare/conventional-commits-parser@2.1.2...conventional-commits-parser@2.1.3) (2018-02-13)
16
58
 
17
59
 
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ ### MIT License
2
+
3
+ Copyright © [conventional-changelog team](https://github.com/conventional-changelog)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/cli.js CHANGED
@@ -1,135 +1,147 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
- var conventionalCommitsParser = require('./');
4
- var forEach = require('lodash').forEach;
5
- var fs = require('fs');
6
- var isTextPath = require('is-text-path');
7
- var JSONStream = require('JSONStream');
8
- var meow = require('meow');
9
- var readline = require('readline');
10
- var split = require('split2');
11
- var through = require('through2');
2
+ 'use strict'
3
+ var conventionalCommitsParser = require('./')
4
+ var forEach = require('lodash').forEach
5
+ var fs = require('fs')
6
+ var isTextPath = require('is-text-path')
7
+ var JSONStream = require('JSONStream')
8
+ var meow = require('meow')
9
+ var readline = require('readline')
10
+ var split = require('split2')
11
+ var through = require('through2')
12
12
 
13
- var filePaths = [];
14
- var separator = '\n\n\n';
13
+ var filePaths = []
14
+ var separator = '\n\n\n'
15
15
 
16
- var cli = meow({
17
- help: [
18
- 'Practice writing commit messages or parse messages from files.',
19
- 'If used without specifying a text file path, you will enter an interactive shell.',
20
- 'Otherwise the commit messages in the files are parsed and printed',
21
- 'By default, commits will be split by three newlines (`\\n\\n\\n`) or you can specify a separator.',
22
- '',
23
- 'Usage',
24
- ' conventional-commits-parser [<commit-separator>]',
25
- ' conventional-commits-parser [<commit-separator>] <path> [<path> ...]',
26
- ' cat <path> | conventional-commits-parser [<commit-separator>]',
27
- '',
28
- 'Example',
29
- ' conventional-commits-parser',
30
- ' conventional-commits-parser log.txt',
31
- ' cat log.txt | conventional-commits-parser',
32
- ' conventional-commits-parser log2.txt \'===\' >> parsed.txt',
33
- '',
34
- 'Options',
35
- ' -p, --header-pattern Regex to match header pattern',
36
- ' -c, --header-correspondence Comma separated parts used to define what capturing group of `headerPattern` captures what',
37
- ' -r, --reference-actions Comma separated keywords that used to reference issues',
38
- ' -i, --issue-prefixes Comma separated prefixes of an issue',
39
- ' -n, --note-keywords Comma separated keywords for important notes',
40
- ' -f, --field-pattern Regex to match other fields',
41
- ' --revert-pattern Regex to match revert pattern',
42
- ' --revert-correspondence Comma separated fields used to define what the commit reverts',
43
- ' -v, --verbose Verbose output'
44
- ]
45
- }, {
46
- alias: {
47
- p: 'headerPattern',
48
- c: 'headerCorrespondence',
49
- r: 'referenceActions',
50
- i: 'issuePrefixes',
51
- n: 'noteKeywords',
52
- f: 'fieldPattern',
53
- v: 'verbose'
16
+ var cli = meow(`
17
+ Practice writing commit messages or parse messages from files.
18
+ If used without specifying a text file path, you will enter an interactive shell.
19
+ Otherwise the commit messages in the files are parsed and printed
20
+ By default, commits will be split by three newlines ('\\n\\n\\n') or you can specify a separator.
21
+
22
+ Usage
23
+ conventional-commits-parser [<commit-separator>]
24
+ conventional-commits-parser [<commit-separator>] <path> [<path> ...]
25
+ cat <path> | conventional-commits-parser [<commit-separator>]
26
+
27
+ Example
28
+ conventional-commits-parser
29
+ conventional-commits-parser log.txt
30
+ cat log.txt | conventional-commits-parser
31
+ conventional-commits-parser log2.txt '===' >> parsed.txt
32
+
33
+ Options
34
+ -p, --header-pattern Regex to match header pattern
35
+ -c, --header-correspondence Comma separated parts used to define what capturing group of 'headerPattern' captures what
36
+ -r, --reference-actions Comma separated keywords that used to reference issues
37
+ -i, --issue-prefixes Comma separated prefixes of an issue
38
+ -n, --note-keywords Comma separated keywords for important notes
39
+ -f, --field-pattern Regex to match other fields
40
+ --revert-pattern Regex to match revert pattern
41
+ --revert-correspondence Comma separated fields used to define what the commit reverts
42
+ -v, --verbose Verbose output
43
+ `, {
44
+ flags: {
45
+ 'header-pattern': {
46
+ alias: `p`
47
+ },
48
+ 'header-correspondence': {
49
+ alias: `c`
50
+ },
51
+ 'reference-actions': {
52
+ alias: `r`
53
+ },
54
+ 'issue-prefixes': {
55
+ alias: `i`
56
+ },
57
+ 'note-keywords': {
58
+ alias: `n`
59
+ },
60
+ 'field-pattern': {
61
+ alias: `f`
62
+ },
63
+ verbose: {
64
+ alias: `v`
65
+ }
54
66
  }
55
- });
67
+ })
56
68
 
57
- forEach(cli.input, function(arg) {
69
+ forEach(cli.input, function (arg) {
58
70
  if (isTextPath(arg)) {
59
- filePaths.push(arg);
71
+ filePaths.push(arg)
60
72
  } else {
61
- separator = arg;
73
+ separator = arg
62
74
  }
63
- });
75
+ })
64
76
 
65
- var length = filePaths.length;
66
- var options = cli.flags;
77
+ var length = filePaths.length
78
+ var options = cli.flags
67
79
 
68
80
  if (options.verbose) {
69
- options.warn = console.log.bind(console);
81
+ options.warn = console.log.bind(console)
70
82
  }
71
83
 
72
- function processFile(fileIndex) {
73
- var filePath = filePaths[fileIndex];
84
+ function processFile (fileIndex) {
85
+ var filePath = filePaths[fileIndex]
74
86
  fs.createReadStream(filePath)
75
- .on('error', function(err) {
76
- console.warn('Failed to read file ' + filePath + '\n' + err);
87
+ .on('error', function (err) {
88
+ console.warn('Failed to read file ' + filePath + '\n' + err)
77
89
  if (++fileIndex < length) {
78
- processFile(fileIndex);
90
+ processFile(fileIndex)
79
91
  }
80
92
  })
81
93
  .pipe(split(separator))
82
94
  .pipe(conventionalCommitsParser(options))
83
95
  .pipe(JSONStream.stringify())
84
- .on('end', function() {
96
+ .on('end', function () {
85
97
  if (++fileIndex < length) {
86
- processFile(fileIndex);
98
+ processFile(fileIndex)
87
99
  }
88
100
  })
89
- .pipe(process.stdout);
101
+ .pipe(process.stdout)
90
102
  }
91
103
 
92
104
  if (process.stdin.isTTY) {
93
105
  if (length > 0) {
94
- processFile(0);
106
+ processFile(0)
95
107
  } else {
96
- var commit = '';
97
- var stream = through();
108
+ var commit = ''
109
+ var stream = through()
98
110
  var rl = readline.createInterface({
99
111
  input: process.stdin,
100
112
  output: process.stdout,
101
113
  terminal: true
102
- });
114
+ })
103
115
 
104
116
  stream.pipe(conventionalCommitsParser(options))
105
117
  .pipe(JSONStream.stringify('', '', ''))
106
- .pipe(through(function(chunk, enc, cb) {
118
+ .pipe(through(function (chunk, enc, cb) {
107
119
  if (chunk.toString() === '""') {
108
- cb(null, 'Commit cannot be parsed\n');
120
+ cb(null, 'Commit cannot be parsed\n')
109
121
  } else {
110
- cb(null, chunk + '\n');
122
+ cb(null, chunk + '\n')
111
123
  }
112
124
  }))
113
- .pipe(process.stdout);
125
+ .pipe(process.stdout)
114
126
 
115
- rl.on('line', function(line) {
116
- commit += line + '\n';
127
+ rl.on('line', function (line) {
128
+ commit += line + '\n'
117
129
  if (commit.indexOf(separator) === -1) {
118
- return;
130
+ return
119
131
  }
120
132
 
121
- stream.write(commit);
122
- commit = '';
123
- });
133
+ stream.write(commit)
134
+ commit = ''
135
+ })
124
136
  }
125
137
  } else {
126
- options.warn = true;
138
+ options.warn = true
127
139
  process.stdin
128
140
  .pipe(conventionalCommitsParser(options))
129
- .on('error', function(err) {
130
- console.error(err.toString());
131
- process.exit(1);
141
+ .on('error', function (err) {
142
+ console.error(err.toString())
143
+ process.exit(1)
132
144
  })
133
145
  .pipe(JSONStream.stringify())
134
- .pipe(process.stdout);
146
+ .pipe(process.stdout)
135
147
  }
package/index.js CHANGED
@@ -1,13 +1,13 @@
1
- 'use strict';
1
+ 'use strict'
2
2
 
3
- var parser = require('./lib/parser');
4
- var regex = require('./lib/regex');
5
- var through = require('through2');
6
- var _ = require('lodash');
3
+ var parser = require('./lib/parser')
4
+ var regex = require('./lib/regex')
5
+ var through = require('through2')
6
+ var _ = require('lodash')
7
7
 
8
- function assignOpts(options) {
8
+ function assignOpts (options) {
9
9
  options = _.extend({
10
- headerPattern: /^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
10
+ headerPattern: /^(\w*)(?:\(([\w$.\-* ]*)\))?: (.*)$/,
11
11
  headerCorrespondence: ['type', 'scope', 'subject'],
12
12
  referenceActions: [
13
13
  'close',
@@ -25,77 +25,77 @@ function assignOpts(options) {
25
25
  fieldPattern: /^-(.*?)-$/,
26
26
  revertPattern: /^Revert\s"([\s\S]*)"\s*This reverts commit (\w*)\./,
27
27
  revertCorrespondence: ['header', 'hash'],
28
- warn: function() {},
28
+ warn: function () {},
29
29
  mergePattern: null,
30
30
  mergeCorrespondence: null
31
- }, options);
31
+ }, options)
32
32
 
33
33
  if (typeof options.headerPattern === 'string') {
34
- options.headerPattern = new RegExp(options.headerPattern);
34
+ options.headerPattern = new RegExp(options.headerPattern)
35
35
  }
36
36
 
37
37
  if (typeof options.headerCorrespondence === 'string') {
38
- options.headerCorrespondence = options.headerCorrespondence.split(',');
38
+ options.headerCorrespondence = options.headerCorrespondence.split(',')
39
39
  }
40
40
 
41
41
  if (typeof options.referenceActions === 'string') {
42
- options.referenceActions = options.referenceActions.split(',');
42
+ options.referenceActions = options.referenceActions.split(',')
43
43
  }
44
44
 
45
45
  if (typeof options.issuePrefixes === 'string') {
46
- options.issuePrefixes = options.issuePrefixes.split(',');
46
+ options.issuePrefixes = options.issuePrefixes.split(',')
47
47
  }
48
48
 
49
49
  if (typeof options.noteKeywords === 'string') {
50
- options.noteKeywords = options.noteKeywords.split(',');
50
+ options.noteKeywords = options.noteKeywords.split(',')
51
51
  }
52
52
 
53
53
  if (typeof options.fieldPattern === 'string') {
54
- options.fieldPattern = new RegExp(options.fieldPattern);
54
+ options.fieldPattern = new RegExp(options.fieldPattern)
55
55
  }
56
56
 
57
57
  if (typeof options.revertPattern === 'string') {
58
- options.revertPattern = new RegExp(options.revertPattern);
58
+ options.revertPattern = new RegExp(options.revertPattern)
59
59
  }
60
60
 
61
61
  if (typeof options.revertCorrespondence === 'string') {
62
- options.revertCorrespondence = options.revertCorrespondence.split(',');
62
+ options.revertCorrespondence = options.revertCorrespondence.split(',')
63
63
  }
64
64
 
65
65
  if (typeof options.mergePattern === 'string') {
66
- options.mergePattern = new RegExp(options.mergePattern);
66
+ options.mergePattern = new RegExp(options.mergePattern)
67
67
  }
68
68
 
69
- return options;
69
+ return options
70
70
  }
71
71
 
72
- function conventionalCommitsParser(options) {
73
- options = assignOpts(options);
74
- var reg = regex(options);
72
+ function conventionalCommitsParser (options) {
73
+ options = assignOpts(options)
74
+ var reg = regex(options)
75
75
 
76
- return through.obj(function(data, enc, cb) {
77
- var commit;
76
+ return through.obj(function (data, enc, cb) {
77
+ var commit
78
78
 
79
79
  try {
80
- commit = parser(data.toString(), options, reg);
81
- cb(null, commit);
80
+ commit = parser(data.toString(), options, reg)
81
+ cb(null, commit)
82
82
  } catch (err) {
83
83
  if (options.warn === true) {
84
- cb(err);
84
+ cb(err)
85
85
  } else {
86
- options.warn(err.toString());
87
- cb(null, '');
86
+ options.warn(err.toString())
87
+ cb(null, '')
88
88
  }
89
89
  }
90
- });
90
+ })
91
91
  }
92
92
 
93
- function sync(commit, options) {
94
- options = assignOpts(options);
95
- var reg = regex(options);
93
+ function sync (commit, options) {
94
+ options = assignOpts(options)
95
+ var reg = regex(options)
96
96
 
97
- return parser(commit, options, reg);
97
+ return parser(commit, options, reg)
98
98
  }
99
99
 
100
- module.exports = conventionalCommitsParser;
101
- module.exports.sync = sync;
100
+ module.exports = conventionalCommitsParser
101
+ module.exports.sync = sync
package/lib/parser.js CHANGED
@@ -1,57 +1,57 @@
1
- 'use strict';
2
- var trimOffNewlines = require('trim-off-newlines');
3
- var _ = require('lodash');
1
+ 'use strict'
2
+ var trimOffNewlines = require('trim-off-newlines')
3
+ var _ = require('lodash')
4
4
 
5
- var CATCH_ALL = /()(.+)/gi;
6
- var SCISSOR = '# ------------------------ >8 ------------------------';
5
+ var CATCH_ALL = /()(.+)/gi
6
+ var SCISSOR = '# ------------------------ >8 ------------------------'
7
7
 
8
- function append(src, line) {
8
+ function append (src, line) {
9
9
  if (src) {
10
- src += '\n' + line;
10
+ src += '\n' + line
11
11
  } else {
12
- src = line;
12
+ src = line
13
13
  }
14
14
 
15
- return src;
15
+ return src
16
16
  }
17
17
 
18
- function getCommentFilter(char) {
19
- return function(line) {
20
- return line.charAt(0) !== char;
21
- };
18
+ function getCommentFilter (char) {
19
+ return function (line) {
20
+ return line.charAt(0) !== char
21
+ }
22
22
  }
23
23
 
24
- function truncateToScissor(lines) {
25
- var scissorIndex = lines.indexOf(SCISSOR);
24
+ function truncateToScissor (lines) {
25
+ var scissorIndex = lines.indexOf(SCISSOR)
26
26
 
27
27
  if (scissorIndex === -1) {
28
- return lines;
28
+ return lines
29
29
  }
30
30
 
31
- return lines.slice(0, scissorIndex);
31
+ return lines.slice(0, scissorIndex)
32
32
  }
33
33
 
34
- function getReferences(input, regex) {
35
- var references = [];
36
- var referenceSentences;
37
- var referenceMatch;
34
+ function getReferences (input, regex) {
35
+ var references = []
36
+ var referenceSentences
37
+ var referenceMatch
38
38
 
39
- var reApplicable = input.match(regex.references) !== null ?
40
- regex.references :
41
- CATCH_ALL;
39
+ var reApplicable = input.match(regex.references) !== null
40
+ ? regex.references
41
+ : CATCH_ALL
42
42
 
43
- while (referenceSentences = reApplicable.exec(input)) {
44
- var action = referenceSentences[1] || null;
45
- var sentence = referenceSentences[2];
43
+ while ((referenceSentences = reApplicable.exec(input))) {
44
+ var action = referenceSentences[1] || null
45
+ var sentence = referenceSentences[2]
46
46
 
47
- while (referenceMatch = regex.referenceParts.exec(sentence)) {
48
- var owner = null;
49
- var repository = referenceMatch[1] || '';
50
- var ownerRepo = repository.split('/');
47
+ while ((referenceMatch = regex.referenceParts.exec(sentence))) {
48
+ var owner = null
49
+ var repository = referenceMatch[1] || ''
50
+ var ownerRepo = repository.split('/')
51
51
 
52
52
  if (ownerRepo.length > 1) {
53
- owner = ownerRepo.shift();
54
- repository = ownerRepo.join('/');
53
+ owner = ownerRepo.shift()
54
+ repository = ownerRepo.join('/')
55
55
  }
56
56
 
57
57
  var reference = {
@@ -61,65 +61,65 @@ function getReferences(input, regex) {
61
61
  issue: referenceMatch[3],
62
62
  raw: referenceMatch[0],
63
63
  prefix: referenceMatch[2]
64
- };
64
+ }
65
65
 
66
- references.push(reference);
66
+ references.push(reference)
67
67
  }
68
68
  }
69
69
 
70
- return references;
70
+ return references
71
71
  }
72
72
 
73
- function passTrough() {
74
- return true;
73
+ function passTrough () {
74
+ return true
75
75
  }
76
76
 
77
- function parser(raw, options, regex) {
77
+ function parser (raw, options, regex) {
78
78
  if (!raw || !raw.trim()) {
79
- throw new TypeError('Expected a raw commit');
79
+ throw new TypeError('Expected a raw commit')
80
80
  }
81
81
 
82
82
  if (_.isEmpty(options)) {
83
- throw new TypeError('Expected options');
83
+ throw new TypeError('Expected options')
84
84
  }
85
85
 
86
86
  if (_.isEmpty(regex)) {
87
- throw new TypeError('Expected regex');
87
+ throw new TypeError('Expected regex')
88
88
  }
89
89
 
90
- var headerMatch;
91
- var mergeMatch;
92
- var currentProcessedField;
93
- var mentionsMatch;
94
- var revertMatch;
95
- var otherFields = {};
96
- var commentFilter = typeof options.commentChar === 'string' ?
97
- getCommentFilter(options.commentChar) :
98
- passTrough;
99
-
100
- var rawLines = trimOffNewlines(raw).split(/\r?\n/);
101
- var lines = truncateToScissor(rawLines).filter(commentFilter);
102
-
103
- var continueNote = false;
104
- var isBody = true;
105
- var headerCorrespondence = _.map(options.headerCorrespondence, function(part) {
106
- return part.trim();
107
- });
108
- var revertCorrespondence = _.map(options.revertCorrespondence, function(field) {
109
- return field.trim();
110
- });
111
- var mergeCorrespondence = _.map(options.mergeCorrespondence, function(field) {
112
- return field.trim();
113
- });
114
-
115
- var body = null;
116
- var footer = null;
117
- var header = null;
118
- var mentions = [];
119
- var merge = null;
120
- var notes = [];
121
- var references = [];
122
- var revert = null;
90
+ var headerMatch
91
+ var mergeMatch
92
+ var currentProcessedField
93
+ var mentionsMatch
94
+ var revertMatch
95
+ var otherFields = {}
96
+ var commentFilter = typeof options.commentChar === 'string'
97
+ ? getCommentFilter(options.commentChar)
98
+ : passTrough
99
+
100
+ var rawLines = trimOffNewlines(raw).split(/\r?\n/)
101
+ var lines = truncateToScissor(rawLines).filter(commentFilter)
102
+
103
+ var continueNote = false
104
+ var isBody = true
105
+ var headerCorrespondence = _.map(options.headerCorrespondence, function (part) {
106
+ return part.trim()
107
+ })
108
+ var revertCorrespondence = _.map(options.revertCorrespondence, function (field) {
109
+ return field.trim()
110
+ })
111
+ var mergeCorrespondence = _.map(options.mergeCorrespondence, function (field) {
112
+ return field.trim()
113
+ })
114
+
115
+ var body = null
116
+ var footer = null
117
+ var header = null
118
+ var mentions = []
119
+ var merge = null
120
+ var notes = []
121
+ var references = []
122
+ var revert = null
123
123
 
124
124
  if (lines.length === 0) {
125
125
  return {
@@ -134,148 +134,148 @@ function parser(raw, options, regex) {
134
134
  scope: null,
135
135
  subject: null,
136
136
  type: null
137
- };
137
+ }
138
138
  }
139
139
 
140
140
  // msg parts
141
- merge = lines.shift();
142
- var mergeParts = {};
143
- var headerParts = {};
144
- body = '';
145
- footer = '';
141
+ merge = lines.shift()
142
+ var mergeParts = {}
143
+ var headerParts = {}
144
+ body = ''
145
+ footer = ''
146
146
 
147
- mergeMatch = merge.match(options.mergePattern);
147
+ mergeMatch = merge.match(options.mergePattern)
148
148
  if (mergeMatch && options.mergePattern) {
149
- merge = mergeMatch[0];
149
+ merge = mergeMatch[0]
150
150
 
151
- header = lines.shift();
151
+ header = lines.shift()
152
152
  while (!header.trim()) {
153
- header = lines.shift();
153
+ header = lines.shift()
154
154
  }
155
155
 
156
- _.forEach(mergeCorrespondence, function(partName, index) {
157
- var partValue = mergeMatch[index + 1] || null;
158
- mergeParts[partName] = partValue;
159
- });
156
+ _.forEach(mergeCorrespondence, function (partName, index) {
157
+ var partValue = mergeMatch[index + 1] || null
158
+ mergeParts[partName] = partValue
159
+ })
160
160
  } else {
161
- header = merge;
162
- merge = null;
161
+ header = merge
162
+ merge = null
163
163
 
164
- _.forEach(mergeCorrespondence, function(partName) {
165
- mergeParts[partName] = null;
166
- });
164
+ _.forEach(mergeCorrespondence, function (partName) {
165
+ mergeParts[partName] = null
166
+ })
167
167
  }
168
168
 
169
- headerMatch = header.match(options.headerPattern);
169
+ headerMatch = header.match(options.headerPattern)
170
170
  if (headerMatch) {
171
- _.forEach(headerCorrespondence, function(partName, index) {
172
- var partValue = headerMatch[index + 1] || null;
173
- headerParts[partName] = partValue;
174
- });
171
+ _.forEach(headerCorrespondence, function (partName, index) {
172
+ var partValue = headerMatch[index + 1] || null
173
+ headerParts[partName] = partValue
174
+ })
175
175
  } else {
176
- _.forEach(headerCorrespondence, function(partName) {
177
- headerParts[partName] = null;
178
- });
176
+ _.forEach(headerCorrespondence, function (partName) {
177
+ headerParts[partName] = null
178
+ })
179
179
  }
180
180
 
181
181
  Array.prototype.push.apply(references, getReferences(header, {
182
182
  references: regex.references,
183
183
  referenceParts: regex.referenceParts
184
- }));
184
+ }))
185
185
 
186
186
  // body or footer
187
- _.forEach(lines, function(line) {
187
+ _.forEach(lines, function (line) {
188
188
  if (options.fieldPattern) {
189
- var fieldMatch = options.fieldPattern.exec(line);
189
+ var fieldMatch = options.fieldPattern.exec(line)
190
190
 
191
191
  if (fieldMatch) {
192
- currentProcessedField = fieldMatch[1];
192
+ currentProcessedField = fieldMatch[1]
193
193
 
194
- return;
194
+ return
195
195
  }
196
196
 
197
197
  if (currentProcessedField) {
198
- otherFields[currentProcessedField] = append(otherFields[currentProcessedField], line);
198
+ otherFields[currentProcessedField] = append(otherFields[currentProcessedField], line)
199
199
 
200
- return;
200
+ return
201
201
  }
202
202
  }
203
203
 
204
- var referenceMatched;
204
+ var referenceMatched
205
205
 
206
206
  // this is a new important note
207
- var notesMatch = line.match(regex.notes);
207
+ var notesMatch = line.match(regex.notes)
208
208
  if (notesMatch) {
209
- continueNote = true;
210
- isBody = false;
211
- footer = append(footer, line);
209
+ continueNote = true
210
+ isBody = false
211
+ footer = append(footer, line)
212
212
 
213
213
  var note = {
214
214
  title: notesMatch[1],
215
215
  text: notesMatch[2]
216
- };
216
+ }
217
217
 
218
- notes.push(note);
218
+ notes.push(note)
219
219
 
220
- return;
220
+ return
221
221
  }
222
222
 
223
223
  var lineReferences = getReferences(line, {
224
224
  references: regex.references,
225
225
  referenceParts: regex.referenceParts
226
- });
226
+ })
227
227
 
228
228
  if (lineReferences.length > 0) {
229
- isBody = false;
230
- referenceMatched = true;
231
- continueNote = false;
229
+ isBody = false
230
+ referenceMatched = true
231
+ continueNote = false
232
232
  }
233
233
 
234
- Array.prototype.push.apply(references, lineReferences);
234
+ Array.prototype.push.apply(references, lineReferences)
235
235
 
236
236
  if (referenceMatched) {
237
- footer = append(footer, line);
237
+ footer = append(footer, line)
238
238
 
239
- return;
239
+ return
240
240
  }
241
241
 
242
242
  if (continueNote) {
243
- notes[notes.length - 1].text = append(notes[notes.length - 1].text, line);
244
- footer = append(footer, line);
243
+ notes[notes.length - 1].text = append(notes[notes.length - 1].text, line)
244
+ footer = append(footer, line)
245
245
 
246
- return;
246
+ return
247
247
  }
248
248
 
249
249
  if (isBody) {
250
- body = append(body, line);
250
+ body = append(body, line)
251
251
  } else {
252
- footer = append(footer, line);
252
+ footer = append(footer, line)
253
253
  }
254
- });
254
+ })
255
255
 
256
- while (mentionsMatch = regex.mentions.exec(raw)) {
257
- mentions.push(mentionsMatch[1]);
256
+ while ((mentionsMatch = regex.mentions.exec(raw))) {
257
+ mentions.push(mentionsMatch[1])
258
258
  }
259
259
 
260
260
  // does this commit revert any other commit?
261
- revertMatch = raw.match(options.revertPattern);
261
+ revertMatch = raw.match(options.revertPattern)
262
262
  if (revertMatch) {
263
- revert = {};
264
- _.forEach(revertCorrespondence, function(partName, index) {
265
- var partValue = revertMatch[index + 1] || null;
266
- revert[partName] = partValue;
267
- });
263
+ revert = {}
264
+ _.forEach(revertCorrespondence, function (partName, index) {
265
+ var partValue = revertMatch[index + 1] || null
266
+ revert[partName] = partValue
267
+ })
268
268
  } else {
269
- revert = null;
269
+ revert = null
270
270
  }
271
271
 
272
- _.map(notes, function(note) {
273
- note.text = trimOffNewlines(note.text);
272
+ _.map(notes, function (note) {
273
+ note.text = trimOffNewlines(note.text)
274
274
 
275
- return note;
276
- });
275
+ return note
276
+ })
277
277
 
278
- var msg = _.merge(headerParts, mergeParts, {
278
+ var msg = _.merge(headerParts, mergeParts, {
279
279
  merge: merge,
280
280
  header: header,
281
281
  body: body ? trimOffNewlines(body) : null,
@@ -284,9 +284,9 @@ function parser(raw, options, regex) {
284
284
  references: references,
285
285
  mentions: mentions,
286
286
  revert: revert
287
- }, otherFields);
287
+ }, otherFields)
288
288
 
289
- return msg;
289
+ return msg
290
290
  }
291
291
 
292
- module.exports = parser;
292
+ module.exports = parser
package/lib/regex.js CHANGED
@@ -1,54 +1,54 @@
1
- 'use strict';
1
+ 'use strict'
2
2
 
3
- var reNomatch = /(?!.*)/;
3
+ var reNomatch = /(?!.*)/
4
4
 
5
- function join(array, joiner) {
5
+ function join (array, joiner) {
6
6
  return array
7
- .map(function(val) {
8
- return val.trim();
7
+ .map(function (val) {
8
+ return val.trim()
9
9
  })
10
- .filter(function(val) {
11
- return val.length;
10
+ .filter(function (val) {
11
+ return val.length
12
12
  })
13
- .join(joiner);
13
+ .join(joiner)
14
14
  }
15
15
 
16
- function getNotesRegex(noteKeywords) {
16
+ function getNotesRegex (noteKeywords) {
17
17
  if (!noteKeywords) {
18
- return reNomatch;
18
+ return reNomatch
19
19
  }
20
20
 
21
- return new RegExp('^[\\s|*]*(' + join(noteKeywords, '|') + ')[:\\s]+(.*)', 'i');
21
+ return new RegExp('^[\\s|*]*(' + join(noteKeywords, '|') + ')[:\\s]+(.*)', 'i')
22
22
  }
23
23
 
24
- function getReferencePartsRegex(issuePrefixes) {
24
+ function getReferencePartsRegex (issuePrefixes) {
25
25
  if (!issuePrefixes) {
26
- return reNomatch;
26
+ return reNomatch
27
27
  }
28
28
 
29
- return new RegExp('(?:.*?)??\\s*([\\w-\\.\\/]*?)??(' + join(issuePrefixes, '|') + ')([\\w-]*\\d+)', 'gi');
29
+ return new RegExp('(?:.*?)??\\s*([\\w-\\.\\/]*?)??(' + join(issuePrefixes, '|') + ')([\\w-]*\\d+)', 'gi')
30
30
  }
31
31
 
32
- function getReferencesRegex(referenceActions) {
32
+ function getReferencesRegex (referenceActions) {
33
33
  if (!referenceActions) {
34
34
  // matches everything
35
- return /()(.+)/gi;
35
+ return /()(.+)/gi
36
36
  }
37
37
 
38
- var joinedKeywords = join(referenceActions, '|');
39
- return new RegExp('(' + joinedKeywords + ')(?:\\s+(.*?))(?=(?:' + joinedKeywords + ')|$)', 'gi');
38
+ var joinedKeywords = join(referenceActions, '|')
39
+ return new RegExp('(' + joinedKeywords + ')(?:\\s+(.*?))(?=(?:' + joinedKeywords + ')|$)', 'gi')
40
40
  }
41
41
 
42
- module.exports = function(options) {
43
- options = options || {};
44
- var reNotes = getNotesRegex(options.noteKeywords);
45
- var reReferenceParts = getReferencePartsRegex(options.issuePrefixes);
46
- var reReferences = getReferencesRegex(options.referenceActions);
42
+ module.exports = function (options) {
43
+ options = options || {}
44
+ var reNotes = getNotesRegex(options.noteKeywords)
45
+ var reReferenceParts = getReferencePartsRegex(options.issuePrefixes)
46
+ var reReferences = getReferencesRegex(options.referenceActions)
47
47
 
48
48
  return {
49
49
  notes: reNotes,
50
50
  referenceParts: reReferenceParts,
51
51
  references: reReferences,
52
52
  mentions: /@([\w-]+)/g
53
- };
54
- };
53
+ }
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conventional-commits-parser",
3
- "version": "2.1.4",
3
+ "version": "3.0.0",
4
4
  "description": "Parse raw conventional commits",
5
5
  "bugs": {
6
6
  "url": "https://github.com/conventional-changelog/conventional-changelog/issues"
@@ -16,6 +16,9 @@
16
16
  "url": "https://github.com/conventional-changelog/conventional-changelog.git"
17
17
  },
18
18
  "license": "MIT",
19
+ "engines": {
20
+ "node": ">=6.9.0"
21
+ },
19
22
  "files": [
20
23
  "index.js",
21
24
  "cli.js",
@@ -33,21 +36,16 @@
33
36
  "JSONStream": "^1.0.4",
34
37
  "is-text-path": "^1.0.0",
35
38
  "lodash": "^4.2.1",
36
- "meow": "^3.3.0",
39
+ "meow": "^4.0.0",
37
40
  "split2": "^2.0.0",
38
41
  "through2": "^2.0.0",
39
42
  "trim-off-newlines": "^1.0.0"
40
43
  },
41
44
  "devDependencies": {
42
- "chai": "^3.0.0",
43
- "concat-stream": "^1.4.7",
44
- "istanbul": "^0.4.2",
45
- "jscs": "^3.0.7",
46
- "jshint": "^2.7.0",
47
- "mocha": "*"
45
+ "concat-stream": "^1.6.0"
48
46
  },
49
47
  "scripts": {
50
- "lint": "jshint *.js lib test && jscs *.js lib test",
48
+ "lint": "eslint --fix .",
51
49
  "test": "npm run lint && mocha --timeout=30000",
52
50
  "test-windows": "echo 'make work on windows'"
53
51
  },