Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Deno #48

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f341003
chore: Update imports for deno
YDX-2147483647 Nov 5, 2023
2105d8c
refactor: jsdom → deno-dom
YDX-2147483647 Nov 5, 2023
902f3bc
chore: Update imports for deno
YDX-2147483647 Nov 5, 2023
48aeb4f
refactor: Drop node-fetch
YDX-2147483647 Nov 5, 2023
374e136
chore: Update `launch.json` for deno
YDX-2147483647 Nov 5, 2023
ee4bfcf
test: Use deno
YDX-2147483647 Nov 6, 2023
d846277
build: Map std imports
YDX-2147483647 Nov 6, 2023
ae714df
style: `deno fmt src. *.md */*.json`
YDX-2147483647 Nov 6, 2023
01d731b
lint: `deno lint src`
YDX-2147483647 Nov 6, 2023
db2c100
chore: Drop unused dependencies
YDX-2147483647 Nov 6, 2023
805ed0f
chore: Install virtual-BIT-network from npm instead of GitHub
YDX-2147483647 Nov 6, 2023
d2d2a5e
chore: Vendor virtual-BIT-network
YDX-2147483647 Nov 6, 2023
f51fa78
chore: Update imports for deno
YDX-2147483647 Nov 6, 2023
51a69e7
test: Use deno
YDX-2147483647 Nov 6, 2023
5df28df
style: `deno fmt`
YDX-2147483647 Nov 6, 2023
4332010
lint
YDX-2147483647 Nov 6, 2023
a48d1d2
lint: `deno check`
YDX-2147483647 Nov 6, 2023
2d069da
chore: Prepend imports with `npm:`
YDX-2147483647 Nov 7, 2023
e3c3c5b
refactor: Drop cheerio
YDX-2147483647 Nov 8, 2023
8b17e8a
chore: Update imports for deno
YDX-2147483647 Nov 8, 2023
613dc59
refactor: check-sources-urls
YDX-2147483647 Nov 8, 2023
5b49a52
Merge branch 'main' into deno
YDX-2147483647 Nov 8, 2023
7c881bb
chore: Drop useless configurations
YDX-2147483647 Nov 8, 2023
5dfc656
refactor: Remove `node:process'
YDX-2147483647 Nov 8, 2023
667dceb
refactor: Drop `node:fs` APIs
YDX-2147483647 Nov 8, 2023
5f51990
chore: `npm run` → `deno task`
YDX-2147483647 Nov 8, 2023
c7725e4
Merge branch 'main' into deno
YDX-2147483647 Nov 10, 2023
2668607
Merge branch 'main' into deno
YDX-2147483647 Dec 7, 2023
2d639a6
Merge branch 'main' into deno
YDX-2147483647 Dec 11, 2023
eb04086
style: `deno task fmt`
YDX-2147483647 Dec 12, 2023
90286e6
refactor: `fetch` → `ky`
YDX-2147483647 Dec 12, 2023
89fd771
refactor: `Deno.errors.TimedOut` → `ky.TimeoutError`
YDX-2147483647 Dec 12, 2023
9e6458c
feat(plugin): Retry after timeout
YDX-2147483647 Dec 12, 2023
366ab51
Merge pull request #53 from YDX-2147483647/ky
YDX-2147483647 Dec 17, 2023
64617d9
Merge branch 'main' into deno
YDX-2147483647 Dec 19, 2023
8e938f5
feat(cli): Catch HTTPError
YDX-2147483647 Dec 25, 2023
e2d30d0
style: `deno task fmt`
YDX-2147483647 Dec 25, 2023
d5a2b3c
Merge branch 'main' into deno
YDX-2147483647 Mar 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .eslintrc.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"recommendations": [
"redhat.vscode-yaml",
"dbaeumer.vscode-eslint"
"denoland.vscode-deno"
]
}
}
29 changes: 11 additions & 18 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
{
// 使用 IntelliSense 了解相关属性。
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Build and Launch Program",
"program": "${file}",
"preLaunchTask": "npm: build-dev",
"console": "integratedTerminal",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}",
"console": "integratedTerminal",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
},
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": [
"run",
"--inspect-wait",
"--allow-all"
],
"attachSimplePort": 9229
}
]
}
}
14 changes: 7 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"cSpell.words": [
"typedoc"
],
"typescript.tsdk": "node_modules\\typescript\\lib",
"yaml.schemas": {
"config/config.schema.json": "config/config.yml",
"config/ding.secrets.schema.json": "config/ding.secrets.yaml"
},
"typescript.format.insertSpaceBeforeFunctionParenthesis": true,
"typescript.format.insertSpaceAfterConstructor": true
}
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
},
"deno.enable": true,
"deno.lint": true,
"deno.unstable": false
}
51 changes: 11 additions & 40 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,12 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "build",
"group": "build",
"problemMatcher": [],
"label": "npm: build"
},
{
"type": "npm",
"script": "build-dev",
"group": "build",
"problemMatcher": [],
"label": "npm: build-dev"
},
{
"type": "npm",
"script": "update",
"problemMatcher": [],
"label": "npm: update",
"detail": "Update notices. (plugin/cli)"
},
{
"type": "npm",
"script": "doc",
"problemMatcher": [],
"label": "npm: doc",
"detail": "typedoc"
},
{
"type": "npm",
"script": "test",
"group": "test",
"problemMatcher": [],
"label": "npm: test",
"detail": "tsc && mocha dist/**/*.test.js"
}
]
}
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "update",
"problemMatcher": [],
"label": "npm: update",
"detail": "Update notices. (plugin/cli)"
}
]
}
22 changes: 11 additions & 11 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
- 分工
- `core`只涉及核心功能,不考虑命令行界面等,不能引用任何`plugin`。
- `util`尽量为纯函数,可单独测试,不能引用`core`或`plugin`。

- 配置文件
- `core`内部模块不引入配置文件,而是把选项设计为参数。

- 在最表层引入配置文件。

- 配置文件(理论上)可被命令行参数替代。

- `plugin`可以向配置文件中添加自己的键,但仍用`core`读取`config`。

```yaml
# config.yml
ding: # plugin/ding 的配置
secrets_path: config/ding.secrets.yaml
```

配置的具体规定目前只加入`config/config.schema.json`,不加入`src/core/config.ts`。

- `core`中钩子
- `core`内部模块通过参数`_hook`传入`hook`。
- 在最表层`new Hook.Collection<HooksType>()`,并向外暴露`hook.api`。

- 尽量模块化
- 隐藏模块内细节:`core`中每个文件夹都有`index.ts`,外部一律引用它。

Expand Down Expand Up @@ -163,11 +163,11 @@ type HooksType = {
}
}

function _foo (options: FooOptions): FooResult {
function _foo(options: FooOptions): FooResult {
// …
}

export function foo ({ _hook, ...options }: {
export function foo({ _hook, ...options }: {
_hook: HookCollection<HooksType>
} & FooOptions): Promise<FooResult> {
return _hook('foo', _foo, options)
Expand All @@ -184,7 +184,7 @@ _hook.before('fetch', before_hook)

await foo({
...options,
_hook
_hook,
})
```

Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,23 @@ npm run update

