-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenItUtils.js
342 lines (278 loc) · 11.6 KB
/
genItUtils.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
exports.writeTemplateFile =(tplFile, outFile, vars) => {
require("./XTemplate");
var path = require("path");
var fs = require("fs-extra");
//var tpl = new Ext.XTemplate(fs.readFileSync(path.resolve(tplFile)).toString());
var tpl = new Ext.XTemplate(fs.readFileSync(tplFile));
//console.log(tplFile)
//console.log(path.resolve(tplFile)).toString()
var t = tpl.apply(vars);
fs.writeFileSync(outFile, t);
//console.log(outFile)
delete tpl;
}
exports.run = (parm, cwd) => {
var all = parm.split(' ')
var command = all[0]
var args = all.slice(1)
if (cwd == undefined) {cwd = process.cwd()}
return promise = new Promise((resolve, reject) => {
let options = {cwd: cwd, stdio: 'inherit', encoding: 'utf-8'}
//console.log(color(command + ' ' + args.toString().replace(',', ' ')) + ' in ' + cwd)
let child = require('child_process').spawn(command, args, options)
child.on('close', (code, signal) => {resolve({code, signal})})
child.on('error', (error) => {reject(error)})
})
}
function getItems(o, type) {
var array = o.items.filter(function(obj) {
return obj.$type == type;
});
if (array.length == 1) {
return array[0].items;
} else {
return [];
}
}
exports.doProperties = (o) => {
var doAllinXtype = true; //dont think this is needed
var sLocalPROPERTIES = `\n`;
//var sPROPERTIESOBJECT = `\n`;
var sGETSET = "";
var propertiesArray = []
// var configsArray = o.items.filter(function(obj) {return obj.$type == 'configs';});
// if (configsArray.length == 1) {
var haveResponsiveConfig = false;
var propertiesLocalDocs = `<div class="select-div"><select id="propertiesDocs" onchange="changeProperty()" name="propertiesDocs">\n`
getItems(o, "configs").forEach(function(config, index, array) {
var propertyLocalObj = {}
propertiesLocalDocs = propertiesLocalDocs + ` <option value="${config.text}">${config.name}</option>\n`
if (config.from == undefined || doAllinXtype == true) {
//configsArray[0].items.forEach(function (config, index, array) {
if (config.deprecatedMessage == undefined) {
sLocalPROPERTIES = `${sLocalPROPERTIES} '${config.name}',\n`;
var type = "";
if (config.type == undefined) {
//log('', `${xtype}${tb}${config.name}`)
type = "any";
} else {
type = config.type.replace(/"/g, "'");
}
if (config.name == "responsiveConfig") {
haveResponsiveConfig = true;
}
var typeArray = type.split("/");
var s = "[";
var i = 0;
typeArray.forEach(function(currentValue, index, arr) {
var comma = "";
if (i > 0) {
comma = ",";
}
i++;
var newVal;
if (currentValue.startsWith("Ext.")) {
newVal = currentValue;
} else {
newVal = currentValue.toLowerCase();
}
s = s + `${comma}"${newVal}"`;
});
s = s + `]`;
propertyLocalObj.text = config.text
propertyLocalObj.name = config.name
//sPROPERTIESOBJECT = `${sPROPERTIESOBJECT}"${config.name}":${s},\n`;
// sGETSET =
// sGETSET +
// tab +
// `get ${config.name}(){return this.getAttribute('${config.name}')};
// set ${config.name}(${config.name}){this.setAttribute('${config.name}',${config.name})}\n`;
}
}
propertiesArray.push(propertyLocalObj)
});
// sLocalPROPERTIES = `${sPROPERTIES}${tab}${tab}'platformConfig',\n`;
// if (haveResponsiveConfig == false) {
// sLocalPROPERTIES = `${sPROPERTIES}${tab}${tab}'responsiveConfig',\n`;
// }
//sLocalPROPERTIES = `${sPROPERTIES}'align',\n`;
// sLocalPROPERTIES = `${sPROPERTIES}${tab}${tab}'fitToParent',\n`;
// sLocalPROPERTIES = `${sPROPERTIES}${tab}${tab}'tab',\n`;
// sLocalPROPERTIES = `${sPROPERTIES}${tab}${tab}'config'\n`;
// sPROPERTIESOBJECT = `${sPROPERTIESOBJECT}"platformConfig": "Object",\n`;
// if (haveResponsiveConfig == false) {
// sPROPERTIESOBJECT = `${sPROPERTIESOBJECT}"responsiveConfig": "Object",\n`;
// }
// //sPROPERTIESOBJECT = `${sPROPERTIESOBJECT}"align": "Object",\n`;
// sPROPERTIESOBJECT = `${sPROPERTIESOBJECT}"tab": "Object",\n`;
// sPROPERTIESOBJECT = `${sPROPERTIESOBJECT}"fitToParent": "Boolean",\n`;
// sPROPERTIESOBJECT = `${sPROPERTIESOBJECT}"config": "Object",\n`;
var eventName = "";
eventName = "platformConfig";
// sGETSET =
// sGETSET +
// tab +
// `get ${eventName}(){return this.getAttribute('${eventName}')};set ${eventName}(${eventName}){this.setAttribute('${eventName}',${eventName})}\n`;
// if (haveResponsiveConfig == false) {
// eventName = "responsiveConfig";
// sGETSET =
// sGETSET +
// tab +
// `get ${eventName}(){return this.getAttribute('${eventName}')};set ${eventName}(${eventName}){this.setAttribute('${eventName}',${eventName})}\n`;
// }
// eventName = "align";
// sGETSET =
// sGETSET +
// tab +
// `get ${eventName}(){return this.getAttribute('${eventName}')};set ${eventName}(${eventName}){this.setAttribute('${eventName}',${eventName})}\n`;
// eventName = "fitToParent";
// sGETSET =
// sGETSET +
// tab +
// `get ${eventName}(){return this.getAttribute('${eventName}')};set ${eventName}(${eventName}){this.setAttribute('${eventName}',${eventName})}\n`;
// eventName = "config";
// sGETSET =
// sGETSET +
// tab +
// `get ${eventName}(){return this.getAttribute('${eventName}')};set ${eventName}(${eventName}){this.setAttribute('${eventName}',${eventName})}\n`;
//}
propertiesLocalDocs = propertiesLocalDocs + `</select></div>\n`
var propLocalNames = `['aMe', 'header', 'renderer', 'label','fitToParent','tab','config','platformConfig','extname','viewport','align','plugins','responsiveConfig','responsiveFormulas',`
propertiesArray.forEach(property => {
//info.propNames.push(property.name)
propLocalNames = propLocalNames + `'${property.name}',`
})
propLocalNames = propLocalNames + `]`
var o = {};
o.propNames = propLocalNames;
o.propertiesDocs = propertiesLocalDocs;
o.sPROPERTIES = sLocalPROPERTIES;
//o.sPROPERTIESOBJECT = sPROPERTIESOBJECT;
//o.sGETSETPROPERTIES = sGETSET;
o.propertiesArray = propertiesArray;
return o;
}
exports.doMethods = (o) => {
var methodsLocalDocs = `<div class="select-div"><select id="methodsDocs" onchange="changeMethod()" name="methodsDocs">\n`
var sLocalMETHODS = "";
var methodsArray = []
getItems(o, "methods").forEach(function(method, index, array) {
var methodObj = {}
methodsLocalDocs = methodsLocalDocs + ` <option value="${method.text}">${method.name}</option>\n`
if (method.from == undefined) {
sLocalMETHODS = sLocalMETHODS + ' ' + ' ' + "{ name:'" + method.name + "', function: function"
// sLocalMETHODS =
// sLocalMETHODS +
// tab +
// tab +
// "{ name:'" +
// method.name +
// "',function: function";
var sItems = "";
if (method.items !== undefined) {
var arrayLength = method.items.length;
for (var i = 0; i < arrayLength; i++) {
if (method.items[i].$type == "param") {
if (i == arrayLength-1){commaOrBlank= ''} else {commaOrBlank= ','};
// if (i == arrayLength - 1) {
// commaOrBlank = "";
// } else {
// commaOrBlank = ",";
// }
sItems = sItems + method.items[i].name + ",";
}
}
}
sItems = sItems.substring(0, sItems.length - 1);
sLocalMETHODS = sLocalMETHODS + "(" + sItems + ") { return this.ext." + method.name + "(" + sItems + ") } },\n";
methodObj.text = method.text
methodObj.name = method.name
methodObj.items = sItems
methodsArray.push(methodObj)
}
// sLocalMETHODS =
// sLocalMETHODS +
// "(" +
// sItems +
// ") { return this.ext." +
// method.name +
// "(" +
// sItems +
// ") } },\n";
});
methodsLocalDocs = methodsLocalDocs + `</select></div>\n`
var o = {};
o.methodsDocs = methodsLocalDocs;
o.sMETHODS = sLocalMETHODS;
o.methodsArray = methodsArray;
return o;
}
exports.doEvents = (o) => {
var eventsLocalDocs = `<div class="select-div"><select id="eventsDocs" onchange="changeEvent()" name="eventsDocs">\n`
var sLocalEVENTS = `\n`;
var sLocalEVENTNAMES = `\n`;
//var sEVENTSGETSET = "";
var eventsLocalArray = []
getItems(o, "events").forEach(function(event, index, array) {
//console.log(event)
var eventObj = {}
eventObj.name = event.name
eventObj.text = event.text
eventObj.parameters = []
eventsLocalDocs = eventsLocalDocs + ` <option value="${event.text}">${event.name}</option>\n`
if (event.name == undefined) {
var s = event.inheritdoc;
event.name = s.substr(s.indexOf("#") + 1);
}
//if (event.name == 'tap') { event.name = 'tapit' };
var eventName = "on" + event.name;
// sEVENTSGETSET =
// sEVENTSGETSET +
// tab +
// `get ${eventName}(){return this.getAttribute('${eventName}')};set ${eventName}(${eventName}){this.setAttribute('${eventName}',${eventName})}\n`;
sLocalEVENTS =
sLocalEVENTS + ' ' + ' ' + "{name:'" + event.name + "', parameters:'";
sLocalEVENTNAMES =
sLocalEVENTNAMES + ' ' + ' ' + "'" + event.name + "'" + "," + '\n';
//if (event.name == 'tap') {console.log(event.items) };
if (event.items != undefined) {
event.items.forEach(function(parameter, index, array) {
if (parameter == undefined) {
return
}
if (index == array.length - 1) {
commaOrBlank = "";
} else {
commaOrBlank = ",";
}
if (parameter.name == "this") {
//if (event.name == 'tap') {console.log(o) };
parameter.name = 'sender'; //o.xtype;
}
sLocalEVENTS = sLocalEVENTS + parameter.name + commaOrBlank;
eventObj.parameters.push(parameter.name)
});
}
sLocalEVENTS = sLocalEVENTS + "'}" + "," + '\n';
eventsLocalArray.push(eventObj)
});
eventsLocalDocs = eventsLocalDocs + `</select></div>\n`
sLocalEVENTS = sLocalEVENTS + ` {name:'ready', parameters:'cmp,cmpObj'},\n` + ` {name:'created', parameters:'cmp'}\n`;
sLocalEVENTNAMES = sLocalEVENTNAMES + `'ready','created'\n`;
//sLocalEVENTS = sLocalEVENTS + ' ' + ' ' + "{name:'" +"ready" +"', parameters:'cmd,cmdAll'}" +"" + '\n';
//sLocalEVENTNAMES = sLocalEVENTNAMES + "'" + "ready" + "'" + "" + '\n';
var eventLocalNames = `['ready','created',`
eventsLocalArray.forEach(event => {
//info.propNames.push(property.name)
eventLocalNames = eventLocalNames + `'${event.name}',`
})
eventLocalNames = eventLocalNames + `]`
var o = {};
o.eventNames = eventLocalNames;
o.eventsDocs = eventsLocalDocs;
o.sEVENTS = sLocalEVENTS;
o.sEVENTNAMES = sLocalEVENTNAMES;
//o.sEVENTSGETSET = sEVENTSGETSET;
o.eventsArray = eventsLocalArray;
return o;
}