#!/bin/bash # Color definitions RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' MAGENTA='\033[0;35m' CYAN='\033[0;36m' BOLD='\033[1m' NC='\033[0m' # No Color # Function to print colored text print_color() { printf "${1}${2}${NC}\n" } # Function to print a styled header print_header() { clear print_color $MAGENTA " ____ _ | _ \ | | | |_) | ___| |__ ___ _ __ | _ < / _ \ '_ \ / _ \| '_ \ | |_) | __/ |_) | (_) | |_) | |____/ \___|_.__/ \___/| .__/ | | |_| " print_color $CYAN "Extension Creator" echo } # Function to prompt user for directory prompt_directory() { print_header print_color $YELLOW "Step 1 of 3: Choose Directory" echo print_color $CYAN "In which directory do you want to create your Bebop extension?" print_color $CYAN "This will also be used as the extension name." echo read -p "$(print_color $GREEN "Directory name: ")" directory # If directory is empty, use a default name if [ -z "$directory" ]; then directory="bebop-extension-$(date +%s)" fi # Remove leading './' if present directory="${directory#./}" print_color $YELLOW "Using directory: $directory" echo } # Function to prompt user for EDK selection prompt_edk() { print_header print_color $YELLOW "Step 2 of 3: Select EDK" echo print_color $CYAN "Select an EDK (Extension Development Kit):" echo select edk in "typescript" "tinygo" "assemblyscript"; do case $edk in typescript | tinygo | assemblyscript) print_color $YELLOW "Selected EDK: $edk" break ;; *) print_color $RED "Invalid selection. Please try again." ;; esac done echo } # Function to download and extract EDK download_and_extract_edk() { print_header print_color $YELLOW "Step 3 of 3: Download and Extract EDK" echo print_color $CYAN "Downloading and extracting EDK..." # Create directory if it doesn't exist mkdir -p "$directory" # Download the zip file if curl -L "https://fetch.bebop.sh/?edk=$edk" -o "$directory/edk.zip"; then # Extract the zip file unzip -q "$directory/edk.zip" -d "$directory" # Remove the zip file rm "$directory/edk.zip" print_color $GREEN "EDK extracted successfully." else print_color $RED "Failed to download EDK. Please check your internet connection and try again." exit 1 fi echo } # Function to modify chord.json modify_chord_json() { print_header print_color $YELLOW "Finalizing: Modifying chord.json" echo chord_json="$directory/chord.json" if [ -f "$chord_json" ]; then # Use jq to modify the JSON file jq ".name = \"$directory\" | .version = \"1.0.0\"" "$chord_json" >"$chord_json.tmp" && mv "$chord_json.tmp" "$chord_json" print_color $GREEN "chord.json updated successfully." else print_color $RED "chord.json not found. Skipping modification." fi echo } # Main script execution print_header print_color $BOLD "Welcome to the Bebop Extension Creator!" echo sleep 1 # Short pause for readability prompt_directory prompt_edk download_and_extract_edk modify_chord_json print_header print_color $GREEN "Bebop extension creation complete!" print_color $CYAN "Your new extension is ready in the '$directory' directory." print_color $CYAN "You can now start developing your Bebop extension using the $edk EDK." echo print_color $YELLOW "Next steps:" print_color $CYAN "1. Change to your new extension directory:" print_color $GREEN " cd $directory" print_color $CYAN "2. Visit https://docs.bebop.sh for more information on developing Bebop extensions." echo print_color $YELLOW "Happy coding!"