check server version

This commit is contained in:
Pavol Bielik 2015-01-27 16:27:35 +01:00
parent 9d013a10af
commit 027027634d
2 changed files with 23 additions and 13 deletions

View File

@ -8,6 +8,7 @@ var sys = require("util");
var yargs = require("yargs"); var yargs = require("yargs");
var fs = require("fs"); var fs = require("fs");
var http = require('http'); var http = require('http');
var json = require("../package.json");
var ARGS = yargs var ARGS = yargs
.usage("$0 input1.js \n") .usage("$0 input1.js \n")
@ -72,7 +73,7 @@ if (ARGS.colors){
} }
if (ARGS.version || ARGS.V) { if (ARGS.version || ARGS.V) {
var json = require("../package.json"); //var json = require("../package.json");
sys.puts(json.name + ' ' + json.version); sys.puts(json.name + ' ' + json.version);
process.exit(0); process.exit(0);
} }
@ -213,18 +214,26 @@ function processFile(file) {
"infer", "infer",
JSON.parse(output), JSON.parse(output),
function(data) { function(data) {
var result = JSON.parse(data).result; var data_json = JSON.parse(data);
var inferred_names = {}; if (data_json.hasOwnProperty('error')){
for (var i = 0; i < result.length; i++) { console.log("ERROR: ".red + data_json.error.message);
if (result[i].hasOwnProperty("inf")) {
inferred_names[result[i].v] = result[i].inf.green;
}
} }
try { else if (data_json.hasOwnProperty('result')) {
var renamed_js = UglifyJS.replaceMangled(code, file, inferred_names); var result = data_json.result;
console.log(renamed_js); var inferred_names = {};
} catch (ex){ for (var i = 0; i < result.length; i++) {
sys.error("ERROR: ".red + "failed rename '" + file + "': " + ex); if (result[i].hasOwnProperty("inf")) {
inferred_names[result[i].v] = result[i].inf.green;
}
}
try {
var renamed_js = UglifyJS.replaceMangled(code, file, inferred_names);
console.log(renamed_js);
} catch (ex) {
sys.error("ERROR: ".red + "failed rename '" + file + "': " + ex);
}
} else {
sys.error("ERROR: ".red + "undefined response. Try to update unuglify-js to the latest version by 'npm update -g unuglify-js'");
} }
}, },
@ -261,6 +270,7 @@ function callServer(server, port, methodName, params, success_cb, error_cb) {
method : methodName, method : methodName,
id : (++json_rpc_id) id : (++json_rpc_id)
}; };
params.version = json.version;
req.params = params; req.params = params;
var post_data = JSON.stringify(req); var post_data = JSON.stringify(req);

View File

@ -3,7 +3,7 @@
"description": "JavaScript tool that renames variables and parameters to names based on statistical model learnt from thousands of open source projects", "description": "JavaScript tool that renames variables and parameters to names based on statistical model learnt from thousands of open source projects",
"homepage": "https://github.com/eth-srl/UnuglifyJS", "homepage": "https://github.com/eth-srl/UnuglifyJS",
"main": "tools/node.js", "main": "tools/node.js",
"version": "0.9.2", "version": "0.9.3",
"engines": { "node" : ">=0.4.0" }, "engines": { "node" : ">=0.4.0" },
"maintainers": [{ "maintainers": [{
"name": "Pavol Bielik", "name": "Pavol Bielik",