Use released versions of maven artifacts
[ccsdk/distribution.git] / dgbuilder / tools / dot_to_json.js
1 var obj={};
2 function dotToJson(str,value,obj){
3     //var objArr = path.split("."), part;
4     var objArr = str.split(".");
5         var prevStr;
6         var currObj;
7         var prevObj;
8         //console.log(str);
9         var isArray = false;
10         var prevObjIsArray = false;
11         for(var i=0;i<objArr.length -1;i++){
12                 var subStr= objArr[i] ;
13                 if(isArray){
14                         prevObjIsArray = true;  
15                 }
16                 isArray = false;
17                 if(subStr.indexOf(']') == subStr.length -1){
18                         subStr = subStr.substring(0,subStr.length -2);
19                         isArray = true;
20                 }
21                 //console.log("subStr:" + subStr + isArray);
22                 //console.dir(prevObj);
23                 if(isArray){
24                         if(i==0 && obj[subStr] == undefined ){
25                                 //console.log("i==0 && obj[subStr] ");
26                                 obj[subStr]=[];
27                         }else if(i==0 && obj[subStr][0] == undefined ){
28                                                 obj[subStr][0]={};
29                         }else if(i==0 && obj[subStr][0] != undefined ){
30                                 currObj= obj[subStr][0];
31                         }else{
32                                 if(i == 1){
33                                         //console.log("i==1 && obj[prevStr] ");
34                                         prevObj=obj[prevStr];
35                                         if(prevObj[subStr] != undefined && prevObj[subStr][0] == undefined){
36                                                 prevObj[subStr] = [];
37                                                 prevObj[subStr][0] = {};
38                                                 currObj = prevObj[subStr][0];
39                                         }else if(prevObj[subStr] != undefined && prevObj[subStr][0] != undefined){
40                                                         currObj = prevObj[subStr][0];
41                                         }else if(prevObj[subStr] == undefined){
42                                                 prevObj[subStr] = [];
43                                                 prevObj[subStr][0] = {};
44                                                 currObj = prevObj[subStr][0];
45                                         }
46                                 }else{
47                                         if(prevObj[subStr] == undefined){
48                                                 prevObj[subStr]=[];
49                                                 prevObj[subStr][0]={};
50                                                 currObj = prevObj[subStr][0];
51                                         }else{
52                                                 currObj = prevObj[subStr][0];
53                                         }
54                                 }
55                         }
56                 }else{
57                         if(i==0 && obj[subStr] == undefined ){
58                                 obj[subStr] = {};
59                                 currObj= obj[subStr];
60                         }else if(i==0 && obj[subStr] != undefined ){
61                                 currObj=obj[subStr];
62                         //console.log("in gkjgjkg");
63                         }else{
64                                 if(i == 1){
65                                         prevObj=obj[prevStr];
66                                         if(prevObj[subStr] == undefined){
67                                                 prevObj[subStr] = {};
68                                                 currObj = prevObj[subStr];
69                                         }else{
70                                                 currObj = prevObj[subStr];
71                                         }
72                                 }else{
73                                         if(prevObj[subStr] == undefined){
74                                                 prevObj[subStr] = {};
75                                                 currObj = prevObj[subStr];
76                                         }else{
77                                                 currObj = prevObj[subStr];
78                                         }
79                                 }
80                         }
81                 }
82                 prevStr=subStr;
83                 if(i <objArr.length-2){
84                         //console.dir(currObj);
85                         prevObj=currObj;        
86                 }
87         }
88         var lastStr = objArr[objArr.length-1];
89         if(isArray){
90                 currObj[lastStr] = value;
91         }else{
92                 currObj[lastStr] = value;
93         }
94         //prevObj[lastStr] = value;
95         //console.dir(currObj);
96         return obj;
97 }
98 function printObj(obj){
99 for( j in obj){
100         console.log(j + ":" + obj[j]);
101         if(typeof obj[j] == "object" ){
102                 printObj(obj[j]);
103         }
104
105 }
106 }
107
108 /*
109 var nObj={};
110 for(var i=0;i<a.length;i++){
111         dotToJson(a[i],'',nObj);
112 }
113 */
114 var sliValuesObj = require(process.argv[2]);
115 var moduleName = process.argv[3];
116 //console.dir(sliValuesObj);
117 var a= sliValuesObj[moduleName + "_VALUES"];  
118 var rpcs= sliValuesObj[moduleName + "_RPCS"];  
119 var nObj={};
120 nObj['moduleName'] = moduleName;
121 console.log("module.exports = ");
122 for(var i=0;i<a.length;i++){
123         var key =a[i].substring(0,a[i].indexOf(':'));
124         //console.log(key);
125         var value =a[i].substring(a[i].indexOf(':') +1);
126         if(value == undefined) value ="";
127         dotToJson(key,value,nObj);
128 }
129
130 nObj[moduleName + "_PROPS"] =[];
131 for(var i=0;i<a.length;i++){
132         var key =a[i].substring(0,a[i].indexOf(':'));
133         nObj[moduleName + "_PROPS"].push(key);
134 }
135
136 nObj[moduleName + "_RPCS"] = rpcs;
137
138 console.log(JSON.stringify(nObj,null,4));

© 2017 ONAP. Copyright © The Linux Foundation ®. All Rights Reserved.
The Linux Foundation has registered trademarks and uses trademarks.
For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.
Linux is a registered trademark of Linus Torvalds.
Privacy Policy and Terms of Use