-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtojson
55 lines (43 loc) · 1.47 KB
/
tojson
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
require("./lib/WebModule.js");
var argv = process.argv.slice(2);
//var json = JSON.stringify( require("./lib/SpecCatalog.js") );
//require("fs").writeFileSync("./lib/SpecCatalog.json", json, "UTF-8");
_minify( require("./lib/SpecCatalog.js"), "./lib/SpecCatalog.json" );
_minify( require("./lib/SpecCatalogFP.js"), "./lib/SpecCatalogFP.json" );
function _minify(json, output, keywords) {
var buffer = ["{", "\n"];
for (var key in json) {
switch (key) {
case "DEVICE_TAGS":
case "GPU_TAGS":
buffer.push( '"' + key + '":' + JSON.stringify(json[key]) );
break;
case "iOS":
case "Android":
case "Windows":
case "SOC":
case "GPU":
case "DOCOMO":
case "KDDI":
case "SOFTBANK":
buffer.push( '"' + key + '":{', "\n" );
for (var i in json[key]) {
buffer.push( '"' + i + '":' + JSON.stringify(json[key][i]) );
buffer.push( ",\n" );
}
buffer.pop();
buffer.push("\n", "}");
break;
}
buffer.push( ",\n" );
}
buffer.pop();
buffer.push("\n", "}");
try {
JSON.parse(buffer.join("")); // test
require("fs").writeFileSync(output, buffer.join(""), "UTF-8");
} catch (error) {
console.log("encode json error: " + error.message + ", " + output);
require("fs").writeFileSync(output, buffer.join(""), "UTF-8");
}
}