Skip to content

Commit

Permalink
Merge pull request #5164 from ruibaby/refactor/load-core-modules
Browse files Browse the repository at this point in the history
refactor: simplify the logic of importing module
  • Loading branch information
JohnNiang authored Jan 11, 2024
2 parents ec5e167 + 57e3394 commit 70cc4ec
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 87 deletions.
54 changes: 8 additions & 46 deletions console/console-src/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,10 @@
// fixme: add supports for auto import
import dashboardModule from "./dashboard/module";
import postModule from "./contents/posts/module";
import pageModule from "./contents/pages/module";
import commentModule from "./contents/comments/module";
import attachmentModule from "./contents/attachments/module";
import themeModule from "./interface/themes/module";
import menuModule from "./interface/menus/module";
import pluginModule from "./system/plugins/module";
import userModule from "./system/users/module";
import roleModule from "./system/roles/module";
import settingModule from "./system/settings/module";
import actuatorModule from "./system/actuator/module";
import authProviderModule from "./system/auth-providers/module";
import backupModule from "./system/backup/module";
import type { PluginModule } from "@halo-dev/console-shared";

// const coreModules = [
// dashboardModule,
// postModule,
// pageModule,
// commentModule,
// attachmentModule,
// themeModule,
// menuModule,
// pluginModule,
// userModule,
// roleModule,
// settingModule,
// ];
const modules = Object.values(
import.meta.glob("./**/module.ts", {
eager: true,
import: "default",
})
) as PluginModule[];

const coreModules = [
postModule,
pluginModule,
settingModule,
actuatorModule,
dashboardModule,
menuModule,
commentModule,
attachmentModule,
pageModule,
themeModule,
userModule,
roleModule,
authProviderModule,
backupModule,
];

export { coreModules };
export default modules;
6 changes: 3 additions & 3 deletions console/console-src/modules/system/auth-providers/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import AuthProviderDetail from "./AuthProviderDetail.vue";
export default definePlugin({
routes: [
{
path: "/users",
path: "/users/auth-providers",
component: BasicLayout,
children: [
{
path: "auth-providers",
path: "",
name: "AuthProviders",
component: AuthProviders,
meta: {
Expand All @@ -19,7 +19,7 @@ export default definePlugin({
},
},
{
path: "auth-providers/:name",
path: ":name",
name: "AuthProviderDetail",
component: AuthProviderDetail,
meta: {
Expand Down
6 changes: 3 additions & 3 deletions console/console-src/modules/system/roles/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export default definePlugin({
components: {},
routes: [
{
path: "/users",
path: "/users/roles",
component: BasicLayout,
children: [
{
path: "roles",
path: "",
name: "Roles",
component: RoleList,
meta: {
Expand All @@ -21,7 +21,7 @@ export default definePlugin({
},
},
{
path: "roles/:name",
path: ":name",
name: "RoleDetail",
component: RoleDetail,
meta: {
Expand Down
52 changes: 19 additions & 33 deletions console/console-src/modules/system/users/module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { definePlugin } from "@halo-dev/console-shared";
import BasicLayout from "@console/layouts/BasicLayout.vue";
import BlankLayout from "@console/layouts/BlankLayout.vue";
import UserStatsWidget from "./widgets/UserStatsWidget.vue";
import UserList from "./UserList.vue";
import UserDetail from "./UserDetail.vue";
Expand Down Expand Up @@ -34,45 +33,32 @@ export default definePlugin({
},
{
path: "/users",
component: BlankLayout,
component: BasicLayout,
children: [
{
path: "",
component: BasicLayout,
children: [
{
path: "",
name: "Users",
component: UserList,
meta: {
title: "core.user.title",
searchable: true,
permissions: ["system:users:view"],
menu: {
name: "core.sidebar.menu.items.users",
group: "system",
icon: markRaw(IconUserSettings),
priority: 1,
mobile: true,
},
},
name: "Users",
component: UserList,
meta: {
title: "core.user.title",
searchable: true,
permissions: ["system:users:view"],
menu: {
name: "core.sidebar.menu.items.users",
group: "system",
icon: markRaw(IconUserSettings),
priority: 1,
mobile: true,
},
],
},
},
{
path: ":name",
component: BasicLayout,
name: "User",
children: [
{
path: "",
name: "UserDetail",
component: UserDetail,
meta: {
title: "core.user.detail.title",
},
},
],
name: "UserDetail",
component: UserDetail,
meta: {
title: "core.user.detail.title",
},
},
],
},
Expand Down
4 changes: 2 additions & 2 deletions console/console-src/setup/setupModules.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { i18n } from "@/locales";
import { coreModules } from "@console/modules";
import modules from "@console/modules";
import router from "@console/router";
import { usePluginModuleStore } from "@/stores/plugin";
import type { PluginModule, RouteRecordAppend } from "@halo-dev/console-shared";
Expand All @@ -10,7 +10,7 @@ import type { RouteRecordRaw } from "vue-router";
import { loadStyle } from "@/utils/load-style";

export function setupCoreModules(app: App) {
coreModules.forEach((module) => {
modules.forEach((module) => {
registerModule(app, module, true);
});
}
Expand Down

0 comments on commit 70cc4ec

Please sign in to comment.