33
44# --- Configuration ---
55REPO_URL=" https://github.com/apiad/starter.git"
6- VERSION=" 0.10.1 "
6+ VERSION=" 0.11.0 "
77
88# --- Functions ---
99banner () {
@@ -23,82 +23,143 @@ error() {
2323 exit 1
2424}
2525
26+ confirm () {
27+ echo -n " $1 [y/N]: "
28+ read CONFIRM < /dev/tty
29+ if [[ ! " $CONFIRM " =~ ^[Yy]$ ]]; then
30+ echo " Aborted by user."
31+ exit 0
32+ fi
33+ }
34+
2635# --- Check Prerequisites ---
2736for cmd in git node; do
2837 if ! command -v " $cmd " > /dev/null 2>&1 ; then
2938 error " $cmd is not installed. Please install it and try again."
3039 fi
3140done
3241
33- # --- Inputs ---
34- # We use /dev/tty for input because curl | bash takes over stdin
35- banner
36-
37- echo -n " Enter project name: "
38- read PROJECT_NAME < /dev/tty
39-
40- if [[ -z " $PROJECT_NAME " ]]; then
41- error " Project name cannot be empty."
42+ # --- Git Environment Validation ---
43+ if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1 ; then
44+ echo " 📂 Initializing git repository..."
45+ git init -q
4246fi
4347
44- # Sanitize project name for default target directory
45- DEFAULT_TARGET=$( echo " $PROJECT_NAME " | tr ' [:upper:]' ' [:lower:]' | sed ' s/[^a-z0-9]/-/g' )
46- echo -n " Enter target directory [$DEFAULT_TARGET ]: "
47- read TARGET_DIR < /dev/tty
48+ if [[ -n $( git status --porcelain) ]]; then
49+ error " Working tree is not clean. Please commit or stash your changes before running this script."
50+ fi
4851
49- TARGET_DIR=${TARGET_DIR:- $DEFAULT_TARGET }
52+ # --- Inputs ---
53+ banner
5054
51- if [[ -d " $TARGET_DIR " ]]; then
52- error " Directory '$TARGET_DIR ' already exists. Choose a different directory or delete the existing one."
55+ # --- Acquisition ---
56+ echo " 🚀 Fetching latest framework from $REPO_URL ..."
57+ TEMP_DIR=$( mktemp -d)
58+ trap ' rm -rf "$TEMP_DIR"' EXIT
59+
60+ git clone --depth 1 -q " $REPO_URL " " $TEMP_DIR " || error " Failed to clone template repository."
61+
62+ # --- Discovery ---
63+ FILES_TO_EXTRACT=(
64+ " GEMINI.md"
65+ " makefile"
66+ " TASKS.md"
67+ " CHANGELOG.md"
68+ " README.md"
69+ )
70+
71+ CONTENT_DIRS=(
72+ " journal"
73+ " plans"
74+ " research"
75+ " drafts"
76+ )
77+
78+ WILL_CREATE=()
79+ WILL_UPDATE=()
80+
81+ # Check .gemini directory
82+ if [[ -d " .gemini" ]]; then
83+ WILL_UPDATE+=(" .gemini/ (core framework)" )
84+ else
85+ WILL_CREATE+=(" .gemini/ (core framework)" )
5386fi
5487
55- # --- Execution ---
56- echo " 🚀 Scaffolding new project: $PROJECT_NAME in $TARGET_DIR ..."
88+ # Check top-level files
89+ for f in " ${FILES_TO_EXTRACT[@]} " ; do
90+ if [[ -e " $f " ]]; then
91+ WILL_UPDATE+=(" $f " )
92+ else
93+ WILL_CREATE+=(" $f " )
94+ fi
95+ done
5796
58- # Clone the template
59- git clone --depth 1 " $REPO_URL " " $TARGET_DIR " || error " Failed to clone template repository."
97+ # Check content directories
98+ for d in " ${CONTENT_DIRS[@]} " ; do
99+ if [[ ! -d " $d " ]]; then
100+ WILL_CREATE+=(" $d /" )
101+ fi
102+ done
60103
61- cd " $TARGET_DIR "
104+ # --- Summary & Confirmation ---
105+ echo -e " \033[1;33mProposed Changes:\033[0m"
106+ if [[ ${# WILL_CREATE[@]} -gt 0 ]]; then
107+ echo -e " \033[1;32mNew files/folders to create:\033[0m"
108+ for f in " ${WILL_CREATE[@]} " ; do echo " + $f " ; done
109+ fi
62110
63- # Reset Git History
64- rm -rf .git
65- git init -q
111+ if [[ ${# WILL_UPDATE[@]} -gt 0 ]]; then
112+ echo -e " \033[1;34mExisting files/folders to update (framework only):\033[0m"
113+ for f in " ${WILL_UPDATE[@]} " ; do echo " ~ $f " ; done
114+ fi
66115
67- # Reset Core Markdown Files
68- cat << EOF > README.md
69- # $PROJECT_NAME
116+ echo " "
117+ confirm " Do you want to proceed with these changes?"
70118
71- This project was bootstrapped from [apiad/starter](https://github.com/apiad/starter).
72- EOF
119+ # --- Execution ---
120+ IS_UPDATE=false
121+ if [[ -d " .gemini" ]]; then
122+ IS_UPDATE=true
123+ fi
73124
74- cat << EOF > CHANGELOG.md
75- # Changelog
125+ echo " 🛠️ Applying changes..."
76126
77- All notable changes to this project will be documented in this file.
127+ # 1. Update .gemini (non-destructive for user files)
128+ mkdir -p .gemini
129+ cp -r " $TEMP_DIR /.gemini/." .gemini/
78130
79- ## [Unreleased]
80- - Initial project scaffold.
81- EOF
131+ # 2. Update Top-Level Files
132+ for f in " ${FILES_TO_EXTRACT[@]} " ; do
133+ cp " $TEMP_DIR /$f " .
134+ done
82135
83- # Clear content directories but preserve .gitkeep
84- for dir in journal plans drafts ; do
85- if [[ -d " $dir " ]] ; then
86- find " $dir " -maxdepth 1 -type f ! -name " .gitkeep" -delete
87- touch " $dir / .gitkeep"
136+ # 3. Ensure Content Directories & .gitkeep
137+ for d in " ${CONTENT_DIRS[@]} " ; do
138+ mkdir -p " $d "
139+ if [[ -f " $TEMP_DIR / $d / .gitkeep" ]] ; then
140+ cp " $TEMP_DIR / $d / .gitkeep" " $d / "
88141 fi
89142done
90143
91- # Create first journal entry
144+ # 4. Journal Entry
92145TODAY=$( date +%Y-%m-%d)
93- cat << EOF > "journal/$TODAY .md"
94- # $TODAY - Initial Kickoff
146+ mkdir -p journal
147+ JOURNAL_FILE=" journal/$TODAY .md"
148+ if [[ ! -f " $JOURNAL_FILE " ]]; then
149+ echo " # $TODAY " > " $JOURNAL_FILE "
150+ fi
95151
96- Started the project "$PROJECT_NAME " using the Gemini CLI framework.
97- EOF
152+ if $IS_UPDATE ; then
153+ echo -e " \n## Gemini CLI Update\n- Updated framework to version $VERSION ." >> " $JOURNAL_FILE "
154+ COMMIT_MSG=" chore: update Gemini CLI framework to v$VERSION "
155+ else
156+ echo -e " \n## Gemini CLI Integration\n- Integrated Gemini CLI framework v$VERSION ." >> " $JOURNAL_FILE "
157+ COMMIT_MSG=" feat: integrate Gemini CLI framework v$VERSION "
158+ fi
98159
99160# --- Post-Install ---
100161git add .
101- git commit -m " Initial commit " -q
162+ git commit -m " $COMMIT_MSG " -q
102163
103- echo " ✅ Project $PROJECT_NAME scaffolded successfully!"
104- echo " 🚀 Run 'gemini /onboard' to get started with your new project !"
164+ echo " ✅ Gemini CLI framework $( [ " $IS_UPDATE " = true ] && echo " updated " || echo " integrated " ) successfully!"
165+ echo " 🚀 Run 'gemini /onboard' to get started!"
0 commit comments