Initial commit
This commit is contained in:
68
hooks/README.md
Normal file
68
hooks/README.md
Normal file
@@ -0,0 +1,68 @@
|
||||
# Obsidian Plugin Builder Hooks
|
||||
|
||||
This directory contains hooks that automate common tasks during Obsidian plugin development.
|
||||
|
||||
## Available Hooks
|
||||
|
||||
### auto-format-typescript.json
|
||||
**Event**: PostToolUse (Write)
|
||||
**Purpose**: Automatically format TypeScript/TSX files after creation or modification
|
||||
**Pattern**: `**/*.{ts,tsx}`
|
||||
Runs Prettier on TypeScript files to maintain consistent code style.
|
||||
|
||||
### validate-manifest.json
|
||||
**Event**: PostToolUse (Write)
|
||||
**Purpose**: Validate manifest.json has required fields
|
||||
**Pattern**: `**/manifest.json`
|
||||
Checks for required fields: id, name, version, description, author.
|
||||
|
||||
### type-check-on-edit.json
|
||||
**Event**: PostToolUse (Edit)
|
||||
**Purpose**: Run TypeScript type checking after editing files
|
||||
**Pattern**: `**/*.{ts,tsx}`
|
||||
Finds the nearest tsconfig.json and runs type checking, reporting any errors.
|
||||
|
||||
### session-start-context.json
|
||||
**Event**: SessionStart
|
||||
**Purpose**: Inject Obsidian plugin development context at session start
|
||||
Reminds Claude about the Obsidian context and available example plugins.
|
||||
|
||||
### prevent-env-commit.json
|
||||
**Event**: PreToolUse (Bash)
|
||||
**Purpose**: Block git commands that would stage .env files
|
||||
**Pattern**: `*git add*`
|
||||
Prevents accidental commits of environment files containing secrets.
|
||||
|
||||
### sync-version-on-tag.json
|
||||
**Event**: PreToolUse (Bash)
|
||||
**Purpose**: Sync version across manifest.json and package.json before git tagging
|
||||
**Pattern**: `*git tag v*`
|
||||
Extracts version from tag and updates both files to keep them in sync.
|
||||
|
||||
## Requirements
|
||||
|
||||
Some hooks require additional tools:
|
||||
- `prettier` - For auto-formatting (install via `npm install -D prettier`)
|
||||
- `jq` - For JSON manipulation (usually pre-installed on macOS)
|
||||
- `tsc` - TypeScript compiler (comes with TypeScript installation)
|
||||
|
||||
## Disabling Hooks
|
||||
|
||||
To disable a hook temporarily, rename it with a `.disabled` extension:
|
||||
```bash
|
||||
mv auto-format-typescript.json auto-format-typescript.json.disabled
|
||||
```
|
||||
|
||||
## Custom Hooks
|
||||
|
||||
You can add your own hooks following the pattern:
|
||||
```json
|
||||
{
|
||||
"event": "PreToolUse|PostToolUse|SessionStart|etc",
|
||||
"tool": "Bash|Write|Edit|etc",
|
||||
"pattern": "glob pattern (optional)",
|
||||
"command": "bash command to execute"
|
||||
}
|
||||
```
|
||||
|
||||
See the [Claude Code Hooks documentation](https://docs.claude.com/en/docs/claude-code/hooks) for more details.
|
||||
6
hooks/auto-format-typescript.json
Normal file
6
hooks/auto-format-typescript.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"event": "PostToolUse",
|
||||
"tool": "Write",
|
||||
"pattern": "**/*.{ts,tsx}",
|
||||
"command": "npx prettier --write \"$FILE_PATH\" 2>&1"
|
||||
}
|
||||
6
hooks/prevent-env-commit.json
Normal file
6
hooks/prevent-env-commit.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"event": "PreToolUse",
|
||||
"tool": "Bash",
|
||||
"pattern": "*git add*",
|
||||
"command": "bash -c 'if echo \"$TOOL_INPUT\" | grep -q \"\\.env\"; then echo \"Blocked: .env files should not be committed\" && exit 1; fi'"
|
||||
}
|
||||
4
hooks/session-start-context.json
Normal file
4
hooks/session-start-context.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"event": "SessionStart",
|
||||
"command": "cat << 'EOF'\nWorking on Obsidian plugin development.\nReference docs: https://docs.obsidian.md\nEOF"
|
||||
}
|
||||
6
hooks/sync-version-on-tag.json
Normal file
6
hooks/sync-version-on-tag.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"event": "PreToolUse",
|
||||
"tool": "Bash",
|
||||
"pattern": "*git tag v*",
|
||||
"command": "bash -c 'VERSION=$(echo \"$TOOL_INPUT\" | grep -oP \"v\\K[0-9.]+\" || echo \"\"); if [ -n \"$VERSION\" ] && [ -f manifest.json ] && [ -f package.json ]; then jq --arg v \"$VERSION\" \".version = \\$v\" manifest.json > manifest.json.tmp && mv manifest.json.tmp manifest.json && jq --arg v \"$VERSION\" \".version = \\$v\" package.json > package.json.tmp && mv package.json.tmp package.json && echo \"Synced version $VERSION to manifest.json and package.json\"; fi'"
|
||||
}
|
||||
6
hooks/type-check-on-edit.json
Normal file
6
hooks/type-check-on-edit.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"event": "PostToolUse",
|
||||
"tool": "Edit",
|
||||
"pattern": "**/*.{ts,tsx}",
|
||||
"command": "bash -c 'cd \"$(dirname \"$FILE_PATH\")\" && while [ ! -f tsconfig.json ] && [ \"$(pwd)\" != \"/\" ]; do cd ..; done; if [ -f tsconfig.json ]; then npx tsc --noEmit 2>&1 || echo \"Type errors detected\"; fi'"
|
||||
}
|
||||
6
hooks/validate-manifest.json
Normal file
6
hooks/validate-manifest.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"event": "PostToolUse",
|
||||
"tool": "Write",
|
||||
"pattern": "**/manifest.json",
|
||||
"command": "bash -c 'jq -e \".id and .name and .version and .description and .author\" \"$FILE_PATH\" > /dev/null && echo \"manifest.json validated\" || (echo \"Error: manifest.json missing required fields\" && exit 1)'"
|
||||
}
|
||||
Reference in New Issue
Block a user