Skip to content

Commit 1c13a9f

Browse files
committed
适配v2.1
1 parent afc972e commit 1c13a9f

File tree

121 files changed

+6441
-4354
lines changed

Some content is hidden

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

121 files changed

+6441
-4354
lines changed

.markdownlint-cli2.jsonc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"globs": ["**.md"],
3+
"ignores": ["node_modules/**"],
4+
"config": {
5+
"no-inline-html": false,
6+
"line-length": false,
7+
"no-duplicate-heading": false,
8+
"blanks-around-fences": false
9+
}
10+
}

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Serein 文档
22

33
<p align="center">
4-
<img src='static/logo.png' width="100"/>
4+
<img src='static/logo.png' width="100" alt="logo"/>
55
<br>
66
Serein的官方文档
77
<br>
@@ -20,22 +20,22 @@ Serein的官方文档
2020

2121
### 要求
2222

23-
NodeJS LTS
23+
NodeJS LTS & PNPM
2424

2525
### 初始化
2626

2727
```ps
28-
> npm i
28+
> pnpm i
2929
```
3030

3131
### 预览
3232

3333
```ps
34-
> npm start
34+
> pnpm start
3535
```
3636

37-
### 生成
37+
### 构建
3838

3939
```ps
40-
> npm run build
40+
> pnpm run build
4141
```

docs/development/index.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
# 开发
22

