Skip to content

Commit af1345c

Browse files
committed
Improve d.ts comments generation
-Improve the script to clean the different kinds of end of line -Improve the alignement with @return multiline comments -Add a jsdoc plugin to convert the class name of p2.js file, like this the comments for the p2 classes are now included in the d.ts files.
1 parent a5fde63 commit af1345c

5 files changed

Lines changed: 1489 additions & 420 deletions

File tree

tasks/buildtsdoc.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ var TypeScriptDocGenerator = (function () {
1818
this.sourceUnit = this.tree.sourceUnit();
1919
this.lineMap = this.tree.lineMap();
2020
}
21+
TypeScriptDocGenerator.prototype.cleanEndLine = function (str) {
22+
return str.replace(new RegExp('[' + "\r\n" + ']', 'g'), "\n").replace(new RegExp('[' + "\r" + ']', 'g'), "\n");
23+
};
2124
TypeScriptDocGenerator.prototype.completePrefix = function (oldPrefix, appendedPrefix) {
2225
if (oldPrefix === "") {
2326
return appendedPrefix;
@@ -54,11 +57,11 @@ var TypeScriptDocGenerator = (function () {
5457
var lc = this.lineMap.getLineAndCharacterFromPosition(position);
5558
var nbSpaces = lc.character();
5659
var startLinePosition = this.lineMap.getLineStartPosition(lc.line());
57-
var comment = "\n" + this.repeatSpaces(nbSpaces) + "/**\n";
60+
var comment = "\r\n" + this.repeatSpaces(nbSpaces) + "/**\r\n";
5861
for (var j = 0; j < commentLines.length; j++) {
59-
comment += this.repeatSpaces(nbSpaces) + "* " + commentLines[j] + "\n";
62+
comment += this.repeatSpaces(nbSpaces) + "* " + commentLines[j].trim() + "\r\n";
6063
}
61-
comment += this.repeatSpaces(nbSpaces) + "*/\n";
64+
comment += this.repeatSpaces(nbSpaces) + "*/\r\n";
6265
this.tsDefFileContent = this.tsDefFileContent.substr(0, startLinePosition + this.nbCharsAdded) + comment + this.tsDefFileContent.substr(startLinePosition + this.nbCharsAdded);
6366
this.nbCharsAdded += comment.length;
6467
}
@@ -80,7 +83,7 @@ var TypeScriptDocGenerator = (function () {
8083
if (c.members[i].name === memberName) {
8184
var m = c.members[i];
8285
var comments = [];
83-
comments = comments.concat(m.description.split("\n"));
86+
comments = comments.concat(this.cleanEndLine(m.description).split("\n"));
8487
if ((m.default != null) && (m.default !== "")) {
8588
comments.push("Default: " + m.default);
8689
}
@@ -96,7 +99,7 @@ var TypeScriptDocGenerator = (function () {
9699
var c = this.findClass(className);
97100
if (c != null) {
98101
var comments = [];
99-
comments = comments.concat(c.description.split("\n"));
102+
comments = comments.concat(this.cleanEndLine(c.description).split("\n"));
100103
return comments;
101104
}
102105
else {
@@ -108,7 +111,7 @@ var TypeScriptDocGenerator = (function () {
108111
if (c != null) {
109112
var con = c.constructor;
110113
var comments = [];
111-
comments = comments.concat(con.description.split("\n"));
114+
comments = comments.concat(this.cleanEndLine(con.description).split("\n"));
112115
if (con.parameters.length > 0) {
113116
comments.push("");
114117
}
@@ -121,7 +124,7 @@ var TypeScriptDocGenerator = (function () {
121124
if ((p.default != null) && (p.default !== "")) {
122125
def = " - Default: " + p.default;
123126
}
124-
var paramComments = p.description.split("\n");
127+
var paramComments = this.cleanEndLine(p.description).split("\n");
125128
for (var k = 0; k < paramComments.length; k++) {
126129
if (k === 0) {
127130
comments.push("@param " + p.name + " " + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
@@ -144,7 +147,7 @@ var TypeScriptDocGenerator = (function () {
144147
if (c.functions[i].name === functionName) {
145148
var f = c.functions[i];
146149
var comments = [];
147-
comments = comments.concat(f.description.split("\n"));
150+
comments = comments.concat(this.cleanEndLine(f.description).split("\n"));
148151
if (f.parameters.length > 0) {
149152
comments.push("");
150153
}
@@ -158,7 +161,7 @@ var TypeScriptDocGenerator = (function () {
158161
def = " - Default: " + p.default;
159162
}
160163

161-
var paramComments = p.description.split("\n");
164+
var paramComments = this.cleanEndLine(p.description).split("\n");
162165
for (var k = 0; k < paramComments.length; k++)
163166
{
164167
if (k === 0)
@@ -173,7 +176,16 @@ var TypeScriptDocGenerator = (function () {
173176

174177
}
175178
if (f.returns != null) {
176-
comments.push("@return " + f.returns.description);
179+
var returnComments = this.cleanEndLine(f.returns.description).split("\n");
180+
for (var l = 0; l < returnComments.length; l++) {
181+
if (l === 0) {
182+
comments.push("@return " + returnComments[l].trim());
183+
}
184+
else
185+
{
186+
comments.push(this.repeatSpaces(("@return ").length) + returnComments[l].trim());
187+
}
188+
}
177189
}
178190
return comments;
179191
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Add Phaser.Physics.P2 before the class name in the p2.js file
3+
*/
4+
var path = require('path');
5+
6+
exports.handlers = {};
7+
exports.handlers.newDoclet = function (e) {
8+
var doclet = e.doclet;
9+
10+
if ((doclet.meta.filename === "p2.js") && (doclet.kind === 'class' || doclet.kind === 'interface'))
11+
{
12+
doclet.longname = "Phaser.Physics.P2." + doclet.longname;
13+
}
14+
};

tasks/jsdocexportjson-conf.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"./tasks/jsdoc-plugins/namealias",
3131
"./tasks/jsdoc-plugins/filterpixi",
3232
"./tasks/jsdoc-plugins/proptomember",
33-
"./tasks/jsdoc-plugins/shortlinks"
33+
"./tasks/jsdoc-plugins/shortlinks",
34+
"./tasks/jsdoc-plugins/p2completeclass"
3435
],
3536
"markdown" : {
3637
"parser" : "gfm",

0 commit comments

Comments
 (0)