Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions beautify-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ require.paths.unshift( "./" );
sys = require( "sys" ),
http = require( "http" ),
url = require( "url" ),
tty = require( "tty" ),
jsb = require( "beautify" ),
options,
result = "";
Expand Down Expand Up @@ -183,22 +184,7 @@ require.paths.unshift( "./" );
beautifySource( sourceFile );
}
}
else {

// I'll be honest: I don't know yet how to check whether there is any
// STDIN or not. When the script is called w/o parameters, it should
// print out usage information; when there's STDIN input, it should
// process that. So I figured that when there's no such input within
// 25ms, there won't be anything later on, either. If you know of a
// cleaner way to do this, please let me know. :) --Carlo

setTimeout( function() {
if ( sourceFile.length === 0 ) {
printUsage();
process.exit( 1 );
}
}, 25 );

else if ( ! tty.isatty( process.stdin ) ) {
stdin = process.openStdin();
stdin.setEncoding( "utf8" );
stdin
Expand All @@ -208,6 +194,9 @@ require.paths.unshift( "./" );
.on( "end", function() {
beautifySource( sourceFile );
});
} else {
printUsage();
process.exit( 1 );
}
}

Expand Down