Skip to content
Closed
Show file tree
Hide file tree
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
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,26 @@ With this example, for each release, a `docs/CHANGELOG.md` will be created or up

### Options

| Options | Description | Default |
| ---------------- | ----------------------------------------------------- | -------------- |
| `changelogFile` | File path of the changelog. | `CHANGELOG.md` |
| `changelogTitle` | Title of the changelog file (first line of the file). | - |
| Options | Description | Default |
| ---------------- | ----------------------------------------------------------------- | -------------- |
| `changelogFile` | File path of the changelog. See [changelogFile](#changelogFile). | `CHANGELOG.md` |
| `changelogTitle` | Title of the changelog file (first line of the file). | - |

#### `changelogFile`

The path to the changelog is generated with [Lodash template](https://lodash.com/docs#template). The following variables are available:

| Parameter | Description |
|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| `branch` | The branch from which the release is done. |
| `branch.name` | The branch name. |
| `branch.type` | The [type of branch](https://github.com/semantic-release/semantic-release/blob/beta/docs/usage/workflow-configuration.md#branch-types). |
| `branch.channel` | The distribution channel on which to publish releases from this branch. |
| `branch.range` | The range of [semantic versions](https://semver.org) to support on this branch. |
| `branch.prerelease` | The pre-release detonation to append to [semantic versions](https://semver.org) released from this branch. |
| `lastRelease` | `Object` with `version`, `gitTag` and `gitHead` of the last release. |
| `nextRelease` | `Object` with `version`, `gitTag`, `gitHead` and `notes` of the release being done. |


### Examples

Expand Down
7 changes: 5 additions & 2 deletions lib/prepare.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const path = require('path');
const {readFile, writeFile, ensureFile} = require('fs-extra');
const resolveConfig = require('./resolve-config');
const {template} = require('lodash');

module.exports = async (pluginConfig, {cwd, nextRelease: {notes}, logger}) => {
module.exports = async (pluginConfig, {cwd, nextRelease, lastRelease, branch, logger}) => {
const {notes} = nextRelease;
const {changelogFile, changelogTitle} = resolveConfig(pluginConfig);
const changelogPath = path.resolve(cwd, changelogFile);
const parsedChangelogFile = template(changelogFile)({branch, lastRelease, nextRelease});
const changelogPath = path.resolve(cwd, parsedChangelogFile);

if (notes) {
await ensureFile(changelogPath);
Expand Down
142 changes: 71 additions & 71 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"prettier": true,
"space": true,
"rules": {
"unicorn/string-content": "off"
"unicorn/string-content": "off",
"no-template-curly-in-string": "off"
}
},
"renovate": {
Expand Down
15 changes: 15 additions & 0 deletions test/prepare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ test('Create new changelog with custom path', async t => {
t.deepEqual(t.context.log.args[0], ['Create %s', changelogPath]);
});

test('Create new changelog with templated path', async t => {
const cwd = tempy.directory();
const notes = 'Test release note';
// New file is based on current branch
const changelogFile = '${branch.name}.txt';
const changelogPath = path.resolve(cwd, 'master.txt');

await prepare({changelogFile}, {cwd, nextRelease: {notes}, logger: t.context.logger, branch: {name: 'master'}});

// Verify the content of the CHANGELOG.md
t.is((await readFile(changelogPath)).toString(), `${notes}\n`);

t.deepEqual(t.context.log.args[0], ['Create %s', changelogPath]);
});

test('Prepend the CHANGELOG.md if there is an existing one', async t => {
const cwd = tempy.directory();
const notes = 'Test release note';
Expand Down