@oneblink/release-cli 1.2.0-beta.1 → 1.2.0-beta.4

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/node_modules/changelog-parser/.DS_Store +0 -0
  3. package/node_modules/changelog-parser/.travis.yml +7 -0
  4. package/node_modules/changelog-parser/CHANGELOG.md +128 -0
  5. package/node_modules/changelog-parser/CONTRIBUTING.md +55 -0
  6. package/node_modules/changelog-parser/LICENSE.md +15 -0
  7. package/node_modules/changelog-parser/README.md +247 -0
  8. package/node_modules/changelog-parser/bin/cli.js +19 -0
  9. package/node_modules/changelog-parser/index.js +201 -0
  10. package/node_modules/changelog-parser/package.json +54 -0
  11. package/node_modules/changelog-parser/test/fixtures/CHANGELOG.md +44 -0
  12. package/node_modules/changelog-parser/test/fixtures/expected.js +113 -0
  13. package/node_modules/changelog-parser/test/fixtures/remove-markdown-expected.js +113 -0
  14. package/node_modules/changelog-parser/test/index.js +105 -0
  15. package/node_modules/line-reader/LICENSE +20 -0
  16. package/node_modules/line-reader/README.md +75 -0
  17. package/node_modules/line-reader/lib/line_reader.js +174 -0
  18. package/node_modules/line-reader/package.json +18 -0
  19. package/node_modules/line-reader/test/data/empty_file.txt +0 -0
  20. package/node_modules/line-reader/test/data/multi_separator_file.txt +2 -0
  21. package/node_modules/line-reader/test/data/multibyte_file.txt +2 -0
  22. package/node_modules/line-reader/test/data/normal_file.txt +6 -0
  23. package/node_modules/line-reader/test/data/one_line_file.txt +1 -0
  24. package/node_modules/line-reader/test/data/separator_file.txt +2 -0
  25. package/node_modules/line-reader/test/data/three_line_file.txt +3 -0
  26. package/node_modules/line-reader/test/line_reader.js +222 -0
  27. package/node_modules/remove-markdown/.npmignore +1 -0
  28. package/node_modules/remove-markdown/LICENSE +21 -0
  29. package/node_modules/remove-markdown/README.md +44 -0
  30. package/node_modules/remove-markdown/index.js +60 -0
  31. package/node_modules/remove-markdown/package.json +31 -0
  32. package/node_modules/remove-markdown/test/remove-markdown.js +139 -0
  33. package/package.json +6 -2
  34. package/patches/changelog-parser+2.8.0.patch +10 -0
package/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Moved
11
+
12
+ `patch-package` to deps
13
+
14
+ ### Added
15
+
16
+ `patches` dir to `files` in `package.json` file
17
+
10
18
  ## [1.1.0] - 2022-08-26
11
19
 
12
20
  ### Patched
