-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate.sh
More file actions
executable file
·34 lines (27 loc) · 1015 Bytes
/
migrate.sh
File metadata and controls
executable file
·34 lines (27 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Check if a file argument is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <file_path>"
exit 1
fi
file_path="$1"
# Check if file exists
if [ ! -f "$file_path" ]; then
echo "Error: File '$file_path' does not exist"
exit 1
fi
# Perform the replacements in-place
# Using a temporary file for safety and better sed compatibility
sed -E \
-e 's/className/class/g' \
-e 's/Link/a/g' \
-e 's/import \{ icons \} from "@\/lib\/icons"/import { icons } from "@\/lib\/icons"\nimport { Icon } from "astro-icon\/components"/g' \
-e 's/<Icon\.([A-Za-z0-9]+)([^>]*)>/<Icon name={icons.\1}\2>/g' \
-e 's/import Image from "next\/image"/import Image from "astro\/components\/Image.astro"/g' \
-e 's/{children}/<slot \/>/g' \
"$file_path" > "$file_path.tmp" && mv "$file_path.tmp" "$file_path"
# If file ends with .tsx, rename it to .astro
if [[ "$file_path" == *.tsx ]]; then
mv "$file_path" "${file_path%.tsx}.astro"
fi
echo "Replacements completed successfully"