Files
ai-proj-helper/sync-skills.sh

125 lines
3.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Sync local skills to marketplace plugins
# Usage: ./sync-skills.sh [marketplace-dir]
set -e
# Configuration
LOCAL_SKILLS_DIR="$HOME/.claude/skills"
MARKETPLACE_DIR="${1:-$(dirname "$0")}"
PLUGINS_DIR="$MARKETPLACE_DIR/plugins"
echo "🔄 Syncing skills to marketplace..."
echo "Source: $LOCAL_SKILLS_DIR"
echo "Target: $PLUGINS_DIR"
echo ""
# Check if local skills directory exists
if [ ! -d "$LOCAL_SKILLS_DIR" ]; then
echo "❌ Error: Local skills directory not found: $LOCAL_SKILLS_DIR"
exit 1
fi
# Track changes
new_count=0
updated_count=0
unchanged_count=0
# Loop through each local skill
for skill_dir in "$LOCAL_SKILLS_DIR"/*; do
# Skip non-directories and special files
if [ ! -d "$skill_dir" ] || [ "$(basename "$skill_dir")" = ".git" ]; then
continue
fi
# Skip registry.yaml if it exists as a directory
if [ "$(basename "$skill_dir")" = "registry.yaml" ]; then
continue
fi
skill_name=$(basename "$skill_dir")
plugin_name="${skill_name}-plugin"
plugin_dir="$PLUGINS_DIR/$plugin_name"
# Check if SKILL.md exists
if [ ! -f "$skill_dir/SKILL.md" ]; then
echo "⚠️ Skipping $skill_name (no SKILL.md)"
continue
fi
# Check if plugin already exists
if [ -d "$plugin_dir" ]; then
# Compare SKILL.md files
if diff -q "$skill_dir/SKILL.md" "$plugin_dir/skills/SKILL.md" > /dev/null 2>&1; then
echo "$skill_name (unchanged)"
((unchanged_count++))
else
echo "📝 $skill_name (updated)"
cp "$skill_dir/SKILL.md" "$plugin_dir/skills/"
((updated_count++))
fi
else
echo " $skill_name (new)"
# Create plugin directory structure
mkdir -p "$plugin_dir/.claude-plugin"
mkdir -p "$plugin_dir/skills"
# Copy SKILL.md
cp "$skill_dir/SKILL.md" "$plugin_dir/skills/"
# Extract description from SKILL.md frontmatter
description=$(grep "^description:" "$skill_dir/SKILL.md" | sed 's/^description: *//' | tr -d '\n\r')
if [ -z "$description" ]; then
description="Plugin for $skill_name"
fi
# Create plugin.json
cat > "$plugin_dir/.claude-plugin/plugin.json" << EOF
{
"name": "$plugin_name",
"description": "$description",
"version": "1.0.0",
"author": {
"name": "qiudl"
}
}
EOF
((new_count++))
fi
done
echo ""
echo "📊 Summary:"
echo " New: $new_count"
echo " Updated: $updated_count"
echo " Unchanged: $unchanged_count"
echo ""
# Regenerate marketplace.json if there are changes
if [ $new_count -gt 0 ] || [ $updated_count -gt 0 ]; then
echo "🔄 Regenerating marketplace.json..."
cd "$MARKETPLACE_DIR"
# Run the generate script if it exists
if [ -f "generate-marketplace.py" ]; then
python3 generate-marketplace.py
else
echo "⚠️ Warning: generate-marketplace.py not found, skipping marketplace.json regeneration"
fi
echo ""
echo "✅ Sync complete! Changes ready to commit."
echo ""
echo "Next steps:"
echo " cd $MARKETPLACE_DIR"
echo " git status"
echo " git add ."
echo " git commit -m 'Sync skills from local'"
echo " git push"
else
echo "✅ All plugins are up to date!"
fi