-
Notifications
You must be signed in to change notification settings - Fork 5
/
ewcJsonDescriptorsGenerator.js
161 lines (138 loc) · 4.47 KB
/
ewcJsonDescriptorsGenerator.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
fs = require('fs');
var path = require('path');
const generateJSONDescriptorForElement = (doxiObj) => {
const widget = {
"name": doxiObj.name,
"selector": doxiObj.name.replace('.', '-').toLowerCase(),
"description": doxiObj.text
}
//Create Properties
const properties = [];
const events = [];
const methods = [];
let superClass = [];
if (doxiObj.extends) {
superClass = doxiObj.extends.split(',');
}
if (doxiObj.items) {
const doxiPropertiesItems = doxiObj.items.filter(item => item[`$type`] == 'properties');
if (doxiPropertiesItems.length > 0) {
const doxiProperties = doxiPropertiesItems[0].items;
doxiProperties.forEach(doxiProp => {
properties.push({
"name": doxiProp.name,
"type": doxiProp.type ? doxiProp.type.toLowerCase() : '',
"value": doxiProp.value,
"allowedValues": [],
"description": doxiProp.text,
"demoValues": []
})
})
}
//Using Configs
const doxiConfigItems = doxiObj.items.filter(item => item[`$type`] == 'configs');
if (doxiConfigItems.length > 0) {
const doxiProperties = doxiConfigItems[0].items.filter(x => x[`$type`] == "property");
doxiProperties.forEach(doxiProp => {
properties.push({
"name": doxiProp.name,
"type": doxiProp.type ? doxiProp.type.toLowerCase() : '',
"value": doxiProp.value,
"allowedValues": [],
"description": doxiProp.text,
"demoValues": []
})
})
}
//Create Events
const doxiEventsItems = doxiObj.items.filter(item => item[`$type`] == 'events');
if (doxiEventsItems.length > 0) {
const doxiEvents = doxiEventsItems[0].items;
doxiEvents.forEach(doxiEvent => {
const event = {
"name": doxiEvent.name,
"description": doxiEvent.text,
"demo": "events"
}
if (doxiEvent.items && doxiEvent.items.length > 0) {
event.detail = [];
doxiEvent.items.forEach(doxiEventParam => {
event.detail.push({
"name": doxiEventParam.name,
"description": doxiEventParam.text
})
})
}
events.push(event);
})
}
//create Methods
const doxiMethodsItems = doxiObj.items.filter(item => item[`$type`] == 'methods');
if (doxiMethodsItems.length > 0) {
const doxiMethods = doxiMethodsItems[0].items;
doxiMethods.forEach(doxiMethod => {
const method = {
"name": doxiMethod.name,
"description": doxiMethod.text ? doxiMethod.name : "",
"demoValues": [],
"returnDataType": null,
"demo": "methods"
}
if (doxiMethod.items && doxiMethod.items.length > 0) {
method.arguments = [];
const returnArgument = doxiMethod.items.filter(x => x['$type'] == 'return');
const params = doxiMethod.items.filter(x => x['$type'] != 'return');
if (returnArgument.length > 0) {
method.returnDataType = returnArgument[0].type;
}
params.forEach(param => {
method.arguments.push({
"name": param.name,
"type": param.type ? param.type : "",
"description": param.text ? param.text : "",
"optional": false
})
})
}
methods.push(method);
})
}
}
const jsonDescriptor = { superClass, widget, properties, events, methods };
//console.log(jsonDescriptor)
return jsonDescriptor;
}
const generateDescriptors = async (fileNameToProcess, outputFolder) => {
fs.readFile(fileNameToProcess, 'utf8', function (err, doxi) {
if (err) {
throw err;
}
const doxiJSON = doxi.toString();
const allElements = JSON.parse(doxiJSON);
const allDoxiElements = allElements.global.items.filter(x => x[`$type`] == 'class');
allDoxiElements.forEach(doxiObj => {
const json = generateJSONDescriptorForElement(doxiObj);
fs.writeFile(__dirname + `/${outputFolder}/${json.widget.name}.json`, JSON.stringify(json, null, 4), function (err, result) {
if (err) console.log('error', err);
});
})
})
}
const main = () => {
const extTheme = process.argv[2];
if (!extTheme) {
return console.error('Specify theme(modern or classic) as third argument.');
}
const outputFolder = `EWC_${extTheme}_Json_Descriptors`;
var outputDirPath = path.join(__dirname, outputFolder);
if (!fs.existsSync(outputDirPath)) {
fs.mkdirSync(outputDirPath);
}
const doxiPath = extTheme === 'classic' ? path.join(__dirname, 'AllClassesFiles', 'docs', 'classic', 'classic-all-classes-flatten.json') : path.join(__dirname, 'AllClassesFiles', 'docs', 'modern', 'modern-all-classes-flatten.json');
generateDescriptors(doxiPath, outputFolder).then(() => {
console.log('Job Completed.');
}).catch(e => {
console.error(e);
});
}
main();