Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support page header setting of changelog file #18

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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