From e178663e5d8bc4a36a918234b4e7b11ce1fce38b Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sat, 29 Nov 2025 18:25:26 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 12 ++++++++++ README.md | 3 +++ hooks/hooks.json | 15 ++++++++++++ hooks/prettier-format.sh | 40 +++++++++++++++++++++++++++++++ plugin.lock.json | 49 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 hooks/hooks.json create mode 100755 hooks/prettier-format.sh create mode 100644 plugin.lock.json diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..ac871e1 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,12 @@ +{ + "name": "prettier-plugin", + "description": "Automatically formats files with Prettier after edits", + "version": "1.0.1", + "author": { + "name": "Eli Oshinsky", + "email": "elimelech.oshinsky@gmail.com" + }, + "hooks": [ + "./hooks" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..184040e --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# prettier-plugin + +Automatically formats files with Prettier after edits diff --git a/hooks/hooks.json b/hooks/hooks.json new file mode 100644 index 0000000..db6c68e --- /dev/null +++ b/hooks/hooks.json @@ -0,0 +1,15 @@ +{ + "hooks": { + "PostToolUse": [ + { + "matcher": "Edit|Write|MultiEdit", + "hooks": [ + { + "type": "command", + "command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/prettier-format.sh" + } + ] + } + ] + } +} diff --git a/hooks/prettier-format.sh b/hooks/prettier-format.sh new file mode 100755 index 0000000..bd10cb1 --- /dev/null +++ b/hooks/prettier-format.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Prettier hook for Claude Code (Plugin Mode) +# Formats files with prettier after edits and outputs JSON format + +# Source utilities +source "$(dirname "$0")/../../shared/hooks/utils.sh" + +# Helper function to output JSON and exit +output_json() { + echo "$1" + exit 0 +} + +# Read input from stdin +INPUT=$(cat) + +# Parse input and extract fields +if ! parse_hook_input "$INPUT"; then + output_json '{}' +fi + +# Check if project has local prettier hook override +if has_project_hook_override "$PROJECT_DIR" "prettier"; then + output_json '{}' +fi + +# Check if project has prettier configured +if ! has_prettier_config "$PROJECT_DIR"; then + output_json '{}' +fi + +# Get the appropriate package runner +PKG_RUNNER=$(get_package_runner) + +# Run prettier on the file (always succeed regardless of outcome) +cd "$PROJECT_DIR" && $PKG_RUNNER prettier --write "$FILE_PATH" >/dev/null 2>&1 + +# Always return empty JSON with success status +output_json '{}' diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..e782599 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,49 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:eli0shin/cli-lsp-client:claude-plugins/prettier-plugin", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "9afe13203d3486923f173a14e0c0755135d0d7e9", + "treeHash": "6cb1aec87d0eef19d0a3fbfdf463c7707abf17b1db18a25ccd593419be7785de", + "generatedAt": "2025-11-28T10:16:45.970996Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "prettier-plugin", + "description": "Automatically formats files with Prettier after edits", + "version": "1.0.1" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "d3ff5a0c255e8e36a5b6365e6ab44257abbd8fb9a80798e1e78f4b474a097a71" + }, + { + "path": "hooks/hooks.json", + "sha256": "a60661fe2fa430fa7e6d32c8e5149c8d0f89b85457218f14ba3f4ba634ec3dd6" + }, + { + "path": "hooks/prettier-format.sh", + "sha256": "75f349f1737bc51e07b7cb5bf740ffb62b768d90c71087e1e4e52d54a26a13eb" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "88e9f8a28c3b39c401c8559c84f138e25bfdb12f904ff20f0521311c23dea271" + } + ], + "dirSha256": "6cb1aec87d0eef19d0a3fbfdf463c7707abf17b1db18a25ccd593419be7785de" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file