Skip to content

Commit

Permalink
add setup nodejs runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
jingjingxyk committed Aug 1, 2024
1 parent 5612440 commit e8ccc8a
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ max_line_length = 120

[*.{html,xml}]
indent_size = 4
indent_style = space

[*.{sh,bash}]
indent_size = 2
indent_style = space
146 changes: 146 additions & 0 deletions tools/setup-nodejs-runtime.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/usr/bin/env bash

set -exu
__DIR__=$(
cd "$(dirname "$0")"
pwd
)
__PROJECT__=$(
cd "${__DIR__}/../"
pwd
)

cd ${__PROJECT__}

OS=$(uname -s)
ARCH=$(uname -m)

case $OS in
'Linux')
OS="linux"
;;
'Darwin')
OS="darwin"
;;
*)
case $OS in
'MSYS_NT'*)
OS="win"
;;
'MINGW64_NT'*)
OS="win"
;;
*)
echo '暂未配置的 OS '
exit 0
;;
esac
;;
esac

case $ARCH in
'x86_64')
ARCH="x64"
;;
'aarch64' | 'arm64')
ARCH="arm64"
;;
*)
echo '暂未配置的 ARCH '
exit 0
;;
esac

APP_VERSION='v20.15.1'
APP_NAME='node'
VERSION='v20.15.1'

mkdir -p bin/runtime
mkdir -p var/runtime

cd ${__PROJECT__}/var/runtime

: <<'EOF'
https://nodejs.org/dist/v20.15.1/node-v20.15.1-darwin-x64.tar.gz
https://nodejs.org/dist/v20.15.1/node-v20.15.1-darwin-arm64.tar.gz
https://nodejs.org/dist/v20.15.1/node-v20.15.1-linux-arm64.tar.xz
https://nodejs.org/dist/v20.15.1/node-v20.15.1-linux-arm64.tar.xz
https://nodejs.org/dist/v20.15.1/node-v20.15.1-win-arm64.zip
https://nodejs.org/dist/v20.15.1/node-v20.15.1-win-x64.zip
https://registry.npmmirror.com/-/binary/node/v20.15.1/node-v20.15.1-win-x64.zip
EOF

APP_DOWNLOAD_URL="https://nodejs.org/dist/${VERSION}/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}.tar.xz"

if [ $OS = 'win' ]; then
APP_DOWNLOAD_URL="https://nodejs.org/dist/${VERSION}/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}.zip"
fi

MIRROR=''
while [ $# -gt 0 ]; do
case "$1" in
--mirror)
MIRROR="$2"
;;
--proxy)
export HTTP_PROXY="$2"
export HTTPS_PROXY="$2"
NO_PROXY="127.0.0.0/8,10.0.0.0/8,100.64.0.0/10,172.16.0.0/12,192.168.0.0/16"
NO_PROXY="${NO_PROXY},::1/128,fe80::/10,fd00::/8,ff00::/8"
NO_PROXY="${NO_PROXY},localhost"
NO_PROXY="${NO_PROXY},.aliyuncs.com,.aliyun.com,.tencent.com"
NO_PROXY="${NO_PROXY},.myqcloud.com,.swoole.com"
export NO_PROXY="${NO_PROXY},.tsinghua.edu.cn,.ustc.edu.cn,.npmmirror.com"
;;
--*)
echo "Illegal option $1"
;;
esac
shift $(($# > 0 ? 1 : 0))
done

case "$MIRROR" in
china)
APP_DOWNLOAD_URL="https://registry.npmmirror.com/-/binary/node/${APP_VERSION}/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}.tar.xz"
if [ $OS = 'windows' ]; then
APP_DOWNLOAD_URL="https://registry.npmmirror.com/-/binary/node/${APP_VERSION}/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}.zip"
fi
;;
esac

APP_RUNTIME="${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}"
if [ $OS = 'win' ]; then
{
test -f ${APP_RUNTIME}.zip || curl -fSLo ${APP_RUNTIME}.zip ${APP_DOWNLOAD_URL}
test -d ${APP_RUNTIME} && rm -rf ${APP_RUNTIME}
unzip "${APP_RUNTIME}.zip"
exit 0
}
else
if [ $OS = "darwin" ]; then
test -f ${APP_RUNTIME}.tar.gz || curl -fSLo ${APP_RUNTIME}.tar.gz ${APP_DOWNLOAD_URL}
test -d ${APP_RUNTIME} && rm -rf ${APP_RUNTIME}
tar -xvf ${APP_RUNTIME}.tar.gz

else
test -f ${APP_RUNTIME}.tar.xz || curl -fSLo ${APP_RUNTIME}.tar.xz ${APP_DOWNLOAD_URL}
test -f ${APP_RUNTIME}.tar || xz -d -k ${APP_RUNTIME}.tar.xz
test -d ${APP_RUNTIME} || tar -xvf ${APP_RUNTIME}.tar
fi
test -d ${__PROJECT__}/bin/runtime/node && rm -rf ${__PROJECT__}/bin/runtime/node
mv ${APP_RUNTIME} ${__PROJECT__}/bin/runtime/node
fi

cd ${__PROJECT__}/

set +x

echo " "
echo " USE PHP RUNTIME :"
echo " "
echo " export PATH=\"${__PROJECT__}/bin/runtime/node/bin/:\$PATH\" "
echo " "
export PATH="${__PROJECT__}/bin/runtime/node/bin/:$PATH"
node -v
npm -v
npx -v

0 comments on commit e8ccc8a

Please sign in to comment.