Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:30:02 +08:00
commit 0df90b9bdc
29 changed files with 2639 additions and 0 deletions

68
hooks/README.md Normal file
View 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.

View File

@@ -0,0 +1,6 @@
{
"event": "PostToolUse",
"tool": "Write",
"pattern": "**/*.{ts,tsx}",
"command": "npx prettier --write \"$FILE_PATH\" 2>&1"
}

View 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'"
}

View File

@@ -0,0 +1,4 @@
{
"event": "SessionStart",
"command": "cat << 'EOF'\nWorking on Obsidian plugin development.\nReference docs: https://docs.obsidian.md\nEOF"
}

View 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'"
}

View 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'"
}

View 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)'"
}