Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

diff2html-cli

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

diff2html-cli - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

src/cli.js

18

package.json
{
"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 @@

#!/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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc