forked from reergymerej/start
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.sh
executable file
·77 lines (57 loc) · 1.47 KB
/
main.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
#!/usr/bin/env bash
# echo "Let's start a project"
DESTINATION=$1
TEMPLATE=$2
if [ -z $DESTINATION ]; then
echo "What is the name of the new project?"
exit 1
fi
if [ $1 = "--version" ]; then
echo "1.2.0"
exit 0
fi
# echo " based on $TEMPLATE"
# Where are the templates stored?
# TODO: Make this configurable by reading from .rc.
TEMPLATE_DIR=~/.start-project/templates/
mkdir -p $TEMPLATE_DIR
# You need to specify the template.
if [ -z $TEMPLATE ]; then
echo "You must specify the template."
# list available
ls $TEMPLATE_DIR
exit 1
fi
# Can we find this template?
TEMPLATE_PATH=$TEMPLATE_DIR$TEMPLATE
if [ -d $TEMPLATE_PATH ]; then
# TODO: Separate destination path and basename.
if [ -z $DESTINATION ]; then
echo "What is the name of the new project?"
exit 1
else
# echo " called $DESTINATION."
if [ -d $DESTINATION ]; then
echo "$DESTINATION already exists."
exit 1
else
git clone $TEMPLATE_PATH $DESTINATION &>/dev/null
CLONE_RESULT=$?
if [ $CLONE_RESULT -ne 0 ]; then
echo "The template could not be cloned."
exit 1
else
cd $DESTINATION
# Replace the placeholders with the project name.
# TODO: Note dependency on Ag.
ag PROJECT_NAME -l | xargs sed -e "s/PROJECT_NAME/$DESTINATION/g" -i ''
# Remove Git evidence.
rm -rf .git
# echo "👍 Party on."
fi
fi
fi
else
echo "$TEMPLATE_PATH does not exist."
exit 1
fi