UNPKG

@ng-doc/builder

Version:

<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>

72 lines 3.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createEntryMetadata = createEntryMetadata; const tslib_1 = require("tslib"); const core_1 = require("@ng-doc/core"); const minimatch_1 = require("minimatch"); const path_1 = tslib_1.__importDefault(require("path")); const rxjs_1 = require("rxjs"); const helpers_1 = require("../../../helpers"); const variables_1 = require("../../variables"); const get_category_source_file_1 = require("./get-category-source-file"); const get_entry_out_dir_1 = require("./get-entry-out-dir"); const get_entry_route_1 = require("./get-entry-route"); const get_variable_statement_from_object_literal_expression_1 = require("./get-variable-statement-from-object-literal-expression"); /** * * @param context * @param entry * @param sourceFile */ function createEntryMetadata(context, entry, sourceFile) { const entryPath = sourceFile.getFilePath(); const dir = sourceFile.getDirectoryPath(); const dirName = path_1.default.basename(dir); const route = (0, get_entry_route_1.getEntryRoute)(entry, entryPath); const categorySourceFile = entry.category && (0, get_category_source_file_1.getCategorySourceFile)(sourceFile); const outDir = (0, get_entry_out_dir_1.getEntryOutDir)(context, entry, entryPath); const isCategory = (0, minimatch_1.minimatch)(entryPath, variables_1.CATEGORY_PATTERN); return { dir, dirName, route, outDir, outPath: path_1.default.join(outDir, 'page.ts'), sourceFile, objectExpression: () => { const objectExpression = (0, helpers_1.getObjectExpressionFromDefault)(sourceFile); if (!objectExpression) { throw new Error(`No object expression found in ${entryPath}, make sure the file has a default export.`); } return objectExpression; }, path: entryPath, title: entry.title, keywordTitle: entry.title, order: entry.order, nestedRoutes: !isCategory, jsDocMetadata: function () { const statement = (0, get_variable_statement_from_object_literal_expression_1.getVariableStatementFromObjectLiteralExpression)(this.objectExpression()); const description = (0, helpers_1.getJsDocDescription)(statement); const tags = (0, helpers_1.getAllJsDocTags)(statement); return { description, tags, }; }, absoluteRoute: function () { return (0, helpers_1.posix)(path_1.default.join(...(0, core_1.asArray)(this.parent?.absoluteRoute() ?? context.config.routePrefix, this.route))); }, breadcrumbs: function () { return (0, core_1.asArray)(this.parent?.breadcrumbs(), this.entry.title); }, refresh: async function () { }, selfDestroy: rxjs_1.NEVER, // @ts-expect-error - This is a valid assignment parent: entry.category && categorySourceFile ? createEntryMetadata(context, entry.category, categorySourceFile) : undefined, entry, }; } //# sourceMappingURL=create-entry-metadata.js.map