mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
模块开发指南之额外文件
This commit is contained in:
1 parent
874a776dbe
commit
b6dce8a030
7 files changed
+39
-8
No files matched your search
@@ -1,4 +1,4 @@
|
||||
# Basic
|
||||
|
||||
Hydro 后端使用 NodeJS 编写,前端使用 JQuery + React。
|
||||
代码风格遵循 airbnb 标准。
|
||||
代码风格遵循 airbnb 标准(详见 .eslintrc.js)。
|
||||
@@ -2,5 +2,7 @@
|
||||
"basic",
|
||||
"module",
|
||||
"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);
|
||||
}
|
||||
|
||||
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 字段使用下划线,函数名使用驼峰命名。
|
||||
|
||||
如 `<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
|
||||
|
||||
## 文件架构
|
||||
|
||||
Hydro 的模块由以下几个部分组成:
|
||||
|
||||
service: 服务
|
||||
script: 脚本
|
||||
handler: 访问路由
|
||||
lib: 库
|
||||
model: 数据库模型
|
||||
file: 额外文件
|
||||
locale: 多国化
|
||||
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
|
||||
Reference in new issue
Block a user