-
Notifications
You must be signed in to change notification settings - Fork 0
/
appetizer.sh
executable file
·107 lines (88 loc) · 2.34 KB
/
appetizer.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
102
103
104
105
106
107
#/bin/sh
#This file is heavily inspired by nvm.sh at https://github.com/creationix/nvm/blob/master/nvm.sh
#directory of this file
if [ ! -d "$APPETIZER_DIR" ]; then
export APPETIZER_DIR=`dirname "${BASH_SOURCE[0]}"`
fi
appetizer()
{
#the action
ACTION="$1"
if [ ! "$ACTION" ]; then
ACTION="help"
fi
#the target directory to start all actions in
TARGET_DIR="$2"
if [ "$TARGET_DIR" ]; then
cd $TARGET_DIR
else
TARGET_DIR=`pwd`
fi
if [ "$ACTION" = "build" ]; then
ACTION="build_release"
fi
case $ACTION in
"build-release" )
if [ ! -d "$TARGET_DIR/build" ]; then
mkdir "$TARGET_DIR/build"
fi
rm -r "$TARGET_DIR/build"
mkdir "$TARGET_DIR/build"
node "$APPETIZER_DIR/lib/build.js" "$TARGET_DIR" release
;;
"build-debug" )
if [ ! -d "$TARGET_DIR/build" ]; then
mkdir "$TARGET_DIR/build"
fi
rm -r "$TARGET_DIR/build"
mkdir "$TARGET_DIR/build"
node "$APPETIZER_DIR/lib/build.js" "$TARGET_DIR" debug
;;
"start" )
node "$APPETIZER_DIR/lib/server.js" start "$TARGET_DIR"
if [ $? = 3 ]; then
echo "Trying again with sudo..."
sudo node "$APPETIZER_DIR/lib/server.js" start "$TARGET_DIR"
fi
;;
"stop" )
node "$APPETIZER_DIR/lib/server.js" stop "$TARGET_DIR"
;;
"make" )
if [ "$(ls $TARGET_DIR)" ]; then
while true; do
read -p "Directory not emty. Do you really want to make here? " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) return;;
* ) echo "Please answer yes or no.";;
esac
done
fi
cp "$APPETIZER_DIR/config.json" "$TARGET_DIR"
if [ ! -d "$TARGET_DIR/src" ]; then
mkdir "$TARGET_DIR/src"
fi
#make copies all template files to the target directory
cp -r "$APPETIZER_DIR"/template/* "$TARGET_DIR"
if [ ! -d "$TARGET_DIR/build" ]; then
mkdir "$TARGET_DIR/build"
fi
echo "Project made in $TARGET_DIR"
;;
"help" )
echo
echo "Appetizer"
echo
echo "Usage:"
echo " appetizer make Creates a project according to a template"
echo " appetizer start Start the development server"
echo " appetizer stop Stop the development server"
echo " appetizer build-debug Build all js and less files into the 'build' folder of the project. Keeps debugging code"
echo " appetizer build-release Like build-debug only it obfuscates all js en minifies the css"
;;
* )
appetizer help
;;
esac
}