From 71d8779b631acce36a872f53a1d2e935974b025a Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Tue, 8 Oct 2019 09:23:52 +0300 Subject: [PATCH] refactor(core): add addAbpRoutes method --- .../lib/services/account-config.service.ts | 4 +-- npm/ng-packs/packages/account/ng-package.json | 2 +- npm/ng-packs/packages/account/package.json | 3 ++- .../src/lib/plugins/config/config.plugin.ts | 14 +++++++++- .../core/src/lib/tests/config.plugin.spec.ts | 6 ++--- .../lib/services/identity-config.service.ts | 6 ++--- .../setting-management-config.service.ts | 4 +-- .../tenant-management-config.service.ts | 4 +-- templates/module/angular/symlink.config.json | 26 +++++++++++++++++++ 9 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 templates/module/angular/symlink.config.json diff --git a/npm/ng-packs/packages/account-config/src/lib/services/account-config.service.ts b/npm/ng-packs/packages/account-config/src/lib/services/account-config.service.ts index 7af86a49c9..dac3704a06 100644 --- a/npm/ng-packs/packages/account-config/src/lib/services/account-config.service.ts +++ b/npm/ng-packs/packages/account-config/src/lib/services/account-config.service.ts @@ -1,4 +1,4 @@ -import { ABP_ROUTES, eLayoutType, RestService } from '@abp/ng.core'; +import { eLayoutType, RestService, addAbpRoutes } from '@abp/ng.core'; import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; @@ -7,7 +7,7 @@ import { Router } from '@angular/router'; }) export class AccountConfigService { constructor(private router: Router, private restService: RestService) { - ABP_ROUTES.push({ + addAbpRoutes({ name: 'AbpAccount::Menu:Account', path: 'account', invisible: true, diff --git a/npm/ng-packs/packages/account/ng-package.json b/npm/ng-packs/packages/account/ng-package.json index 9e94619264..ad23aa3fd2 100644 --- a/npm/ng-packs/packages/account/ng-package.json +++ b/npm/ng-packs/packages/account/ng-package.json @@ -4,5 +4,5 @@ "lib": { "entryFile": "src/public-api.ts" }, - "whitelistedNonPeerDependencies": ["@abp/ng.theme.shared"] + "whitelistedNonPeerDependencies": ["@abp/ng.theme.shared", "abp/ng.account.config"] } diff --git a/npm/ng-packs/packages/account/package.json b/npm/ng-packs/packages/account/package.json index 495b427bf3..a0e5dae2da 100644 --- a/npm/ng-packs/packages/account/package.json +++ b/npm/ng-packs/packages/account/package.json @@ -2,7 +2,8 @@ "name": "@abp/ng.account", "version": "0.9.0", "dependencies": { - "@abp/ng.theme.shared": "^0.9.0" + "@abp/ng.theme.shared": "^0.9.0", + "abp/ng.account.config": "^0.0.1" }, "publishConfig": { "access": "public" diff --git a/npm/ng-packs/packages/core/src/lib/plugins/config/config.plugin.ts b/npm/ng-packs/packages/core/src/lib/plugins/config/config.plugin.ts index 2c15787f84..daab72d249 100644 --- a/npm/ng-packs/packages/core/src/lib/plugins/config/config.plugin.ts +++ b/npm/ng-packs/packages/core/src/lib/plugins/config/config.plugin.ts @@ -8,7 +8,19 @@ import clone from 'just-clone'; export const NGXS_CONFIG_PLUGIN_OPTIONS = new InjectionToken('NGXS_CONFIG_PLUGIN_OPTIONS'); -export let ABP_ROUTES = [] as ABP.FullRoute[]; +let ABP_ROUTES = [] as ABP.FullRoute[]; + +export function addAbpRoutes(routes: ABP.FullRoute | ABP.FullRoute[]): void { + if (!Array.isArray(routes)) { + routes = [routes]; + } + + ABP_ROUTES.push(...routes); +} + +export function getAbpRoutes(): ABP.FullRoute[] { + return []; +} @Injectable() export class ConfigPlugin implements NgxsPlugin { diff --git a/npm/ng-packs/packages/core/src/lib/tests/config.plugin.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/config.plugin.spec.ts index 1cd4266924..b9560ddf87 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/config.plugin.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/config.plugin.spec.ts @@ -4,13 +4,13 @@ import { NGXS_PLUGINS, NgxsModule, InitState, Store } from '@ngxs/store'; import { environment } from '../../../../../apps/dev-app/src/environments/environment'; import { LAYOUTS } from '../../../../theme-basic/src/public-api'; import { ABP } from '../models'; -import { ConfigPlugin, NGXS_CONFIG_PLUGIN_OPTIONS, ABP_ROUTES } from '../plugins'; +import { ConfigPlugin, NGXS_CONFIG_PLUGIN_OPTIONS, addAbpRoutes } from '../plugins'; import { RouterOutletComponent } from '../components'; import { ConfigState } from '../states'; import { CoreModule } from '../core.module'; import { eLayoutType } from '../enums/common'; -ABP_ROUTES.push( +addAbpRoutes([ { name: 'AbpUiNavigation::Menu:Administration', path: '', @@ -54,7 +54,7 @@ ABP_ROUTES.push( }, ], }, -); +]); const expectedState = { environment, diff --git a/npm/ng-packs/packages/identity-config/src/lib/services/identity-config.service.ts b/npm/ng-packs/packages/identity-config/src/lib/services/identity-config.service.ts index fe78f8e810..960634809d 100644 --- a/npm/ng-packs/packages/identity-config/src/lib/services/identity-config.service.ts +++ b/npm/ng-packs/packages/identity-config/src/lib/services/identity-config.service.ts @@ -1,4 +1,4 @@ -import { ABP_ROUTES, eLayoutType, RestService } from '@abp/ng.core'; +import { addAbpRoutes, eLayoutType, RestService } from '@abp/ng.core'; import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { Observable } from 'rxjs'; @@ -8,7 +8,7 @@ import { Observable } from 'rxjs'; }) export class IdentityConfigService { constructor(private router: Router, private restService: RestService) { - ABP_ROUTES.push( + addAbpRoutes([ { name: 'AbpUiNavigation::Menu:Administration', path: '', @@ -27,6 +27,6 @@ export class IdentityConfigService { { path: 'users', name: 'AbpIdentity::Users', order: 1, requiredPolicy: 'AbpIdentity.Users' }, ], }, - ); + ]); } } diff --git a/npm/ng-packs/packages/setting-management-config/src/lib/services/setting-management-config.service.ts b/npm/ng-packs/packages/setting-management-config/src/lib/services/setting-management-config.service.ts index 851f435449..6d4fbec90b 100644 --- a/npm/ng-packs/packages/setting-management-config/src/lib/services/setting-management-config.service.ts +++ b/npm/ng-packs/packages/setting-management-config/src/lib/services/setting-management-config.service.ts @@ -1,12 +1,12 @@ import { Injectable } from '@angular/core'; -import { ABP_ROUTES, eLayoutType } from '@abp/ng.core'; +import { addAbpRoutes, eLayoutType } from '@abp/ng.core'; @Injectable({ providedIn: 'root', }) export class SettingManagementConfigService { constructor() { - ABP_ROUTES.push({ + addAbpRoutes({ name: 'Settings', path: 'setting-management', parentName: 'AbpUiNavigation::Menu:Administration', diff --git a/npm/ng-packs/packages/tenant-management-config/src/lib/services/tenant-management-config.service.ts b/npm/ng-packs/packages/tenant-management-config/src/lib/services/tenant-management-config.service.ts index 8d77d1005f..48a6d31c84 100644 --- a/npm/ng-packs/packages/tenant-management-config/src/lib/services/tenant-management-config.service.ts +++ b/npm/ng-packs/packages/tenant-management-config/src/lib/services/tenant-management-config.service.ts @@ -1,12 +1,12 @@ import { Injectable } from '@angular/core'; -import { ABP_ROUTES, eLayoutType } from '@abp/ng.core'; +import { addAbpRoutes, eLayoutType } from '@abp/ng.core'; @Injectable({ providedIn: 'root', }) export class TenantManagementConfigService { constructor() { - ABP_ROUTES.push({ + addAbpRoutes({ name: 'AbpTenantManagement::Menu:TenantManagement', path: 'tenant-management', parentName: 'AbpUiNavigation::Menu:Administration', diff --git a/templates/module/angular/symlink.config.json b/templates/module/angular/symlink.config.json new file mode 100644 index 0000000000..f67140e55a --- /dev/null +++ b/templates/module/angular/symlink.config.json @@ -0,0 +1,26 @@ +{ + "yarn": true, + "packages": [ + { + "libraryFolderPath": "../../../npm/ng-packs/packages/core", + "linkFolderPath": "../../../npm/ng-packs/dist/core", + "buildCommand": "ng build core", + "buildCommandRunPath": "../../../npm/ng-packs/", + "exclude": ["node_modules", "dist"] + }, + { + "libraryFolderPath": "../../../npm/ng-packs/packages/account", + "linkFolderPath": "../../../npm/ng-packs/dist/account", + "buildCommand": "ng build account", + "buildCommandRunPath": "../../../npm/ng-packs/", + "exclude": ["node_modules", "dist"] + }, + { + "libraryFolderPath": "../../../npm/ng-packs/packages/account-config", + "linkFolderPath": "../../../npm/ng-packs/dist/account-config", + "buildCommand": "ng build account-config", + "buildCommandRunPath": "../../../npm/ng-packs/", + "exclude": ["node_modules", "dist"] + } + ] +}