const fs = require("fs"); const changelogText = fs.readFileSync("CHANGELOG.md", "utf8"); const pkg = JSON.parse(fs.readFileSync("package.json", "utf8")); const changelogLines = changelogText.split("\n"); for (const line of changelogLines) { if (line.startsWith(`## [${pkg.version}]`)) { const re = new RegExp(`## \\[${pkg.version}\\] - \\d{4}-\\d{2}-\\d{2}`); const isMatch = re.test(line); if (isMatch) { process.exit(0); } else { console.error( `Found entry for version v${pkg.version}, ` + `but it must be on format: ## [${pkg.version}] - YYYY-MM-DD` ); } } } console.error( `Could not find a changelog entry for version v${pkg.version} in CHANGELOG.md` ); process.exit(1);