From 515ec78842d5089412eb4ad0f8d51f2875641f1f Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Fri, 17 Jun 2022 15:00:14 +0800 Subject: [PATCH] feat: use definePlugin function to define a plugin object Signed-off-by: Ryan Wang --- packages/shared/src/core/plugins.ts | 5 +++++ packages/shared/src/index.ts | 1 + src/main.ts | 4 ++-- src/modules/contents/attachments/module.ts | 8 +++----- src/modules/contents/comments/module.ts | 8 +++----- src/modules/contents/posts/module.ts | 8 +++----- src/modules/contents/sheets/module.ts | 8 +++----- src/modules/dashboard/module.ts | 8 +++----- src/modules/interface/menus/module.ts | 8 +++----- src/modules/interface/themes/module.ts | 8 +++----- src/modules/system/plugins/module.ts | 8 +++----- src/modules/system/roles/module.ts | 8 +++----- src/modules/system/settings/module.ts | 8 +++----- src/modules/system/users/module.ts | 8 +++----- 14 files changed, 41 insertions(+), 57 deletions(-) create mode 100644 packages/shared/src/core/plugins.ts diff --git a/packages/shared/src/core/plugins.ts b/packages/shared/src/core/plugins.ts new file mode 100644 index 00000000..8e3003d5 --- /dev/null +++ b/packages/shared/src/core/plugins.ts @@ -0,0 +1,5 @@ +import type { Plugin } from "@/types/plugin"; + +export function definePlugin(plugin: Plugin): Plugin { + return plugin; +} diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 94c9cf4f..c46da2c2 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -1,2 +1,3 @@ export * from "./types/plugin"; export * from "./types/menus"; +export * from "./core/plugins"; diff --git a/src/main.ts b/src/main.ts index 530f9a71..2313f516 100644 --- a/src/main.ts +++ b/src/main.ts @@ -50,7 +50,7 @@ async function registerModule(pluginModule: Plugin) { } function loadCoreModules() { - [ + Array.from([ dashboardModule, postModule, sheetModule, @@ -62,7 +62,7 @@ function loadCoreModules() { userModule, roleModule, settingModule, - ].forEach(registerModule); + ]).forEach(registerModule); } function loadPluginModules() { diff --git a/src/modules/contents/attachments/module.ts b/src/modules/contents/attachments/module.ts index 2e9c1bee..0f13f706 100644 --- a/src/modules/contents/attachments/module.ts +++ b/src/modules/contents/attachments/module.ts @@ -1,9 +1,9 @@ -import type { Plugin } from "@halo-dev/admin-shared"; +import { definePlugin } from "@halo-dev/admin-shared"; import { BasicLayout } from "@/layouts"; import AttachmentList from "./AttachmentList.vue"; import { IconFolder } from "@halo-dev/components"; -const attachmentModule: Plugin = { +export default definePlugin({ name: "attachmentModule", components: [], routes: [ @@ -31,6 +31,4 @@ const attachmentModule: Plugin = { ], }, ], -}; - -export default attachmentModule; +}); diff --git a/src/modules/contents/comments/module.ts b/src/modules/contents/comments/module.ts index c70d8a29..cfd85cec 100644 --- a/src/modules/contents/comments/module.ts +++ b/src/modules/contents/comments/module.ts @@ -1,9 +1,9 @@ -import type { Plugin } from "@halo-dev/admin-shared"; +import { definePlugin } from "@halo-dev/admin-shared"; import { BasicLayout } from "@/layouts"; import { IconMessage } from "@halo-dev/components"; import CommentList from "./CommentList.vue"; -const commentModule: Plugin = { +export default definePlugin({ name: "commentModule", components: [], routes: [ @@ -31,6 +31,4 @@ const commentModule: Plugin = { ], }, ], -}; - -export default commentModule; +}); diff --git a/src/modules/contents/posts/module.ts b/src/modules/contents/posts/module.ts index 7ddf8f48..972af8fb 100644 --- a/src/modules/contents/posts/module.ts +++ b/src/modules/contents/posts/module.ts @@ -1,4 +1,4 @@ -import type { Plugin } from "@halo-dev/admin-shared"; +import { definePlugin } from "@halo-dev/admin-shared"; import { BasicLayout, BlankLayout } from "@/layouts"; import { IconBookRead } from "@halo-dev/components"; import PostList from "./PostList.vue"; @@ -6,7 +6,7 @@ import PostEditor from "./PostEditor.vue"; import CategoryList from "./categories/CategoryList.vue"; import TagList from "./tags/TagList.vue"; -const postModule: Plugin = { +export default definePlugin({ name: "postModule", components: [], routes: [ @@ -61,6 +61,4 @@ const postModule: Plugin = { ], }, ], -}; - -export default postModule; +}); diff --git a/src/modules/contents/sheets/module.ts b/src/modules/contents/sheets/module.ts index 36eb1e42..c8498eb4 100644 --- a/src/modules/contents/sheets/module.ts +++ b/src/modules/contents/sheets/module.ts @@ -1,9 +1,9 @@ -import type { Plugin } from "@halo-dev/admin-shared"; +import { definePlugin } from "@halo-dev/admin-shared"; import { BasicLayout } from "@/layouts"; import SheetList from "./SheetList.vue"; import { IconPages } from "@halo-dev/components"; -const sheetModule: Plugin = { +export default definePlugin({ name: "sheetModule", components: [], routes: [ @@ -31,6 +31,4 @@ const sheetModule: Plugin = { ], }, ], -}; - -export default sheetModule; +}); diff --git a/src/modules/dashboard/module.ts b/src/modules/dashboard/module.ts index f48ac183..844abfd5 100644 --- a/src/modules/dashboard/module.ts +++ b/src/modules/dashboard/module.ts @@ -1,4 +1,4 @@ -import type { Plugin } from "@halo-dev/admin-shared"; +import { definePlugin } from "@halo-dev/admin-shared"; import { BasicLayout } from "@/layouts"; import Dashboard from "./Dashboard.vue"; import { IconDashboard } from "@halo-dev/components"; @@ -12,7 +12,7 @@ import RecentPublishedWidget from "./widgets/RecentPublishedWidget.vue"; import UserStatsWidget from "./widgets/UserStatsWidget.vue"; import ViewsStatsWidget from "./widgets/ViewsStatsWidget.vue"; -const dashboardModule: Plugin = { +export default definePlugin({ name: "dashboardModule", components: [ CommentStatsWidget, @@ -50,6 +50,4 @@ const dashboardModule: Plugin = { ], }, ], -}; - -export default dashboardModule; +}); diff --git a/src/modules/interface/menus/module.ts b/src/modules/interface/menus/module.ts index a463d5c8..516ebe4c 100644 --- a/src/modules/interface/menus/module.ts +++ b/src/modules/interface/menus/module.ts @@ -1,9 +1,9 @@ -import type { Plugin } from "@halo-dev/admin-shared"; +import { definePlugin } from "@halo-dev/admin-shared"; import { BasicLayout } from "@/layouts"; import MenuList from "./MenuList.vue"; import { IconListSettings } from "@halo-dev/components"; -const menuModule: Plugin = { +export default definePlugin({ name: "menuModule", components: [], routes: [ @@ -31,6 +31,4 @@ const menuModule: Plugin = { ], }, ], -}; - -export default menuModule; +}); diff --git a/src/modules/interface/themes/module.ts b/src/modules/interface/themes/module.ts index 09493b1d..b56bfd98 100644 --- a/src/modules/interface/themes/module.ts +++ b/src/modules/interface/themes/module.ts @@ -1,10 +1,10 @@ -import type { Plugin } from "@halo-dev/admin-shared"; +import { definePlugin } from "@halo-dev/admin-shared"; import { BasicLayout, BlankLayout } from "@/layouts"; import ThemeDetail from "./ThemeDetail.vue"; import Visual from "./Visual.vue"; import { IconPalette } from "@halo-dev/components"; -const themeModule: Plugin = { +export default definePlugin({ name: "themeModule", components: [], routes: [ @@ -43,6 +43,4 @@ const themeModule: Plugin = { ], }, ], -}; - -export default themeModule; +}); diff --git a/src/modules/system/plugins/module.ts b/src/modules/system/plugins/module.ts index 0844fcf6..9bfbbca7 100644 --- a/src/modules/system/plugins/module.ts +++ b/src/modules/system/plugins/module.ts @@ -1,10 +1,10 @@ -import type { Plugin } from "@halo-dev/admin-shared"; +import { definePlugin } from "@halo-dev/admin-shared"; import { BasicLayout } from "@/layouts"; import PluginList from "./PluginList.vue"; import PluginDetail from "./PluginDetail.vue"; import { IconPlug } from "@halo-dev/components"; -const pluginModule: Plugin = { +export default definePlugin({ name: "pluginModule", components: [], routes: [ @@ -37,6 +37,4 @@ const pluginModule: Plugin = { ], }, ], -}; - -export default pluginModule; +}); diff --git a/src/modules/system/roles/module.ts b/src/modules/system/roles/module.ts index cb5ba440..7b40ee76 100644 --- a/src/modules/system/roles/module.ts +++ b/src/modules/system/roles/module.ts @@ -1,9 +1,9 @@ -import type { Plugin } from "@halo-dev/admin-shared"; +import { definePlugin } from "@halo-dev/admin-shared"; import { BasicLayout } from "@/layouts"; import RoleList from "./RoleList.vue"; import RoleDetail from "./RoleDetail.vue"; -const roleModule: Plugin = { +export default definePlugin({ name: "roleModule", components: [], routes: [ @@ -25,6 +25,4 @@ const roleModule: Plugin = { }, ], menus: [], -}; - -export default roleModule; +}); diff --git a/src/modules/system/settings/module.ts b/src/modules/system/settings/module.ts index abce1b1b..9a0f6187 100644 --- a/src/modules/system/settings/module.ts +++ b/src/modules/system/settings/module.ts @@ -1,10 +1,10 @@ -import type { Plugin } from "@halo-dev/admin-shared"; +import { definePlugin } from "@halo-dev/admin-shared"; import { SystemSettingsLayout } from "@/layouts"; import GeneralSettings from "./GeneralSettings.vue"; import NotificationSettings from "./NotificationSettings.vue"; import { IconSettings } from "@halo-dev/components"; -const settingModule: Plugin = { +export default definePlugin({ name: "settingModule", components: [], routes: [ @@ -38,6 +38,4 @@ const settingModule: Plugin = { ], }, ], -}; - -export default settingModule; +}); diff --git a/src/modules/system/users/module.ts b/src/modules/system/users/module.ts index 76fe94eb..7ddfbab9 100644 --- a/src/modules/system/users/module.ts +++ b/src/modules/system/users/module.ts @@ -1,4 +1,4 @@ -import type { Plugin } from "@halo-dev/admin-shared"; +import { definePlugin } from "@halo-dev/admin-shared"; import { BasicLayout, BlankLayout, UserProfileLayout } from "@/layouts"; import UserList from "./UserList.vue"; import UserDetail from "./UserDetail.vue"; @@ -7,7 +7,7 @@ import PasswordChange from "./PasswordChange.vue"; import PersonalAccessTokens from "./PersonalAccessTokens.vue"; import { IconUserSettings } from "@halo-dev/components"; -const userModule: Plugin = { +export default definePlugin({ name: "userModule", components: [], routes: [ @@ -68,6 +68,4 @@ const userModule: Plugin = { ], }, ], -}; - -export default userModule; +});