-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare_repository.sh
68 lines (54 loc) · 1.74 KB
/
prepare_repository.sh
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
######################################################################
#
######################################################################
FRAMEWORK_NAME="${1}"
PROJECT_DESTINATION="${2}"
OLD_FRAMEWORK_NAME="MyCoreUIFramework"
_usage() {
printf -- "Usage: %s FRAMEWORK_NAME PROJECT_DESTINATION" "${0}"
exit 1
}
_rename_filename() {
local file app_name rename
file="${1}"
if [[ "$file" != "*${OLD_FRAMEWORK_NAME}*" ]]
then
rename=$(echo "${file}" | sed -E "s/${OLD_FRAMEWORK_NAME}/${FRAMEWORK_NAME}/g")
mv "${file}" "${rename}" &> /dev/null
fi
}
_rename_file() {
local file app_name
file="${1}"
if [[ "${file}" != *.DS_Store ]] && [[ "${file}" != *.strings ]]
then
sed -Ei '' "s/${OLD_FRAMEWORK_NAME}/${FRAMEWORK_NAME}/g" "${file}"
fi
}
_main() {
cp -prf . "${PROJECT_DESTINATION}"
rm -rf "${PROJECT_DESTINATION}/.git"
rm -f "${PROJECT_DESTINATION}/README.md"
mv "${PROJECT_DESTINATION}/README_future.md" "${PROJECT_DESTINATION}/README.md"
rm "${PROJECT_DESTINATION}/prepare_repository.sh"
find "${PROJECT_DESTINATION}" | while read line
do
_rename_filename "${line}"
done
find "${PROJECT_DESTINATION}" -type f -print0 | while read -d $'\0' file;
do
_rename_file "${file}"
done
echo "Your project is ready at ${PROJECT_DESTINATION}"
open ${PROJECT_DESTINATION}
}
######################################################################
# main script
######################################################################
if [ "$#" -ne 2 ] ; then
_usage
fi
test ! "${FRAMEWORK_NAME}" && echo "please set FRAMEWORK_NAME" && _usage
test ! "${PROJECT_DESTINATION}" && echo "please set destination" && _usage
_main