-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathversion.js
30 lines (25 loc) · 935 Bytes
/
version.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'use strict'
const fsp = require('node:fs/promises')
const ospath = require('node:path')
const PROJECT_ROOT_DIR = ospath.join(__dirname, '..')
const CHANGELOG_FILE = ospath.join(PROJECT_ROOT_DIR, 'CHANGELOG.adoc')
const VERSION = process.env.npm_package_version
function getCurrentDate () {
const now = new Date()
return new Date(now.getTime() - now.getTimezoneOffset() * 60000)
}
function updateChangelog (releaseDate) {
return fsp.readFile(CHANGELOG_FILE, 'utf8').then((changelog) =>
fsp.writeFile(
CHANGELOG_FILE,
changelog.replace(/^== (?:(Unreleased)|\d.*)$/m, (currentLine, replace) => {
const newLine = `== ${VERSION} (${releaseDate})`
return replace ? newLine : [newLine, '_No changes since previous release._', currentLine].join('\n\n')
})
)
)
}
;(async () => {
const releaseDate = getCurrentDate().toISOString().split('T')[0]
await updateChangelog(releaseDate)
})()