This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcli.sh
executable file
·70 lines (58 loc) · 1.97 KB
/
cli.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
#!/usr/bin/env sh
set -e
NODE_VERSION='10.11.0'
NODE_ARCH='x64'
NODE_PLATFORM='linux'
NODE_EXTENSION='tar.xz'
if [[ "$OSTYPE" == "darwin"* ]]; then
NODE_PLATFORM='darwin'
NODE_EXTENSION='tar.gz'
fi
NODE_URL="https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-${NODE_PLATFORM}-${NODE_ARCH}.${NODE_EXTENSION}"
NODE_PKG_NAME="node-v${NODE_VERSION}-${NODE_PLATFORM}-${NODE_ARCH}.${NODE_EXTENSION}"
#rm -rf .node node_modules
#echo "NODE_URL=${NODE_URL}"
if [ ! -f "/tmp/${NODE_PKG_NAME}" ]; then
echo "Downloading Node:${NODE_VERSION} ..."
curl -sSL "${NODE_URL}" -o "/tmp/${NODE_PKG_NAME}"
fi
NODE_HOME=".node/node-v${NODE_VERSION}-${NODE_PLATFORM}-${NODE_ARCH}"
if [ ! -d "${NODE_HOME}" ]; then
mkdir -p ".node"
if [[ "$NODE_EXTENSION" == "tar.xz" ]]; then
tar -xf "/tmp/${NODE_PKG_NAME}" -C ".node"
else
tar -xzf "/tmp/${NODE_PKG_NAME}" -C ".node"
fi
fi
export PATH="${NODE_HOME}/bin:$PATH"
#TODO: set NPM_CONFIG_PREFIX
#npm install npm@latest -g
echo "node: $(node --version) (from $(which node))"
echo "npm: $(npm --version) (from $(which npm))"
#export NPM_CONFIG_CACHE="$(pwd)/.npm/cache"
#export NPM_CONFIG_LOGLEVEL='verbose'
#export NPM_CONFIG_USERCONFIG="$(pwd)/.npmrc"
#npm config ls -l
#unset NPM_CONFIG_LOGLEVEL
if [ ! -d "node_modules" ]; then
#rm -rf node_modules
#npm list -g --depth 0
#shasum -a 256 packages.json
if [[ "$OSTYPE" == "darwin"* ]]; then
PACKAGE_HASH="$(shasum -p -a 256 package-lock.json | awk '{ print $1 }')"
else
PACKAGE_HASH="$(sha256sum package-lock.json | awk '{ print $1 }')"
fi
if [ -f "/tmp/${PACKAGE_HASH}.tar.gz" ]; then
#untar
touch "/tmp/${PACKAGE_HASH}.tar.gz"
tar -xzf "/tmp/${PACKAGE_HASH}.tar.gz"
else
NODE_ENV=PRODUCTION "${NODE_HOME}/bin/npm" "ci"
tar -czf "${PACKAGE_HASH}.tar.gz" node_modules
mv -f "${PACKAGE_HASH}.tar.gz" "/tmp/${PACKAGE_HASH}.tar.gz"
fi
#NODE_ENV=PRODUCTION "${NODE_HOME}/bin/npm" "install" --no-audit
fi
exec "${NODE_HOME}/bin/npm" run-script "$@"