模块开发指南之额外文件

pull/1/head
undefined 4 years ago
parent 874a776dbe
commit b6dce8a030

@ -1,4 +1,4 @@
# Basic # Basic
Hydro 后端使用 NodeJS 编写,前端使用 JQuery + React。 Hydro 后端使用 NodeJS 编写,前端使用 JQuery + React。
代码风格遵循 airbnb 标准。 代码风格遵循 airbnb 标准(详见 .eslintrc.js

@ -2,5 +2,7 @@
"basic", "basic",
"module", "module",
"handler", "handler",
"service" "service",
"file",
"template"
] ]

@ -0,0 +1,3 @@
# File
file 文件夹下的所有文件将被自动解压到 `$TMPDIR/hydro/模块ID/路径` 的位置权限755通常用于启动子进程

@ -33,7 +33,7 @@ async function apply() {
Route('/route/:username', module.exports.CustomHandler); 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) (如果存在) 再执行 prepare(args) (如果存在)
检查请求类型: 检查请求类型:
```
为 GET 为 GET
-> 执行 get(args) -> 执行 get(args)
为 POST ? 为 POST ?
-> 执行 post(args) -> 执行 post(args)
-> 含有 operation 字段? -> 含有 operation 字段?
-> 执行 post[Operation] -> 执行 post[Operation]
```
执行 cleanup() 执行 cleanup()
执行 _cleanup() 执行 _cleanup()
@ -86,3 +88,9 @@ args 为传入的参数集合(包括 QueryString, Body, Path中的全部参
* 在表单提交时的 operation 字段使用下划线,函数名使用驼峰命名。 * 在表单提交时的 operation 字段使用下划线,函数名使用驼峰命名。
`<input type="hidden" name="operation" value="confirm_delete">` 对应 `postConfirmDelete` 函数。 `<input type="hidden" name="operation" value="confirm_delete">` 对应 `postConfirmDelete` 函数。
应当提供 `apply` 函数,并与定义的 Handler 一同挂载到 `global.Hydro.handler[模块名]` 位置。
`apply` 函数将在初始化阶段被调用。
<blockquote class="note">请在 apply 函数中从 module.exports 引用,因为它们可能需要被其他模块修改。</blockquote>

@ -1,13 +1,23 @@
# Module # Module
## 文件架构
Hydro 的模块由以下几个部分组成: Hydro 的模块由以下几个部分组成:
service: 服务 service: 服务
script: 脚本 script: 脚本
handler: 访问路由 handler: 访问路由
lib: 库 lib: 库
model: 数据库模型
file: 额外文件 file: 额外文件
locale: 多国化 locale: 多国化
template: UI 模板 template: UI 模板
README.md: 介绍
hydro.json: 声明文件(必须)
## 模块编译
TODO 使用 `hydro-build` 进行编译。
安装:`yarn add hydro-build -D`
编译:`hydro-build`
如果命运的齿轮没有出差错,您应该可以找到生成的.hydro文件了。

@ -0,0 +1,3 @@
# README.md
项目的说明文件。

@ -0,0 +1,5 @@
# Template
页面模板。
TODO
Loading…
Cancel
Save