Created
March 13, 2015 12:14
-
-
Save amoilanen/01bd492be4d1a53816e9 to your computer and use it in GitHub Desktop.
Command line tool to make readable the code that was minified with Uglify.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var help = [ | |
'Command line tool to unuglify a JavaScript file.', | |
'', | |
'Before using install js-beautify:', | |
'', | |
'npm install js-beautify', | |
'', | |
'To unuglify file code.js run:', | |
'', | |
'node unuglify code.js > code.unuglified.js' | |
].join('\n'); | |
var beautify = require('js-beautify').js_beautify; | |
var fs = require('fs'); | |
var beautifyOptions = { | |
indent_size: 2 | |
}; | |
function unuglify(file, callback) { | |
fs.readFile(file, 'utf8', function (err, data) { | |
if (err) { | |
throw err; | |
} | |
callback(beautify(data, beautifyOptions)); | |
}); | |
} | |
var codePath = process.argv[2]; | |
if (codePath) { | |
unuglify(codePath, function(unuglifiedCode) { | |
console.log(unuglifiedCode); | |
}); | |
} else { | |
console.log(help); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment