UNPKG

useasdemo

Version:

Schematics specific to ecip

106 lines (104 loc) 5.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MODULE_ROUTE_CONTENTS = { LOG: `\n\t\t\t{ path: 'log', loadChildren: './log/log.module#LogModule' },`, USER: `\n\t\t\t{ path: 'user', loadChildren: './user/user.module#UserModule' },`, PERMISSION: `\n\t\t\t{ path: 'permission', loadChildren: './permission/permission.module#PermissionModule' },`, SYSTEM: `\n\t\t\t{ path: 'system', loadChildren: './system/system.module#SystemModule' },`, APP: `\n\t\t\t{ path: 'app', loadChildren: './app/app.module#AppModule' },`, AUTH: `\n\t\t\t{ path: 'auth', loadChildren: './auth/auth.module#AuthModule' },`, }; function routingModuleContent(addcontents) { const routingModuleContentStart = `import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { environment } from '@env/environment'; // layout import { LayoutDefaultComponent } from '../layout/default/default.component'; import { LayoutFullScreenComponent } from '../layout/fullscreen/fullscreen.component'; import { LayoutPassportComponent } from '../layout/passport/passport.component'; // dashboard pages import { DashboardComponent } from './dashboard/dashboard.component'; // passport pages import { UserLoginComponent } from './passport/login/login.component'; import { UserRegisterComponent } from './passport/register/register.component'; import { UserRegisterResultComponent } from './passport/register-result/register-result.component'; // single pages import { CallbackComponent } from './callback/callback.component'; import { UserLockComponent } from './passport/lock/lock.component'; import { Exception403Component } from './exception/403.component'; import { Exception404Component } from './exception/404.component'; import { Exception500Component } from './exception/500.component'; const routes: Routes = [ { path: '', component: LayoutDefaultComponent, children: [ { path: '', redirectTo: 'dashboard', pathMatch: 'full' }, { path: 'dashboard', component: DashboardComponent, data: { title: '主页'} }, // 业务子模块 // { path: 'widgets', loadChildren: './widgets/widgets.module#WidgetsModule' } `; var fullContent = routingModuleContentStart; addcontents.forEach(content => { fullContent += content; }); fullContent += ` \n] }, // 全屏布局 // { // path: 'fullscreen', // component: LayoutFullScreenComponent, // children: [ // ] // }, // passport { path: 'passport', component: LayoutPassportComponent, children: [ { path: 'login', component: UserLoginComponent, data: { title: '登录', titleI18n: 'pro-login' } }, { path: 'register', component: UserRegisterComponent, data: { title: '注册', titleI18n: 'pro-register' } }, { path: 'register-result', component: UserRegisterResultComponent, data: { title: '注册结果', titleI18n: 'pro-register-result' } } ] }, // 单页不包裹Layout { path: 'callback/:type', component: CallbackComponent }, { path: 'lock', component: UserLockComponent, data: { title: '锁屏', titleI18n: 'lock' } }, { path: '403', component: Exception403Component }, { path: '404', component: Exception404Component }, { path: '500', component: Exception500Component }, { path: '**', redirectTo: 'dashboard' } ]; @NgModule({ imports: [RouterModule.forRoot(routes, { useHash: environment.useHash , onSameUrlNavigation: 'reload', scrollPositionRestoration: 'disabled' })], exports: [RouterModule] }) export class RouteRoutingModule { }`; return fullContent; } exports.routingModuleContent = routingModuleContent; function insertContent(source, start, newContent) { return source.slice(0, start) + newContent + source.slice(start); } exports.insertContent = insertContent; /** 字符串匹配,判断是否已存在对应子路由**/ function routeModules(tree, path) { const routes = []; const orginalRoutingModuleContent = tree.get(`${path}/app/routes/routes-routing.module.ts`).content.toString(); const appModuleIndex = orginalRoutingModuleContent.lastIndexOf(`${exports.MODULE_ROUTE_CONTENTS.APP}`.trim()); const authModuleIndex = orginalRoutingModuleContent.indexOf(`${exports.MODULE_ROUTE_CONTENTS.AUTH}`.trim()); const permissionModuleIndex = orginalRoutingModuleContent.indexOf(`${exports.MODULE_ROUTE_CONTENTS.PERMISSION}`.trim()); const systemModuleIndex = orginalRoutingModuleContent.lastIndexOf(`${exports.MODULE_ROUTE_CONTENTS.SYSTEM}`.trim()); const userModuleIndex = orginalRoutingModuleContent.indexOf(`${exports.MODULE_ROUTE_CONTENTS.USER}`.trim()); const logModuleIndex = orginalRoutingModuleContent.indexOf(`${exports.MODULE_ROUTE_CONTENTS.LOG}`.trim()); routes.push(appModuleIndex, authModuleIndex, permissionModuleIndex, systemModuleIndex, userModuleIndex, logModuleIndex); routes.sort(); console.log(routes); return routes; } exports.routeModules = routeModules; //# sourceMappingURL=content.js.map