mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 20:53:39 +00:00
Rebuilt Phaser Comments TypeScript defs.
This commit is contained in:
parent
47f0224a40
commit
694debe94b
9 changed files with 41103 additions and 5768 deletions
|
@ -36,8 +36,8 @@
|
||||||
"typescript": {
|
"typescript": {
|
||||||
"definitions": [
|
"definitions": [
|
||||||
"typescript/p2.d.ts",
|
"typescript/p2.d.ts",
|
||||||
"typescript/phaser.d.ts",
|
"typescript/phaser.comments.d.ts",
|
||||||
"typescript/pixi.d.ts"
|
"typescript/pixi.comments.d.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,14 +43,14 @@
|
||||||
"grunt-text-replace": "^0.3.11",
|
"grunt-text-replace": "^0.3.11",
|
||||||
"jsdoc": "~3.3.0-alpha10",
|
"jsdoc": "~3.3.0-alpha10",
|
||||||
"load-grunt-config": "~0.7.2",
|
"load-grunt-config": "~0.7.2",
|
||||||
"typescript": "^1.4.1",
|
"typescript": "1.4.1",
|
||||||
"yuidocjs": "^0.3.50"
|
"yuidocjs": "^0.3.50"
|
||||||
},
|
},
|
||||||
"typescript": {
|
"typescript": {
|
||||||
"definitions": [
|
"definitions": [
|
||||||
"typescript/p2.d.ts",
|
"typescript/p2.d.ts",
|
||||||
"typescript/phaser.d.ts",
|
"typescript/phaser.comments.d.ts",
|
||||||
"typescript/pixi.d.ts"
|
"typescript/pixi.comments.d.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,215 +5,458 @@
|
||||||
|
|
||||||
var ts = require('typescript');
|
var ts = require('typescript');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var _grunt = null;
|
||||||
|
|
||||||
var TypeScriptDocGenerator = (function () {
|
var TypeScriptDocGenerator = (function () {
|
||||||
|
|
||||||
function TypeScriptDocGenerator(tsDefFileName, jsdocJsonFileName) {
|
function TypeScriptDocGenerator(tsDefFileName, jsdocJsonFileName) {
|
||||||
|
|
||||||
|
_grunt.log.writeln("TS Defs: " + tsDefFileName + " json: " + jsdocJsonFileName);
|
||||||
|
|
||||||
this.nbCharsAdded = 0;
|
this.nbCharsAdded = 0;
|
||||||
this.tsDefFileName = ts.normalizePath(tsDefFileName);
|
this.tsDefFileName = ts.normalizePath(tsDefFileName);
|
||||||
this.tsDefFileContent = fs.readFileSync(this.tsDefFileName, 'utf-8').toString();
|
this.tsDefFileContent = fs.readFileSync(this.tsDefFileName, 'utf-8').toString();
|
||||||
this.delintNodeFunction = this.delintNode.bind(this);
|
this.delintNodeFunction = this.delintNode.bind(this);
|
||||||
|
|
||||||
var jsonDocsFileContent = fs.readFileSync(jsdocJsonFileName, 'utf-8').toString();
|
var jsonDocsFileContent = fs.readFileSync(jsdocJsonFileName, 'utf-8').toString();
|
||||||
|
|
||||||
this.docs = JSON.parse(jsonDocsFileContent);
|
this.docs = JSON.parse(jsonDocsFileContent);
|
||||||
|
|
||||||
|
_grunt.log.writeln("json parsed");
|
||||||
|
|
||||||
var options = { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.AMD };
|
var options = { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.AMD };
|
||||||
var host = ts.createCompilerHost(options);
|
var host = ts.createCompilerHost(options);
|
||||||
var program = ts.createProgram([this.tsDefFileName], options, host);
|
var program = ts.createProgram([this.tsDefFileName], options, host);
|
||||||
|
|
||||||
this.sourceFile = program.getSourceFile(this.tsDefFileName);
|
this.sourceFile = program.getSourceFile(this.tsDefFileName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.getTsDefCommentedFileContent = function () {
|
TypeScriptDocGenerator.prototype.getTsDefCommentedFileContent = function () {
|
||||||
|
|
||||||
this.scan();
|
this.scan();
|
||||||
|
|
||||||
return this.tsDefFileContent;
|
return this.tsDefFileContent;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.repeatSpaces = function (nb) {
|
TypeScriptDocGenerator.prototype.repeatSpaces = function (nb) {
|
||||||
|
|
||||||
var res = "";
|
var res = "";
|
||||||
for (var i = 0; i < nb; i++) {
|
|
||||||
|
for (var i = 0; i < nb; i++)
|
||||||
|
{
|
||||||
res += " ";
|
res += " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.insertComment = function (commentLines, position) {
|
TypeScriptDocGenerator.prototype.insertComment = function (commentLines, position) {
|
||||||
if ((commentLines != null) && (commentLines.length > 0)) {
|
|
||||||
|
if ((commentLines != null) && (commentLines.length > 0))
|
||||||
|
{
|
||||||
var nbChars = 0;
|
var nbChars = 0;
|
||||||
for (var i = 0; i < commentLines.length; i++) {
|
|
||||||
|
for (var i = 0; i < commentLines.length; i++)
|
||||||
|
{
|
||||||
nbChars += commentLines[i].trim().length;
|
nbChars += commentLines[i].trim().length;
|
||||||
}
|
}
|
||||||
if (nbChars > 0) {
|
|
||||||
|
if (nbChars > 0)
|
||||||
|
{
|
||||||
var lc = this.sourceFile.getLineAndCharacterFromPosition(position);
|
var lc = this.sourceFile.getLineAndCharacterFromPosition(position);
|
||||||
var nbSpaces = lc.character - 1;
|
var nbSpaces = lc.character - 1;
|
||||||
var startLinePosition = this.sourceFile.getLineStarts()[lc.line - 1];
|
var startLinePosition = this.sourceFile.getLineStarts()[lc.line - 1];
|
||||||
var comment = "\r\n" + this.repeatSpaces(nbSpaces) + "/**\r\n";
|
var comment = "\r\n" + this.repeatSpaces(nbSpaces) + "/**\r\n";
|
||||||
for (var j = 0; j < commentLines.length; j++) {
|
|
||||||
|
for (var j = 0; j < commentLines.length; j++)
|
||||||
|
{
|
||||||
comment += this.repeatSpaces(nbSpaces) + "* " + commentLines[j].trimRight() + "\r\n";
|
comment += this.repeatSpaces(nbSpaces) + "* " + commentLines[j].trimRight() + "\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
comment += this.repeatSpaces(nbSpaces) + "*/\r\n";
|
comment += this.repeatSpaces(nbSpaces) + "*/\r\n";
|
||||||
|
|
||||||
this.tsDefFileContent = this.tsDefFileContent.substr(0, startLinePosition + this.nbCharsAdded) + comment + this.tsDefFileContent.substr(startLinePosition + this.nbCharsAdded);
|
this.tsDefFileContent = this.tsDefFileContent.substr(0, startLinePosition + this.nbCharsAdded) + comment + this.tsDefFileContent.substr(startLinePosition + this.nbCharsAdded);
|
||||||
this.nbCharsAdded += comment.length;
|
this.nbCharsAdded += comment.length;
|
||||||
|
|
||||||
|
// _grunt.log.writeln("comment: " + comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.cleanEndLine = function (str) {
|
TypeScriptDocGenerator.prototype.cleanEndLine = function (str) {
|
||||||
|
|
||||||
return str.replace(new RegExp('[' + "\r\n" + ']', 'g'), "\n").replace(new RegExp('[' + "\r" + ']', 'g'), "\n");
|
return str.replace(new RegExp('[' + "\r\n" + ']', 'g'), "\n").replace(new RegExp('[' + "\r" + ']', 'g'), "\n");
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.findClass = function (className) {
|
TypeScriptDocGenerator.prototype.findClass = function (className) {
|
||||||
if (className.indexOf("p2.") === 0) {
|
|
||||||
|
// _grunt.log.writeln("findClass: " + className);
|
||||||
|
|
||||||
|
if (className.indexOf("p2.") === 0)
|
||||||
|
{
|
||||||
className = className.replace("p2.", "Phaser.Physics.P2.");
|
className = className.replace("p2.", "Phaser.Physics.P2.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var elements = this.docs.classes.filter(function (element) {
|
var elements = this.docs.classes.filter(function (element) {
|
||||||
return (element.name === className);
|
return (element.name === className);
|
||||||
});
|
});
|
||||||
|
|
||||||
return elements[0];
|
return elements[0];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.generateClassComments = function (className) {
|
TypeScriptDocGenerator.prototype.generateClassComments = function (className) {
|
||||||
|
|
||||||
|
// _grunt.log.writeln("generateClassComments: " + className);
|
||||||
|
|
||||||
var c = this.findClass(className);
|
var c = this.findClass(className);
|
||||||
if (c != null) {
|
|
||||||
|
// _grunt.log.writeln("generateClassComments class found: " + JSON.stringify(c));
|
||||||
|
|
||||||
|
if (c !== null && c !== undefined)
|
||||||
|
{
|
||||||
var comments = [];
|
var comments = [];
|
||||||
comments = comments.concat(this.cleanEndLine(c.description).split("\n"));
|
comments = comments.concat(this.cleanEndLine(c.description).split("\n"));
|
||||||
|
// _grunt.log.writeln("generateClassComments return comments");
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
|
// _grunt.log.writeln("generateClassComments return null");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.generateMemberComments = function (className, memberName) {
|
TypeScriptDocGenerator.prototype.generateMemberComments = function (className, memberName) {
|
||||||
|
|
||||||
|
_grunt.log.writeln("generateMemberComments: " + className + " = " + memberName);
|
||||||
|
|
||||||
var c = this.findClass(className);
|
var c = this.findClass(className);
|
||||||
if (c != null) {
|
|
||||||
for (var i = 0; i < c.members.length; i++) {
|
if (c !== null)
|
||||||
if (c.members[i].name === memberName) {
|
{
|
||||||
|
for (var i = 0; i < c.members.length; i++)
|
||||||
|
{
|
||||||
|
if (c.members[i].name === memberName)
|
||||||
|
{
|
||||||
var m = c.members[i];
|
var m = c.members[i];
|
||||||
var comments = [];
|
var comments = [];
|
||||||
comments = comments.concat(this.cleanEndLine(m.description).split("\n"));
|
comments = comments.concat(this.cleanEndLine(m.description).split("\n"));
|
||||||
if ((m.default != null) && (m.default !== "")) {
|
|
||||||
|
if ((m.default != null) && (m.default !== ""))
|
||||||
|
{
|
||||||
comments.push("Default: " + m.default);
|
comments.push("Default: " + m.default);
|
||||||
}
|
}
|
||||||
|
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.generateFunctionComments = function (className, functionName) {
|
TypeScriptDocGenerator.prototype.generateFunctionComments = function (className, functionName) {
|
||||||
|
|
||||||
|
_grunt.log.writeln("generateFunctionComments: " + className);
|
||||||
|
|
||||||
var c = this.findClass(className);
|
var c = this.findClass(className);
|
||||||
if (c != null) {
|
|
||||||
for (var i = 0; i < c.functions.length; i++) {
|
if (c !== null)
|
||||||
if (c.functions[i].name === functionName) {
|
{
|
||||||
|
for (var i = 0; i < c.functions.length; i++)
|
||||||
|
{
|
||||||
|
if (c.functions[i].name === functionName)
|
||||||
|
{
|
||||||
var f = c.functions[i];
|
var f = c.functions[i];
|
||||||
var comments = [];
|
var comments = [];
|
||||||
comments = comments.concat(this.cleanEndLine(f.description).split("\n"));
|
comments = comments.concat(this.cleanEndLine(f.description).split("\n"));
|
||||||
if (f.parameters.length > 0) {
|
|
||||||
|
if (f.parameters.length > 0)
|
||||||
|
{
|
||||||
comments.push("");
|
comments.push("");
|
||||||
}
|
}
|
||||||
for (var j = 0; j < f.parameters.length; j++) {
|
|
||||||
|
for (var j = 0; j < f.parameters.length; j++)
|
||||||
|
{
|
||||||
var p = f.parameters[j];
|
var p = f.parameters[j];
|
||||||
if (p.type === "*") {
|
|
||||||
|
if (p.type === "*")
|
||||||
|
{
|
||||||
p.name = "args";
|
p.name = "args";
|
||||||
}
|
}
|
||||||
|
|
||||||
var def = "";
|
var def = "";
|
||||||
if ((p.default != null) && (p.default !== "")) {
|
|
||||||
|
if ((p.default != null) && (p.default !== ""))
|
||||||
|
{
|
||||||
def = " - Default: " + p.default;
|
def = " - Default: " + p.default;
|
||||||
}
|
}
|
||||||
|
|
||||||
var paramComments = this.cleanEndLine(p.description).split("\n");
|
var paramComments = this.cleanEndLine(p.description).split("\n");
|
||||||
for (var k = 0; k < paramComments.length; k++) {
|
|
||||||
if (k === 0) {
|
for (var k = 0; k < paramComments.length; k++)
|
||||||
|
{
|
||||||
|
if (k === 0)
|
||||||
|
{
|
||||||
comments.push("@param " + p.name + " " + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
comments.push("@param " + p.name + " " + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
comments.push(this.repeatSpaces(("@param " + p.name + " ").length) + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
comments.push(this.repeatSpaces(("@param " + p.name + " ").length) + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((f.returns != null) && (f.returns.description.trim().length > 0)) {
|
|
||||||
|
if ((f.returns != null) && (f.returns.description.trim().length > 0))
|
||||||
|
{
|
||||||
var returnComments = this.cleanEndLine(f.returns.description).split("\n");
|
var returnComments = this.cleanEndLine(f.returns.description).split("\n");
|
||||||
for (var l = 0; l < returnComments.length; l++) {
|
|
||||||
if (l === 0) {
|
for (var l = 0; l < returnComments.length; l++)
|
||||||
|
{
|
||||||
|
if (l === 0)
|
||||||
|
{
|
||||||
comments.push("@return " + returnComments[l].trim());
|
comments.push("@return " + returnComments[l].trim());
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
comments.push(this.repeatSpaces(("@return ").length) + returnComments[l].trim());
|
comments.push(this.repeatSpaces(("@return ").length) + returnComments[l].trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.generateConstructorComments = function (className) {
|
TypeScriptDocGenerator.prototype.generateConstructorComments = function (className) {
|
||||||
|
|
||||||
|
_grunt.log.writeln("generateConstructorComments: " + className);
|
||||||
|
|
||||||
var c = this.findClass(className);
|
var c = this.findClass(className);
|
||||||
if (c != null) {
|
|
||||||
|
if (c !== null)
|
||||||
|
{
|
||||||
|
// _grunt.log.writeln("Class: " + c);
|
||||||
|
|
||||||
var con = c.constructor;
|
var con = c.constructor;
|
||||||
var comments = [];
|
var comments = [];
|
||||||
|
|
||||||
comments = comments.concat(this.cleanEndLine(con.description).split("\n"));
|
comments = comments.concat(this.cleanEndLine(con.description).split("\n"));
|
||||||
if (con.parameters.length > 0) {
|
|
||||||
|
if (con.parameters.length > 0)
|
||||||
|
{
|
||||||
comments.push("");
|
comments.push("");
|
||||||
}
|
}
|
||||||
for (var j = 0; j < con.parameters.length; j++) {
|
|
||||||
|
for (var j = 0; j < con.parameters.length; j++)
|
||||||
|
{
|
||||||
var p = con.parameters[j];
|
var p = con.parameters[j];
|
||||||
if (p.type === "*") {
|
|
||||||
|
if (p.type === "*")
|
||||||
|
{
|
||||||
p.name = "args";
|
p.name = "args";
|
||||||
}
|
}
|
||||||
|
|
||||||
var def = "";
|
var def = "";
|
||||||
if ((p.default != null) && (p.default !== "")) {
|
|
||||||
|
if ((p.default != null) && (p.default !== ""))
|
||||||
|
{
|
||||||
def = " - Default: " + p.default;
|
def = " - Default: " + p.default;
|
||||||
}
|
}
|
||||||
|
|
||||||
var paramComments = this.cleanEndLine(p.description).split("\n");
|
var paramComments = this.cleanEndLine(p.description).split("\n");
|
||||||
for (var k = 0; k < paramComments.length; k++) {
|
|
||||||
if (k === 0) {
|
for (var k = 0; k < paramComments.length; k++)
|
||||||
|
{
|
||||||
|
if (k === 0)
|
||||||
|
{
|
||||||
comments.push("@param " + p.name + " " + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
comments.push("@param " + p.name + " " + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
comments.push(this.repeatSpaces(("@param " + p.name + " ").length) + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
comments.push(this.repeatSpaces(("@param " + p.name + " ").length) + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return comments;
|
return comments;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.scan = function () {
|
TypeScriptDocGenerator.prototype.scan = function () {
|
||||||
|
|
||||||
this.delintNode(this.sourceFile);
|
this.delintNode(this.sourceFile);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.getClassName = function (node) {
|
TypeScriptDocGenerator.prototype.getClassName = function (node) {
|
||||||
|
|
||||||
|
// _grunt.log.writeln("getClassName: " + JSON.stringify(node));
|
||||||
|
// _grunt.log.writeln("getClassName: " + JSON.stringify(node.kind));
|
||||||
|
// _grunt.log.writeln("getClassName: " + JSON.stringify(node.name));
|
||||||
|
|
||||||
var fullName = '';
|
var fullName = '';
|
||||||
if (node.kind === ts.SyntaxKind.ClassDeclaration) {
|
|
||||||
|
if (node.name !== undefined && node.kind === ts.SyntaxKind.ClassDeclaration)
|
||||||
|
{
|
||||||
|
// _grunt.log.writeln("getClassName 1a: " + node.name.text);
|
||||||
|
|
||||||
|
try {
|
||||||
fullName = node.name.getText();
|
fullName = node.name.getText();
|
||||||
|
// _grunt.log.writeln("getClassName 1b: " + fullName);
|
||||||
}
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
fullName = node.name.text;
|
||||||
|
// _grunt.log.writeln("getClassName bail");
|
||||||
|
// return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var parent = node.parent;
|
var parent = node.parent;
|
||||||
while (parent != null) {
|
|
||||||
if (parent.kind === ts.SyntaxKind.ModuleDeclaration || parent.kind === ts.SyntaxKind.ClassDeclaration) {
|
while (parent !== null && parent !== undefined)
|
||||||
|
{
|
||||||
|
// _grunt.log.writeln("getClassName 2");
|
||||||
|
|
||||||
|
if (parent.kind === ts.SyntaxKind.ModuleDeclaration || parent.kind === ts.SyntaxKind.ClassDeclaration)
|
||||||
|
{
|
||||||
fullName = parent.name.getText() + ((fullName !== '') ? "." + fullName : fullName);
|
fullName = parent.name.getText() + ((fullName !== '') ? "." + fullName : fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent = parent.parent;
|
parent = parent.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fullName === undefined || fullName === null)
|
||||||
|
{
|
||||||
|
fullName = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// _grunt.log.writeln("getClassName: " + fullName);
|
||||||
|
|
||||||
return fullName;
|
return fullName;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.delintNode = function (node) {
|
TypeScriptDocGenerator.prototype.delintNode = function (node) {
|
||||||
switch (node.kind) {
|
|
||||||
|
var c = this.getClassName(node);
|
||||||
|
|
||||||
|
var r = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
r = node.getStart();
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
r = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (node.kind)
|
||||||
|
{
|
||||||
case ts.SyntaxKind.Constructor:
|
case ts.SyntaxKind.Constructor:
|
||||||
this.insertComment(this.generateConstructorComments(this.getClassName(node)), node.getStart());
|
// _grunt.log.writeln("insert1: " + node);
|
||||||
|
|
||||||
|
if (c !== '' && r)
|
||||||
|
{
|
||||||
|
this.insertComment(this.generateConstructorComments(c, r));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ts.SyntaxKind.ClassDeclaration:
|
case ts.SyntaxKind.ClassDeclaration:
|
||||||
this.insertComment(this.generateClassComments(this.getClassName(node)), node.getStart());
|
// _grunt.log.writeln("insertX2: " + JSON.stringify(node));
|
||||||
|
// _grunt.log.writeln("insertX2a: " + JSON.stringify(node.name));
|
||||||
|
// _grunt.log.writeln("insertX2b: " + this.getClassName(node));
|
||||||
|
// _grunt.log.writeln("insertX2c: " + r);
|
||||||
|
// _grunt.log.writeln("insertX2d ...");
|
||||||
|
|
||||||
|
if (c !== '' && r)
|
||||||
|
{
|
||||||
|
this.insertComment(this.generateClassComments(c, r));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ts.SyntaxKind.Property:
|
case ts.SyntaxKind.Property:
|
||||||
this.insertComment(this.generateMemberComments(this.getClassName(node), node.name.getText()), node.getStart());
|
// _grunt.log.writeln("insert3: " + node);
|
||||||
|
|
||||||
|
var t = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
t = node.name.getText();
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
t = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c !== '' && r && t)
|
||||||
|
{
|
||||||
|
this.insertComment(this.generateMemberComments(c, t, r));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ts.SyntaxKind.Method:
|
case ts.SyntaxKind.Method:
|
||||||
this.insertComment(this.generateFunctionComments(this.getClassName(node), node.name.getText()), node.getStart());
|
// _grunt.log.writeln("insert4: " + node);
|
||||||
|
|
||||||
|
var t = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
t = node.name.getText();
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
t = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c !== '' && r && t)
|
||||||
|
{
|
||||||
|
this.insertComment(this.generateFunctionComments(c, t, r));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ts.forEachChild(node, this.delintNodeFunction);
|
ts.forEachChild(node, this.delintNodeFunction);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return TypeScriptDocGenerator;
|
return TypeScriptDocGenerator;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
module.exports = function (grunt) {
|
module.exports = function (grunt) {
|
||||||
|
|
||||||
|
_grunt = grunt;
|
||||||
|
|
||||||
grunt.registerMultiTask('buildtsdoc', 'Generate a TypeScript def with comments', function () {
|
grunt.registerMultiTask('buildtsdoc', 'Generate a TypeScript def with comments', function () {
|
||||||
var tsdg = new TypeScriptDocGenerator(this.data.tsDefFileName, this.data.jsdocJsonFileName);
|
var tsdg = new TypeScriptDocGenerator(this.data.tsDefFileName, this.data.jsdocJsonFileName);
|
||||||
fs.writeFileSync(this.data.dest, tsdg.getTsDefCommentedFileContent(), 'utf8');
|
fs.writeFileSync(this.data.dest, tsdg.getTsDefCommentedFileContent(), 'utf8');
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
|
@ -5,458 +5,215 @@
|
||||||
|
|
||||||
var ts = require('typescript');
|
var ts = require('typescript');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var _grunt = null;
|
|
||||||
|
|
||||||
var TypeScriptDocGenerator = (function () {
|
var TypeScriptDocGenerator = (function () {
|
||||||
|
|
||||||
function TypeScriptDocGenerator(tsDefFileName, jsdocJsonFileName) {
|
function TypeScriptDocGenerator(tsDefFileName, jsdocJsonFileName) {
|
||||||
|
|
||||||
_grunt.log.writeln("TS Defs: " + tsDefFileName + " json: " + jsdocJsonFileName);
|
|
||||||
|
|
||||||
this.nbCharsAdded = 0;
|
this.nbCharsAdded = 0;
|
||||||
this.tsDefFileName = ts.normalizePath(tsDefFileName);
|
this.tsDefFileName = ts.normalizePath(tsDefFileName);
|
||||||
this.tsDefFileContent = fs.readFileSync(this.tsDefFileName, 'utf-8').toString();
|
this.tsDefFileContent = fs.readFileSync(this.tsDefFileName, 'utf-8').toString();
|
||||||
this.delintNodeFunction = this.delintNode.bind(this);
|
this.delintNodeFunction = this.delintNode.bind(this);
|
||||||
|
|
||||||
var jsonDocsFileContent = fs.readFileSync(jsdocJsonFileName, 'utf-8').toString();
|
var jsonDocsFileContent = fs.readFileSync(jsdocJsonFileName, 'utf-8').toString();
|
||||||
|
|
||||||
this.docs = JSON.parse(jsonDocsFileContent);
|
this.docs = JSON.parse(jsonDocsFileContent);
|
||||||
|
|
||||||
_grunt.log.writeln("json parsed");
|
|
||||||
|
|
||||||
var options = { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.AMD };
|
var options = { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.AMD };
|
||||||
var host = ts.createCompilerHost(options);
|
var host = ts.createCompilerHost(options);
|
||||||
var program = ts.createProgram([this.tsDefFileName], options, host);
|
var program = ts.createProgram([this.tsDefFileName], options, host);
|
||||||
|
|
||||||
this.sourceFile = program.getSourceFile(this.tsDefFileName);
|
this.sourceFile = program.getSourceFile(this.tsDefFileName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.getTsDefCommentedFileContent = function () {
|
TypeScriptDocGenerator.prototype.getTsDefCommentedFileContent = function () {
|
||||||
|
|
||||||
this.scan();
|
this.scan();
|
||||||
|
|
||||||
return this.tsDefFileContent;
|
return this.tsDefFileContent;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.repeatSpaces = function (nb) {
|
TypeScriptDocGenerator.prototype.repeatSpaces = function (nb) {
|
||||||
|
|
||||||
var res = "";
|
var res = "";
|
||||||
|
for (var i = 0; i < nb; i++) {
|
||||||
for (var i = 0; i < nb; i++)
|
|
||||||
{
|
|
||||||
res += " ";
|
res += " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.insertComment = function (commentLines, position) {
|
TypeScriptDocGenerator.prototype.insertComment = function (commentLines, position) {
|
||||||
|
if ((commentLines != null) && (commentLines.length > 0)) {
|
||||||
if ((commentLines != null) && (commentLines.length > 0))
|
|
||||||
{
|
|
||||||
var nbChars = 0;
|
var nbChars = 0;
|
||||||
|
for (var i = 0; i < commentLines.length; i++) {
|
||||||
for (var i = 0; i < commentLines.length; i++)
|
|
||||||
{
|
|
||||||
nbChars += commentLines[i].trim().length;
|
nbChars += commentLines[i].trim().length;
|
||||||
}
|
}
|
||||||
|
if (nbChars > 0) {
|
||||||
if (nbChars > 0)
|
|
||||||
{
|
|
||||||
var lc = this.sourceFile.getLineAndCharacterFromPosition(position);
|
var lc = this.sourceFile.getLineAndCharacterFromPosition(position);
|
||||||
var nbSpaces = lc.character - 1;
|
var nbSpaces = lc.character - 1;
|
||||||
var startLinePosition = this.sourceFile.getLineStarts()[lc.line - 1];
|
var startLinePosition = this.sourceFile.getLineStarts()[lc.line - 1];
|
||||||
var comment = "\r\n" + this.repeatSpaces(nbSpaces) + "/**\r\n";
|
var comment = "\r\n" + this.repeatSpaces(nbSpaces) + "/**\r\n";
|
||||||
|
for (var j = 0; j < commentLines.length; j++) {
|
||||||
for (var j = 0; j < commentLines.length; j++)
|
|
||||||
{
|
|
||||||
comment += this.repeatSpaces(nbSpaces) + "* " + commentLines[j].trimRight() + "\r\n";
|
comment += this.repeatSpaces(nbSpaces) + "* " + commentLines[j].trimRight() + "\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
comment += this.repeatSpaces(nbSpaces) + "*/\r\n";
|
comment += this.repeatSpaces(nbSpaces) + "*/\r\n";
|
||||||
|
|
||||||
this.tsDefFileContent = this.tsDefFileContent.substr(0, startLinePosition + this.nbCharsAdded) + comment + this.tsDefFileContent.substr(startLinePosition + this.nbCharsAdded);
|
this.tsDefFileContent = this.tsDefFileContent.substr(0, startLinePosition + this.nbCharsAdded) + comment + this.tsDefFileContent.substr(startLinePosition + this.nbCharsAdded);
|
||||||
this.nbCharsAdded += comment.length;
|
this.nbCharsAdded += comment.length;
|
||||||
|
|
||||||
// _grunt.log.writeln("comment: " + comment);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.cleanEndLine = function (str) {
|
TypeScriptDocGenerator.prototype.cleanEndLine = function (str) {
|
||||||
|
|
||||||
return str.replace(new RegExp('[' + "\r\n" + ']', 'g'), "\n").replace(new RegExp('[' + "\r" + ']', 'g'), "\n");
|
return str.replace(new RegExp('[' + "\r\n" + ']', 'g'), "\n").replace(new RegExp('[' + "\r" + ']', 'g'), "\n");
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.findClass = function (className) {
|
TypeScriptDocGenerator.prototype.findClass = function (className) {
|
||||||
|
if (className.indexOf("p2.") === 0) {
|
||||||
// _grunt.log.writeln("findClass: " + className);
|
|
||||||
|
|
||||||
if (className.indexOf("p2.") === 0)
|
|
||||||
{
|
|
||||||
className = className.replace("p2.", "Phaser.Physics.P2.");
|
className = className.replace("p2.", "Phaser.Physics.P2.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var elements = this.docs.classes.filter(function (element) {
|
var elements = this.docs.classes.filter(function (element) {
|
||||||
return (element.name === className);
|
return (element.name === className);
|
||||||
});
|
});
|
||||||
|
|
||||||
return elements[0];
|
return elements[0];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.generateClassComments = function (className) {
|
TypeScriptDocGenerator.prototype.generateClassComments = function (className) {
|
||||||
|
|
||||||
// _grunt.log.writeln("generateClassComments: " + className);
|
|
||||||
|
|
||||||
var c = this.findClass(className);
|
var c = this.findClass(className);
|
||||||
|
if (c != null) {
|
||||||
// _grunt.log.writeln("generateClassComments class found: " + JSON.stringify(c));
|
|
||||||
|
|
||||||
if (c !== null && c !== undefined)
|
|
||||||
{
|
|
||||||
var comments = [];
|
var comments = [];
|
||||||
comments = comments.concat(this.cleanEndLine(c.description).split("\n"));
|
comments = comments.concat(this.cleanEndLine(c.description).split("\n"));
|
||||||
// _grunt.log.writeln("generateClassComments return comments");
|
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
// _grunt.log.writeln("generateClassComments return null");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.generateMemberComments = function (className, memberName) {
|
TypeScriptDocGenerator.prototype.generateMemberComments = function (className, memberName) {
|
||||||
|
|
||||||
_grunt.log.writeln("generateMemberComments: " + className + " = " + memberName);
|
|
||||||
|
|
||||||
var c = this.findClass(className);
|
var c = this.findClass(className);
|
||||||
|
if (c != null) {
|
||||||
if (c !== null)
|
for (var i = 0; i < c.members.length; i++) {
|
||||||
{
|
if (c.members[i].name === memberName) {
|
||||||
for (var i = 0; i < c.members.length; i++)
|
|
||||||
{
|
|
||||||
if (c.members[i].name === memberName)
|
|
||||||
{
|
|
||||||
var m = c.members[i];
|
var m = c.members[i];
|
||||||
var comments = [];
|
var comments = [];
|
||||||
comments = comments.concat(this.cleanEndLine(m.description).split("\n"));
|
comments = comments.concat(this.cleanEndLine(m.description).split("\n"));
|
||||||
|
if ((m.default != null) && (m.default !== "")) {
|
||||||
if ((m.default != null) && (m.default !== ""))
|
|
||||||
{
|
|
||||||
comments.push("Default: " + m.default);
|
comments.push("Default: " + m.default);
|
||||||
}
|
}
|
||||||
|
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.generateFunctionComments = function (className, functionName) {
|
TypeScriptDocGenerator.prototype.generateFunctionComments = function (className, functionName) {
|
||||||
|
|
||||||
_grunt.log.writeln("generateFunctionComments: " + className);
|
|
||||||
|
|
||||||
var c = this.findClass(className);
|
var c = this.findClass(className);
|
||||||
|
if (c != null) {
|
||||||
if (c !== null)
|
for (var i = 0; i < c.functions.length; i++) {
|
||||||
{
|
if (c.functions[i].name === functionName) {
|
||||||
for (var i = 0; i < c.functions.length; i++)
|
|
||||||
{
|
|
||||||
if (c.functions[i].name === functionName)
|
|
||||||
{
|
|
||||||
var f = c.functions[i];
|
var f = c.functions[i];
|
||||||
var comments = [];
|
var comments = [];
|
||||||
comments = comments.concat(this.cleanEndLine(f.description).split("\n"));
|
comments = comments.concat(this.cleanEndLine(f.description).split("\n"));
|
||||||
|
if (f.parameters.length > 0) {
|
||||||
if (f.parameters.length > 0)
|
|
||||||
{
|
|
||||||
comments.push("");
|
comments.push("");
|
||||||
}
|
}
|
||||||
|
for (var j = 0; j < f.parameters.length; j++) {
|
||||||
for (var j = 0; j < f.parameters.length; j++)
|
|
||||||
{
|
|
||||||
var p = f.parameters[j];
|
var p = f.parameters[j];
|
||||||
|
if (p.type === "*") {
|
||||||
if (p.type === "*")
|
|
||||||
{
|
|
||||||
p.name = "args";
|
p.name = "args";
|
||||||
}
|
}
|
||||||
|
|
||||||
var def = "";
|
var def = "";
|
||||||
|
if ((p.default != null) && (p.default !== "")) {
|
||||||
if ((p.default != null) && (p.default !== ""))
|
|
||||||
{
|
|
||||||
def = " - Default: " + p.default;
|
def = " - Default: " + p.default;
|
||||||
}
|
}
|
||||||
|
|
||||||
var paramComments = this.cleanEndLine(p.description).split("\n");
|
var paramComments = this.cleanEndLine(p.description).split("\n");
|
||||||
|
for (var k = 0; k < paramComments.length; k++) {
|
||||||
for (var k = 0; k < paramComments.length; k++)
|
if (k === 0) {
|
||||||
{
|
|
||||||
if (k === 0)
|
|
||||||
{
|
|
||||||
comments.push("@param " + p.name + " " + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
comments.push("@param " + p.name + " " + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
comments.push(this.repeatSpaces(("@param " + p.name + " ").length) + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
comments.push(this.repeatSpaces(("@param " + p.name + " ").length) + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ((f.returns != null) && (f.returns.description.trim().length > 0)) {
|
||||||
if ((f.returns != null) && (f.returns.description.trim().length > 0))
|
|
||||||
{
|
|
||||||
var returnComments = this.cleanEndLine(f.returns.description).split("\n");
|
var returnComments = this.cleanEndLine(f.returns.description).split("\n");
|
||||||
|
for (var l = 0; l < returnComments.length; l++) {
|
||||||
for (var l = 0; l < returnComments.length; l++)
|
if (l === 0) {
|
||||||
{
|
|
||||||
if (l === 0)
|
|
||||||
{
|
|
||||||
comments.push("@return " + returnComments[l].trim());
|
comments.push("@return " + returnComments[l].trim());
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
comments.push(this.repeatSpaces(("@return ").length) + returnComments[l].trim());
|
comments.push(this.repeatSpaces(("@return ").length) + returnComments[l].trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.generateConstructorComments = function (className) {
|
TypeScriptDocGenerator.prototype.generateConstructorComments = function (className) {
|
||||||
|
|
||||||
_grunt.log.writeln("generateConstructorComments: " + className);
|
|
||||||
|
|
||||||
var c = this.findClass(className);
|
var c = this.findClass(className);
|
||||||
|
if (c != null) {
|
||||||
if (c !== null)
|
|
||||||
{
|
|
||||||
// _grunt.log.writeln("Class: " + c);
|
|
||||||
|
|
||||||
var con = c.constructor;
|
var con = c.constructor;
|
||||||
var comments = [];
|
var comments = [];
|
||||||
|
|
||||||
comments = comments.concat(this.cleanEndLine(con.description).split("\n"));
|
comments = comments.concat(this.cleanEndLine(con.description).split("\n"));
|
||||||
|
if (con.parameters.length > 0) {
|
||||||
if (con.parameters.length > 0)
|
|
||||||
{
|
|
||||||
comments.push("");
|
comments.push("");
|
||||||
}
|
}
|
||||||
|
for (var j = 0; j < con.parameters.length; j++) {
|
||||||
for (var j = 0; j < con.parameters.length; j++)
|
|
||||||
{
|
|
||||||
var p = con.parameters[j];
|
var p = con.parameters[j];
|
||||||
|
if (p.type === "*") {
|
||||||
if (p.type === "*")
|
|
||||||
{
|
|
||||||
p.name = "args";
|
p.name = "args";
|
||||||
}
|
}
|
||||||
|
|
||||||
var def = "";
|
var def = "";
|
||||||
|
if ((p.default != null) && (p.default !== "")) {
|
||||||
if ((p.default != null) && (p.default !== ""))
|
|
||||||
{
|
|
||||||
def = " - Default: " + p.default;
|
def = " - Default: " + p.default;
|
||||||
}
|
}
|
||||||
|
|
||||||
var paramComments = this.cleanEndLine(p.description).split("\n");
|
var paramComments = this.cleanEndLine(p.description).split("\n");
|
||||||
|
for (var k = 0; k < paramComments.length; k++) {
|
||||||
for (var k = 0; k < paramComments.length; k++)
|
if (k === 0) {
|
||||||
{
|
|
||||||
if (k === 0)
|
|
||||||
{
|
|
||||||
comments.push("@param " + p.name + " " + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
comments.push("@param " + p.name + " " + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
comments.push(this.repeatSpaces(("@param " + p.name + " ").length) + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
comments.push(this.repeatSpaces(("@param " + p.name + " ").length) + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return comments;
|
return comments;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.scan = function () {
|
TypeScriptDocGenerator.prototype.scan = function () {
|
||||||
|
|
||||||
this.delintNode(this.sourceFile);
|
this.delintNode(this.sourceFile);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.getClassName = function (node) {
|
TypeScriptDocGenerator.prototype.getClassName = function (node) {
|
||||||
|
|
||||||
// _grunt.log.writeln("getClassName: " + JSON.stringify(node));
|
|
||||||
// _grunt.log.writeln("getClassName: " + JSON.stringify(node.kind));
|
|
||||||
// _grunt.log.writeln("getClassName: " + JSON.stringify(node.name));
|
|
||||||
|
|
||||||
var fullName = '';
|
var fullName = '';
|
||||||
|
if (node.kind === ts.SyntaxKind.ClassDeclaration) {
|
||||||
if (node.name !== undefined && node.kind === ts.SyntaxKind.ClassDeclaration)
|
|
||||||
{
|
|
||||||
// _grunt.log.writeln("getClassName 1a: " + node.name.text);
|
|
||||||
|
|
||||||
try {
|
|
||||||
fullName = node.name.getText();
|
fullName = node.name.getText();
|
||||||
// _grunt.log.writeln("getClassName 1b: " + fullName);
|
|
||||||
}
|
}
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
fullName = node.name.text;
|
|
||||||
// _grunt.log.writeln("getClassName bail");
|
|
||||||
// return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var parent = node.parent;
|
var parent = node.parent;
|
||||||
|
while (parent != null) {
|
||||||
while (parent !== null && parent !== undefined)
|
if (parent.kind === ts.SyntaxKind.ModuleDeclaration || parent.kind === ts.SyntaxKind.ClassDeclaration) {
|
||||||
{
|
|
||||||
// _grunt.log.writeln("getClassName 2");
|
|
||||||
|
|
||||||
if (parent.kind === ts.SyntaxKind.ModuleDeclaration || parent.kind === ts.SyntaxKind.ClassDeclaration)
|
|
||||||
{
|
|
||||||
fullName = parent.name.getText() + ((fullName !== '') ? "." + fullName : fullName);
|
fullName = parent.name.getText() + ((fullName !== '') ? "." + fullName : fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent = parent.parent;
|
parent = parent.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fullName === undefined || fullName === null)
|
|
||||||
{
|
|
||||||
fullName = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// _grunt.log.writeln("getClassName: " + fullName);
|
|
||||||
|
|
||||||
return fullName;
|
return fullName;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeScriptDocGenerator.prototype.delintNode = function (node) {
|
TypeScriptDocGenerator.prototype.delintNode = function (node) {
|
||||||
|
switch (node.kind) {
|
||||||
var c = this.getClassName(node);
|
|
||||||
|
|
||||||
var r = true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
r = node.getStart();
|
|
||||||
}
|
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
r = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (node.kind)
|
|
||||||
{
|
|
||||||
case ts.SyntaxKind.Constructor:
|
case ts.SyntaxKind.Constructor:
|
||||||
// _grunt.log.writeln("insert1: " + node);
|
this.insertComment(this.generateConstructorComments(this.getClassName(node)), node.getStart());
|
||||||
|
|
||||||
if (c !== '' && r)
|
|
||||||
{
|
|
||||||
this.insertComment(this.generateConstructorComments(c, r));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ts.SyntaxKind.ClassDeclaration:
|
case ts.SyntaxKind.ClassDeclaration:
|
||||||
// _grunt.log.writeln("insertX2: " + JSON.stringify(node));
|
this.insertComment(this.generateClassComments(this.getClassName(node)), node.getStart());
|
||||||
// _grunt.log.writeln("insertX2a: " + JSON.stringify(node.name));
|
|
||||||
// _grunt.log.writeln("insertX2b: " + this.getClassName(node));
|
|
||||||
// _grunt.log.writeln("insertX2c: " + r);
|
|
||||||
// _grunt.log.writeln("insertX2d ...");
|
|
||||||
|
|
||||||
if (c !== '' && r)
|
|
||||||
{
|
|
||||||
this.insertComment(this.generateClassComments(c, r));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ts.SyntaxKind.Property:
|
case ts.SyntaxKind.Property:
|
||||||
// _grunt.log.writeln("insert3: " + node);
|
this.insertComment(this.generateMemberComments(this.getClassName(node), node.name.getText()), node.getStart());
|
||||||
|
|
||||||
var t = true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
t = node.name.getText();
|
|
||||||
}
|
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
t = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c !== '' && r && t)
|
|
||||||
{
|
|
||||||
this.insertComment(this.generateMemberComments(c, t, r));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ts.SyntaxKind.Method:
|
case ts.SyntaxKind.Method:
|
||||||
// _grunt.log.writeln("insert4: " + node);
|
this.insertComment(this.generateFunctionComments(this.getClassName(node), node.name.getText()), node.getStart());
|
||||||
|
|
||||||
var t = true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
t = node.name.getText();
|
|
||||||
}
|
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
t = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c !== '' && r && t)
|
|
||||||
{
|
|
||||||
this.insertComment(this.generateFunctionComments(c, t, r));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ts.forEachChild(node, this.delintNodeFunction);
|
ts.forEachChild(node, this.delintNodeFunction);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return TypeScriptDocGenerator;
|
return TypeScriptDocGenerator;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
module.exports = function (grunt) {
|
module.exports = function (grunt) {
|
||||||
|
|
||||||
_grunt = grunt;
|
|
||||||
|
|
||||||
grunt.registerMultiTask('buildtsdoc', 'Generate a TypeScript def with comments', function () {
|
grunt.registerMultiTask('buildtsdoc', 'Generate a TypeScript def with comments', function () {
|
||||||
var tsdg = new TypeScriptDocGenerator(this.data.tsDefFileName, this.data.jsdocJsonFileName);
|
var tsdg = new TypeScriptDocGenerator(this.data.tsDefFileName, this.data.jsdocJsonFileName);
|
||||||
fs.writeFileSync(this.data.dest, tsdg.getTsDefCommentedFileContent(), 'utf8');
|
fs.writeFileSync(this.data.dest, tsdg.getTsDefCommentedFileContent(), 'utf8');
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
31552
typescript/phaser.comments.d.ts
vendored
Normal file
31552
typescript/phaser.comments.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load diff
24
typescript/phaser.d.ts
vendored
24
typescript/phaser.d.ts
vendored
|
@ -5,8 +5,10 @@
|
||||||
// Project: https://github.com/photonstorm/phaser
|
// Project: https://github.com/photonstorm/phaser
|
||||||
|
|
||||||
declare module "phaser" {
|
declare module "phaser" {
|
||||||
|
export = Phaser;
|
||||||
|
}
|
||||||
|
|
||||||
export class Phaser {
|
declare class Phaser {
|
||||||
|
|
||||||
static VERSION: string;
|
static VERSION: string;
|
||||||
static DEV_VERSION: string;
|
static DEV_VERSION: string;
|
||||||
|
@ -87,7 +89,7 @@ declare module "phaser" {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export module Phaser {
|
declare module Phaser {
|
||||||
|
|
||||||
class Animation {
|
class Animation {
|
||||||
|
|
||||||
|
@ -2803,12 +2805,7 @@ declare module "phaser" {
|
||||||
game: Phaser.Game;
|
game: Phaser.Game;
|
||||||
ninja: Phaser.Physics.Ninja;
|
ninja: Phaser.Physics.Ninja;
|
||||||
p2: Phaser.Physics.P2;
|
p2: Phaser.Physics.P2;
|
||||||
//todo box2d
|
|
||||||
box2d: any;
|
box2d: any;
|
||||||
//todo chipmunk
|
|
||||||
//chipmunk: any;
|
|
||||||
//todo matter
|
|
||||||
//matter: any;
|
|
||||||
|
|
||||||
clear(): void;
|
clear(): void;
|
||||||
destroy(): void;
|
destroy(): void;
|
||||||
|
@ -3057,7 +3054,7 @@ declare module "phaser" {
|
||||||
|
|
||||||
constructor(game: Phaser.Game);
|
constructor(game: Phaser.Game);
|
||||||
|
|
||||||
game: Phaser.Game
|
game: Phaser.Game;
|
||||||
gravity: number;
|
gravity: number;
|
||||||
bounds: Phaser.Rectangle;
|
bounds: Phaser.Rectangle;
|
||||||
maxObjects: number;
|
maxObjects: number;
|
||||||
|
@ -4652,8 +4649,8 @@ declare module "phaser" {
|
||||||
height: number;
|
height: number;
|
||||||
incorrectOrientation: boolean;
|
incorrectOrientation: boolean;
|
||||||
isFullScreen: boolean;
|
isFullScreen: boolean;
|
||||||
isGameLandscape: boolean; //readonly
|
isGameLandscape: boolean;
|
||||||
isGamePortrait: boolean; //readonly
|
isGamePortrait: boolean;
|
||||||
isPortrait: boolean;
|
isPortrait: boolean;
|
||||||
isLandscape: boolean;
|
isLandscape: boolean;
|
||||||
leaveIncorrectOrientation: Signal;
|
leaveIncorrectOrientation: Signal;
|
||||||
|
@ -4931,7 +4928,7 @@ declare module "phaser" {
|
||||||
|
|
||||||
class Tile {
|
class Tile {
|
||||||
|
|
||||||
constructor(layer: any, index: number, x: number, y: Number, width: number, height: number);//
|
constructor(layer: any, index: number, x: number, y: Number, width: number, height: number);
|
||||||
|
|
||||||
alpha: number;
|
alpha: number;
|
||||||
bottom: number;
|
bottom: number;
|
||||||
|
@ -5357,7 +5354,6 @@ declare module "phaser" {
|
||||||
pendingDelete: boolean;
|
pendingDelete: boolean;
|
||||||
properties: any;
|
properties: any;
|
||||||
repeatCounter: number;
|
repeatCounter: number;
|
||||||
//repeatDelay: number;
|
|
||||||
reverse: boolean;
|
reverse: boolean;
|
||||||
target: any;
|
target: any;
|
||||||
timeline: Phaser.TweenData[];
|
timeline: Phaser.TweenData[];
|
||||||
|
@ -5618,12 +5614,10 @@ declare module "phaser" {
|
||||||
sortTopBottom(a: Phaser.Sprite, b: Phaser.Sprite): number;
|
sortTopBottom(a: Phaser.Sprite, b: Phaser.Sprite): number;
|
||||||
sortBottomTop(a: Phaser.Sprite, b: Phaser.Sprite): number;
|
sortBottomTop(a: Phaser.Sprite, b: Phaser.Sprite): number;
|
||||||
sort(group: Phaser.Group, sortDirection?: number): void;
|
sort(group: Phaser.Group, sortDirection?: number): void;
|
||||||
sort(key?: string, order?: number): void; //ugly? Group already has a sort method remove this line and you get error.
|
sort(key?: string, order?: number): void;
|
||||||
shutdown(): void;
|
shutdown(): void;
|
||||||
wrap(sprite: any, padding?: number, useBounds?: boolean, horizontal?: boolean, vertical?: boolean): void;
|
wrap(sprite: any, padding?: number, useBounds?: boolean, horizontal?: boolean, vertical?: boolean): void;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
3732
typescript/pixi.comments.d.ts
vendored
Normal file
3732
typescript/pixi.comments.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load diff
20
typescript/pixi.d.ts
vendored
20
typescript/pixi.d.ts
vendored
|
@ -65,7 +65,7 @@ declare module PIXI {
|
||||||
export function autoDetectRecommendedRenderer(width?: number, height?: number, options?: PixiRendererOptions): PixiRenderer;
|
export function autoDetectRecommendedRenderer(width?: number, height?: number, options?: PixiRendererOptions): PixiRenderer;
|
||||||
|
|
||||||
export function canUseNewCanvasBlendModes(): boolean;
|
export function canUseNewCanvasBlendModes(): boolean;
|
||||||
export function getNextPowerOfTwo(number: number): number;
|
export function getNextPowerOfTwo(value: number): number;
|
||||||
|
|
||||||
export function AjaxRequest(): XMLHttpRequest;
|
export function AjaxRequest(): XMLHttpRequest;
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ declare module PIXI {
|
||||||
|
|
||||||
|
|
||||||
export interface IEventCallback {
|
export interface IEventCallback {
|
||||||
(e?: IEvent): void
|
(e?: IEvent): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IEvent {
|
export interface IEvent {
|
||||||
|
@ -87,7 +87,7 @@ declare module PIXI {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IInteractionDataCallback {
|
export interface IInteractionDataCallback {
|
||||||
(interactionData: InteractionData): void
|
(interactionData: InteractionData): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PixiRenderer {
|
export interface PixiRenderer {
|
||||||
|
@ -917,7 +917,7 @@ declare module PIXI {
|
||||||
constructor(...points: Point[]);
|
constructor(...points: Point[]);
|
||||||
constructor(...points: number[]);
|
constructor(...points: number[]);
|
||||||
|
|
||||||
points: any[]; //number[] Point[]
|
points: any[];
|
||||||
|
|
||||||
clone(): Polygon;
|
clone(): Polygon;
|
||||||
contains(x: number, y: number): boolean;
|
contains(x: number, y: number): boolean;
|
||||||
|
@ -1073,7 +1073,7 @@ declare module PIXI {
|
||||||
TRIANGLE_STRIP: number;
|
TRIANGLE_STRIP: number;
|
||||||
TRIANGLES: number;
|
TRIANGLES: number;
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
constructor(texture: Texture);
|
constructor(texture: Texture);
|
||||||
|
|
||||||
|
@ -1274,7 +1274,7 @@ declare module PIXI {
|
||||||
|
|
||||||
static renderGraphics(graphics: Graphics, renderRession: RenderSession): void;
|
static renderGraphics(graphics: Graphics, renderRession: RenderSession): void;
|
||||||
static updateGraphics(graphics: Graphics, gl: WebGLRenderingContext): void;
|
static updateGraphics(graphics: Graphics, gl: WebGLRenderingContext): void;
|
||||||
static switchMode(webGL: WebGLRenderingContext, type: number): any; //WebGLData
|
static switchMode(webGL: WebGLRenderingContext, type: number): any;
|
||||||
static buildRectangle(graphicsData: GraphicsData, webGLData: any): void;
|
static buildRectangle(graphicsData: GraphicsData, webGLData: any): void;
|
||||||
static buildRoundedRectangle(graphicsData: GraphicsData, webGLData: any): void;
|
static buildRoundedRectangle(graphicsData: GraphicsData, webGLData: any): void;
|
||||||
static quadraticBezierCurve(fromX: number, fromY: number, cpX: number, cpY: number, toX: number, toY: number): number[];
|
static quadraticBezierCurve(fromX: number, fromY: number, cpX: number, cpY: number, toX: number, toY: number): number[];
|
||||||
|
@ -1396,7 +1396,7 @@ declare module PIXI {
|
||||||
textures: Texture[];
|
textures: Texture[];
|
||||||
shaders: IPixiShader[];
|
shaders: IPixiShader[];
|
||||||
size: number;
|
size: number;
|
||||||
sprites: any[]; //todo Sprite[]?
|
sprites: any[];
|
||||||
vertices: number[];
|
vertices: number[];
|
||||||
vertSize: number;
|
vertSize: number;
|
||||||
|
|
||||||
|
@ -1767,7 +1767,7 @@ declare module PIXI {
|
||||||
rgb888: number;
|
rgb888: number;
|
||||||
rgba8888: number;
|
rgba8888: number;
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
static TextureFilter: {
|
static TextureFilter: {
|
||||||
|
|
||||||
|
@ -1779,7 +1779,7 @@ declare module PIXI {
|
||||||
mipMapNearestLinear: number;
|
mipMapNearestLinear: number;
|
||||||
mipMapLinearLinear: number;
|
mipMapLinearLinear: number;
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
static textureWrap: {
|
static textureWrap: {
|
||||||
|
|
||||||
|
@ -1787,7 +1787,7 @@ declare module PIXI {
|
||||||
clampToEdge: number;
|
clampToEdge: number;
|
||||||
repeat: number;
|
repeat: number;
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
constructor(atlasText: string, textureLoader: AtlasLoader);
|
constructor(atlasText: string, textureLoader: AtlasLoader);
|
||||||
|
|
||||||
|
|
57
typescript/tslint.json
Normal file
57
typescript/tslint.json
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
{
|
||||||
|
"rules": {
|
||||||
|
"class-name": true,
|
||||||
|
"comment-format": [
|
||||||
|
true,
|
||||||
|
"check-space"
|
||||||
|
],
|
||||||
|
"indent": [
|
||||||
|
true,
|
||||||
|
"spaces"
|
||||||
|
],
|
||||||
|
"no-duplicate-variable": true,
|
||||||
|
"no-eval": true,
|
||||||
|
"no-internal-module": true,
|
||||||
|
"no-trailing-whitespace": true,
|
||||||
|
"no-var-keyword": true,
|
||||||
|
"one-line": [
|
||||||
|
true,
|
||||||
|
"check-open-brace",
|
||||||
|
"check-whitespace"
|
||||||
|
],
|
||||||
|
"quotemark": [
|
||||||
|
true,
|
||||||
|
"double"
|
||||||
|
],
|
||||||
|
"semicolon": [
|
||||||
|
true,
|
||||||
|
"always"
|
||||||
|
],
|
||||||
|
"triple-equals": [
|
||||||
|
true,
|
||||||
|
"allow-null-check"
|
||||||
|
],
|
||||||
|
"typedef-whitespace": [
|
||||||
|
true,
|
||||||
|
{
|
||||||
|
"call-signature": "nospace",
|
||||||
|
"index-signature": "nospace",
|
||||||
|
"parameter": "nospace",
|
||||||
|
"property-declaration": "nospace",
|
||||||
|
"variable-declaration": "nospace"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"variable-name": [
|
||||||
|
true,
|
||||||
|
"ban-keywords"
|
||||||
|
],
|
||||||
|
"whitespace": [
|
||||||
|
true,
|
||||||
|
"check-branch",
|
||||||
|
"check-decl",
|
||||||
|
"check-operator",
|
||||||
|
"check-separator",
|
||||||
|
"check-type"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue