Skip to content

feat: Add post-generation hooks support#106

Merged
connerohnesorge merged 1 commit intomainfrom
feature/post-generation-hooks
Oct 14, 2025
Merged

feat: Add post-generation hooks support#106
connerohnesorge merged 1 commit intomainfrom
feature/post-generation-hooks

Conversation

@connerohnesorge
Copy link
Copy Markdown
Owner

Summary

Add support for running bash commands after protobuf code generation completes. This feature allows users to automate post-generation tasks like formatting, building packages, running validation, etc.

Changes

  • Configuration Schema (src/lib/bufrnix-options.nix)

    • Add hooks.postGeneration option for bash commands to run after all generation
    • Add hooks.onFailure option to control behavior when hooks fail (continue/stop)
    • Proper type definitions with examples and descriptions
  • Core Implementation (src/lib/mkBufrnix.nix)

    • Execute hooks after all language generation completes
    • Set environment variables for hook context:
      • BUFRNIX_ROOT: Project root directory
      • BUFRNIX_ENABLED_LANGUAGES: List of enabled languages
      • BUFRNIX_DEBUG_ENABLE: Debug flag
      • BUFRNIX_DEBUG_VERBOSITY: Debug verbosity level
    • Proper error handling and logging integration
    • Backward compatible (hooks are optional)

Usage Example

config = {
  # ... existing configuration ...
  
  hooks = {
    postGeneration = ''
      echo "🚀 Running post-generation tasks..."
      
      # Format Go code
      find . -name "*.pb.go" -exec gofmt -w {} +
      
      # Run Go module tidy
      cd gen/go && go mod tidy
      
      # Build JavaScript packages
      cd gen/js && npm run build
      
      echo "✅ Post-generation complete!"
    '';
    
    onFailure = "continue"; # or "stop"
  };
};

Testing

  • ✅ All 25+ existing examples pass without issues
  • ✅ Hook execution verified with test case
  • ✅ Environment variables properly set and accessible
  • ✅ Generated files accessible to hooks
  • ✅ Backward compatibility maintained

Benefits

  • Non-intrusive: Minimal changes to core Bufrnix architecture
  • Powerful: Full bash scripting capabilities with environment context
  • Consistent: Follows existing patterns in the codebase
  • Flexible: Users can run any post-processing commands
  • Production-ready: Comprehensive testing and error handling

This feature enables users to automate common post-generation tasks like code formatting, package building, validation, and other custom workflows as part of their declarative Bufrnix configuration.

🤖 Generated with Claude Code

Add support for running bash commands after protobuf code generation completes.

- Add hooks.postGeneration option for bash commands to run after all generation
- Add hooks.onFailure option to control behavior when hooks fail (continue/stop)
- Set environment variables for hook context (BUFRNIX_ROOT, enabled languages, etc.)
- Integrate with existing debug logging system
- Maintain backward compatibility (hooks are optional)

Usage example:
hooks = {
  postGeneration = ''
    echo "Running post-generation tasks..."
    find . -name "*.pb.go" -exec gofmt -w {} +
    cd gen/go && go mod tidy
  '';
  onFailure = "continue";
};

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@connerohnesorge connerohnesorge merged commit 40199c1 into main Oct 14, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant