changelog-version
Version:
Build tool to update CHANGELOG.md file with the version
22 lines (14 loc) • 620 B
JavaScript
const fs = require('fs')
const path = require('path')
const regexp = /(\n+)(?!<!--)(\n)(## )(\[UNRELEASED])/gi
const date = new Date().toISOString().replace(/T.*/, '')
const changelogVersion = function (changelogPath) {
const pkgInfo = require(path.join(process.cwd(), 'package.json'))
const version = 'v' + pkgInfo.version
changelogPath = changelogPath || path.join(process.cwd(), 'CHANGELOG.md')
let data = fs.readFileSync(changelogPath, 'utf8')
data = data.replace(regexp, `$1$2$3${version} - ${date}`)
fs.writeFileSync(changelogPath, data, 'utf8')
}
module.exports = changelogVersion