-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_component.sh
executable file
·104 lines (78 loc) · 2.18 KB
/
init_component.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# Parse command-line options
name=""
remote=""
namespace="cltl"
no_app=false
usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -n, --name <name> Name of the component"
echo " -r, --remote <remote> Remote repository URL (optional)"
echo " -s, --namespace <namespace>"
echo " Namespace to use for packages, 'cltl' by default (optional) "
echo " -a, --no-app Remove app specific code (py-app/) (optional)"
echo ""
echo "Example:"
echo ""
echo "$0 --name mycomponent --remote 'https://github.com/me/mycomponent.git' --namespace myproject"
echo ""
exit 1
}
while [[ $# -gt 0 ]]; do
case "$1" in
-n|--name) shift; name="$1" ;;
-r|--remote) shift; remote="$1" ;;
-s|--namespace) shift; namespace="$1" ;;
-a|--no-app) no_app=true ;;
*)
echo "Unknown option: $1" >&2
usage
;;
esac
shift
done
# Validate if required options are provided
if [ -z "$name" ]; then
usage
exit 1
fi
echo "Init repository for component $name in namespace $namespace with remote repository $remote"
# Remove app specific code
if [ "$no_app" = true ]; then
rm -rf py-app
fi
git add .
# Adjust namespace for modules
if [ "$namespace" != "cltl" ]; then
git mv src/cltl "src/$namespace"
git mv src/cltl_service "src/${namespace}_service"
fi
# Setup setup.py
sed -i '.bak' "s|https://github.com/leolani/cltl-template|$remote|g" setup.py
sed -i '.bak' "s/cltl[.]template/$namespace.$name/g" setup.py
sed -i '.bak' "s/cltl\([^.]*\)[.][*]/$namespace\1.*/g" setup.py
sed -i '.bak' "s/template/$name/g" setup.py
rm setup.py.bak
# Setup README
echo "# $name" > README.md
# Setup git
if [ -n "$remote" ]; then
echo "Setup remote repository to $remote"
git remote remove origin
git remote add origin $remote
if ! git ls-remote "$remote" &> /dev/null; then
echo "Remote repository $remote not found on on GitHub"
exit 1
fi
if git ls-remote "$remote" | grep -q "refs/heads"; then
echo "Remote repository $remote is not empty:"
git ls-remote
exit 1
fi
fi
git add .
git status
echo "Commit and push your changes with"
echo ""
echo "git push --set-upstream origin main"