chore: add prettier

This commit is contained in:
Federico Grandi
2020-11-29 17:51:26 +01:00
parent 3ed8463058
commit 3140d34146
8 changed files with 290 additions and 154 deletions

View File

@@ -2,7 +2,7 @@ import fs from 'fs'
import path from 'path'
const currentVersion = require('../package.json').version
if (!currentVersion) throw new Error('Cant\'t detect library version.')
if (!currentVersion) throw new Error("Cant't detect library version.")
const changelogPath = path.resolve(__dirname, '../CHANGELOG.md')
const changelog = fs.readFileSync(changelogPath, { encoding: 'utf-8' })
@@ -12,7 +12,8 @@ let futureChangelog = ''
// Add version section
let arr = changelog.split('## [Unreleased]')
arr[1] = `
arr[1] =
`
## [${currentVersion}] - ${new Date().toISOString().slice(0, 10)}
### Removed:
@@ -28,13 +29,15 @@ futureChangelog = arr.join('## [Unreleased]')
// Update footer
arr = futureChangelog
.split('\n')
.map(line => line.startsWith('[Unreleased]')
? `[Unreleased]: https://github.com/EndBug/add-and-commit/compare/v${currentVersion}...HEAD`
: line)
.map((line) =>
line.startsWith('[Unreleased]')
? `[Unreleased]: https://github.com/EndBug/add-and-commit/compare/v${currentVersion}...HEAD`
: line
)
// eslint-disable-next-line no-useless-escape
const lastVersion = ([...arr].reverse()[1]?.match(/\[([^\][]*)]/) || [])[0].replace(/[\[\]']+/g, '')
if (!lastVersion) throw new Error('Can\'t find last version in changelog.')
const lastVersion = ([...arr].reverse()[1]?.match(/\[([^\][]*)]/) ||
[])[0].replace(/[\[\]']+/g, '') // eslint-disable-line no-useless-escape
if (!lastVersion) throw new Error("Can't find last version in changelog.")
const lastLine = `[${currentVersion}]: https://github.com/EndBug/add-and-commit/compare/v${lastVersion}...v${currentVersion}`
if (arr[arr.length - 1] === '') arr[arr.length - 1] = lastLine