Skip to content

Commit 45dcf61

Browse files
committed
init
0 parents  commit 45dcf61

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+7576
-0
lines changed

.github/copilot-instructions.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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)

.github/workflows/build.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build JSON Format Converter
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
release:
9+
types: [ created ]
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.x'
23+
24+
- name: Setup Just
25+
uses: extractions/setup-just@v3
26+
27+
- name: Build project
28+
run: |
29+
just build-new
30+
31+
- name: Run tests
32+
run: |
33+
just test-comments
34+
35+
- name: Validate project
36+
run: |
37+
just check-all
38+
39+
- name: Upload build artifacts
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: json-format-converter-${{ github.sha }}
43+
path: |
44+
*.zip
45+
dist/
46+
retention-days: 30
47+
48+
- name: Get version for release
49+
if: github.event_name == 'release'
50+
id: get_version
51+
run: echo "version=$(grep '"version"' package.json | head -1 | cut -d'"' -f4)" >> $GITHUB_OUTPUT
52+
53+
- name: Upload Extension ZIP to Release
54+
if: github.event_name == 'release'
55+
uses: actions/upload-release-asset@v1
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
with:
59+
upload_url: ${{ github.event.release.upload_url }}
60+
asset_path: ./json-format-converter-extension.zip
61+
asset_name: json-format-converter-extension-v${{ steps.get_version.outputs.version }}.zip
62+
asset_content_type: application/zip
63+
64+
- name: Upload Standalone ZIP to Release
65+
if: github.event_name == 'release'
66+
uses: actions/upload-release-asset@v1
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
with:
70+
upload_url: ${{ github.event.release.upload_url }}
71+
asset_path: ./json-format-converter-standalone.zip
72+
asset_name: json-format-converter-standalone-v${{ steps.get_version.outputs.version }}.zip
73+
asset_content_type: application/zip

.github/workflows/quality.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Code Quality Check
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
quality:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: '3.x'
21+
22+
- name: Setup Just
23+
uses: extractions/setup-just@v3
24+
25+
- name: Check project structure
26+
run: |
27+
just check-structure
28+
29+
- name: Validate file syntax
30+
run: |
31+
# Check JSON files
32+
find . -name "*.json" -not -path "./node_modules/*" -not -path "./dist/*" | xargs -I {} sh -c 'echo "Checking {}" && python -m json.tool {} > /dev/null'
33+
34+
# Check JavaScript files for basic syntax
35+
find src/js -name "*.js" | xargs -I {} sh -c 'echo "Checking {}" && node -c {}'
36+
37+
- name: Test comment preservation
38+
run: |
39+
just test-comments
40+
41+
- name: Run complete validation
42+
run: |
43+
just check-all
44+
45+
- name: Check documentation
46+
run: |
47+
# Verify README files exist and are not empty
48+
test -s README.md || (echo "README.md is missing or empty" && exit 1)
49+
test -s README_zh.md || (echo "README_zh.md is missing or empty" && exit 1)
50+
51+
# Check for broken internal links in README
52+
grep -o '\[.*\](.*\.md)' README.md | grep -v 'http' | while read link; do
53+
file=$(echo "$link" | sed 's/.*](\(.*\))/\1/')
54+
test -f "$file" || (echo "Broken link: $file" && exit 1)
55+
done
56+
57+
- name: Verify build artifacts
58+
run: |
59+
just build-new
60+
61+
# Check that build produces expected files
62+
test -f json-format-converter-extension.zip || (echo "Extension ZIP not created" && exit 1)
63+
test -f json-format-converter-standalone.zip || (echo "Standalone ZIP not created" && exit 1)
64+
test -d dist/extension || (echo "Extension build directory missing" && exit 1)
65+
test -d dist/standalone || (echo "Standalone build directory missing" && exit 1)
66+
67+
# Check ZIP file contents
68+
unzip -t json-format-converter-extension.zip > /dev/null || (echo "Extension ZIP is corrupted" && exit 1)
69+
unzip -t json-format-converter-standalone.zip > /dev/null || (echo "Standalone ZIP is corrupted" && exit 1)
70+
71+
- name: Check package sizes
72+
run: |
73+
echo "📊 Package Sizes:"
74+
echo "Extension: $(du -h json-format-converter-extension.zip | cut -f1)"
75+
echo "Standalone: $(du -h json-format-converter-standalone.zip | cut -f1)"
76+
77+
# Warn if packages are too large (>500KB)
78+
ext_size=$(stat -c%s json-format-converter-extension.zip)
79+
standalone_size=$(stat -c%s json-format-converter-standalone.zip)
80+
81+
if [ $ext_size -gt 512000 ]; then
82+
echo "⚠️ Warning: Extension package is larger than 500KB ($ext_size bytes)"
83+
fi
84+
85+
if [ $standalone_size -gt 512000 ]; then
86+
echo "⚠️ Warning: Standalone package is larger than 500KB ($standalone_size bytes)"
87+
fi

0 commit comments

Comments
 (0)