Skip to content
Merged
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
30 changes: 29 additions & 1 deletion bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,39 @@
const editor = require('editor');
const changes = require('..');

const argv = require('minimist')(process.argv.slice(2), {
alias: {
file: 'f',
help: 'h'
}
});
/* eslint-disable max-len */
const HELP_TEXT = `usage: changes [--file] [--help]

Options are ...
-f, --file [FILENAME] Specify the name of the changelog file. Defaults to CHANGES.md.
-h, --help Display this help message.
`;
/* eslint-enable */

if (argv.h || argv.help) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you know that minimist has an alias option?

console.log(HELP_TEXT);
process.exit();
}

let file = argv.file;

if (file) {
changes.setFile(file);
} else {
file = changes.getFile();
}

// Write the commit history to the changes file
const previous = changes.write();

// Let the user edit the changes
editor('CHANGES.md', (code) => {
editor(file, (code) => {
if (code === 0) {
// Add the changes file to git
changes.add(previous);
Expand Down
12 changes: 11 additions & 1 deletion lib/changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
const fs = require('fs');
const $ = require('child_process');

const CHANGES_FILE = 'CHANGES.md';
const CHANGES_HEADING = '# Changes';
let CHANGES_FILE = 'CHANGES.md';

function exists(changes, version) {
const escaped_version = version.replace(/([\.\-])/g, '\\$1');
Expand Down Expand Up @@ -101,3 +101,13 @@ exports.add = function (previous) {
exports.abort(previous);
}
};

// Get file to write changelog
exports.getFile = function () {
return CHANGES_FILE;
};

// Set file to write changelog
exports.setFile = function (file) {
CHANGES_FILE = file;
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
}
},
"dependencies": {
"editor": "^1.0.0"
"editor": "^1.0.0",
"minimist": "^1.2.0"
},
"devDependencies": {
"@studio/eslint-config": "^1.0.0",
Expand Down
19 changes: 19 additions & 0 deletions test/changes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ describe('changes', () => {
$.execSync.returns(log);
}

it('defaults changes file to CHANGES.md', () => {
assert.equal(changes.getFile(), 'CHANGES.md');
});

it('can set changes file to custom name', () => {
changes.setFile('foo.txt');

assert.equal(changes.getFile(), 'foo.txt');

missingChanges();
setLog('foo');

changes.write();

sinon.assert.calledWith(fs.writeFileSync, 'foo.txt');

changes.setFile('CHANGES.md'); // reset state
});

it('generates new changes file', () => {
missingChanges();
setLog('» Inception (That Dude)\n\n\n\n');
Expand Down