64 lines
2.0 KiB
Bash
Executable File
64 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Install Lyrebird Xcode file templates.
|
|
#
|
|
# Copies every .xctemplate under Sources/LyrebirdCLI/Resources/XcodeTemplates/ into
|
|
# ~/Library/Developer/Xcode/Templates/File Templates/Lyrebird/
|
|
#
|
|
# Equivalent to `lyrebird install-templates` once that binary is on PATH.
|
|
#
|
|
# After install, Xcode's New File dialog (⌘N) shows a "Lyrebird" section with
|
|
# the templates listed. No Xcode restart required — Xcode rescans on next ⌘N.
|
|
#
|
|
# Run from repo root:
|
|
# bash scripts/install-xcode-templates.sh
|
|
# bash scripts/install-xcode-templates.sh --dry-run # show actions only
|
|
#
|
|
# Uninstall via scripts/uninstall-xcode-templates.sh.
|
|
|
|
set -euo pipefail
|
|
|
|
DRY_RUN=false
|
|
case "${1:-}" in
|
|
--dry-run|-n) DRY_RUN=true ;;
|
|
"") ;;
|
|
*) echo "usage: $0 [--dry-run]" >&2; exit 2 ;;
|
|
esac
|
|
|
|
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
SRC="$REPO_ROOT/Sources/LyrebirdCLI/Resources/XcodeTemplates"
|
|
DEST="$HOME/Library/Developer/Xcode/Templates/File Templates/Lyrebird"
|
|
|
|
if [[ ! -d "$SRC" ]]; then
|
|
echo "error: source dir not found: $SRC" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Count templates being installed for the summary line.
|
|
COUNT=$(find "$SRC" -maxdepth 1 -type d -name "*.xctemplate" | wc -l | tr -d ' ')
|
|
if [[ "$COUNT" -eq 0 ]]; then
|
|
echo "error: no .xctemplate directories found under $SRC" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Installing $COUNT Lyrebird templates"
|
|
echo " from: $SRC"
|
|
echo " to: $DEST"
|
|
|
|
if [[ "$DRY_RUN" == "true" ]]; then
|
|
echo
|
|
echo "(dry-run — no changes made)"
|
|
find "$SRC" -maxdepth 1 -type d -name "*.xctemplate" -exec basename {} \; | sort | sed 's/^/ + /'
|
|
exit 0
|
|
fi
|
|
|
|
mkdir -p "$DEST"
|
|
|
|
# rsync with --delete so the destination is a faithful mirror of the repo's
|
|
# templates dir — stale templates removed by a `git rm` upstream get cleaned
|
|
# up on next install. Trailing slash on $SRC/ copies contents, not the dir.
|
|
rsync -a --delete "$SRC/" "$DEST/"
|
|
|
|
echo
|
|
echo "✓ Installed. Open Xcode → File → New → File from Template…"
|
|
echo " → scroll to the 'Lyrebird' section."
|