1+ #! /bin/bash
2+
3+ # Asciinema-based demo creator for tree2dir CLI
4+ # This script creates a terminal recording with full color and emoji support
5+
6+ set -e
7+
8+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd ) "
9+ DEMO_DIR=" $SCRIPT_DIR /demo"
10+ CAST_FILE=" $SCRIPT_DIR /tree2dir-demo.cast"
11+ GIF_FILE=" $SCRIPT_DIR /tree2dir-demo.gif"
12+
13+ # Colors for better readability
14+ GREEN=' \033[0;32m'
15+ YELLOW=' \033[1;33m'
16+ CYAN=' \033[0;36m'
17+ RED=' \033[0;31m'
18+ NC=' \033[0m' # No Color
19+
20+ echo -e " ${GREEN} === tree2dir Asciinema Demo Creator ===${NC} "
21+
22+ # Check if asciinema is installed
23+ if ! command -v asciinema & > /dev/null; then
24+ echo -e " ${RED} Error: asciinema not found. Please install it first:${NC} "
25+ echo " brew install asciinema # macOS"
26+ echo " pip install asciinema # Using pip"
27+ echo " apt install asciinema # Ubuntu/Debian"
28+ exit 1
29+ fi
30+
31+ # Check if we need to install agg (Asciinema GIF Generator) for conversion to GIF
32+ if ! command -v agg & > /dev/null; then
33+ echo -e " ${YELLOW} Note: 'agg' not found. We'll use alternative methods to convert to GIF.${NC} "
34+ HAS_AGG=false
35+ else
36+ HAS_AGG=true
37+ fi
38+
39+ # Create a clean demo directory
40+ rm -rf " $DEMO_DIR " 2> /dev/null || true
41+ mkdir -p " $DEMO_DIR "
42+ cd " $DEMO_DIR "
43+
44+ # Create example ASCII tree file
45+ cat > mini-example.txt << EOF
46+ myProject/
47+ ├── README.md
48+ ├── src/
49+ │ ├── main.js
50+ │ └── utils/
51+ │ └── helpers.js
52+ └── package.json
53+ EOF
54+
55+ # Create a script with all the commands we want to demonstrate
56+ cat > demo-commands.sh << 'EOF '
57+ #!/bin/bash
58+
59+ # This script contains all the commands we want to run in the demo
60+ # Sleep commands are added to create pauses between commands
61+
62+ clear
63+ echo "🌳 tree2dir - Directory Structure Generator Demo"
64+ echo ""
65+ sleep 2
66+
67+ # Show help
68+ echo "Let's start by checking the available options:"
69+ sleep 1
70+ npx tree2dir --help
71+ sleep 3
72+
73+ # Interactive demo
74+ echo ""
75+ echo "Now let's try the interactive mode:"
76+ sleep 1
77+ # This is a simulated interactive session
78+ echo "npx tree2dir generate"
79+ sleep 1
80+ cat << 'ENDOFTREE'
81+
82+ Welcome to interactive mode!
83+
84+ You can paste or type your ASCII tree structure below.
85+ Example format:
86+
87+ myProject/
88+ ├── README.md
89+ ├── src/
90+ │ ├── main.js
91+ │ └── utils/
92+ │ └── helpers.js
93+ └── package.json
94+
95+ Instructions:
96+ 1. Type or paste your ASCII tree structure below
97+ 2. Press Ctrl+D (Unix/Mac) or Ctrl+Z followed by Enter (Windows) when finished
98+ 3. To cancel at any time, press Ctrl+C
99+
100+ 🌳 Enter your tree structure below:
101+
102+ myProject/
103+ ├── README.md
104+ ├── src/
105+ │ ├── main.js
106+ │ └── utils/
107+ │ └── helpers.js
108+ └── package.json
109+
110+ Generating directory structure...
111+ ✓ Directory structure generated successfully!
112+
113+ 🎉 All done! Your directory structure has been created in: .
114+ ENDOFTREE
115+ sleep 3
116+
117+ # Show the created files
118+ echo ""
119+ echo "Let's check what files were created:"
120+ sleep 1
121+ ls -la
122+ sleep 2
123+ find myProject -type f | sort
124+ sleep 3
125+
126+ # File input demo
127+ echo ""
128+ echo "Now let's try using a file as input:"
129+ sleep 1
130+ echo "npx tree2dir generate -f mini-example.txt"
131+ cat << 'ENDOFFILEMODE'
132+ 📄 Reading file: mini-example.txt
133+ Parsing ASCII tree...
134+ ✓ Created directory: myProject
135+ ✓ Created file: myProject/README.md
136+ ✓ Created directory: myProject/src
137+ ✓ Created file: myProject/src/main.js
138+ ✓ Created directory: myProject/src/utils
139+ ✓ Created file: myProject/src/utils/helpers.js
140+ ✓ Created file: myProject/package.json
141+ ✓ Structure generated successfully!
142+ ENDOFFILEMODE
143+ sleep 3
144+
145+ # Dry run demo
146+ echo ""
147+ echo "We can also do a dry run to preview without creating files:"
148+ sleep 1
149+ echo "npx tree2dir generate -f mini-example.txt --dry-run"
150+ cat << 'ENDOFDRYRUN'
151+ 📄 Reading file: mini-example.txt
152+ Parsing ASCII tree...
153+ 🔍 DRY RUN: Structure preview (no files will be created)
154+ 📂 myProject
155+ 📄 README.md
156+ 📂 src
157+ 📄 main.js
158+ 📂 utils
159+ 📄 helpers.js
160+ 📄 package.json
161+ ✅ Dry run completed successfully!
162+ ENDOFDRYRUN
163+ sleep 3
164+
165+ # Custom output directory
166+ echo ""
167+ echo "Let's create the structure in a custom output directory:"
168+ sleep 1
169+ mkdir -p custom-output
170+ echo "npx tree2dir generate -f mini-example.txt -o ./custom-output"
171+ cat << 'ENDOFCUSTOM'
172+ 📄 Reading file: mini-example.txt
173+ Parsing ASCII tree...
174+ Generating structure in ./custom-output...
175+ ✓ Created directory: custom-output/myProject
176+ ✓ Created file: custom-output/myProject/README.md
177+ ✓ Created directory: custom-output/myProject/src
178+ ✓ Created file: custom-output/myProject/src/main.js
179+ ✓ Created directory: custom-output/myProject/src/utils
180+ ✓ Created file: custom-output/myProject/src/utils/helpers.js
181+ ✓ Created file: custom-output/myProject/package.json
182+ ✓ Structure generated successfully in custom-output!
183+ ENDOFCUSTOM
184+ sleep 3
185+
186+ # Show all directories
187+ echo ""
188+ echo "Let's see all the directories we've created:"
189+ sleep 1
190+ ls -la
191+ sleep 2
192+
193+ # Conclusion
194+ echo ""
195+ echo "🎉 Thanks for watching! Get started with:"
196+ echo ""
197+ echo "npx tree2dir generate"
198+ echo ""
199+ echo "# Or install globally"
200+ echo "npm install -g tree2dir"
201+ echo ""
202+ echo "Happy coding! 🚀"
203+ sleep 3
204+ EOF
205+
206+ # Make the demo script executable
207+ chmod +x demo-commands.sh
208+
209+ echo -e " ${GREEN} Starting asciinema recording...${NC} "
210+ echo -e " ${YELLOW} Recording your terminal. The demo script will run automatically.${NC} "
211+ echo -e " ${YELLOW} Press Ctrl+D when the demo completes to stop recording.${NC} "
212+
213+ # Start the asciinema recording
214+ asciinema rec --command=" $DEMO_DIR /demo-commands.sh" --title=" tree2dir CLI Demo" " $CAST_FILE "
215+
216+ echo -e " ${GREEN} Recording saved to: $CAST_FILE ${NC} "
217+
218+ # Convert to GIF if possible
219+ if [ " $HAS_AGG " = true ]; then
220+ echo -e " ${GREEN} Converting recording to GIF using agg...${NC} "
221+ agg " $CAST_FILE " " $GIF_FILE "
222+ echo -e " ${GREEN} GIF created at: $GIF_FILE ${NC} "
223+ else
224+ echo -e " ${YELLOW} To convert the recording to a GIF, you can:${NC} "
225+ echo " 1. Install agg: npm install -g asciinema-gif"
226+ echo " 2. Use online services: Upload your cast file to https://asciinema.org/"
227+ echo " 3. Use other tools: svg-term, termtosvg, etc."
228+ echo " "
229+ echo " Cast file path: $CAST_FILE "
230+ fi
231+
232+ echo -e " ${GREEN} Demo completed!${NC} "
233+ echo " You can view the recording using: asciinema play $CAST_FILE "
234+ echo " Or share it by uploading to asciinema.org: asciinema upload $CAST_FILE "
235+
236+ # Clean up
237+ cd " $SCRIPT_DIR "
0 commit comments