-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathgenerated_data.js
More file actions
106 lines (93 loc) · 3.12 KB
/
generated_data.js
File metadata and controls
106 lines (93 loc) · 3.12 KB
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
var fs = require('fs-extra');
var setDocDefaults = require('./set_doc_defaults');
var changeCase = require('change-case');
var removePointerReferences = function(text) {
if (!text) return '';
text = text.replace(/a pointer to /ig, '');
text = text.replace(/pointer where to store /ig, '');
text = text.match(/pointer/i) ? '' : text; // Better to ignore pointer text
return text;
}
var sanitizeArgName = function(className, comment) {
var argName = changeCase.camelCase(className);
if (argName == 'number') {
argName = 'result';
}
return argName;
}
var generatedData = function(path, missingTestsPath) {
var apiData = {};
var generatedJSON = fs.readJsonSync(path);
if (missingTestsPath) {
var missingTests = fs.readJsonSync(missingTestsPath);
}
generatedJSON.forEach(function(item) {
switch (item.type) {
case 'class':
case 'struct':
var obj = setDocDefaults(apiData, item.jsClassName);
obj.type = item.type
obj.hasConstructor = item.hasConstructor || false
item.functions.forEach(function(func) {
data = {
params: [],
fires: [],
return: {
type: func.return.jsClassName,
name: sanitizeArgName(func.return.jsClassName, func.return.comment),
description: removePointerReferences(func.return.comment)
},
isAsync: func.isAsync,
description: "",
experimental: false,
}
if (missingTests) {
if (!missingTests[item.filename] || missingTests[item.filename].testFileMissing === false) {
data.experimental = true;
} else {
if (missingTests[item.filename].functions.indexOf(item.jsClassName) != -1) {
data.experimental = true;
}
}
}
func.args.forEach(function(arg) {
if (arg.isReturn) {
data.return = {
name: sanitizeArgName(arg.jsClassName, arg.comment),
type: arg.jsClassName,
description: removePointerReferences(arg.comment)
};
} else if (!arg.ignore && !arg.isSelf) {
data.params.push({
"name": arg.name,
"types": [arg.jsClassName],
"description": arg.comment,
"optional": arg.isOptional || false
});
}
});
if (func.isPrototypeMethod) {
obj.prototypes[func.jsFunctionName] = data
} else {
obj.constructors[func.jsFunctionName] = data
}
});
item.fields.forEach(function(field) {
obj.fields[field.jsFunctionName] = {
'type': field.jsClassName,
'description' : field.comments
};
});
break;
case 'enum':
obj = setDocDefaults(apiData, item.owner);
var list = obj.enums[item.JsName] = {}
item.values.forEach(function(value) {
list[value.JsName] = value.value;
});
break;
}
});
return apiData;
}
module.exports = generatedData;