| @ -0,0 +1,28 @@ | |||||
| #!/usr/bin/env node | |||||
| var fs = require('fs'); | |||||
| var path = require('path'); | |||||
| var docopt = require('docopt'); | |||||
| var jsnice = require('../'); | |||||
| var doc = [ | |||||
| 'Usage:', | |||||
| ' jsnice <file>', | |||||
| ' jsnice (--help | --version)', | |||||
| '', | |||||
| 'Options:', | |||||
| ' --help Show this text', | |||||
| ' --version Show jsnice version info', | |||||
| ].join('\r\n'); | |||||
| var args = docopt.docopt(doc, { | |||||
| help: true, | |||||
| version: 'jsnice ' + require('../package.json').version, | |||||
| }); | |||||
| var cwd = process.cwd(); | |||||
| filePath = path.join(cwd, args['<file>']); | |||||
| var js = fs.readFileSync(filePath); | |||||
| jsnice.nicify(js, function(data) { | |||||
| console.log(data.js); | |||||
| }); | |||||
| @ -0,0 +1,35 @@ | |||||
| var http = require('http'); | |||||
| module.exports.nicify = function(js, options, callback) { | |||||
| if (typeof options === 'function') { | |||||
| callback = options; | |||||
| options = {}; | |||||
| } | |||||
| options = options || {}; | |||||
| var reqOptions = { | |||||
| hostname: 'www.jsnice.org', | |||||
| path: '/beautify?pretty=1&rename=1&types=1&suggest=0', | |||||
| port: 80, | |||||
| method: 'POST', | |||||
| }; | |||||
| var req = http.request(reqOptions, function(res) { | |||||
| var data = ''; | |||||
| res.on('data', function(chunk) { | |||||
| data += chunk.toString(); | |||||
| }); | |||||
| res.on('end', function() { | |||||
| data = JSON.parse(data); | |||||
| callback(data); | |||||
| }); | |||||
| }); | |||||
| req.on('error', function(err) { | |||||
| console.dir(err); | |||||
| }); | |||||
| req.write(js); | |||||
| req.end(); | |||||
| }; | |||||
| @ -0,0 +1,34 @@ | |||||
| { | |||||
| "name": "jsnice", | |||||
| "version": "0.1.0", | |||||
| "description": "Run JSNice on your javascripts", | |||||
| "main": "lib/index.js", | |||||
| "scripts": { | |||||
| "test": "echo \"Error: no test specified\" && exit 1" | |||||
| }, | |||||
| "bin": { | |||||
| "jsnice": "bin/jsnice" | |||||
| }, | |||||
| "repository": { | |||||
| "type": "git", | |||||
| "url": "git://github.com/brettlangdon/jsnice.git" | |||||
| }, | |||||
| "keywords": [ | |||||
| "js", | |||||
| "nice", | |||||
| "jsnice", | |||||
| "unminify", | |||||
| "minify", | |||||
| "deobfuscation", | |||||
| "obfuscation" | |||||
| ], | |||||
| "author": "Brett Langdon <brett@blangdon.com> (http://brett.is)", | |||||
| "license": "MIT", | |||||
| "bugs": { | |||||
| "url": "https://github.com/brettlangdon/jsnice/issues" | |||||
| }, | |||||
| "homepage": "https://github.com/brettlangdon/jsnice", | |||||
| "dependencies": { | |||||
| "docopt": "~0.4.0" | |||||
| } | |||||
| } | |||||