2020-11-02 04:08:18 +00:00
|
|
|
#!/bin/sh
|
2020-09-17 10:24:35 +00:00
|
|
|
|
2020-11-08 16:26:14 +00:00
|
|
|
DIR=$(dirname "$(readlink -f "$0")")
|
2020-11-02 04:08:18 +00:00
|
|
|
. "$DIR/../env.sh"
|
2020-09-17 10:24:35 +00:00
|
|
|
|
2020-10-29 07:42:23 +00:00
|
|
|
# install specific version
|
2020-11-02 04:08:18 +00:00
|
|
|
if [ -n "$1" ]; then
|
|
|
|
if command -v node 1>/dev/null 2>&1 && [ "$1" != "$(node -v)" ]; then
|
2020-10-29 07:42:23 +00:00
|
|
|
NODE_URL=https://nodejs.org/dist
|
2020-11-02 04:08:18 +00:00
|
|
|
in_china && NODE_URL=https://npm.taobao.org/mirrors/node
|
|
|
|
if [ "$1" = 'ls' ]; then
|
2020-10-29 07:42:23 +00:00
|
|
|
curl -s $NODE_URL/index.json | jq '.[] | "\(.version) \(if .lts then "(lts)" else "" end)"' -r | less
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
FN=node-$1-linux-x64.tar.gz
|
2020-11-02 04:08:18 +00:00
|
|
|
wget -O "/tmp/$FN" "$NODE_URL/$1/$FN"
|
|
|
|
sudo tar zxvf "/tmp/$FN" --strip 1 -C /usr/local/
|
|
|
|
rm "/tmp/$FN"
|
2020-10-29 07:42:23 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# install from distribution repo
|
|
|
|
case "$PM" in
|
|
|
|
apt)
|
|
|
|
sudo apt install -y nodejs npm yarnpkg
|
|
|
|
;;
|
|
|
|
pacman)
|
|
|
|
sudo pacman -S --needed nodejs npm yarn
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2020-09-17 10:24:35 +00:00
|
|
|
|
|
|
|
|
2020-09-17 16:02:24 +00:00
|
|
|
# install nvm
|
2020-11-02 04:08:18 +00:00
|
|
|
if command -v fish 2>/dev/null; then
|
2020-09-17 16:02:24 +00:00
|
|
|
fish -c "fisher add jorgebucaran/nvm.fish"
|
|
|
|
else
|
|
|
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
|
|
|
|
fi
|
|
|
|
|
2020-09-17 10:24:35 +00:00
|
|
|
|
|
|
|
# config mirrors for CHINA
|
2020-11-02 04:08:18 +00:00
|
|
|
if in_china; then
|
2020-10-20 08:16:37 +00:00
|
|
|
sudo npm install cnpm -g --registry=https://r.npm.taobao.org
|
2020-09-17 10:24:35 +00:00
|
|
|
yarnpkg config set registry https://registry.npm.taobao.org --global && \
|
|
|
|
yarnpkg config set disturl https://npm.taobao.org/dist --global && \
|
|
|
|
yarnpkg config set sass_binary_site https://npm.taobao.org/mirrors/node-sass --global && \
|
|
|
|
yarnpkg config set electron_mirror https://npm.taobao.org/mirrors/electron/ --global && \
|
|
|
|
yarnpkg config set puppeteer_download_host https://npm.taobao.org/mirrors --global && \
|
|
|
|
yarnpkg config set chromedriver_cdnurl https://npm.taobao.org/mirrors/chromedriver --global && \
|
|
|
|
yarnpkg config set operadriver_cdnurl https://npm.taobao.org/mirrors/operadriver --global && \
|
|
|
|
yarnpkg config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs --global && \
|
|
|
|
yarnpkg config set selenium_cdnurl https://npm.taobao.org/mirrors/selenium --global && \
|
2020-10-20 08:16:37 +00:00
|
|
|
yarnpkg config set sqlite3_binary_host_mirror https://foxgis.oss-cn-shanghai.aliyuncs.com/ --global && \
|
|
|
|
yarnpkg config set profiler_binary_host_mirror https://npm.taobao.org/mirrors/node-inspector/ --global && \
|
|
|
|
yarnpkg config set chromedriver_cdnurl https://cdn.npm.taobao.org/dist/chromedriver --global && \
|
2020-09-17 10:24:35 +00:00
|
|
|
yarnpkg config set node_inspector_cdnurl https://npm.taobao.org/mirrors/node-inspector --global && \
|
2020-10-20 08:16:37 +00:00
|
|
|
yarnpkg config set sentrycli_cdnurl https://npm.taobao.org/mirrors/sentry-cli
|
2020-09-17 10:24:35 +00:00
|
|
|
fi
|