|
#!/usr/bin/env bash |
|
|
|
############################################################################### |
|
# VS Code Extension Installer |
|
# ----------------------------------------------------------------------------- |
|
# Installs a focused set of Visual Studio Code extensions for: |
|
# |
|
# - Nuxt 3 and Nuxt 4 |
|
# - Vue 3 |
|
# - TypeScript |
|
# - ESLint |
|
# - Prettier |
|
# - Git and GitHub workflows |
|
# |
|
# Supported environments: |
|
# |
|
# - Git Bash on Windows 11 |
|
# - WSL with access to the Windows VS Code CLI |
|
# - Bash terminals on macOS and Linux |
|
# |
|
# Requirements: |
|
# |
|
# - Visual Studio Code |
|
# - The VS Code CLI command: code |
|
# |
|
# Usage: |
|
# |
|
# bash install-vscode-extensions.sh |
|
# |
|
# Optional: |
|
# |
|
# bash install-vscode-extensions.sh --with-tailwind |
|
# |
|
############################################################################### |
|
|
|
set -u |
|
set -o pipefail |
|
|
|
|
|
# ---------------------------- |
|
# OUTPUT HELPERS |
|
# ---------------------------- |
|
|
|
print_header() { |
|
printf '%s\n' "---------------------------------------------------------" |
|
printf '%s\n' " VS Code Extension Installer" |
|
printf '%s\n' " Nuxt 3/4, Vue, TypeScript, ESLint and Prettier" |
|
printf '%s\n' "---------------------------------------------------------" |
|
printf '\n' |
|
} |
|
|
|
|
|
print_usage() { |
|
cat <<'EOF' |
|
Usage: |
|
|
|
bash install-vscode-extensions.sh |
|
bash install-vscode-extensions.sh --with-tailwind |
|
bash install-vscode-extensions.sh --help |
|
|
|
Options: |
|
|
|
--with-tailwind Also install Tailwind CSS IntelliSense |
|
--help Display this help message |
|
EOF |
|
} |
|
|
|
|
|
command_exists() { |
|
command -v "$1" >/dev/null 2>&1 |
|
} |
|
|
|
|
|
# ---------------------------- |
|
# ARGUMENTS |
|
# ---------------------------- |
|
|
|
INSTALL_TAILWIND=false |
|
|
|
while [[ $# -gt 0 ]]; do |
|
case "$1" in |
|
--with-tailwind) |
|
INSTALL_TAILWIND=true |
|
shift |
|
;; |
|
--help | -h) |
|
print_usage |
|
exit 0 |
|
;; |
|
*) |
|
printf 'β Unknown option: %s\n\n' "$1" >&2 |
|
print_usage >&2 |
|
exit 1 |
|
;; |
|
esac |
|
done |
|
|
|
|
|
# ---------------------------- |
|
# VS CODE CLI DETECTION |
|
# ---------------------------- |
|
|
|
find_vscode_cli() { |
|
if command_exists code; then |
|
printf '%s\n' "code" |
|
return 0 |
|
fi |
|
|
|
if command_exists code-insiders; then |
|
printf '%s\n' "code-insiders" |
|
return 0 |
|
fi |
|
|
|
# Common Windows installation locations visible from Git Bash. |
|
local windows_candidates=( |
|
"/c/Users/${USERNAME:-}/AppData/Local/Programs/Microsoft VS Code/bin/code" |
|
"/c/Program Files/Microsoft VS Code/bin/code" |
|
"/c/Program Files (x86)/Microsoft VS Code/bin/code" |
|
) |
|
|
|
local candidate |
|
|
|
for candidate in "${windows_candidates[@]}"; do |
|
if [[ -x "$candidate" ]]; then |
|
printf '%s\n' "$candidate" |
|
return 0 |
|
fi |
|
done |
|
|
|
# Common Windows installation locations visible from WSL. |
|
local wsl_candidates=( |
|
"/mnt/c/Users/${USERNAME:-}/AppData/Local/Programs/Microsoft VS Code/bin/code" |
|
"/mnt/c/Program Files/Microsoft VS Code/bin/code" |
|
"/mnt/c/Program Files (x86)/Microsoft VS Code/bin/code" |
|
) |
|
|
|
for candidate in "${wsl_candidates[@]}"; do |
|
if [[ -x "$candidate" ]]; then |
|
printf '%s\n' "$candidate" |
|
return 0 |
|
fi |
|
done |
|
|
|
return 1 |
|
} |
|
|
|
|
|
print_header |
|
|
|
if ! VSCODE_CLI="$(find_vscode_cli)"; then |
|
printf '%s\n' "β ERROR: The Visual Studio Code CLI could not be found." |
|
printf '\n' |
|
printf '%s\n' "Install Visual Studio Code and ensure the 'code' command is available." |
|
printf '\n' |
|
printf '%s\n' "In VS Code, open the Command Palette and run:" |
|
printf '%s\n' " Shell Command: Install 'code' command in PATH" |
|
printf '\n' |
|
printf '%s\n' "On Windows, reinstalling or modifying VS Code with" |
|
printf '%s\n' "'Add to PATH' enabled may also resolve the problem." |
|
exit 1 |
|
fi |
|
|
|
printf 'Using VS Code CLI: %s\n\n' "$VSCODE_CLI" |
|
|
|
|
|
# ---------------------------- |
|
# EXTENSIONS |
|
# ---------------------------- |
|
|
|
# Core extensions for Nuxt 3/4 development. |
|
# |
|
# Vue (Official) provides Vue SFC and TypeScript language support. |
|
# ESLint handles project linting and automatic fixes. |
|
# Prettier handles project formatting. |
|
# |
|
# Nuxt itself does not require a separate extension pack. |
|
|
|
EXTENSIONS=( |
|
# Vue 3 and Nuxt SFC language support |
|
"Vue.volar" |
|
|
|
# ESLint integration |
|
"dbaeumer.vscode-eslint" |
|
|
|
# Prettier formatting |
|
"esbenp.prettier-vscode" |
|
|
|
# Path completion |
|
"christian-kohler.path-intellisense" |
|
|
|
# Git history, blame and repository tooling |
|
"eamodio.gitlens" |
|
|
|
# GitHub pull requests and issues |
|
"GitHub.vscode-pull-request-github" |
|
|
|
# Environment-file syntax highlighting |
|
"mikestead.dotenv" |
|
) |
|
|
|
|
|
# Tailwind is optional because not every Nuxt project uses it. |
|
if [[ "$INSTALL_TAILWIND" == true ]]; then |
|
EXTENSIONS+=( |
|
"bradlc.vscode-tailwindcss" |
|
) |
|
fi |
|
|
|
|
|
# ---------------------------- |
|
# INSTALLATION |
|
# ---------------------------- |
|
|
|
SUCCESS_COUNT=0 |
|
FAILURE_COUNT=0 |
|
SKIPPED_COUNT=0 |
|
|
|
FAILED_EXTENSIONS=() |
|
|
|
printf '%s\n' "π¦ Installing VS Code extensions..." |
|
printf '\n' |
|
|
|
|
|
for extension in "${EXTENSIONS[@]}"; do |
|
printf 'β %s\n' "$extension" |
|
|
|
# Determine whether the extension is already installed. |
|
if "$VSCODE_CLI" --list-extensions 2>/dev/null | |
|
grep -Fqi -- "$extension"; then |
|
printf '%s\n' " β» Already installed; checking for updates" |
|
fi |
|
|
|
# --force installs the extension or updates an existing installation. |
|
if "$VSCODE_CLI" \ |
|
--install-extension "$extension" \ |
|
--force \ |
|
>/dev/null 2>&1; then |
|
printf '%s\n' " β Installed or updated" |
|
SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) |
|
else |
|
printf '%s\n' " β Installation failed" |
|
FAILURE_COUNT=$((FAILURE_COUNT + 1)) |
|
FAILED_EXTENSIONS+=("$extension") |
|
fi |
|
|
|
printf '\n' |
|
done |
|
|
|
|
|
# ---------------------------- |
|
# RESULTS |
|
# ---------------------------- |
|
|
|
printf '%s\n' "---------------------------------------------------------" |
|
printf '%s\n' " Installation Complete" |
|
printf '%s\n' "---------------------------------------------------------" |
|
printf 'β Successful installs or updates: %d\n' "$SUCCESS_COUNT" |
|
printf 'β Failed installs: %d\n' "$FAILURE_COUNT" |
|
|
|
if [[ "$INSTALL_TAILWIND" == true ]]; then |
|
printf '%s\n' "β Tailwind CSS IntelliSense: requested" |
|
else |
|
printf '%s\n' "βΉ Tailwind CSS IntelliSense: not requested" |
|
fi |
|
|
|
printf '\n' |
|
|
|
|
|
if [[ "$FAILURE_COUNT" -gt 0 ]]; then |
|
printf '%s\n' "The following extensions failed:" |
|
printf '\n' |
|
|
|
for extension in "${FAILED_EXTENSIONS[@]}"; do |
|
printf ' - %s\n' "$extension" |
|
done |
|
|
|
printf '\n' |
|
printf '%s\n' "Run the script again or install those extensions manually." |
|
printf '%s\n' "Review the terminal output from this command for more details:" |
|
printf '\n' |
|
|
|
for extension in "${FAILED_EXTENSIONS[@]}"; do |
|
printf ' %q --install-extension %q --force\n' \ |
|
"$VSCODE_CLI" \ |
|
"$extension" |
|
done |
|
|
|
printf '\n' |
|
exit 1 |
|
fi |
|
|
|
|
|
printf '%s\n' "All requested extensions were installed successfully." |
|
printf '%s\n' "Restart or reload VS Code so every extension is activated." |
|
printf '\n' |
|
printf '%s\n' "In VS Code, use:" |
|
printf '%s\n' " Ctrl+Shift+P β Developer: Reload Window" |
|
printf '%s\n' "---------------------------------------------------------" |
|
|
|
exit 0 |