|
| 1 | +# GEMINI.md |
| 2 | + |
| 3 | +This file provides guidance to Gemini CLI or other coding agents when working with code in this repository. It focuses on key conventions and best practices. For a comprehensive guide on the development setup and contribution process, see [`CONTRIBUTING.md`](CONTRIBUTING.md). |
| 4 | + |
| 5 | +## Essential Commands |
| 6 | + |
| 7 | +```bash |
| 8 | +# Build the project |
| 9 | +npm run build |
| 10 | + |
| 11 | +# Link the package - once this is run, you can manually test changes in your terminal |
| 12 | +npm link |
| 13 | + |
| 14 | +npm test # Full test suite with linting and compilation |
| 15 | +npm run mocha:fast # Quick unit tests only |
| 16 | +npx mocha {testfile} # Quick unit test for a specific file |
| 17 | + |
| 18 | +# Linting and formatting |
| 19 | +npm run lint # Check all code |
| 20 | +npm run lint:changed-files # Lint changed files only (much faster) |
| 21 | +npm run format # Auto-fix formatting issues |
| 22 | +``` |
| 23 | + |
| 24 | +## Best Practices |
| 25 | + |
| 26 | +### Code Quality & Utilities |
| 27 | + |
| 28 | +- **Look for existing utilities first:** Before writing common helper functions (e.g., for logging, file system operations, promises, string manipulation), check `src/utils.ts` to see if a suitable function already exists. |
| 29 | +- **Use the central `logger`** (`src/logger.ts`); never use `console.log()` for user-facing output. |
| 30 | +- **Throw `FirebaseError`** (`src/error.ts`) for expected, user-facing errors. |
| 31 | +- **API calls must use `apiv2.ts`** for authenticated requests. |
| 32 | + |
| 33 | +### TypeScript |
| 34 | + |
| 35 | +- **Never use `any` or `unknown` as an escape hatch.** Define proper interfaces/types or use type guards. |
| 36 | +- Use strict null checks and handle `undefined`/`null` explicitly. |
| 37 | + |
| 38 | +### Testing |
| 39 | + |
| 40 | +- **Avoid excessive mocking in unit tests.** If a test requires many mocks, it might be better as an integration test in `/scripts/[feature]-tests/`. |
| 41 | +- **Unit tests (`*.spec.ts`) should be co-located with their source files.** |
| 42 | +- Test error cases and edge conditions, not just the "happy path." |
| 43 | + |
| 44 | +## Git Workflow & Pull Requests |
| 45 | + |
| 46 | +1. **Lint and Test Before Committing:** Run `npm run lint:changed-files` for a quick check, and run the full `npm test` before submitting your PR to catch any issues. |
| 47 | +2. **Structure Commit Messages for Pull Requests:** To streamline PR creation, format your commit messages to serve as both the commit and the PR description: |
| 48 | + - **Subject Line:** A concise, imperative summary (e.g., `feat: add frobnicator support`). This will become the PR title. |
| 49 | + - **Body:** After a blank line, structure the commit body to match the PR template. This will pre-populate the PR description. Include: |
| 50 | + - `### Description` |
| 51 | + - `### Scenarios Tested` |
| 52 | + - `### Sample Commands` |
| 53 | + - Reference issues with "Fixes #123" in the description. |
| 54 | +3. **Update Changelog:** For any user-facing change (new features, bug fixes, deprecations), add a corresponding entry to `CHANGELOG.md`. |
0 commit comments