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>

52 lines 2.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generate = generate; const strings_1 = require("@angular-devkit/core/src/utils/strings"); const schematics_1 = require("@angular-devkit/schematics"); const path_1 = require("path"); const variables_1 = require("../../engine/variables"); const posix_1 = require("../../helpers/posix"); const utils_1 = require("../utils"); const extract_default_export_name_1 = require("../utils/extract-default-export-name"); /** * Generates a NgDocCategory * @param {NgDocBuildCategorySchema} options - The options to generate the category * @returns {Rule} Angular Schematic Rule */ function generate(options) { return (host) => { options.title = (0, utils_1.getTitle)(options.title); const categoryName = options.name ?? `${(0, strings_1.classify)(options.title)}Category`; (0, utils_1.varNameValidation)(categoryName); const execPath = options?.path ?? ''; const categoryFolder = (0, strings_1.dasherize)(options.name ?? '').replace(/-category$/, '') || (0, strings_1.dasherize)(options.title); const path = (0, path_1.join)(execPath, `/${categoryFolder}`); const closestCategoryFile = options.category ? (0, utils_1.findClosestFile)(host, options?.path ?? '', variables_1.CATEGORY_NAME) : null; const parentCategoryName = options.category && closestCategoryFile ? (0, extract_default_export_name_1.extractDefaultExportName)(host, closestCategoryFile) : null; const categoryImportPath = closestCategoryFile ? (0, posix_1.posix)((0, path_1.relative)(path, closestCategoryFile)).replace(/.ts$/, '') : null; return (0, schematics_1.chain)([ (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [ (0, schematics_1.applyTemplates)({ ...options, categoryName, parentCategoryName, importPath: categoryImportPath, }), (0, schematics_1.move)(path), (0, schematics_1.forEach)((fileEntry) => { if (host.exists(fileEntry.path)) { host.overwrite(fileEntry.path, fileEntry.content); } return fileEntry; }), ]), schematics_1.MergeStrategy.Overwrite), ]); }; } //# sourceMappingURL=index.js.map