Skip to content

Commit

Permalink
Support page header setting of changelog file
Browse files Browse the repository at this point in the history
It is the same as the conventional-changelog-config-spec setting of standard-version.
  • Loading branch information
lpreterite committed Apr 26, 2021
1 parent a9364e5 commit fb62fa4
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,18 @@ class ConventionalChangelog extends Plugin {
});
}

async writeChangelog() {
getOldChangelog() {
const { infile } = this.options;
return new Promise((resolve, reject) => {
const readStream = fs.createReadStream(infile);
const resolver = result => resolve(result.toString().trim());
readStream.pipe(concat(resolver));
readStream.on('error', reject);
});
}

async writeChangelog() {
const { infile, header } = this.options;
let { changelog } = this.config.getContext();

let hasInfile = false;
Expand All @@ -95,12 +105,20 @@ class ConventionalChangelog extends Plugin {
this.debug(err);
}

let oldChangelog = ""
try{
oldChangelog = await this.getOldChangelog();
oldChangelog = oldChangelog.replace(new RegExp(EOL, 'g'), '\n').replace(header, '');
}catch(err){
this.debug(err);
}

if (!hasInfile) {
changelog = await this.generateChangelog({ releaseCount: 0 });
this.debug({ changelog });
}

await prependFile(infile, changelog + EOL + EOL);
fs.writeFileSync(infile, header + EOL + EOL + changelog + EOL + EOL + oldChangelog);

if (!hasInfile) {
await this.exec(`git add ${infile}`);
Expand Down

0 comments on commit fb62fa4

Please sign in to comment.