Skip to content

Commit c934273

Browse files
author
whyboris
committed
pass ignore files as array
1 parent 1c7a8ae commit c934273

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ 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+
| --ig | --ignore | Ignore particular files from the diff | _[string]_ | |
7475
| -v | --version | | Show version number | | |
7576
| -h | --help | Show help | | |
7677

@@ -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: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,28 @@
4444

4545
Diff2HtmlInterface.prototype._runGitDiff = function(gitArgsArr, ignore, callback) {
4646
var gitArgs;
47+
4748
if (gitArgsArr.length && gitArgsArr[0]) {
4849
gitArgs = gitArgsArr.map(function(arg) {
49-
return '"' + (ignore ? ':(exclude)' : '') + arg + '"'; // wrap parameters
50+
return '"' + arg + '"'; // wrap parameters
5051
}).join(' ');
5152
} else {
5253
gitArgs = '-M -C HEAD';
5354
}
5455

55-
if (!ignore && gitArgs.indexOf('--no-color') < 0) {
56+
if (gitArgs.indexOf('--no-color') < 0) {
5657
gitArgs += ' --no-color';
5758
}
5859

59-
var diffCommand = 'git diff ' + (ignore ? '--no-color ' : '') + 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;
6069

6170
return callback(null, utils.runCmd(diffCommand));
6271
};

src/main.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ var argv = yargs.usage('Usage: diff2html [options] -- [diff args]')
142142
alias: 'ignore',
143143
describe: 'ignore a file',
144144
nargs: 1,
145-
type: 'boolean',
146-
choices: [true, false],
147-
default: false
145+
type: 'array'
148146
}
149147
})
150148
.example('diff2html -s line -f html -d word -i command -o preview -- -M HEAD~1',
@@ -153,7 +151,7 @@ var argv = yargs.usage('Usage: diff2html [options] -- [diff args]')
153151
.example('diff2html -i file -- my-file-diff.diff', 'reading the input from a file')
154152
.example('diff2html -f json -o stdout -- -M HEAD~1', 'print json format to stdout')
155153
.example('diff2html -F my-pretty-diff.html -- -M HEAD~1', 'print to file')
156-
.example('diff2html -ig -- package-lock.json yarn.lock',
154+
.example('diff2html --ig -- package-lock.json --ig yarn.lock',
157155
'ignore two particular files when generating the diff')
158156
.help('h')
159157
.alias('v', 'version')

0 commit comments

Comments
 (0)