Skip to content

Commit

Permalink
feat: versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiya10 committed Nov 30, 2024
1 parent 3cc8f5b commit a898ff4
Show file tree
Hide file tree
Showing 66 changed files with 1,541 additions and 25 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ const config: Config = {
position: "left",
label: "TREM",
},
{
type: 'docsVersionDropdown',
position: 'right',
},
{
href: "https://github.com/ExpTechTW/TREM-Docs",
label: "GitHub",
Expand Down
2 changes: 1 addition & 1 deletion i18n/en/docusaurus-plugin-content-docs/current.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version.label": {
"message": "Next",
"message": "Next 🚧",
"description": "The label for version current"
}
}
10 changes: 10 additions & 0 deletions i18n/en/docusaurus-plugin-content-docs/current/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
sidebar_position: 1
---

# TREM
Taiwan Real-time Earthquake Monitoring (臺灣即時地震監測)

## TREM 是什麼?
是一款開源地震速報軟體,提供給用戶即時的地震資訊,利用自製的測站,
顯示各地的即時震度,在地震發生的第一時間取得各管道發布的強震即時警報訊息。
13 changes: 13 additions & 0 deletions i18n/en/docusaurus-plugin-content-docs/current/install.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
sidebar_position: 2
---

# 開始

## 安裝

