8.0 KiB
Developer Documentation
Project Structure
ftc-project-gen-1.0.0-beta/
├── ftc-new-project # Main entry point (Linux/macOS)
├── ftc-new-project.bat # Main entry point (Windows)
├── VERSION # Version file (1.0.0-beta)
├── README.md # User documentation
├── CHANGELOG.md # Version history
├── DEVELOPER.md # This file
│
├── linux/ # Linux-specific implementation
│ ├── lib.sh # Shared library functions
│ └── templates/ # File templates
│ ├── *.java # Java source templates
│ ├── *.kts # Gradle Kotlin scripts
│ ├── *.template # Templates with placeholders
│ └── *.sh # Helper scripts
│
├── windows/ # Windows-specific implementation
│ ├── lib.bat # Shared library functions
│ └── templates/ # File templates (mirrors Linux)
│
└── tests/ # Test suite
├── run-tests.sh # Test runner
├── unit/ # Unit tests
└── system/ # System/integration tests
Architecture
Template System
Templates are stored in linux/templates/ and windows/templates/. They come in two types:
- Static templates: Direct copies (e.g., Pose2d.java, Drive.java)
- Parameterized templates: Use placeholders (e.g., settings.gradle.kts.template)
Supported Placeholders:
{{PROJECT_NAME}}- Name of the project{{SDK_DIR}}- Path to FTC SDK{{FTC_VERSION}}- FTC SDK version tag{{GENERATOR_VERSION}}- Generator version
Library Functions (lib.sh)
Key Functions:
get_generator_version()- Read VERSION fileprocess_template(input, output)- Replace placeholderscopy_template(src, dest)- Direct file copycreate_project_structure(dir)- Make directoriesinstall_templates(project_dir, template_dir)- Copy all templatescreate_deploy_script(dir)- Generate deployment scriptsetup_gradle_wrapper(dir)- Configure Gradleis_generator_project(dir)- Check if dir is generator projectget_project_generator_version(dir)- Read project versionupgrade_project(dir, template_dir)- Upgrade infrastructure filesinit_git_repo(dir)- Initialize gitcheck_prerequisites()- Validate environment
Main Script Flow
- Parse command-line arguments
- Load library functions
- Export environment variables for templates
- Handle upgrade mode (if
--upgradeflag) - Check if project exists (error if not upgrading)
- Check prerequisites (git, java, gradle)
- Setup/verify FTC SDK
- Create project structure
- Install templates
- Setup Gradle wrapper
- Initialize git repository
- Display success message
Upgrade Process
What Gets Updated:
build.gradle.kts- Build configurationsettings.gradle.kts- Gradle settings.gitignore- Git ignore rulesbuild.sh/build.bat- Build helper scriptdeploy-to-robot.sh/deploy-to-robot.bat- Deploy script.ftc-generator-version- Version marker
What's Preserved:
- All source code in
src/main/java/robot/ - All tests in
src/test/java/robot/ - README.md (user may have customized)
- Git history
- Gradle wrapper files
Testing
Unit Tests:
- Template processing correctness
- Version extraction
- Template file existence
- Library function behavior
System Tests:
- End-to-end project creation
- Directory structure validation
- File existence checks
- Git repository initialization
- Project builds successfully
- Project tests pass
- Upgrade functionality
- Duplicate detection
Running Tests:
# All tests
./tests/run-tests.sh
# Just unit tests
./tests/run-tests.sh unit
# Just system tests
./tests/run-tests.sh system
Adding New Features
Adding a New Template
- Create the template file in
linux/templates/andwindows/templates/ - If it needs variable substitution, use
.templateextension and add placeholders - Update
install_templates()inlib.sh/lib.batto copy it - Add test to verify template exists
- Update documentation
Example:
# Create template
cat > linux/templates/MyFile.java.template << 'EOF'
package robot;
// Generated for project: {{PROJECT_NAME}}
public class MyFile {
// ...
}
EOF
# Update lib.sh install_templates()
process_template "$template_dir/MyFile.java.template" "src/main/java/robot/MyFile.java"
# Update tests
REQUIRED_TEMPLATES+=("MyFile.java.template")
Adding a New Placeholder
- Export the variable in main script before template processing
- Update
process_template()to include the new placeholder - Update documentation
- Add test to verify replacement works
Example:
# In ftc-new-project
export TEAM_NUMBER="12345"
# In lib.sh process_template()
sed -e "s|{{TEAM_NUMBER}}|${TEAM_NUMBER}|g" \
...
Upgrading Template System
If you need to modify what files get upgraded:
- Update
upgrade_project()function inlib.sh/lib.bat - Add/remove files from the upgrade list
- Test with existing projects
- Update CHANGELOG.md
- Bump version if breaking change
Version Management
Bumping Version
- Update
VERSIONfile - Update
CHANGELOG.mdwith changes - Test thoroughly
- Tag git release:
git tag -a v1.0.0-beta -m "Release 1.0.0-beta" - Generated projects will use new version
Version Compatibility
Projects track their generator version in .ftc-generator-version. This allows:
- Upgrade detection
- Version-specific upgrade logic (if needed)
- Migration paths between major versions
Testing Strategy
Pre-Commit Checklist
- All templates exist in both
linux/andwindows/ - Run
./tests/run-tests.sh- all pass - Create test project manually
- Build test project:
./gradlew build - Run test project tests:
./gradlew test - Test upgrade on existing project
- Update CHANGELOG.md
- Update VERSION if needed
Release Checklist
- All tests pass
- Manual testing on Linux and Windows
- Documentation updated
- CHANGELOG.md current
- VERSION file bumped
- Git tag created
- README.md reflects current features
Common Issues
Template Processing
Problem: Placeholders not replaced
Solution: Make sure variable is exported before process_template() call
Problem: File not found during template install
Solution: Check template exists in templates/ directory
Testing
Problem: System tests fail with "command not found" Solution: Install prerequisites (git, java, gradle)
Problem: Generated project doesn't build Solution: Check Gradle configuration templates are valid
Cross-Platform
Problem: Line endings differ between platforms
Solution: Use .gitattributes to normalize line endings
Problem: Path separators (/ vs ) Solution: Use platform-appropriate functions in lib.sh/lib.bat
Best Practices
- Templates are static: Keep templates simple, move logic to scripts
- Test everything: Add tests for new features
- Document changes: Update CHANGELOG.md
- Version carefully: Breaking changes require major version bump
- Preserve user code: Never modify user source during upgrade
- Cross-platform parity: Keep Linux and Windows in sync
Future Improvements
Potential areas for enhancement:
- More template examples (autonomous, advanced subsystems)
- Template selection during creation (mecanum vs swerve)
- Web-based project generator
- CI/CD integration examples
- Performance optimization for large projects
- Plugin system for custom templates
- Migration tools for older FTC projects
Contributing
- Fork the repository
- Create feature branch
- Add tests for new features
- Ensure all tests pass
- Update documentation
- Submit pull request
License
MIT License - See LICENSE file for details.