mirror of
https://github.com/halo-dev/plugin-starter.git
synced 2025-10-14 15:11:52 +00:00
4
.github/workflows/workflow.yaml
vendored
4
.github/workflows/workflow.yaml
vendored
@@ -44,10 +44,10 @@ jobs:
|
|||||||
- name: Build with Gradle
|
- name: Build with Gradle
|
||||||
run: |
|
run: |
|
||||||
./gradlew clean build -x test
|
./gradlew clean build -x test
|
||||||
- name: Archive plugin-template jar
|
- name: Archive plugin-starter jar
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
with:
|
with:
|
||||||
name: plugin-template
|
name: plugin-starter
|
||||||
path: |
|
path: |
|
||||||
build/libs/*-plain.jar
|
build/libs/*-plain.jar
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
23
README.md
23
README.md
@@ -1,4 +1,4 @@
|
|||||||
# plugin-template
|
# plugin-starter
|
||||||
|
|
||||||
Halo 2.0 插件开发快速开始模板(WIP)
|
Halo 2.0 插件开发快速开始模板(WIP)
|
||||||
|
|
||||||
@@ -67,7 +67,8 @@ Halo 2.0 插件开发快速开始模板(WIP)
|
|||||||
|
|
||||||
- `admin-frontend`: 插件前端项目目录,为一个 Vue 项目,技术栈为 Vue 3 + Vite,其中已经预配置好了构建策略。
|
- `admin-frontend`: 插件前端项目目录,为一个 Vue 项目,技术栈为 Vue 3 + Vite,其中已经预配置好了构建策略。
|
||||||
- `build`:插件后端构建目录,`build/libs` 下的 jar 包为最终插件产物。
|
- `build`:插件后端构建目录,`build/libs` 下的 jar 包为最终插件产物。
|
||||||
- `lib`:为临时的 Halo 依赖,为了使用 Halo 中提供的类在 `build.gradle` 中作为编译时依赖引入 `compileOnly files("lib/halo-2.0.0-SNAPSHOT-plain.jar")`
|
- `lib`:为临时的 Halo 依赖,为了使用 Halo 中提供的类在 `build.gradle`
|
||||||
|
中作为编译时依赖引入 `compileOnly files("lib/halo-2.0.0-SNAPSHOT-plain.jar")`
|
||||||
,待 `2.0` 正式发布会将其发布到 `maven` 中央仓库,便可通过 `gradle` 依赖。
|
,待 `2.0` 正式发布会将其发布到 `maven` 中央仓库,便可通过 `gradle` 依赖。
|
||||||
- `src`: 为插件后端源码目录。
|
- `src`: 为插件后端源码目录。
|
||||||
- `Apple.java`: 为自定义模型。
|
- `Apple.java`: 为自定义模型。
|
||||||
@@ -81,7 +82,8 @@ Halo 2.0 插件开发快速开始模板(WIP)
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
关键在于标注 `@GVK` 注解和 `extends AbstractExtension`,当如此定义了一个模型后,插件启动时会根据 `@GVK` 配置自动生成`CRUD`的 `RESTful API`
|
关键在于标注 `@GVK` 注解和 `extends AbstractExtension`,当如此定义了一个模型后,插件启动时会根据 `@GVK`
|
||||||
|
配置自动生成`CRUD`的 `RESTful API`
|
||||||
,以此为例子会生成如下 `APIs`
|
,以此为例子会生成如下 `APIs`
|
||||||
|
|
||||||
```http
|
```http
|
||||||
@@ -98,7 +100,8 @@ Halo 2.0 插件开发快速开始模板(WIP)
|
|||||||
|
|
||||||
生成规则见:[Halo extension RFC](https://github.com/halo-dev/rfcs/tree/main/extension)
|
生成规则见:[Halo extension RFC](https://github.com/halo-dev/rfcs/tree/main/extension)
|
||||||
|
|
||||||
- `TemplatePlugin.java`:插件生命周期入口,它继承 `BasePlugin`,可以通过 `getApplicationContext()` 方法获取到 `SchemeManager`,然后在 `start()`
|
- `TemplatePlugin.java`:插件生命周期入口,它继承 `BasePlugin`,可以通过 `getApplicationContext()`
|
||||||
|
方法获取到 `SchemeManager`,然后在 `start()`
|
||||||
方法中注册自定义模型,这一步必不可少,所有定义的自定义模型都需要在此注册,并在 `stop()` 生命周期方法中清理资源。
|
方法中注册自定义模型,这一步必不可少,所有定义的自定义模型都需要在此注册,并在 `stop()` 生命周期方法中清理资源。
|
||||||
|
|
||||||
```java
|
```java
|
||||||
@@ -122,7 +125,8 @@ Halo 2.0 插件开发快速开始模板(WIP)
|
|||||||
|
|
||||||
注意:该类不能标注 `@Component` 等能将其声明为 `Spring Bean` 的注解
|
注意:该类不能标注 `@Component` 等能将其声明为 `Spring Bean` 的注解
|
||||||
|
|
||||||
- `ApplesController.java`:如果根据模型自动生成的 `CURD RESTful APIs` 无法满足业务需要,可以写常规 `Controller` 来自定义 `APIs`,示例:
|
- `ApplesController.java`:如果根据模型自动生成的 `CURD RESTful APIs` 无法满足业务需要,可以写常规 `Controller`
|
||||||
|
来自定义 `APIs`,示例:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
|
||||||
@@ -138,7 +142,8 @@ Halo 2.0 插件开发快速开始模板(WIP)
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
插件定义 `Controller` 必须要标注 `@ApiVersion` 注解,否则启动时会报错。如果定义了这样的 `Controller` ,插件启动后会生成如下的 `APIs`:
|
插件定义 `Controller` 必须要标注 `@ApiVersion` 注解,否则启动时会报错。如果定义了这样的 `Controller`
|
||||||
|
,插件启动后会生成如下的 `APIs`:
|
||||||
|
|
||||||
```http
|
```http
|
||||||
GET /api/v1alpha1/plugins/apples/colors
|
GET /api/v1alpha1/plugins/apples/colors
|
||||||
@@ -254,7 +259,8 @@ Halo 2.0 插件开发快速开始模板(WIP)
|
|||||||
|
|
||||||
必须带有`plugin.halo.run/role-template: "true"` labels,表示该角色为角色模版,当用户启用插件后,创建角色或修改角色时会将其列在权限列表位置。
|
必须带有`plugin.halo.run/role-template: "true"` labels,表示该角色为角色模版,当用户启用插件后,创建角色或修改角色时会将其列在权限列表位置。
|
||||||
|
|
||||||
插件如果不提供角色模版除非是超级管理员否则其他账号没有权限访问,因为 Halo 规定 `/api` 和 `/apis` 开头的 `api` 都需要授权才能访问,因此插件不提供角色模版的自定义资源,就无法将其分配给用户。
|
插件如果不提供角色模版除非是超级管理员否则其他账号没有权限访问,因为 Halo 规定 `/api` 和 `/apis` 开头的 `api`
|
||||||
|
都需要授权才能访问,因此插件不提供角色模版的自定义资源,就无法将其分配给用户。
|
||||||
|
|
||||||
更多详情参考:[Halo security RFC](https://github.com/halo-dev/rfcs/blob/main/identity/002-security.md)
|
更多详情参考:[Halo security RFC](https://github.com/halo-dev/rfcs/blob/main/identity/002-security.md)
|
||||||
|
|
||||||
@@ -376,7 +382,8 @@ pnpm dev
|
|||||||
|
|
||||||
### 开发
|
### 开发
|
||||||
|
|
||||||
修改前端代码或者后端代码,然后运行 `./gradlew.bat build` 或者 `./gradlew build`(macOS/Linux)即可构建插件,无需重启 Halo。但修改配置文件后需要 build 插件以及重启 Halo。
|
修改前端代码或者后端代码,然后运行 `./gradlew.bat build` 或者 `./gradlew build`(macOS/Linux)即可构建插件,无需重启
|
||||||
|
Halo。但修改配置文件后需要 build 插件以及重启 Halo。
|
||||||
|
|
||||||
## 构建生产产物
|
## 构建生产产物
|
||||||
|
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
# halo-plugin-frontend-template(WIP)
|
|
||||||
|
|
||||||
> Front-end template for Halo 2.0 pluggable system
|
|
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "@halo-dev/plugin-frontend-template",
|
"name": "@halo-dev/plugin-starter",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@@ -4,7 +4,7 @@ import { IconGrid } from "@halo-dev/components";
|
|||||||
import "./styles/index.css";
|
import "./styles/index.css";
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "PluginTemplate",
|
name: "PluginStarter",
|
||||||
components: [],
|
components: [],
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
@@ -24,7 +24,7 @@ export default definePlugin({
|
|||||||
],
|
],
|
||||||
menus: [
|
menus: [
|
||||||
{
|
{
|
||||||
name: "From PluginTemplate",
|
name: "From PluginStarter",
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
name: "HelloWorld",
|
name: "HelloWorld",
|
||||||
|
@@ -19,7 +19,7 @@ export default defineConfig({
|
|||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
lib: {
|
lib: {
|
||||||
entry: "src/index.ts",
|
entry: "src/index.ts",
|
||||||
name: "PluginTemplate",
|
name: "PluginStarter",
|
||||||
formats: ["iife"],
|
formats: ["iife"],
|
||||||
fileName: () => "main.js",
|
fileName: () => "main.js",
|
||||||
},
|
},
|
||||||
|
@@ -5,7 +5,7 @@ plugins {
|
|||||||
id 'java'
|
id 'java'
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'run.halo.template'
|
group 'run.halo.starter'
|
||||||
version '0.0.1-SNAPSHOT'
|
version '0.0.1-SNAPSHOT'
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
|
||||||
|
@@ -6,5 +6,5 @@ pluginManagement {
|
|||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rootProject.name = 'plugin-template'
|
rootProject.name = 'plugin-starter'
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
package run.halo.template;
|
package run.halo.starter;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -10,7 +10,7 @@ import run.halo.app.extension.GVK;
|
|||||||
* @author guqing
|
* @author guqing
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@GVK(group = "run.halo.template", kind = "Apple",
|
@GVK(group = "run.halo.starter", kind = "Apple",
|
||||||
version = "v1alpha1", singular = "apple", plural = "apples")
|
version = "v1alpha1", singular = "apple", plural = "apples")
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
@@ -1,4 +1,4 @@
|
|||||||
package run.halo.template;
|
package run.halo.starter;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
@@ -1,4 +1,4 @@
|
|||||||
package run.halo.template;
|
package run.halo.starter;
|
||||||
|
|
||||||
import org.pf4j.PluginWrapper;
|
import org.pf4j.PluginWrapper;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -11,10 +11,10 @@ import run.halo.app.plugin.BasePlugin;
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class TemplatePlugin extends BasePlugin {
|
public class StarterPlugin extends BasePlugin {
|
||||||
private final SchemeManager schemeManager;
|
private final SchemeManager schemeManager;
|
||||||
|
|
||||||
public TemplatePlugin(PluginWrapper wrapper) {
|
public StarterPlugin(PluginWrapper wrapper) {
|
||||||
super(wrapper);
|
super(wrapper);
|
||||||
this.schemeManager = getApplicationContext().getBean(SchemeManager.class);
|
this.schemeManager = getApplicationContext().getBean(SchemeManager.class);
|
||||||
}
|
}
|
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
|||||||
apiVersion: run.halo.template/v1alpha1
|
apiVersion: run.halo.starter/v1alpha1
|
||||||
kind: Apple
|
kind: Apple
|
||||||
metadata:
|
metadata:
|
||||||
name: Fuji-apple
|
name: Fuji-apple
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
apiVersion: v1alpha1
|
apiVersion: v1alpha1
|
||||||
kind: Setting
|
kind: Setting
|
||||||
metadata:
|
metadata:
|
||||||
name: template-settings
|
name: starter-settings
|
||||||
spec:
|
spec:
|
||||||
- group: basic
|
- group: basic
|
||||||
label: 基本设置
|
label: 基本设置
|
||||||
|
@@ -2,7 +2,7 @@ apiVersion: plugin.halo.run/v1alpha1
|
|||||||
kind: Plugin
|
kind: Plugin
|
||||||
metadata:
|
metadata:
|
||||||
# The name defines how the plugin is invoked,A unique name
|
# The name defines how the plugin is invoked,A unique name
|
||||||
name: PluginTemplate
|
name: PluginStarter
|
||||||
spec:
|
spec:
|
||||||
enabled: true
|
enabled: true
|
||||||
# 'version' is a valid semantic version string (see semver.org).
|
# 'version' is a valid semantic version string (see semver.org).
|
||||||
@@ -10,10 +10,10 @@ spec:
|
|||||||
requires: "*"
|
requires: "*"
|
||||||
author: halo-dev
|
author: halo-dev
|
||||||
logo: https://halo.run/logo
|
logo: https://halo.run/logo
|
||||||
settingName: template-settings
|
settingName: starter-settings
|
||||||
configMapName: template-settings
|
configMapName: starter-settings
|
||||||
# 'homepage' usually links to the GitHub repository of the plugin
|
# 'homepage' usually links to the GitHub repository of the plugin
|
||||||
homepage: https://github.com/halo-sigs/halo-plugin-template
|
homepage: https://github.com/halo-sigs/plugin-starter
|
||||||
# 'displayName' explains what the plugin does in only a few words
|
# 'displayName' explains what the plugin does in only a few words
|
||||||
displayName: "插件快速开始模板"
|
displayName: "插件快速开始模板"
|
||||||
description: "这是一个插件快速开始模板"
|
description: "这是一个插件快速开始模板"
|
||||||
|
Reference in New Issue
Block a user