Skip to content

Commit 16b8ae3

Browse files
authored
Run configure.sh straight from download script (#17)
1 parent 1daa4bf commit 16b8ae3

3 files changed

Lines changed: 55 additions & 49 deletions

File tree

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99

1010
Template for Hummingbird App
1111

12-
Either click on `Use this template` or run the following to clone locally.
12+
Run the download script and follow the instructions.
13+
1314
```bash
14-
curl -L https://raw.githubusercontent.com/hummingbird-project/template/main/scripts/download.sh | bash -s <project-name>
15+
curl -L https://raw.githubusercontent.com/hummingbird-project/template/main/scripts/download.sh | bash
1516
```
1617

17-
Then enter the folder created, run `./configure.sh` and follow the instructions.
18-
1918
## Alternative method
2019

2120
Clone this repository locally

configure.sh

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,8 @@
1212
## SPDX-License-Identifier: Apache-2.0
1313
##
1414
##===----------------------------------------------------------------------===##
15-
PWD=$(pwd)
16-
TEMPLATE_FOLDER=$(dirname $0)
17-
RELATIVE_TARGET_FOLDER=${1:-}
18-
TARGET_FOLDER=$(cd "$(dirname "$RELATIVE_TARGET_FOLDER")"; pwd -P)/$(basename "$RELATIVE_TARGET_FOLDER")
19-
BASE_FOLDER=$(basename "$TARGET_FOLDER")
20-
CLEAN_BASE_FOLDER=$(echo "$BASE_FOLDER" | sed -e 's/[^a-zA-Z0-9_]/_/g')
21-
22-
TEMP_FOLDER=$(mktemp -d)
23-
MO="$TEMP_FOLDER"/mo
2415

25-
if [ "$TARGET_FOLDER" = "$PWD/" ]; then
26-
IN_PLACE_EDIT=true
27-
else
28-
IN_PLACE_EDIT=false
29-
fi
16+
TEMPLATE_FOLDER=$(dirname $0)
3017

3118
cleanup()
3219
{
@@ -43,7 +30,7 @@ download_mo()
4330

4431
read_input_with_default () {
4532
echo -n "[$1] > "
46-
read -r READ_INPUT_RETURN
33+
read -r READ_INPUT_RETURN </dev/tty
4734

4835
if [ -z "$READ_INPUT_RETURN" ]; then
4936
READ_INPUT_RETURN="$1"
@@ -61,7 +48,7 @@ yn_prompt () {
6148
read_yes_no () {
6249
while [[ true ]]; do
6350
echo -n "[$(yn_prompt $1)] > "
64-
read -r READ_INPUT_RETURN
51+
read -r READ_INPUT_RETURN </dev/tty
6552

6653
case "$READ_INPUT_RETURN" in
6754
"y" | "Y")
@@ -89,6 +76,7 @@ read_yes_no () {
8976
run_mustache()
9077
{
9178
FILES=$1
79+
TARGET_FOLDER=$2
9280
TEMP_FILE="$TEMP_FOLDER"/tempfile
9381
for FILE in $FILES; do
9482
$MO "$FILE" > "$TEMP_FILE"
@@ -98,11 +86,7 @@ run_mustache()
9886
rm "$TEMP_FILE"
9987
rm "$TARGET_FOLDER/$FILE"
10088
else
101-
if [ "$IN_PLACE_EDIT" = true ]; then
102-
echo "Updating $FILE"
103-
else
104-
echo "Copying $FILE"
105-
fi
89+
echo "Copying $FILE"
10690
mv -f "$TEMP_FILE" "$TARGET_FOLDER/$FILE"
10791
fi
10892
done
@@ -121,21 +105,42 @@ check_valid() {
121105
}
122106
trap cleanup EXIT $?
123107

124-
echo "Configuring your Hummingbird project"
125-
126108
# Download Bash Mustache
109+
TEMP_FOLDER=$(mktemp -d)
110+
MO="$TEMP_FOLDER"/mo
127111
download_mo
128112

129-
if [ "$IN_PLACE_EDIT" = false ]; then
130-
echo "Outputting to $TARGET_FOLDER"
131-
mkdir -p "$TARGET_FOLDER"/Sources/App
132-
mkdir -p "$TARGET_FOLDER"/Tests/AppTests
133-
mkdir -p "$TARGET_FOLDER"/.vscode
134-
mkdir -p "$TARGET_FOLDER"/.github/workflows
135-
else
136-
echo "Outputting to current folder"
113+
echo "Configuring your Hummingbird project"
114+
115+
RELATIVE_TARGET_FOLDER=${1:-}
116+
117+
# if no target folder is supplied ask for one
118+
if [[ -z "$RELATIVE_TARGET_FOLDER" ]]; then
119+
echo ""
120+
echo -n "Enter your folder name: "
121+
read_input_with_default "my-app"
122+
export RELATIVE_TARGET_FOLDER=$READ_INPUT_RETURN
123+
fi
124+
125+
# verify parent folder exists
126+
PARENT_FOLDER=$(dirname "$RELATIVE_TARGET_FOLDER")
127+
if [ ! -d "$PARENT_FOLDER" ]; then
128+
echo "$PARENT_FOLDER does not exist"
129+
exit -1
137130
fi
138131

132+
TARGET_FOLDER=$(cd "$(dirname "$RELATIVE_TARGET_FOLDER")"; pwd -P)/$(basename "$RELATIVE_TARGET_FOLDER")
133+
134+
echo "Outputting to $TARGET_FOLDER"
135+
mkdir -p "$TARGET_FOLDER"/Sources/App
136+
mkdir -p "$TARGET_FOLDER"/Tests/AppTests
137+
mkdir -p "$TARGET_FOLDER"/.vscode
138+
mkdir -p "$TARGET_FOLDER"/.github/workflows
139+
140+
# get base folder of target folder so we can use that as default app name
141+
BASE_FOLDER=$(basename "$TARGET_FOLDER")
142+
CLEAN_BASE_FOLDER=$(echo "$BASE_FOLDER" | sed -e 's/[^a-zA-Z0-9_\-]/_/g')
143+
139144
echo ""
140145
echo -n "Enter your Swift package name: "
141146
read_input_with_default "$CLEAN_BASE_FOLDER"
@@ -163,10 +168,10 @@ pushd $TEMPLATE_FOLDER > /dev/null
163168

164169
# Root level files
165170
FILES=$(find . -maxdepth 1 ! -type d ! -name "*.sh" ! -name LICENSE)
166-
run_mustache "$FILES"
171+
run_mustache "$FILES" "$TARGET_FOLDER"
167172
# Files in Sources and Tests folder
168173
FILES=$(find Sources Tests .github .vscode/hummingbird.code-snippets ! -type d)
169-
run_mustache "$FILES"
174+
run_mustache "$FILES" "$TARGET_FOLDER"
170175

171176
# README file
172177
cat <<EOF | $MO > "$TARGET_FOLDER"/README.md
@@ -177,8 +182,4 @@ EOF
177182
popd > /dev/null
178183

179184
echo ""
180-
if [ "$IN_PLACE_EDIT" = true ]; then
181-
echo "Run 'swift run' to build and run your server. Then open 'http://localhost:8080' in your web browser."
182-
else
183-
echo "Enter the folder $TARGET_FOLDER and run 'swift run' to build and run your server. Then open 'http://localhost:8080' in your web browser."
184-
fi
185+
echo "Enter the folder $TARGET_FOLDER and run 'swift run' to build and run your server. Then open 'http://localhost:8080' in your web browser."

scripts/download.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
#!/usr/bin/env bash
2-
FOLDER=${1:-}
32
TEMPLATE_VERSION=2.0.4
3+
TEMP_DIR=$(mktemp -d)
44

5-
if [[ -z "$FOLDER" ]]; then
6-
echo "Missing folder name"
7-
echo "Usage: download.sh <folder>"
8-
exit 1
9-
fi
5+
trap cleanup EXIT $?
106

11-
curl -sSL https://github.com/hummingbird-project/template/archive/refs/tags/"$TEMPLATE_VERSION".tar.gz | tar xvz -s /template-"$TEMPLATE_VERSION"/"$FOLDER"/
7+
cleanup()
8+
{
9+
if [ -n "$TEMP_DIR" ]; then
10+
rm -rf $TEMP_DIR
11+
fi
12+
}
13+
14+
# Run curl and extract to temp folder
15+
curl -sSL https://github.com/hummingbird-project/template/archive/refs/tags/"$TEMPLATE_VERSION".tar.gz | tar xvz -C $TEMP_DIR
16+
# Run configure.sh
17+
"$TEMP_DIR"/template-"$TEMPLATE_VERSION"/configure.sh

0 commit comments

Comments
 (0)