-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathTSDoc.js
More file actions
99 lines (81 loc) · 2.34 KB
/
TSDoc.js
File metadata and controls
99 lines (81 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function HTMLEncode(str){
var i = str.length,
aRet = [];
while (i--) {
var iC = str[i].charCodeAt();
if (iC < 65 || iC > 127 || (iC>90 && iC<97)) {
aRet[i] = '&#'+iC+';';
} else {
aRet[i] = str[i];
}
}
return aRet.join('');
}
var path = require( 'path' );
var fs = require( 'fs' );
var configFile = process.cwd()+path.sep+'tsdoc.json';
var configContents = fs.readFileSync( configFile,'utf8');
var config = JSON.parse( configContents );
exports.defineTags = function(dictionary) {
dictionary.defineTag('implements', {
mustHaveValue:true,
canHaveType:true,
onTagged: function(doclet, tag) {
doclet.implements = doclet.implements || [];
doclet.implements.push( { name:tag.text, link:"{@link "+tag.text+"}" } );
}
});
dictionary.defineTag('generic', {
onTagged: function(doclet, tag) {
doclet.genericAnnotation = HTMLEncode( tag.text ) ||"";
}
});
dictionary.defineTag('ts_enum', {
onTagged: function(doclet, tag) {
doclet.isTSEnum = true;
//console.log( doclet, tag )
}
});
dictionary.lookUp('augments').synonym('extends');
}
exports.handlers = {
newDoclet: function(e) {
// e.doclet will refer to the newly created doclet
// you can read and modify properties of that doclet if you wish
if(e.doclet.kind == "class")
{
//console.log(e.doclet)
}
},
beforeParse: function(e) {
if( config.tsdoc.commentsOnly )
{
// Remove All but conserve Comments
var comments = e.source.match(/\/\*\*[\s\S]+?\*\//g);
if (comments) {
e.source = comments.join('\n\n');
}
else {
e.source = "";
return;
}
}
// Search for class declarations and check for generics descriptors
// Replace it to clean class name & new doclet @generic with the generics descriptor
var findClasses = /(@class .*)(<.*>)/g;
var foundClasses;
while ( foundClasses = findClasses.exec(e.source))
{
e.source = e.source.replace( foundClasses[0], foundClasses[1]+'\n * @generic '+foundClasses[2])
}
// Search for class declarations and check for generics descriptors
// Replace it to clean class name & new doclet @generic with the generics descriptor
var findEnums = /(@tsenum )(.*)/g;
var foundEnums;
while ( foundEnums = findEnums.exec(e.source))
{
e.source = e.source.replace( foundEnums[0], "@typedef "+foundEnums[2]+'\n * @ts_enum ')
}
//console.log( e.source )
}
};