@@ -0,0 +1,7 @@
1
+ language: node_js
2
+ node_js:
3
+ - '8'
4
+ - '10'
5
+ cache:
6
+ directories:
7
+ - node_modules
@@ -0,0 +1,128 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/).
7
+
8
+ ## [2.8.0](https://github.com/hypermodules/changelog-parser/compare/v2.7.0...v2.8.0) - 2019-05-02
9
+
10
+ ### Features
11
+
12
+ - accept input text instead of file (#32) - @jedwards1211 & @ungoldman
13
+
14
+ ## [2.7.0](https://github.com/hypermodules/changelog-parser/compare/v2.6.0...v2.7.0) - 2019-03-07
15
+
16
+ ### Features
17
+
18
+ - accept options object, add removeMarkdown option (#29) - @cironunes & @ungoldman
19
+
20
+ ## [2.6.0](https://github.com/hypermodules/changelog-parser/compare/v2.5.0...v2.5.1) - 2018-12-18
21
+
22
+ ### Features
23
+
24
+ - allow version headers in CHANGELOG to use either H1 (#) or H2 (##) headers (#14) - @eladb
25
+
26
+ ## [2.5.1](https://github.com/hypermodules/changelog-parser/compare/v2.5.0...v2.5.1) - 2018-12-05
27
+
28
+ ### Fixes
29
+
30
+ - Protect against no current value (#24) - thanks @sabrehagen
31
+
32
+ ## [2.5.0](https://github.com/hypermodules/changelog-parser/compare/v2.4.0...v2.5.0) - 2018-05-30
33
+
34
+ ### Features
35
+
36
+ - add international date format support (#25) - thanks @godban
37
+
38
+ ## [2.4.0](https://github.com/hypermodules/changelog-parser/compare/v2.3.0...v2.4.0) - 2018-02-13
39
+
40
+ ### Features
41
+
42
+ - stringify results in CLI (#22) - thanks @benmonro
43
+
44
+ ## [2.3.0](https://github.com/hypermodules/changelog-parser/compare/v2.2.0...v2.3.0) - 2018-01-09
45
+
46
+ ### Features
47
+
48
+ - add support for parsed body (#20) (#21) - thanks @jrmykolyn
49
+
50
+ ## [2.2.0](https://github.com/hypermodules/changelog-parser/compare/v2.1.0...v2.2.0) - 2017-12-29
51
+
52
+ ### Features
53
+
54
+ - add promise support (#18) (#19) - thanks @jrmykolyn
55
+
56
+ ## [2.1.0](https://github.com/hypermodules/changelog-parser/compare/v2.0.5...v2.1.0) - 2017-12-12
57
+
58
+ ### Features
59
+
60
+ - add date to version objects; update tests. (#6) (#15) - thanks @jrmykolyn
61
+
62
+ ### Chores
63
+
64
+ - add release script
65
+
66
+ ## [2.0.5](https://github.com/hypermodules/changelog-parser/compare/v2.0.4...v2.0.5) - 2017-06-28
67
+
68
+ ### Changes
69
+
70
+ - chore(ci): add 8, drop .10 & .12
71
+ - docs(readme): move badges out of title
72
+ - lint: fix useless escapes
73
+ - chore(pkg): bump to latest standard
74
+ - chore(gitignore): ignore lock files
75
+ - docs(readme): update repo web address
76
+
77
+ ## [2.0.4](https://github.com/hypermodules/changelog-parser/compare/v2.0.3...v2.0.4)
78
+
79
+ ### Fixes
80
+
81
+ - reset log & current vars after each execution (#10)
82
+
83
+ ## [2.0.3](https://github.com/hypermodules/changelog-parser/compare/v2.0.2...v2.0.3) - 2016-09-09
84
+
85
+ - bump dev dependencies
86
+ - update repo URL
87
+ - update maintainer email
88
+
89
+ ## [2.0.2](https://github.com/hypermodules/changelog-parser/compare/v2.0.1...v2.0.2) - 2015-06-15
90
+
91
+ - readme updates
92
+ - change log fix
93
+ - add keywords to package.json
94
+
95
+ ## [2.0.1](https://github.com/hypermodules/changelog-parser/compare/v2.0.0...v2.0.1) - 2015-06-07
96
+
97
+ ### Changes
98
+
99
+ - use `os` module to support cross-platform EOL parsing ([#4](https://github.com/hypermodules/changelog-parser/pull/4))
100
+
101
+ ## [2.0.0](https://github.com/hypermodules/changelog-parser/compare/v1.1.0...v2.0.0) - 2015-04-02
102
+
103
+ ### Breaking Changes
104
+
105
+ - `version` key of version object is now `null` unless semver found
106
+
107
+ ### Changes
108
+
109
+ - parse out `v` prefix for version numbers ([gh-release#23](https://github.com/hypermodules/gh-release/issues/23))
110
+
111
+ ### Additions
112
+
113
+ - add `title` key to version object
114
+ - add a real test
115
+
116
+ ## [1.1.0](https://github.com/hypermodules/changelog-parser/compare/v1.0.1...v1.1.0) - 2015-03-07
117
+
118
+ - add cli support
119
+ - remove `description` key if empty
120
+ - add `CONTRIBUTING.md`
121
+ - add node 0.10 to travis-ci testing environments
122
+
123
+ ## [1.0.1](https://github.com/hypermodules/changelog-parser/compare/v1.0.0...v1.0.1) - 2015-03-02
124
+
125
+ - fix readme example for [paulcpederson](http://github.com/paulcpederson/)
126
+
127
+ ## 1.0.0 - 2015-03-02
128
+ - init
@@ -0,0 +1,55 @@
1
+ # Contributing Guidelines
2
+
3
+ Contributions welcome! Please check past issues and pull requests before you open your own issue or pull request to avoid duplicating a frequently asked question.
4
+
5
+ In addition to improving the project, refactoring code, and implementing features, this project welcomes the following types of contributions:
6
+
7
+ - **Ideas**: participate in an issue thread or start your own to have your voice heard.
8
+ - **Writing**: contribute your expertise in an area by helping expand the included content.
9
+ - **Copy editing**: fix typos, clarify language, and generally improve the quality of the content.
10
+ - **Formatting**: help keep content easy to read with consistent formatting.
11
+
12
+ ## Install
13
+
14
+ Fork and clone the repo, then `npm install` to install all dependencies.
15
+
16
+ ## Testing
17
+
18
+ Tests are run with `npm test`. Please ensure all tests are passing before submitting a pull request (unless you're creating a failing test to increase test coverage or show a problem).
19
+
20
+ ## Code Style
21
+
22
+ [![standard][standard-image]][standard-url]
23
+
24
+ This repository uses [`standard`][standard-url] to maintain code style and consistency and avoid style arguments. `npm test` runs `standard` so you don't have to!
25
+
26
+ [standard-image]: https://cdn.rawgit.com/feross/standard/master/badge.svg
27
+ [standard-url]: https://github.com/feross/standard
28
+
29
+ ---
30
+
31
+ # Collaborating Guidelines
32
+
33
+ **This is an OPEN Open Source Project.**
34
+
35
+ ## What?
36
+
37
+ Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
38
+
39
+ ## Rules
40
+
41
+ There are a few basic ground-rules for contributors:
42
+
43
+ 1. **No `--force` pushes** or modifying the Git history in any way.
44
+ 1. **Non-master branches** ought to be used for ongoing work.
45
+ 1. **External API changes and significant modifications** ought to be subject to an **internal pull-request** to solicit feedback from other contributors.
46
+ 1. Internal pull-requests to solicit feedback are *encouraged* for any other non-trivial contribution but left to the discretion of the contributor.
47
+ 1. Contributors should attempt to adhere to the prevailing code style.
48
+
49
+ ## Releases
50
+
51
+ Declaring formal releases remains the prerogative of the project maintainer.
52
+
53
+ ## Changes to this arrangement
54
+
55
+ This is an experiment and feedback is welcome! This document may also be subject to pull-requests or changes by contributors where you believe you have something valuable to add or change.
@@ -0,0 +1,15 @@
1
+ # [ISC License](https://spdx.org/licenses/ISC)
2
+
3
+ Copyright (c) 2016, Nate Goldman <ungoldman@gmail.com>
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,247 @@
1
+ # changelog-parser
2
+
3
+ [![npm][npm-img]][npm-url] [![travis][travis-img]][travis-url] [![standard][standard-image]][standard-url] [![downloads][downloads-img]][npm-url]
4
+
5
+ Change log parser for node.
6
+
7
+ [npm-img]: https://img.shields.io/npm/v/changelog-parser.svg?style=flat-square
8
+ [npm-url]: https://www.npmjs.com/package/changelog-parser
9
+ [travis-img]: https://img.shields.io/travis/hypermodules/changelog-parser.svg?style=flat-square
10
+ [travis-url]: https://travis-ci.org/hypermodules/changelog-parser
11
+ [standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
12
+ [standard-url]: http://standardjs.com/
13
+ [downloads-img]: https://img.shields.io/npm/dm/changelog-parser.svg?style=flat-square
14
+
15
+ ## Install
16
+
17
+ ```
18
+ npm install changelog-parser
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ This module exports a single function. It supports both callbacks and promises.
24
+
25
+ ```js
26
+ var parseChangelog = require('changelog-parser')
27
+ ```
28
+
29
+ ### Callback
30
+
31
+ If provided with a callback, `parseChangelog` will invoke the function with the parsed changelog.
32
+
33
+ ```js
34
+ parseChangelog('path/to/CHANGELOG.md', function (err, result) {
35
+ if (err) throw err
36
+
37
+ // changelog object
38
+ console.log(result)
39
+ })
40
+ ```
41
+
42
+ ### Promise
43
+
44
+ If no callback is provided, `parseChangelog` will return a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
45
+
46
+ ```js
47
+ parseChangelog('path/to/CHANGELOG.md')
48
+ .then(function (result) {
49
+ // changelog object
50
+ console.log(result)
51
+ })
52
+ .catch(function (err) {
53
+ // Whoops, something went wrong!
54
+ console.error(err)
55
+ })
56
+ ```
57
+
58
+ ### Options
59
+
60
+ You can optionally provide a configuration object `parseChangelog` function.
61
+
62
+ ```js
63
+ parseChangelog({
64
+ filePath: 'path/to/CHANGELOG.md',
65
+ removeMarkdown: false // default: true
66
+ })
67
+ ```
68
+
69
+ #### filePath
70
+
71
+ Path to changelog file.
72
+
73
+ #### text
74
+
75
+ Text of changelog file (you can use this instead of `filePath`).
76
+
77
+ #### removeMarkdown
78
+
79
+ Removes the markdown markup from the changelog entries by default. You can change its value to `false` to keep the markdown.
80
+
81
+ ### Command-line interface
82
+
83
+ There is also a command-line interface available if you install it with `-g`.
84
+
85
+ ```
86
+ npm install -g changelog-parser
87
+ ```
88
+
89
+ This installs a program called `changelog-parser` that you simply pass a `CHANGELOG.md` file.
90
+
91
+ ```
92
+ changelog-parser path/to/CHANGELOG.md
93
+ ```
94
+
95
+ This will print the JSON object representing the change log to the terminal.
96
+
97
+ Alternately you can run it without arguments and it will look for a `CHANGELOG.md` file in the working directory.
98
+
99
+ ## Standards
100
+
101
+ This module assumes your change log is a [markdown](http://daringfireball.net/projects/markdown/syntax) file structured roughly like so:
102
+
103
+ ```markdown
104
+ # changelog title
105
+
106
+ A cool description (optional).
107
+
108
+ ## unreleased
109
+ * foo
110
+
111
+ ## x.y.z - YYYY-MM-DD (or DD.MM.YYYY, D/M/YY, etc.)
112
+ * bar
113
+
114
+ ## [a.b.c]
115
+
116
+ ### Changes
117
+
118
+ * Update API
119
+ * Fix bug #1
120
+
121
+ ## 2.2.3-pre.1 - 2013-02-14
122
+ * Update API
123
+
124
+ ## 2.0.0-x.7.z.92 - 2013-02-14
125
+ * bark bark
126
+ * woof
127
+ * arf
128
+
129
+ ## v1.3.0
130
+
131
+ * make it so
132
+
133
+ ## [1.2.3](link)
134
+ * init
135
+
136
+ [a.b.c]: http://altavista.com
137
+ ```
138
+
139
+ Parsing the above example will return the following object:
140
+
141
+ ```js
142
+ {
143
+ title: 'changelog title',
144
+ description: 'A cool description (optional).',
145
+ versions: [
146
+ { version: null,
147
+ title: 'unreleased',
148
+ date: null,
149
+ body: '* foo',
150
+ parsed: {
151
+ _: [
152
+ 'foo'
153
+ ]
154
+ }
155
+ },
156
+ { version: 'x.y.z',
157
+ title: 'x.y.z - YYYY-MM-DD',
158
+ date: null,
159
+ body: '* bar',
160
+ parsed: {
161
+ _: [
162
+ 'bar'
163
+ ]
164
+ }
165
+ },
166
+ { version: 'a.b.c',
167
+ title: '[a.b.c]',
168
+ date: null,
169
+ body: '### Changes\n\n* Update API\n* Fix bug #1',
170
+ parsed: {
171
+ _: [
172
+ 'Update API',
173
+ 'Fix bug #1'
174
+ ],
175
+ Changes: [
176
+ 'Update API',
177
+ 'Fix bug #1'
178
+ ]
179
+ }
180
+ },
181
+ { version: '2.2.3-pre.1',
182
+ title: '2.2.3-pre.1 - 2013-02-14',
183
+ date: '2013-02-14',
184
+ body: '* Update API',
185
+ parsed: {
186
+ _: [
187
+ 'Update API'
188
+ ]
189
+ }
190
+ },
191
+ { version: '2.0.0-x.7.z.92',
192
+ title: '2.0.0-x.7.z.92 - 2013-02-14',
193
+ date: '2013-02-14',
194
+ body: '* bark bark\n* woof\n* arf',
195
+ parsed: {
196
+ _: [
197
+ 'bark bark',
198
+ 'woof',
199
+ 'arf'
200
+ ]
201
+ }
202
+ },
203
+ { version: '1.3.0',
204
+ title: 'v1.3.0',
205
+ date: null,
206
+ body: '* make it so',
207
+ parsed: {
208
+ _: [
209
+ 'make it so'
210
+ ]
211
+ }
212
+ },
213
+ { version: '1.2.3',
214
+ title: '[1.2.3](link)',
215
+ date: null,
216
+ body: '* init',
217
+ parsed: {
218
+ _: [
219
+ 'init'
220
+ ]
221
+ }
222
+ }
223
+ ]
224
+ }
225
+ ```
226
+
227
+ Expects versions to be [semver](http://semver.org/) compliant, otherwise sets `version` to null.
228
+
229
+ Each entry is available as an object in the `versions` array. The body of a given entry can be accessed using the following properties:
230
+
231
+ - `body` - A string containing all of the updates/changes/etc. for the current entry. This property includes both plain text and markdown.
232
+ - `parsed` - An object which points to one or more arrays of data for the current entry. All data for the current entry is present in the array at key `_` (eg. `parsed._`). If the entry contains subheadings (eg. `### Added`, `### Changed`), then any items underneath each subheading will be present in an array at the corresponding key (eg. `parsed.Added`, `parsed.Changed`). Each array contains plain text.
233
+
234
+ `CHANGELOG.md` standards are inspired by [keepachangelog.com](http://keepachangelog.com/).
235
+
236
+ ## Contributing
237
+
238
+ Contributions welcome! Please read the [contributing guidelines](CONTRIBUTING.md) first.
239
+
240
+ ## See Also
241
+
242
+ - [changelog-init](https://github.com/bcomnes/changelog-init)
243
+ - [gh-release](https://github.com/hypermodules/gh-release)
244
+
245
+ ## License
246
+
247
+ [ISC](LICENSE.md)
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+
3
+ var parseChangelog = require('..')
4
+ var file = process.argv[2] || 'CHANGELOG.md'
5
+ var help = process.argv[2] === '-h' || process.argv[2] === '--help'
6
+
7
+ if (help) {
8
+ console.log('usage: changelog-parser [filename]')
9
+ process.exit(0)
10
+ }
11
+
12
+ parseChangelog(file, function (err, result) {
13
+ if (err) {
14
+ console.error(err)
15
+ process.exit(1)
16
+ }
17
+
18
+ console.log(JSON.stringify(result))
19
+ })
@@ -0,0 +1,201 @@
1
+ var EOL = '\n'
2
+ var lineReader = require('line-reader')
3
+ var removeMarkdown = require('remove-markdown')
4
+
5
+ // patterns
6
+ var semver = /\[?v?([\w\d.-]+\.[\w\d.-]+[a-zA-Z0-9])\]?/
7
+ var date = /.*[ ](\d\d?\d?\d?[-/.]\d\d?[-/.]\d\d?\d?\d?).*/
8
+ var subhead = /^###/
9
+ var listitem = /^[*-]/
10
+
11
+ var defaultOptions = { removeMarkdown: true }
12
+
13
+ /**
14
+ * Changelog parser.
15
+ *
16
+ * @param {string|object} options - changelog file string or options object containing file string
17
+ * @param {string} [options.filePath] - path to changelog file
18
+ * @param {string} [options.text] - changelog text (filePath alternative)
19
+ * @param {boolean} [options.removeMarkdown=true] - changelog file string to parse
20
+ * @param {function} [callback] - optional callback
21
+ * @returns {Promise<object>} - parsed changelog object
22
+ */
23
+ function parseChangelog (options, callback) {
24
+ if (typeof options === 'undefined') throw new Error('missing options argument')
25
+ if (typeof options === 'string') options = { filePath: options }
26
+ if (typeof options === 'object') {
27
+ var hasFilePath = typeof options.filePath !== 'undefined'
28
+ var hasText = typeof options.text !== 'undefined'
29
+ var invalidFilePath = typeof options.filePath !== 'string'
30
+ var invalidText = typeof options.text !== 'string'
31
+
32
+ if (!hasFilePath && !hasText) {
33
+ throw new Error('must provide filePath or text')
34
+ }
35
+
36
+ if (hasFilePath && invalidFilePath) {
37
+ throw new Error('invalid filePath, expected string')
38
+ }
39
+
40
+ if (hasText && invalidText) {
41
+ throw new Error('invalid text, expected string')
42
+ }
43
+ }
44
+
45
+ var opts = Object.assign({}, defaultOptions, options)
46
+ var changelog = parse(opts)
47
+
48
+ if (typeof callback === 'function') {
49
+ changelog
50
+ .then(function (log) { callback(null, log) })
51
+ .catch(function (err) { callback(err) })
52
+ }
53
+
54
+ // otherwise, invoke callback
55
+ return changelog
56
+ }
57
+
58
+ /**
59
+ * Internal parsing logic.
60
+ *
61
+ * @param {options} options - options object
62
+ * @param {string} [options.filePath] - path to changelog file
63
+ * @param {string} [options.text] - changelog text (filePath alternative)
64
+ * @param {boolean} [options.removeMarkdown] - remove markdown
65
+ * @returns {Promise<object>} - parsed changelog object
66
+ */
67
+ function parse (options) {
68
+ var filePath = options.filePath
69
+ var text = options.text
70
+ var data = {
71
+ log: { versions: [] },
72
+ current: null
73
+ }
74
+
75
+ // allow `handleLine` to mutate log/current data as `this`.
76
+ var cb = handleLine.bind(data, options)
77
+
78
+ return new Promise(function (resolve, reject) {
79
+ function done () {
80
+ // push last version into log
81
+ if (data.current) {
82
+ pushCurrent(data)
83
+ }
84
+
85
+ // clean up description
86
+ data.log.description = clean(data.log.description)
87
+ if (data.log.description === '') delete data.log.description
88
+
89
+ resolve(data.log)
90
+ }
91
+
92
+ if (text) {
93
+ text.split(/\r\n?|\n/mg).forEach(cb)
94
+ done()
95
+ } else {
96
+ lineReader.eachLine(filePath, cb, EOL).then(done)
97
+ }
98
+ })
99
+ }
100
+
101
+ /**
102
+ * Handles each line and mutates data object (bound to `this`) as needed.
103
+ *
104
+ * @param {object} options - options object
105
+ * @param {boolean} options.removeMarkdown - whether or not to remove markdown
106
+ * @param {string} line - line from changelog file
107
+ */
108
+ function handleLine (options, line) {
109
+ // skip line if it's a link label
110
+ if (line.match(/^\[[^[\]]*\] *?:/)) return
111
+
112
+ // set title if it's there
113
+ if (!this.log.title && line.match(/^# ?[^#]/)) {
114
+ this.log.title = line.substring(1).trim()
115
+ return
116
+ }
117
+
118
+ // new version found!
119
+ if (line.match(/^##? ?[^#]/)) {
120
+ if (this.current && this.current.title) pushCurrent(this)
121
+
122
+ this.current = versionFactory()
123
+
124
+ if (semver.exec(line)) this.current.version = semver.exec(line)[1]
125
+
126
+ this.current.title = line.substring(2).trim()
127
+
128
+ if (this.current.title && date.exec(this.current.title)) this.current.date = date.exec(this.current.title)[1]
129
+
130
+ return
131
+ }
132
+
133
+ // deal with body or description content
134
+ if (this.current) {
135
+ this.current.body += line + EOL
136
+
137
+ // handle case where current line is a 'subhead':
138
+ // - 'handleize' subhead.
139
+ // - add subhead to 'parsed' data if not already present.
140
+ if (subhead.exec(line)) {
141
+ var key = line.replace('###', '').trim()
142
+
143
+ if (!this.current.parsed[key]) {
144
+ this.current.parsed[key] = []
145
+ this.current._private.activeSubhead = key
146
+ }
147
+ }
148
+
149
+ // handle case where current line is a 'list item':
150
+ if (listitem.exec(line)) {
151
+ const log = options.removeMarkdown ? removeMarkdown(line) : line
152
+ // add line to 'catch all' array
153
+ this.current.parsed._.push(log)
154
+
155
+ // add line to 'active subhead' if applicable (eg. 'Added', 'Changed', etc.)
156
+ if (this.current._private.activeSubhead) {
157
+ this.current.parsed[this.current._private.activeSubhead].push(log)
158
+ }
159
+ }
160
+ } else {
161
+ this.log.description = (this.log.description || '') + line + EOL
162
+ }
163
+ }
164
+
165
+ function versionFactory () {
166
+ return {
167
+ version: null,
168
+ title: null,
169
+ date: null,
170
+ body: '',
171
+ parsed: {
172
+ _: []
173
+ },
174
+ _private: {
175
+ activeSubhead: null
176
+ }
177
+ }
178
+ }
179
+
180
+ function pushCurrent (data) {
181
+ // remove private properties
182
+ delete data.current._private
183
+
184
+ data.current.body = clean(data.current.body)
185
+ data.log.versions.push(data.current)
186
+ }
187
+
188
+ function clean (str) {
189
+ if (!str) return ''
190
+
191
+ // trim
192
+ str = str.trim()
193
+ // remove leading newlines
194
+ str = str.replace(new RegExp('[' + EOL + ']*'), '')
195
+ // remove trailing newlines
196
+ str = str.replace(new RegExp('[' + EOL + ']*$'), '')
197
+
198
+ return str
199
+ }
200
+
201
+ module.exports = parseChangelog