Skip to content

Commit 03f4148

Browse files
bamboo0403kamiya4047whes1015
authored
fix: pack (#2)
* feat: versioning * fix(plugin): init with class * fix: broken link * fix: broken link (plugin_dev -> plugin) * fix: version 3.1.0 * fix: word * fix: versioning * fix: version * fix: sidebar version * fix: pack * feat: event list --------- Co-authored-by: Kamiya <kamiya@kamiya.app> Co-authored-by: YuYu1015 <whes1015@gmail.com>
1 parent ab5d960 commit 03f4148

66 files changed

Lines changed: 1755 additions & 11 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
File renamed without changes.
File renamed without changes.
File renamed without changes.

docs/miscellaneous/events_list.mdx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# 事件列表
6+
7+
查看可用的事件。
8+
9+
## 目錄
10+
11+
- onServerStartEvent
12+
- EewRelease
13+
- EewAlert
14+
- RtsPga2
15+
- RtsPga1
16+
- RtsShindo2
17+
- RtsShindo1
18+
- RtsShindo0
19+
- ReportRelease
20+
- IntensityRelease
21+
- LpgmRelease
22+
- TsunamiRelease
23+
- EewNewAreaAlert
24+
25+
## onServerStartEvent
26+
27+
#### 回傳參數 `pid`
28+
29+
當伺服器被啟動
30+
31+
## EewRelease
32+
33+
當收到地震警報
34+
35+
## EewAlert
36+
37+
當收到緊急地震警報
38+
39+
## RtsPga2
40+
41+
當 PGA > 200gal
42+
43+
## RtsPga1
44+
45+
當 PGA > 8gal
46+
47+
## RtsShindo2
48+
49+
當收到地震檢知 震度4級
50+
51+
## RtsShindo1
52+
53+
當收到地震檢知 震度2級
54+
55+
## RtsShindo0
56+
57+
當收到地震檢知 震度0級
58+
59+
## ReportRelease
60+
61+
當收到地震報告
62+
63+
## IntensityRelease
64+
65+
當收到震度速報
66+
67+
## LpgmRelease
68+
69+
當收到長週期地震動資訊
70+
71+
## TsunamiRelease
72+
73+
當收到海嘯警報
74+
75+
## EewNewAreaAlert
76+
77+
當收到地震速報新區域
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ sidebar_position: 4
1111
:::
1212

1313
:::tip
14-
若是擴充要使用的 logger 推薦使用[自定義日誌](../plugin_dev/log)
14+
若是擴充要使用的 logger 推薦使用[自定義日誌](../plugin/log)
1515
:::
1616

1717
```js

docs/miscellaneous/plugin_repo.mdx

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
sidebar_position: 7
3+
---
4+
5+
# 擴充倉庫
6+
7+
將自己製作的擴充套件放置在倉庫內,並使用 workflow 自動 pr 到 trem-plugin 倉庫。
8+
9+
## 文件結構
10+
11+
```
12+
plugin/
13+
index.js
14+
info.json
15+
16+
.github/
17+
workflows/
18+
auto-pr-info.yml
19+
```
20+
21+
## index.js
22+
23+
擴充套件的入口點
24+
25+
### Class 形式
26+
27+
28+
```js
29+
class Plugin {
30+
#ctx;
31+
32+
constructor(ctx) {
33+
this.#ctx = ctx;
34+
}
35+
36+
onLoad() {
37+
const { TREM, logger, MixinManager } = this.#ctx;
38+
}
39+
}
40+
41+
module.exports = Plugin;
42+
```
43+
44+
### Function 形式
45+
46+
```js
47+
module.exports = function (ctx) {
48+
ctx.on("load", () => {
49+
const { TREM, logger, MixinManager } = ctx;
50+
});
51+
};
52+
```
53+
54+
## info.json
55+
56+
定義擴充資訊的文件
57+
58+
```json
59+
{
60+
"version": "1.0.0", // 擴充版本
61+
"description": {
62+
"zh_tw": "TREM 範例擴充" // 擴充說明
63+
},
64+
"author": [
65+
"YuYu1015" // 擴充作者
66+
],
67+
"dependencies": {
68+
"trem": ">=3.0.0" // 擴充所需的 TREM 最低版本
69+
},
70+
"resources": [
71+
"AGPL-3.0" // 擴充的開源協議
72+
],
73+
"link": "https://github.com/ExpTechTW/TREM-Lite" // 擴充 的 GitHub Link
74+
}
75+
```
76+
77+
## auto-pr-info.yml
78+
79+
自動 pr 到 trem-plugin 倉庫的 workflow
80+
81+
```yml
82+
name: Auto PR to infos folder
83+
84+
on:
85+
push:
86+
branches:
87+
- main
88+
paths:
89+
- "info.json"
90+
91+
jobs:
92+
create-pr:
93+
runs-on: ubuntu-latest
94+
steps:
95+
- name: Checkout source repository
96+
uses: actions/checkout@v4
97+
with:
98+
path: source-repo
99+
100+
- name: Get filename from info.json
101+
id: get-filename
102+
run: |
103+
cd source-repo
104+
BASE_NAME=$(jq -r '.name' info.json)
105+
FILENAME="${BASE_NAME}.json"
106+
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
107+
echo "branch_name=update-file-$(date +%s)" >> $GITHUB_OUTPUT
108+
cp info.json ../target.json
109+
110+
- name: Checkout target repository
111+
uses: actions/checkout@v4
112+
with:
113+
repository: ExpTechTW/TREM-Plugins
114+
token: ${{ secrets.PAT_TOKEN }}
115+
path: target-repo
116+
117+
- name: Copy and commit file
118+
run: |
119+
mkdir -p target-repo/infos
120+
mv target.json "target-repo/infos/${{ steps.get-filename.outputs.filename }}"
121+
cd target-repo
122+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
123+
git config --global user.name "github-actions[bot]"
124+
BRANCH_NAME="${{ steps.get-filename.outputs.branch_name }}"
125+
git checkout -b $BRANCH_NAME
126+
git add infos
127+
if ! git diff --cached --quiet; then
128+
git commit -m "Update ${{ steps.get-filename.outputs.filename }}"
129+
git push origin $BRANCH_NAME
130+
else
131+
echo "No changes to commit."
132+
exit 0
133+
fi
134+
135+
- name: Create Pull Request
136+
if: success()
137+
env:
138+
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
139+
run: |
140+
pr_url=$(gh pr create \
141+
--repo ExpTechTW/TREM-Plugins \
142+
--base main \
143+
--head ${{ steps.get-filename.outputs.branch_name }} \
144+
--title "Update ${{ steps.get-filename.outputs.filename }}" \
145+
--body "Automated update from plugin repository" \
146+
--label "auto-merge")
147+
echo "Created PR: $pr_url"
148+
```
149+
# 備註
150+
151+
只有在 info.json 有變更時,才會觸發 workflow。
152+
153+
:::warning
154+
需要先建立 Releases 在 push 更新到倉庫,不然 pr 時會失敗。
155+
:::
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)