From b6dce8a03081d79ce0c5dcfc5f2c11f638df758f Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 18 May 2020 18:40:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=BC=80=E5=8F=91=E6=8C=87?= =?UTF-8?q?=E5=8D=97=E4=B9=8B=E9=A2=9D=E5=A4=96=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/wiki/raw/development/basic.md | 2 +- module/wiki/raw/development/contents.json | 4 +++- module/wiki/raw/development/file.md | 3 +++ module/wiki/raw/development/handler.md | 18 +++++++++++++----- module/wiki/raw/development/module.md | 12 +++++++++++- module/wiki/raw/development/readme.md | 3 +++ module/wiki/raw/development/template.md | 5 +++++ 7 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 module/wiki/raw/development/file.md create mode 100644 module/wiki/raw/development/readme.md create mode 100644 module/wiki/raw/development/template.md diff --git a/module/wiki/raw/development/basic.md b/module/wiki/raw/development/basic.md index b140a5c8f..b31a35a4e 100644 --- a/module/wiki/raw/development/basic.md +++ b/module/wiki/raw/development/basic.md @@ -1,4 +1,4 @@ # Basic Hydro 后端使用 NodeJS 编写,前端使用 JQuery + React。 -代码风格遵循 airbnb 标准。 \ No newline at end of file +代码风格遵循 airbnb 标准(详见 .eslintrc.js)。 diff --git a/module/wiki/raw/development/contents.json b/module/wiki/raw/development/contents.json index 0e96a8feb..4c2610c37 100644 --- a/module/wiki/raw/development/contents.json +++ b/module/wiki/raw/development/contents.json @@ -2,5 +2,7 @@ "basic", "module", "handler", - "service" + "service", + "file", + "template" ] \ No newline at end of file diff --git a/module/wiki/raw/development/file.md b/module/wiki/raw/development/file.md new file mode 100644 index 000000000..1679674e1 --- /dev/null +++ b/module/wiki/raw/development/file.md @@ -0,0 +1,3 @@ +# File + +file 文件夹下的所有文件将被自动解压到 `$TMPDIR/hydro/模块ID/路径` 的位置(权限755,通常用于启动子进程)。 diff --git a/module/wiki/raw/development/handler.md b/module/wiki/raw/development/handler.md index 0424ad132..90c87af8d 100644 --- a/module/wiki/raw/development/handler.md +++ b/module/wiki/raw/development/handler.md @@ -33,7 +33,7 @@ async function apply() { Route('/route/:username', module.exports.CustomHandler); } -module.exports = { CustomHandler, apply }; +global.Hydro.handler.custom = module.exports = { CustomHandler, apply }; ``` 在路由中定义所有的函数应均为异步函数,支持的函数如下: @@ -71,12 +71,14 @@ args 为传入的参数集合(包括 QueryString, Body, Path)中的全部参 再执行 prepare(args) (如果存在) 检查请求类型: +``` 为 GET ? - -> 执行 get(args) + -> 执行 get(args) 为 POST ? - -> 执行 post(args) - -> 含有 operation 字段? - -> 执行 post[Operation] + -> 执行 post(args) + -> 含有 operation 字段? + -> 执行 post[Operation] +``` 执行 cleanup() 执行 _cleanup() @@ -86,3 +88,9 @@ args 为传入的参数集合(包括 QueryString, Body, Path)中的全部参 * 在表单提交时的 operation 字段使用下划线,函数名使用驼峰命名。 如 `` 对应 `postConfirmDelete` 函数。 + +应当提供 `apply` 函数,并与定义的 Handler 一同挂载到 `global.Hydro.handler[模块名]` 位置。 +`apply` 函数将在初始化阶段被调用。 + +
请在 apply 函数中从 module.exports 引用,因为它们可能需要被其他模块修改。
+ diff --git a/module/wiki/raw/development/module.md b/module/wiki/raw/development/module.md index 053c918db..80f32b702 100644 --- a/module/wiki/raw/development/module.md +++ b/module/wiki/raw/development/module.md @@ -1,13 +1,23 @@ # Module +## 文件架构 + Hydro 的模块由以下几个部分组成: service: 服务 script: 脚本 handler: 访问路由 lib: 库 +model: 数据库模型 file: 额外文件 locale: 多国化 template: UI 模板 +README.md: 介绍 +hydro.json: 声明文件(必须) -TODO \ No newline at end of file +## 模块编译 + +使用 `hydro-build` 进行编译。 +安装:`yarn add hydro-build -D` +编译:`hydro-build` +如果命运的齿轮没有出差错,您应该可以找到生成的.hydro文件了。 diff --git a/module/wiki/raw/development/readme.md b/module/wiki/raw/development/readme.md new file mode 100644 index 000000000..0dac92d71 --- /dev/null +++ b/module/wiki/raw/development/readme.md @@ -0,0 +1,3 @@ +# README.md + +项目的说明文件。 diff --git a/module/wiki/raw/development/template.md b/module/wiki/raw/development/template.md new file mode 100644 index 000000000..73676252b --- /dev/null +++ b/module/wiki/raw/development/template.md @@ -0,0 +1,5 @@ +# Template + +页面模板。 + +TODO \ No newline at end of file