chore(doc-gen): generate router typings file

Closes #2659
This commit is contained in:
Peter Bacon Darwin
2015-07-02 08:13:54 +01:00
parent a7ea2e5566
commit 561b78a5b3
3 changed files with 95 additions and 43 deletions

View File

@ -1,27 +1,77 @@
var _ = require('lodash');
var path = require('canonical-path');
module.exports = function createTypeDefinitionFile() {
module.exports = function createTypeDefinitionFile(log) {
return {
$runAfter: ['processing-docs'],
$runBefore: ['docs-processed'],
$process: function(docs) {
var typeDefDoc = {
id: 'type-definition',
aliases: ['type-definition'],
path: 'type-definition',
outputPath: 'typings/angular2/angular2.d.ts',
modules: []
};
_.forEach(docs, function(doc) {
// The shape of the public API is determined by what is reexported into
// angular2/angular2, with hacks layered into angular2.api.ts
if (doc.id === 'angular2/angular2.api') {
doc.id = 'angular2/angular2';
typeDefDoc.modules.push(doc);
$validate: {
dtsPath: { presence: true },
dtsExtension: { presence: true },
typeDefinitions: { presence: true }
},
dtsPath: 'typings',
dtsExtension: '.d.ts',
typeDefinitions: [
{
id: 'angular2/angular2',
modules: {
// The shape of the public API is determined by what is reexported into
// angular2/angular2, with hacks layered into angular2.api.ts
'angular2/angular2': 'angular2/angular2.api',
}
},
{
id: 'angular2/router',
modules: {
'angular2/router': 'angular2/router'
}
}
],
$process: function(docs) {
var dtsPath = this.dtsPath;
var dtsExtension = this.dtsExtension;
// For each type definition that we wish to create we define a dgeni "doc" for it
var typeDefDocs = _.map(this.typeDefinitions, function(def) {
var id = def.id + dtsExtension;
var docPath = path.join(dtsPath, id);
return {
docType: 'type-definition',
id: id,
aliases: [id],
path: docPath,
outputPath: docPath,
// A type definition may include a number of top level modules
// And those modules could be aliased (such as 'angular2/angular2.api' -> 'angular2/angular2')
moduleDocs: _.transform(def.modules, function(moduleDocs, id, alias) {
moduleDocs[id] = { id: alias, doc: null };
})
};
});
docs.push(typeDefDoc);
// Now add all the module docs to their corresponding type definition doc
_.forEach(docs, function(doc) {
_.forEach(typeDefDocs, function(typeDefDoc) {
if(typeDefDoc.moduleDocs[doc.id]) {
typeDefDoc.moduleDocs[doc.id].doc = doc;
}
});
});
_.forEach(typeDefDocs, function(doc) {
_.forEach(doc.moduleDocs, function(modDoc, alias) {
if (!modDoc.doc) {
log.error('createTypeDefinitionFile processor: no such module "' + alias + '" (Did you forget to add it to the modules to load?)');
}
});
});
// Add all the type definition docs to the docs collection so that dgeni can process them
return docs.concat(typeDefDocs);
}
};
};