From 599d362fdf09b5dd14df49e54cf7df62c315dc4c Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Thu, 29 Sep 2022 16:24:58 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E8=A1=A5=E5=85=85=E5=9C=A8=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E4=B8=AD=E4=B8=A2=E5=A4=B1=E7=9A=84=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/.gitignore | 1 - cli/src/commands/declaration.ts | 2 +- .../{{id}}/web/plugins/{{id}}/manifest.json | 9 + .../{{id}}/web/plugins/{{id}}/package.json | 14 + .../{{id}}/web/plugins/{{id}}/src/index.tsx | 1 + .../{{id}}/web/plugins/{{id}}/tsconfig.json | 7 + .../web/plugins/{{id}}/types/tailchat.d.ts | 2 + .../{{id}}/web/plugins/{{id}}/manifest.json | 9 + .../{{id}}/web/plugins/{{id}}/package.json | 14 + .../{{id}}/web/plugins/{{id}}/src/index.tsx | 1 + .../{{id}}/web/plugins/{{id}}/tsconfig.json | 7 + .../web/plugins/{{id}}/types/tailchat.d.ts | 2 + .../generate-plugin-declaration.typescript.ts | 2 + .../com.msgbyte.topic/types/tailchat.d.ts | 300 ++++++++++++++++++ 14 files changed, 369 insertions(+), 2 deletions(-) create mode 100644 cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/manifest.json create mode 100644 cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/package.json create mode 100644 cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/src/index.tsx create mode 100644 cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/tsconfig.json create mode 100644 cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/types/tailchat.d.ts create mode 100644 cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/manifest.json create mode 100644 cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/package.json create mode 100644 cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/src/index.tsx create mode 100644 cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/tsconfig.json create mode 100644 cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/types/tailchat.d.ts create mode 100644 server/plugins/com.msgbyte.topic/types/tailchat.d.ts diff --git a/cli/.gitignore b/cli/.gitignore index 9e824efe..2b10736c 100644 --- a/cli/.gitignore +++ b/cli/.gitignore @@ -1,5 +1,4 @@ lib -plugins # Logs logs diff --git a/cli/src/commands/declaration.ts b/cli/src/commands/declaration.ts index e2bdbda7..f10cb529 100644 --- a/cli/src/commands/declaration.ts +++ b/cli/src/commands/declaration.ts @@ -6,7 +6,7 @@ import ora from 'ora'; import got from 'got'; export const declarationCommand: CommandModule = { - command: 'declaration [source]', + command: 'declaration ', describe: 'Tailchat 插件类型声明', builder: (yargs) => yargs.positional('source', { diff --git a/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/manifest.json b/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/manifest.json new file mode 100644 index 00000000..7c498923 --- /dev/null +++ b/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/manifest.json @@ -0,0 +1,9 @@ +{ + "label": "{{name}}", + "name": "{{id}}", + "url": "{BACKEND}/plugins/{{id}}/index.js", + "version": "0.0.0", + "author": "{{author}}", + "description": "{{desc}}", + "requireRestart": true +} diff --git a/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/package.json b/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/package.json new file mode 100644 index 00000000..1e16cb65 --- /dev/null +++ b/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/package.json @@ -0,0 +1,14 @@ +{ + "name": "@plugins/{{id}}", + "main": "src/index.tsx", + "version": "0.0.0", + "description": "{{desc}}", + "private": true, + "scripts": { + "sync:declaration": "tailchat declaration github" + }, + "dependencies": {}, + "devDependencies": { + "react": "18.2.0" + } +} diff --git a/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/src/index.tsx b/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/src/index.tsx new file mode 100644 index 00000000..304ed5ea --- /dev/null +++ b/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/src/index.tsx @@ -0,0 +1 @@ +console.log('Plugin {{name}} is loaded'); diff --git a/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/tsconfig.json b/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/tsconfig.json new file mode 100644 index 00000000..d9b47ed0 --- /dev/null +++ b/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "esModuleInterop": true, + "jsx": "react", + "importsNotUsedAsValues": "error" + } +} diff --git a/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/types/tailchat.d.ts b/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/types/tailchat.d.ts new file mode 100644 index 00000000..49f524ae --- /dev/null +++ b/cli/templates/server-plugin-full/{{id}}/web/plugins/{{id}}/types/tailchat.d.ts @@ -0,0 +1,2 @@ +declare module '@capital/common'; +declare module '@capital/component'; diff --git a/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/manifest.json b/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/manifest.json new file mode 100644 index 00000000..7c498923 --- /dev/null +++ b/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/manifest.json @@ -0,0 +1,9 @@ +{ + "label": "{{name}}", + "name": "{{id}}", + "url": "{BACKEND}/plugins/{{id}}/index.js", + "version": "0.0.0", + "author": "{{author}}", + "description": "{{desc}}", + "requireRestart": true +} diff --git a/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/package.json b/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/package.json new file mode 100644 index 00000000..1e16cb65 --- /dev/null +++ b/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/package.json @@ -0,0 +1,14 @@ +{ + "name": "@plugins/{{id}}", + "main": "src/index.tsx", + "version": "0.0.0", + "description": "{{desc}}", + "private": true, + "scripts": { + "sync:declaration": "tailchat declaration github" + }, + "dependencies": {}, + "devDependencies": { + "react": "18.2.0" + } +} diff --git a/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/src/index.tsx b/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/src/index.tsx new file mode 100644 index 00000000..304ed5ea --- /dev/null +++ b/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/src/index.tsx @@ -0,0 +1 @@ +console.log('Plugin {{name}} is loaded'); diff --git a/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/tsconfig.json b/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/tsconfig.json new file mode 100644 index 00000000..d9b47ed0 --- /dev/null +++ b/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "esModuleInterop": true, + "jsx": "react", + "importsNotUsedAsValues": "error" + } +} diff --git a/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/types/tailchat.d.ts b/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/types/tailchat.d.ts new file mode 100644 index 00000000..49f524ae --- /dev/null +++ b/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/types/tailchat.d.ts @@ -0,0 +1,2 @@ +declare module '@capital/common'; +declare module '@capital/component'; diff --git a/client/web/scripts/generate-plugin-declaration.typescript.ts b/client/web/scripts/generate-plugin-declaration.typescript.ts index 90d6afb0..98cb8299 100644 --- a/client/web/scripts/generate-plugin-declaration.typescript.ts +++ b/client/web/scripts/generate-plugin-declaration.typescript.ts @@ -47,6 +47,8 @@ function generateDeclarationFile() { const output = `/* eslint-disable @typescript-eslint/no-explicit-any */ +/// + /** * 该文件由 Tailchat 自动生成 * 用于插件的类型声明 diff --git a/server/plugins/com.msgbyte.topic/types/tailchat.d.ts b/server/plugins/com.msgbyte.topic/types/tailchat.d.ts new file mode 100644 index 00000000..eb43d216 --- /dev/null +++ b/server/plugins/com.msgbyte.topic/types/tailchat.d.ts @@ -0,0 +1,300 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +/** + * 该文件由 Tailchat 自动生成 + * 用于插件的类型声明 + * 生成命令: pnpm run plugins:declaration:generate + */ + +/** + * Tailchat 通用 + */ + +declare module '@capital/common' { + export const useGroupPanelParams: any; + + /** + * 打开模态框 + */ + export const openModal: ( + content: React.ReactNode, + + props?: { + /** + * 是否显示右上角的关闭按钮 + * @default false + */ + closable?: boolean; + + /** + * 遮罩层是否可关闭 + */ + maskClosable?: boolean; + + /** + * 关闭modal的回调 + */ + onCloseModal?: () => void; + } + ) => number; + + export const closeModal: any; + + export const ModalWrapper: any; + + export const useModalContext: any; + + export const openConfirmModal: any; + + export const openReconfirmModal: any; + + export const Loadable: any; + + export const getGlobalState: any; + + export const getJWTUserInfo: () => Promise<{ + _id?: string; + nickname?: string; + email?: string; + avatar?: string; + }>; + + export const dataUrlToFile: any; + + export const urlSearchStringify: any; + + export const urlSearchParse: any; + + export const appendUrlSearch: any; + + export const useGroupIdContext: any; + + export const getServiceUrl: () => string; + + export const getCachedUserInfo: ( + userId: string, + refetch?: boolean + ) => Promise<{ + _id: string; + email: string; + nickname: string; + discriminator: string; + avatar: string | null; + temporary: boolean; + }>; + + export const getCachedConverseInfo: any; + + export const localTrans: any; + + export const getLanguage: any; + + export const sharedEvent: any; + + export const useAsync: any; + + export const useAsyncFn: any; + + export const useAsyncRefresh: any; + + export const useAsyncRequest: any; + + export const uploadFile: any; + + export const showToasts: any; + + export const showErrorToasts: any; + + export const fetchAvailableServices: any; + + export const isValidStr: any; + + export const useGroupPanelInfo: any; + + export const sendMessage: any; + + export const useLocation: any; + + export const useHistory: any; + + export const createFastFormSchema: any; + + export const fieldSchema: any; + + export const useCurrentUserInfo: any; + + export const createPluginRequest: (pluginName: string) => { + get: (actionName: string, config?: any) => Promise; + post: (actionName: string, data?: any, config?: any) => Promise; + }; + + export const postRequest: any; + + export const pluginCustomPanel: any; + + export const regCustomPanel: any; + + export const pluginGroupPanel: any; + + export const regGroupPanel: any; + + export const messageInterpreter: any; + + export const regMessageInterpreter: any; + + export const getMessageRender: any; + + export const regMessageRender: any; + + export const getMessageTextDecorators: any; + + export const regMessageTextDecorators: any; + + export const ChatInputActionContextProps: any; + + export const pluginChatInputActions: any; + + export const regChatInputAction: any; + + export const regSocketEventListener: (item: { + eventName: string; + eventFn: (...args: any[]) => void; + }) => void; + + export const pluginColorScheme: any; + + export const regPluginColorScheme: any; + + export const pluginInspectServices: any; + + export const regInspectService: any; + + export const pluginMessageExtraParsers: any; + + export const regMessageExtraParser: any; + + export const pluginRootRoute: any; + + export const regPluginRootRoute: any; + + export const pluginPanelActions: any; + + export const regPluginPanelAction: any; + + export const pluginPermission: any; + + export const regPluginPermission: (permission: { + /** + * 权限唯一key, 用于写入数据库 + * 如果为插件则权限点应当符合命名规范, 如: plugin.com.msgbyte.github.manage + */ + key: string; + /** + * 权限点显示名称 + */ + title: string; + /** + * 权限描述 + */ + desc: string; + /** + * 是否默认开启 + */ + default: boolean; + /** + * 是否依赖其他权限点 + */ + required?: string[]; + }) => void; +} + +/** + * Tailchat 组件 + */ +declare module '@capital/component' { + export const Button: any; + + export const Checkbox: any; + + export const Input: any; + + export const Divider: any; + + export const Space: any; + + export const Menu: any; + + export const Table: any; + + export const Switch: any; + + export const Tooltip: any; + + /** + * @link https://ant.design/components/notification-cn/ + */ + export const notification: any; + + export const Avatar: any; + + export const SensitiveText: React.FC<{ className?: string; text: string }>; + + export const TextArea: any; + + export const Image: any; + + export const Icon: any; + + export const IconBtn: any; + + export const PillTabs: any; + + export const PillTabPane: any; + + export const LoadingSpinner: any; + + export const WebFastForm: any; + + export const WebMetaForm: any; + + export const createMetaFormSchema: any; + + export const metaFormFieldSchema: any; + + export const FullModalField: any; + + export const DefaultFullModalInputEditorRender: any; + + export const DefaultFullModalTextAreaEditorRender: any; + + export const openModal: any; + + export const closeModal: any; + + export const ModalWrapper: any; + + export const useModalContext: any; + + export const openConfirmModal: any; + + export const openReconfirmModal: any; + + export const Loading: any; + + export const SidebarView: any; + + export const GroupPanelSelector: any; + + export const Emoji: any; + + export const PortalAdd: any; + + export const PortalRemove: any; + + export const ErrorBoundary: any; + + export const UserName: React.FC<{ + userId: string; + className?: string; + }>; +}