-
Notifications
You must be signed in to change notification settings - Fork 1
/
version-extract.js
41 lines (34 loc) · 1.16 KB
/
version-extract.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
31
32
33
34
35
36
37
38
39
40
41
const fs = require('fs');
const { Plugin } = require('release-it');
class VersionExtracter extends Plugin {
static disablePlugin() {
return 'version';
}
static isEnabled() {
return true;
}
init() {
this.changelogFile = fs.readFileSync('CHANGELOG.md', "utf-8");
const versionRegex = /.*?\[(.*?)\]/
const dateRegex = /\([\d-]+\)/
this.version = this.changelogFile.match(versionRegex)[1];
const oldDate = this.changelogFile.match(dateRegex)[0];
this.changelogFile = this.changelogFile.replace(oldDate, "("+new Date().toISOString().substring(0, 10)+")");
const start = this.changelogFile.indexOf("## [" + this.version)
const stop = this.changelogFile.indexOf("\n## ", start)
this.changelog = this.changelogFile.substring(start, stop);
}
getIncrementedVersion() {
return this.version;
}
getChangelog() {
return this.changelog;
}
beforeRelease() {
const { isDryRun } = this.global;
if (!isDryRun) {
fs.writeFileSync('CHANGELOG.md', this.changelogFile);
}
}
}
module.exports = VersionExtracter;