Skip to content

Commit d661f14

Browse files
Merge pull request #148 from SeasonsChange422/main
vuepress文档
2 parents ba840e7 + c06c8a3 commit d661f14

26 files changed

+6044
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build and Deploy
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- 'docs/**'
8+
9+
jobs:
10+
build-and-deploy:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 20
21+
22+
- name: Install and Build
23+
run: |
24+
cd docs
25+
npm install
26+
npm run docs:build
27+
28+
- name: Deploy to GitHub Pages
29+
uses: peaceiris/actions-gh-pages@v3
30+
with:
31+
github_token: ${{ secrets.GITHUB_TOKEN }}
32+
publish_dir: ./docs/.vuepress/dist
33+
publish_branch: gh-pages

docs/.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
src/*.d.ts
13+
dist-ssr
14+
*.local
15+
16+
# VuePress/Vite generated
17+
.vuepress/.cache
18+
.vuepress/.temp
19+
.vuepress/dist
20+
.vite
21+
.eslintcache
22+
23+
# OS files
24+
Thumbs.db
25+
26+
# Env files
27+
.env
28+
.env.*
29+
30+
# Editor directories and files
31+
.vscode/*
32+
!.vscode/extensions.json
33+
.idea
34+
.DS_Store
35+
*.suo
36+
*.ntvs*
37+
*.njsproj
38+
*.sln
39+
*.sw?

docs/.vuepress/config.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { defineUserConfig } from 'vuepress'
2+
import { defaultTheme } from '@vuepress/theme-default'
3+
import { viteBundler } from '@vuepress/bundler-vite'
4+
import { path } from '@vuepress/utils'
5+
6+
export default defineUserConfig({
7+
lang: 'zh-CN',
8+
title: 'Mosaic Framework',
9+
description: '基于插件化架构的Java模块化框架',
10+
base: '/Mosaic/',
11+
public: path.resolve(__dirname, '../public'),
12+
bundler: viteBundler({
13+
viteOptions: {},
14+
vuePluginOptions: {},
15+
}),
16+
17+
theme: defaultTheme({
18+
logo: '/logo.png',
19+
navbar: [
20+
{
21+
text: '指南',
22+
link: '/guide/',
23+
},
24+
{
25+
text: 'API参考',
26+
link: '/api/',
27+
},
28+
{
29+
text: '插件开发',
30+
link: '/plugin/',
31+
},
32+
{
33+
text: '示例',
34+
link: '/examples/',
35+
},
36+
{
37+
text: 'GitHub',
38+
link: 'https://github.com/Time-Machine-Lab/Mosaic'
39+
}
40+
],
41+
sidebar: {
42+
'/guide/': [
43+
{
44+
text: '指南',
45+
children: [
46+
'/guide/README.md',
47+
'/guide/getting-started.md',
48+
'/guide/core-concepts.md',
49+
'/guide/configuration.md',
50+
'/guide/event-system.md'
51+
]
52+
}
53+
],
54+
'/api/': [
55+
{
56+
text: 'API参考',
57+
children: [
58+
'/api/README.md',
59+
'/api/cube-api.md',
60+
'/api/extension-api.md',
61+
'/api/event-api.md',
62+
'/api/config-api.md'
63+
]
64+
}
65+
],
66+
'/plugin/': [
67+
{
68+
text: '插件开发',
69+
children: [
70+
'/plugin/README.md',
71+
'/plugin/cube-development.md',
72+
'/plugin/extension-development.md',
73+
'/plugin/listener-development.md',
74+
'/plugin/best-practices.md'
75+
]
76+
}
77+
],
78+
'/examples/': [
79+
{
80+
text: '示例',
81+
children: [
82+
'/examples/README.md',
83+
'/examples/ai-chat-plugin.md',
84+
'/examples/system-log-plugin.md',
85+
'/examples/listener-plugin.md'
86+
]
87+
}
88+
]
89+
}
90+
})
91+
})

docs/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
home: true
3+
heroImage: /logo.png
4+
heroText: Mosaic Framework
5+
tagline: 基于插件化架构的Java模块化框架
6+
actionText: 快速开始 →
7+
actionLink: /guide/getting-started
8+
features:
9+
- title: 🧩 插件化架构
10+
details: 基于Cube概念的模块化设计,支持插件的动态加载和管理
11+
- title: 🔌 扩展点机制
12+
details: 通过注解驱动的扩展点系统,实现插件间的松耦合交互
13+
- title: 📡 事件驱动
14+
details: 完整的事件系统支持插件间的异步通信
15+
- title: ⚙️ 配置管理
16+
details: 灵活的配置系统,支持类型验证和默认值
17+
- title: 🔄 生命周期管理
18+
details: 完整的插件生命周期管理(初始化、启动、停止、销毁)
19+
- title: 🏗️ 多实例支持
20+
details: 支持单例和多例插件模式
21+
footer: MIT Licensed | Copyright © 2024 Mosaic Framework
22+
---
23+
24+
## 什么是 Mosaic Framework?
25+
26+
Mosaic Framework 是一个基于插件化架构的Java模块化框架,旨在帮助开发者构建可扩展、可维护的模块化应用系统。
27+
28+
### 核心特性
29+
30+
- **插件化架构**: 基于Cube概念的模块化设计
31+
- **扩展点机制**: 注解驱动的扩展点系统
32+
- **事件驱动**: 完整的事件系统
33+
- **配置管理**: 灵活的配置系统
34+
- **生命周期管理**: 完整的插件生命周期
35+
36+
### 快速体验
37+
38+
```xml
39+
<dependency>
40+
<groupId>io.github.timemachinelab</groupId>
41+
<artifactId>mosaic-core</artifactId>
42+
<version>1.0-SNAPSHOT</version>
43+
</dependency>
44+
```
45+
46+
```java
47+
@MCube(name = "示例插件", description = "这是一个示例插件")
48+
public class ExampleCube extends MosaicCube {
49+
@Override
50+
public boolean init() {
51+
System.out.println("插件初始化成功!");
52+
return true;
53+
}
54+
55+
@Override
56+
public String cubeId() {
57+
return "example.cube";
58+
}
59+
}
60+
```

docs/api/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# API 概览
2+
3+
本节列出宿主与插件常用 API:
4+
- Cube API:生命周期、配置访问、标识
5+
- 扩展 API:扩展点注解、扩展包抽象与注入
6+
- 事件 API:事件与监听器编写
7+
- 配置 API:CubeConfig 读取

docs/api/config-api.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 配置 API
2+
3+
## CubeConfig
4+
```java
5+
public class CubeConfig {
6+
<T> T getConfig(String name, Class<T> type);
7+
<T> T getConfig(String name, Class<T> type, T defaultValue);
8+
Map<String, Object> getAllConfigs();
9+
}
10+
```
11+
12+
## 读取示例
13+
```java
14+
CubeConfig cfg = getCubeConfig();
15+
String model = cfg.getConfig("model", String.class, "gpt-3.5-turbo");
16+
Integer timeout = cfg.getConfig("timeout", Integer.class, 30);
17+
Boolean enableLogging = cfg.getConfig("enableLogging", Boolean.class, true);
18+
```
19+
20+
说明:
21+
- CubeConfig 由框架在实例化时注入(线程上下文绑定 cubeId -> 配置)。
22+
- 不建议在插件中长期持有可变引用,按需读取或复制。

docs/api/cube-api.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Cube API
2+
3+
## 接口
4+
```java
5+
public interface CubeApi {
6+
boolean init();
7+
boolean destroy();
8+
String cubeId();
9+
default CubeConfig getCubeConfig() { ... }
10+
}
11+
```
12+
13+
## 基类
14+
- MosaicCube:插件实现通常继承此类,覆盖 init/destroy/cubeId。
15+
- AngelCube:守护型方块,需实现 start()/stop(),由 AngelCubeActuator 管理其生命周期。
16+
17+
## 注解
18+
```java
19+
@Target(ElementType.TYPE)
20+
@Retention(RetentionPolicy.RUNTIME)
21+
public @interface MCube {
22+
String name() default "";
23+
String version() default "1.0.0";
24+
String description() default "";
25+
String scope() default "singleton";
26+
}
27+
```
28+
29+
## 运行特性
30+
- scope=singleton/property 控制实例复用与重建;
31+
- 获取配置:getCubeConfig();
32+
- AngelCube 的 execute 只负责启动守护任务,停止请使用 ActuatorProxy.stop(slotId)。

docs/api/event-api.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 事件 API
2+
3+
## 监听器编写
4+
- 继承 SelectiveMosaicEventListener,覆盖 getListenedEventTypes() 指定关心事件;
5+
- 在 onSelectiveEvent 中用 when(...).orWhen(...).orDefault() 分派处理;
6+
- 通过 getListenerName() 返回监听器名称。
7+
8+
常见事件(示例):
9+
- CubeConfigUpdateEvent:Cube 配置变更
10+
- CubeDefinitionRegisteredEvent:Cube 定义注册完成
11+
12+
提示:
13+
- AngelCube 的监听器会在 init 成功后自动注册到广播器。

docs/api/extension-api.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 扩展 API
2+
3+
## 扩展点注解
4+
```java
5+
@Target(ElementType.METHOD)
6+
@Retention(RetentionPolicy.RUNTIME)
7+
public @interface MExtension {
8+
String extPointId();
9+
String name() default "";
10+
String description() default "";
11+
int priority() default 100;
12+
}
13+
```
14+
15+
## 扩展包抽象
16+
```java
17+
public abstract class MosaicExtPackage<T extends MosaicCube> implements ExtensionPackageApi {
18+
protected T mosaicCube;
19+
@Override
20+
public void initCube(MosaicCube mosaicCube) {
21+
this.mosaicCube = (T) mosaicCube;
22+
}
23+
}
24+
```
25+
26+
## 返回值约定
27+
- 返回 MosaicResult:框架原样使用(并以 default 名再存一份),调用方可按 resName + itemName 拿到命名结果;
28+
- 返回普通类型:框架封装为 MosaicResult 并以 default 命名;
29+
- 返回 void/MosaicVoid:表示无返回。

docs/examples/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# 示例
2+
3+
本节包含三个示例:
4+
- AI 聊天插件:HTTP 调用大模型接口,演示配置读取与重试
5+
- 系统日志插件:演示多实例配置读取
6+
- 监听器插件:演示选择性事件监听与处理

0 commit comments

Comments
 (0)