-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.sh
executable file
·48 lines (40 loc) · 1.06 KB
/
gen.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
#!/bin/bash
# A tool that generate rpc.js from etcd rpc.proto
# ./gen.sh -- generate rpc.js
# ./gen.sh update -- update dependencies and regenerate rpc.js
set -e
RUNDIR=$(dirname $0)
BASE_DIR=$RUNDIR/protos
function clone_repo {
local destination=$BASE_DIR/${1}
local repository_url=https://github.com/${2}.git
git clone $repository_url $destination
}
function update_repo {
for repo in googleapis etcd googleapis;do
git --git-dir=$BASE_DIR/$repo/.git pull origin master
done
}
function clone_all {
clone_repo googleapis googleapis/googleapis
clone_repo etcd coreos/etcd
clone_repo gogoprotobuf gogo/protobuf
}
function gen {
$RUNDIR/node_modules/.bin/pbjs -p ${BASE_DIR}/googleapis \
-p ${BASE_DIR} \
-p ${BASE_DIR}/gogoprotobuf \
-s proto \
-t $1 \
-e etcdserverpb \
${BASE_DIR}/etcd/etcdserver/etcdserverpb/rpc.proto > ${RUNDIR}/lib/pb/rpc.$1
}
if [ ! -d $BASE_DIR ]; then
mkdir $BASE_DIR
clone_all
else
if [ ! -z "$1" ] && [ 'update' = $1 ];then
update_repo
fi
fi
gen