Skip to content

Commit

Permalink
Merge branch 'master' into feature/es-modules
Browse files Browse the repository at this point in the history
# Conflicts:
#	index.js
#	package.json
#	test.js
  • Loading branch information
webpro committed Apr 18, 2022
2 parents f47d2d6 + 464435f commit 44629ed
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 8 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ Default value: `undefined`
- When `infile` is not set, the changelog generated by this plugin will still be used as release notes for e.g.
[GitHub Releases](https://github.com/release-it/release-it/blob/master/docs/github-releases.md).

### `header`

Set the main header for the changelog document:

```json
{
"plugins": {
"@release-it/conventional-changelog": {
"infile": "CHANGELOG.md",
"header": "# Changelog",
"preset": {
"name": "conventionalcommits"
}
}
}
}
```

### `ignoreRecommendedBump`

Default value: `false`
Expand Down Expand Up @@ -172,6 +190,25 @@ For example, you can use the following option to group the commits by 'scope' in
}
```

If you want to customize the templates used to write the changelog, you can do it like in a `.release-it.js` file like
so:

```js
const fs = require('fs');

const commitTemplate = fs.readFileSync('commit.hbs').toString();

module.exports = {
plugins: {
'@release-it/conventional-changelog': {
writerOpts: {
commitPartial: commitTemplate
}
}
}
};
```

## GitHub Actions

When using this plugin in a GitHub Action, make sure to set
Expand Down
31 changes: 27 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import conventionalRecommendedBump from 'conventional-recommended-bump';
import conventionalChangelog from 'conventional-changelog';
import semver from 'semver';
import concat from 'concat-stream';
import prependFile from 'prepend-file';

class ConventionalChangelog extends Plugin {
static disablePlugin(options) {
Expand Down Expand Up @@ -73,7 +72,7 @@ class ConventionalChangelog extends Plugin {
const options = Object.assign({}, { releaseCount }, this.options);
const { context, gitRawCommitsOpts, parserOpts, writerOpts, ..._o } = options;
const _c = Object.assign({ version, previousTag, currentTag }, context);
const _r = Object.assign({ debug }, gitRawCommitsOpts);
const _r = Object.assign({ debug, from: previousTag }, gitRawCommitsOpts);
this.debug('conventionalChangelog', { options: _o, context: _c, gitRawCommitsOpts: _r, parserOpts, writerOpts });
return conventionalChangelog(_o, _c, _r, parserOpts, writerOpts);
}
Expand All @@ -87,9 +86,20 @@ class ConventionalChangelog extends Plugin {
});
}

async writeChangelog() {
getPreviousChangelog() {
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: _header = '' } = this.options;
let { changelog } = this.config.getContext();
const header = _header.split(/\r\n|\r|\n/g).join(EOL);

let hasInfile = false;
try {
Expand All @@ -99,12 +109,25 @@ class ConventionalChangelog extends Plugin {
this.debug(err);
}

let previousChangelog = '';
try {
previousChangelog = await this.getPreviousChangelog();
previousChangelog = previousChangelog.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 +
(changelog ? EOL + EOL + changelog.trim() : '') +
(previousChangelog ? EOL + EOL + previousChangelog.trim() : '')
);

if (!hasInfile) {
await this.exec(`git add ${infile}`);
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@
},
"dependencies": {
"concat-stream": "^2.0.0",
"conventional-changelog": "^3.1.24",
"conventional-recommended-bump": "^6.1.0",
"prepend-file": "^2.0.1"
"conventional-changelog": "^3.1.25",
"conventional-recommended-bump": "^6.1.0"
},
"devDependencies": {
"bron": "^2.0.2",
"release-it": "^15.0.0-esm.4",
"shelljs": "^0.8.5",
"sinon": "^12.0.1",
"sinon": "^13.0.2",
"tmp": "^0.2.1"
},
"peerDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import runTasks from 'release-it';

sh.config.silent = true;

try {
fs.unlinkSync('CHANGES.md');
} catch (error) {}

const noop = () => {};
const log = {
log: noop,
Expand Down

0 comments on commit 44629ed

Please sign in to comment.