chore(doc-gen): dgenerate the type definition file for angular2
Closes #2017 Closes #1966
This commit is contained in:
parent
91ccc9af98
commit
f6eeb9aa66
|
@ -38,6 +38,7 @@ module.exports = new Package('angular', [jsdocPackage, nunjucksPackage, linksPac
|
|||
.processor(require('./processors/generateNavigationDoc'))
|
||||
.processor(require('./processors/extractTitleFromGuides'))
|
||||
.processor(require('./processors/createOverviewDump'))
|
||||
.processor(require('./processors/createTypeDefinitionFile'))
|
||||
|
||||
|
||||
// Configure the log service
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
var _ = require('lodash');
|
||||
|
||||
module.exports = function createTypeDefinitionFile() {
|
||||
|
||||
return {
|
||||
$runAfter: ['processing-docs'],
|
||||
$runBefore: ['docs-processed'],
|
||||
$process: function(docs) {
|
||||
var typeDefDoc = {
|
||||
id: 'type-definition',
|
||||
aliases: ['type-definition'],
|
||||
path: 'type-definition',
|
||||
outputPath: 'angular2.d.ts',
|
||||
modules: []
|
||||
};
|
||||
_.forEach(docs, function(doc) {
|
||||
if ( doc.docType === 'module' ) {
|
||||
typeDefDoc.modules.push(doc);
|
||||
}
|
||||
});
|
||||
docs.push(typeDefDoc);
|
||||
}
|
||||
};
|
||||
};
|
|
@ -127,6 +127,8 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo
|
|||
};
|
||||
if(exportSymbol.flags & ts.SymbolFlags.Function) {
|
||||
exportDoc.parameters = getParameters(typeChecker, exportSymbol);
|
||||
}
|
||||
if(exportSymbol.flags & ts.SymbolFlags.Value) {
|
||||
exportDoc.returnType = getReturnType(typeChecker, exportSymbol);
|
||||
}
|
||||
return exportDoc;
|
||||
|
@ -148,7 +150,6 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo
|
|||
// with the `params` property that will be updated by dgeni reading the
|
||||
// `@param` tags from the docs
|
||||
memberDoc.parameters = getParameters(typeChecker, memberSymbol);
|
||||
memberDoc.returnType = getReturnType(typeChecker, memberSymbol);
|
||||
}
|
||||
|
||||
if (memberSymbol.flags & ts.SymbolFlags.Constructor) {
|
||||
|
@ -156,6 +157,10 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo
|
|||
memberDoc.name = 'constructor';
|
||||
}
|
||||
|
||||
if(memberSymbol.flags & ts.SymbolFlags.Value) {
|
||||
memberDoc.returnType = getReturnType(typeChecker, memberSymbol);
|
||||
}
|
||||
|
||||
return memberDoc;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
{%- macro commentBlock(doc, level) -%}
|
||||
{%- if doc.content | trim %}
|
||||
{% if level > 1 %}{$ '/**' | indent(level-1, true) | replace(r/\n$/, "") $}{% else %}/**{% endif %}
|
||||
{$ doc.content | replace(r/^/gm, "* ") | indent(level, true) | replace(r/\n$/, "") $}
|
||||
{$ '*/' | indent(level, true) | replace(r/\n$/, "") $}{% endif -%}
|
||||
{%- endmacro -%}
|
||||
|
||||
// Type definitions for Angular v2.0.0-alpha.22
|
||||
// Project: http://angular.io/
|
||||
// Definitions by: angular team <https://github.com/angular/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
{% for module in doc.modules %}
|
||||
{$ commentBlock(module, 1) $}
|
||||
declare module "{$ module.id $}" {
|
||||
|
||||
{% for export in module.exports -%}
|
||||
{$ commentBlock(export, 3) $}
|
||||
{$ export.docType $} {$ export.name $}
|
||||
{%- if export.docType == 'class' or export.docType == 'interface' %} {
|
||||
{% for member in export.members -%}
|
||||
{$ commentBlock(member, 5) $}
|
||||
{$ member.name $}
|
||||
{%- if member.parameters %}({% for param in member.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}){%- endif %}
|
||||
{%- if member.returnType %} : {$ member.returnType $} {% endif %}
|
||||
{% endfor %}
|
||||
}
|
||||
{%- else -%}
|
||||
{% if export.parameters %}({% for param in export.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}){%- endif %}
|
||||
{%- if export.returnType %} : {$ export.returnType $} {% endif -%}
|
||||
{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
}
|
||||
|
||||
{% endfor %}
|
||||
|
Loading…
Reference in New Issue