6.0 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			6.0 KiB
		
	
	
	
	
	
	
	
Gitzone CLI - Development Hints
- the cli of the git.zone project.
Project Overview
Gitzone CLI (@git.zone/cli) is a comprehensive toolbelt for streamlining local development cycles. It provides utilities for:
- Project initialization and templating (via smartscaf)
- Code formatting and standardization
- Version control and commit management
- Docker and CI/CD integration
- Meta project management
Architecture
Core Structure
- Main CLI entry: cli.ts/cli.child.ts
- Modular architecture with separate modules in ts/mod_*directories
- Each module handles specific functionality (format, commit, docker, etc.)
- Extensive use of plugins pattern via plugins.tsfiles
Configuration Management
- Uses npmextra.jsonfor all tool configuration
- Configuration stored under gitzonekey in npmextra
- No separate .gitzonercfile - everything in npmextra.json
- Project type and module metadata also stored in npmextra
Format Module (mod_format) - SIGNIFICANTLY ENHANCED
The format module is responsible for project standardization:
Current Modules:
- cleanup - Removes obsolete files (yarn.lock, tslint.json, etc.)
- copy - File copying with glob patterns (fully implemented)
- gitignore - Creates/updates .gitignore from templates
- license - Checks dependency licenses for compatibility
- npmextra - Manages project metadata and configuration
- packagejson - Formats and updates package.json
- prettier - Applies code formatting with batching
- readme - Ensures readme files exist
- templates - Updates project templates based on type
- tsconfig - Formats TypeScript configuration
Execution Order (Dependency-Based):
- Modules are now executed in parallel groups based on dependencies
- Independent modules run concurrently for better performance
- Dependency analyzer ensures correct execution order
New Architecture Features
- BaseFormatter Pattern: All formatters extend abstract BaseFormatter class
- FormatContext: Central state management across all modules
- FormatPlanner: Implements plan → action workflow
- RollbackManager: Full backup/restore capabilities
- ChangeCache: Tracks file changes to optimize performance
- DependencyAnalyzer: Manages module execution order
- DiffReporter: Generates diff views for changes
- FormatStats: Comprehensive execution statistics
Key Patterns
- Plugin Architecture: All dependencies imported through plugins.tsfiles
- Streaming: Uses smartstream for file processing
- Interactive Prompts: smartinteract for user input
- Enhanced Error Handling: Comprehensive try-catch with automatic rollback
- Template System: Templates handled by smartscaf, not directly by gitzone
- Type Safety: Full TypeScript with interfaces and type definitions
Important Notes
- .nogit/directory used for temporary/untracked files, backups, and cache
- .nogit/gitzone-backups/stores format operation backups
- .nogit/gitzone-cache/stores file change cache
- Templates are managed by smartscaf - improvements should be made there
- License checking configurable with exceptions support
- All features implemented: ensureDependency, copy module, etc.
Recent Improvements (Completed)
- Plan → Action Workflow: Shows changes before applying them
- Rollback Mechanism: Full backup and restore on failures
- Enhanced Configuration: Granular control via npmextra.json
- Better Error Handling: Detailed errors with recovery options
- Performance Optimizations: Parallel execution and caching
- Reporting: Diff views, statistics, verbose logging
- Architecture: Clean separation of concerns with new classes
Development Tips
- Always check readme.plan.md for ongoing improvement plans
- Use npmextra.json for any new configuration options
- Keep modules focused and single-purpose
- Maintain the existing plugin pattern for dependencies
- Test format operations on sample projects before deploying
- Consider backward compatibility when changing configuration structure
- Use BaseFormatter pattern for new format modules
- Leverage FormatContext for cross-module state sharing
Configuration Examples
{
  "gitzone": {
    "format": {
      "interactive": true,
      "parallel": true,
      "showStats": true,
      "cache": {
        "enabled": true,
        "clean": true
      },
      "rollback": {
        "enabled": true,
        "autoRollbackOnError": true,
        "backupRetentionDays": 7
      },
      "modules": {
        "skip": ["prettier"],
        "only": [],
        "order": []
      },
      "licenses": {
        "allowed": ["MIT", "Apache-2.0"],
        "exceptions": {
          "some-package": "GPL-3.0"
        }
      }
    }
  }
}
CLI Usage
# Basic format
gitzone format
# Dry run to preview changes
gitzone format --dry-run
# Non-interactive mode
gitzone format --yes
# Plan only (no execution)
gitzone format --plan-only
# Save plan for later
gitzone format --save-plan format.json
# Execute saved plan
gitzone format --from-plan format.json
# Verbose mode
gitzone format --verbose
# Detailed diff views
gitzone format --detailed
# Rollback operations
gitzone format --rollback
gitzone format --rollback <operation-id>
gitzone format --list-backups
gitzone format --clean-backups
Common Issues (Now Resolved)
- ✅ Format operations are now reversible with rollback
- ✅ Enhanced error messages with recovery suggestions
- ✅ All modules fully implemented (including copy)
- ✅ Dry-run capability available
- ✅ Extensive configuration options available
Future Considerations
- Plugin system for custom formatters
- Git hooks integration for pre-commit formatting
- Advanced UI with interactive configuration
- Format presets for common scenarios
- Performance benchmarking tools
API Changes
- smartfile API updated to use fs._ and memory._ namespaces
- smartnpm requires instance creation: new NpmRegistry()
- All file operations now use updated APIs
- Type imports use import typefor proper verbatim module syntax