-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sh
executable file
·105 lines (93 loc) · 2 KB
/
build.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
#!/bin/bash
if [ ! -e node_modules ]
then
mkdir node_modules
fi
if [ -z ${USER_UID:+x} ]
then
export USER_UID=1000
export GROUP_GID=1000
fi
# options
SPRINGBOARD="recette"
for i in "$@"
do
case $i in
-s=*|--springboard=*)
SPRINGBOARD="${i#*=}"
shift
;;
*)
;;
esac
done
clean () {
rm -rf node_modules
rm -rf bundle
rm -rf dist
rm -f yarn.lock
}
init () {
BRANCH_NAME=`echo $GIT_BRANCH | sed -e "s|origin/||g"`
if [ "$BRANCH_NAME" = "" ]; then
echo "[init] Get branch name from git..."
BRANCH_NAME=`git branch | sed -n -e "s/^\* \(.*\)/\1/p"`
fi
echo "[init] Generate package.json from package.json.template..."
NPM_VERSION_SUFFIX=`date +"%Y%m%d%H%M"`
cp package.json.template package.json
sed -i "s/%generateVersion%/${NPM_VERSION_SUFFIX}/" package.json
sed -i "s/%branch%/${BRANCH_NAME}/" package.json
echo "[init] Install yarn dependencies..."
docker-compose run --rm -u "$USER_UID:$GROUP_GID" node sh -c "yarn install"
}
build () {
local extras=$1
docker-compose run --rm \
-u "$USER_UID:$GROUP_GID" \
-e EXTRAS=$extras \
node sh -c "pnpm run release:build"
}
watch () {
docker-compose run --rm \
-u "$USER_UID:$GROUP_GID" \
-v $PWD/../$SPRINGBOARD:/home/node/$SPRINGBOARD \
-e SPRINGBOARD=$SPRINGBOARD \
node sh -c "pnpm run dev:watch"
}
publish () {
LOCAL_BRANCH=`echo $GIT_BRANCH | sed -e "s|origin/||g"`
mkdir dist 2> /dev/null
mkdir dist/template 2> /dev/null
cp -R src/template/* cp -R dist/template/
cp -R bundle/* cp -R dist/
docker-compose run --rm -u "$USER_UID:$GROUP_GID" node sh -c "pnpm publish --no-git-checks --tag $LOCAL_BRANCH"
}
for param in "$@"
do
case $param in
clean)
clean
;;
init)
init
;;
build)
build
;;
install)
init && build "--springboard=../${SPRINGBOARD}"
;;
watch)
watch
;;
publish)
publish
;;
*)
echo "Invalid argument : $param"
esac
if [ ! $? -eq 0 ]; then
exit 1
fi
done