Skip to content

Commit ec4b429

Browse files
author
whyboris
committed
Merge branch 'master' into unit-testing
2 parents 0a9a054 + a8c4a59 commit ec4b429

File tree

3 files changed

+81
-50
lines changed

3 files changed

+81
-50
lines changed

README.md

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -54,60 +54,70 @@ Diff to Html generates pretty HTML diffs from unified and git diff output in you
5454

5555
## Usage
5656

57-
Usage: diff2html [options] -- [diff args]
58-
59-
Options:
60-
-s, --style Output style [choices: "line", "side"] [default: "line"]
61-
--sc, --synchronisedScroll Synchronised horizontal scroll [choices: "enabled", "disabled"] [default: "enabled"]
62-
--su, --summary Show files summary [choices: "closed", "open", "hidden"] [default: "closed"]
63-
--lm, --matching Diff line matching type [choices: "lines", "words", "none"] [default: "none"]
64-
--lmt, --matchWordsThreshold Diff line matching word threshold [default: "0.25"]
65-
--lmm, --matchingMaxComparisons Diff line matching maximum line comparisons of a block of changes [default: 2500]
66-
--hwt, --htmlWrapperTemplate Path to custom template to be rendered when using the "html" output format [string]
67-
-f, --format Output format [choices: "html", "json"] [default: "html"]
68-
-d, --diff Diff style [choices: "word", "char"] [default: "word"]
69-
-i, --input Diff input source [choices: "file", "command", "stdin"] [default: "command"]
70-
-o, --output Output destination [choices: "preview", "stdout"] [default: "preview"]
71-
-u, --diffy Upload to diffy.org [choices: "browser", "pbcopy", "print"]
72-
-F, --file Send output to file (overrides output option) [string]
73-
--version Show version number
74-
-h, --help Show help
75-
76-
Examples:
77-
diff2html -s line -f html -d word -i command -o preview -- -M HEAD~1
78-
-> diff last commit, line by line, word comparison between lines,previewed
79-
in the browser and input from git diff command
80-
diff2html -i file -- my-file-diff.diff
81-
-> reading the input from a file
82-
diff -u file1.txt file2.txt | diff2html -i stdin
83-
-> reading diff from stdin
84-
diff2html -f json -o stdout -- -M HEAD~1
85-
-> print json format to stdout
86-
diff2html -F my-pretty-diff.html -- -M HEAD~1
87-
-> print to file
88-
diff2html -F my-pretty-diff.html --hwt my-custom-template.html -- -M HEAD~1
89-
-> print to file using custom markup
90-
templates can include the following variables:
91-
`<!--diff2html-css-->` - writes default CSS to page
92-
`<!--diff2html-js-ui-->` - writes default JavaScript UI scripts to page
93-
`//diff2html-fileListCloseable` - writes code to support selected list interaction, must be within a <script> block
94-
`//diff2html-synchronisedScroll` - writes code to support selected scroll interaction, must be within a <script> block
95-
`<!--diff2html-diff-->` - writes diff content to page
96-
97-
© 2014-2016 rtfpessoa
98-
For support, check out https://github.com/rtfpessoa/diff2html-cli
99-
100-
> NOTE: notice the `--` in the examples
57+
Usage: diff2html [options] -- [diff args]
58+
59+
| flag | alias | description | choices | default |
60+
| --- | --- | --- | --- | --- |
61+
| -s | --style | Output style | `line`, `side` | `line` |
62+
| --sc | --synchronisedScroll | Synchronised horizontal scroll | `enabled`, `disabled` | `enabled` |
63+
| --su | --summary | Show files summary | `closed`, `open`, `hidden` | `closed` |
64+
| --lm | --matching | Diff line matching type | `lines`, `words`, `none` | `none` |
65+
| --lmt | --matchWordsThreshold | Diff line matching word threshold | | `0.25` |
66+
| --lmm | --matchingMaxComparisons | Diff line matching maximum line comparisons of a block of changes | `2500` |
67+
| --hwt | --htmlWrapperTemplate | Path to custom template to be rendered when using the `html` output format | _[string]_ |
68+
| -f | --format | Output format | `html`, `json` | `html` |
69+
| -d | --diff | Diff style | `word`, `char` | `word` |
70+
| -i | --input | Diff input source | `file`, `command`, `stdin` | `command` |
71+
| -o | --output | Output destination | `preview`, `stdout` | `preview` |
72+
| -u | --diffy | Upload to diffy.org | `browser`, `pbcopy`, `print` | |
73+
| -F | --file | Send output to file (overrides output option) | _[string]_ | |
74+
| --ig | --ignore | Ignore particular files from the diff | _[string]_ | |
75+
| -v | --version | | Show version number | | |
76+
| -h | --help | Show help | | |
77+
78+
Examples:
79+
80+
`diff2html -s line -f html -d word -i command -o preview -- -M HEAD~1`
81+
- diff last commit, line by line, word comparison between lines, previewed in the browser and input from git diff command
82+
83+
`diff2html -i file -- my-file-diff.diff`
84+
- reading the input from a file
85+
86+
`diff -u file1.txt file2.txt | diff2html -i stdin`
87+
- reading diff from stdin
88+
89+
`diff2html -f json -o stdout -- -M HEAD~1`
90+
- print json format to stdout
91+
92+
`diff2html -F my-pretty-diff.html -- -M HEAD~1`
93+
- print to file
94+
95+
`diff2html -F my-pretty-diff.html --hwt my-custom-template.html -- -M HEAD~1`
96+
- print to file using custom markup templates can include the following variables:
97+
- `<!--diff2html-css-->` - writes default CSS to page
98+
- `<!--diff2html-js-ui-->` - writes default JavaScript UI scripts to page
99+
- `//diff2html-fileListCloseable` - writes code to support selected list interaction, must be within a `<script>` block
100+
- `//diff2html-synchronisedScroll` - writes code to support selected scroll interaction, must be within a `<script>` block
101+
- `<!--diff2html-diff-->` - writes diff content to page
102+
103+
`diff2htal --ig package-lock.json --ig yarn.lock`
104+
- Ignore `package-lock.json` and `yarn.lock` from the generated diff
105+
106+
_NOTE_: notice the `--` in the examples
101107

102108
## Contributions
103109

104110
This is a developer friendly project, all the contributions are welcome.
105111
To contribute just send a pull request with your changes following the guidelines described in `CONTRIBUTING.md`.
106112
I will try to review them as soon as possible.
107113

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

110-
Copyright 2014-2016 Rodrigo Fernandes. Released under the terms of the MIT license.
120+
Copyright 2014-2019 Rodrigo Fernandes. Released under the terms of the MIT license.
111121

112122
## Thanks
113123

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)