Skip to content

Commit dec07e4

Browse files
committed
chore(release): enforce CHANGELOG entry via preversion script
1 parent 54af4ea commit dec07e4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dev": "tsc --watch",
1313
"start": "node dist/cli.js",
1414
"test": "jest",
15+
"preversion": "node scripts/check-changelog.js",
1516
"test:watch": "jest --watch",
1617
"lint": "eslint 'src/**/*.ts'",
1718
"lint:fix": "eslint 'src/**/*.ts' --fix",

scripts/check-changelog.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env node
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
function fail(msg) {
6+
console.error(`❌ CHANGELOG check failed: ${msg}`);
7+
process.exit(1);
8+
}
9+
10+
try {
11+
const pkgPath = path.join(process.cwd(), 'package.json');
12+
const changelogPath = path.join(process.cwd(), 'CHANGELOG.md');
13+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
14+
const version = pkg.version;
15+
const changelog = fs.readFileSync(changelogPath, 'utf-8');
16+
const header = new RegExp(`^##\\s+${version}\\s+—`, 'm');
17+
if (!header.test(changelog)) {
18+
fail(`CHANGELOG.md does not contain a header for version ${version}`);
19+
}
20+
console.log(`✓ CHANGELOG contains entry for ${version}`);
21+
} catch (e) {
22+
fail(e && e.message ? e.message : String(e));
23+
}
24+
25+

0 commit comments

Comments
 (0)