mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 12:43:26 +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": {
|
||||
"definitions": [
|
||||
"typescript/p2.d.ts",
|
||||
"typescript/phaser.d.ts",
|
||||
"typescript/pixi.d.ts"
|
||||
"typescript/phaser.comments.d.ts",
|
||||
"typescript/pixi.comments.d.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,14 +43,14 @@
|
|||
"grunt-text-replace": "^0.3.11",
|
||||
"jsdoc": "~3.3.0-alpha10",
|
||||
"load-grunt-config": "~0.7.2",
|
||||
"typescript": "^1.4.1",
|
||||
"typescript": "1.4.1",
|
||||
"yuidocjs": "^0.3.50"
|
||||
},
|
||||
"typescript": {
|
||||
"definitions": [
|
||||
"typescript/p2.d.ts",
|
||||
"typescript/phaser.d.ts",
|
||||
"typescript/pixi.d.ts"
|
||||
"typescript/phaser.comments.d.ts",
|
||||
"typescript/pixi.comments.d.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,215 +5,458 @@
|
|||
|
||||
var ts = require('typescript');
|
||||
var fs = require('fs');
|
||||
var _grunt = null;
|
||||
|
||||
var TypeScriptDocGenerator = (function () {
|
||||
|
||||
function TypeScriptDocGenerator(tsDefFileName, jsdocJsonFileName) {
|
||||
|
||||
_grunt.log.writeln("TS Defs: " + tsDefFileName + " json: " + jsdocJsonFileName);
|
||||
|
||||
this.nbCharsAdded = 0;
|
||||
this.tsDefFileName = ts.normalizePath(tsDefFileName);
|
||||
this.tsDefFileContent = fs.readFileSync(this.tsDefFileName, 'utf-8').toString();
|
||||
this.delintNodeFunction = this.delintNode.bind(this);
|
||||
|
||||
var jsonDocsFileContent = fs.readFileSync(jsdocJsonFileName, 'utf-8').toString();
|
||||
|
||||
this.docs = JSON.parse(jsonDocsFileContent);
|
||||
|
||||
_grunt.log.writeln("json parsed");
|
||||
|
||||
var options = { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.AMD };
|
||||
var host = ts.createCompilerHost(options);
|
||||
var program = ts.createProgram([this.tsDefFileName], options, host);
|
||||
|
||||
this.sourceFile = program.getSourceFile(this.tsDefFileName);
|
||||
|
||||
}
|
||||
|
||||
TypeScriptDocGenerator.prototype.getTsDefCommentedFileContent = function () {
|
||||
|
||||
this.scan();
|
||||
|
||||
return this.tsDefFileContent;
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.repeatSpaces = function (nb) {
|
||||
|
||||
var res = "";
|
||||
for (var i = 0; i < nb; i++) {
|
||||
|
||||
for (var i = 0; i < nb; i++)
|
||||
{
|
||||
res += " ";
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.insertComment = function (commentLines, position) {
|
||||
if ((commentLines != null) && (commentLines.length > 0)) {
|
||||
|
||||
if ((commentLines != null) && (commentLines.length > 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;
|
||||
}
|
||||
if (nbChars > 0) {
|
||||
|
||||
if (nbChars > 0)
|
||||
{
|
||||
var lc = this.sourceFile.getLineAndCharacterFromPosition(position);
|
||||
var nbSpaces = lc.character - 1;
|
||||
var startLinePosition = this.sourceFile.getLineStarts()[lc.line - 1];
|
||||
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) + "*/\r\n";
|
||||
|
||||
this.tsDefFileContent = this.tsDefFileContent.substr(0, startLinePosition + this.nbCharsAdded) + comment + this.tsDefFileContent.substr(startLinePosition + this.nbCharsAdded);
|
||||
this.nbCharsAdded += comment.length;
|
||||
|
||||
// _grunt.log.writeln("comment: " + comment);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.cleanEndLine = function (str) {
|
||||
|
||||
return str.replace(new RegExp('[' + "\r\n" + ']', 'g'), "\n").replace(new RegExp('[' + "\r" + ']', 'g'), "\n");
|
||||
|
||||
};
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
var elements = this.docs.classes.filter(function (element) {
|
||||
return (element.name === className);
|
||||
});
|
||||
|
||||
return elements[0];
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.generateClassComments = function (className) {
|
||||
|
||||
// _grunt.log.writeln("generateClassComments: " + 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 = [];
|
||||
comments = comments.concat(this.cleanEndLine(c.description).split("\n"));
|
||||
// _grunt.log.writeln("generateClassComments return comments");
|
||||
return comments;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// _grunt.log.writeln("generateClassComments return null");
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.generateMemberComments = function (className, memberName) {
|
||||
|
||||
_grunt.log.writeln("generateMemberComments: " + className + " = " + memberName);
|
||||
|
||||
var c = this.findClass(className);
|
||||
if (c != null) {
|
||||
for (var i = 0; i < c.members.length; i++) {
|
||||
if (c.members[i].name === memberName) {
|
||||
|
||||
if (c !== null)
|
||||
{
|
||||
for (var i = 0; i < c.members.length; i++)
|
||||
{
|
||||
if (c.members[i].name === memberName)
|
||||
{
|
||||
var m = c.members[i];
|
||||
var comments = [];
|
||||
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);
|
||||
}
|
||||
|
||||
return comments;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.generateFunctionComments = function (className, functionName) {
|
||||
|
||||
_grunt.log.writeln("generateFunctionComments: " + className);
|
||||
|
||||
var c = this.findClass(className);
|
||||
if (c != null) {
|
||||
for (var i = 0; i < c.functions.length; i++) {
|
||||
if (c.functions[i].name === functionName) {
|
||||
|
||||
if (c !== null)
|
||||
{
|
||||
for (var i = 0; i < c.functions.length; i++)
|
||||
{
|
||||
if (c.functions[i].name === functionName)
|
||||
{
|
||||
var f = c.functions[i];
|
||||
var comments = [];
|
||||
comments = comments.concat(this.cleanEndLine(f.description).split("\n"));
|
||||
if (f.parameters.length > 0) {
|
||||
|
||||
if (f.parameters.length > 0)
|
||||
{
|
||||
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];
|
||||
if (p.type === "*") {
|
||||
|
||||
if (p.type === "*")
|
||||
{
|
||||
p.name = "args";
|
||||
}
|
||||
|
||||
var def = "";
|
||||
if ((p.default != null) && (p.default !== "")) {
|
||||
|
||||
if ((p.default != null) && (p.default !== ""))
|
||||
{
|
||||
def = " - Default: " + p.default;
|
||||
}
|
||||
|
||||
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 : ""));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
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");
|
||||
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());
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
comments.push(this.repeatSpaces(("@return ").length) + returnComments[l].trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return comments;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.generateConstructorComments = function (className) {
|
||||
|
||||
_grunt.log.writeln("generateConstructorComments: " + className);
|
||||
|
||||
var c = this.findClass(className);
|
||||
if (c != null) {
|
||||
|
||||
if (c !== null)
|
||||
{
|
||||
// _grunt.log.writeln("Class: " + c);
|
||||
|
||||
var con = c.constructor;
|
||||
var comments = [];
|
||||
|
||||
comments = comments.concat(this.cleanEndLine(con.description).split("\n"));
|
||||
if (con.parameters.length > 0) {
|
||||
|
||||
if (con.parameters.length > 0)
|
||||
{
|
||||
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];
|
||||
if (p.type === "*") {
|
||||
|
||||
if (p.type === "*")
|
||||
{
|
||||
p.name = "args";
|
||||
}
|
||||
|
||||
var def = "";
|
||||
if ((p.default != null) && (p.default !== "")) {
|
||||
|
||||
if ((p.default != null) && (p.default !== ""))
|
||||
{
|
||||
def = " - Default: " + p.default;
|
||||
}
|
||||
|
||||
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 : ""));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
comments.push(this.repeatSpaces(("@param " + p.name + " ").length) + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return comments;
|
||||
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.scan = function () {
|
||||
|
||||
this.delintNode(this.sourceFile);
|
||||
|
||||
};
|
||||
|
||||
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 = '';
|
||||
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();
|
||||
// _grunt.log.writeln("getClassName 1b: " + fullName);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
fullName = node.name.text;
|
||||
// _grunt.log.writeln("getClassName bail");
|
||||
// return '';
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
parent = parent.parent;
|
||||
}
|
||||
|
||||
if (fullName === undefined || fullName === null)
|
||||
{
|
||||
fullName = '';
|
||||
}
|
||||
|
||||
// _grunt.log.writeln("getClassName: " + fullName);
|
||||
|
||||
return fullName;
|
||||
|
||||
};
|
||||
|
||||
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:
|
||||
this.insertComment(this.generateConstructorComments(this.getClassName(node)), node.getStart());
|
||||
// _grunt.log.writeln("insert1: " + node);
|
||||
|
||||
if (c !== '' && r)
|
||||
{
|
||||
this.insertComment(this.generateConstructorComments(c, r));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
ts.forEachChild(node, this.delintNodeFunction);
|
||||
|
||||
};
|
||||
|
||||
return TypeScriptDocGenerator;
|
||||
|
||||
})();
|
||||
|
||||
module.exports = function (grunt) {
|
||||
|
||||
_grunt = grunt;
|
||||
|
||||
grunt.registerMultiTask('buildtsdoc', 'Generate a TypeScript def with comments', function () {
|
||||
var tsdg = new TypeScriptDocGenerator(this.data.tsDefFileName, this.data.jsdocJsonFileName);
|
||||
fs.writeFileSync(this.data.dest, tsdg.getTsDefCommentedFileContent(), 'utf8');
|
||||
});
|
||||
|
||||
};
|
|
@ -5,458 +5,215 @@
|
|||
|
||||
var ts = require('typescript');
|
||||
var fs = require('fs');
|
||||
var _grunt = null;
|
||||
|
||||
var TypeScriptDocGenerator = (function () {
|
||||
|
||||
function TypeScriptDocGenerator(tsDefFileName, jsdocJsonFileName) {
|
||||
|
||||
_grunt.log.writeln("TS Defs: " + tsDefFileName + " json: " + jsdocJsonFileName);
|
||||
|
||||
this.nbCharsAdded = 0;
|
||||
this.tsDefFileName = ts.normalizePath(tsDefFileName);
|
||||
this.tsDefFileContent = fs.readFileSync(this.tsDefFileName, 'utf-8').toString();
|
||||
this.delintNodeFunction = this.delintNode.bind(this);
|
||||
|
||||
var jsonDocsFileContent = fs.readFileSync(jsdocJsonFileName, 'utf-8').toString();
|
||||
|
||||
this.docs = JSON.parse(jsonDocsFileContent);
|
||||
|
||||
_grunt.log.writeln("json parsed");
|
||||
|
||||
var options = { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.AMD };
|
||||
var host = ts.createCompilerHost(options);
|
||||
var program = ts.createProgram([this.tsDefFileName], options, host);
|
||||
|
||||
this.sourceFile = program.getSourceFile(this.tsDefFileName);
|
||||
|
||||
}
|
||||
|
||||
TypeScriptDocGenerator.prototype.getTsDefCommentedFileContent = function () {
|
||||
|
||||
this.scan();
|
||||
|
||||
return this.tsDefFileContent;
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.repeatSpaces = function (nb) {
|
||||
|
||||
var res = "";
|
||||
|
||||
for (var i = 0; i < nb; i++)
|
||||
{
|
||||
for (var i = 0; i < nb; i++) {
|
||||
res += " ";
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.insertComment = function (commentLines, position) {
|
||||
|
||||
if ((commentLines != null) && (commentLines.length > 0))
|
||||
{
|
||||
if ((commentLines != null) && (commentLines.length > 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;
|
||||
}
|
||||
|
||||
if (nbChars > 0)
|
||||
{
|
||||
if (nbChars > 0) {
|
||||
var lc = this.sourceFile.getLineAndCharacterFromPosition(position);
|
||||
var nbSpaces = lc.character - 1;
|
||||
var startLinePosition = this.sourceFile.getLineStarts()[lc.line - 1];
|
||||
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) + "*/\r\n";
|
||||
|
||||
this.tsDefFileContent = this.tsDefFileContent.substr(0, startLinePosition + this.nbCharsAdded) + comment + this.tsDefFileContent.substr(startLinePosition + this.nbCharsAdded);
|
||||
this.nbCharsAdded += comment.length;
|
||||
|
||||
// _grunt.log.writeln("comment: " + comment);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.cleanEndLine = function (str) {
|
||||
|
||||
return str.replace(new RegExp('[' + "\r\n" + ']', 'g'), "\n").replace(new RegExp('[' + "\r" + ']', 'g'), "\n");
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.findClass = function (className) {
|
||||
|
||||
// _grunt.log.writeln("findClass: " + className);
|
||||
|
||||
if (className.indexOf("p2.") === 0)
|
||||
{
|
||||
if (className.indexOf("p2.") === 0) {
|
||||
className = className.replace("p2.", "Phaser.Physics.P2.");
|
||||
}
|
||||
|
||||
var elements = this.docs.classes.filter(function (element) {
|
||||
return (element.name === className);
|
||||
});
|
||||
|
||||
return elements[0];
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.generateClassComments = function (className) {
|
||||
|
||||
// _grunt.log.writeln("generateClassComments: " + className);
|
||||
|
||||
var c = this.findClass(className);
|
||||
|
||||
// _grunt.log.writeln("generateClassComments class found: " + JSON.stringify(c));
|
||||
|
||||
if (c !== null && c !== undefined)
|
||||
{
|
||||
if (c != null) {
|
||||
var comments = [];
|
||||
comments = comments.concat(this.cleanEndLine(c.description).split("\n"));
|
||||
// _grunt.log.writeln("generateClassComments return comments");
|
||||
return comments;
|
||||
}
|
||||
else
|
||||
{
|
||||
// _grunt.log.writeln("generateClassComments return null");
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.generateMemberComments = function (className, memberName) {
|
||||
|
||||
_grunt.log.writeln("generateMemberComments: " + className + " = " + memberName);
|
||||
|
||||
var c = this.findClass(className);
|
||||
|
||||
if (c !== null)
|
||||
{
|
||||
for (var i = 0; i < c.members.length; i++)
|
||||
{
|
||||
if (c.members[i].name === memberName)
|
||||
{
|
||||
if (c != null) {
|
||||
for (var i = 0; i < c.members.length; i++) {
|
||||
if (c.members[i].name === memberName) {
|
||||
var m = c.members[i];
|
||||
var comments = [];
|
||||
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);
|
||||
}
|
||||
|
||||
return comments;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.generateFunctionComments = function (className, functionName) {
|
||||
|
||||
_grunt.log.writeln("generateFunctionComments: " + className);
|
||||
|
||||
var c = this.findClass(className);
|
||||
|
||||
if (c !== null)
|
||||
{
|
||||
for (var i = 0; i < c.functions.length; i++)
|
||||
{
|
||||
if (c.functions[i].name === functionName)
|
||||
{
|
||||
if (c != null) {
|
||||
for (var i = 0; i < c.functions.length; i++) {
|
||||
if (c.functions[i].name === functionName) {
|
||||
var f = c.functions[i];
|
||||
var comments = [];
|
||||
comments = comments.concat(this.cleanEndLine(f.description).split("\n"));
|
||||
|
||||
if (f.parameters.length > 0)
|
||||
{
|
||||
if (f.parameters.length > 0) {
|
||||
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];
|
||||
|
||||
if (p.type === "*")
|
||||
{
|
||||
if (p.type === "*") {
|
||||
p.name = "args";
|
||||
}
|
||||
|
||||
var def = "";
|
||||
|
||||
if ((p.default != null) && (p.default !== ""))
|
||||
{
|
||||
if ((p.default != null) && (p.default !== "")) {
|
||||
def = " - Default: " + p.default;
|
||||
}
|
||||
|
||||
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 : ""));
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
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");
|
||||
|
||||
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());
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
comments.push(this.repeatSpaces(("@return ").length) + returnComments[l].trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return comments;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.generateConstructorComments = function (className) {
|
||||
|
||||
_grunt.log.writeln("generateConstructorComments: " + className);
|
||||
|
||||
var c = this.findClass(className);
|
||||
|
||||
if (c !== null)
|
||||
{
|
||||
// _grunt.log.writeln("Class: " + c);
|
||||
|
||||
if (c != null) {
|
||||
var con = c.constructor;
|
||||
var comments = [];
|
||||
|
||||
comments = comments.concat(this.cleanEndLine(con.description).split("\n"));
|
||||
|
||||
if (con.parameters.length > 0)
|
||||
{
|
||||
if (con.parameters.length > 0) {
|
||||
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];
|
||||
|
||||
if (p.type === "*")
|
||||
{
|
||||
if (p.type === "*") {
|
||||
p.name = "args";
|
||||
}
|
||||
|
||||
var def = "";
|
||||
|
||||
if ((p.default != null) && (p.default !== ""))
|
||||
{
|
||||
if ((p.default != null) && (p.default !== "")) {
|
||||
def = " - Default: " + p.default;
|
||||
}
|
||||
|
||||
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 : ""));
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
comments.push(this.repeatSpaces(("@param " + p.name + " ").length) + paramComments[k].trim() + ((k === paramComments.length - 1) ? def : ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return comments;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.scan = function () {
|
||||
|
||||
this.delintNode(this.sourceFile);
|
||||
|
||||
};
|
||||
|
||||
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 = '';
|
||||
|
||||
if (node.name !== undefined && node.kind === ts.SyntaxKind.ClassDeclaration)
|
||||
{
|
||||
// _grunt.log.writeln("getClassName 1a: " + node.name.text);
|
||||
|
||||
try {
|
||||
if (node.kind === ts.SyntaxKind.ClassDeclaration) {
|
||||
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;
|
||||
|
||||
while (parent !== null && parent !== undefined)
|
||||
{
|
||||
// _grunt.log.writeln("getClassName 2");
|
||||
|
||||
if (parent.kind === ts.SyntaxKind.ModuleDeclaration || parent.kind === ts.SyntaxKind.ClassDeclaration)
|
||||
{
|
||||
while (parent != null) {
|
||||
if (parent.kind === ts.SyntaxKind.ModuleDeclaration || parent.kind === ts.SyntaxKind.ClassDeclaration) {
|
||||
fullName = parent.name.getText() + ((fullName !== '') ? "." + fullName : fullName);
|
||||
}
|
||||
|
||||
parent = parent.parent;
|
||||
}
|
||||
|
||||
if (fullName === undefined || fullName === null)
|
||||
{
|
||||
fullName = '';
|
||||
}
|
||||
|
||||
// _grunt.log.writeln("getClassName: " + fullName);
|
||||
|
||||
return fullName;
|
||||
|
||||
};
|
||||
|
||||
TypeScriptDocGenerator.prototype.delintNode = function (node) {
|
||||
|
||||
var c = this.getClassName(node);
|
||||
|
||||
var r = true;
|
||||
|
||||
try {
|
||||
r = node.getStart();
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
r = false;
|
||||
}
|
||||
|
||||
switch (node.kind)
|
||||
{
|
||||
switch (node.kind) {
|
||||
case ts.SyntaxKind.Constructor:
|
||||
// _grunt.log.writeln("insert1: " + node);
|
||||
|
||||
if (c !== '' && r)
|
||||
{
|
||||
this.insertComment(this.generateConstructorComments(c, r));
|
||||
}
|
||||
|
||||
this.insertComment(this.generateConstructorComments(this.getClassName(node)), node.getStart());
|
||||
break;
|
||||
|
||||
case ts.SyntaxKind.ClassDeclaration:
|
||||
// _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));
|
||||
}
|
||||
|
||||
this.insertComment(this.generateClassComments(this.getClassName(node)), node.getStart());
|
||||
break;
|
||||
|
||||
case ts.SyntaxKind.Property:
|
||||
// _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));
|
||||
}
|
||||
|
||||
this.insertComment(this.generateMemberComments(this.getClassName(node), node.name.getText()), node.getStart());
|
||||
break;
|
||||
|
||||
case ts.SyntaxKind.Method:
|
||||
// _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));
|
||||
}
|
||||
|
||||
this.insertComment(this.generateFunctionComments(this.getClassName(node), node.name.getText()), node.getStart());
|
||||
break;
|
||||
}
|
||||
|
||||
ts.forEachChild(node, this.delintNodeFunction);
|
||||
|
||||
};
|
||||
|
||||
return TypeScriptDocGenerator;
|
||||
|
||||
})();
|
||||
|
||||
module.exports = function (grunt) {
|
||||
|
||||
_grunt = grunt;
|
||||
|
||||
grunt.registerMultiTask('buildtsdoc', 'Generate a TypeScript def with comments', function () {
|
||||
var tsdg = new TypeScriptDocGenerator(this.data.tsDefFileName, this.data.jsdocJsonFileName);
|
||||
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
|
||||
|
||||
declare module "phaser" {
|
||||
export = Phaser;
|
||||
}
|
||||
|
||||
export class Phaser {
|
||||
declare class Phaser {
|
||||
|
||||
static VERSION: string;
|
||||
static DEV_VERSION: string;
|
||||
|
@ -87,7 +89,7 @@ declare module "phaser" {
|
|||
|
||||
}
|
||||
|
||||
export module Phaser {
|
||||
declare module Phaser {
|
||||
|
||||
class Animation {
|
||||
|
||||
|
@ -2803,12 +2805,7 @@ declare module "phaser" {
|
|||
game: Phaser.Game;
|
||||
ninja: Phaser.Physics.Ninja;
|
||||
p2: Phaser.Physics.P2;
|
||||
//todo box2d
|
||||
box2d: any;
|
||||
//todo chipmunk
|
||||
//chipmunk: any;
|
||||
//todo matter
|
||||
//matter: any;
|
||||
|
||||
clear(): void;
|
||||
destroy(): void;
|
||||
|
@ -3057,7 +3054,7 @@ declare module "phaser" {
|
|||
|
||||
constructor(game: Phaser.Game);
|
||||
|
||||
game: Phaser.Game
|
||||
game: Phaser.Game;
|
||||
gravity: number;
|
||||
bounds: Phaser.Rectangle;
|
||||
maxObjects: number;
|
||||
|
@ -4652,8 +4649,8 @@ declare module "phaser" {
|
|||
height: number;
|
||||
incorrectOrientation: boolean;
|
||||
isFullScreen: boolean;
|
||||
isGameLandscape: boolean; //readonly
|
||||
isGamePortrait: boolean; //readonly
|
||||
isGameLandscape: boolean;
|
||||
isGamePortrait: boolean;
|
||||
isPortrait: boolean;
|
||||
isLandscape: boolean;
|
||||
leaveIncorrectOrientation: Signal;
|
||||
|
@ -4931,7 +4928,7 @@ declare module "phaser" {
|
|||
|
||||
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;
|
||||
bottom: number;
|
||||
|
@ -5357,7 +5354,6 @@ declare module "phaser" {
|
|||
pendingDelete: boolean;
|
||||
properties: any;
|
||||
repeatCounter: number;
|
||||
//repeatDelay: number;
|
||||
reverse: boolean;
|
||||
target: any;
|
||||
timeline: Phaser.TweenData[];
|
||||
|
@ -5618,12 +5614,10 @@ declare module "phaser" {
|
|||
sortTopBottom(a: Phaser.Sprite, b: Phaser.Sprite): number;
|
||||
sortBottomTop(a: Phaser.Sprite, b: Phaser.Sprite): number;
|
||||
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;
|
||||
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 canUseNewCanvasBlendModes(): boolean;
|
||||
export function getNextPowerOfTwo(number: number): number;
|
||||
export function getNextPowerOfTwo(value: number): number;
|
||||
|
||||
export function AjaxRequest(): XMLHttpRequest;
|
||||
|
||||
|
@ -74,7 +74,7 @@ declare module PIXI {
|
|||
|
||||
|
||||
export interface IEventCallback {
|
||||
(e?: IEvent): void
|
||||
(e?: IEvent): void;
|
||||
}
|
||||
|
||||
export interface IEvent {
|
||||
|
@ -87,7 +87,7 @@ declare module PIXI {
|
|||
}
|
||||
|
||||
export interface IInteractionDataCallback {
|
||||
(interactionData: InteractionData): void
|
||||
(interactionData: InteractionData): void;
|
||||
}
|
||||
|
||||
export interface PixiRenderer {
|
||||
|
@ -917,7 +917,7 @@ declare module PIXI {
|
|||
constructor(...points: Point[]);
|
||||
constructor(...points: number[]);
|
||||
|
||||
points: any[]; //number[] Point[]
|
||||
points: any[];
|
||||
|
||||
clone(): Polygon;
|
||||
contains(x: number, y: number): boolean;
|
||||
|
@ -1073,7 +1073,7 @@ declare module PIXI {
|
|||
TRIANGLE_STRIP: number;
|
||||
TRIANGLES: number;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
constructor(texture: Texture);
|
||||
|
||||
|
@ -1274,7 +1274,7 @@ declare module PIXI {
|
|||
|
||||
static renderGraphics(graphics: Graphics, renderRession: RenderSession): 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 buildRoundedRectangle(graphicsData: GraphicsData, webGLData: any): void;
|
||||
static quadraticBezierCurve(fromX: number, fromY: number, cpX: number, cpY: number, toX: number, toY: number): number[];
|
||||
|
@ -1396,7 +1396,7 @@ declare module PIXI {
|
|||
textures: Texture[];
|
||||
shaders: IPixiShader[];
|
||||
size: number;
|
||||
sprites: any[]; //todo Sprite[]?
|
||||
sprites: any[];
|
||||
vertices: number[];
|
||||
vertSize: number;
|
||||
|
||||
|
@ -1767,7 +1767,7 @@ declare module PIXI {
|
|||
rgb888: number;
|
||||
rgba8888: number;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
static TextureFilter: {
|
||||
|
||||
|
@ -1779,7 +1779,7 @@ declare module PIXI {
|
|||
mipMapNearestLinear: number;
|
||||
mipMapLinearLinear: number;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
static textureWrap: {
|
||||
|
||||
|
@ -1787,7 +1787,7 @@ declare module PIXI {
|
|||
clampToEdge: number;
|
||||
repeat: number;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
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