Skip to content

Commit

Permalink
replace NODE_PATH by soft link (#1478)
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Jul 14, 2018
1 parent 035b4af commit 7dd5bc4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key
&& rm -rf /tmp/* /var/lib/apt/lists/* \
&& rm -rf /usr/bin/google-chrome* /opt/google/chrome-unstable

RUN mkdir /wechaty
RUN mkdir /wechaty /node_modules
WORKDIR /wechaty

COPY package.json .
Expand All @@ -66,9 +66,9 @@ RUN npm run dist
# If it is not found there, then it moves to the parent directory, and so on, until the root of the file system is reached.
RUN sudo mkdir /bot \
&& npm link \
&& sudo ln -s /usr/lib/node_modules/ / \
&& sudo ln -s /wechaty/node_modules/@babel /node_modules \
&& sudo ln -s /wechaty/tsconfig.json / \
&& sudo ln -sfv /usr/lib/node_modules/* /node_modules/ \
&& sudo ln -sfv /wechaty/node_modules/* /node_modules/ \
&& sudo ln -sfv /wechaty/tsconfig.json / \
&& echo 'Linked Wechaty to Global'

ENTRYPOINT [ "/wechaty/bin/entrypoint.sh" ]
Expand Down
15 changes: 14 additions & 1 deletion bin/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set -e

export HOME=/bot
export PATH=$PATH:/wechaty/bin:/wechaty/node_modules/.bin
export NODE_PATH=/wechaty/node_modules:/bot/node_modules

function wechaty::banner() {
echo
Expand Down Expand Up @@ -137,6 +136,20 @@ function wechaty::runBot() {
echo "Please make sure you had installed all the NPM modules which is depended on your bot script."
# yarn < /dev/null || return $? # yarn will close stdin??? cause `read` command fail after yarn

cwd=$(pwd)
for module in node_modules/*; do
[ -e "$module" ] || continue

module=${module//node_modules\//}

globalModule="/node_modules/$module"

if [ ! -e "$globalModule" ]; then
ln -sfv "$cwd/node_modules/$module" /node_modules/
else
echo "$globalModule exists"
fi
done
}

# echo -n "Linking Wechaty module to bot ... "
Expand Down

0 comments on commit 7dd5bc4

Please sign in to comment.