UNPKG

angular-docgen

Version:

A toolkit to extract information from Angular components for documentation generation.

41 lines 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var ts = require("typescript"); var getConstructorProperty = function (node, propName) { var decorators = (node.decorators); if (!decorators) return null; var componentNode = (decorators.find(function (decorator) { return decorator.expression.expression.getText() === "Component"; })); var decoratorArgs = (componentNode.expression).arguments; var propertyList = (decoratorArgs.find(function (node) { return node.kind === ts.SyntaxKind.ObjectLiteralExpression; })); var decoratorProps = propertyList.properties; var propertyNode = (decoratorProps.find(function (node) { return node.name.getText() === propName; })); if (!propertyNode) return null; var initializer = propertyNode.initializer; switch (initializer.kind) { case ts.SyntaxKind.ArrayLiteralExpression: return initializer.elements.map(function (node) { return node.getText().replace(/"|'/g, ""); }); default: return initializer.getText().replace(/"|'/g, ""); } }; exports.default = (function (node) { var className = (ts.getNameOfDeclaration(node)); var componentDoc = { description: node.jsDoc ? node.jsDoc.map(function (doc) { return doc.comment; }).join("\n") : null, name: className && className.getText(), selector: getConstructorProperty(node, "selector"), styles: getConstructorProperty(node, "styles"), styleUrls: getConstructorProperty(node, "styleUrls"), templateUrl: getConstructorProperty(node, "templateUrl"), template: getConstructorProperty(node, "template") }; return componentDoc; }); //# sourceMappingURL=classDeclarationHandler.js.map