3-
import DocCardList from '@theme/DocCardList';
4-
53
<DocCardList />
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# 内置模块
2+
3+
为方便插件开发者使用,Serein 按照 NodeJs 的风格内置了一些基本的函数
4+
5+
所有模块已默认导入到上下文中,所以你可以直接使用
6+
7+
## `fs`
8+
9+
```ts title="示例"
10+
fs.writeFileSync("1.txt", "Hello, World!");
11+
fs.copyFileSync("1.txt", "2.txt");
12+
```
13+
14+
:::warning
15+
16+
- ~~因懒得实现`Buffer`~~,所有`Buffer`均使用`integer[]`代替,方便内部.NET 代码转换
17+
- 只实现了部分同步函数,剩余的函数可能在未来补全
18+
- 没有进行过严格的测试,**其行为可能和 NodeJs 中的存在差异**
19+
20+
:::
21+
22+
- [`appendFileSync(path: string, data: string, options?: string | object): void`](https://nodejs.org/docs/latest/api/fs.html#fsappendfilesyncpath-data-options)
23+
- [`appendFileSync(path: string, data: integer[], options?: string | object): void`](https://nodejs.org/docs/latest/api/fs.html#fsappendfilesyncpath-data-options)
24+
- [`closeSync(fd: integer): void`](https://nodejs.org/docs/latest/api/fs.html#fsclosesyncfd)
25+
- [`copyFileSync(src: string, dest: string, flags: integer = 0): void`](https://nodejs.org/docs/latest/api/fs.html#fscopyfilesyncsrc-dest-mode)
26+
- `flags != 1`时会覆盖原有文件(如果存在)
27+
- [`existsSync(path: string): boolean`](https://nodejs.org/docs/latest/api/fs.html#fsexistssyncpath)
28+
- [`fsyncSync(fd: integer)`](https://nodejs.org/docs/latest/api/fs.html#fsfsyncsyncfd)
29+
- [`ftruncateSync(fd: integer, len: integer = 0): void`](https://nodejs.org/docs/latest/api/fs.html#fsftruncatesyncfd-len)
30+
- [`futimesSync(fd: integer, atime: Date, mtime: Date): void`](https://nodejs.org/docs/latest/api/fs.html#fsfutimessyncfd-atime-mtime)
31+
- [`globSync(pattern: string, options?: object): string`](https://nodejs.org/docs/latest/api/fs.html#fsglobsyncpattern-options)
32+
- [`globSync(pattern: string[], options?: object): string`](https://nodejs.org/docs/latest/api/fs.html#fsglobsyncpattern-options)
33+
- [`mkdirSync(path: string, options?: object): void`](https://nodejs.org/docs/latest/api/fs.html#fsmkdirsyncpath-options)
34+
- `options.mode`仅在非 Windows 平台上生效,这与 NodeJs 中一致,下同
35+
- [`mkdirSync(path: string, options?: integer = 0o777): void`](https://nodejs.org/docs/latest/api/fs.html#fsmkdirsyncpath-options)
36+
- [`mkdtempSync(prefix: string, options?: object): string`](https://nodejs.org/docs/latest/api/fs.html#fsmkdtempsyncprefix-options)
37+
- [`openSync(path: string, flags: string, mode?: string | integer): integer`](https://nodejs.org/docs/latest/api/fs.html#fsopensyncpath-flags-mode)
38+
- `mode` 总是会被忽略
39+
- [`readdirSync(path: string, options?: object): string[]`](https://nodejs.org/docs/latest/api/fs.html#fsreaddirsyncpath-options)
40+
- 仅有 `options.recursive` 会生效
41+
- [`readFileSync(path: string, options?: object): string`](https://nodejs.org/docs/latest/api/fs.html#fsreadfilesyncpath-options)
42+
- [`readSync(fd: integet, buffer: integer[], offset: integer, length: integer, position: integer = 0): integer`](https://nodejs.org/docs/latest/api/fs.html#fsreadsyncfd-buffer-offset-length-position)
43+
- [`renameSync(oldPath: string, newPath: string): void`](https://nodejs.org/docs/latest/api/fs.html#fsrenamesyncoldpath-newpath)
44+
- [`rmdirSync(path: string, options?: object): void`](https://nodejs.org/docs/latest/api/fs.html#fsrmdirsyncpath-options)
45+
- 仅有 `options.recursive` 会生效
46+
- [`rmSync(path: string, options?: object): void`](https://nodejs.org/docs/latest/api/fs.html#fsrmsyncpath-options)
47+
- 仅有 `options.recursive` 会生效
48+
- [`symlinkSync(target: string, path: string, type?: string): void`](https://nodejs.org/docs/latest/api/fs.html#fssymlinksynctarget-path-type)
49+
- `type` 总是会被忽略
50+
- [`truncateSync(path: string, len: integer = 0): void`](https://nodejs.org/docs/latest/api/fs.html#fstruncatesyncpath-len)
51+
- [`unlinkSync(path: string): void`](https://nodejs.org/docs/latest/api/fs.html#fsunlinksyncpath)
52+
- 实际上是删除 `path`
53+
- [`utimesSync(path: string, atime: Date, mtime: Date): void`](https://nodejs.org/docs/latest/api/fs.html#fsutimessyncpath-atime-mtime)
54+
- [`writeFileSync(path: string, data: string, options?: string | object): void`](https://nodejs.org/docs/latest/api/fs.html#fswritefilesyncpath-data-options)
55+
- [`writeFileSync(path: string, data: integer[], options?: string | object): void`](https://nodejs.org/docs/latest/api/fs.html#fswritefilesyncpath-data-options)
56+
- [`writeSync(fd: integer, buffer: integer[], offset: integer, length: integer, position: integer): integer`](https://nodejs.org/docs/latest/api/fs.html#fswritesyncfd-buffer-offset-length-position)
57+
- [`writeSync(fd: integer, data: string, position: integer = 0, encoding: string = 'utf8'): integer`](https://nodejs.org/docs/latest/api/fs.html#fswritesyncfd-buffer-offset-length-position)
58+
59+
## `process`
60+
61+
- `arch: string`
62+
- 实际上只会返回 `"x64"``"arm64"`,这是因为 Serein 的发行版没有 x86 的构建
63+
- `argv: string[]`
64+
- `argv0: string`
65+
-`argv[0]`
66+
- `chdir(directory: string): string`
67+
- 不推荐使用此函数,否则可能**导致文件错位**
68+
- `cwd(): string`
69+
- `exit(code: integer = 0): void`
70+
- 不推荐使用此函数
71+
- `env: { [key: string]: string }`
72+
- `execPath: string`
73+
- `exitCode: integer`
74+
- `kill(pid: integer)`
75+
- `pid: integer`
76+
- `platform: string`
77+
- 实际上仅会返回 `"win32nt"``"unix"``"other"`
78+
- `version: string`
79+
- 返回的是.NET 运行时版本
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 导入.NET程序集
1+
# 导入.NET 程序集
22

33
- 部分较基础的命名空间默认已加载到上下文中
44
- `System`
@@ -15,6 +15,14 @@ declare type ClrType = {
1515
};
1616
```
1717

18+
```ts
19+
const File = importNamespace('System.IO').File;
20+
File.WriteAllTexts(
21+
'path/to/file/1.txt',
22+
'hello world'
23+
);
24+
```
25+
1826
## 直接导入
1927

2028
:::tip
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 开发助手
2+
3+
[![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=SereinDev&repo=HelperLib)](https://github.com/SereinDev/HelperLib)
4+
5+
TypeScript 类型定义库
6+
7+
详见 [SereinDev/HelperLib](https://github.com/SereinDev/HelperLib)

docs/development/plugins/js/index.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
# JavaScript 插件开发
22

3-
## JS标准
3+
## JS 标准
44

55
ECMAScript 2024 / ES6
66

77
具体特性支持列表详见[Supported features - sebastienros/jint](https://github.com/sebastienros/jint?tab=readme-ov-file#supported-features)
88

9-
## 开发助手
10-
11-
TypeScript 类型定义库
12-
13-
详见[HelperLib](https://github.com/SereinDev/HelperLib)
14-
159
## 优点
1610

1711
- 一键热重载,快速编写插件
18-
- [导入NET几乎所有的命名空间以及其对象、类、方法和属性](net)
12+
- [导入 NET 几乎所有的命名空间以及其对象、类、方法和属性](net)
1913

2014
:::tip
21-
配合一定C#基础食用更佳
15+
配合一定 C#基础食用更佳
2216

2317
C#语法详见 [.NET API 浏览器](https://learn.microsoft.com/zh-cn/dotnet/api/)
2418
:::
Lines changed: 35 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,46 @@
1-
# 内置模块
1+
# 使用模块
22

3-
为方便插件开发者使用,Serein按照NodeJs的风格内置了一些基本的函数
3+
除了被主动加载的文件(插件入口点),其他 Js 文件只能通过作为模块被读取和加载
44

5-
所有模块已默认导入到上下文中,所以你可以直接使用
5+
## 编写模块
66

7-
## `fs`
7+
使用 [`export`](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/export) 导出变量、函数、类
88

9-
```ts title="示例"
10-
fs.writeFileSync("1.txt", "Hello, World!");
11-
fs.copyFileSync("1.txt", "2.txt");
9+
```js title="Serein/plugins/test/myModule.js"
10+
// highlight-next-line
11+
import { test } from './anotherLib.js'
12+
13+
export const value = 114514;
14+
15+
export async function getPosts() {
16+
// ...
17+
}
18+
19+
export class Student {
20+
// ...
21+
}
22+
```
23+
24+
模块中可使用`import ... from '...'`导入其他模块
25+
26+
```js title="Serein/plugins/test/myModule.js"
27+
// highlight-next-line
28+
import { test } from './anotherLib.js'
1229
```
1330

14-
:::warning
31+
## 导入
1532

16-
- ~~因懒得实现`Buffer`~~,所有`Buffer`均使用`integer[]`代替,方便内部.NET代码转换
17-
- 只实现了部分同步函数,剩余的函数可能在未来补全
18-
- 没有进行过严格的测试,**其行为可能和NodeJs中的存在差异**
33+
在被加载的 JS 文件中,你可以通过 `require()` 函数导入其他模块中导出的内容
1934

20-
:::
35+
```ts
36+
require(file: string): any
37+
```
2138

22-
- [`appendFileSync(path: string, data: string, options?: string | object): void`](https://nodejs.org/docs/latest/api/fs.html#fsappendfilesyncpath-data-options)
23-
- [`appendFileSync(path: string, data: integer[], options?: string | object): void`](https://nodejs.org/docs/latest/api/fs.html#fsappendfilesyncpath-data-options)
24-
- [`closeSync(fd: integer): void`](https://nodejs.org/docs/latest/api/fs.html#fsclosesyncfd)
25-
- [`copyFileSync(src: string, dest: string, flags: integer = 0): void`](https://nodejs.org/docs/latest/api/fs.html#fscopyfilesyncsrc-dest-mode)
26-
- `flags != 1`时会覆盖原有文件(如果存在)
27-
- [`existsSync(path: string): boolean`](https://nodejs.org/docs/latest/api/fs.html#fsexistssyncpath)
28-
- [`fsyncSync(fd: integer)`](https://nodejs.org/docs/latest/api/fs.html#fsfsyncsyncfd)
29-
- [`ftruncateSync(fd: integer, len: integer = 0): void`](https://nodejs.org/docs/latest/api/fs.html#fsftruncatesyncfd-len)
30-
- [`futimesSync(fd: integer, atime: Date, mtime: Date): void`](https://nodejs.org/docs/latest/api/fs.html#fsfutimessyncfd-atime-mtime)
31-
- [`globSync(pattern: string, options?: object): string`](https://nodejs.org/docs/latest/api/fs.html#fsglobsyncpattern-options)
32-
- [`globSync(pattern: string[], options?: object): string`](https://nodejs.org/docs/latest/api/fs.html#fsglobsyncpattern-options)
33-
- [`mkdirSync(path: string, options?: object): void`](https://nodejs.org/docs/latest/api/fs.html#fsmkdirsyncpath-options)
34-
- `options.mode`仅在非Windows平台上生效,这与NodeJs中一致,下同
35-
- [`mkdirSync(path: string, options?: integer = 0o777): void`](https://nodejs.org/docs/latest/api/fs.html#fsmkdirsyncpath-options)
36-
- [`mkdtempSync(prefix: string, options?: object): string`](https://nodejs.org/docs/latest/api/fs.html#fsmkdtempsyncprefix-options)
37-
- [`openSync(path: string, flags: string, mode?: string | integer): integer`](https://nodejs.org/docs/latest/api/fs.html#fsopensyncpath-flags-mode)
38-
- `mode`总是会被忽略
39-
- [`readdirSync(path: string, options?: object): string[]`](https://nodejs.org/docs/latest/api/fs.html#fsreaddirsyncpath-options)
40-
- 仅有`options.recursive`会生效
41-
- [`readFileSync(path: string, options?: object): string`](https://nodejs.org/docs/latest/api/fs.html#fsreadfilesyncpath-options)
42-
- [`readSync(fd: integet, buffer: integer[], offset: integer, length: integer, position: integer = 0): integer`](https://nodejs.org/docs/latest/api/fs.html#fsreadsyncfd-buffer-offset-length-position)
43-
- [`renameSync(oldPath: string, newPath: string): void`](https://nodejs.org/docs/latest/api/fs.html#fsrenamesyncoldpath-newpath)
44-
- [`rmdirSync(path: string, options?: object): void`](https://nodejs.org/docs/latest/api/fs.html#fsrmdirsyncpath-options)
45-
- 仅有`options.recursive`会生效
46-
- [`rmSync(path: string, options?: object): void`](https://nodejs.org/docs/latest/api/fs.html#fsrmsyncpath-options)
47-
- 仅有`options.recursive`会生效
48-
- [`symlinkSync(target: string, path: string, type?: string): void`](https://nodejs.org/docs/latest/api/fs.html#fssymlinksynctarget-path-type)
49-
- `type`总是会被忽略
50-
- [`truncateSync(path: string, len: integer = 0): void`](https://nodejs.org/docs/latest/api/fs.html#fstruncatesyncpath-len)
51-
- [`unlinkSync(path: string): void`](https://nodejs.org/docs/latest/api/fs.html#fsunlinksyncpath)
52-
- 实际上是删除`path`
53-
- [`utimesSync(path: string, atime: Date, mtime: Date): void`](https://nodejs.org/docs/latest/api/fs.html#fsutimessyncpath-atime-mtime)
54-
- [`writeFileSync(path: string, data: string, options?: string | object): void`](https://nodejs.org/docs/latest/api/fs.html#fswritefilesyncpath-data-options)
55-
- [`writeFileSync(path: string, data: integer[], options?: string | object): void`](https://nodejs.org/docs/latest/api/fs.html#fswritefilesyncpath-data-options)
56-
- [`writeSync(fd: integer, buffer: integer[], offset: integer, length: integer, position: integer): integer`](https://nodejs.org/docs/latest/api/fs.html#fswritesyncfd-buffer-offset-length-position)
57-
- [`writeSync(fd: integer, data: string, position: integer = 0, encoding: string = 'utf8'): integer`](https://nodejs.org/docs/latest/api/fs.html#fswritesyncfd-buffer-offset-length-position)
39+
| 参数 | 类型 | 说明 |
40+
| ------ | -------- | ---------------------- |
41+
| `file` | `string` | 相对于被加载文件的路径 |
5842

59-
## `process`
43+
```js title="Serein/plugins/test/index.js"
6044

61-
- `arch: string`
62-
- 实际上只会返回`"x64"``"arm64"`,这是因为Serein的发行版没有x86的构建(
63-
- `argv: string[]`
64-
- `argv0: string`
65-
-`argv[0]`
66-
- `chdir(directory: string): string`
67-
- 不推荐使用此函数,否则可能**导致文件错位**
68-
- `cwd(): string`
69-
- `exit(code: integer = 0): void`
70-
- 不推荐使用此函数
71-
- `env: { [key: string]: string }`
72-
- `execPath: string`
73-
- `exitCode: integer`
74-
- `kill(pid: integer)`
75-
- `pid: integer`
76-
- `platform: string`
77-
- 实际上仅会返回`"win32nt"``"unix"``"other"`
78-
- `version: string`
79-
- 返回的是.NET运行时版本
45+
const { value, getPosts, Student } = require('./myModule.js')
46+
```

docs/development/plugins/net/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![dotnet](https://img.shields.io/badge/8.0-512BD4?style=for-the-badge&logo=.net)](https://dotnet.microsoft.com/zh-cn/download/dotnet/8.0)
44

5-
借助.NET的CLR可动态加载的特性实现插件的热插拔功能
5+
借助.NET 的 CLR 可动态加载的特性实现插件的热插拔功能
66

77
:::tip
88

@@ -13,7 +13,7 @@
1313
## 优点
1414

1515
- 运行速度快
16-
- 可以添加项目引用或[NuGet](https://www.nuget.org/)
16+
- 可以添加项目引用或 [NuGet](https://www.nuget.org/)
1717

1818
## 缺点
1919

docs/development/plugins/net/injection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 依赖服务注入
22

3-
在构造函数`.ctor`中填入需要的参数,在执行构造函数时会自动填充,类似于[Microsoft.Extensions.DependencyInjection](https://learn.microsoft.com/zh-cn/dotnet/api/microsoft.extensions.dependencyinjection?view=net-8.0)中的[`IServiceCollection`](https://learn.microsoft.com/zh-cn/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection?view=net-8.0)
3+
在构造函数 `.ctor` 中填入需要服务对象,在执行构造函数时会自动填充,类似于[Microsoft.Extensions.DependencyInjection](https://learn.microsoft.com/zh-cn/dotnet/api/microsoft.extensions.dependencyinjection?view=net-8.0)中的[`IServiceCollection`](https://learn.microsoft.com/zh-cn/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection?view=net-8.0)
44

55
:::note
66

0 commit comments

Comments
 (0)