-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom-setup
More file actions
executable file
·152 lines (137 loc) · 5.21 KB
/
Copy pathatom-setup
File metadata and controls
executable file
·152 lines (137 loc) · 5.21 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env bash
# atom-setup — one-command bootstrap.
#
# First-time use, from inside a freshly cloned atom directory:
# ./atom-setup
#
# Installs atom's CLIs globally (if not already present), then launches
# the interactive wizard to transform this directory into your new
# project. Forwards any flags to the wizard, e.g.:
#
# ./atom-setup --bare
# ./atom-setup --minimal
# ./atom-setup --full
#
# After the first run, the global `atom-setup` is on your PATH and
# future clones can skip the `./` and just run `atom-setup`.
#
# Wrapper-only flag (consumed here, not forwarded to the wizard):
#
# --reinstall Re-install every atom CLI globally even if already
# on PATH. Stop-gap until `atom upgrade` is the daily
# refresh path; useful when a global is stale or
# pointing at an old clone.
set -e
ATOM_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# ─── parse wrapper-only flags ───────────────────────────────────────
FORCE_REINSTALL=0
WIZARD_ARGS=()
for arg in "$@"; do
case "$arg" in
--reinstall) FORCE_REINSTALL=1 ;;
*) WIZARD_ARGS+=("$arg") ;;
esac
done
# ─── pre-flight ─────────────────────────────────────────────────────
if ! command -v node > /dev/null 2>&1; then
echo "Error: node not found on PATH." >&2
echo "atom requires Node.js 18+. Install from https://nodejs.org and re-run." >&2
exit 1
fi
if ! command -v npm > /dev/null 2>&1; then
echo "Error: npm not found on PATH." >&2
echo "npm ships with Node.js. Reinstall Node from https://nodejs.org and re-run." >&2
exit 1
fi
NODE_MAJOR=$(node -p "process.versions.node.split('.')[0]")
if [ "$NODE_MAJOR" -lt 18 ]; then
echo "Error: Node $(node -v) is too old. atom requires Node 18 or newer." >&2
exit 1
fi
CLIS=(atom atom-setup nucleus learnings model-race atom-update-check)
# Find the GLOBAL atom-setup (skip cwd in PATH so we don't recurse into
# this script). Used both for "already installed?" detection and for the
# final exec.
#
# Two failure modes the cleanup handles:
# - $ATOM_DIR explicitly in PATH (filtered by `grep -v ^$ATOM_DIR$`)
# - empty PATH components (which bash treats as cwd) introduced when
# splitting/joining; if cwd happens to be $ATOM_DIR, that smuggles
# `./atom-setup` (this script) in as a "global" hit. Strip both empty
# lines and the trailing colon.
find_global() {
local name="$1"
local cleaned
cleaned=$(echo "$PATH" | tr ':' '\n' | grep -v "^$ATOM_DIR$" | grep -v '^$' | tr '\n' ':' | sed 's/:$//')
PATH="$cleaned" command -v "$name" 2>/dev/null
}
# ─── install CLIs (only what's missing, or all if --reinstall) ──────
need_install=0
if [ "$FORCE_REINSTALL" = "1" ]; then
need_install=1
else
for cli in "${CLIS[@]}"; do
if [ -z "$(find_global $cli)" ]; then
need_install=1
break
fi
done
fi
if [ "$need_install" = "1" ]; then
echo ""
if [ "$FORCE_REINSTALL" = "1" ]; then
echo "Re-installing all atom CLIs globally (--reinstall)..."
else
echo "Installing atom's CLIs globally (one-time per machine)..."
fi
echo ""
for cli in "${CLIS[@]}"; do
if [ "$FORCE_REINSTALL" != "1" ] && [ -n "$(find_global $cli)" ]; then
printf " → %-12s already installed, skipping\n" "$cli"
continue
fi
printf " → %-12s " "$cli"
# First populate the source's node_modules so the global install can
# resolve deps (`npm install -g .` alone does not pull deps reliably
# on a fresh clone — symptoms: ERR_MODULE_NOT_FOUND for commander, etc.).
if ! (cd "$ATOM_DIR/bin/$cli" && npm install > /tmp/atom-install-$cli.log 2>&1); then
echo "FAILED"
echo "" >&2
echo "npm install (deps) for $cli failed. Last 10 lines of output:" >&2
tail -10 /tmp/atom-install-$cli.log >&2
exit 1
fi
if (cd "$ATOM_DIR/bin/$cli" && npm install -g . >> /tmp/atom-install-$cli.log 2>&1); then
echo "ok"
else
echo "FAILED"
echo "" >&2
echo "npm install -g for $cli failed. Last 10 lines of output:" >&2
tail -10 /tmp/atom-install-$cli.log >&2
echo "" >&2
echo "Common cause: EACCES on global install. Either re-run with sudo," >&2
echo "or set up an npm prefix in your home dir:" >&2
echo " https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally" >&2
exit 1
fi
done
# Re-check PATH after install (npm prefix may not be on PATH)
for cli in "${CLIS[@]}"; do
if [ -z "$(find_global $cli)" ]; then
echo "" >&2
echo "Error: '$cli' was installed but is not on your PATH." >&2
echo "Run 'npm config get prefix' and ensure that prefix's bin/ is in PATH." >&2
exit 1
fi
done
echo ""
echo "Installed. Launching wizard..."
echo ""
fi
# ─── launch the wizard, forwarding any flags ────────────────────────
GLOBAL_ATOM_SETUP=$(find_global atom-setup)
if [ -z "$GLOBAL_ATOM_SETUP" ]; then
echo "Error: atom-setup not found on PATH after install." >&2
exit 1
fi
exec "$GLOBAL_ATOM_SETUP" "${WIZARD_ARGS[@]}"