Skip to content

Commit 0077c79

Browse files
committed
initial commit
0 parents  commit 0077c79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+26711
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
generated
3+
doc

AceGitLinkPlugin.js

+261
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
var ConverterComponent = require("typedoc/dist/lib/converter/components").ConverterComponent;
2+
var Converter = require("typedoc/dist/lib/converter/converter").Converter;
3+
var fs = require("fs");
4+
var modelTypes = require("typedoc/dist/lib/models/types/index");
5+
var modelReflections = require("typedoc/dist/lib/models/reflections/index");
6+
7+
class AceGitLinkPlugin extends ConverterComponent {
8+
initialize() {
9+
this.listenTo(this.owner, Converter.EVENT_BEGIN, this.onBegin);
10+
this.logs = '';
11+
}
12+
13+
onBegin() {
14+
// read options parameter
15+
var options = this.application.options;
16+
var urlPrefix = options.getValue('acegitlink');
17+
if (urlPrefix) {
18+
this.urlPrefix = urlPrefix;
19+
}
20+
try {
21+
// register handler
22+
this.listenTo(this.owner, Converter.EVENT_RESOLVE_BEGIN, this.onBeginResolve);
23+
this.listenTo(this.owner, Converter.EVENT_RESOLVE_END, this.onEndResolve);
24+
}
25+
catch (e) {
26+
console.error('typedoc-plugin-sourcefile-url: ' + e.message);
27+
}
28+
}
29+
30+
onBeginResolve(context) {
31+
var project = context.project;
32+
for (var key in project.reflections) {
33+
var reflection = project.reflections[key];
34+
if (reflection.kind === 4096 && reflection.parent && reflection.parent.kind === 2048 && reflection.parent.parent && reflection.parent.parent.kind === 128) {
35+
if (!reflection.comment) {
36+
removeReflection(project, reflection.parent);
37+
this.logs = this.logs + "Warning: ignoring method without comment: " + reflection.name + ". Class: " + reflection.parent.parent.name + "\r\n";
38+
}
39+
}
40+
}
41+
};
42+
43+
onEndResolve(context) {
44+
var _this = this;
45+
var project = context.project;
46+
if (_this.urlPrefix) {
47+
var data = fs.readFileSync("generated/classes.json", "utf8");
48+
var classes = JSON.parse(data.toString());
49+
for (var key in project.reflections) {
50+
var reflection = project.reflections[key];
51+
if (reflection.sources) {
52+
reflection.sources.forEach(function (source) {
53+
if (source.file) {
54+
var obj = getSourceUrlFromFile(classes, reflection);
55+
if (obj) {
56+
if (obj.log) {
57+
source.url = _this.urlPrefix + obj.source + "#L" + obj.line;
58+
source.fileName = obj.source;
59+
source.line = obj.line;
60+
_this.logs = _this.logs + obj.log;
61+
} else {
62+
source.url = _this.urlPrefix + obj.source + "#L" + obj.line;
63+
source.fileName = obj.source;
64+
source.line = obj.line;
65+
}
66+
} else {
67+
if (reflection.inheritedFrom || reflection.implementationOf) {
68+
let condition = (reflection.inheritedFrom) ? "inheritedFrom" : "implementationOf";
69+
var objInh = getSourceUrlFromFile(classes, reflection[condition].reflection);
70+
if (objInh) {
71+
source.url = _this.urlPrefix + objInh.source + "#L" + objInh.line;
72+
source.fileName = objInh.source;
73+
source.line = objInh.line;
74+
}
75+
} else {
76+
source.fileName = undefined;
77+
source.line = '';
78+
}
79+
}
80+
}
81+
});
82+
}
83+
}
84+
fs.writeFileSync("generated/documentation.log", this.logs + _this.logs);
85+
}
86+
};
87+
88+
}
89+
90+
function getSourceUrlFromFile(aceObjects, reflection) {
91+
if (reflection.kindString === "Interface" || reflection.kindString === "Class") {
92+
var source = aceObjects[reflection.name];
93+
if (source && source.sourceName) {
94+
if (source.described) {
95+
return {
96+
"source": (source.sourceName.match(/lib\/ace(.)*/i)) ? source.sourceName.match(/lib\/ace(.)*/i)[0] : source.sourceName,
97+
"line": source.line
98+
};
99+
} else {
100+
return {
101+
"source": (source.sourceName.match(/lib\/ace(.)*/i)) ? source.sourceName.match(/lib\/ace(.)*/i)[0] : source.sourceName,
102+
"line": source.line,
103+
log: "No described class in classes.json: " + reflection.name + "\r\n"
104+
};
105+
}
106+
107+
}
108+
} else if (reflection.kindString === "Call signature" && reflection.parent && reflection.parent.kindString === "Method" && (reflection.parent.parent.kindString === "Interface" || reflection.parent.parent.kindString === "Class")) {
109+
if (aceObjects[reflection.parent.parent.name]) {
110+
var parentSource = aceObjects[reflection.parent.parent.name][reflection.name];
111+
if (parentSource && parentSource.sourceName) {
112+
if (parentSource.described) {
113+
return {
114+
"source": (parentSource.sourceName.match(/lib\/ace(.)*/i)) ? parentSource.sourceName.match(/lib\/ace(.)*/i)[0] : parentSource.sourceName,
115+
"line": parentSource.line
116+
};
117+
} else {
118+
if (!reflection.inheritedFrom && !reflection.implementationOf) {
119+
return {
120+
"source": (parentSource.sourceName.match(/lib\/ace(.)*/i)) ? parentSource.sourceName.match(/lib\/ace(.)*/i)[0] : parentSource.sourceName,
121+
"line": parentSource.line,
122+
log: "No described method in classes.json: " + reflection.name + ". Class:" + reflection.parent.parent.name + "\r\n"
123+
};
124+
}
125+
}
126+
}
127+
}
128+
} else if (reflection.kindString === "Event" && reflection.parent && reflection.parent.kindString === "Event" && (reflection.parent.parent.kindString === "Interface" || reflection.parent.parent.kindString === "Class")) {
129+
if (aceObjects[reflection.parent.parent.name]) {
130+
if (reflection.parameters && reflection.parameters.length > 0 && reflection.parameters[0].name === "name") {
131+
var eventName = reflection.parameters[0].type.value + '_event';
132+
var parentSource = aceObjects[reflection.parent.parent.name][eventName];
133+
if (parentSource && parentSource.sourceName) {
134+
if (parentSource.described) {
135+
return {
136+
"source": (parentSource.sourceName.match(/lib\/ace(.)*/i)) ? parentSource.sourceName.match(/lib\/ace(.)*/i)[0] : parentSource.sourceName,
137+
"line": parentSource.line
138+
};
139+
} else {
140+
if (!reflection.inheritedFrom && !reflection.implementationOf) {
141+
return {
142+
"source": (parentSource.sourceName.match(/lib\/ace(.)*/i)) ? parentSource.sourceName.match(/lib\/ace(.)*/i)[0] : parentSource.sourceName,
143+
"line": parentSource.line,
144+
log: "No described event in classes.json: " + eventName + ". Class:" + reflection.parent.parent.name + "\r\n"
145+
};
146+
}
147+
}
148+
}
149+
}
150+
}
151+
} else if (reflection.kindString === "Constructor signature" && reflection.parent && reflection.parent.kindString === "Constructor" && (reflection.parent.parent.kindString === "Interface" || reflection.parent.parent.kindString === "Class")) {
152+
if (aceObjects[reflection.parent.parent.name]) {
153+
var parentSource = aceObjects[reflection.parent.parent.name]["construct"];
154+
if (parentSource && parentSource.sourceName) {
155+
if (parentSource.described) {
156+
return {
157+
"source": (parentSource.sourceName.match(/lib\/ace(.)*/i)) ? parentSource.sourceName.match(/lib\/ace(.)*/i)[0] : parentSource.sourceName,
158+
"line": parentSource.line
159+
};
160+
} else {
161+
if (!reflection.inheritedFrom && !reflection.implementationOf) {
162+
return {
163+
"source": (parentSource.sourceName.match(/lib\/ace(.)*/i)) ? parentSource.sourceName.match(/lib\/ace(.)*/i)[0] : parentSource.sourceName,
164+
"line": parentSource.line,
165+
log: "No constructor in classes.json: " + reflection.name + ". Class:" + reflection.parent.parent.name + "\r\n"
166+
};
167+
}
168+
}
169+
}
170+
}
171+
} else if (reflection.kindString === "Property" && reflection.parent && (reflection.parent.kindString === "Interface" || reflection.parent.kindString === "Class")) {
172+
if (aceObjects[reflection.parent.name]) {
173+
var parentSource = aceObjects[reflection.parent.name][reflection.name + "_prop"];
174+
if (parentSource && parentSource.sourceName) {
175+
if (parentSource.described) {
176+
return {
177+
"source": (parentSource.sourceName.match(/lib\/ace(.)*/i)) ? parentSource.sourceName.match(/lib\/ace(.)*/i)[0] : parentSource.sourceName,
178+
"line": parentSource.line
179+
};
180+
} else {
181+
if (!reflection.inheritedFrom && !reflection.implementationOf) {
182+
return {
183+
"source": (parentSource.sourceName.match(/lib\/ace(.)*/i)) ? parentSource.sourceName.match(/lib\/ace(.)*/i)[0] : parentSource.sourceName,
184+
"line": parentSource.line,
185+
log: "No described property in classes.json: " + reflection.name + ". Class:" + reflection.parent.name + "\r\n"
186+
};
187+
}
188+
}
189+
}
190+
}
191+
}
192+
193+
}
194+
195+
function removeReflection(project, reflection) {
196+
reflection.traverse(function (child) {
197+
return removeReflection(project, child);
198+
});
199+
var parent = reflection.parent;
200+
parent.traverse(function (child, property) {
201+
if (child === reflection) {
202+
switch (property) {
203+
case modelReflections.TraverseProperty.Children:
204+
if (parent.children) {
205+
var index = parent.children.indexOf(reflection);
206+
if (index !== -1) {
207+
parent.children.splice(index, 1);
208+
}
209+
}
210+
break;
211+
case modelReflections.TraverseProperty.GetSignature:
212+
delete parent.getSignature;
213+
break;
214+
case modelReflections.TraverseProperty.IndexSignature:
215+
delete parent.indexSignature;
216+
break;
217+
case modelReflections.TraverseProperty.Parameters:
218+
if (reflection.parent.parameters) {
219+
var index = reflection.parent.parameters.indexOf(reflection);
220+
if (index !== -1) {
221+
reflection.parent.parameters.splice(index, 1);
222+
}
223+
}
224+
break;
225+
case modelReflections.TraverseProperty.SetSignature:
226+
delete parent.setSignature;
227+
break;
228+
case modelReflections.TraverseProperty.Signatures:
229+
if (parent.signatures) {
230+
var index = parent.signatures.indexOf(reflection);
231+
if (index !== -1) {
232+
parent.signatures.splice(index, 1);
233+
}
234+
}
235+
break;
236+
case modelReflections.TraverseProperty.TypeLiteral:
237+
parent.type = new modelTypes.IntrinsicType('Object');
238+
break;
239+
case modelReflections.TraverseProperty.TypeParameter:
240+
if (parent.typeParameters) {
241+
var index = parent.typeParameters.indexOf(reflection);
242+
if (index !== -1) {
243+
parent.typeParameters.splice(index, 1);
244+
}
245+
}
246+
break;
247+
}
248+
}
249+
});
250+
var id = reflection.id;
251+
delete project.reflections[id];
252+
for (var key in project.symbolMapping) {
253+
if (project.symbolMapping.hasOwnProperty(key) && project.symbolMapping[key] === id) {
254+
delete project.symbolMapping[key];
255+
}
256+
}
257+
};
258+
259+
AceGitLinkPlugin.prototype.componentName = "acegitlink";
260+
261+
exports.AceGitLinkPlugin = AceGitLinkPlugin;

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Ace documentation generator
2+
3+
requires node >= 8
4+
5+
```
6+
node generateAnnotations.js AceDirName/lib/ace
7+
```
8+
9+
Creates `classes.json` file in directory `generated`.
10+
There will be warnings in `generated\annotations.log` for duplicated classes\methods implementations from different files.
11+
12+
Apply `classes.json` file to declaration with command
13+
14+
```
15+
node generateNewDts.js ace.d.ts
16+
```
17+
18+
There will be some information in `generated\declarations.log` that you could use for improving declaration file. (Missing events, methods, constructors)
19+
20+
The final step will generate output documentation with TypeDoc.
21+
You will need to change `generateDoc.js` with your settings. Main parameters described in `https://typedoc.org/api/`
22+
23+
Important! Change `acegitlink` parameter with used Ace release link - for example: `https://github.com/ajaxorg/ace/tree/v1.4.2/`
24+
25+
```
26+
node generateDoc.js doc
27+
```
28+
29+
First parameter - output directory for documentation
30+
31+
Also log file will be created in `generated` dir with name `documentation.log`
32+
33+
34+
35+
```
36+
node generateAnnotations.js ace/lib/ace
37+
node generateNewDts.js ace.d.ts
38+
node generateDoc.js doc
39+
```

0 commit comments

Comments
 (0)