|
| 1 | +# Objective: Implementation of `install.sh` Scaffolding Script |
| 2 | + |
| 3 | +The objective is to provide a robust, interactive shell script at the root of the repository that allows users to quickly bootstrap new projects based on this opinionated Gemini CLI framework. The script is designed to be run via `curl` and piped to `bash`. |
| 4 | + |
| 5 | +## Architectural Impact |
| 6 | +- **Developer Experience:** Simplifies the onboarding process for new projects. |
| 7 | +- **Project Structure:** Adds a new utility script (`install.sh`) to the repository root. |
| 8 | +- **Framework Integrity:** Ensures that all necessary configuration files (specifically the `.gemini/` directory) are preserved while user-specific content is reset. |
| 9 | + |
| 10 | +## File Operations |
| 11 | +- **Created File:** `install.sh` at the repository root. |
| 12 | + |
| 13 | +## Step-by-Step Execution |
| 14 | + |
| 15 | +### 1. Script Drafting |
| 16 | +Create `install.sh` with the following logic: |
| 17 | +- **Environment Checks:** Verify that `git` and `node` are installed. |
| 18 | +- **Interactive Prompts:** |
| 19 | + - Use `/dev/tty` for `read` commands to ensure compatibility with `curl | bash` execution. |
| 20 | + - Ask for the `Project Name`. |
| 21 | + - Ask for the `Target Directory` (defaulting to a kebab-case version of the project name). |
| 22 | +- **Core Scaffolding:** |
| 23 | + - Clone the `apiad/starter` repository using `--depth 1` for a fast, shallow clone. |
| 24 | + - Remove the `.git` directory and run `git init` to establish a new history. |
| 25 | +- **Content Reset:** |
| 26 | + - Overwrite `README.md` with a minimal title and template reference. |
| 27 | + - Overwrite `CHANGELOG.md` with a clean header. |
| 28 | + - Clear all markdown files from `journal/`, `plans/`, and `drafts/` while preserving `.gitkeep` files. |
| 29 | + - Generate a first journal entry for the current date (`journal/YYYY-MM-DD.md`). |
| 30 | +- **Finalization:** |
| 31 | + - Perform an initial `git add .` and `git commit -m "Initial commit"`. |
| 32 | + - Attempt to launch the `gemini` CLI command. |
| 33 | + |
| 34 | +### 2. Permissions (Informational) |
| 35 | +While the user will likely run this via `bash`, the script itself should be marked as executable in the repository for local use. |
| 36 | + |
| 37 | +## Proposed `install.sh` Content |
| 38 | + |
| 39 | +```bash |
| 40 | +#!/bin/bash |
| 41 | +set -e |
| 42 | + |
| 43 | +# --- Configuration --- |
| 44 | +REPO_URL="https://github.com/apiad/starter.git" |
| 45 | + |
| 46 | +# --- Functions --- |
| 47 | +error() { |
| 48 | + echo -e "\033[0;31m❌ Error: \$1\033[0m" >&2 |
| 49 | + exit 1 |
| 50 | +} |
| 51 | + |
| 52 | +# --- Check Prerequisites --- |
| 53 | +for cmd in git node; do |
| 54 | + if ! command -v "\$cmd" >/dev/null 2>&1; then |
| 55 | + error "\$cmd is not installed. Please install it and try again." |
| 56 | + fi |
| 57 | +done |
| 58 | + |
| 59 | +# --- Inputs --- |
| 60 | +# We use /dev/tty for input because curl | bash takes over stdin |
| 61 | +echo -n "Enter project name: " |
| 62 | +read PROJECT_NAME < /dev/tty |
| 63 | + |
| 64 | +if [[ -z "\$PROJECT_NAME" ]]; then |
| 65 | + error "Project name cannot be empty." |
| 66 | +fi |
| 67 | + |
| 68 | +# Sanitize project name for default target directory |
| 69 | +DEFAULT_TARGET=\$(echo "\$PROJECT_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g') |
| 70 | +echo -n "Enter target directory [\$DEFAULT_TARGET]: " |
| 71 | +read TARGET_DIR < /dev/tty |
| 72 | + |
| 73 | +TARGET_DIR=\${TARGET_DIR:-\$DEFAULT_TARGET} |
| 74 | + |
| 75 | +if [[ -d "\$TARGET_DIR" ]]; then |
| 76 | + error "Directory '\$TARGET_DIR' already exists. Choose a different directory or delete the existing one." |
| 77 | +fi |
| 78 | + |
| 79 | +# --- Execution --- |
| 80 | +echo "🚀 Scaffolding new project: \$PROJECT_NAME in \$TARGET_DIR..." |
| 81 | + |
| 82 | +# Clone the template |
| 83 | +git clone --depth 1 "\$REPO_URL" "\$TARGET_DIR" || error "Failed to clone template repository." |
| 84 | + |
| 85 | +cd "\$TARGET_DIR" |
| 86 | + |
| 87 | +# Reset Git History |
| 88 | +rm -rf .git |
| 89 | +git init -q |
| 90 | + |
| 91 | +# Reset Core Markdown Files |
| 92 | +cat <<EOF > README.md |
| 93 | +# \$PROJECT_NAME |
| 94 | +
|
| 95 | +This project was bootstrapped from [apiad/starter](https://github.com/apiad/starter). |
| 96 | +EOF |
| 97 | + |
| 98 | +cat <<EOF > CHANGELOG.md |
| 99 | +# Changelog |
| 100 | +
|
| 101 | +All notable changes to this project will be documented in this file. |
| 102 | +
|
| 103 | +## [Unreleased] |
| 104 | +- Initial project scaffold. |
| 105 | +EOF |
| 106 | + |
| 107 | +# Clear content directories but preserve .gitkeep |
| 108 | +for dir in journal plans drafts; do |
| 109 | + if [[ -d "\$dir" ]]; then |
| 110 | + find "\$dir" -maxdepth 1 -type f ! -name ".gitkeep" -delete |
| 111 | + touch "\$dir/.gitkeep" |
| 112 | + fi |
| 113 | +done |
| 114 | + |
| 115 | +# Create first journal entry |
| 116 | +TODAY=\$(date +%Y-%m-%d) |
| 117 | +cat <<EOF > "journal/\$TODAY.md" |
| 118 | +# \$TODAY - Initial Kickoff |
| 119 | +
|
| 120 | +Started the project "\$PROJECT_NAME" using the Gemini CLI framework. |
| 121 | +EOF |
| 122 | + |
| 123 | +# --- Post-Install --- |
| 124 | +git add . |
| 125 | +git commit -m "Initial commit" -q |
| 126 | + |
| 127 | +echo "✅ Project \$PROJECT_NAME scaffolded successfully!" |
| 128 | +echo "🚀 Starting Gemini CLI..." |
| 129 | + |
| 130 | +# Run the gemini CLI |
| 131 | +if command -v gemini >/dev/null 2>&1; then |
| 132 | + exec gemini |
| 133 | +else |
| 134 | + echo "⚠️ 'gemini' command not found. Please ensure the Gemini CLI is installed and in your PATH." |
| 135 | +fi |
| 136 | +``` |
0 commit comments