type2docfx
Version:
A tool to convert json format output from TypeDoc to schema driven reference model for DocFx to consume.
70 lines • 3.17 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypeConverter = void 0;
var base_1 = require("./base");
var constants_1 = require("../common/constants");
var TypeConverter = /** @class */ (function (_super) {
__extends(TypeConverter, _super);
function TypeConverter() {
return _super !== null && _super.apply(this, arguments) || this;
}
TypeConverter.prototype.generate = function (node, context) {
// to add this to handle duplicate class and module under the same hirachy
if (node.kindString === 'Class' || node.kindString === 'Interface' || node.kindString === 'Type alias') {
if (context.ParentKind === 'Class' || context.ParentKind === 'Interface') {
var currentUid = context.ParentUid + ("." + node.name);
var mapping = [];
if (this.references.has(context.ParentUid)) {
mapping = this.references.get(context.ParentUid);
}
mapping.push(currentUid);
this.references.set(context.ParentUid, mapping);
}
}
var uid = context.ParentUid + ("." + node.name);
console.log(node.kindString + ": " + uid);
var model = {
uid: uid,
name: node.name,
fullName: node.name + this.getGenericType(node.typeParameter),
children: [],
langs: constants_1.langs,
type: node.kindString.toLowerCase(),
summary: node.comment ? this.findDescriptionInComment(node.comment) : ''
};
if (model.type === 'enumeration') {
model.type = 'enum';
}
if (model.type === 'type alias') {
var typeArgumentsContent = this.parseTypeArgumentsForTypeAlias(node);
if (typeArgumentsContent) {
model.syntax = { content: 'type ' + model.name + typeArgumentsContent + ' = ' + this.parseTypeDeclarationForTypeAlias(node.type) };
}
else {
model.syntax = { content: 'type ' + model.name + ' = ' + this.parseTypeDeclarationForTypeAlias(node.type) };
}
}
if (node.extendedTypes && node.extendedTypes.length) {
model.extends = {
name: this.extractType(node.extendedTypes[0])[0]
};
}
return [model];
};
return TypeConverter;
}(base_1.AbstractConverter));
exports.TypeConverter = TypeConverter;
//# sourceMappingURL=type.js.map