-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.sh
executable file
·74 lines (56 loc) · 2.86 KB
/
setup.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
69
70
71
72
73
74
#!/bin/bash
git_name=`git config user.name`;
git_email=`git config user.email`;
read -p "Author name ($git_name): " author_name
author_name=${author_name:-$git_name}
read -p "Author email ($git_email): " author_email
author_email=${author_email:-$git_email}
username_guess=${author_name//[[:blank:]]/}
username_guess="$(echo $username_guess | tr '[A-Z]' '[a-z]')"
read -p "Author GitHub username ($username_guess): " author_username
author_username=${author_username:-$username_guess}
current_directory=`pwd`
current_directory=`basename $current_directory`
read -p "Package Composer name ($current_directory): " package_name
package_name=${package_name:-$current_directory}
fullname_guess="$(echo $package_name | perl -pe 's/(^|-)./uc($&)/ge;s/-/ /g')"
read -p "Package full name ($fullname_guess): " package_fullname
package_fullname=${package_fullname:-$fullname_guess}
namespace_guess="$(echo $package_name | perl -pe 's/(^|-)./uc($&)/ge;s/-//g')"
read -p "Package PHP namespace ($namespace_guess): " package_php_namespace
package_php_namespace=${package_php_namespace:-$namespace_guess}
read -p "Package description: " package_description
echo
echo "----------------------------------------------------------------------"
echo -e "Author: $author_name ($author_email)"
echo -e " github.com/$author_username"
echo
echo -e "Name: $package_fullname"
echo -e "Description: $package_description"
echo -e "PHP: Tighten\\$package_php_namespace"
echo -e "Packagist: tightenco/$package_name"
echo "----------------------------------------------------------------------"
echo
echo "This script will replace the above values in all files in the project."
read -p "Are you sure you wish to continue? (Y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi
echo
LC_ALL=C find . -type f -exec sed -i '' -e "s/:author_name/$author_name/g" {} \;
LC_ALL=C find . -type f -exec sed -i '' -e "s/:author_username/$author_username/g" {} \;
LC_ALL=C find . -type f -exec sed -i '' -e "s/:author_email/$author_email/g" {} \;
LC_ALL=C find . -type f -exec sed -i '' -e "s/:package_name/$package_name/g" {} \;
LC_ALL=C find . -type f -exec sed -i '' -e "s/:package_fullname/$package_name/g" {} \;
LC_ALL=C find . -type f -exec sed -i '' -e "s/:package_description/$package_description/g" {} \;
LC_ALL=C find . -type f -exec sed -i '' -e "s/:package_php_namespace/$package_php_namespace/g" {} \;
mv src/Skeleton.php "src/${package_php_namespace}.php"
mv src/SkeletonFacade.php "src/${package_php_namespace}Facade.php"
mv src/SkeletonServiceProvider.php "src/${package_php_namespace}ServiceProvider.php"
mkdir -p .github/workflows
mv skeleton.workflow.yml ".github/workflows/tests.yml"
LC_ALL=C sed -i '' -e "/^\*\*Note:\*\* Replace/d" README.md
echo "Replaced all values and reset git directory, self destructing in 3... 2... 1..."
rm -- "$0"