rules/arkts/hooks.md
This file extends common/hooks.md with HarmonyOS-specific build and validation hooks.
# Build HAP package (global hvigor environment)
hvigorw assembleHap -p product=default
# Build with specific module
hvigorw assembleHap -p module=entry -p product=default
# Clean build
hvigorw clean
# Check project structure
hvigorw --version
# Install dependencies
ohpm install
# Update dependencies
ohpm update
Run hvigor build to check for ArkTS compilation errors:
{
"type": "PostToolUse",
"matcher": {
"tool": ["Edit", "Write"],
"filePath": ["**/*.ets", "**/*.ts"]
},
"hooks": [
{
"command": "hvigorw assembleHap -p product=default 2>&1 | tail -20",
"async": true,
"timeout": 60000
}
]
}
Validate permission and ability declarations:
{
"type": "PostToolUse",
"matcher": {
"tool": "Edit",
"filePath": "**/module.json5"
},
"hooks": [
{
"command": "echo '[HarmonyOS] module.json5 modified - verify permissions and abilities'",
"async": false
}
]
}
Reinstall dependencies:
{
"type": "PostToolUse",
"matcher": {
"tool": "Edit",
"filePath": "**/oh-package.json5"
},
"hooks": [
{
"command": "ohpm install 2>&1 | tail -10",
"async": true,
"timeout": 30000
}
]
}
Warn when code contains V1 state management decorators:
{
"type": "PreToolUse",
"matcher": {
"tool": ["Write", "Edit"],
"filePath": "**/*.ets"
},
"hooks": [
{
"command": "echo '[HarmonyOS] Reminder: Use @ComponentV2 / @Local / @Param - V1 decorators (@State, @Prop, @Link) are prohibited'"
}
]
}
After each implementation cycle, verify:
hvigorw assembleHap completes without errors.ets files@ohos.router imports in new or modified filesmodule.json5oh-package.json5