chore(doc-gen): move the "private class" converter into a helper service

This will allow it to be reused in other doc gen configurations
This commit is contained in:
Peter Bacon Darwin
2015-09-04 19:01:26 +01:00
parent be954115f8
commit 4bffd97edd
4 changed files with 111 additions and 24 deletions

View File

@ -2,7 +2,7 @@ var _ = require('lodash');
var path = require('canonical-path');
var codeGen = require('./code_gen.js');
module.exports = function createTypeDefinitionFile(log) {
module.exports = function createTypeDefinitionFile(log, convertPrivateClassesToInterfaces) {
return {
$runAfter: ['processing-docs'],
@ -63,29 +63,7 @@ module.exports = function createTypeDefinitionFile(log) {
doc = null;
return;
}
_.forEach(modDoc.doc.exports, function(exportDoc) {
// Search for classes with a constructor marked as `@private`
if (exportDoc.docType === 'class' && exportDoc.constructorDoc && exportDoc.constructorDoc.private) {
// Convert this class to an interface with no constructor
exportDoc.docType = 'interface';
exportDoc.constructorDoc = null;
if (exportDoc.heritage) {
// convert the heritage since interfaces use `extends` not `implements`
exportDoc.heritage = exportDoc.heritage.replace('implements', 'extends');
}
// Add the `declare var SomeClass extends InjectableReference` construct
modDoc.doc.exports.push({
docType: 'var',
name: exportDoc.name,
id: exportDoc.id,
returnType: 'InjectableReference'
});
}
});
convertPrivateClassesToInterfaces(modDoc.doc.exports, true);
});
return !!doc;
});