Skip to content

Commit

Permalink
Use os.tmpdir() to find a legitimate temp directory across OSes
Browse files Browse the repository at this point in the history
Fixes #25
  • Loading branch information
scottgonzalez committed Feb 29, 2016
1 parent 8367e66 commit 64d97d4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pretty-diff.js
@@ -1,6 +1,8 @@
#!/usr/bin/env node

var fs = require( "fs" );
var path = require( "path" );
var os = require( "os" );
var open = require( "open" );
var diff = require( "./diff" );

Expand Down Expand Up @@ -28,6 +30,7 @@ diff( process.argv.slice( 2 ).join( " " ), function( error, parsedDiff ) {
function generatePrettyDiff( parsedDiff ) {
var template = fs.readFileSync( __dirname + "/template.html", "utf8" );
var diffHtml = "";
var tempPath = path.join( os.tmpdir(), "diff.html" );

for ( var file in parsedDiff ) {
diffHtml += "<h2>" + file + "</h2>" +
Expand All @@ -36,8 +39,8 @@ function generatePrettyDiff( parsedDiff ) {
"</div></div>";
}

fs.writeFileSync( "/tmp/diff.html", template.replace( "{{diff}}", diffHtml ) );
open( "/tmp/diff.html" );
fs.writeFileSync( tempPath, template.replace( "{{diff}}", diffHtml ) );
open( tempPath );
}

var markUpDiff = function() {
Expand Down

0 comments on commit 64d97d4

Please sign in to comment.