Welcome to the NZ Legislation Tool development team! This guide will help you get set up and contributing in under 30 minutes.
# Clone the repository
git clone https://github.com/edithatogo/nz-legislation.git
cd nz-legislation-tool
# Install dependencies
npm install
# Copy environment example
cp .env.example .env
# Edit .env with your API key (get from https://api.legislation.govt.nz/docs/)# Run in development mode
npm run dev -- search --query "health" --limit 5
# Run tests
npm test
# Type check
npm run typecheck✅ If all commands succeed, you're ready to contribute!
# Hot reload enabled (auto-restarts on changes)
npm run dev -- <command>
# Examples
npm run dev -- search --query "health"
npm run dev -- get "act_public_1989_18"
npm run dev -- export --query "health" --output test.csv
npm run dev -- cite "act_public_1989_18" --style nzmj
npm run dev -- config --show# Run tests in watch mode (re-runs on changes)
npm test
# Run tests once
npm run test:run
# Run with coverage report
npm run test:coverage
# Run specific test file
npm test -- tests/client.test.ts
# Run with mutation testing
npm run test:mutation# Type check (no emit)
npm run typecheck
# Lint with ESLint
npm run lint
# Auto-fix lint issues
npm run lint:fix
# Format code with Prettier
npm run format
# Check formatting (CI/CD)
npm run format:check# Compile TypeScript to dist/
npm run build
# Analyze bundle size
npm run build:analyzeThis project includes pre-configured debug setups in .vscode/launch.json:
- Debug CLI - Search: Debug search command
- Debug CLI - Get: Debug get command
- Debug CLI - Export: Debug export command
- Debug CLI - Cite: Debug cite command
- Debug MCP Server: Debug MCP server
- Run Tests: Debug test suite
To debug:
- Set breakpoints in your code (click left of line number)
- Press
F5or go to Run and Debug panel - Select a debug configuration
- Click the green play button
# Enable verbose logging
npm run dev -- search --query "health" --verbose
# Or set environment variable
export DEBUG=nzlegislation:*
npm run dev -- search --query "health"Error logs are stored at:
- Linux/macOS:
~/.nz-legislation-tool/logs/error-YYYY-MM-DD.log - Windows:
%USERPROFILE%\.nz-legislation-tool\logs\error-YYYY-MM-DD.log
View recent logs:
cat ~/.nz-legislation-tool/logs/error-*.log# Run benchmarks
npm run bench
# Profile with clinic.js (advanced)
npx clinic doctor -- node dist/cli.js search --query "health"- main: Protected branch, auto-deploys to npm
- feature/: New features (e.g.,
feature/add-filter-command) - fix/: Bug fixes (e.g.,
fix/handle-timeout-errors) - chore/: Maintenance (e.g.,
chore/update-dependencies)
<type>: <description>
[optional body]
[optional footer]
Types:
feat:New featurefix:Bug fixdocs:Documentationtest:Testsrefactor:Code refactoringchore:Maintenanceci:CI/CDperf:Performance
Examples:
feat: Add rate limit configuration
fix: Handle API timeout errors gracefully
docs: Update README with new features
test: Add tests for CSV export
refactor: Simplify logger clearOldLogs method
chore: Update dependencies-
Create branch
git checkout -b feature/your-feature
-
Make changes with hot reload
npm run dev -- <command>
-
Run tests
npm test -
Type check
npm run typecheck
-
Lint and format
npm run lint:fix npm run format
-
Commit (pre-commit hooks run automatically)
git add . git commit -m "feat: Your feature description"
-
Push and create PR
git push origin feature/your-feature
This project uses Husky with lint-staged. On every commit:
- ESLint runs on staged
.tsfiles with auto-fix - TypeScript type checking runs
- Prettier formats
.jsonand.mdfiles
If hooks fail, fix the issues and try again.
import { describe, it, expect, beforeEach } from 'vitest';
describe('ComponentName', () => {
beforeEach(() => {
// Setup
});
it('should expected_behavior', () => {
// Arrange
// Act
// Assert
expect(actual).toBe(expected);
});
});- Unit Tests: Test individual functions/modules
- Integration Tests: Test API interactions (MSW mocked)
- E2E Tests: Test full CLI commands (execa)
- Property Tests: Test invariants with fast-check
- Hypothesis Tests: Test consistency/reproducibility
# By file
npm test -- tests/client.test.ts
# By test name pattern
npm test -- -t "should handle empty results"
# By directory
npm test -- tests/integration/# Check configuration
nzlegislation config --show
# Re-set API key
nzlegislation config --key YOUR_API_KEY# Clear Vite cache
rm -rf node_modules/.vite
# Re-run tests
npm run test:run# Clean and rebuild
rm -rf dist/ node_modules/
npm install
npm run build# Check for type errors
npm run typecheck
# Fix common issues:
# - Missing return types
# - Import path issues (use @ aliases)
# - Zod schema mismatches- README.md: User documentation
- TESTING.md: Comprehensive testing guide
- CONTRIBUTING.md: Contribution guidelines
- MCP_GUIDE.md: MCP server documentation
- API Documentation: NZ Legislation API
- ESLint (
dbaeumer.vscode-eslint) - Prettier (
esbenp.prettier-vscode) - Vitest (
vitest.explorer) - GitLens (
eamodio.gitlens)
For a pre-configured environment:
- Install Dev Containers extension
- Open folder in VS Code
- Press
F1→ "Dev Containers: Reopen in Container"
This sets up Node.js, dependencies, and extensions automatically.
- ✅ Complete quick start
- 📖 Read CONTRIBUTING.md
- 🐛 Pick a good first issue
- 💬 Join discussions (GitHub Issues)
- 🎉 Submit your first PR!
Welcome aboard! 🎉