1
1
/*
2
2
*
3
- * diff2html CLI (main.js)
3
+ * Diff to HTML CLI (main.js)
4
4
* Author: rtfpessoa
5
5
*
6
6
*/
@@ -66,11 +66,12 @@ var argv = require('yargs')
66
66
}
67
67
} )
68
68
. 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' )
70
71
. example ( 'diff2html -i file -- my-file-diff.diff' , 'reading the input from a file' )
71
72
. example ( 'diff2html -f json -o stdout -- -M HEAD~1' , 'print json format to stdout' )
72
73
. example ( 'diff2html -F my-pretty-diff.html -- -M HEAD~1' , 'print to file' )
73
- . version ( function ( ) {
74
+ . version ( function ( ) {
74
75
return require ( '../package' ) . version ;
75
76
} )
76
77
. help ( 'h' )
@@ -94,7 +95,7 @@ function main() {
94
95
print ( content ) ;
95
96
}
96
97
} else {
97
- error ( " The input is empty. Try again." ) ;
98
+ error ( ' The input is empty. Try again.' ) ;
98
99
argv . help ( ) ;
99
100
}
100
101
@@ -107,9 +108,9 @@ function getInput() {
107
108
} else {
108
109
var gitArgs ;
109
110
if ( argv . _ . length && argv . _ [ 0 ] ) {
110
- gitArgs = argv . _ . join ( " " ) ;
111
+ gitArgs = argv . _ . join ( ' ' ) ;
111
112
} else {
112
- gitArgs = " -M HEAD~1"
113
+ gitArgs = ' -M HEAD~1'
113
114
}
114
115
115
116
var diffCommand = 'git diff ' + gitArgs ;
@@ -139,17 +140,17 @@ function getOutput(input) {
139
140
}
140
141
141
142
function preview ( content ) {
142
- var filePath = " /tmp/diff." + argv . format ;
143
+ var filePath = ' /tmp/diff.' + argv . format ;
143
144
writeFile ( filePath , content ) ;
144
- runCmd ( " open " + filePath ) ;
145
+ runCmd ( ' open ' + filePath ) ;
145
146
}
146
147
147
148
function 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' ) ;
150
151
return template
151
- . replace ( "{{ css}}" , css )
152
- . replace ( "{{ diff}}" , content ) ;
152
+ . replace ( '<!-- css-->' , '<style>\n' + css + '\n</style>' )
153
+ . replace ( '<!-- diff-->' , content ) ;
153
154
}
154
155
155
156
function prepareJSON ( content ) {
@@ -166,7 +167,7 @@ function error(msg) {
166
167
167
168
function readFile ( filePath ) {
168
169
var fs = require ( 'fs' ) ;
169
- return fs . readFileSync ( filePath , " utf8" ) ;
170
+ return fs . readFileSync ( filePath , ' utf8' ) ;
170
171
}
171
172
172
173
function writeFile ( filePath , content ) {
0 commit comments