UNPKG

ng-devui-admin

Version:

Schematics for ng-devui-admin

64 lines 3.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const schematics_1 = require("@angular-devkit/schematics"); const core_1 = require("@angular-devkit/core"); const find_module_1 = require("@schematics/angular/utility/find-module"); const utils_1 = require("../utils"); function genAddMaterialsRules(blocks, options) { let rules = []; blocks.forEach((block) => { rules.push((0, schematics_1.schematic)('blocks', { blockName: block, dirPath: `${options.dirPath}/${core_1.strings.dasherize(options.viewName)}`, importWay: options.importWay, })); }); return (0, schematics_1.chain)(rules); } function buildPageRoute(options, modulePath) { return `{ title: '${core_1.strings.classify(options.viewName)}', link: '/pages/${(0, utils_1.getModuleName)(modulePath)}/${options.routePath}' },`; } function default_1(options) { return (tree) => { const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [ (0, schematics_1.applyTemplates)({ viewName: options.viewName, style: options.style, selector: options.selector, dasherize: core_1.strings.dasherize, classify: core_1.strings.classify, }), (0, schematics_1.move)(options.dirPath), ]); // 创建空页面啊后,在插入的module中引入页面的declaration const modulePath = (0, find_module_1.findModule)(tree, options.dirPath); const componentName = `${core_1.strings.classify(options.viewName)}Component`; const relativePath = (0, find_module_1.buildRelativePath)(modulePath, `/${options.dirPath}/${core_1.strings.dasherize(options.viewName)}/${core_1.strings.dasherize(options.viewName)}.component`); let routingModulePath = (0, utils_1.getRoutingModule)(tree, modulePath); if (routingModulePath) { (0, utils_1.addRouteToNgModule)(tree, routingModulePath, options.viewName, options.routePath, relativePath); if (options.addToNav) { (0, utils_1.insertTSArray)(tree, '/src/app/pages/pages.component.ts', buildPageRoute(options, modulePath), 'this.menu', 'end'); } } else { throw new schematics_1.SchematicsException('Please make sure a routing module is existed.'); } let blocks = []; if (options.blocks) { blocks = options.blocks.split(' '); } if (blocks.length > 0) { return (0, schematics_1.chain)([ (0, schematics_1.mergeWith)(templateSource), (0, utils_1.addDeclaration)(componentName, modulePath, relativePath), genAddMaterialsRules(blocks, options), ]); } else { return (0, schematics_1.chain)([(0, schematics_1.mergeWith)(templateSource), (0, utils_1.addDeclaration)(componentName, modulePath, relativePath)]); } }; } exports.default = default_1; //# sourceMappingURL=index.js.map