-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(sub-directory): add -s, --sub-directory
option
#32
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing, @altJake! Sorry for the delay in the review, but hopefully we can get this merged soon. I left some comments, but if you have any questions, feel free to ask!
lib/file.js
Outdated
|
||
file = Path.normalize(file); | ||
|
||
if (Path.dirname(file) === '.') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not replying on the issue earlier, but I think the desired behavior of how -f
and -s
will work together will be to always have it be relative from the subdirectory. I think that will give the most options for where the file should go. For example, in the current implementation, I'm not sure there's any way to write the file to root directory of the repo (I tried CHANGELOG.md
, ../CHANGELOG.md
, ./../CHANGELOG.md
).
And since this is a completely new feature, we don't have to worry about backwards compatibility as long as we don't affect the current functionality. So we should pick what makes the most sense and provides the greatest control.
lib/file.js
Outdated
* @returns {Promise} | ||
*/ | ||
exports.normalizeFilePath = function (file, subDirectory) { | ||
return Bluebird.resolve() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like anything in this function is actually asynchronous so you don't have to make it return a promise. It should make the implementation a bit simpler.
lib/file.js
Outdated
@@ -2,6 +2,7 @@ | |||
|
|||
var Bluebird = require('bluebird'); | |||
var Fs = Bluebird.promisifyAll(require('fs')); | |||
var Path = Bluebird.promisifyAll(require('path')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not using any async functions in path
so we don't have to promisify it.
lib/git.js
Outdated
@@ -33,8 +33,14 @@ exports.getCommits = function (options) { | |||
revisions = tag ? tag + '..HEAD' : ''; | |||
} | |||
|
|||
var gitLogCommand = 'git log -E --format=' + FORMAT + ' ' + revisions; | |||
|
|||
if (options.subDirectory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like if you do git log -- .
, it behaves the same way as git log
, so it might simplify the logic if you make the default value of subDirectory
.
in lib/cli.js
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The combination of using default value for 'subDirectory' and discarding all the explicit path handling - make this PR way simpler 😅
Liked it way better though 👍
test/file.test.js
Outdated
@@ -7,6 +7,7 @@ var Sinon = require('sinon'); | |||
|
|||
var File = require('../lib/file'); | |||
|
|||
var DEFAULT_FILE = './CHANGELOG.md'; | |||
var NONEXISTENT = Path.resolve(__dirname, '../fake-file.txt'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you align the equal signs within this block of var
s?
lib/cli.js
Outdated
@@ -17,4 +17,5 @@ module.exports = CLI | |||
.option('-t, --tag <range>', 'generate from specific tag or range (e.g. v1.2.3 or v1.2.3..v1.2.4)') | |||
.option('-x, --exclude <types>', 'exclude selected commit types (comma separated)', list) | |||
.option('-f, --file [file]', 'file to write to, defaults to ./CHANGELOG.md, use - for stdout', './CHANGELOG.md') | |||
.option('-u, --repo-url [url]', 'specify the repo URL for commit links, defaults to checking the package.json'); | |||
.option('-u, --repo-url [url]', 'specify the repo URL for commit links, defaults to checking the package.json') | |||
.option('-s, --sub-directory <path>', 'specify an explicit relatvie path to a sub-directory'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make the description specify a path to be passed into git log
? And then maybe add a subsection within ## Usage
in the README titled ### Sub-directory
under ### Recommended
to explain the nuances with how --file
is relative from --sub-directory
since it is a bit nuanced?
README.md
Outdated
@@ -62,6 +62,7 @@ $ changelog -h | |||
-x, --exclude <types> exclude selected commit types (comma separated) | |||
-f, --file [file] file to write to, defaults to ./CHANGELOG.md, use - for stdout | |||
-u, --repo-url [url] specify the repo URL for commit links, defaults to checking the package.json | |||
-s, --sub-directory <path> specify an explicit relatvie path to a sub-directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the alignment here is also a bit off. Can you generate the help and just replace the whole help text to make sure it's exactly as it would be outputted?
- update ouput of help command - add section to clarify sub-directory flag's usage nuances
Hope it looks better and cleaner now. |
Hi @robinjoseph08 ! Just bump it, probably has been forgotten (also by me) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @altJake! Yeah, looks like it slipped through the cracks, sorry again about that.
It's all looking really good, the last thing we need to make sure we account for is when using --sub-directory
and --file -
at the same time. Should be easy enough to fix by deferring the joining of the sub-directory and the file paths.
Let me know if you have any questions! Thanks again for your help!
|
||
var CLI = require('../lib/cli'); | ||
var Changelog = require('../lib'); | ||
var File = require('../lib/file'); | ||
|
||
CLI.parse(process.argv); | ||
|
||
var filePath = Path.join(CLI.subDirectory, CLI.file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm not sure if we can join the paths together here since some people might be passing in -
for stdout. We might need to pass CLI.subDirectory
through to the two functions. We also should probably be checking for -
explicitly in File.readIfExists
, but you don't have to do that in this PR.
@altJake bump! |
1 similar comment
@altJake bump! |
Hey @altJake, I'll be closing this PR as there hasn't been any activity for a while. If you want to revisit this issue in the future feel free to comment and we can re-open this PR. |
Add an option to generate a changelog for a specific sub-directory in the repository, using the
git log -- <path>
command ability.Also add a reconciling/normalizing of the input/output file path to handle the read/write in a sub-directory, when it is given.
closes #13