Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW committed Oct 9, 2024
1 parent 3e2043b commit 36ad0a7
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 12 deletions.
94 changes: 94 additions & 0 deletions tools/cli/bin/modus
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env bash

get_script_dir() {
SOURCE="${BASH_SOURCE[0]}"
DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
echo "$DIR"
}

# Config
NODE_WANTED=20.18.0
NODE_REQUIRED=18
NODE_PATH="$(which node)"
NODE_INSTALL_PATH="node-bin"

# Properties
ARCH="$(uname -m)"
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
DIR=$(get_script_dir)

PATH_FILE="$DIR/scripts/modus-path"
LOCAL_FILE="$DIR/scripts/modus-local"

case $ARCH in
aarch64) ARCH="arm64" ;;
x86_64) ARCH="x64" ;;
armv6l) ARCH="arm" ;;
*) ;;
esac

echo_fexists() {
[ -f "$1" ] && echo "$1"
}

install_node() {
mkdir -p "$DIR/$NODE_INSTALL_PATH"

download_file="node-v$NODE_WANTED-$OS-$ARCH.tar.gz"
download_url="https://nodejs.org/dist/v$NODE_WANTED/$download_file"
temp_dir="$DIR/.temp"

rm -rf $temp_dir
mkdir $temp_dir
curl --silent --show-error --location --fail "$download_url" \
--output "$temp_dir/$download_file"

tar -xf "$temp_dir/$download_file" -C "$temp_dir"
rm -rf $download_file
rm -rf "$DIR/$NODE_INSTALL_PATH"
mkdir "$DIR/$NODE_INSTALL_PATH"
mv "$temp_dir/node-v$NODE_WANTED-$OS-$ARCH/"* "$DIR/$NODE_INSTALL_PATH/"
chmod +x "$DIR/$NODE_INSTALL_PATH/bin/node"
chmod +x "$DIR/$NODE_INSTALL_PATH/bin/npm"
rm -rf $temp_dir
NODE_PATH="$DIR/$NODE_INSTALL_PATH/bin/node"
}

check_node() {
if ! echo_fexists "./$NODE_INSTALL_PATH/bin/node"; then
NODE_VERSION=$($NODE_PATH -v 2>/dev/null)

if [ $? -ne 0 ]; then
install_node
fi

NODE_VERSION=${NODE_VERSION#v}
MAJOR_VERSION=${NODE_VERSION%%.*}

if [ "$MAJOR_VERSION" -le $NODE_REQUIRED ]; then
install_node
fi
fi
}

if ! echo_fexists $LOCAL_FILE; then
mkdir -p "$DIR/scripts/"
echo "#!$DIR/node-bin/bin/node
import { execute } from \"@oclif/core\";
await execute({ dir: import.meta.url });" >$LOCAL_FILE
chmod +x $LOCAL_FILE
else
$LOCAL_FILE
exit 0
fi

if ! echo_fexists $PATH_FILE; then
mkdir -p "$DIR/scripts/"
echo "#!/usr/bin/env node
import { execute } from \"@oclif/core\";
await execute({ dir: import.meta.url });" >$PATH_FILE
chmod +x $PATH_FILE
else
check_node
$PATH_FILE
fi
1 change: 0 additions & 1 deletion tools/cli/bin/run.cmd → tools/cli/bin/modus.cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
@echo off

node "%~dp0\run" %*
5 changes: 0 additions & 5 deletions tools/cli/bin/run.js

This file was deleted.

12 changes: 6 additions & 6 deletions tools/cli/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ build_path_str() {
if [[ $profile == *.fish ]]; then
echo -e "set -gx MODUS_CLI \"$install_dir\"\nstring match -r \".modus\" \"\$PATH\" > /dev/null; or set -gx PATH \"\$MODUS_CLI/bin\" \$PATH"
else
echo -e "# Modus CLI\nexport MODUS_CLI=\"$install_dir\"\nexport PATH=\"\$MODUS_CLI/bin:\$PATH\""
echo -e "\n# Modus CLI\nexport MODUS_CLI=\"$install_dir\"\nexport PATH=\"\$MODUS_CLI/bin:\$PATH\""
fi
}

Expand Down Expand Up @@ -183,7 +183,7 @@ install_from_file() {
rm -f "$archive"
mv "$extract_to/modus/"* "$INSTALL_DIR"
rm -rf "$extract_to"

clear_line
echo "[2/5] Unpacked archive"
}
Expand All @@ -210,10 +210,10 @@ restart_shell() {
echo -e "[5/5] Restarted shell ${DIM}($shell_name)${RESET}\n\nThe Modus CLI has been installed! 🎉\nRun ${DIM}modus${RESET} to get started"

case "$shell_name" in
bash|zsh|fish) exec "$shell_name" ;;
*)
echo -e "[5/5] Clean up\n\nPlease restart your shell for changes to take effect"
;;
bash | zsh | fish) exec "$shell_name" ;;
*)
echo -e "[5/5] Clean up\n\nPlease restart your shell for changes to take effect"
;;
esac
}

Expand Down

0 comments on commit 36ad0a7

Please sign in to comment.