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>

54 lines 2.74 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"); const demoTemplates = ['ng-doc.module.ts.template']; /** * Generates a NgDocPage * @param {NgDocBuildPageSchema} options - The options to generate the page * @returns {Rule} Angular Schematic Rule */ function generate(options) { return (host) => { const pageName = options.name ?? (0, strings_1.classify)(options.title + 'Page'); options.title = (0, utils_1.getTitle)(options.title); options.keyword = options.keyword ?? pageName; (0, utils_1.varNameValidation)(pageName); const execPath = options?.path ?? ''; const pageFolder = (0, strings_1.dasherize)(options.name ?? '').replace(/-page$/, '') || (0, strings_1.dasherize)(options.title); const path = (0, path_1.join)(execPath, `/${pageFolder}`); const closestCategoryFile = (options.category && (0, utils_1.findClosestFile)(host, execPath, variables_1.CATEGORY_NAME)) || null; const categoryConstantName = (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.filter)((path) => !demoTemplates.includes((0, path_1.basename)(path))), (0, schematics_1.applyTemplates)({ ...options, categoryName: categoryConstantName, importPath: categoryImportPath, pageName, keyword: options.keyword, }), (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