Skip to content

Commit

Permalink
update install script
Browse files Browse the repository at this point in the history
  • Loading branch information
di-sukharev committed Nov 26, 2023
1 parent 274e23c commit ec05081
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 70 deletions.
102 changes: 37 additions & 65 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,75 +1,47 @@
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail

# Function to print error messages in red
error() {
echo -e "\033[0;31merror:\033[0m $1" >&2
exit 1
}
# [Initialize color codes and helper functions as in bun.sh]

# Function to print information in dim color
info() {
echo -e "\033[0;2m$1\033[0m"
}
# Check for bun
command -v bun >/dev/null ||
error 'bun is required to run aitdd. Please install bun first.'

# Function to install bun
install_bun() {
info "Installing bun..."
curl -fsSL https://bun.sh/install | bash
}
# Define the GitHub repository URL
github_repo="https://github.com/di-sukharev/AI-TDD"

# Check for bun and install if not present
if ! command -v bun &> /dev/null; then
install_bun
else
info "bun is already installed. Good. Continue."
fi
# Construct the download URL for your CLI
# Modify this URL to point to the specific release or directory containing cli.ts
aitdd_uri="$github_repo/releases/latest/download/out.zip"

# Define installation directory
BIN_DIR="$HOME/.local/bin"
mkdir -p "$BIN_DIR"
# Define the installation directory
install_dir=${HOME}/.aitdd
bin_dir=$install_dir/bin
exe=$bin_dir/aitdd

# Create a symbolic link to the CLI tool
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
CLI_FILE="$SCRIPT_DIR/cli.ts"
ln -sf "$CLI_FILE" "$BIN_DIR/aitdd"
# Create the installation directory if it doesn't exist
mkdir -p "$bin_dir" ||
error "Failed to create install directory \"$bin_dir\""

# Detect the shell and update the corresponding configuration file
SHELL_NAME=$(basename "$SHELL")
case "$SHELL_NAME" in
bash)
SHELL_CONFIG="$HOME/.bashrc"
;;
zsh)
SHELL_CONFIG="$HOME/.zshrc"
;;
fish)
SHELL_CONFIG="$HOME/.config/fish/config.fish"
;;
*)
SHELL_CONFIG=""
;;
esac
# Download and extract your CLI files
curl --fail --location --output "$exe.zip" "$aitdd_uri" ||
error "Failed to download aitdd from \"$aitdd_uri\""

# Update PATH in the user's shell configuration file
if [[ -n $SHELL_CONFIG && -w $SHELL_CONFIG ]]; then
if ! grep -q "$BIN_DIR" "$SHELL_CONFIG"; then
if [[ "$SHELL_NAME" == "fish" ]]; then
echo "set -gx PATH \"$BIN_DIR\" \$PATH" >> "$SHELL_CONFIG"
else
echo "export PATH=\"$BIN_DIR:\$PATH\"" >> "$SHELL_CONFIG"
fi
info "Added $BIN_DIR to PATH in $SHELL_CONFIG"
fi
else
info "Could not update PATH automatically. Please add $BIN_DIR to your PATH manually."
fi
unzip -oqd "$install_dir" "$exe.zip" ||
error 'Failed to extract aitdd'

# Refresh environment (this won't affect the parent shell)
export PATH="$BIN_DIR:$PATH"
# Create the aitdd wrapper command
cat <<EOF >"$exe"
#!/usr/bin/env bash
set -euo pipefail
bun $install_dir/src/cli.ts "\$@"
EOF

# Check if the tool is available in the PATH
if command -v aitdd &> /dev/null; then
info "aitdd tool installed successfully and is available in your PATH."
else
info "Installation complete, but the aitdd tool is not in your PATH. Please restart your shell or source your shell configuration file."
fi
# Make the wrapper executable
chmod +x "$exe" ||
error 'Failed to set permissions on aitdd executable'

# [Optional: Provide instructions for adding $bin_dir to PATH]

# Success message
success "aitdd was installed successfully"
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
{
"version": "2.1.7",
"version": "0.0.1",
"name": "ai-tdd",
"description": "You write a test -> GPT writes the code to pass it ✅",
"bin": {
"aitdd": ".cli.ts"
"aitdd": "./cli.ts"
},
"author": "https://github.com/di-sukharev",
"module": "cli.ts",
"type": "module",
"files": [
"./out/cli.js"
],
"release": {
"branches": [
"master"
Expand Down

0 comments on commit ec05081

Please sign in to comment.