-
Notifications
You must be signed in to change notification settings - Fork 7
/
install.sh
executable file
·68 lines (55 loc) · 1.8 KB
/
install.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
#!/bin/bash
# Check if npm is available
if ! command -v npm &> /dev/null; then
echo "npm could not be found, please install Node.js and npm"
exit 1
fi
if ! command -v node &> /dev/null; then
echo "node could not be found, please install Node.js and npm"
exit 1
fi
if ! command -v npx tsc &> /dev/null; then
echo "tsc could not be found, please install tsc (TypeScript CLI & compiler)"
exit 1
fi
NODE_VERSION="$(node --version)"
NPM_VERSION="$(npm --version)"
TSC_VERSION="$(npx tsc -v)"
echo "Node version: $NODE_VERSION"
echo "npm version: $NPM_VERSION"
echo "tsc version: $TSC_VERSION"
# Install npm dependencies
npm install
npx tsc
# Setup .env file
node ./dist/src/cmdh.js configure
# Get the directory where the install script is located
CMDH_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Alias command using the dynamically determined path
alias_cmd="alias cmdh='node $CMDH_DIR/dist/src/cmdh.js'"
# Function to add alias and reload config for Bash and Zsh
add_alias_and_reload() {
shell_rc=$1
echo "$alias_cmd" >> "$shell_rc"
source "$shell_rc"
}
# Detect the shell and update the corresponding config file
if [ -n "$BASH_VERSION" ]; then
# Bash shell
add_alias_and_reload "${HOME}/.bashrc"
echo "Alias added to .bashrc."
elif [ -n "$ZSH_VERSION" ]; then
# Zsh shell
add_alias_and_reload "${HOME}/.zshrc"
echo "Alias added to .zshrc."
elif [ -n "$FISH_VERSION" ]; then
# Fish shell
echo "set -Ux cmdh 'node $CMDH_DIR/dist/index.js'" | fish
echo "Alias added to Fish universal variables."
else
echo "Unsupported shell. Please add the alias manually to your shell initializer."
echo "$alias_cmd"
exit 1
fi
echo "Installation complete!"
echo "Reload your shell config file or open a new terminal session to run cmdh."