Skip to content

Commit a8c4a59

Browse files
authored
Merge pull request #42 from whyboris/ignore-files-flag
Ignore files command line flag
2 parents 9fa3f59 + 0da4a9e commit a8c4a59

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ Usage: diff2html [options] -- [diff args]
7171
| -o | --output | Output destination | `preview`, `stdout` | `preview` |
7272
| -u | --diffy | Upload to diffy.org | `browser`, `pbcopy`, `print` | |
7373
| -F | --file | Send output to file (overrides output option) | _[string]_ | |
74-
| --version | | Show version number | | |
74+
| --ig | --ignore | Ignore particular files from the diff | _[string]_ | |
75+
| -v | --version | | Show version number | | |
7576
| -h | --help | Show help | | |
7677

7778
Examples:
@@ -99,6 +100,8 @@ Examples:
99100
- `//diff2html-synchronisedScroll` - writes code to support selected scroll interaction, must be within a `<script>` block
100101
- `<!--diff2html-diff-->` - writes diff content to page
101102

103+
`diff2htal --ig package-lock.json --ig yarn.lock`
104+
- Ignore `package-lock.json` and `yarn.lock` from the generated diff
102105

103106
_NOTE_: notice the `--` in the examples
104107

@@ -108,6 +111,10 @@ This is a developer friendly project, all the contributions are welcome.
108111
To contribute just send a pull request with your changes following the guidelines described in `CONTRIBUTING.md`.
109112
I will try to review them as soon as possible.
110113

114+
## Developing
115+
116+
Make some changes and then `node src/main.js` 😉
117+
111118
## License
112119

113120
Copyright 2014-2019 Rodrigo Fernandes. Released under the terms of the MIT license.

src/cli.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Input
2727
*/
2828

29-
Diff2HtmlInterface.prototype.getInput = function getInput(inputType, inputArgs, callback) {
29+
Diff2HtmlInterface.prototype.getInput = function getInput(inputType, inputArgs, ignore, callback) {
3030
var that = this;
3131
switch (inputType) {
3232
case 'file':
@@ -38,12 +38,13 @@
3838
break;
3939

4040
default:
41-
that._runGitDiff(inputArgs, callback);
41+
that._runGitDiff(inputArgs, ignore, callback);
4242
}
4343
};
4444

45-
Diff2HtmlInterface.prototype._runGitDiff = function(gitArgsArr, callback) {
45+
Diff2HtmlInterface.prototype._runGitDiff = function(gitArgsArr, ignore, callback) {
4646
var gitArgs;
47+
4748
if (gitArgsArr.length && gitArgsArr[0]) {
4849
gitArgs = gitArgsArr.map(function(arg) {
4950
return '"' + arg + '"'; // wrap parameters
@@ -56,7 +57,16 @@
5657
gitArgs += ' --no-color';
5758
}
5859

59-
var diffCommand = 'git diff ' + gitArgs;
60+
var ignoreString = '';
61+
62+
if (ignore) {
63+
ignoreString = ignore.map(function(file) {
64+
return ' ":(exclude)' + file + '" ';
65+
}).join(' ');
66+
}
67+
68+
var diffCommand = 'git diff ' + gitArgs + ignoreString;
69+
6070
return callback(null, utils.runCmd(diffCommand));
6171
};
6272

src/main.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,24 @@ var argv = yargs.usage('Usage: diff2html [options] -- [diff args]')
137137
type: 'string'
138138
}
139139
})
140+
.options({
141+
'ig': {
142+
alias: 'ignore',
143+
describe: 'ignore a file',
144+
nargs: 1,
145+
type: 'array'
146+
}
147+
})
140148
.example('diff2html -s line -f html -d word -i command -o preview -- -M HEAD~1',
141149
'diff last commit, line by line, word comparison between lines,' +
142150
'previewed in the browser and input from git diff command')
143151
.example('diff2html -i file -- my-file-diff.diff', 'reading the input from a file')
144152
.example('diff2html -f json -o stdout -- -M HEAD~1', 'print json format to stdout')
145153
.example('diff2html -F my-pretty-diff.html -- -M HEAD~1', 'print to file')
154+
.example('diff2html --ig -- package-lock.json --ig yarn.lock',
155+
'ignore two particular files when generating the diff')
146156
.help('h')
157+
.alias('v', 'version')
147158
.alias('h', 'help')
148159
.epilog('© 2014-' + currentYear + ' rtfpessoa\n' +
149160
'For more information, check out https://diff2html.xyz/\n' +
@@ -193,4 +204,4 @@ function onOutput(err, output) {
193204
}
194205
}
195206

196-
cli.getInput(argv.input, argv._, onInput);
207+
cli.getInput(argv.input, argv._, argv.ig, onInput);

0 commit comments

Comments
 (0)