Files
gymkhana-actions/install-extension.sh

217 lines
6.2 KiB
Bash
Executable File

#!/bin/bash
# ASHES Language Support Extension Installer
# This script installs the ASHES language support extension for VSCode/VSCodium
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to detect VSCode/VSCodium extensions directory
detect_extensions_dir() {
local extensions_dir=""
# Check for VSCodium first (more common on Linux)
if command -v codium &> /dev/null; then
extensions_dir="$HOME/.vscode-oss/extensions"
elif command -v code &> /dev/null; then
extensions_dir="$HOME/.vscode/extensions"
else
print_warning "Neither VSCode nor VSCodium found in PATH"
extensions_dir="$HOME/.vscode/extensions"
fi
echo "$extensions_dir"
}
# Function to check if directory exists and is writable
check_directory() {
local dir="$1"
if [ ! -d "$dir" ]; then
print_info "Creating directory: $dir"
mkdir -p "$dir" || {
print_error "Failed to create directory: $dir"
return 1
}
fi
if [ ! -w "$dir" ]; then
print_error "Directory is not writable: $dir"
return 1
fi
return 0
}
# Main installation function
main() {
print_info "ASHES Language Support Extension Installer"
print_info "=========================================="
echo
# Get the script directory (where the vscode-extension folder is located)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
EXTENSION_SOURCE="$SCRIPT_DIR/vscode-extension-ashes"
# Check if source extension directory exists
if [ ! -d "$EXTENSION_SOURCE" ]; then
print_error "Extension source directory not found: $EXTENSION_SOURCE"
print_error "Please run this script from the project root directory."
exit 1
fi
# Detect default extensions directory
DEFAULT_EXTENSIONS_DIR=$(detect_extensions_dir)
print_info "Default VSCode/VSCodium extensions directory:"
print_info " $DEFAULT_EXTENSIONS_DIR"
echo
# Ask for confirmation or custom path
read -p "Use default path? (y/n) [y]: " use_default
use_default=${use_default:-y}
if [[ $use_default =~ ^[Yy]$ ]]; then
EXTENSIONS_DIR="$DEFAULT_EXTENSIONS_DIR"
else
echo
read -p "Enter custom extensions directory path: " custom_path
EXTENSIONS_DIR="$custom_path"
fi
# Validate the extensions directory
if ! check_directory "$EXTENSIONS_DIR"; then
exit 1
fi
# Set the destination path for the symlink
EXTENSION_DEST="$EXTENSIONS_DIR/vscode-extension-ashes"
echo
print_info "Installation Summary:"
print_info "===================="
print_info "Source: $EXTENSION_SOURCE"
print_info "Destination: $EXTENSION_DEST"
print_info "Link name: vscode-extension-ashes"
echo
# Final confirmation
read -p "Proceed with installation? (y/n) [y]: " confirm
confirm=${confirm:-y}
if [[ ! $confirm =~ ^[Yy]$ ]]; then
print_info "Installation cancelled."
exit 0
fi
echo
print_info "Installing extension..."
# Compile the extension before creating symlink
print_info "Compiling extension..."
cd "$EXTENSION_SOURCE" || {
print_error "Failed to change to extension directory: $EXTENSION_SOURCE"
exit 1
}
# Check if nvm is available and use it if .nvmrc exists
if [ -f ".nvmrc" ] && command -v nvm &> /dev/null; then
print_info "Using nvm to set Node.js version from .nvmrc"
source ~/.nvm/nvm.sh
nvm use || {
print_warning "Failed to use nvm, continuing with system Node.js"
}
elif [ -f ".nvmrc" ] && [ -s "$NVM_DIR/nvm.sh" ]; then
print_info "Loading nvm and using Node.js version from .nvmrc"
source "$NVM_DIR/nvm.sh"
nvm use || {
print_warning "Failed to use nvm, continuing with system Node.js"
}
fi
# Install dependencies if node_modules doesn't exist
if [ ! -d "node_modules" ]; then
print_info "Installing npm dependencies..."
npm install || {
print_error "Failed to install npm dependencies"
exit 1
}
else
print_info "Dependencies already installed, skipping npm install"
fi
# Compile TypeScript
print_info "Compiling TypeScript..."
npm run compile || {
print_error "Failed to compile TypeScript"
exit 1
}
print_success "Extension compiled successfully!"
# Return to original directory
cd - > /dev/null
# Check if destination already exists
if [ -e "$EXTENSION_DEST" ]; then
print_warning "Destination already exists: $EXTENSION_DEST"
read -p "Remove existing installation? (y/n) [y]: " remove_existing
remove_existing=${remove_existing:-y}
if [[ $remove_existing =~ ^[Yy]$ ]]; then
print_info "Removing existing installation..."
rm -rf "$EXTENSION_DEST" || {
print_error "Failed to remove existing installation"
exit 1
}
else
print_info "Installation cancelled."
exit 0
fi
fi
# Create the symlink
print_info "Creating symlink..."
if ln -s "$EXTENSION_SOURCE" "$EXTENSION_DEST"; then
print_success "Extension installed successfully!"
echo
print_info "Next steps:"
print_info "1. Restart VSCode/VSCodium"
print_info "2. Open any .esc file to test the extension"
print_info "3. The language should be automatically detected as 'ASHES'"
echo
print_info "To uninstall, simply remove the symlink:"
print_info " rm '$EXTENSION_DEST'"
else
print_error "Failed to create symlink"
print_error "Make sure you have write permissions to: $EXTENSIONS_DIR"
exit 1
fi
}
# Run main function
main "$@"