Skip to content

Commit 9a72f19

Browse files
chore(doc-gen): add TypeScript parsing
1 parent 25a9527 commit 9a72f19

File tree

16 files changed

+546
-19
lines changed

16 files changed

+546
-19
lines changed

docs/angular.io-package/templates/class.template.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
{% block body %}
55
p.location-badge.
6-
exported from <a href="/{$ doc.moduleDoc.path $}">{$ doc.moduleDoc.id $}</a>
7-
defined in <a href="https://github.com/angular/angular/tree/master/modules/{$ doc.location.start.source.name $}.js#L{$ doc.location.start.line $}">{$ doc.location.start.source.name $}.js (line {$ doc.location.start.line $})</a>
6+
exported from {@link {$ doc.moduleDoc.id $} {$doc.moduleDoc.id $} }
7+
defined in <a href="https://github.com/angular/angular/tree/master/modules/{$ doc.fileInfo.relativePath $}#L{$ doc.location.start.line+1 $}-L{$ doc.location.end.line+1 $}">{$ doc.fileInfo.relativePath $} (line {$ doc.location.start.line+1 $})</a>
88

99
:markdown
1010
{$ doc.description | indent(2, true) $}
@@ -17,10 +17,10 @@
1717
.l-sub-section
1818
h3 {$ doc.constructorDoc.name $}
1919

20-
{% if doc.constructorDoc.params %}
20+
{% if doc.constructorDoc.parameters %}
2121
pre.prettyprint
2222
code.
23-
{$ doc.constructorDoc.name $}{$ paramList(doc.constructorDoc.params) | indent(4, true) | trim $}
23+
{$ doc.constructorDoc.name $}{$ paramList(doc.constructorDoc.parameters) | indent(4, true) | trim $}
2424
{% endif %}
2525
:markdown
2626
{$ doc.constructorDoc.description | indent(6, true) | replace('## Example', '') | replace('# Example', '') $}
@@ -32,10 +32,10 @@
3232
.l-sub-section
3333
h3 {$ member.name $}
3434

35-
{% if member.params %}
35+
{% if member.parameters %}
3636
pre.prettyprint
3737
code.
38-
{$ member.name $}{$ paramList(member.params) | indent(4, true) | trim $}
38+
{$ member.name $}{$ paramList(member.parameters) | indent(4, true) | trim $}{$ returnType(doc.returnType) $}
3939
{% endif %}
4040
:markdown
4141

docs/angular.io-package/templates/function.template.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
.l-main-section
66
h2(class="function export") {$ doc.name $}
77

8-
p <code>{$ paramList(doc.parameters) $}</code>
8+
{% if doc.parameters %}
9+
pre.prettyprint
10+
code.
11+
{$ doc.name $}{$ paramList(doc.parameters) | indent(4, true) | trim $}{$ returnType(doc.returnType) $}
12+
{% endif %}
913

1014
p.location-badge.
11-
exported from <a href="/{$ doc.moduleDoc.path $}">{$ doc.moduleDoc.id $}</a>
15+
exported from {@link {$ doc.moduleDoc.id $} {$doc.moduleDoc.id $} }
16+
defined in <a href="https://github.com/angular/angular/tree/master/modules/{$ doc.fileInfo.relativePath $}#L{$ doc.location.start.line+1 $}-L{$ doc.location.end.line+1 $}">{$ doc.fileInfo.relativePath $} (line {$ doc.location.start.line+1 $})</a>
1217

1318
:markdown
1419
{$ doc.description | indent(4, true) $}

docs/angular.io-package/templates/lib/paramList.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
{$ param | escape $}{% if not loop.last %}, {% endif %}
55
{%- endfor %})
66
{%- endif %}
7-
{%- endmacro -%}
7+
{%- endmacro -%}
8+
9+
10+
{% macro returnType(returnType) -%}
11+
{%- if returnType %} : {$ returnType | escape $}{% endif -%}
12+
{%- endmacro -%}

docs/angular.io-package/templates/module.template.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{% extends 'layout/base.template.html' -%}
22
{% block body -%}
3+
p.location-badge.
4+
defined in <a href="https://github.com/angular/angular/tree/master/modules/{$ doc.fileInfo.relativePath $}#L{$ doc.location.start.line+1 $}-L{$ doc.location.end.line+1 $}">{$ doc.fileInfo.relativePath $} (line {$ doc.location.start.line+1 $})</a>
5+
36
ul
47
for page, slug in public.docs[current.path[1]][current.path[2]][current.path[3]][current.path[4]]._data
58
if slug != 'index'

