diff2html-cli
Advanced tools
Comparing version 0.2.4 to 1.0.0-1
{ | ||
"name": "diff2html-cli", | ||
"version": "0.2.4", | ||
"version": "1.0.0-1", | ||
"homepage": "https://www.github.com/rtfpessoa/diff2html-nodejs-cli", | ||
"homepage": "https://www.github.com/rtfpessoa/diff2html-cli", | ||
"description": "Fast Diff to colorized HTML", | ||
@@ -32,11 +32,11 @@ "keywords": [ | ||
"type": "git", | ||
"url": "https://www.github.com/rtfpessoa/diff2html-nodejs-cli.git" | ||
"url": "https://www.github.com/rtfpessoa/diff2html-cli.git" | ||
}, | ||
"bugs": { | ||
"url": "https://www.github.com/rtfpessoa/diff2html-nodejs-cli/issues" | ||
"url": "https://www.github.com/rtfpessoa/diff2html-cli/issues" | ||
}, | ||
"engines": { | ||
"node": ">=0.12.2" | ||
"node": ">=0.12.0" | ||
}, | ||
@@ -57,5 +57,4 @@ | ||
"dependencies": { | ||
"commander": "2.8.1", | ||
"yargs": "3.18.*", | ||
"extend": "3.0.0", | ||
"pkginfo": "0.3.0", | ||
"diff2html": "*" | ||
@@ -67,8 +66,3 @@ }, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/rtfpessoa/diff2html-node-cli/blob/master/LICENSE" | ||
} | ||
], | ||
"license": "MIT", | ||
@@ -75,0 +69,0 @@ "files": [ |
@@ -1,9 +0,5 @@ | ||
# Diff to Html Node Module (CLI) by [rtfpessoa](https://github.com/rtfpessoa) | ||
# Diff to Html CLI by [rtfpessoa](https://github.com/rtfpessoa) | ||
Diff to Html generates pretty HTML diffs. | ||
Diff to Html generates pretty HTML diffs from git diff output in your terminal | ||
### Inspiration | ||
This project is just a CLI for [diff2html-nodejs](https://github.com/rtfpessoa/diff2html-nodejs). | ||
## Features | ||
@@ -19,2 +15,4 @@ | ||
* Code syntax highlight | ||
## Online Example | ||
@@ -24,10 +22,14 @@ | ||
## Other Distributions | ||
## Distributions | ||
* [WebJar](http://www.webjars.org/) | ||
* Manually download and import [diff2html.js](https://github.com/rtfpessoa/diff2html) into your page | ||
* [Node Module](https://www.npmjs.org/package/diff2html) | ||
* Import Node library [diff2html-nodejs](https://github.com/rtfpessoa/diff2html-nodejs) into your package.json | ||
* [Bower Package](http://bower.io/search/?q=diff2html) | ||
* [Node CLI](https://www.npmjs.org/package/diff2html-cli) | ||
* Manually download and import `rtfpessoa/diff2html/dist/diff2html.min.js` into your page | ||
## Setup | ||
@@ -52,8 +54,14 @@ | ||
## Contribution | ||
Example: | ||
All contributions are welcome. | ||
diff2html -p -l "HEAD~1" | ||
To contribute just send a pull request with your feature,fix,... and it will be reviewed asap. | ||
> NOTE: notice the " in the example | ||
## Contributions | ||
All the contributions are welcome. | ||
To contribute just send a pull request with your changes and I will review it asap. | ||
## License | ||
@@ -63,2 +71,6 @@ | ||
## Thanks | ||
This project is inspired in [pretty-diff](https://github.com/scottgonzalez/pretty-diff) by [Scott González](https://github.com/scottgonzalez). | ||
--- |
216
src/main.js
@@ -1,43 +0,100 @@ | ||
require('pkginfo')(module, 'version'); | ||
/* | ||
* | ||
* Diff to HTML CLI (main.js) | ||
* Author: rtfpessoa | ||
* | ||
*/ | ||
var fs = require('fs'); | ||
var program = require('commander'); | ||
var appVersion = module.exports.version; | ||
var argv = require('yargs') | ||
.usage('Usage: diff2html [options]') | ||
.options({ | ||
's': { | ||
alias: 'style', | ||
describe: 'Output style', | ||
nargs: 1, | ||
type: 'string', | ||
choices: ['line', 'side'], | ||
default: 'line' | ||
} | ||
}) | ||
.options({ | ||
'f': { | ||
alias: 'format', | ||
describe: 'Output format', | ||
nargs: 1, | ||
type: 'string', | ||
choices: ['html', 'json'], | ||
default: 'html' | ||
} | ||
}) | ||
.options({ | ||
'd': { | ||
alias: 'diff', | ||
describe: 'Diff style', | ||
nargs: 1, | ||
type: 'string', | ||
choices: ['word', 'char'], | ||
default: 'word' | ||
} | ||
}) | ||
.options({ | ||
'i': { | ||
alias: 'input', | ||
describe: 'Diff input source', | ||
nargs: 1, | ||
type: 'string', | ||
choices: ['file', 'command'], | ||
default: 'command' | ||
} | ||
}) | ||
.options({ | ||
'o': { | ||
alias: 'output', | ||
describe: 'Output destination', | ||
nargs: 1, | ||
type: 'string', | ||
choices: ['preview', 'stdout'], | ||
default: 'preview' | ||
} | ||
}) | ||
.options({ | ||
'F': { | ||
alias: 'file', | ||
describe: 'Send output to file (overrides output option)', | ||
nargs: 1, | ||
type: 'string' | ||
} | ||
}) | ||
.example('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') | ||
.example('diff2html -i file -- my-file-diff.diff', 'reading the input from a file') | ||
.example('diff2html -f json -o stdout -- -M HEAD~1', 'print json format to stdout') | ||
.example('diff2html -F my-pretty-diff.html -- -M HEAD~1', 'print to file') | ||
.version(function() { | ||
return require('../package').version; | ||
}) | ||
.help('h') | ||
.alias('h', 'help') | ||
.epilog('Copyright 2015\n' + | ||
'For support, check out https://github.com/rtfpessoa/diff2html-cli') | ||
.argv; | ||
program.version(appVersion); | ||
program.usage('[git-diff options]'); | ||
main(); | ||
program | ||
.option('-i, --input [file]', 'Diff input file.') | ||
.option('-o, --output [file]', 'Output to file path. Defaults to stdout.') | ||
.option('-p, --preview', 'Open preview in the browser.') | ||
.option('-l, --line', 'Line by Line diff.') | ||
.option('-s, --side', 'Side by Side diff.') | ||
.option('-w, --word', 'Word by Word highlight.') | ||
.option('-c, --char', 'Char by Char highlight.') | ||
.option('-j, --json', 'Export diff in json format.'); | ||
program.on('--help', function () { | ||
console.log('For support, check out https://github.com/rtfpessoa/diff2html-nodejs'); | ||
}); | ||
program.parse(process.argv); | ||
main(program); | ||
function main(program) { | ||
var input = getInput(program); | ||
function main() { | ||
var input = getInput(); | ||
if (input) { | ||
var content = getHtml(program, input); | ||
var content = getOutput(input); | ||
if (program.output) { | ||
fs.writeFileSync(program.output, content); | ||
} else if (!program.json && program.preview) { | ||
preview(content) | ||
if (argv.F) { | ||
writeFile(argv.F, content); | ||
} else if (argv.output == 'preview') { | ||
preview(content); | ||
} else { | ||
console.log(content); | ||
print(content); | ||
} | ||
} else { | ||
console.error("The diff is empty. Try another command."); | ||
program.help(); | ||
error('The input is empty. Try again.'); | ||
argv.help(); | ||
} | ||
@@ -48,41 +105,78 @@ | ||
function preview(diffHTML) { | ||
var exec = require("child_process").exec; | ||
function getInput() { | ||
if (argv.input == 'file') { | ||
return readFile(argv._[0]); | ||
} else { | ||
var gitArgs; | ||
if (argv._.length && argv._[0]) { | ||
gitArgs = argv._.join(' '); | ||
} else { | ||
gitArgs = '-M HEAD~1' | ||
} | ||
var template = fs.readFileSync(__dirname + "/../dist/template.html", "utf8"); | ||
var diffCommand = 'git diff ' + gitArgs; | ||
return runCmd(diffCommand); | ||
} | ||
} | ||
var cssDir = __dirname + "/../dist/diff2html.css"; | ||
function getOutput(input) { | ||
var diff2Html = require('diff2html').Diff2Html; | ||
var template = template.replace("{{css}}", cssDir).replace("{{diff}}", diffHTML); | ||
var config = {}; | ||
config.wordByWord = (argv.diff === 'word'); | ||
config.charByChar = (argv.diff === 'char'); | ||
fs.writeFileSync("/tmp/diff.html", template); | ||
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); | ||
} | ||
} | ||
exec("open /tmp/diff.html"); | ||
function preview(content) { | ||
var filePath = '/tmp/diff.' + argv.format; | ||
writeFile(filePath, content); | ||
runCmd('open ' + filePath); | ||
} | ||
function getInput(program) { | ||
if (program.input) { | ||
return fs.readFileSync(program.input, "utf8"); | ||
} else { | ||
var childProcess = require('child_process'); | ||
var lineDiffCommand = 'git diff ' + program.args; | ||
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); | ||
} | ||
return childProcess.execSync(lineDiffCommand).toString('utf8'); | ||
} | ||
function prepareJSON(content) { | ||
return JSON.stringify(content); | ||
} | ||
function getHtml(program, input) { | ||
var diff2Html = require('diff2html').Diff2Html; | ||
function print(line) { | ||
console.log(line); | ||
} | ||
var config = {}; | ||
config.wordByWord = program.word; | ||
config.charByChar = program.char; | ||
function error(msg) { | ||
console.error(msg); | ||
} | ||
if (program.side) { | ||
return diff2Html.getPrettySideBySideHtmlFromDiff(input, config); | ||
} else if (program.json) { | ||
return JSON.stringify(diff2Html.getJsonFromDiff(input, config)); | ||
} else { | ||
return diff2Html.getPrettyHtmlFromDiff(input, config); | ||
} | ||
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'); | ||
} |
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
13520
3
348
73
1
2
+ Addedyargs@3.18.*
+ Addedalign-text@0.1.4(transitive)
+ Addedcamelcase@1.2.1(transitive)
+ Addedcenter-align@0.1.3(transitive)
+ Addedcliui@2.1.0(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedkind-of@3.2.2(transitive)
+ Addedlazy-cache@1.0.4(transitive)
+ Addedlongest@1.0.1(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedright-align@0.1.3(transitive)
+ Addedwindow-size@0.1.4(transitive)
+ Addedwordwrap@0.0.2(transitive)
+ Addedy18n@3.2.2(transitive)
+ Addedyargs@3.18.1(transitive)
- Removedcommander@2.8.1
- Removedpkginfo@0.3.0
- Removedcommander@2.8.1(transitive)
- Removedgraceful-readlink@1.0.1(transitive)
- Removedpkginfo@0.3.0(transitive)