|
| 1 | +# swap-shakacode-deps Implementation Plan |
| 2 | + |
| 3 | +## Executive Summary |
| 4 | + |
| 5 | +Create a globally installable Ruby gem `swap-shakacode-deps` that provides the dependency swapping functionality currently in `react_on_rails_demo_common`, making it available for use in any repository. |
| 6 | + |
| 7 | +## Architecture Overview |
| 8 | + |
| 9 | +### Package Type: Ruby Gem |
| 10 | +- **Rationale**: Ruby ecosystem provides better file manipulation, process management, and cross-platform compatibility |
| 11 | +- **Global Installation**: `gem install swap-shakacode-deps` |
| 12 | +- **Command**: `swap-shakacode-deps [options]` |
| 13 | + |
| 14 | +## Core Features (Maintaining Full Parity) |
| 15 | + |
| 16 | +1. **Local Path Swapping** |
| 17 | + - `--shakapacker PATH` |
| 18 | + - `--react-on-rails PATH` |
| 19 | + - `--cypress-on-rails PATH` |
| 20 | + |
| 21 | +2. **GitHub Repository Swapping** |
| 22 | + - `--github user/repo#branch` |
| 23 | + - `--github user/repo@tag` |
| 24 | + |
| 25 | +3. **Configuration File Support** |
| 26 | + - `.swap-deps.yml` in project root |
| 27 | + - `--apply` to use config file |
| 28 | + |
| 29 | +4. **Backup & Restore** |
| 30 | + - Automatic backup creation |
| 31 | + - `--restore` to revert changes |
| 32 | + |
| 33 | +5. **Build Management** |
| 34 | + - `--build` / `--skip-build` |
| 35 | + - `--watch` for auto-rebuild |
| 36 | + |
| 37 | +6. **Watch Process Management** |
| 38 | + - `--list-watch` |
| 39 | + - `--kill-watch` |
| 40 | + |
| 41 | +7. **Cache Management** |
| 42 | + - `--show-cache` |
| 43 | + - `--clean-cache [GEM]` |
| 44 | + |
| 45 | +8. **Status Reporting** |
| 46 | + - `--status` to show current swaps |
| 47 | + |
| 48 | +9. **Dry Run & Verbose Modes** |
| 49 | + - `--dry-run` |
| 50 | + - `--verbose` |
| 51 | + |
| 52 | +## File Structure |
| 53 | + |
| 54 | +```plaintext |
| 55 | +swap-shakacode-deps/ |
| 56 | +├── bin/ |
| 57 | +│ └── swap-shakacode-deps # Executable |
| 58 | +├── lib/ |
| 59 | +│ ├── swap_shakacode_deps.rb # Main entry |
| 60 | +│ ├── swap_shakacode_deps/ |
| 61 | +│ │ ├── version.rb |
| 62 | +│ │ ├── cli.rb # CLI parser |
| 63 | +│ │ ├── swapper.rb # Core swapping logic |
| 64 | +│ │ ├── gem_swapper.rb # Gemfile manipulation |
| 65 | +│ │ ├── npm_swapper.rb # package.json manipulation |
| 66 | +│ │ ├── github_handler.rb # GitHub repo management |
| 67 | +│ │ ├── cache_manager.rb # Cache operations |
| 68 | +│ │ ├── watch_manager.rb # Watch process management |
| 69 | +│ │ ├── backup_manager.rb # Backup/restore logic |
| 70 | +│ │ └── config_loader.rb # YAML config handling |
| 71 | +├── spec/ # Tests |
| 72 | +├── README.md |
| 73 | +├── CHANGELOG.md |
| 74 | +├── LICENSE |
| 75 | +├── Gemfile |
| 76 | +├── Rakefile |
| 77 | +└── swap-shakacode-deps.gemspec |
| 78 | +``` |
| 79 | + |
| 80 | +## Key Implementation Details |
| 81 | + |
| 82 | +### 1. Context Detection |
| 83 | +The gem will detect project type by looking for: |
| 84 | +- `Gemfile` (Ruby project) |
| 85 | +- `package.json` (Node project) |
| 86 | +- `.swap-deps.yml` (Configuration file) |
| 87 | + |
| 88 | +### 2. Multi-Project Support |
| 89 | +Unlike the current implementation that works with `demos/` directories, the global tool will: |
| 90 | +- Work in the current directory by default |
| 91 | +- Support `--path` option to specify target directory |
| 92 | +- Support `--recursive` to process subdirectories |
| 93 | + |
| 94 | +### 3. Improved Error Handling |
| 95 | +- Clear error messages for missing dependencies |
| 96 | +- Validation before making changes |
| 97 | +- Rollback on partial failures |
| 98 | + |
| 99 | +### 4. Platform Compatibility |
| 100 | +- macOS (primary) |
| 101 | +- Linux |
| 102 | +- Windows (WSL) |
| 103 | + |
| 104 | +## Migration Strategy |
| 105 | + |
| 106 | +### Phase 1: Gem Development |
| 107 | +1. Extract core logic from `demo_scripts` |
| 108 | +2. Remove demo-specific assumptions |
| 109 | +3. Generalize for any project structure |
| 110 | + |
| 111 | +### Phase 2: Integration |
| 112 | +1. Create gem with full feature parity |
| 113 | +2. Test with various project types |
| 114 | +3. Publish to RubyGems |
| 115 | + |
| 116 | +### Phase 3: Update react_on_rails_demo_common |
| 117 | +1. Add gem as dependency |
| 118 | +2. Create wrapper script that delegates to gem |
| 119 | +3. Maintain backward compatibility |
| 120 | + |
| 121 | +## Installation & Usage |
| 122 | + |
| 123 | +### Installation |
| 124 | +```bash |
| 125 | +# Global installation |
| 126 | +gem install swap-shakacode-deps |
| 127 | + |
| 128 | +# Or add to Gemfile for project-specific use |
| 129 | +gem 'swap-shakacode-deps' |
| 130 | +``` |
| 131 | + |
| 132 | +### Basic Usage |
| 133 | +```bash |
| 134 | +# Swap to local shakapacker |
| 135 | +swap-shakacode-deps --shakapacker ~/dev/shakapacker |
| 136 | + |
| 137 | +# Use GitHub branch |
| 138 | +swap-shakacode-deps --github shakacode/react_on_rails#feature-x |
| 139 | + |
| 140 | +# Apply from config |
| 141 | +swap-shakacode-deps --apply |
| 142 | + |
| 143 | +# Restore originals |
| 144 | +swap-shakacode-deps --restore |
| 145 | +``` |
| 146 | + |
| 147 | +## Configuration File Format |
| 148 | + |
| 149 | +```yaml |
| 150 | +# .swap-deps.yml |
| 151 | +gems: |
| 152 | + shakapacker: ~/dev/shakapacker |
| 153 | + react_on_rails: ~/dev/react_on_rails |
| 154 | + |
| 155 | +github: |
| 156 | + shakapacker: |
| 157 | + repo: shakacode/shakapacker |
| 158 | + branch: main |
| 159 | +``` |
| 160 | +
|
| 161 | +## Benefits Over Current Implementation |
| 162 | +
|
| 163 | +1. **Global Availability**: Use in any project, not just react_on_rails_demo_common |
| 164 | +2. **Simplified Maintenance**: Single source of truth for the tool |
| 165 | +3. **Better Testing**: Isolated gem with its own test suite |
| 166 | +4. **Version Management**: Semantic versioning for the tool |
| 167 | +5. **Documentation**: Dedicated docs for the tool |
| 168 | +6. **Community Contribution**: Easier for others to contribute |
| 169 | +
|
| 170 | +## Timeline Estimate |
| 171 | +
|
| 172 | +- **Week 1**: Core gem structure and logic extraction |
| 173 | +- **Week 2**: Feature implementation and testing |
| 174 | +- **Week 3**: Documentation and publishing |
| 175 | +- **Week 4**: Integration with react_on_rails_demo_common |
| 176 | +
|
| 177 | +## Success Criteria |
| 178 | +
|
| 179 | +1. All current swap-deps features work globally |
| 180 | +2. No breaking changes for existing users |
| 181 | +3. Clear upgrade path |
| 182 | +4. Comprehensive documentation |
| 183 | +5. Published to RubyGems |
| 184 | +6. Works with any Shakacode project |
0 commit comments