-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_project.sh
executable file
·60 lines (50 loc) · 2.47 KB
/
new_project.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
#!/bin/bash
# exit when any command fails
set -e
if [[ $# -lt 2 ]]; then
echo "Usage: ./new_project.sh my.new.package ApplicationName" >&2
exit 2
fi
PACKAGE=$1
APPNAME=$2
SUBDIR=${PACKAGE//.//} # Replaces . with /
#app_dirs=("app/src/androidTest" "app/src/main" "app/src/test")
for n in $(find . -type d \( -path './app/src/androidTest' -or -path './app/src/main' -or -path './app/src/test' \) )
do
echo "Creating $n/kotlin/$SUBDIR"
mkdir -p $n/kotlin/$SUBDIR
echo "Moving files to $n/kotlin/$SUBDIR"
rm -rf $n/kotlin/$SUBDIR/*
mv $n/kotlin/blueprint/* $n/kotlin/$SUBDIR
echo "Removing old $n/kotlin/blueprint"
rm -rf mv $n/kotlin/blueprint
done
# Rename package and imports
echo "Renaming packages to $PACKAGE"
find ./ -type f -name "*.kt" -exec sed -i.bak "s/package blueprint/package $PACKAGE/g" {} \;
find ./ -type f -name "*.kt" -exec sed -i.bak "s/import blueprint/import $PACKAGE/g" {} \;
find ./ -type f -name "*.kt" -exec sed -i.bak "s/BlueprintApp/${APPNAME}App/g" {} \;
find ./ -name "BlueprintApp.kt" | sed "p;s/BlueprintApp/${APPNAME}App/" | tr '\n' '\0' | xargs -0 -n 2 mv
find ./ -type f -name "*.kt" -exec sed -i.bak "s/BlueprintTheme/${APPNAME}Theme/g" {} \;
find ./ -type f -name "*.kt" -exec sed -i.bak "s/BlueprintNavHost/${APPNAME}NavHost/g" {} \;
find ./ -name "BlueprintNavHost.kt" | sed "p;s/BlueprintNavHost/${APPNAME}NavHost/" | tr '\n' '\0' | xargs -0 -n 2 mv
find ./ -type f -name "*.kt" -exec sed -i.bak "s/BlueprintFlavor/${APPNAME}Flavor/g" {} \;
find ./ -name "BlueprintFlavor.kt" | sed "p;s/BlueprintFlavor/${APPNAME}Flavor/" | tr '\n' '\0' | xargs -0 -n 2 mv
find ./ -type f -name "*.kt" -exec sed -i.bak "s/BlueprintBuildType/${APPNAME}BuildType/g" {} \;
find ./ -name "BlueprintBuildType.kt" | sed "p;s/BlueprintBuildType/${APPNAME}BuildType/" | tr '\n' '\0' | xargs -0 -n 2 mv
# Gradle files
find ./ -type f -name "*.kts" -exec sed -i.bak "s/blueprint/$PACKAGE/g" {} \;
find ./ -type f -name "*.kts" -exec sed -i.bak "s/Blueprint/$APPNAME/g" {} \;
find ./ -type f -name "*.kt" -exec sed -i.bak "s/blueprint/$PACKAGE/g" {} \;
find ./ -type f -name "*.xml" -exec sed -i.bak "s/BlueprintApp/${APPNAME}App/g" {} \;
find ./ -type f -name "*.xml" -exec sed -i.bak "s/blueprint./${PACKAGE}./g" {} \;
find ./ -type f -name "*.xml" -exec sed -i.bak "s/Blueprint/$APPNAME/g" {} \;
echo "Cleaning up"
find . -name "*.bak" -type f -delete
rm -rf LICENSE README.md new_project.sh
rm -rf .git/
git init
git add --all
git commit -m 'init'
git tag -a 1.0 -m 'v1.0'
echo "Done!"