注:如果你不知道怎么提拉取请求(pull request),不妨直接新建[议题(issue)](https://github.com/YDX-2147483647/bulletin-issues-transferred/issues/new/choose)。

- 写明名称、网址、同学该如何找到它等等。
- 写明名称、网址、同学该如何找到它等等。

这些内容写在`config/sources_by_selectors.json`中,详细规则见同文件夹的`*.schema.json`。
这些内容写在`config/sources_by_selectors.json`中,详细规则见同文件夹的`*.schema.json`。

其实也不用太研究那个 JSON Schema,只要看一下现有的`sources_by_selectors.json`,结合 VS Code 的语法提示,照猫画虎就行了。
其实也不用太研究那个 JSON Schema,只要看一下现有的`sources_by_selectors.json`,结合 VS Code 的语法提示,照猫画虎就行了。

- 描述如何从这个来源获取通知。
- 描述如何从这个来源获取通知。

目前有两类方法:
目前有两类方法:

- 先获取通知列表的静态网页,然后用 CSS 选择器从中提取信息。
- 先获取通知列表的静态网页,然后用 CSS 选择器从中提取信息。

CSS 选择器写在`config/sources_by_selectors.json`中。
CSS 选择器写在`config/sources_by_selectors.json`中。

- 利用学校的 API。
- 利用学校的 API。

在`src/core/sources/special.ts`中的`raw_sources: SourceSpecialInterface[]`里。
在`src/core/sources/special.ts`中的`raw_sources: SourceSpecialInterface[]`里。

### 移植到别的学校

Expand All @@ -122,22 +122,22 @@ npm run update

## 这合法吗?

- 绝对不涉密
- 绝对不涉密

> 上网不涉密,涉密不上网。
> 上网不涉密,涉密不上网。

我们只获取无需登录就能访问到的通知。一般人用搜索引擎都能找到这些页面,只是比较麻烦。
我们只获取无需登录就能访问到的通知。一般人用搜索引擎都能找到这些页面,只是比较麻烦。

- 不侵犯版权
- 不侵犯版权

(且不论通知有没有版权)我们只获取通知的标题,并且会给出原链接。
(且不论通知有没有版权)我们只获取通知的标题,并且会给出原链接。

- 基本不会给学校服务器造成压力
- 基本不会给学校服务器造成压力

如[前](#添加别的通知来源)所述,获取通知不会频繁访问学校网站,一个普通人在学校网上乱点造成的压力可能都比这个项目的大。
如[前](#添加别的通知来源)所述,获取通知不会频繁访问学校网站,一个普通人在学校网上乱点造成的压力可能都比这个项目的大。

另外,这个项目也许会方便一些同学找通知,避免在学校网上乱翻,从而可能减小学校服务器的压力。
另外,这个项目也许会方便一些同学找通知,避免在学校网上乱翻,从而可能减小学校服务器的压力。

- 原理基于公开内容
- 原理基于公开内容

CSS 选择器只是描述学校网页,API 是搜索学校网页源代码得到的。这些内容都在 Web 前端,是公开的。
CSS 选择器只是描述学校网页,API 是搜索学校网页源代码得到的。这些内容都在 Web 前端,是公开的。
15 changes: 13 additions & 2 deletions config/config.schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "config.schema.json-v0.3.1",
"$id": "config.schema.json-v0.3.2",
"title": "Bulletin IT 设置",
"type": "object",
"properties": {
Expand Down Expand Up @@ -77,6 +77,17 @@
"output_path"
]
},
"retry": {
"title": "超时后重试插件",
"type": "object",
"properties": {
"delay": {
"title": "超时后等待的毫秒数",
"type": "number",
"default": 10000
}
}
},
"proxy": {
"title": "虚拟校园网插件",
"type": "object",
Expand All @@ -103,4 +114,4 @@
]
}
}
}
}
4 changes: 2 additions & 2 deletions config/ding.secrets.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"description": "以“https://oapi.dingtalk.com”开头。"
},
"secret": {
"type":"string",
"type": "string",
"title": "加密用签名",
"description": "安全设置→加签,以“SEC”开头。"
}
Expand All @@ -20,4 +20,4 @@
"webhook",
"secret"
]
}
}
2 changes: 1 addition & 1 deletion config/proxy.secrets.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"username",
"password"
]
}
}
2 changes: 1 addition & 1 deletion config/sources_by_selectors.json
Original file line number Diff line number Diff line change
Expand Up @@ -654,4 +654,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion config/sources_by_selectors.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@
}
}
}
}
}
37 changes: 37 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"tasks": {
"fmt": "deno fmt --ignore=docs/,output/,package.json,package-lock.json",
"doc": "deno doc --html --name='Bulletin Issues Transferred' src/core/index.ts",
"check-sources-urls": "deno run --allow-env --allow-net --allow-read=config/sources_by_selectors.json scripts/check_sources_urls.ts",
"update": "deno run --allow-env=NODE_ENV --allow-net --allow-read --allow-write=output/ --allow-sys=osRelease src/examples/cli.ts",
"update-ding": "deno run --allow-env=NODE_ENV --allow-net --allow-read --allow-write=output/ --allow-sys=osRelease src/examples/ding-cli.ts",
"update-rss": "deno run --allow-env=NODE_ENV --allow-net --allow-read --allow-write=output/ --allow-sys=osRelease src/examples/rss-cli.ts",
"update-proxy": "deno run --allow-env=NODE_ENV --allow-net --allow-read --allow-write=output/ --allow-sys=osRelease src/examples/proxy-cli.ts",
"update-server": "deno run --allow-env=NODE_ENV --allow-net --allow-read --allow-write=output/ --allow-sys=osRelease src/examples/server-cli.ts",
"update-server-ding": "deno run --allow-env=NODE_ENV --allow-net --allow-read --allow-write=output/ --allow-sys=osRelease src/examples/server-ding-cli.ts"
},
"imports": {
"std/": "https://deno.land/[email protected]/",
"ky": "https://esm.sh/[email protected]",
"npm:aes-js": "npm:aes-js@^3.1.2",
"npm:before-after-hook": "npm:before-after-hook@^2.2.2",
"npm:chalk": "npm:chalk@^5.3.0",
"npm:cli-progress": "npm:cli-progress@^3.9.1",
"npm:inquirer": "npm:inquirer@^9.2.11",
"npm:terminal-image": "npm:terminal-image@^2.0.0",
"npm:winston": "npm:winston@^3.8.1",
"npm:xml": "npm:xml@^1.0.1",
"npm:yaml": "npm:yaml@^2.2.2"
},
"fmt": {
"singleQuote": true,
"semiColons": false,
"indentWidth": 4,
"proseWrap": "preserve"
},
"lint": {
"include": [
"src/"
]
}
}
Loading