-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli
More file actions
executable file
·64 lines (49 loc) · 1.42 KB
/
Copy pathcli
File metadata and controls
executable file
·64 lines (49 loc) · 1.42 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
#! /bin/bash
LAST_BUILD_SHA_FILE=./.buildsha
if [ "$(uname -s)" = "Darwin" ]; then
function readlink() {
greadlink "$@"
}
fi
export AWS_SDK_LOAD_CONFIG=1
export CLI_DIR="${CLI_DIR:-$(readlink -f "$(dirname "$0")/..")}"
if [ -z "$CLI_DIR" ]; then
echo ""
echo "CLI_DIR is a required environment variable. We tried to figure it out but it was unsuccessful."
fi
cliDir="$CLI_DIR"
if [ ! -d "$cliDir" ]; then
echo "Couldn't find $cliDir. Is your CLI_DIR set correctly? No trailing slash or typos?"
echo "CLI_DIR=$CLI_DIR"
exit 1
fi
cd "$cliDir"
if [ ! -d "./node_modules" ]; then
echo "./node_modules missing. Running yarn.." >&2
yarn install >&2
fi
lastBuildSha="$(cat $LAST_BUILD_SHA_FILE 2>/dev/null)"
lastShaCliChanged=$(git log --no-color -n1 --oneline . | awk '{print $1;}')
recompileCli() {
yarn build >&2
echo $lastShaCliChanged > $LAST_BUILD_SHA_FILE
}
runCli() {
node -r dotenv/config "$cliDir/lib/cli.js" "$@"
}
if [[ -z "$lastBuildSha" ]]; then
echo "Cli has never built locally, building now.." >&2
recompileCli
elif [[ $(git ls-files -dm) ]]; then
echo "Cli has local changed files, recompiling.." >&2
recompileCli
elif ! git merge-base --is-ancestor $lastShaCliChanged $lastBuildSha; then
echo "Cli has changed since last local build, recompiling.." >&2
recompileCli
fi
if [[ "$1" = "dc" ]]; then
shift
dcShortcuts "$@"
else
runCli "$@"
fi