Development
This guide covers how to contribute to PUPT development or build it from source.
Prerequisites
- Node.js 18.x or higher
- npm 8.x or higher
- Git
Getting Started
Clone the Repository
bash
git clone https://github.com/apowers313/pupt.git
cd puptInstall Dependencies
bash
npm installDevelopment Commands
Building
bash
# Build the TypeScript project
npm run build
# Watch mode for development
npm run devTesting
PUPT uses Vitest for testing with comprehensive coverage:
bash
# Run all tests
npm test
# Run tests with verbose output
npm run test:verbose
# Run tests in watch mode
npm run test:watch
# Run tests with UI interface
npm run test:ui
# Run tests with coverage
npm run test:coverageRunning Specific Tests
bash
# Run a single test file
npm test test/commands/add.test.ts
# Run tests matching a pattern
npm test -- -t "pattern"
# Run tests for a specific component
npm test -- test/template/Code Quality
bash
# Run linter
npm run lint
# Format code with prettier
npm run format
# Run all checks (lint, build, test with coverage)
npm run checkRunning Locally
After building, you can run PUPT locally:
bash
# Run the CLI directly
node dist/cli.js
# Or use npm link for global access
npm link
pt --versionProject Structure
pupt/
├── src/ # Source code
│ ├── cli.ts # CLI entry point
│ ├── commands/ # Command implementations
│ ├── config/ # Configuration management
│ ├── history/ # History tracking
│ ├── prompts/ # Prompt management
│ ├── search/ # Search functionality
│ ├── template/ # Template engine
│ ├── ui/ # User interface components
│ └── utils/ # Utility functions
├── test/ # Test files
│ ├── commands/ # Command tests
│ ├── integration/ # Integration tests
│ └── fixtures/ # Test fixtures
├── docs/ # Documentation
├── prompts/ # Example prompts
└── dist/ # Compiled outputArchitecture
Core Components
CLI Layer (
src/cli.ts)- Uses Commander.js for command parsing
- Handles global options and command routing
Configuration System (
src/config/)ConfigManager: Loads and merges configurations- Supports multiple file formats
Prompt Management (
src/prompts/)PromptManager: Discovers and loads prompts- Handles frontmatter parsing
- Manages prompt metadata
Template Engine (
src/template/)TemplateEngine: Processes Handlebars templatesTemplateContext: Manages variables- Custom helpers for user input
Search System (
src/search/)SearchEngine: Fuzzy search using MiniSearchInteractiveSearch: UI for prompt selection
History Management (
src/history/)HistoryManager: Saves execution history- Masks sensitive values
- Supports annotations
Testing Strategy
Unit Tests
- Test individual components in isolation
- Mock external dependencies
- Focus on edge cases and error conditions
Integration Tests
- Test complete workflows
- Use temporary directories for file operations
- Verify component interactions
E2E Tests
- Test CLI commands end-to-end
- Simulate user interactions
- Verify output and side effects
Contributing
Development Workflow
Fork the repository
Create a feature branch
bashgit checkout -b feature/my-new-featureMake your changes
- Write tests for new functionality
- Update documentation as needed
- Follow existing code style
Run tests and checks
bashnpm run checkCommit your changes
bashgit commit -m "feat: add new feature"Push and create PR
bashgit push origin feature/my-new-feature
Commit Convention
Follow conventional commits:
feat:New featuresfix:Bug fixesdocs:Documentation changestest:Test additions/changesrefactor:Code refactoringchore:Maintenance tasks
Code Style
- TypeScript strict mode enabled
- ESLint configuration enforced
- Prettier for formatting
- 100 character line limit
Debugging
VS Code Configuration
.vscode/launch.json:
json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug CLI",
"program": "${workspaceFolder}/dist/cli.js",
"args": ["add"],
"console": "integratedTerminal",
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
}
]
}Debug Logging
Enable debug logs:
bash
PT_LOG_LEVEL=debug node dist/cli.jsMemory Profiling
bash
node --inspect dist/cli.js
# Open chrome://inspect in ChromeRelease Process
Update version
bashnpm version patch|minor|majorRun checks
bashnpm run checkBuild and test
bashnpm run build npm testPublish
bashnpm publishCreate GitHub release
- Tag the version
- Add release notes
- Upload artifacts if needed
