Skip to content

Commit

Permalink
Merge pull request #47 from rwjblue/always-emit-something
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue authored Apr 27, 2020
2 parents adb8be2 + 1d52bd4 commit 68dd9ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ const LERNA_PATH = require.resolve('lerna-changelog/bin/cli');
// and this makes it much simpler
const UNRELEASED = 'Unreleased';

function getToday() {
const date = new Date().toISOString();

return date.slice(0, date.indexOf('T'));
}

module.exports = class LernaChangelogGeneratorPlugin extends Plugin {
async init() {
let from = (await this.getTagForHEAD()) || (await this.getFirstCommit());
Expand Down Expand Up @@ -63,8 +69,11 @@ module.exports = class LernaChangelogGeneratorPlugin extends Plugin {
return changelog;
}

async processChangelog(_changelog) {
let changelog = _changelog.replace(UNRELEASED, this.nextVersion);
async processChangelog() {
// this is populated in `init`
let changelog = this.changelog
? this.changelog.replace(UNRELEASED, this.nextVersion)
: `## ${this.nextVersion} (${getToday()})`;

let finalChangelog = await this.reviewChangelog(changelog);

Expand Down Expand Up @@ -159,9 +168,7 @@ module.exports = class LernaChangelogGeneratorPlugin extends Plugin {
}

async beforeRelease() {
// this is populated in `init`
let changelog = this.changelog || '';
let processedChangelog = await this.processChangelog(changelog);
let processedChangelog = await this.processChangelog();

this.debug({ changelog: processedChangelog });

Expand Down
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ test('it sets the changelog without version information onto the config', async
t.is(changelog, 'The changelog');
});

test('it prints something to CHANGELOG.md when lerna-changelog returns no content', async (t) => {
let infile = tmp.fileSync().name;
let plugin = buildPlugin({ infile });

plugin.responses[`${LERNA_PATH} --next-version=Unreleased --from=v1.0.0`] = '';

await runTasks(plugin);

const changelog = fs.readFileSync(infile, { encoding: 'utf8' });
t.is(changelog, `## 1.0.1 (${new Date().toISOString().slice(0, 10)})\n\n`);
});

test('it uses the first commit when no tags exist', async (t) => {
let infile = tmp.fileSync().name;

Expand Down

0 comments on commit 68dd9ca

Please sign in to comment.