diff2html-cli
Advanced tools
Comparing version 1.2.1 to 1.3.0
{ | ||
"name": "diff2html-cli", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"homepage": "https://www.github.com/rtfpessoa/diff2html-cli", | ||
@@ -39,3 +39,5 @@ "description": "Fast Diff to colorized HTML", | ||
"scripts": { | ||
"test": "" | ||
"test": "mocha", | ||
"style": "jscs src test", | ||
"codacy": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/.bin/codacy-coverage && rm -rf ./coverage" | ||
}, | ||
@@ -47,8 +49,12 @@ "bin": { | ||
"dependencies": { | ||
"yargs": "3.27.*", | ||
"extend": "3.0.*", | ||
"request": "2.65.*", | ||
"diff2html": "*" | ||
"yargs": "^3.31.0", | ||
"extend": "^3.0.0", | ||
"request": "^2.67.0", | ||
"diff2html": "~1.2.0" | ||
}, | ||
"devDependencies": { | ||
"codacy-coverage": "^1.1.3", | ||
"istanbul": "^0.4.1", | ||
"jscs": "^2.7.0", | ||
"mocha": "^2.3.4" | ||
}, | ||
@@ -55,0 +61,0 @@ "license": "MIT", |
@@ -1,3 +0,16 @@ | ||
# Diff to Html CLI by [rtfpessoa](https://github.com/rtfpessoa) | ||
# diff2html-cli | ||
[![Circle CI](https://circleci.com/gh/rtfpessoa/diff2html-cli.svg?style=svg)](https://circleci.com/gh/rtfpessoa/diff2html-cli) | ||
[![Codacy Code Badge](https://api.codacy.com/project/badge/grade/e6139937d72f40ed8b3920d53c74298a)](https://www.codacy.com/app/Codacy/diff2html-cli) | ||
[![Codacy Coverage Badge](https://api.codacy.com/project/badge/coverage/e6139937d72f40ed8b3920d53c74298a)](https://www.codacy.com/app/Codacy/diff2html-cli) | ||
[![npm](https://img.shields.io/npm/v/diff2html-cli.svg)](https://www.npmjs.com/package/diff2html-cli) | ||
[![David](https://img.shields.io/david/rtfpessoa/diff2html-cli.svg)](https://david-dm.org/rtfpessoa/diff2html-cli) | ||
[![David](https://img.shields.io/david/dev/rtfpessoa/diff2html-cli.svg)](https://david-dm.org/rtfpessoa/diff2html-cli) | ||
[![node](https://img.shields.io/node/v/diff2html-cli.svg)]() | ||
[![npm](https://img.shields.io/npm/l/diff2html-cli.svg)]() | ||
[![npm](https://img.shields.io/npm/dm/diff2html-cli.svg)](https://www.npmjs.com/package/diff2html-cli) | ||
[![Gitter](https://badges.gitter.im/rtfpessoa/diff2html.svg)](https://gitter.im/rtfpessoa/diff2html?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) | ||
Diff to Html generates pretty HTML diffs from git diff output in your terminal | ||
@@ -17,2 +30,4 @@ | ||
* Line similarity matching | ||
## Online Example | ||
@@ -40,34 +55,30 @@ | ||
diff2html [options] -- [diff args] | ||
Usage: diff2html [options] -- [diff args] | ||
Options: | ||
-s, --style Output style | ||
[string] [choices: "line", "side"] [default: "line"] | ||
-f, --format Output format | ||
[string] [choices: "html", "json"] [default: "html"] | ||
-d, --diff Diff style [string] [choices: "word", "char"] [default: "word"] | ||
-i, --input Diff input source | ||
[string] [choices: "file", "command", "stdin"] [default: "command"] | ||
-o, --output Output destination | ||
[string] [choices: "preview", "stdout"] [default: "preview"] | ||
-u, --diffy Upload to diffy.org | ||
[string] [choices: "browser", "pbcopy", "print"] | ||
-F, --file Send output to file (overrides output option) [string] | ||
--version Show version number [boolean] | ||
-h, --help Show help [boolean] | ||
-s, --style Output style [string] [choices: "line", "side"] [default: "line"] | ||
--su, --summary Show files summary [boolean] [default: "true"] | ||
--lm, --matching Diff line matching type [string] [choices: "lines", "words", "none"] [default: "none"] | ||
--lmt, --matchWordsThreshold Diff line matching word threshold [string] [default: "0.25"] | ||
-f, --format Output format [string] [choices: "html", "json"] [default: "html"] | ||
-d, --diff Diff style [string] [choices: "word", "char"] [default: "word"] | ||
-i, --input Diff input source [string] [choices: "file", "command", "stdin"] [default: "command"] | ||
-o, --output Output destination [string] [choices: "preview", "stdout"] [default: "preview"] | ||
-u, --diffy Upload to diffy.org [string] [choices: "browser", "pbcopy", "print"] | ||
-F, --file Send output to file (overrides output option) [string] | ||
--version Show version number [boolean] | ||
-h, --help Show help [boolean] | ||
Examples: | ||
diff2html -s line -f html -d word -i diff last commit, line by line, word | ||
command -o preview -- -M HEAD~1 comparison between lines,previewed | ||
in the browser and input from git | ||
diff command | ||
diff2html -i file -- my-file-diff.diff reading the input from a file | ||
diff2html -f json -o stdout -- -M HEAD~1 print json format to stdout | ||
diff2html -F my-pretty-diff.html -- -M print to file | ||
HEAD~1 | ||
diff2html -s line -f html -d word -i command -o preview -- -M HEAD~1 | ||
-> diff last commit, line by line, word comparison between lines,previewed | ||
in the browser and input from git diff command | ||
diff2html -i file -- my-file-diff.diff | ||
-> reading the input from a file | ||
diff2html -f json -o stdout -- -M HEAD~1 | ||
-> print json format to stdout | ||
diff2html -F my-pretty-diff.html -- -M HEAD~1 | ||
-> print to file | ||
© 2015 rtfpessoa | ||
© 2014 rtfpessoa | ||
For support, check out https://github.com/rtfpessoa/diff2html-cli | ||
@@ -79,6 +90,6 @@ | ||
All the contributions are welcome. | ||
This is a developer friendly project, all the contributions are welcome. | ||
To contribute just send a pull request with your changes following the guidelines described in `CONTRIBUTING.md`. | ||
I will try to review them as soon as possible. | ||
To contribute just send a pull request with your changes and I will review it asap. | ||
## License | ||
@@ -85,0 +96,0 @@ |
193
src/main.js
#!/usr/bin/env node | ||
/* | ||
@@ -9,2 +10,6 @@ * | ||
var cli = require('./cli.js').Diff2HtmlInterface; | ||
var log = require('./logger.js').Logger; | ||
var utils = require('./utils.js').Utils; | ||
var argv = require('yargs') | ||
@@ -23,2 +28,29 @@ .usage('Usage: diff2html [options] -- [diff args]') | ||
.options({ | ||
'su': { | ||
alias: 'summary', | ||
describe: 'Show files summary', | ||
type: 'boolean', | ||
default: 'true' | ||
} | ||
}) | ||
.options({ | ||
'lm': { | ||
alias: 'matching', | ||
describe: 'Diff line matching type', | ||
nargs: 1, | ||
type: 'string', | ||
choices: ['lines', 'words', 'none'], | ||
default: 'words' | ||
} | ||
}) | ||
.options({ | ||
'lmt': { | ||
alias: 'matchWordsThreshold', | ||
describe: 'Diff line matching word threshold', | ||
nargs: 1, | ||
type: 'string', | ||
default: '0.25' | ||
} | ||
}) | ||
.options({ | ||
'f': { | ||
@@ -91,153 +123,44 @@ alias: 'format', | ||
.alias('h', 'help') | ||
.epilog('© 2015 rtfpessoa\n' + | ||
.epilog('© 2014 rtfpessoa\n' + | ||
'For support, check out https://github.com/rtfpessoa/diff2html-cli') | ||
.argv; | ||
function getInput() { | ||
if (argv.input === 'file') { | ||
return readFile(argv._[0]); | ||
} else if (argv.input === 'stdin') { | ||
return readFile('/dev/stdin'); | ||
} else { | ||
var gitArgs; | ||
if (argv._.length && argv._[0]) { | ||
gitArgs = argv._.join(' '); | ||
} else { | ||
gitArgs = '-M HEAD~1' | ||
} | ||
/* | ||
* CLI code | ||
*/ | ||
var diffCommand = 'git diff ' + gitArgs; | ||
return runCmd(diffCommand); | ||
function onInput(err, input) { | ||
if (err) { | ||
log.error(err); | ||
return; | ||
} | ||
} | ||
function getOutput(input) { | ||
var diff2Html = require('diff2html').Diff2Html; | ||
if (!input) { | ||
log.error('The input is empty. Try again.'); | ||
argv.help(); | ||
} | ||
var config = {}; | ||
config.wordByWord = (argv.diff === 'word'); | ||
config.charByChar = (argv.diff === 'char'); | ||
if (argv.format === 'html') { | ||
var htmlContent; | ||
if (argv.style === 'side') { | ||
htmlContent = diff2Html.getPrettySideBySideHtmlFromDiff(input, config); | ||
} else { | ||
htmlContent = diff2Html.getPrettyHtmlFromDiff(input, config); | ||
} | ||
return prepareHTML(htmlContent); | ||
} else { | ||
var jsonContent = diff2Html.getJsonFromDiff(input, config); | ||
return prepareJSON(jsonContent); | ||
if (argv.diffy) { | ||
cli.postToDiffy(input, argv.diffy); | ||
return; | ||
} | ||
} | ||
function preview(content) { | ||
var filePath = '/tmp/diff.' + argv.format; | ||
writeFile(filePath, content); | ||
runCmd('open ' + filePath); | ||
cli.getOutput(argv, input, onOutput); | ||
} | ||
function prepareHTML(content) { | ||
var template = readFile(__dirname + '/../dist/template.html', 'utf8'); | ||
var css = readFile(__dirname + '/../dist/diff2html.css', 'utf8'); | ||
return template | ||
.replace('<!--css-->', '<style>\n' + css + '\n</style>') | ||
.replace('<!--diff-->', content); | ||
} | ||
function onOutput(err, output) { | ||
if (err) { | ||
log.error(err); | ||
return; | ||
} | ||
function postToDiffy(diff, postType) { | ||
var jsonParams = {udiff: diff}; | ||
post('http://diffy.org/api/new', jsonParams, function(err, response) { | ||
if (err) { | ||
print(err); | ||
return; | ||
} | ||
if (response.status != 'error') { | ||
print("Link powered by diffy.org:"); | ||
print(response.url); | ||
if (postType === 'browser') { | ||
runCmd('open ' + response.url); | ||
} else if (postType === 'pbcopy') { | ||
runCmd('echo "' + response.url + '" | pbcopy'); | ||
} | ||
} else { | ||
print("Error: " + message); | ||
} | ||
}); | ||
} | ||
function post(url, payload, callback) { | ||
var request = require('request'); | ||
request({ | ||
url: url, | ||
method: 'POST', | ||
form: payload | ||
}) | ||
.on('response', function(response) { | ||
response.on('data', function(body) { | ||
try { | ||
callback(null, JSON.parse(body.toString('utf8'))); | ||
} catch (err) { | ||
callback(new Error('could not parse response')); | ||
} | ||
}) | ||
}) | ||
.on('error', function(err) { | ||
callback(err); | ||
}); | ||
} | ||
function prepareJSON(content) { | ||
return JSON.stringify(content); | ||
} | ||
function print(line) { | ||
console.log(line); | ||
} | ||
function error(msg) { | ||
console.error(msg); | ||
} | ||
function readFile(filePath) { | ||
var fs = require('fs'); | ||
return fs.readFileSync(filePath, 'utf8'); | ||
} | ||
function writeFile(filePath, content) { | ||
var fs = require('fs'); | ||
fs.writeFileSync(filePath, content); | ||
} | ||
function runCmd(cmd) { | ||
var childProcess = require('child_process'); | ||
return childProcess.execSync(cmd).toString('utf8'); | ||
} | ||
/* | ||
* CLI code | ||
*/ | ||
var input = getInput(); | ||
if (input && argv.diffy) { | ||
postToDiffy(input, argv.diffy); | ||
} else if (input) { | ||
var content = getOutput(input); | ||
if (argv.file) { | ||
writeFile(argv.file, content); | ||
utils.writeFile(argv.file, output); | ||
} else if (argv.output === 'preview') { | ||
preview(content); | ||
cli.preview(output, argv.format); | ||
} else { | ||
print(content); | ||
log.print(output); | ||
} | ||
} else { | ||
error('The input is empty. Try again.'); | ||
argv.help(); | ||
} | ||
cli.getInput(argv.input, argv._, onInput); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
22755
11
603
0
0
101
1
4
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcamelcase@2.1.1(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcliui@3.2.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddiff@2.2.3(transitive)
+ Addeddiff2html@1.2.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.13.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedwrap-ansi@2.1.0(transitive)
+ Addedyargs@3.32.0(transitive)
- Removedabbrev@1.1.1(transitive)
- Removedalign-text@0.1.4(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedasn1@0.1.11(transitive)
- Removedassert-plus@0.1.5(transitive)
- Removedasync@2.6.4(transitive)
- Removedaws-sign2@0.6.0(transitive)
- Removedbl@1.0.3(transitive)
- Removedboom@2.10.1(transitive)
- Removedcamelcase@1.2.1(transitive)
- Removedcaseless@0.11.0(transitive)
- Removedcenter-align@0.1.3(transitive)
- Removedchalk@1.1.3(transitive)
- Removedcliui@2.1.0(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedcryptiles@2.0.5(transitive)
- Removedctype@0.5.3(transitive)
- Removeddiff@5.1.0(transitive)
- Removeddiff2html@3.4.48(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedform-data@1.0.1(transitive)
- Removedgenerate-function@2.3.1(transitive)
- Removedgenerate-object-property@1.2.0(transitive)
- Removedhar-validator@2.0.6(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhawk@3.1.3(transitive)
- Removedhighlight.js@11.9.0(transitive)
- Removedhoek@2.16.3(transitive)
- Removedhogan.js@3.0.2(transitive)
- Removedhttp-signature@0.11.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-my-ip-valid@1.0.1(transitive)
- Removedis-my-json-valid@2.20.6(transitive)
- Removedis-property@1.0.2(transitive)
- Removedisarray@1.0.0(transitive)
- Removedjsonpointer@5.0.1(transitive)
- Removedkind-of@3.2.2(transitive)
- Removedlazy-cache@1.0.4(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlongest@1.0.1(transitive)
- Removedmkdirp@0.3.0(transitive)
- Removednode-uuid@1.4.8(transitive)
- Removednopt@1.0.10(transitive)
- Removedoauth-sign@0.8.2(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedprocess-nextick-args@1.0.7(transitive)
- Removedqs@5.2.1(transitive)
- Removedreadable-stream@2.0.6(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedrequest@2.65.0(transitive)
- Removedright-align@0.1.3(transitive)
- Removedsntp@1.0.9(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedstringstream@0.0.6(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedtough-cookie@2.2.2(transitive)
- Removedtunnel-agent@0.4.3(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwordwrap@0.0.2(transitive)
- Removedxtend@4.0.2(transitive)
- Removedyargs@3.27.0(transitive)
Updateddiff2html@~1.2.0
Updatedextend@^3.0.0
Updatedrequest@^2.67.0
Updatedyargs@^3.31.0