-
Notifications
You must be signed in to change notification settings - Fork 0
/
java.js
54 lines (40 loc) · 1.1 KB
/
java.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @file java.js
*
* Take json as input and convert the keys into fields
*/
var fs = require('fs'),
util = require('util');
var log = console; // require('./log');
var Params = require('./params');
var optsAvailable = {
//
'from-json-to-class': true,
//
'json-to-type': false
};
var params = new Params(optsAvailable);
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
var opts = params.getOpts();
var optCount = params.getOptCount();
if (optCount === 0) {
params.setUsage(optsAvailable);
params.showUsage();
process.exit(-1);
}
var longOpts = opts;
var inputs = opts['---'];
var jsonFile = Array.isArray(inputs) ? inputs[0] : inputs;
var jsonString = fs.readFileSync(jsonFile, 'utf8').trim();
var datatype = require('tyo-utils').datatype;
var java = require('./lib/java').java;
java.opts = longOpts;
if (longOpts['from-json-to-class']) {
}
else if (longOpts['json-to-type']) {
var target = java.jsonToType(jsonString);
console.log(JSON.stringify(target));
}