Skip to content

Commit 2454a3f

Browse files
author
whyboris
committed
merge master resolve conflicts recreate yarn.lock
2 parents 9bbf72f + 70434e2 commit 2454a3f

File tree

8 files changed

+1092
-574
lines changed

8 files changed

+1092
-574
lines changed

.circleci/config.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- ./node_modules
1616
- run: npm run coverage
1717
- run: npm run check-coverage
18+
- run: npm run report
1819

1920
build-latest: &latest-build
2021
docker:
@@ -31,18 +32,9 @@ jobs:
3132
- ./node_modules
3233
- run: yarn run test
3334
- run: yarn run lint
35+
- run: yarn run coverage-lcov
3436
- run: yarn run codacy
3537

36-
build-node_4:
37-
<<: *common-build
38-
docker:
39-
- image: node:4
40-
41-
build-node_5:
42-
<<: *common-build
43-
docker:
44-
- image: node:5
45-
4638
build-node_6:
4739
<<: *common-build
4840
docker:
@@ -64,18 +56,22 @@ jobs:
6456
- image: node:9
6557

6658
build-node_10:
67-
<<: *latest-build
59+
<<: *common-build
6860
docker:
6961
- image: node:10
7062

63+
build-node_11:
64+
<<: *latest-build
65+
docker:
66+
- image: node:11
67+
7168
workflows:
7269
version: 2
7370
build:
7471
jobs:
75-
- build-node_4
76-
- build-node_5
7772
- build-node_6
7873
- build-node_7
7974
- build-node_8
8075
- build-node_9
8176
- build-node_10
77+
- build-node_11

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ node_modules/
2020
npm-debug.log
2121
yarn-error.log
2222

23-
# Istanbul
23+
# NYC
2424
coverage/
25+
.nyc_output/
2526

2627
# Bower
2728
bower_components/

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

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@
3232
"url": "https://www.github.com/rtfpessoa/diff2html-cli/issues"
3333
},
3434
"engines": {
35-
"node": ">=8"
35+
"node": ">=6"
3636
},
3737
"preferGlobal": true,
3838
"scripts": {
3939
"lint": "eslint .",
4040
"style": "yarn run lint",
41-
"coverage": "istanbul cover _mocha -- -u exports -R spec ./test/**/*",
42-
"check-coverage": "istanbul check-coverage --statements 50 --functions 40 --branches 0 --lines 50 ./coverage/coverage.json",
4341
"test": "yarn run coverage",
42+
"coverage": "nyc mocha",
43+
"coverage-html": "nyc report --reporter=html && open ./coverage/index.html",
44+
"check-coverage": "nyc check-coverage --statements 40 --functions 40 --branches 0 --lines 40",
45+
"report": "nyc report",
46+
"coverage-lcov": "nyc report --reporter=lcov",
4447
"codacy": "cat ./coverage/lcov.info | codacy-coverage",
4548
"preversion": "yarn run test",
4649
"postversion": "git push && git push --tags"
@@ -55,15 +58,16 @@
5558
"extend": "^3.0.2",
5659
"open": "^0.0.5",
5760
"request": "^2.88.0",
58-
"yargs": "^13.0.0"
61+
"yargs": "^12.0.5"
5962
},
6063
"devDependencies": {
6164
"codacy-coverage": "^3.4.0",
6265
"eslint": "^5.13.0",
6366
"eslint-plugin-promise": "^4.0.1",
6467
"eslint-plugin-standard": "^4.0.0",
65-
"istanbul": "^0.4.5",
66-
"mocha": "^5.2.0"
68+
"mocha": "^5.2.0",
69+
"nyc": "^13.2.0",
70+
"sinon": "^7.2.3"
6771
},
6872
"license": "MIT",
6973
"files": [

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);

test/cli-tests.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var assert = require('assert');
2+
3+
var sinon = require('sinon');
4+
5+
var Cli = require('../src/cli.js').Diff2HtmlInterface;
6+
var http = require('../src/http-utils.js').HttpUtils;
7+
var Utils = require('../src/utils.js').Utils;
8+
9+
describe('Cli', function() {
10+
describe('getInput', function() {
11+
it('should readFile when inputType is `file`', function() {
12+
var spy = sinon.stub(Utils, 'readFile');
13+
Cli.getInput('file', ['lol', 'foo'], 'ignore', 'callback');
14+
assert(spy.calledOnce);
15+
assert(spy.calledWith('lol', 'callback'));
16+
spy.restore();
17+
});
18+
19+
it('should readStdin when inputType is `stdin`', function() {
20+
var spy = sinon.stub(Utils, 'readStdin');
21+
Cli.getInput('stdin', ['lol'], 'ignore', 'callback');
22+
assert(spy.calledOnce);
23+
assert(spy.calledWith('callback'));
24+
spy.restore();
25+
});
26+
27+
it('should _runGitDiff by default', function() {
28+
var spy = sinon.stub(Cli, '_runGitDiff');
29+
Cli.getInput('abc', ['lol', 'foo'], 'ignore', 'callback');
30+
assert(spy.calledOnce);
31+
assert(spy.calledWith(['lol', 'foo'], 'ignore', 'callback'));
32+
});
33+
});
34+
35+
describe('preview', function() {
36+
it('should call `utils.writeFile`', function() {
37+
var spy = sinon.stub(Utils, 'writeFile');
38+
Cli.preview('a', 'b');
39+
assert(spy.calledOnce);
40+
spy.restore();
41+
});
42+
});
43+
44+
describe('postToDiffy', function() {
45+
it('should call `http.post`', function() {
46+
var spy = sinon.stub(http, 'post');
47+
Cli.postToDiffy('a', 'b', 'callback');
48+
assert(spy.calledOnce);
49+
assert(spy.calledWith('http://diffy.org/api/new', { udiff: 'a' }));
50+
});
51+
});
52+
});

0 commit comments

Comments
 (0)