Skip to content

Commit

Permalink
feat: add date to CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
aotarola committed Mar 13, 2020
1 parent df01025 commit 4d56023
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/steps/version-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ function commit(cwd, message) {
});
}

function getCurrentDate() {
return new Date().toISOString().substring(0, 10);
}

function getHEAD(cwd) {
return run('git', ['rev-parse', 'HEAD'], {
cwd,
Expand Down Expand Up @@ -99,7 +103,9 @@ function createVersionCommit(cwd, pkg, options) {
changeLogContent = '';
}

changeLogContent = `### ${options.nextVersion}\n\n${options.changelog}${changeLogContent}`;
changeLogContent = `### ${options.nextVersion} - ${getCurrentDate()}\n\n${
options.changelog
}${changeLogContent}`;
fs.writeFileSync(changeLogFile, `${changeLogContent.trim()}\n`);
const packageJsonFile = path.join(cwd, 'package.json');
pkg.version = options.nextVersion;
Expand Down
12 changes: 12 additions & 0 deletions test/steps/version-commit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('createVersionCommit', () => {
afterEach(resetVars);
describe('with no package-lock.json', () => {
const dirname = withFixture('multiple-commits');
let currentDate;
before('commits with the original author', done => {
execFile(
'git',
Expand All @@ -83,12 +84,23 @@ describe('createVersionCommit', () => {
);
});
before('create version commit', () => {
currentDate = new Date().toISOString().substring(0, 10);
return createVersionCommit(dirname, pkg, options);
});
it('writes the correct HEAD sha', () => {
const HEAD = fs.readFileSync(`${dirname}/.git/refs/heads/master`, 'utf8');
assert.equal(HEAD.trim(), options.versionCommitSha);
});

it('writes the correct CHANGELOG', () => {
const [version, , commit1, commit2] = fs
.readFileSync(`${dirname}/CHANGELOG.md`, 'utf8')
.split('\n');
assert.equal(`### 1.0.0 - ${currentDate}`, version);
assert.equal('* New stuff', commit1);
assert.equal('* Interesting features', commit2);
});

it('commits with the proper user', done => {
execFile(
'git',
Expand Down

0 comments on commit 4d56023

Please sign in to comment.