-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.sh
executable file
·231 lines (170 loc) · 3.9 KB
/
cli.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/env bash
NODE_BIN=${NODE_BIN:-node_modules/.bin}
CONTAINER_NAME=${CONTAINER_NAME:-magic-localhost}
MAGIC_DIR=${MAGIC_DIR:-node_modules/magic-root}
MAGIC_BIN=${MAGIC_BIN:-node_modules/magic-root/bin}
NODEJS_SRC_FILES=${NODEJS_FILES:-"src/server"}
NODEJS_DIST_DIR=${NODEJS_DIST_DIR:-"dist"}
CLIENT_SRC_FILES=${CLIENT_SRC_FILES:-"src/client"}
DIST_DIR=${DIST_DIR:-dist}
function echo-start() {
echo "START: $@"
}
function echo-end() {
echo "FINISHED: $@"
}
function dev() {
echo-start "dev environment"
build-src
export NODE_ENV=development;
$NODE_BIN/nodemon \
--exec "$NODE_BIN/babel-node src/server/index.js" \
--watch ./src/server/
}
function build() {
echo-start "building $CONTAINER_NAME docker container"
docker build \
--tag $CONTAINER_NAME \
--build-arg NODE_ENV=production \
. # dot!
echo-end "building docker container"
}
function build-root() {
echo-start "building magic-root"
${MAGIC_DIR}/cli.sh docker-build
echo-end "building magic-root"
}
function build-src() {
build-express-dirs
}
function build-node-js() {
echo-start "building nodejs"
mkdir -p $DIST_DIR/
$NODE_BIN/babel \
--out-dir $NODEJS_DIST_DIR \
$NODEJS_SRC_FILES # order is important
echo-end "building nodejs"
}
function build-express-dirs() {
echo-start "copying express views and public dir"
mkdir -p $DIST_DIR/
cp -r \
src/client \
$DIST_DIR/
echo-end "copying express views and public dir"
}
function run() {
docker-rm
echo-start "docker container"
docker run \
--name $CONTAINER_NAME \
--detach \
--env DIST_DIR=$DIST_DIR \
--env SERVER_SRC_FILES=$NODEJS_SRC_FILES \
--env CLIENT_SRC_FILES=$CLIENT_SRC_FILES \
$CONTAINER_NAME
ip
}
function ip() {
echo-start "gather ip"
ip=$(python ./bin/ip.py $CONTAINER_NAME)
echo $ip > ./SERVER_IP
echo-end "container $CONTAINER_NAME started with ip: $ip"
}
function docker-rm() {
echo-start "delete docker container"
docker rm -f $CONTAINER_NAME
echo-end "delete docker container"
}
function lint() {
echo-start "lint tasks"
eslint
jade-lint
stylint
echo-end "linting"
}
function eslint() {
echo-start "eslint"
$NODE_BIN/eslint \
src
echo-end "eslint"
}
function eslint-fix() {
echo-start "lint-fix"
$NODE_BIN/eslint \
--fix \
src
echo-end "lint-fix"
}
function install() {
echo-start "install magic-root including devDependencies"
npm i --dev
echo-end "install magic-root including devDependencies"
}
function pug-lint() {
echo-start "pug-lint"
$NODE_BIN/pug-lint \
./src/client/views/*
echo-end "pug-lint"
}
function stylint() {
echo-start "stylint"
$NODE_BIN/stylint \
src/client/public/css
echo-end "stylint"
}
function clean() {
echo-start "cleaning up out dir"
rm -rf $DIST_DIR
echo-end "cleaning up"
}
function logs() {
echo-start "connecting to container logs: $CONTAINER_NAME"
docker logs --follow $CONTAINER_NAME
}
function debug() {
docker-rm
build
echo-start "connecting to container $CONTAINER_NAME"
docker run \
--interactive \
--tty \
--name "$CONTAINER_NAME" \
--entrypoint=sh "$CONTAINER_NAME"
}
function update() {
git pull
}
function status() {
git status
}
function help() {
echo "
make [task]
running make without task starts a dev env
dev - run dev environment
build-src - build express app
lint - eslint javascript sources
lint-fix - eslint and fix javascript sources
pug-lint - run pug-lint (html)
jade-lint - run pug-lint (html)
stylint - run stylint (css)
build - build docker container
run - run docker container
clean - remove build library and test files
debug - connect to a debug container
logs - tail the logs of the running container
clean - remove out dir
update - git pull
status - git status
docker-rm - remote docker container
"
}
if [ $1 ]
then
function=$1
shift
$function $@
else
help $@
fi