You've already forked tribes-plugin-template
88 lines
2.1 KiB
Bash
Executable File
88 lines
2.1 KiB
Bash
Executable File
#!/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 (portable across GNU/BSD sed)
|
|
sed_in_place() {
|
|
file=$1
|
|
|
|
if sed --version >/dev/null 2>&1; then
|
|
sed -i \
|
|
-e "s/my_plugin/$SNAKE/g" \
|
|
-e "s/MyPlugin/$MODULE/g" \
|
|
-e "s/my-plugin/$SNAKE/g" \
|
|
"$file"
|
|
else
|
|
sed -i '' \
|
|
-e "s/my_plugin/$SNAKE/g" \
|
|
-e "s/MyPlugin/$MODULE/g" \
|
|
-e "s/my-plugin/$SNAKE/g" \
|
|
"$file"
|
|
fi
|
|
}
|
|
|
|
while IFS= read -r -d '' file; do
|
|
sed_in_place "$file"
|
|
done < <(
|
|
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' \) \
|
|
-print0
|
|
)
|
|
|
|
# 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"
|