docs/dgeni-package/index.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ module.exports = new Package('angular', [jsdocPackage, nunjucksPackage, linksPac
1515

1616
// Register the services and file readers
1717
.factory(require('./services/modules'))
18+
.factory(require('./services/tsParser'))
19+
.factory(require('./services/tsParser/createCompilerHost'))
20+
.factory(require('./services/tsParser/getFileInfo'))
21+
.factory(require('./services/tsParser/getExportDocType'))
22+
.factory(require('./services/tsParser/getContent'))
1823
.factory(require('./readers/ngdoc'))
1924

2025
.factory('EXPORT_DOC_TYPES', function() {
@@ -28,6 +33,7 @@ module.exports = new Package('angular', [jsdocPackage, nunjucksPackage, linksPac
2833

2934

3035
// Register the processors
36+
.processor(require('./processors/readTypeScriptModules'))
3137
.processor(require('./processors/generateNavigationDoc'))
3238
.processor(require('./processors/extractTitleFromGuides'))
3339
.processor(require('./processors/createOverviewDump'))
@@ -40,20 +46,38 @@ module.exports = new Package('angular', [jsdocPackage, nunjucksPackage, linksPac
4046

4147

4248
// Configure file reading
43-
.config(function(readFilesProcessor, ngdocFileReader) {
49+
.config(function(readFilesProcessor, ngdocFileReader, readTypeScriptModules) {
4450
readFilesProcessor.fileReaders = [ngdocFileReader];
4551
readFilesProcessor.basePath = path.resolve(__dirname, '../..');
4652
readFilesProcessor.sourceFiles = [
4753
{ include: 'modules/*/docs/**/*.md', basePath: 'modules' },
4854
{ include: 'docs/content/**/*.md', basePath: 'docs/content' }
4955
];
56+
57+
readTypeScriptModules.sourceFiles = [
58+
'*/*.js',
59+
'*/src/**/*.js',
60+
'*/*.es6',
61+
'*/src/**/*.es6',
62+
'*/*.ts',
63+
'*/src/**/*.ts'
64+
];
65+
readTypeScriptModules.basePath = 'modules';
5066
})
5167

5268

5369
.config(function(parseTagsProcessor, getInjectables) {
5470
parseTagsProcessor.tagDefinitions.push(require('./tag-defs/public'));
5571
parseTagsProcessor.tagDefinitions.push(require('./tag-defs/private'));
5672
parseTagsProcessor.tagDefinitions.push(require('./tag-defs/exportedAs'));
73+
74+
// We actually don't want to parse param docs in this package as we are getting the data out using TS
75+
parseTagsProcessor.tagDefinitions.forEach(function(tagDef) {
76+
if (tagDef.name === 'param') {
77+
tagDef.ignore = true;
78+
}
79+
});
80+
5781
})
5882

5983

@@ -88,12 +112,6 @@ module.exports = new Package('angular', [jsdocPackage, nunjucksPackage, linksPac
88112
// Configure ids and paths
89113
.config(function(computeIdsProcessor, computePathsProcessor, EXPORT_DOC_TYPES) {
90114

91-
computeIdsProcessor.idTemplates.push({
92-
docTypes: EXPORT_DOC_TYPES,
93-
idTemplate: '${moduleDoc.id}.${name}',
94-
getAliases: function(doc) { return [doc.id, doc.name]; }
95-
});
96-
97115
computeIdsProcessor.idTemplates.push({
98116
docTypes: ['member'],
99117
idTemplate: '${classDoc.id}.${name}',
@@ -117,7 +135,7 @@ module.exports = new Package('angular', [jsdocPackage, nunjucksPackage, linksPac
117135

118136
computePathsProcessor.pathTemplates.push({
119137
docTypes: ['module'],
120-
pathTemplate: '${id}',
138+
pathTemplate: '/${id}',
121139
outputPathTemplate: MODULES_DOCS_PATH + '/${id}/index.html'
122140
});
123141

@@ -136,7 +154,7 @@ module.exports = new Package('angular', [jsdocPackage, nunjucksPackage, linksPac
136154

137155
computePathsProcessor.pathTemplates.push({
138156
docTypes: ['guide'],
139-
pathTemplate: '${id}',
157+
pathTemplate: '/${id}',
140158
outputPathTemplate: GUIDES_PATH + '/${id}.html'
141159
});
142160
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export var x = 100;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @module
3+
* @description
4+
* This is the module description
5+
*/
6+
7+
export * from 'importedSrc';
8+
9+
/**
10+
* This is some random other comment
11+
*/
12+
13+
/**
14+
* This is MyClass
15+
*/
16+
export class MyClass {
17+
message: String;
18+
19+
/**
20+
* Create a new MyClass
21+
* @param {String} name The name to say hello to
22+
*/
23+
constructor(name) {
24+
this.message = 'hello ' + name;
25+
}
26+
27+
/**
28+
* Return a greeting message
29+
*/
30+
greet() {
31+
return this.message;
32+
}
33+
}
34+
35+
/**
36+
* An exported function
37+
*/
38+
export var myFn = (val:number) => { return val*2; }

0 commit comments

Comments
 (0)