diff --git a/bin/cli.js b/bin/cli.js index a4ffb68..0d53443 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,8 +1,8 @@ #!/usr/bin/env node -var parseChangelog = require('..') -var file = process.argv[2] || 'CHANGELOG.md' -var help = process.argv[2] === '-h' || process.argv[2] === '--help' +const parseChangelog = require('..') +const file = process.argv[2] || 'CHANGELOG.md' +const help = process.argv[2] === '-h' || process.argv[2] === '--help' if (help) { console.log('usage: changelog-parser [filename]') diff --git a/index.js b/index.js index a14d61d..65c0dac 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,14 @@ -var EOL = require('os').EOL -var lineReader = require('line-reader') -var removeMarkdown = require('remove-markdown') +const EOL = require('os').EOL +const lineReader = require('line-reader') +const removeMarkdown = require('remove-markdown') // patterns -var semver = /\[?v?([\w\d.-]+\.[\w\d.-]+[a-zA-Z0-9])\]?/ -var date = /.*[ ](\d\d?\d?\d?[-/.]\d\d?[-/.]\d\d?\d?\d?).*/ -var subhead = /^###/ -var listitem = /^[*-]/ +const semver = /\[?v?([\w\d.-]+\.[\w\d.-]+[a-zA-Z0-9])\]?/ +const date = /.*[ ](\d\d?\d?\d?[-/.]\d\d?[-/.]\d\d?\d?\d?).*/ +const subhead = /^###/ +const listitem = /^[*-]/ -var defaultOptions = { removeMarkdown: true } +const defaultOptions = { removeMarkdown: true } /** * Changelog parser. @@ -24,10 +24,10 @@ function parseChangelog (options, callback) { if (typeof options === 'undefined') throw new Error('missing options argument') if (typeof options === 'string') options = { filePath: options } if (typeof options === 'object') { - var hasFilePath = typeof options.filePath !== 'undefined' - var hasText = typeof options.text !== 'undefined' - var invalidFilePath = typeof options.filePath !== 'string' - var invalidText = typeof options.text !== 'string' + const hasFilePath = typeof options.filePath !== 'undefined' + const hasText = typeof options.text !== 'undefined' + const invalidFilePath = typeof options.filePath !== 'string' + const invalidText = typeof options.text !== 'string' if (!hasFilePath && !hasText) { throw new Error('must provide filePath or text') @@ -42,8 +42,8 @@ function parseChangelog (options, callback) { } } - var opts = Object.assign({}, defaultOptions, options) - var changelog = parse(opts) + const opts = Object.assign({}, defaultOptions, options) + const changelog = parse(opts) if (typeof callback === 'function') { changelog @@ -65,15 +65,15 @@ function parseChangelog (options, callback) { * @returns {Promise} - parsed changelog object */ function parse (options) { - var filePath = options.filePath - var text = options.text - var data = { + const filePath = options.filePath + const text = options.text + const data = { log: { versions: [] }, current: null } // allow `handleLine` to mutate log/current data as `this`. - var cb = handleLine.bind(data, options) + const cb = handleLine.bind(data, options) return new Promise(function (resolve, reject) { function done () { @@ -138,7 +138,7 @@ function handleLine (options, line) { // - 'handleize' subhead. // - add subhead to 'parsed' data if not already present. if (subhead.exec(line)) { - var key = line.replace('###', '').trim() + const key = line.replace('###', '').trim() if (!this.current.parsed[key]) { this.current.parsed[key] = [] diff --git a/package.json b/package.json index 0c22df0..e1d2159 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,10 @@ "remove-markdown": "^0.2.2" }, "devDependencies": { - "gh-release": "^3.1.1", - "standard": "^10.0.2", - "tap-spec": "^4.1.1", - "tape": "^4.6.0" + "gh-release": "^6.0.1", + "standard": "^16.0.4", + "tap-spec": "^5.0.0", + "tape": "^5.5.2" }, "homepage": "https://github.com/hypermodules/changelog-parser", "keywords": [ diff --git a/test/fixtures/expected.js b/test/fixtures/expected.js index 85b84e2..dab1450 100644 --- a/test/fixtures/expected.js +++ b/test/fixtures/expected.js @@ -1,4 +1,4 @@ -var EOL = require('os').EOL +const EOL = require('os').EOL module.exports = { title: 'changelog title', @@ -7,7 +7,7 @@ module.exports = { { version: null, title: 'unreleased', - 'date': null, + date: null, body: '* foo', parsed: { _: [ @@ -18,7 +18,7 @@ module.exports = { { version: 'x.y.z', title: 'x.y.z - YYYY-MM-DD', - 'date': null, + date: null, body: '* bar', parsed: { _: [ @@ -29,7 +29,7 @@ module.exports = { { version: 'a.b.c', title: '[a.b.c]', - 'date': null, + date: null, body: '### Changes' + EOL + EOL + '* Update API' + EOL + '* Fix bug #1', parsed: { _: [ @@ -45,7 +45,7 @@ module.exports = { { version: '2.3.0', title: '2.3.0 - 2018-12-18', - 'date': '2018-12-18', + date: '2018-12-18', body: '### Added' + EOL + EOL + '- Some changelog generators such as [standard-version](https://github.com/conventional-changelog/standard-version) would produce H1s for major versions and H2s for minor versions. We want the parser to be able to parse both.', parsed: { _: [ @@ -59,7 +59,7 @@ module.exports = { { version: '2.2.3-pre.1', title: '2.2.3-pre.1 - 2013-02-14', - 'date': '2013-02-14', + date: '2013-02-14', body: '### Added' + EOL + '- Added an item.' + EOL + '* Added another item.' + EOL + EOL + '* Update API', parsed: { _: [ @@ -77,7 +77,7 @@ module.exports = { { version: '2.0.0-x.7.z.92', title: '2.0.0-x.7.z.92 - 2013-02-14', - 'date': '2013-02-14', + date: '2013-02-14', body: '* bark bark' + EOL + '* woof' + EOL + '* arf', parsed: { _: [ @@ -90,7 +90,7 @@ module.exports = { { version: '1.3.0', title: 'v1.3.0', - 'date': null, + date: null, body: '* make it so', parsed: { _: [ @@ -101,7 +101,7 @@ module.exports = { { version: '1.2.3', title: '[1.2.3](link)', - 'date': null, + date: null, body: '* init', parsed: { _: [ diff --git a/test/fixtures/remove-markdown-expected.js b/test/fixtures/remove-markdown-expected.js index 618c93f..21e5a56 100644 --- a/test/fixtures/remove-markdown-expected.js +++ b/test/fixtures/remove-markdown-expected.js @@ -1,4 +1,4 @@ -var EOL = require('os').EOL +const EOL = require('os').EOL module.exports = { title: 'changelog title', @@ -7,7 +7,7 @@ module.exports = { { version: null, title: 'unreleased', - 'date': null, + date: null, body: '* foo', parsed: { _: [ @@ -18,7 +18,7 @@ module.exports = { { version: 'x.y.z', title: 'x.y.z - YYYY-MM-DD', - 'date': null, + date: null, body: '* bar', parsed: { _: [ @@ -29,7 +29,7 @@ module.exports = { { version: 'a.b.c', title: '[a.b.c]', - 'date': null, + date: null, body: '### Changes' + EOL + EOL + '* Update API' + EOL + '* Fix bug #1', parsed: { _: [ @@ -45,7 +45,7 @@ module.exports = { { version: '2.3.0', title: '2.3.0 - 2018-12-18', - 'date': '2018-12-18', + date: '2018-12-18', body: '### Added' + EOL + EOL + '- Some changelog generators such as [standard-version](https://github.com/conventional-changelog/standard-version) would produce H1s for major versions and H2s for minor versions. We want the parser to be able to parse both.', parsed: { _: [ @@ -59,7 +59,7 @@ module.exports = { { version: '2.2.3-pre.1', title: '2.2.3-pre.1 - 2013-02-14', - 'date': '2013-02-14', + date: '2013-02-14', body: '### Added' + EOL + '- Added an item.' + EOL + '* Added another item.' + EOL + EOL + '* Update API', parsed: { _: [ @@ -77,7 +77,7 @@ module.exports = { { version: '2.0.0-x.7.z.92', title: '2.0.0-x.7.z.92 - 2013-02-14', - 'date': '2013-02-14', + date: '2013-02-14', body: '* bark bark' + EOL + '* woof' + EOL + '* arf', parsed: { _: [ @@ -90,7 +90,7 @@ module.exports = { { version: '1.3.0', title: 'v1.3.0', - 'date': null, + date: null, body: '* make it so', parsed: { _: [ @@ -101,7 +101,7 @@ module.exports = { { version: '1.2.3', title: '[1.2.3](link)', - 'date': null, + date: null, body: '* init', parsed: { _: [ diff --git a/test/index.js b/test/index.js index 53ab4c2..ba0f688 100644 --- a/test/index.js +++ b/test/index.js @@ -1,17 +1,17 @@ -var parseChangelog = require('..') -var test = require('tape') -var path = require('path') -var fs = require('fs') -var expected = require('./fixtures/expected') -var removeMarkdownExpected = require('./fixtures/remove-markdown-expected') -var filePath = path.join(__dirname, 'fixtures', 'CHANGELOG.md') +const parseChangelog = require('..') +const test = require('tape') +const path = require('path') +const fs = require('fs') +const expected = require('./fixtures/expected') +const removeMarkdownExpected = require('./fixtures/remove-markdown-expected') +const filePath = path.join(__dirname, 'fixtures', 'CHANGELOG.md') test('throws on bad params', function (t) { t.plan(3) - var missing = 'must provide filePath or text' - var invalidPath = 'invalid filePath, expected string' - var invalidText = 'invalid text, expected string' + const missing = 'must provide filePath or text' + const invalidPath = 'invalid filePath, expected string' + const invalidText = 'invalid text, expected string' t.throws(parseChangelog, missing, missing) t.throws(function () { @@ -36,7 +36,7 @@ test('parses example changelog', function (t) { test('parses example changelog as text', function (t) { t.plan(1) - parseChangelog({text: fs.readFileSync(filePath, 'utf8')}, function (err, result) { + parseChangelog({ text: fs.readFileSync(filePath, 'utf8') }, function (err, result) { if (err) throw err t.deepEqual(result, expected) @@ -47,7 +47,7 @@ test('parses example changelog as text', function (t) { test('returns a Promise when invoked without a valid `callback`', function (t) { t.plan(2) - var result = parseChangelog(filePath) + const result = parseChangelog(filePath) t.true(typeof result === 'object') t.true(result instanceof Promise) @@ -69,11 +69,11 @@ test('callback and Promise methods should yield identical values', function (t) if (err) t.fail() parseChangelog(filePath) - .then(function (resultB) { - t.deepEqual(resultA, resultB) - t.end() - }) - .catch(t.fail) + .then(function (resultB) { + t.deepEqual(resultA, resultB) + t.end() + }) + .catch(t.fail) }) }) @@ -91,7 +91,7 @@ test('accepts object as first argument', function (t) { test('accepts { removeMardown: false } option', function (t) { t.plan(1) - var options = { + const options = { filePath: filePath, removeMarkdown: false }