HarmonyOS / ArkTS 钩子¶
本文件使用 HarmonyOS 特有的构建和验证钩子扩展 common/hooks.md。
构建命令¶
构建 HAP 包¶
# HAP パッケージをビルドする(グローバル hvigor 環境)
hvigorw assembleHap -p product=default
# 特定のモジュールでビルドする
hvigorw assembleHap -p module=entry -p product=default
# クリーンビルド
hvigorw clean
DevEco Studio CLI¶
推荐的 PostToolUse 钩子¶
编辑 .ets/.ts 文件后¶
运行 hvigor 构建以检查 ArkTS 编译错误:
{
"type": "PostToolUse",
"matcher": {
"tool": ["Edit", "Write"],
"filePath": ["**/*.ets", "**/*.ts"]
},
"hooks": [
{
"command": "hvigorw assembleHap -p product=default 2>&1 | tail -20",
"async": true,
"timeout": 60000
}
]
}
编辑 module.json5 后¶
验证权限和 Ability 声明:
{
"type": "PostToolUse",
"matcher": {
"tool": "Edit",
"filePath": "**/module.json5"
},
"hooks": [
{
"command": "echo '[HarmonyOS] module.json5 modified - verify permissions and abilities'",
"async": false
}
]
}
编辑 oh-package.json5 后¶
重新安装依赖:
{
"type": "PostToolUse",
"matcher": {
"tool": "Edit",
"filePath": "**/oh-package.json5"
},
"hooks": [
{
"command": "ohpm install 2>&1 | tail -10",
"async": true,
"timeout": 30000
}
]
}
PreToolUse 钩子¶
V1 装饰器守卫¶
当代码中包含 V1 状态管理装饰器时发出警告:
{
"type": "PreToolUse",
"matcher": {
"tool": ["Write", "Edit"],
"filePath": "**/*.ets"
},
"hooks": [
{
"command": "echo '[HarmonyOS] Reminder: Use @ComponentV2 / @Local / @Param - V1 decorators (@State, @Prop, @Link) are prohibited'"
}
]
}
验证检查清单¶
每个实现周期后,确认以下事项:
- [ ]
hvigorw assembleHap无错误完成 - [ ] 新增或修改的
.ets文件中没有 V1 装饰器 - [ ] 新增或修改的文件中没有
@ohos.router导入 - [ ] 所有 API 权限都已在
module.json5中声明 - [ ] 所有依赖项都已在
oh-package.json5中列出 - [ ] 资源字符串已添加到所有 i18n 目录
- [ ] 新的颜色资源已提供深色主题颜色
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 ev/ECC