- [下載](https://github.com/ExpTechTW/TREM-Lite/releases)

:::tip
請根據自身作業系統,下載對應副檔名的安裝檔。
:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
sidebar_position: 3
---

# 依賴關係

擴充之間的依賴關係

## 聲明依賴

`info.json` 中 聲明

:::tip

依賴中 `trem` 為必須的。

:::

:::tip 版本格式說明
版本號格式為: 主版本.次版本.修訂版本-預發布標識

例如: `3.0.0-pre.1`

支援的版本規則格式:

`>=3.0.0-pre.1` - 大於等於指定版本

`<=3.0.0-pre.4` - 小於等於指定版本

`<3.0.0-pre.4` - 小於指定版本

`>3.0.0-pre.4` - 大於指定版本

`=3.0.0-pre.4` - 等於指定版本

`>=3.0.0-pre.1 <=3.0.0-pre.4` - 版本需同時符合兩個條件
:::

```json
{
// ...
"dependencies": {
"trem": ">=3.0.0" // 擴充所需的 TREM 最低版本
}
// ...
}
```

## 用途

檢查是否有執行擴充所需的其他擴充

:::tip

舉例來說,`websocket` 需要 `exptech` 提供地震報告資料。換句話說,`exptech` 就是 `websocket` 所必需的依賴。

:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
sidebar_position: 6
---

# 自定義事件註冊

除了 TREM 本身,擴充還可以分發自己的事件。

:::tip

**自定義事件**是擴充之間,傳遞訊息的一種方式。

:::

## 用法

事件發射

```js
const emit = (event, data) => TREM.variable.events.emit(event, data);
emit("test", { data: "test" });
```

事件接收

```js
const event = (event, callback) => TREM.variable.events.on(event, callback);
event("test", (data) => {
console.log(data); // { data: "test" }
});
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
sidebar_position: 1
---

# 事件列表

查看可用的事件。

## 目錄

- onServerStartEvent

## onServerStartEvent

#### 回傳參數 `pid`

當伺服器被啟動
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
sidebar_position: 3
---

# 雜項

這裡紀錄著,一些瑣碎的東西。

## 目錄

- [事件列表](./events_list)
- [版本管理](./version)
- [依賴關係](./dependencies)
- [日誌紀錄](./logger)
- [導入其他擴充](./require)
- [自定義事件註冊](./event)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
sidebar_position: 4
---

# 日誌紀錄

主視窗 logger 實例,有 `debug``info``warn``error` 四種等級。

:::tip
支援 `logger.info("info", 123, false);` 用法。
:::

:::tip
若是擴充要使用的 logger 推薦使用[自定義日誌](../plugin_dev/log)
:::

```js
const { TREM, Logger, logger, MixinManager } = this.#ctx;
logger.debug("debug");
logger.info("info");
logger.warn("warn");
logger.error("error");
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
sidebar_position: 5
---

# 導入其他擴充

## test.js

plugins/test/test.js

```js
const test = 123;

module.exports = test;
```

## example.js

plugins/example/example.js

```js
const { TREM, Logger, logger, MixinManager } = this.#ctx;

// 導入 test.js
// pluginLoader 會處理路徑問題,使用相對路徑即可。
const test = this.#ctx.require("../test/test");
console.log(test);
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
sidebar_position: 2
---

# 版本管理

擴充作者應做好版本管理

## 擴充版本命名方式

`X.Y.Z`

### X 主版號

當產品進行了重大的更新或功能改變,影響了向下相容性,或完全重寫了代碼時,應增加 `主版號`

- 1.5.8 -> 2.0.0

### Y 次版號

擴充新增功能後,應增加 `次版號`,然後 `修訂號` 歸零。

- 1.1.5 -> 1.2.0

### Z 修訂號

擴充修復錯誤或問題增加 `修訂號`
23 changes: 23 additions & 0 deletions i18n/en/docusaurus-plugin-content-docs/current/plugin/event.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
sidebar_position: 2
---

# 事件

監聽發生的事件,並執行對應功能。

## Event Listener

定義一個 Listener 後,向**事件管理器**註冊。

<span style={{ color: "red" }}>❗ 不推薦的做法</span>

:::caution
不保證事件發生後,執行的優先順序,應考慮 [Mixin](./mixin)
:::

```js
const event = (event, callback) => TREM.variable.events.on(event, callback);

event("EewNewAreaAlert", (ans) => console.log("收到地震預警:", ans));
```
14 changes: 14 additions & 0 deletions i18n/en/docusaurus-plugin-content-docs/current/plugin/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
sidebar_position: 2
---

# 擴充開發

並不是所有想要的功能,軟體都會有,如果有能力,不妨試試動手做看看!!!

## 準備

- Node.js ( 推薦 `>= 18.20.2` )
- VSCode ( 或其他 IDE )
- Git
- GitHub Desktop (可選)
101 changes: 101 additions & 0 deletions i18n/en/docusaurus-plugin-content-docs/current/plugin/log.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
sidebar_position: 4
---

# 自定義日誌

一個屬於擴充自己的日誌紀錄方式。

## index.js

```js
const { TREM, Logger, MixinManager } = this.#ctx;
// 傳入主視窗 Logger 類定義 (父類)
// 導入新的自定義類 (繼承的子類)
const { CustomLogger } = require("./logger").createCustomLogger(Logger);
// 初始化自定義類
this.logger = new CustomLogger("example");
this.logger.info("info");
```

## test.js

```js
// 由於是單例模式,在 index.js 初始化後,即可在任何地方使用。
const logger = require("./logger");
logger.info("info");
```

## logger.js

```js
let globalInstance = null;
let CustomLoggerClass = null;

function createCustomLogger(BaseLogger) {
if (CustomLoggerClass && globalInstance)
return {
CustomLogger: CustomLoggerClass,
instance: globalInstance,
};

class CustomLogger extends BaseLogger {
constructor(prefix = "") {
super();

if (globalInstance) {
globalInstance.prefix = prefix;
return globalInstance;
}

this.prefix = prefix;
globalInstance = this;
}

_formatMessage(message, ...args) {
const formattedMessage = super._formatMessage(message, ...args);
return this.prefix
? `[${this.prefix}] ${formattedMessage}`
: formattedMessage;
}
}

CustomLoggerClass = CustomLogger;

return {
CustomLogger,
instance: globalInstance,
};
}

function checkInitialized() {
if (!globalInstance)
throw new Error(
"Logger not initialized. Please call createCustomLogger first."
);
}

module.exports = {
createCustomLogger,
info: (...args) => {
checkInitialized();
return globalInstance.info(...args);
},
error: (...args) => {
checkInitialized();
return globalInstance.error(...args);
},
warn: (...args) => {
checkInitialized();
return globalInstance.warn(...args);
},
debug: (...args) => {
checkInitialized();
return globalInstance.debug(...args);
},
get prefix() {
checkInitialized();
return globalInstance.prefix;
},
};
```
Loading

0 comments on commit a898ff4

Please sign in to comment.