-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbuild-from-source-link.sh
More file actions
executable file
·88 lines (73 loc) · 2.96 KB
/
Copy pathbuild-from-source-link.sh
File metadata and controls
executable file
·88 lines (73 loc) · 2.96 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PACKAGE_DIR="$REPO_ROOT/cli"
if [[ ! -f "$PACKAGE_DIR/package.json" ]]; then
echo "error: expected DisCo package at $PACKAGE_DIR" >&2
exit 1
fi
if ! command -v node >/dev/null 2>&1 || ! command -v npm >/dev/null 2>&1; then
echo "error: Node.js and npm must be available on PATH" >&2
exit 1
fi
# Honor HTTP_PROXY/HTTPS_PROXY during dependency installation when supported by Node.
export NODE_USE_ENV_PROXY="${NODE_USE_ENV_PROXY:-1}"
echo "==> Installing DisCo source dependencies"
npm --prefix "$PACKAGE_DIR" ci --include=dev --ignore-scripts
echo "==> Building DisCo from cli"
npm --prefix "$PACKAGE_DIR" run build
if [[ ! -x "$PACKAGE_DIR/dist/cli.js" ]]; then
echo "error: build did not create executable $PACKAGE_DIR/dist/cli.js" >&2
exit 1
fi
echo "==> Linking disco globally"
global_prefix="$(npm prefix --global)"
global_node_modules="$global_prefix/lib/node_modules"
global_bin="$global_prefix/bin/disco"
global_bin_target=""
global_bin_is_previous_disco_link=false
if [[ -L "$global_bin" ]]; then
# `readlink -m` also resolves a dangling symlink, which lets the cleanup
# recover from an interrupted scope migration.
global_bin_target="$(readlink -m "$global_bin")"
fi
# The package was previously linked as @auto-ml-skills/disco. Both scopes
# expose the same `disco` binary, so remove only source links that resolve to
# this checkout before creating the new @arex-skill/disco link.
for package_link in \
"$global_node_modules/@auto-ml-skills/disco" \
"$global_node_modules/@arex-skill/disco"; do
if [[ -L "$package_link" ]] && [[ "$(readlink -f "$package_link")" == "$PACKAGE_DIR" ]]; then
echo "==> Removing previous DisCo source link: $package_link"
if [[ "$global_bin_target" == "$package_link/dist/cli.js" ]]; then
global_bin_is_previous_disco_link=true
fi
rm "$package_link"
elif [[ ! -e "$package_link" ]] && [[ "$global_bin_target" == "$package_link/dist/cli.js" ]]; then
# Recover a dangling bin link left by an interrupted previous run.
global_bin_is_previous_disco_link=true
fi
done
if [[ "$global_bin_target" == "$PACKAGE_DIR/dist/cli.js" ]] || [[ "$global_bin_is_previous_disco_link" == true ]]; then
echo "==> Removing previous DisCo command link: $global_bin"
rm "$global_bin"
elif [[ -e "$global_bin" || -L "$global_bin" ]]; then
echo "error: $global_bin already exists and does not point to this DisCo checkout" >&2
echo "error: remove or rename that existing disco command, then rerun this script" >&2
exit 1
fi
(
cd "$PACKAGE_DIR"
npm link --ignore-scripts
)
if ! command -v disco >/dev/null 2>&1; then
global_prefix="$(npm prefix --global)"
echo "error: npm linked DisCo, but disco is not on PATH" >&2
echo "error: add $global_prefix/bin to PATH and rerun this script" >&2
exit 1
fi
echo "==> Verifying linked CLI"
disco --version
disco --help >/dev/null
echo "==> Done"
echo "disco is built from source and linked globally. Try: disco --help"