5 var U2 = require("../tools/node");
6 var fs = require("fs");
7 var yargs = require("yargs");
9 .describe("o", "Output file")
11 var files = ARGS._.slice();
18 output = JSON.parse(fs.readFileSync(ARGS.o, "utf8"));
21 files.forEach(getProps);
24 fs.writeFileSync(ARGS.o, JSON.stringify(output, null, 2), "utf8");
26 console.log("%s", JSON.stringify(output, null, 2));
29 function getProps(filename) {
30 var code = fs.readFileSync(filename, "utf8");
31 var ast = U2.parse(code);
33 ast.walk(new U2.TreeWalker(function(node){
34 if (node instanceof U2.AST_ObjectKeyVal) {
37 else if (node instanceof U2.AST_ObjectProperty) {
40 else if (node instanceof U2.AST_Dot) {
43 else if (node instanceof U2.AST_Sub) {
44 addStrings(node.property);
48 function addStrings(node) {
52 node.walk(new U2.TreeWalker(function(node){
53 if (node instanceof U2.AST_Seq) {
57 if (node instanceof U2.AST_String) {
61 if (node instanceof U2.AST_Conditional) {
62 walk(node.consequent);
63 walk(node.alternative);
70 if (ex !== out) throw ex;
75 output.props[name] = true;