-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp-create.sh
More file actions
executable file
·55 lines (50 loc) · 1.93 KB
/
app-create.sh
File metadata and controls
executable file
·55 lines (50 loc) · 1.93 KB
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
#!/bin/bash
#
# Copyright 2019 Markus Schwarz.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
if [ $# -ne 2 ]; then
echo " $0 EXISTING-TARGET-DIRECTORY APP-NAME"
echo "e.g.: $0 ~/importer-component importer"
exit 1
fi
TARGET_DIR=$1
NEW_APP_NAME=$2
SCRIPT_TEMPLATE_FOLDER=$(dirname $0)
if [ "$SCRIPT_TEMPLATE_FOLDER" = '.' ]; then
SCRIPT_TEMPLATE_FOLDER="$(pwd)" # current dir
fi
createFolderAndReplacePom() {
TARGET_FOLDER=$1
TEMPLATE_FOLDER="$TARGET_FOLDER"
if [ $# -eq 2 ]; then
TEMPLATE_FOLDER=$2
fi
[ -d "$TARGET_FOLDER" ] || mkdir "$TARGET_FOLDER"
sed "s/##APP_NAME##/${NEW_APP_NAME}/g" "$SCRIPT_TEMPLATE_FOLDER"/templates/"$TEMPLATE_FOLDER"/pom.xml > "$TARGET_FOLDER"/pom.xml
}
# https://github.com/koalaman/shellcheck/wiki/SC2103#use-a--subshell--to-avoid-having-to-cd-back
(
cd "$TARGET_DIR" || exit
createFolderAndReplacePom "${NEW_APP_NAME}"-blueprint-bom blueprint-bom
createFolderAndReplacePom .
createFolderAndReplacePom blueprint-parent
createFolderAndReplacePom modules
createFolderAndReplacePom docker
createFolderAndReplacePom docker/"$NEW_APP_NAME" docker-app
sed "s/##APP_NAME##/${NEW_APP_NAME}/g" "$SCRIPT_TEMPLATE_FOLDER"/templates/docker-app/Dockerfile > docker/"$NEW_APP_NAME"/Dockerfile
createFolderAndReplacePom spring-boot
createFolderAndReplacePom spring-boot/"$NEW_APP_NAME"-app spring-boot-app
cp -r "$SCRIPT_TEMPLATE_FOLDER"/templates/spring-boot-app/src spring-boot/"$NEW_APP_NAME"-app
)