forked from Tencent/wepy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·119 lines (88 loc) · 2.32 KB
/
bootstrap.sh
File metadata and controls
executable file
·119 lines (88 loc) · 2.32 KB
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
#!/bin/bash
set -e
prod=$1
info() {
printf "\e[34m[➧]\e[0m ${1}\n"
}
error() {
printf "\e[31m[✘]\e[0m ${1}\n"
}
success() {
printf "\e[32m[✔]\e[0m ${1}\n"
}
function toWinPath() {
echo "$1" | sed -e 's/^\///' -e 's/\//\\/g' -e 's/^./\0:/'
}
function toPosixPath() {
echo "/$1" | sed -e 's/\\/\//g' -e 's/://' -e 's/\/\//\//g'
}
# Install packages, if yarn is installed then use yarn to install packages.
function installPackage() {
if type yarn >/dev/null 2>&1; then
yarn install $prod
else
npm install $prod
fi
}
globalDirForWin=$(npm config get prefix)
currentDirForPosix=$(pwd)
currentDirForWin=$(toWinPath $currentDirForPosix)
globalDirForPosix=$(toPosixPath $globalDirForWin)
os="win"
uname=$(uname)
if [ "$uname"x = "Darwin"x ]; then
os="mac"
globalDirForPosix="$globalDirForPosix/bin"
fi
if [ "$prod"x = "--production"x ]; then
# Generate dev and debug bin file
array=( dev debug )
for mod in "${array[@]}"
do
params=""
if [ "$mod"x = "debug"x ]; then
params=" --inspect-brk"
fi
cat > "$globalDirForPosix/wepy-$mod" <<- EOF
#!/bin/sh
basedir=\$(dirname "\$(echo "\$0" | sed -e 's,\\\\,/,g')")
case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "\$basedir"\`;;
esac
if [ -x "\$basedir/node" ]; then
"\$basedir/node"$params "$currentDirForPosix/packages/wepy-cli/bin/wepy.js" "\$@"
ret=\$?
else
node$params "$currentDirForPosix/packages/wepy-cli/bin/wepy.js" "\$@"
ret=\$?
fi
exit \$ret
EOF
chmod +x "$globalDirForPosix/wepy-$mod"
success "generated: $globalDirForPosix/wepy-$mod"
# If it's win then generate cmd file
if [ "$os"x = "win"x ]; then
cat > "$globalDirForPosix/wepy-$mod.cmd" <<- EOF
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe"$params "$currentDirForWin\packages\wepy-cli\bin\wepy.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node$params "$currentDirForWin\packages\wepy-cli\bin\wepy.js" %*
)
EOF
success "generated: $globalDirForPosix/wepy-$mod.cmd"
fi
done
fi
cd $currentDirForPosix
installPackage
# Run npm install for every packages
# Change to install wepy-cli only
packages=$(ls -1 ./packages | grep "wepy-cli")
for package in ${packages[@]}
do
cd "$currentDirForPosix/packages/$package"
info "install npm packages for $package"
installPackage
done