UNPKG

devui-admin-test

Version:

Schematics for ng-devui-admin

71 lines 3.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getModuleName = exports.getRoutingModule = exports.getPageNameFromFilePath = exports.addRouteToNgModule = exports.addDeclaration = exports.addModule = void 0; const schematics_1 = require("@angular-devkit/schematics"); const core_1 = require("@angular-devkit/core"); const change_1 = require("@schematics/angular/utility/change"); const ast_utils_1 = require("@schematics/angular/utility/ast-utils"); const schematics_2 = require("@angular/cdk/schematics"); const insert_1 = require("./insert"); function addModule(filePath, moduleName, modulePath) { return (tree) => { schematics_2.addModuleImportToModule(tree, filePath, moduleName, modulePath); return tree; }; } exports.addModule = addModule; function addDeclaration(componentName, modulePath, relativePath) { return (tree) => { const source = insert_1.readIntoSourceFile(tree, modulePath); const declarationChanges = schematics_2.addDeclarationToModule(source, modulePath, componentName, relativePath); const declarationRecorder = tree.beginUpdate(modulePath); for (const change of declarationChanges) { if (change instanceof change_1.InsertChange) { declarationRecorder.insertLeft(change.pos, change.toAdd); } } tree.commitUpdate(declarationRecorder); return schematics_1.noop(); }; } exports.addDeclaration = addDeclaration; function addRouteToNgModule(tree, path, componentName, routePath, relativePath) { const sourceFile = insert_1.readIntoSourceFile(tree, path); const routeDeclarationChange = ast_utils_1.addRouteDeclarationToModule(sourceFile, path, buildRoute(routePath, componentName)); const symbolName = `${core_1.strings.classify(componentName)}Component`; const importChange = ast_utils_1.insertImport(sourceFile, path, symbolName, relativePath); let changes = []; changes.push(routeDeclarationChange); changes.push(importChange); const recorder = tree.beginUpdate(path); for (const change of changes) { if (change instanceof change_1.InsertChange) { recorder.insertLeft(change.pos, change.toAdd); } } tree.commitUpdate(recorder); return tree; } exports.addRouteToNgModule = addRouteToNgModule; function getPageNameFromFilePath(filePath) { let pathArray = filePath.split(/(\/|\\)/); let pageName = pathArray[pathArray.length - 1]; return pageName; } exports.getPageNameFromFilePath = getPageNameFromFilePath; function getRoutingModule(tree, modulePath) { const routingModulePath = modulePath.endsWith('-routing.module.ts') ? modulePath : modulePath.replace('.module.ts', '-routing.module.ts'); return tree.exists(routingModulePath) ? routingModulePath : undefined; } exports.getRoutingModule = getRoutingModule; function getModuleName(modulePath) { const module = modulePath.endsWith('.module.ts') ? modulePath.replace('.module.ts', '') : modulePath; const moduleArr = module.split('/'); return moduleArr[moduleArr.length - 1]; } exports.getModuleName = getModuleName; function buildRoute(routePath, componentName) { // options.routePath return `{ path: '${routePath}', component: ${core_1.strings.classify(componentName)}Component }`; } //# sourceMappingURL=file-modify.js.map