-
Notifications
You must be signed in to change notification settings - Fork 0
/
jam
executable file
·210 lines (173 loc) · 4.91 KB
/
jam
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
#!/usr/bin/env bash
#
# collider.jam boot shell script
#
# Following steps are performed if needed:
# * check all necessary prerequisites (node, npm)
# * generate initial package.json
# * install collider.jam shell
# * run jam shell
#
# save command line
CMD_LINE=$@
# env
NODE="node"
NPM="npm"
JAM="jam"
JAM_MODULE="collider.jam"
BOOT_MODULE="collider-boot.mix"
# error codes
ERROR_NO_NODEJS=1
ERROR_INIT_FIRST=2
ERROR_PACKAGE_EXISTS=3
ERROR_NO_SHELL=4
ERROR_ALREADY_GENERATED=5
# === flags ===
# check node.js
NODE_FLAG=1
type "$NODE" >/dev/null 2>&1 || { unset NODE_FLAG; }
# check npm
NPM_FLAG=1
type "$NPM" >/dev/null 2>&1 || { unset NPM_FLAG; }
# check global collider.jam installation
GLOBAL_JAM_FLAG=1
type "$JAM" >/dev/null 2>&1 || { unset GLOBAL_JAM_FLAG; }
update_flags() {
# check package.json
if [ -f ./package.json ]; then
PACKAGE_FLAG=1
fi
# check node modules
if [ -d ./node_modules ]; then
MODULES_FLAG=1
fi
# check local collider.jam shell
if [ -d ./node_modules/$JAM_MODULE ]; then
JAM_PACKAGE_FLAG=1
fi
if [ -f ./node_modules/$JAM_MODULE/jam.js ]; then
JAM_SHELL_FLAG=1
fi
# check collider.jam
if [ -d ./node_modules/$COLLIDER ]; then
COLLIDER_FLAG=1
fi
}
help() {
echo '=== Welcome to collider.jam boot script! ==='
echo ''
echo 'Usage: ./jam'
echo ' ./jam <command>'
echo ' ./jam <command> <arguments...>'
echo ''
echo 'Available options are:'
echo ' init <bootstrap-template> - generate project using provided template'
echo ' install - install collider.jam shell globally'
echo ''
echo 'All other commands are routed to collider.jam shell when installed'
}
check_status() {
LAST=$?
if [ $LAST -ne 0 ]; then
echo "A problem occured during the execution (error #$LAST)"
exit $LAST
fi
}
install() {
echo 'Installing collider.jam shell globaly'
#$NPM install -g git+$JAM_REPO
$NPM install -g $JAM_REPO
check_status
}
init() {
NAME=$1
# check that no package.json present before generating a new one
if [[ $PACKAGE_FLAG ]]; then
echo "Error: package.json is already exists!"
echo "Can't init the project [$NAME]"
exit $ERROR_PACKAGE_EXISTS
fi
echo "Generating project [$NAME]"
echo -n 'Generating package.json...'
echo -e "{
\"name\": \"$NAME\",
\"version\": \"0.0.1\",
\"description\": \"collider.jam game project\",
\"keywords\": \"collider,jam,mod,game engine,game framework,game jam\",
\"scripts\": {
\"start\": \"node ./node_modules/$JAM_MODULE/jam.js\"
},
\"dependencies\": {
\"$JAM_MODULE\": \"https://github.com/invider/collider.jam.git\",
\"collider.mix\": \"https://github.com/invider/collider.mix.git\",
\"collider-boot.mix\": \"https://github.com/invider/collider-boot.mix.git\",
\"collider-dev.mix\": \"https://github.com/invider/collider-dev.mix.git\"
},
\"author\": \"\",
\"license\": \"MIT\"\n}" > package.json
echo 'Installing dependencies...'
$NPM install
echo `du -sh ./node_modules | cut -f 1`' of modules installed'
update_flags
bootstrap
}
bootstrap() {
# trim 'init' command from params
CMD_LINE=${CMD_LINE:4}
node ./node_modules/$JAM_MODULE/jam.js bootstrap $CMD_LINE
check_status
echo ''
echo '=== The project is ready! ==='
echo ''
echo "Type ./jam play"
echo ' or'
echo 'Type ./jam and then open http://localhost:9999 in browser'
}
cmd() {
update_flags
if [[ ! $JAM_SHELL_FLAG ]]; then
echo 'No collider.jam shell installed!'
exit $ERROR_NO_SHELL
fi
if [[ $1 = "init" ]]; then
echo 'it looks like the project is already generated!'
exit $ERROR_ALREADY_GENERATED
else
node ./node_modules/$JAM_MODULE/jam.js $CMD_LINE
fi
}
update_flags
if [[ ! $NODE_FLAG || ! $NPM_FLAG ]]; then
echo 'No Node.js found!'
echo 'You must install Node.js in order to use collider.jam shell!'
exit $ERROR_NO_NODEJS
fi
# generic commands always working from bootstrap script
if [[ $1 = "install" ]]; then
install
fi
if [[ ! $PACKAGE_FLAG ]]; then
echo 'No collider.jam project detected!'
if [[ $1 = "init" ]]; then
NAME="${PWD##*/}"
init $NAME
elif [[ $1 = "help" ]]; then
help
else
echo 'You must init the project first'
echo 'Try ./jam init'
exit $ERROR_INIT_FIRST
fi
else
if [[ ! $MODULES_FLAG || ! $JAM_PACKAGE_FLAG ]]; then
echo '[jam-starter] Modules missing!'
echo '[jam-starter] Installing dependencies... '
$NPM update
check_status
fi
if [[ ! $GLOBAL_JAM_FLAG ]]; then
echo "[jam-starter] no global collider.jam installation found!"
echo "[jam-starter] to install, type ./jam install"
fi
cmd $1
fi