This commit is contained in:
2026-03-25 12:42:19 +01:00
commit 647d5537ff
18 changed files with 701 additions and 0 deletions

68
scripts/rename.sh Executable file
View File

@@ -0,0 +1,68 @@
#!/usr/bin/env bash
set -euo pipefail
# Renames the template plugin to your chosen name.
#
# Usage:
# ./scripts/rename.sh <snake_case_name> <ModuleName>
#
# Example:
# ./scripts/rename.sh billing_reports BillingReports
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <snake_case_name> <ModuleName>"
echo "Example: $0 billing_reports BillingReports"
exit 1
fi
SNAKE="$1"
MODULE="$2"
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
# Validate inputs
if ! echo "$SNAKE" | grep -qE '^[a-z][a-z0-9_]*$'; then
echo "Error: snake_case_name must match [a-z][a-z0-9_]*"
exit 1
fi
if ! echo "$MODULE" | grep -qE '^[A-Z][a-zA-Z0-9]*$'; then
echo "Error: ModuleName must start with uppercase and contain only alphanumeric characters"
exit 1
fi
echo "Renaming my_plugin -> $SNAKE, MyPlugin -> $MODULE"
# Rename directories
if [ -d "lib/my_plugin" ]; then
mv "lib/my_plugin" "lib/$SNAKE"
fi
if [ -d "lib/my_plugin_web" ]; then
mv "lib/my_plugin_web" "lib/${SNAKE}_web"
fi
if [ -d "test/my_plugin" ]; then
mv "test/my_plugin" "test/$SNAKE"
fi
# Replace in all text files
find . -type f \( -name '*.ex' -o -name '*.exs' -o -name '*.json' -o -name '*.js' -o -name '*.css' -o -name '*.md' -o -name '*.yml' -o -name '*.yaml' -o -name '.formatter.exs' \) -exec \
sed -i '' \
-e "s/my_plugin/$SNAKE/g" \
-e "s/MyPlugin/$MODULE/g" \
-e "s/my-plugin/$SNAKE/g" \
{} +
# Rename asset files
for ext in js css; do
if [ -f "assets/$ext/my_plugin.$ext" ]; then
mv "assets/$ext/my_plugin.$ext" "assets/$ext/$SNAKE.$ext"
fi
if [ -f "priv/static/my_plugin.$ext" ]; then
mv "priv/static/my_plugin.$ext" "priv/static/$SNAKE.$ext"
fi
done
echo "Done. Review the changes, then:"
echo " 1. Edit manifest.json — set description, capabilities"
echo " 2. Run: mix deps.get && mix test"