11/*
22 *
3- * diff2html CLI (main.js)
3+ * Diff to HTML CLI (main.js)
44 * Author: rtfpessoa
55 *
66 */
@@ -66,11 +66,12 @@ var argv = require('yargs')
6666 }
6767 } )
6868 . example ( 'diff2html -s line -f html -d word -i command -o preview -- -M HEAD~1' ,
69- 'diff last commit, line by line, word comparison between lines, previewed in the browser and input from git diff command' )
69+ 'diff last commit, line by line, word comparison between lines,' +
70+ 'previewed in the browser and input from git diff command' )
7071 . example ( 'diff2html -i file -- my-file-diff.diff' , 'reading the input from a file' )
7172 . example ( 'diff2html -f json -o stdout -- -M HEAD~1' , 'print json format to stdout' )
7273 . example ( 'diff2html -F my-pretty-diff.html -- -M HEAD~1' , 'print to file' )
73- . version ( function ( ) {
74+ . version ( function ( ) {
7475 return require ( '../package' ) . version ;
7576 } )
7677 . help ( 'h' )
@@ -94,7 +95,7 @@ function main() {
9495 print ( content ) ;
9596 }
9697 } else {
97- error ( " The input is empty. Try again." ) ;
98+ error ( ' The input is empty. Try again.' ) ;
9899 argv . help ( ) ;
99100 }
100101
@@ -107,9 +108,9 @@ function getInput() {
107108 } else {
108109 var gitArgs ;
109110 if ( argv . _ . length && argv . _ [ 0 ] ) {
110- gitArgs = argv . _ . join ( " " ) ;
111+ gitArgs = argv . _ . join ( ' ' ) ;
111112 } else {
112- gitArgs = " -M HEAD~1"
113+ gitArgs = ' -M HEAD~1'
113114 }
114115
115116 var diffCommand = 'git diff ' + gitArgs ;
@@ -139,17 +140,17 @@ function getOutput(input) {
139140}
140141
141142function preview ( content ) {
142- var filePath = " /tmp/diff." + argv . format ;
143+ var filePath = ' /tmp/diff.' + argv . format ;
143144 writeFile ( filePath , content ) ;
144- runCmd ( " open " + filePath ) ;
145+ runCmd ( ' open ' + filePath ) ;
145146}
146147
147148function prepareHTML ( content ) {
148- var template = readFile ( __dirname + " /../dist/template.html" , " utf8" ) ;
149- var css = readFile ( __dirname + " /../dist/diff2html.css" , " utf8" ) ;
149+ var template = readFile ( __dirname + ' /../dist/template.html' , ' utf8' ) ;
150+ var css = readFile ( __dirname + ' /../dist/diff2html.css' , ' utf8' ) ;
150151 return template
151- . replace ( "{{ css}}" , css )
152- . replace ( "{{ diff}}" , content ) ;
152+ . replace ( '<!-- css-->' , '<style>\n' + css + '\n</style>' )
153+ . replace ( '<!-- diff-->' , content ) ;
153154}
154155
155156function prepareJSON ( content ) {
@@ -166,7 +167,7 @@ function error(msg) {
166167
167168function readFile ( filePath ) {
168169 var fs = require ( 'fs' ) ;
169- return fs . readFileSync ( filePath , " utf8" ) ;
170+ return fs . readFileSync ( filePath , ' utf8' ) ;
170171}
171172
172173function writeFile ( filePath , content ) {
0 commit comments