-
Notifications
You must be signed in to change notification settings - Fork 0
/
apifork
98 lines (93 loc) · 2.65 KB
/
apifork
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
#!/bin/bash
# CONTRIBUTION
## Author: Tom Sapletta
## Created Date: 26.05.2022
## EXAMPLE
# ./apifork.sh install
# ./apifork.sh update
# ./apifork.sh remove
# CONFIG
CMD=$1
[ -z "$CMD" ] && CMD="install"
#
DSL_HASH="#"
CONFIG_FILE=".apifork"
CONFIG_DEFAULT="apifork.txt"
CONFIG_DEV="apifork.dev.txt"
CONFIG_TEST="apifork.test.txt"
if [ "$CMD" == "-h" ] || [ "$CMD" == "--help" ]; then
echo "set config for:"
echo "init - the default config, for customers"
echo "dev - development packages, for contributors and developers"
echo "test - for testing the project"
echo ""
echo "git repositories:"
echo "install - clone and build"
echo "clone"
echo "update"
echo "build"
echo "remove"
echo ""
exit
fi
if [ "$CMD" == "init" ]; then
echo -n "$CONFIG_DEFAULT" > "$CONFIG_FILE"
exit
fi
if [ "$CMD" == "dev" ]; then
echo -n "$CONFIG_DEV" > "$CONFIG_FILE"
exit
fi
if [ "$CMD" == "test" ]; then
echo -n "$CONFIG_TEST" > "$CONFIG_FILE"
exit
fi
#
PROJECT_LIST=$2
[ -z "$PROJECT_LIST" ] && [ -f "$CONFIG_FILE" ] && PROJECT_LIST=$(cat "$CONFIG_FILE")
[ -z "$PROJECT_LIST" ] && PROJECT_LIST="$CONFIG_DEFAULT"
PROJECT_PATH=$(pwd)
echo $PROJECT_PATH
BUILD="pwd"
APIBUILD="./apibuild"
APIFORK_BUILD="pwd"
APIFORK_BUILD="./apifork install"
APIFORK_UPDATE="./apifork update"
BUILD_PHP="composer update"
BUILD_NODEJS="npm update"
BUILD_PYTHON="python"
BUILD_JAVA="mvn clean package"
BUILD_APIFORK="./apifork install"
# START
# If the last line of your file has no newline on the end
while git_repo=; IFS=$' \t\r\n' read -r git_repo || [[ $git_repo ]]; do
repo=($git_repo)
# Comments
[ "${repo:0:1}" == "${DSL_HASH}" ] && continue
# Empty line
[ -z "$repo" ] && continue
echo "$CMD PROJECT: ${repo[1]}/ FROM REPO: (${repo[0]})"
if [ "$CMD" == "install" ]; then
echo "${repo[1]}" >>.gitignore
git clone ${git_repo}
cd ${repo[1]}
[ "$(pwd)" == "${PROJECT_PATH}" ] && echo "!!! PROJECT ${repo[1]} NOT EXIST, PLEASE INSTALL FIRST " && continue
[ -f "composer.json" ] && ${BUILD_PHP}
[ -f "package.json" ] && ${BUILD_NODEJS}
elif [ "$CMD" == "update" ]; then
cd ${repo[1]}
[ "$(pwd)" == "${PROJECT_PATH}" ] && echo "!!! PROJECT ${repo[1]} NOT EXIST, PLEASE INSTALL FIRST " && continue
git pull
elif [ "$CMD" == "build" ]; then
cd ${repo[1]}
[ "$(pwd)" == "${PROJECT_PATH}" ] && echo "!!! PROJECT ${repo[1]} NOT EXIST, PLEASE INSTALL FIRST " && continue
[ -f "composer.json" ] && ${BUILD_PHP}
[ -f "package.json" ] && ${BUILD_NODEJS}
[ -f "apifork" ] && ${BUILD_APIFORK}
elif [ "$CMD" == "remove" ]; then
rm -rf ${repo[1]}
else
echo "Command $CMD is not recognized"
fi
cd ${PROJECT_PATH}
done <"$PROJECT_LIST"