|
| 1 | + |
| 2 | +# JSON Format Converter - GitHub Copilot Instructions |
| 3 | + |
| 4 | +<!-- Use this file to provide workspace-specific custom instructions to Copilot. For more details, visit https://code.visualstudio.com/docs/copilot/copilot-customization#_use-a-githubcopilotinstructionsmd-file --> |
| 5 | + |
| 6 | +## Project Overview |
| 7 | + |
| 8 | +This is a **JSON Format Converter** project - a Chrome extension and standalone web application for converting between JSON, JSONC (JSON with Comments), and JSON5 formats with advanced editing features and comment preservation. |
| 9 | + |
| 10 | +## Project Structure |
| 11 | + |
| 12 | +``` |
| 13 | +json-format-converter/ |
| 14 | +├── src/ # Source code |
| 15 | +│ ├── html/ # HTML files (popup.html, standalone.html, help.html) |
| 16 | +│ ├── css/ # Stylesheets (styles.css) |
| 17 | +│ ├── js/ # JavaScript files (converter.js, popup.js, i18n.js) |
| 18 | +│ ├── lib/ # Third-party libraries (CodeMirror, JSON5) |
| 19 | +│ ├── icons/ # Icon files (SVG and PNG) |
| 20 | +│ └── manifest.json # Chrome extension manifest |
| 21 | +├── scripts/ # Build and development scripts |
| 22 | +├── tests/ # Test files |
| 23 | +├── .github/ # GitHub Actions workflows |
| 24 | +├── dist/ # Build output (generated) |
| 25 | +└── justfile # Just command runner configuration |
| 26 | +``` |
| 27 | + |
| 28 | +## Development Guidelines |
| 29 | + |
| 30 | +### Technology Stack |
| 31 | +- **Vanilla JavaScript**: No framework dependencies for maximum compatibility |
| 32 | +- **CodeMirror 5**: Advanced code editor with syntax highlighting |
| 33 | +- **JSON5**: Extended JSON parsing with comment support |
| 34 | +- **CSS3**: Modern styling with flexbox and grid layouts |
| 35 | +- **Just**: Modern command runner for development tasks |
| 36 | +- **Python HTTP Server**: Built-in development server |
| 37 | + |
| 38 | +### Key Features to Maintain |
| 39 | +1. **Smart Format Conversion**: JSON ↔ JSONC ↔ JSON5 with comment preservation |
| 40 | +2. **Advanced Editor**: CodeMirror with syntax highlighting and line numbers |
| 41 | +3. **Multi-language Support**: English and Chinese interfaces |
| 42 | +4. **Comment Preservation**: Maintains comments during JSONC ↔ JSON5 conversion |
| 43 | +5. **Processing Tools**: Format, compress, escape, and data type conversion |
| 44 | +6. **Keyboard Shortcuts**: Productivity-focused hotkeys |
| 45 | + |
| 46 | +### Build System |
| 47 | +- Use `just build-new` for production builds |
| 48 | +- Use `just dev` for development server |
| 49 | +- Use `just test-comments` for testing comment preservation |
| 50 | +- Use `just check-all` for complete project validation |
| 51 | + |
| 52 | +### Code Style Guidelines |
| 53 | +- Follow existing code style and conventions |
| 54 | +- Use meaningful variable and function names |
| 55 | +- Add comments for complex logic, especially in converter.js |
| 56 | +- Maintain consistent indentation (4 spaces) |
| 57 | +- Keep functions focused and modular |
| 58 | + |
| 59 | +### Testing Guidelines |
| 60 | +- Test all conversion scenarios (JSON ↔ JSONC ↔ JSON5) |
| 61 | +- Verify comment preservation in JSONC ↔ JSON5 conversions |
| 62 | +- Test both Chrome extension and standalone versions |
| 63 | +- Validate multi-language functionality |
| 64 | +- Ensure keyboard shortcuts work correctly |
| 65 | + |
| 66 | +### File Modification Guidelines |
| 67 | + |
| 68 | +#### Core Files (Handle with Care) |
| 69 | +- **src/js/converter.js**: Core conversion logic, comment preservation system |
| 70 | +- **src/js/popup.js**: Main UI logic and event handlers |
| 71 | +- **src/js/i18n.js**: Internationalization system (English/Chinese) |
| 72 | +- **src/css/styles.css**: Main stylesheet with responsive design |
| 73 | +- **src/manifest.json**: Chrome extension configuration |
| 74 | + |
| 75 | +#### When Adding New Features |
| 76 | +1. **Conversion Features**: Add to converter.js with proper error handling |
| 77 | +2. **UI Features**: Update popup.js and corresponding HTML files |
| 78 | +3. **Styling**: Use existing CSS classes and maintain responsive design |
| 79 | +4. **Internationalization**: Add translations to both English and Chinese in i18n.js |
| 80 | +5. **Testing**: Create test cases in tests/ directory |
| 81 | + |
| 82 | +#### When Fixing Bugs |
| 83 | +1. **Identify Root Cause**: Check converter.js for logic issues |
| 84 | +2. **Test Thoroughly**: Use `just test-comments` and manual testing |
| 85 | +3. **Maintain Compatibility**: Ensure both extension and standalone versions work |
| 86 | +4. **Update Documentation**: Modify README files if behavior changes |
| 87 | + |
| 88 | +### Common Development Tasks |
| 89 | + |
| 90 | +#### Starting Development |
| 91 | +```bash |
| 92 | +just dev # Start development server on port 8080 |
| 93 | +just dev 8081 # Start on custom port |
| 94 | +``` |
| 95 | + |
| 96 | +#### Building and Testing |
| 97 | +```bash |
| 98 | +just build-new # Build production packages |
| 99 | +just test-comments # Test comment preservation |
| 100 | +just check-all # Run complete validation (59 checks) |
| 101 | +``` |
| 102 | + |
| 103 | +#### Adding New Conversion Logic |
| 104 | +1. Add conversion method to `JSONConverter` class in converter.js |
| 105 | +2. Update format detection logic if needed |
| 106 | +3. Add UI controls in popup.html if required |
| 107 | +4. Update i18n.js with new translation keys |
| 108 | +5. Test with various input formats |
| 109 | + |
| 110 | +#### Debugging Common Issues |
| 111 | +- **Comment Loss**: Check comment preservation methods in converter.js |
| 112 | +- **UI Layout**: Verify CSS flexbox/grid layouts in styles.css |
| 113 | +- **Language Issues**: Check i18n.js translation keys and popup.js language handling |
| 114 | +- **Build Failures**: Run `just check-all` to identify missing files or syntax errors |
| 115 | + |
| 116 | +### Browser Compatibility |
| 117 | +- **Chrome Extension**: Chrome 88+ (Manifest V3 compatible) |
| 118 | +- **Standalone Web App**: All modern browsers supporting ES6+ |
| 119 | +- **CodeMirror**: Version 5.x for maximum compatibility |
| 120 | +- **JSON5**: Latest version for extended JSON parsing |
| 121 | + |
| 122 | +### License and Attribution |
| 123 | +- **License**: Apache 2.0 |
| 124 | +- **Author **: Jetsung Chan <[email protected]> |
| 125 | +- **Dependencies**: CodeMirror, JSON5 (see package.json for versions) |
0 commit comments