From fce177a0df4ca3a70c6e6397ec8a493ec99b6c08 Mon Sep 17 00:00:00 2001 From: Aditya Gupta Date: Sat, 20 Jun 2026 19:33:52 +0530 Subject: [PATCH] refactor: Improve project scaffolding --- .agents/skills/add_installer/SKILL.md | 13 ++++++++----- VERSION | 2 +- pixel_art.ansi => assets/pixel_art.ansi | 0 b.sh | 2 +- bootstrap.sh | 12 ++++++------ registry.sh => lib/registry.sh | 0 routes.sh => lib/routes.sh | 12 ++++++------ readme.md | 2 +- scripts/generate_registry.sh | 2 +- scripts/pre-commit | 2 +- 10 files changed, 25 insertions(+), 22 deletions(-) rename pixel_art.ansi => assets/pixel_art.ansi (100%) rename registry.sh => lib/registry.sh (100%) rename routes.sh => lib/routes.sh (94%) diff --git a/.agents/skills/add_installer/SKILL.md b/.agents/skills/add_installer/SKILL.md index fda6442..04fe3d1 100644 --- a/.agents/skills/add_installer/SKILL.md +++ b/.agents/skills/add_installer/SKILL.md @@ -16,12 +16,15 @@ Bootstrap CLI (`b`) is a bash-based tool installer and system bootstrapper. User ``` bootstrap/ ├── installers/ # Individual installer scripts (install_.sh) -├── lib/ # Shared libraries sourced by all installers +├── lib/ # Shared libraries and router sourced by all installers │ ├── common.sh # Logging, confirm(), has_command(), make_temp_dir() │ ├── platform.sh # detect_distro(), detect_arch(), pkg_install() -│ └── shell_config.sh # get_shell_configs(), inject_block(), remove_block(), add_alias_if_missing(), add_env_if_missing() +│ ├── shell_config.sh # get_shell_configs(), inject_block(), remove_block(), add_alias_if_missing(), add_env_if_missing() +│ ├── registry.sh # Dynamically generated installer registry +│ └── routes.sh # Central router script ├── commands/ # Non-installer commands (help, con, uninstall) -├── routes.sh # Central router + installer registry +├── assets/ # Assets (logo art, etc.) +│ └── pixel_art.ansi ├── bootstrap.sh # Metascript for environment setup + library loading ├── b.sh # The `b` shell function and autocompletion └── VERSION @@ -44,7 +47,7 @@ At the top of your new installer script, right below `#!/usr/bin/env bash`, add # Description: ``` -The central router `routes.sh` and autocomplete function in `b.sh` will dynamically parse this metadata from all `install_*.sh` scripts to register the installer and keys automatically! No manual edits to `routes.sh` or `b.sh` are required. +The central router `lib/routes.sh` and autocomplete function in `b.sh` will dynamically parse this metadata from all `install_*.sh` scripts to register the installer and keys automatically! No manual edits to `lib/routes.sh` or `b.sh` are required. ### Step 3: Verify (optional) @@ -252,7 +255,7 @@ inject_block "$config_file" " init" 'eval "$(tool init bash)"' ## Rules & Conventions 1. **File naming**: Always `install_.sh` in the `installers/` directory. -2. **Alphabetical order**: Keep `INSTALLERS` entries and `INSTALLER_KEYS` in alphabetical order in `routes.sh`. +2. **Registry generation**: The registry in `lib/registry.sh` is automatically generated by `scripts/generate_registry.sh` (run automatically on commit by the git pre-commit hook). 3. **Confirmation prompts**: Always ask before installing. Check if already installed first. 4. **Idempotent**: Installers must be safe to re-run. Use `inject_block` (not append) for shell configs. 5. **No hardcoded paths**: Use `$HOME`, library functions, and `detect_*` helpers. diff --git a/VERSION b/VERSION index 781dcb0..65087b4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.3 +1.1.4 diff --git a/pixel_art.ansi b/assets/pixel_art.ansi similarity index 100% rename from pixel_art.ansi rename to assets/pixel_art.ansi diff --git a/b.sh b/b.sh index 44b749e..c38d0d3 100755 --- a/b.sh +++ b/b.sh @@ -7,7 +7,7 @@ b() { fi local routes_dir="$HOME/.config/bootstrap" - local routes_file="$routes_dir/routes.sh" + local routes_file="$routes_dir/lib/routes.sh" local last_update_file="$routes_dir/.last_b_update" local current_time diff --git a/bootstrap.sh b/bootstrap.sh index 3e9c644..23fa998 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -89,8 +89,8 @@ install_bootstrap() { local files=( "VERSION" "b.sh" - "routes.sh" - "registry.sh" + "lib/routes.sh" + "lib/registry.sh" "lib/common.sh" "lib/platform.sh" "lib/shell_config.sh" @@ -100,7 +100,7 @@ install_bootstrap() { "commands/up.sh" ) - if [ -f "$_SCRIPT_DIR/b.sh" ] && [ -f "$_SCRIPT_DIR/routes.sh" ]; then + if [ -f "$_SCRIPT_DIR/b.sh" ] && [ -f "$_SCRIPT_DIR/lib/routes.sh" ]; then log_info "Using local files from repository..." for file in "${files[@]}"; do mkdir -p "$(dirname "$routes_dir/$file")" @@ -221,7 +221,7 @@ if [ "$is_sourced" = false ]; then clear 2>/dev/null || true # Locate or download pixel_art.ansi and VERSION - _art_file="$_SCRIPT_DIR/pixel_art.ansi" + _art_file="$_SCRIPT_DIR/assets/pixel_art.ansi" _version_file="$_SCRIPT_DIR/VERSION" if [ ! -f "$_art_file" ]; then @@ -231,10 +231,10 @@ if [ "$is_sourced" = false ]; then _base_url="${_BASE_URL:-https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master}" if [ ! -f "$_art_file" ]; then if command -v curl >/dev/null 2>&1; then - curl -fsSL -o "$_art_file" "$_base_url/pixel_art.ansi" 2>/dev/null + curl -fsSL -o "$_art_file" "$_base_url/assets/pixel_art.ansi" 2>/dev/null curl -fsSL -o "$_version_file" "$_base_url/VERSION" 2>/dev/null elif command -v wget >/dev/null 2>&1; then - wget -qO "$_art_file" "$_base_url/pixel_art.ansi" 2>/dev/null + wget -qO "$_art_file" "$_base_url/assets/pixel_art.ansi" 2>/dev/null wget -qO "$_version_file" "$_base_url/VERSION" 2>/dev/null fi fi diff --git a/registry.sh b/lib/registry.sh similarity index 100% rename from registry.sh rename to lib/registry.sh diff --git a/routes.sh b/lib/routes.sh similarity index 94% rename from routes.sh rename to lib/routes.sh index 330b2cf..f08a949 100755 --- a/routes.sh +++ b/lib/routes.sh @@ -20,19 +20,19 @@ _SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd 2>/dev/null || pwd)" # Source registry if [ -f "$_SCRIPT_DIR/registry.sh" ]; then . "$_SCRIPT_DIR/registry.sh" -elif [ -f "$BOOTSTRAP_DIR/registry.sh" ]; then - . "$BOOTSTRAP_DIR/registry.sh" +elif [ -f "$BOOTSTRAP_DIR/lib/registry.sh" ]; then + . "$BOOTSTRAP_DIR/lib/registry.sh" else # Standalone/remote fallback: download registry _tmp_registry=$(mktemp) BOOTSTRAP_BASE_URL="${BOOTSTRAP_BASE_URL:-https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master}" BOOTSTRAP_FALLBACK_URL="${BOOTSTRAP_FALLBACK_URL:-https://raw.githubusercontent.com/sortedcord/bootstrap/refs/heads/master}" if has_command curl; then - curl -fsSL "${BOOTSTRAP_BASE_URL}/registry.sh" -o "$_tmp_registry" 2>/dev/null || \ - curl -fsSL "${BOOTSTRAP_FALLBACK_URL}/registry.sh" -o "$_tmp_registry" 2>/dev/null + curl -fsSL "${BOOTSTRAP_BASE_URL}/lib/registry.sh" -o "$_tmp_registry" 2>/dev/null || \ + curl -fsSL "${BOOTSTRAP_FALLBACK_URL}/lib/registry.sh" -o "$_tmp_registry" 2>/dev/null elif has_command wget; then - wget -qO "$_tmp_registry" "${BOOTSTRAP_BASE_URL}/registry.sh" 2>/dev/null || \ - wget -qO "$_tmp_registry" "${BOOTSTRAP_FALLBACK_URL}/registry.sh" 2>/dev/null + wget -qO "$_tmp_registry" "${BOOTSTRAP_BASE_URL}/lib/registry.sh" 2>/dev/null || \ + wget -qO "$_tmp_registry" "${BOOTSTRAP_FALLBACK_URL}/lib/registry.sh" 2>/dev/null fi if [ -s "$_tmp_registry" ]; then . "$_tmp_registry" diff --git a/readme.md b/readme.md index e2bc4b4..7942f7e 100644 --- a/readme.md +++ b/readme.md @@ -137,7 +137,7 @@ If you want to audit the core Bootstrap CLI itself before running it: ```bash curl -fsSL https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/bootstrap.sh -curl -fsSL https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/routes.sh +curl -fsSL https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/lib/routes.sh ``` and review the contents before piping it into a shell. diff --git a/scripts/generate_registry.sh b/scripts/generate_registry.sh index 5dc8251..39933e2 100755 --- a/scripts/generate_registry.sh +++ b/scripts/generate_registry.sh @@ -6,7 +6,7 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_DIR="$(dirname "$SCRIPT_DIR")" INSTALLERS_DIR="$REPO_DIR/installers" -REGISTRY_FILE="$REPO_DIR/registry.sh" +REGISTRY_FILE="$REPO_DIR/lib/registry.sh" echo "==> Generating registry.sh..." diff --git a/scripts/pre-commit b/scripts/pre-commit index df4bde7..d550057 100644 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -7,7 +7,7 @@ set -euo pipefail # Generate the registry dynamically and stage it if [ -f "./scripts/generate_registry.sh" ]; then ./scripts/generate_registry.sh - git add registry.sh + git add lib/registry.sh fi VERSION_FILE="VERSION"