63 changed files with 2547 additions and 663 deletions
@ -0,0 +1,75 @@ |
|||||
|
# Architecture Rules Directory |
||||
|
|
||||
|
**Author**: Matthew Raymer |
||||
|
**Date**: 2025-08-20 |
||||
|
**Status**: 🎯 **ACTIVE** - Architecture protection guidelines |
||||
|
|
||||
|
## Overview |
||||
|
|
||||
|
This directory contains MDC (Model Directive Configuration) rules that protect |
||||
|
critical architectural components of the TimeSafari project. These rules ensure |
||||
|
that changes to system architecture follow proper review, testing, and |
||||
|
documentation procedures. |
||||
|
|
||||
|
## Available Rules |
||||
|
|
||||
|
### Build Architecture Guard (`build_architecture_guard.mdc`) |
||||
|
|
||||
|
Protects the multi-platform build system including: |
||||
|
|
||||
|
- Vite configuration files |
||||
|
- Build scripts and automation |
||||
|
- Platform-specific configurations (iOS, Android, Electron, Web) |
||||
|
- Docker and deployment infrastructure |
||||
|
- CI/CD pipeline components |
||||
|
|
||||
|
**When to use**: Any time you're modifying build scripts, configuration files, |
||||
|
or deployment processes. |
||||
|
|
||||
|
**Authorization levels**: |
||||
|
|
||||
|
- **Level 1**: Minor changes (review required) |
||||
|
- **Level 2**: Moderate changes (testing required) |
||||
|
- **Level 3**: Major changes (ADR required) |
||||
|
|
||||
|
## Usage Guidelines |
||||
|
|
||||
|
### For Developers |
||||
|
|
||||
|
1. **Check the rule**: Before making architectural changes, review the relevant |
||||
|
rule |
||||
|
2. **Follow the process**: Use the appropriate authorization level |
||||
|
3. **Complete validation**: Run through the required checklist |
||||
|
4. **Update documentation**: Keep BUILDING.md and related docs current |
||||
|
|
||||
|
### For Reviewers |
||||
|
|
||||
|
1. **Verify authorization**: Ensure changes match the required level |
||||
|
2. **Check testing**: Confirm appropriate testing has been completed |
||||
|
3. **Validate documentation**: Ensure BUILDING.md reflects changes |
||||
|
4. **Assess risk**: Consider impact on other platforms and systems |
||||
|
|
||||
|
## Integration with Other Rules |
||||
|
|
||||
|
- **Version Control**: Works with `workflow/version_control.mdc` |
||||
|
- **Research & Diagnostic**: Supports `research_diagnostic.mdc` for |
||||
|
investigations |
||||
|
- **Software Development**: Aligns with development best practices |
||||
|
- **Markdown Automation**: Integrates with `docs/markdown-automation.mdc` for |
||||
|
consistent documentation formatting |
||||
|
|
||||
|
## Emergency Procedures |
||||
|
|
||||
|
If architectural changes cause system failures: |
||||
|
|
||||
|
1. **Immediate rollback** to last known working state |
||||
|
2. **Document the failure** with full error details |
||||
|
3. **Investigate root cause** using diagnostic workflows |
||||
|
4. **Update procedures** to prevent future failures |
||||
|
|
||||
|
--- |
||||
|
|
||||
|
**Status**: Active architecture protection |
||||
|
**Priority**: Critical |
||||
|
**Maintainer**: Development team |
||||
|
**Next Review**: 2025-09-20 |
@ -0,0 +1,295 @@ |
|||||
|
--- |
||||
|
description: Guards against unauthorized changes to the TimeSafari building |
||||
|
architecture |
||||
|
alwaysApply: false |
||||
|
--- |
||||
|
|
||||
|
# Build Architecture Guard Directive |
||||
|
|
||||
|
**Author**: Matthew Raymer |
||||
|
**Date**: 2025-08-20 |
||||
|
**Status**: 🎯 **ACTIVE** - Build system protection guidelines |
||||
|
|
||||
|
## Purpose |
||||
|
|
||||
|
Protect the TimeSafari building architecture from unauthorized changes that |
||||
|
could break the multi-platform build pipeline, deployment processes, or |
||||
|
development workflow. This directive ensures all build system modifications |
||||
|
follow proper review, testing, and documentation procedures. |
||||
|
|
||||
|
## Protected Architecture Components |
||||
|
|
||||
|
### Core Build Infrastructure |
||||
|
|
||||
|
- **Vite Configuration Files**: `vite.config.*.mts` files |
||||
|
- **Build Scripts**: All scripts in `scripts/` directory |
||||
|
- **Package Scripts**: `package.json` build-related scripts |
||||
|
- **Platform Configs**: `capacitor.config.ts`, `electron/`, `android/`, |
||||
|
`ios/` |
||||
|
- **Docker Configuration**: `Dockerfile`, `docker-compose.yml` |
||||
|
- **Environment Files**: `.env.*`, `.nvmrc`, `.node-version` |
||||
|
|
||||
|
### Critical Build Dependencies |
||||
|
|
||||
|
- **Build Tools**: Vite, Capacitor, Electron, Android SDK, Xcode |
||||
|
- **Asset Management**: `capacitor-assets.config.json`, asset scripts |
||||
|
- **Testing Infrastructure**: Playwright, Jest, mobile test scripts |
||||
|
- **CI/CD Pipeline**: GitHub Actions, build validation scripts |
||||
|
- **Service Worker Assembly**: `sw_scripts/`, `sw_combine.js`, WASM copy steps |
||||
|
|
||||
|
## Change Authorization Requirements |
||||
|
|
||||
|
### Level 1: Minor Changes (Requires Review) |
||||
|
|
||||
|
- Documentation updates to `BUILDING.md` |
||||
|
- Non-breaking script improvements |
||||
|
- Test additions or improvements |
||||
|
- Asset configuration updates |
||||
|
|
||||
|
**Process**: Code review + basic testing |
||||
|
|
||||
|
### Level 2: Moderate Changes (Requires Testing) |
||||
|
|
||||
|
- New build script additions |
||||
|
- Environment variable changes |
||||
|
- Dependency version updates |
||||
|
- Platform-specific optimizations |
||||
|
|
||||
|
**Process**: Code review + platform testing + documentation update |
||||
|
|
||||
|
### Level 3: Major Changes (Requires ADR) |
||||
|
|
||||
|
- Build system architecture changes |
||||
|
- New platform support |
||||
|
- Breaking changes to build scripts |
||||
|
- Major dependency migrations |
||||
|
|
||||
|
**Process**: ADR creation + comprehensive testing + team review |
||||
|
|
||||
|
## Prohibited Actions |
||||
|
|
||||
|
### ❌ Never Allow Without ADR |
||||
|
|
||||
|
- **Delete or rename** core build scripts |
||||
|
- **Modify** `package.json` build script names |
||||
|
- **Change** Vite configuration structure |
||||
|
- **Remove** platform-specific build targets |
||||
|
- **Alter** Docker build process |
||||
|
- **Modify** CI/CD pipeline without testing |
||||
|
|
||||
|
### ❌ Never Allow Without Testing |
||||
|
|
||||
|
- **Update** build dependencies |
||||
|
- **Change** environment configurations |
||||
|
- **Modify** asset generation scripts |
||||
|
- **Alter** test infrastructure |
||||
|
- **Update** platform SDK versions |
||||
|
|
||||
|
## Required Validation Checklist |
||||
|
|
||||
|
### Before Any Build System Change |
||||
|
|
||||
|
- [ ] **Impact Assessment**: Which platforms are affected? |
||||
|
- [ ] **Testing Plan**: How will this be tested across platforms? |
||||
|
- [ ] **Rollback Plan**: How can this be reverted if it breaks? |
||||
|
- [ ] **Documentation**: Will `BUILDING.md` need updates? |
||||
|
- [ ] **Dependencies**: Are all required tools available? |
||||
|
|
||||
|
### After Build System Change |
||||
|
|
||||
|
- [ ] **Web Platform**: Does `npm run build:web:dev` work? |
||||
|
- [ ] **Mobile Platforms**: Do iOS/Android builds succeed? |
||||
|
- [ ] **Desktop Platform**: Does Electron build and run? |
||||
|
- [ ] **Tests Pass**: Do all build-related tests pass? |
||||
|
- [ ] **Documentation Updated**: Is `BUILDING.md` current? |
||||
|
|
||||
|
## Specific Test Commands (Minimum Required) |
||||
|
|
||||
|
### Web Platform |
||||
|
|
||||
|
- **Development**: `npm run build:web:dev` - serve and load app |
||||
|
- **Production**: `npm run build:web:prod` - verify SW and WASM present |
||||
|
|
||||
|
### Mobile Platforms |
||||
|
|
||||
|
- **Android**: `npm run build:android:test` or `:prod` - confirm assets copied |
||||
|
- **iOS**: `npm run build:ios:test` or `:prod` - verify build succeeds |
||||
|
|
||||
|
### Desktop Platform |
||||
|
|
||||
|
- **Electron**: `npm run build:electron:dev` and packaging for target OS |
||||
|
- **Verify**: Single-instance behavior and app boot |
||||
|
|
||||
|
### Auto-run (if affected) |
||||
|
|
||||
|
- **Test Mode**: `npm run auto-run:test` and platform variants |
||||
|
- **Production Mode**: `npm run auto-run:prod` and platform variants |
||||
|
|
||||
|
### Clean and Rebuild |
||||
|
|
||||
|
- Run relevant `clean:*` scripts and ensure re-build works |
||||
|
|
||||
|
## Emergency Procedures |
||||
|
|
||||
|
### Build System Broken |
||||
|
|
||||
|
1. **Immediate**: Revert to last known working commit |
||||
|
2. **Investigation**: Create issue with full error details |
||||
|
3. **Testing**: Verify all platforms work after revert |
||||
|
4. **Documentation**: Update `BUILDING.md` with failure notes |
||||
|
|
||||
|
### Platform-Specific Failure |
||||
|
|
||||
|
1. **Isolate**: Identify which platform is affected |
||||
|
2. **Test Others**: Verify other platforms still work |
||||
|
3. **Rollback**: Revert platform-specific changes |
||||
|
4. **Investigation**: Debug in isolated environment |
||||
|
|
||||
|
## Integration Points |
||||
|
|
||||
|
### With Version Control |
||||
|
|
||||
|
- **Branch Protection**: Require reviews for build script changes |
||||
|
- **Commit Messages**: Must reference ADR for major changes |
||||
|
- **Testing**: All build changes must pass CI/CD pipeline |
||||
|
|
||||
|
### With Documentation |
||||
|
|
||||
|
- **BUILDING.md**: Must be updated for any script changes |
||||
|
- **README.md**: Must reflect new build requirements |
||||
|
- **CHANGELOG.md**: Must document breaking build changes |
||||
|
|
||||
|
### With Testing |
||||
|
|
||||
|
- **Pre-commit**: Run basic build validation |
||||
|
- **CI/CD**: Full platform build testing |
||||
|
- **Manual Testing**: Human verification of critical paths |
||||
|
|
||||
|
## Risk Matrix & Required Validation |
||||
|
|
||||
|
### Environment Handling |
||||
|
|
||||
|
- **Trigger**: Change to `.env.*` loading / variable names |
||||
|
- **Validation**: Prove `dev/test/prod` builds; show environment echo in logs |
||||
|
|
||||
|
### Script Flow |
||||
|
|
||||
|
- **Trigger**: Reorder steps (prebuild → build → package), new flags |
||||
|
- **Validation**: Dry-run + normal run, show exit codes & timing |
||||
|
|
||||
|
### Platform Packaging |
||||
|
|
||||
|
- **Trigger**: Electron NSIS/DMG/AppImage, Android/iOS bundle |
||||
|
- **Validation**: Produce installer/artifact and open it; verify single-instance, |
||||
|
icons, signing |
||||
|
|
||||
|
### Service Worker / WASM |
||||
|
|
||||
|
- **Trigger**: `sw_combine.js`, WASM copy path |
||||
|
- **Validation**: Verify combined SW exists and is injected; page loads offline; |
||||
|
WASM present |
||||
|
|
||||
|
### Docker |
||||
|
|
||||
|
- **Trigger**: New base image, build args |
||||
|
- **Validation**: Build image locally; run container; list produced `/dist` |
||||
|
|
||||
|
### Signing/Notarization |
||||
|
|
||||
|
- **Trigger**: Cert path/profiles |
||||
|
- **Validation**: Show signing logs + verify on target OS |
||||
|
|
||||
|
## PR Template (Paste into Description) |
||||
|
|
||||
|
- [ ] **Level**: L1 / L2 / L3 + justification |
||||
|
- [ ] **Files & platforms touched**: |
||||
|
- [ ] **Risk triggers & mitigations**: |
||||
|
- [ ] **Commands run (paste logs)**: |
||||
|
- [ ] **Artifacts (names + sha256)**: |
||||
|
- [ ] **Docs updated (sections/links)**: |
||||
|
- [ ] **Rollback steps verified**: |
||||
|
- [ ] **CI**: Jobs passing and artifacts uploaded |
||||
|
|
||||
|
## Rollback Playbook |
||||
|
|
||||
|
### Immediate Rollback |
||||
|
|
||||
|
1. `git revert` or `git reset --hard <prev>`; restore prior `scripts/` or config |
||||
|
files |
||||
|
2. Rebuild affected targets; verify old behavior returns |
||||
|
3. Post-mortem notes → update this guard and `BUILDING.md` if gaps found |
||||
|
|
||||
|
### Rollback Verification |
||||
|
|
||||
|
- **Web**: `npm run build:web:dev` and `npm run build:web:prod` |
||||
|
- **Mobile**: `npm run build:android:test` and `npm run build:ios:test` |
||||
|
- **Desktop**: `npm run build:electron:dev` and packaging commands |
||||
|
- **Clean**: Run relevant `clean:*` scripts and verify re-build works |
||||
|
|
||||
|
## ADR Trigger List |
||||
|
|
||||
|
Raise an ADR when you propose any of: |
||||
|
|
||||
|
- **New build stage** or reorder of canonical stages |
||||
|
- **Replacement of packager** / packaging format |
||||
|
- **New environment model** or secure secret handling scheme |
||||
|
- **New service worker assembly** strategy or cache policy |
||||
|
- **New Docker base** or multi-stage pipeline |
||||
|
- **Relocation of build outputs** or directory conventions |
||||
|
|
||||
|
**ADR must include**: motivation, alternatives, risks, validation plan, rollback, |
||||
|
doc diffs. |
||||
|
|
||||
|
## Competence Hooks |
||||
|
|
||||
|
### Why This Works |
||||
|
|
||||
|
- **Prevents Build Failures**: Catches issues before they reach production |
||||
|
- **Maintains Consistency**: Ensures all platforms build identically |
||||
|
- **Reduces Debugging Time**: Prevents build system regressions |
||||
|
|
||||
|
### Common Pitfalls |
||||
|
|
||||
|
- **Silent Failures**: Changes that work on one platform but break others |
||||
|
- **Dependency Conflicts**: Updates that create version incompatibilities |
||||
|
- **Documentation Drift**: Build scripts that don't match documentation |
||||
|
|
||||
|
### Next Skill Unlock |
||||
|
|
||||
|
- Learn to test build changes across all platforms simultaneously |
||||
|
|
||||
|
### Teach-back |
||||
|
|
||||
|
- "What three platforms must I test before committing a build script change?" |
||||
|
|
||||
|
## Collaboration Hooks |
||||
|
|
||||
|
### Team Review Requirements |
||||
|
|
||||
|
- **Platform Owners**: iOS, Android, Electron, Web specialists |
||||
|
- **DevOps**: CI/CD pipeline maintainers |
||||
|
- **QA**: Testing infrastructure owners |
||||
|
|
||||
|
### Discussion Prompts |
||||
|
|
||||
|
- "Which platforms will be affected by this build change?" |
||||
|
- "How can we test this change without breaking existing builds?" |
||||
|
- "What's our rollback plan if this change fails?" |
||||
|
|
||||
|
## Self-Check (Before Allowing Changes) |
||||
|
|
||||
|
- [ ] **Authorization Level**: Is this change appropriate for the level? |
||||
|
- [ ] **Testing Plan**: Is there a comprehensive testing strategy? |
||||
|
- [ ] **Documentation**: Will BUILDING.md be updated? |
||||
|
- [ ] **Rollback**: Is there a safe rollback mechanism? |
||||
|
- [ ] **Team Review**: Have appropriate stakeholders been consulted? |
||||
|
- [ ] **CI/CD**: Will this pass the build pipeline? |
||||
|
|
||||
|
--- |
||||
|
|
||||
|
**Status**: Active build system protection |
||||
|
**Priority**: Critical |
||||
|
**Estimated Effort**: Ongoing vigilance |
||||
|
**Dependencies**: All build system components |
||||
|
**Stakeholders**: Development team, DevOps, Platform owners |
||||
|
**Next Review**: 2025-09-20 |
@ -0,0 +1,79 @@ |
|||||
|
--- |
||||
|
alwaysApply: true |
||||
|
--- |
||||
|
|
||||
|
# Markdown Automation System |
||||
|
|
||||
|
**Author**: Matthew Raymer |
||||
|
**Date**: 2025-08-20 |
||||
|
**Status**: 🎯 **ACTIVE** - Markdown formatting automation |
||||
|
|
||||
|
## Overview |
||||
|
|
||||
|
The Markdown Automation System ensures your markdown formatting standards are |
||||
|
followed **during content generation** by AI agents, not just applied after the |
||||
|
fact. |
||||
|
|
||||
|
## AI-First Approach |
||||
|
|
||||
|
### **Primary Method**: AI Agent Compliance |
||||
|
|
||||
|
- **AI agents follow markdown rules** while generating content |
||||
|
- **No post-generation fixes needed** - content is compliant from creation |
||||
|
- **Consistent formatting** across all generated documentation |
||||
|
|
||||
|
### **Secondary Method**: Automated Validation |
||||
|
|
||||
|
- **Pre-commit hooks** catch any remaining issues |
||||
|
- **GitHub Actions** validate formatting before merge |
||||
|
- **Manual tools** for bulk fixes when needed |
||||
|
|
||||
|
## How It Works |
||||
|
|
||||
|
### 1. **AI Agent Compliance** (Primary) |
||||
|
|
||||
|
- **When**: Every time AI generates markdown content |
||||
|
- **What**: AI follows markdown rules during generation |
||||
|
- **Result**: Content is properly formatted from creation |
||||
|
|
||||
|
### 2. **Pre-commit Hooks** (Backup) |
||||
|
|
||||
|
- **When**: Every time you commit |
||||
|
- **What**: Catches any remaining formatting issues |
||||
|
- **Result**: Clean, properly formatted markdown files |
||||
|
|
||||
|
### 3. **GitHub Actions** (Pre-merge) |
||||
|
|
||||
|
- **When**: Every pull request |
||||
|
- **What**: Validates markdown formatting across all files |
||||
|
- **Result**: Blocks merge if formatting issues exist |
||||
|
|
||||
|
## AI Agent Rules Integration |
||||
|
|
||||
|
The AI agent follows markdown rules defined in `.cursor/rules/docs/markdown.mdc`: |
||||
|
|
||||
|
- **alwaysApply: true** - Rules are enforced during generation |
||||
|
- **Line Length**: AI never generates lines > 80 characters |
||||
|
- **Blank Lines**: AI adds proper spacing around all elements |
||||
|
- **Structure**: AI uses established templates and patterns |
||||
|
|
||||
|
## Available Commands |
||||
|
|
||||
|
### NPM Scripts |
||||
|
|
||||
|
- **`npm run markdown:setup`** - Install the automation system |
||||
|
- **`npm run markdown:fix`** - Fix formatting in all markdown files |
||||
|
- **`npm run markdown:check`** - Validate formatting without fixing |
||||
|
|
||||
|
## Benefits |
||||
|
|
||||
|
- **No more manual fixes** - AI generates compliant content from start |
||||
|
- **Consistent style** - All files follow same standards |
||||
|
- **Faster development** - No need to fix formatting manually |
||||
|
|
||||
|
--- |
||||
|
|
||||
|
**Status**: Active automation system |
||||
|
**Priority**: High |
||||
|
**Maintainer**: Development team |
||||
|
**Next Review**: 2025-09-20 |
@ -1,142 +0,0 @@ |
|||||
name: Asset Validation & CI Safeguards |
|
||||
|
|
||||
on: |
|
||||
pull_request: |
|
||||
paths: |
|
||||
- 'resources/**' |
|
||||
- 'config/assets/**' |
|
||||
- 'capacitor-assets.config.json' |
|
||||
- 'capacitor.config.ts' |
|
||||
- 'capacitor.config.json' |
|
||||
push: |
|
||||
branches: [main, develop] |
|
||||
paths: |
|
||||
- 'resources/**' |
|
||||
- 'config/assets/**' |
|
||||
- 'capacitor-assets.config.json' |
|
||||
- 'capacitor.config.ts' |
|
||||
- 'capacitor.config.json' |
|
||||
|
|
||||
jobs: |
|
||||
asset-validation: |
|
||||
runs-on: ubuntu-latest |
|
||||
steps: |
|
||||
- name: Checkout code |
|
||||
uses: actions/checkout@v4 |
|
||||
|
|
||||
- name: Setup Node.js |
|
||||
uses: actions/setup-node@v4 |
|
||||
with: |
|
||||
node-version-file: '.nvmrc' |
|
||||
cache: 'npm' |
|
||||
|
|
||||
- name: Install dependencies |
|
||||
run: npm ci |
|
||||
|
|
||||
- name: Validate asset configuration |
|
||||
run: npm run assets:validate |
|
||||
|
|
||||
- name: Check for committed platform assets (Android) |
|
||||
run: | |
|
||||
if git ls-files -z android/app/src/main/res | grep -E '(AppIcon.*\.png|Splash.*\.png|mipmap-.*/ic_launcher.*\.png)' > /dev/null; then |
|
||||
echo "❌ Android platform assets found in VCS - these should be generated at build-time" |
|
||||
git ls-files -z android/app/src/main/res | grep -E '(AppIcon.*\.png|Splash.*\.png|mipmap-.*/ic_launcher.*\.png)' |
|
||||
exit 1 |
|
||||
fi |
|
||||
echo "✅ No Android platform assets committed" |
|
||||
|
|
||||
- name: Check for committed platform assets (iOS) |
|
||||
run: | |
|
||||
if git ls-files -z ios/App/App/Assets.xcassets | grep -E '(AppIcon.*\.png|Splash.*\.png)' > /dev/null; then |
|
||||
echo "❌ iOS platform assets found in VCS - these should be generated at build-time" |
|
||||
git ls-files -z ios/App/App/Assets.xcassets | grep -E '(AppIcon.*\.png|Splash.*\.png)' |
|
||||
exit 1 |
|
||||
fi |
|
||||
echo "✅ No iOS platform assets committed" |
|
||||
|
|
||||
- name: Test asset generation |
|
||||
run: | |
|
||||
echo "🧪 Testing asset generation workflow..." |
|
||||
npm run build:capacitor |
|
||||
npx cap sync |
|
||||
npx capacitor-assets generate --dry-run || npx capacitor-assets generate |
|
||||
echo "✅ Asset generation test completed" |
|
||||
|
|
||||
- name: Verify clean tree after build |
|
||||
run: | |
|
||||
if [ -n "$(git status --porcelain)" ]; then |
|
||||
echo "❌ Dirty tree after build - asset configs were modified" |
|
||||
git status |
|
||||
git diff |
|
||||
exit 1 |
|
||||
fi |
|
||||
echo "✅ Build completed with clean tree" |
|
||||
|
|
||||
schema-validation: |
|
||||
runs-on: ubuntu-latest |
|
||||
steps: |
|
||||
- name: Checkout code |
|
||||
uses: actions/checkout@v4 |
|
||||
|
|
||||
- name: Setup Node.js |
|
||||
uses: actions/setup-node@v4 |
|
||||
with: |
|
||||
node-version-file: '.nvmrc' |
|
||||
cache: 'npm' |
|
||||
|
|
||||
- name: Install dependencies |
|
||||
run: npm ci |
|
||||
|
|
||||
- name: Validate schema compliance |
|
||||
run: | |
|
||||
echo "🔍 Validating schema compliance..." |
|
||||
node -e " |
|
||||
const fs = require('fs'); |
|
||||
const config = JSON.parse(fs.readFileSync('capacitor-assets.config.json', 'utf8')); |
|
||||
const schema = JSON.parse(fs.readFileSync('config/assets/schema.json', 'utf8')); |
|
||||
|
|
||||
// Basic schema validation |
|
||||
if (!config.icon || !config.splash) { |
|
||||
throw new Error('Missing required sections: icon and splash'); |
|
||||
} |
|
||||
|
|
||||
if (!config.icon.source || !config.splash.source) { |
|
||||
throw new Error('Missing required source fields'); |
|
||||
} |
|
||||
|
|
||||
if (!/^resources\/.*\.(png|svg)$/.test(config.icon.source)) { |
|
||||
throw new Error('Icon source must be in resources/ directory'); |
|
||||
} |
|
||||
|
|
||||
if (!/^resources\/.*\.(png|svg)$/.test(config.splash.source)) { |
|
||||
throw new Error('Splash source must be in resources/ directory'); |
|
||||
} |
|
||||
|
|
||||
console.log('✅ Schema validation passed'); |
|
||||
" |
|
||||
|
|
||||
- name: Check source file existence |
|
||||
run: | |
|
||||
echo "📁 Checking source file existence..." |
|
||||
node -e " |
|
||||
const fs = require('fs'); |
|
||||
const config = JSON.parse(fs.readFileSync('capacitor-assets.config.json', 'utf8')); |
|
||||
|
|
||||
const requiredFiles = [ |
|
||||
config.icon.source, |
|
||||
config.splash.source |
|
||||
]; |
|
||||
|
|
||||
if (config.splash.darkSource) { |
|
||||
requiredFiles.push(config.splash.darkSource); |
|
||||
} |
|
||||
|
|
||||
const missingFiles = requiredFiles.filter(file => !fs.existsSync(file)); |
|
||||
|
|
||||
if (missingFiles.length > 0) { |
|
||||
console.error('❌ Missing source files:', missingFiles); |
|
||||
process.exit(1); |
|
||||
} |
|
||||
|
|
||||
console.log('✅ All source files exist'); |
|
||||
" |
|
@ -1,27 +0,0 @@ |
|||||
name: Playwright Tests |
|
||||
on: |
|
||||
push: |
|
||||
branches: [ main, master ] |
|
||||
pull_request: |
|
||||
branches: [ main, master ] |
|
||||
jobs: |
|
||||
test: |
|
||||
timeout-minutes: 60 |
|
||||
runs-on: ubuntu-latest |
|
||||
steps: |
|
||||
- uses: actions/checkout@v4 |
|
||||
- uses: actions/setup-node@v4 |
|
||||
with: |
|
||||
node-version: lts/* |
|
||||
- name: Install dependencies |
|
||||
run: npm ci |
|
||||
- name: Install Playwright Browsers |
|
||||
run: npx playwright install --with-deps |
|
||||
- name: Run Playwright tests |
|
||||
run: npx playwright test |
|
||||
- uses: actions/upload-artifact@v4 |
|
||||
if: always() |
|
||||
with: |
|
||||
name: playwright-report |
|
||||
path: playwright-report/ |
|
||||
retention-days: 30 |
|
@ -0,0 +1,40 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
# |
||||
|
# Husky Helper Script |
||||
|
# This file is sourced by all Husky hooks |
||||
|
# |
||||
|
if [ -z "$husky_skip_init" ]; then |
||||
|
debug () { |
||||
|
if [ "$HUSKY_DEBUG" = "1" ]; then |
||||
|
echo "husky (debug) - $1" |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
readonly hook_name="$(basename -- "$0")" |
||||
|
debug "starting $hook_name..." |
||||
|
|
||||
|
if [ "$HUSKY" = "0" ]; then |
||||
|
debug "HUSKY env variable is set to 0, skipping hook" |
||||
|
exit 0 |
||||
|
fi |
||||
|
|
||||
|
if [ -f ~/.huskyrc ]; then |
||||
|
debug "sourcing ~/.huskyrc" |
||||
|
. ~/.huskyrc |
||||
|
fi |
||||
|
|
||||
|
readonly husky_skip_init=1 |
||||
|
export husky_skip_init |
||||
|
sh -e "$0" "$@" |
||||
|
exitCode="$?" |
||||
|
|
||||
|
if [ $exitCode != 0 ]; then |
||||
|
echo "husky - $hook_name hook exited with code $exitCode (error)" |
||||
|
fi |
||||
|
|
||||
|
if [ $exitCode = 127 ]; then |
||||
|
echo "husky - command not found in PATH=$PATH" |
||||
|
fi |
||||
|
|
||||
|
exit $exitCode |
||||
|
fi |
@ -0,0 +1,10 @@ |
|||||
|
#!/usr/bin/env bash |
||||
|
# |
||||
|
# Husky Commit Message Hook |
||||
|
# Validates commit message format using commitlint |
||||
|
# |
||||
|
. "$(dirname -- "$0")/_/husky.sh" |
||||
|
|
||||
|
# Run commitlint but don't fail the commit (|| true) |
||||
|
# This provides helpful feedback without blocking commits |
||||
|
npx commitlint --edit "$1" || true |
@ -0,0 +1,15 @@ |
|||||
|
#!/usr/bin/env bash |
||||
|
# |
||||
|
# Husky Pre-commit Hook |
||||
|
# Runs Build Architecture Guard to check staged files |
||||
|
# |
||||
|
. "$(dirname -- "$0")/_/husky.sh" |
||||
|
|
||||
|
echo "🔍 Running Build Architecture Guard (pre-commit)..." |
||||
|
bash ./scripts/build-arch-guard.sh --staged || { |
||||
|
echo |
||||
|
echo "💡 To bypass this check for emergency commits, use:" |
||||
|
echo " git commit --no-verify" |
||||
|
echo |
||||
|
exit 1 |
||||
|
} |
@ -0,0 +1,27 @@ |
|||||
|
#!/usr/bin/env bash |
||||
|
# |
||||
|
# Husky Pre-push Hook |
||||
|
# Runs Build Architecture Guard to check commits being pushed |
||||
|
# |
||||
|
. "$(dirname -- "$0")/_/husky.sh" |
||||
|
|
||||
|
echo "🔍 Running Build Architecture Guard (pre-push)..." |
||||
|
|
||||
|
# Get the remote branch we're pushing to |
||||
|
REMOTE_BRANCH="origin/$(git rev-parse --abbrev-ref HEAD)" |
||||
|
|
||||
|
# Check if remote branch exists |
||||
|
if git show-ref --verify --quiet "refs/remotes/$REMOTE_BRANCH"; then |
||||
|
RANGE="$REMOTE_BRANCH...HEAD" |
||||
|
else |
||||
|
# If remote branch doesn't exist, check last commit |
||||
|
RANGE="HEAD~1..HEAD" |
||||
|
fi |
||||
|
|
||||
|
bash ./scripts/build-arch-guard.sh --range "$RANGE" || { |
||||
|
echo |
||||
|
echo "💡 To bypass this check for emergency pushes, use:" |
||||
|
echo " git push --no-verify" |
||||
|
echo |
||||
|
exit 1 |
||||
|
} |
File diff suppressed because it is too large
@ -0,0 +1,290 @@ |
|||||
|
# Build Architecture Guard - Husky Implementation |
||||
|
|
||||
|
## Overview |
||||
|
|
||||
|
The Build Architecture Guard protects your build system by enforcing |
||||
|
documentation requirements through **Git hooks**. When you modify |
||||
|
build-critical files, the system automatically blocks commits/pushes |
||||
|
until you update `BUILDING.md`. |
||||
|
|
||||
|
## 🎯 **Why Husky-Only?** |
||||
|
|
||||
|
**Advantages:** |
||||
|
|
||||
|
- ✅ **Immediate feedback** - Hooks run before commit/push |
||||
|
- ✅ **Works everywhere** - No server-side CI/CD required |
||||
|
- ✅ **Simple setup** - One tool, one configuration |
||||
|
- ✅ **Fast execution** - No network delays or server queues |
||||
|
- ✅ **Offline support** - Works without internet connection |
||||
|
|
||||
|
**Trade-offs:** |
||||
|
|
||||
|
- ⚠️ **Can be bypassed** - `git commit --no-verify` or `git push --no-verify` |
||||
|
- ⚠️ **Developer discipline** - Relies on team following the rules |
||||
|
|
||||
|
## 🏗️ **Architecture** |
||||
|
|
||||
|
```bash |
||||
|
Developer Workflow: |
||||
|
1. Modify build files (scripts/, vite.config.*, etc.) |
||||
|
2. Try to commit → Husky pre-commit hook runs |
||||
|
3. Guard script checks if BUILDING.md was updated |
||||
|
4. ✅ Commit succeeds if docs updated |
||||
|
5. ❌ Commit blocked if docs missing |
||||
|
``` |
||||
|
|
||||
|
## 🚀 **Quick Start** |
||||
|
|
||||
|
### 1. Install Dependencies |
||||
|
|
||||
|
```bash |
||||
|
npm install |
||||
|
npm run prepare # Sets up Husky hooks |
||||
|
``` |
||||
|
|
||||
|
### 2. Test the System |
||||
|
|
||||
|
```bash |
||||
|
# Modify a build file without updating BUILDING.md |
||||
|
echo "# test" >> scripts/test.sh |
||||
|
|
||||
|
# Try to commit (should be blocked) |
||||
|
git add scripts/test.sh |
||||
|
git commit -m "test: add build script" |
||||
|
# ❌ Hook blocks commit with helpful message |
||||
|
``` |
||||
|
|
||||
|
### 3. Fix and Retry |
||||
|
|
||||
|
```bash |
||||
|
# Update BUILDING.md with your changes |
||||
|
echo "## New Build Script" >> BUILDING.md |
||||
|
echo "Added test.sh for testing purposes" >> BUILDING.md |
||||
|
|
||||
|
# Now commit should succeed |
||||
|
git add BUILDING.md |
||||
|
git commit -m "feat: add test build script with docs" |
||||
|
# ✅ Commit succeeds |
||||
|
``` |
||||
|
|
||||
|
## 🔧 **How It Works** |
||||
|
|
||||
|
### Pre-commit Hook (`.husky/pre-commit`) |
||||
|
|
||||
|
- **When**: Every `git commit` |
||||
|
- **What**: Runs `./scripts/build-arch-guard.sh --staged` |
||||
|
- **Result**: Blocks commit if build files changed without BUILDING.md update |
||||
|
|
||||
|
### Pre-push Hook (`.husky/pre-push`) |
||||
|
|
||||
|
- **When**: Every `git push` |
||||
|
- **What**: Runs `./scripts/build-arch-guard.sh --range` |
||||
|
- **Result**: Blocks push if commits contain undocumented build changes |
||||
|
|
||||
|
### Guard Script (`scripts/build-arch-guard.sh`) |
||||
|
|
||||
|
- **Detects**: Changes to build-sensitive file patterns |
||||
|
- **Validates**: BUILDING.md was updated alongside changes |
||||
|
- **Reports**: Clear error messages with guidance |
||||
|
|
||||
|
## 📁 **Protected File Patterns** |
||||
|
|
||||
|
The guard script monitors these paths for changes: |
||||
|
|
||||
|
```text |
||||
|
Build Configuration: |
||||
|
├── vite.config.* # Vite configuration |
||||
|
├── capacitor.config.ts # Capacitor configuration |
||||
|
├── package.json # Package configuration |
||||
|
├── package-lock.json # Lock files |
||||
|
├── yarn.lock |
||||
|
└── pnpm-lock.yaml |
||||
|
|
||||
|
Build Scripts: |
||||
|
├── scripts/** # All build and automation scripts |
||||
|
├── electron/** # Electron build files |
||||
|
├── android/** # Android build configuration |
||||
|
├── ios/** # iOS build configuration |
||||
|
├── sw_scripts/** # Service worker scripts |
||||
|
└── sw_combine.js # Service worker combination |
||||
|
|
||||
|
Deployment: |
||||
|
├── Dockerfile # Docker configuration |
||||
|
└── docker/** # Docker services |
||||
|
``` |
||||
|
|
||||
|
## 🎭 **Usage Scenarios** |
||||
|
|
||||
|
### Scenario 1: Adding a New Build Script |
||||
|
|
||||
|
```bash |
||||
|
# ❌ This will be blocked |
||||
|
echo '#!/bin/bash' > scripts/new-build.sh |
||||
|
git add scripts/new-build.sh |
||||
|
git commit -m "feat: add new build script" |
||||
|
# Hook blocks: "Build-sensitive files changed but BUILDING.md not updated" |
||||
|
|
||||
|
# ✅ This will succeed |
||||
|
echo '#!/bin/bash' > scripts/new-build.sh |
||||
|
echo '## New Build Script' >> BUILDING.md |
||||
|
echo 'Added new-build.sh for feature X' >> BUILDING.md |
||||
|
git add scripts/new-build.sh BUILDING.md |
||||
|
git commit -m "feat: add new build script with docs" |
||||
|
# ✅ Commit succeeds |
||||
|
``` |
||||
|
|
||||
|
### Scenario 2: Updating Vite Configuration |
||||
|
|
||||
|
```bash |
||||
|
# ❌ This will be blocked |
||||
|
echo 'export default { newOption: true }' >> vite.config.ts |
||||
|
git add vite.config.ts |
||||
|
git commit -m "config: add new vite option" |
||||
|
# Hook blocks: "Build-sensitive files changed but BUILDING.md not updated" |
||||
|
|
||||
|
# ✅ This will succeed |
||||
|
echo 'export default { newOption: true }' >> vite.config.ts |
||||
|
echo '### New Vite Option' >> BUILDING.md |
||||
|
echo 'Added newOption for improved performance' >> BUILDING.md |
||||
|
git add vite.config.ts BUILDING.md |
||||
|
git commit -m "config: add new vite option with docs" |
||||
|
# ✅ Commit succeeds |
||||
|
``` |
||||
|
|
||||
|
## 🚨 **Emergency Bypass** |
||||
|
|
||||
|
**⚠️ Use sparingly and only for emergencies:** |
||||
|
|
||||
|
```bash |
||||
|
# Skip pre-commit hook |
||||
|
git commit -m "emergency: critical fix" --no-verify |
||||
|
|
||||
|
# Skip pre-push hook |
||||
|
git push --no-verify |
||||
|
|
||||
|
# Remember to update BUILDING.md later! |
||||
|
``` |
||||
|
|
||||
|
## 🔍 **Troubleshooting** |
||||
|
|
||||
|
### Hooks Not Running |
||||
|
|
||||
|
```bash |
||||
|
# Reinstall hooks |
||||
|
npm run prepare |
||||
|
|
||||
|
# Check hook files exist and are executable |
||||
|
ls -la .husky/ |
||||
|
chmod +x .husky/* |
||||
|
|
||||
|
# Verify Git hooks path |
||||
|
git config core.hooksPath |
||||
|
# Should show: .husky |
||||
|
``` |
||||
|
|
||||
|
### Guard Script Issues |
||||
|
|
||||
|
```bash |
||||
|
# Test guard script manually |
||||
|
./scripts/build-arch-guard.sh --help |
||||
|
|
||||
|
# Check script permissions |
||||
|
chmod +x scripts/build-arch-guard.sh |
||||
|
|
||||
|
# Test with specific files |
||||
|
./scripts/build-arch-guard.sh --staged |
||||
|
``` |
||||
|
|
||||
|
### False Positives |
||||
|
|
||||
|
```bash |
||||
|
# If guard blocks legitimate changes, check: |
||||
|
# 1. Are you modifying a protected file pattern? |
||||
|
# 2. Did you update BUILDING.md? |
||||
|
# 3. Is BUILDING.md staged for commit? |
||||
|
|
||||
|
# View what the guard sees |
||||
|
git diff --name-only --cached |
||||
|
``` |
||||
|
|
||||
|
## 📋 **Best Practices** |
||||
|
|
||||
|
### For Developers |
||||
|
|
||||
|
1. **Update BUILDING.md first** - Document changes before implementing |
||||
|
2. **Test locally** - Run `./scripts/build-arch-guard.sh --staged` before committing |
||||
|
3. **Use descriptive commits** - Include context about build changes |
||||
|
4. **Don't bypass lightly** - Only use `--no-verify` for true emergencies |
||||
|
|
||||
|
### For Teams |
||||
|
|
||||
|
1. **Document the system** - Ensure everyone understands the guard |
||||
|
2. **Review BUILDING.md updates** - Verify documentation quality |
||||
|
3. **Monitor bypass usage** - Track when hooks are skipped |
||||
|
4. **Regular audits** - Check that BUILDING.md stays current |
||||
|
|
||||
|
### For Maintainers |
||||
|
|
||||
|
1. **Update protected patterns** - Modify `scripts/build-arch-guard.sh` as needed |
||||
|
2. **Monitor effectiveness** - Track how often the guard catches issues |
||||
|
3. **Team training** - Help developers understand the system |
||||
|
4. **Continuous improvement** - Refine patterns and error messages |
||||
|
|
||||
|
## 🔄 **Customization** |
||||
|
|
||||
|
### Adding New Protected Paths |
||||
|
|
||||
|
Edit `scripts/build-arch-guard.sh`: |
||||
|
|
||||
|
```bash |
||||
|
SENSITIVE=( |
||||
|
# ... existing patterns ... |
||||
|
"new-pattern/**" # Add your new pattern |
||||
|
"*.config.js" # Add file extensions |
||||
|
) |
||||
|
``` |
||||
|
|
||||
|
### Modifying Error Messages |
||||
|
|
||||
|
Edit the guard script to customize: |
||||
|
|
||||
|
- Error message content |
||||
|
- File pattern matching |
||||
|
- Documentation requirements |
||||
|
- Bypass instructions |
||||
|
|
||||
|
### Adding New Validation Rules |
||||
|
|
||||
|
Extend the guard script to check for: |
||||
|
|
||||
|
- Specific file content patterns |
||||
|
- Required documentation sections |
||||
|
- Commit message formats |
||||
|
- Branch naming conventions |
||||
|
|
||||
|
## 📚 **Integration with PR Template** |
||||
|
|
||||
|
The `pull_request_template.md` works with this system by: |
||||
|
|
||||
|
- **Guiding developers** through required documentation |
||||
|
- **Ensuring consistency** across all build changes |
||||
|
- **Providing checklist** for comprehensive updates |
||||
|
- **Supporting L1/L2/L3** change classification |
||||
|
|
||||
|
## 🎯 **Success Metrics** |
||||
|
|
||||
|
Track the effectiveness of your Build Architecture Guard: |
||||
|
|
||||
|
- **Hook execution rate** - How often hooks run successfully |
||||
|
- **Bypass frequency** - How often `--no-verify` is used |
||||
|
- **Documentation quality** - BUILDING.md stays current |
||||
|
- **Build failures** - Fewer issues from undocumented changes |
||||
|
- **Team adoption** - Developers follow the process |
||||
|
|
||||
|
--- |
||||
|
|
||||
|
**Status**: Active protection system |
||||
|
**Architecture**: Client-side Git hooks only |
||||
|
**Dependencies**: Husky, Git, Bash |
||||
|
**Maintainer**: Development team |
||||
|
**Related**: `pull_request_template.md`, `scripts/build-arch-guard.sh` |
@ -0,0 +1,82 @@ |
|||||
|
# Pull Request Template |
||||
|
|
||||
|
## Location |
||||
|
|
||||
|
The Build Architecture Guard PR template is located at: |
||||
|
|
||||
|
- **`pull_request_template.md`** (root directory) |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
When creating a pull request in Gitea, this template will automatically populate the PR description with the required checklist. |
||||
|
|
||||
|
## Template Features |
||||
|
|
||||
|
### Change Level Classification |
||||
|
|
||||
|
- **L1**: Minor changes, documentation updates |
||||
|
- **L2**: Moderate changes, new features, environment changes |
||||
|
- **L3**: Major changes, architecture changes, new platforms |
||||
|
|
||||
|
### Required Fields for All Levels |
||||
|
|
||||
|
- Change level selection |
||||
|
- Scope and impact description |
||||
|
- Commands executed and their output |
||||
|
- Documentation updates (BUILDING.md) |
||||
|
- Rollback verification steps |
||||
|
|
||||
|
### Additional Requirements for L3 |
||||
|
|
||||
|
- **ADR link**: Must provide URL to Architectural Decision Record |
||||
|
- **Artifacts with SHA256**: Must list artifacts with cryptographic hashes |
||||
|
|
||||
|
## Integration |
||||
|
|
||||
|
This template works with: |
||||
|
|
||||
|
- **Gitea Actions**: `.gitea/workflows/build-guard.yml` |
||||
|
- **Client-side hooks**: `.husky/` pre-commit and pre-push hooks |
||||
|
- **Guard script**: `scripts/build-arch-guard.sh` |
||||
|
|
||||
|
## Example Usage |
||||
|
|
||||
|
```markdown |
||||
|
### Change Level |
||||
|
- [x] Level: **L2** |
||||
|
|
||||
|
**Why:** Adding new build script for Docker deployment |
||||
|
|
||||
|
### Scope & Impact |
||||
|
- [x] Files & platforms touched: scripts/build-docker.sh, |
||||
|
BUILDING.md |
||||
|
- [x] Risk triggers: Docker build process changes |
||||
|
- [x] Mitigations/validation done: Tested on local Docker environment |
||||
|
|
||||
|
### Commands Run |
||||
|
- [x] Web: `npm run build:web:docker` ✅ |
||||
|
- [x] Docker: `docker build -t test-image .` ✅ |
||||
|
|
||||
|
### Artifacts |
||||
|
- [x] Names + **sha256** of artifacts/installers: |
||||
|
|
||||
|
Artifacts: |
||||
|
```text |
||||
|
test-image.tar a1b2c3d4e5f6... |
||||
|
``` |
||||
|
|
||||
|
### Docs |
||||
|
- [x] **BUILDING.md** updated (sections): Docker deployment |
||||
|
- [x] Troubleshooting updated: Added Docker troubleshooting section |
||||
|
|
||||
|
### Rollback |
||||
|
- [x] Verified steps to restore previous behavior: |
||||
|
1. `git revert HEAD` |
||||
|
2. `docker rmi test-image` |
||||
|
3. Restore previous BUILDING.md |
||||
|
``` |
||||
|
|
||||
|
--- |
||||
|
|
||||
|
**Note**: This template is enforced by the Build Architecture Guard |
||||
|
system. Complete all required fields to ensure your PR can be merged. |
@ -1,270 +1,118 @@ |
|||||
# TimeSafari.app - Crowd-Funder for Time - PWA |
# Time Safari Application |
||||
|
|
||||
[Time Safari](https://timesafari.org/) allows people to ease into collaboration: start with expressions of gratitude |
**Author**: Matthew Raymer |
||||
and expand to crowd-fund with time & money, then record and see the impact of contributions. |
**Version**: 1.0.8-beta |
||||
|
**Description**: Time Safari Application |
||||
|
|
||||
## Roadmap |
## 🛡️ Build Architecture Guard |
||||
|
|
||||
See [ClickUp](https://sharing.clickup.com/9014278710/l/h/8cmnyhp-174/10573fec74e2ba0) for current priorities. |
This project uses **Husky Git hooks** to protect the build system |
||||
|
architecture. When you modify build-critical files, the system |
||||
|
automatically blocks commits until you update `BUILDING.md`. |
||||
|
|
||||
## Setup & Building |
### Quick Setup |
||||
|
|
||||
Quick start: |
|
||||
|
|
||||
* For setup, we recommend [pkgx](https://pkgx.dev), which installs what you need (either automatically or with the `dev` command). Core dependencies are typescript & npm; when building for other platforms, you'll need other things such as those in the pkgx.yaml & BUILDING.md files. |
|
||||
|
|
||||
```bash |
```bash |
||||
npm install |
npm run guard:setup # Install and activate the guard |
||||
npm run build:web:serve -- --test |
|
||||
``` |
|
||||
|
|
||||
To be able to make submissions: go to "profile" (bottom left), go to the bottom and expand "Show Advanced Settings", go to the bottom and to the "Test Page", and finally "Become User 0" to see all the functionality. |
|
||||
|
|
||||
See [BUILDING.md](BUILDING.md) for comprehensive build instructions for all platforms (Web, Electron, iOS, Android, Docker). |
|
||||
|
|
||||
## Development Database Clearing |
|
||||
|
|
||||
TimeSafari provides a simple script-based approach to clear the local database (not the claim server) for development purposes. |
|
||||
|
|
||||
## Logging Configuration |
|
||||
|
|
||||
TimeSafari supports configurable logging levels via the `VITE_LOG_LEVEL` environment variable. This allows developers to control console output verbosity without modifying code. |
|
||||
|
|
||||
### Quick Usage |
|
||||
|
|
||||
```bash |
|
||||
# Show only errors |
|
||||
VITE_LOG_LEVEL=error npm run dev |
|
||||
|
|
||||
# Show warnings and errors |
|
||||
VITE_LOG_LEVEL=warn npm run dev |
|
||||
|
|
||||
# Show info, warnings, and errors (default) |
|
||||
VITE_LOG_LEVEL=info npm run dev |
|
||||
|
|
||||
# Show all log levels including debug |
|
||||
VITE_LOG_LEVEL=debug npm run dev |
|
||||
``` |
``` |
||||
|
|
||||
### Available Levels |
### How It Works |
||||
|
|
||||
- **`error`**: Critical errors only |
- **Pre-commit**: Blocks commits if build files changed without |
||||
- **`warn`**: Warnings and errors (default for production web) |
BUILDING.md updates |
||||
- **`info`**: Info, warnings, and errors (default for development/capacitor) |
- **Pre-push**: Blocks pushes if commits contain undocumented build |
||||
- **`debug`**: All log levels including verbose debugging |
changes |
||||
|
- **Protected paths**: `scripts/`, `vite.config.*`, `electron/`, |
||||
|
`android/`, `ios/`, etc. |
||||
|
|
||||
See [Logging Configuration Guide](doc/logging-configuration.md) for complete details. |
### Usage |
||||
|
|
||||
### Quick Usage |
|
||||
```bash |
```bash |
||||
# Run the database clearing script |
# Test the guard manually |
||||
./scripts/clear-database.sh |
npm run guard:test |
||||
|
|
||||
# Then restart your development server |
# Emergency bypass (use sparingly) |
||||
npm run build:electron:dev # For Electron |
git commit --no-verify |
||||
npm run build:web:dev # For Web |
git push --no-verify |
||||
``` |
``` |
||||
|
|
||||
### What It Does |
**📚 Full documentation**: See `README-BUILD-GUARD.md` |
||||
|
|
||||
#### **Electron (Desktop App)** |
|
||||
- Automatically finds and clears the SQLite database files |
|
||||
- Works on Linux, macOS, and Windows |
|
||||
- Clears all data and forces fresh migrations on next startup |
|
||||
|
|
||||
#### **Web Browser** |
|
||||
- Provides instructions for using custom browser data directories |
|
||||
- Shows manual clearing via browser DevTools |
|
||||
- Ensures reliable database clearing without browser complications |
|
||||
|
|
||||
### Safety Features |
|
||||
- ✅ **Interactive Script**: Guides you through the process |
|
||||
- ✅ **Platform Detection**: Automatically detects your OS |
|
||||
- ✅ **Clear Instructions**: Step-by-step guidance for each platform |
|
||||
- ✅ **Safe Paths**: Only clears TimeSafari-specific data |
|
||||
|
|
||||
### Manual Commands (if needed) |
## 🚀 Quick Start |
||||
|
|
||||
#### **Electron Database Location** |
### Prerequisites |
||||
```bash |
|
||||
# Linux |
|
||||
rm -rf ~/.config/TimeSafari/* |
|
||||
|
|
||||
# macOS |
- Node.js 18+ |
||||
rm -rf ~/Library/Application\ Support/TimeSafari/* |
- npm, yarn, or pnpm |
||||
|
- Git |
||||
|
|
||||
# Windows |
### Installation |
||||
rmdir /s /q %APPDATA%\TimeSafari |
|
||||
``` |
|
||||
|
|
||||
#### **Web Browser (Custom Data Directory)** |
|
||||
```bash |
```bash |
||||
# Create isolated browser profile |
npm install |
||||
mkdir ~/timesafari-dev-data |
npm run guard:setup # Sets up Build Architecture Guard |
||||
``` |
|
||||
|
|
||||
## Domain Configuration |
|
||||
|
|
||||
TimeSafari uses a centralized domain configuration system to ensure consistent |
|
||||
URL generation across all environments. This prevents localhost URLs from |
|
||||
appearing in shared links during development. |
|
||||
|
|
||||
### Key Features |
|
||||
- ✅ **Production URLs for Sharing**: All copy link buttons use production domain |
|
||||
- ✅ **Environment-Specific Internal URLs**: Internal operations use appropriate |
|
||||
environment URLs |
|
||||
- ✅ **Single Point of Control**: Change domain in one place for entire app |
|
||||
- ✅ **Type-Safe Configuration**: Full TypeScript support |
|
||||
|
|
||||
### Quick Reference |
|
||||
|
|
||||
```typescript |
|
||||
// For sharing functionality (environment-specific) |
|
||||
import { APP_SERVER } from "@/constants/app"; |
|
||||
const shareLink = `${APP_SERVER}/deep-link/claim/123`; |
|
||||
|
|
||||
// For internal operations (environment-specific) |
|
||||
import { APP_SERVER } from "@/constants/app"; |
|
||||
const apiUrl = `${APP_SERVER}/api/claim/123`; |
|
||||
``` |
``` |
||||
|
|
||||
### Documentation |
### Development |
||||
|
|
||||
- [Constants and Configuration](src/constants/app.ts) - Core constants |
|
||||
|
|
||||
## Tests |
|
||||
|
|
||||
See [TESTING.md](test-playwright/TESTING.md) for detailed test instructions. |
|
||||
|
|
||||
## Asset Management |
|
||||
|
|
||||
TimeSafari uses a standardized asset configuration system for consistent |
|
||||
icon and splash screen generation across all platforms. |
|
||||
|
|
||||
### Asset Sources |
|
||||
|
|
||||
- **Single source of truth**: `resources/` directory (Capacitor default) |
|
||||
- **Source files**: `icon.png`, `splash.png`, `splash_dark.png` |
|
||||
- **Format**: PNG or SVG files for optimal quality |
|
||||
|
|
||||
### Asset Generation |
|
||||
|
|
||||
- **Configuration**: `config/assets/capacitor-assets.config.json` |
|
||||
- **Schema validation**: `config/assets/schema.json` |
|
||||
- **Build-time generation**: Platform assets generated via `capacitor-assets` |
|
||||
- **No VCS commits**: Generated assets are never committed to version control |
|
||||
|
|
||||
### Development Commands |
|
||||
|
|
||||
```bash |
```bash |
||||
# Generate/update asset configurations |
npm run build:web:dev # Build web version |
||||
npm run assets:config |
npm run build:ios:test # Build iOS test version |
||||
|
npm run build:android:test # Build Android test version |
||||
# Validate asset configurations |
npm run build:electron:dev # Build Electron dev version |
||||
npm run assets:validate |
|
||||
|
|
||||
# Clean generated platform assets (local dev only) |
|
||||
npm run assets:clean |
|
||||
|
|
||||
# Build with asset generation |
|
||||
npm run build:native |
|
||||
``` |
``` |
||||
|
|
||||
### Environment Setup & Dependencies |
### Testing |
||||
|
|
||||
Before building the application, ensure your development environment is properly |
|
||||
configured: |
|
||||
|
|
||||
```bash |
```bash |
||||
# Install all dependencies (required first time and after updates) |
npm run test:web # Run web tests |
||||
npm install |
npm run test:mobile # Run mobile tests |
||||
|
npm run test:all # Run all tests |
||||
# Validate your development environment |
|
||||
npm run check:dependencies |
|
||||
|
|
||||
# Check prerequisites for testing |
|
||||
npm run test:prerequisites |
|
||||
``` |
``` |
||||
|
|
||||
**Common Issues & Solutions**: |
## 📁 Project Structure |
||||
|
|
||||
- **"tsx: command not found"**: Run `npm install` to install devDependencies |
```text |
||||
- **"capacitor-assets: command not found"**: Ensure `@capacitor/assets` is installed |
timesafari/ |
||||
- **Build failures**: Run `npm run check:dependencies` to diagnose environment issues |
├── 📁 src/ # Source code |
||||
|
├── 📁 scripts/ # Build and automation scripts |
||||
**Required Versions**: |
├── 📁 electron/ # Electron configuration |
||||
- Node.js: 18+ (LTS recommended) |
├── 📁 android/ # Android configuration |
||||
- npm: 8+ (comes with Node.js) |
├── 📁 ios/ # iOS configuration |
||||
- Platform-specific tools: Android Studio, Xcode (for mobile builds) |
├── 📁 .husky/ # Git hooks (Build Architecture Guard) |
||||
|
├── 📄 BUILDING.md # Build system documentation |
||||
### Platform Support |
├── 📄 pull_request_template.md # PR template |
||||
|
└── 📄 README-BUILD-GUARD.md # Guard system documentation |
||||
- **Android**: Adaptive icons with foreground/background, monochrome support |
``` |
||||
- **iOS**: LaunchScreen storyboard preferred, splash assets when needed |
|
||||
- **Web**: PWA icons generated during build to `dist/` (not committed) |
|
||||
|
|
||||
### Font Awesome Icons |
|
||||
|
|
||||
To add a Font Awesome icon, add to `fontawesome.ts` and reference with |
|
||||
`font-awesome` element and `icon` attribute with the hyphenated name. |
|
||||
|
|
||||
## Other |
|
||||
|
|
||||
### Reference Material |
|
||||
|
|
||||
* Notifications can be type of `toast` (self-dismiss), `info`, `success`, `warning`, and `danger`. |
|
||||
They are done via [notiwind](https://www.npmjs.com/package/notiwind) and set up in App.vue. |
|
||||
|
|
||||
* [Customize Vue configuration](https://cli.vuejs.org/config/). |
|
||||
|
|
||||
* If you are deploying in a subdirectory, add it to `publicPath` in vue.config.js, eg: `publicPath: "/app/time-tracker/",` |
|
||||
|
|
||||
### Code Organization |
|
||||
|
|
||||
The project uses a centralized approach to type definitions and interfaces: |
|
||||
|
|
||||
* `src/interfaces/` - Contains all TypeScript interfaces and type definitions |
## 🔧 Build System |
||||
* `deepLinks.ts` - Deep linking type system and Zod validation schemas |
|
||||
* `give.ts` - Give-related interfaces and type definitions |
|
||||
* `claims.ts` - Claim-related interfaces and verifiable credentials |
|
||||
* `common.ts` - Shared interfaces and utility types |
|
||||
* Other domain-specific interface files |
|
||||
|
|
||||
Key principles: |
This project supports multiple platforms: |
||||
- All interfaces and types are defined in the interfaces folder |
|
||||
- Zod schemas are used for runtime validation and type generation |
|
||||
- Domain-specific interfaces are separated into their own files |
|
||||
- Common interfaces are shared through `common.ts` |
|
||||
- Type definitions are generated from Zod schemas where possible |
|
||||
|
|
||||
### Database Architecture |
- **Web**: Vite-based build with service worker support |
||||
|
- **Mobile**: Capacitor-based iOS and Android builds |
||||
|
- **Desktop**: Electron-based cross-platform desktop app |
||||
|
- **Docker**: Containerized deployment options |
||||
|
|
||||
The application uses a platform-agnostic database layer with Vue mixins for service access: |
## 📚 Documentation |
||||
|
|
||||
* `src/services/PlatformService.ts` - Database interface definition |
- **`BUILDING.md`** - Complete build system guide |
||||
* `src/services/PlatformServiceFactory.ts` - Platform-specific service factory |
- **`README-BUILD-GUARD.md`** - Build Architecture Guard documentation |
||||
* `src/services/AbsurdSqlDatabaseService.ts` - SQLite implementation |
- **`pull_request_template.md`** - PR template for build changes |
||||
* `src/utils/PlatformServiceMixin.ts` - Vue mixin for database access with caching |
|
||||
* `src/db/` - Legacy Dexie database (migration in progress) |
|
||||
|
|
||||
**Development Guidelines**: |
## 🤝 Contributing |
||||
|
|
||||
- Always use `PlatformServiceMixin` for database operations in components |
1. **Follow the Build Architecture Guard** - Update BUILDING.md when modifying build files |
||||
- Test with PlatformServiceMixin for new features |
2. **Use the PR template** - Complete the checklist for build-related changes |
||||
- Use migration tools for data transfer between systems |
3. **Test your changes** - Ensure builds work on affected platforms |
||||
- Leverage mixin's ultra-concise methods: `$db()`, `$exec()`, `$one()`, `$contacts()`, `$settings()` |
4. **Document updates** - Keep BUILDING.md current and accurate |
||||
|
|
||||
**Architecture Decision**: The project uses Vue mixins over Composition API composables for platform service access. See [Architecture Decisions](doc/architecture-decisions.md) for detailed rationale. |
## 📄 License |
||||
|
|
||||
### Kudos |
[Add your license information here] |
||||
|
|
||||
Gifts make the world go 'round! |
--- |
||||
|
|
||||
* [WebStorm by JetBrains](https://www.jetbrains.com/webstorm/) for the free open-source license |
**Note**: The Build Architecture Guard is active and will block |
||||
* [Máximo Fernández](https://medium.com/@maxfarenas) for the 3D [code](https://github.com/maxfer03/vue-three-ns) and [explanatory post](https://medium.com/nicasource/building-an-interactive-web-portfolio-with-vue-three-js-part-three-implementing-three-js-452cb375ef80) |
commits/pushes that modify build files without proper documentation |
||||
* [Many tools & libraries](https://gitea.anomalistdesign.com/trent_larson/crowd-funder-for-time-pwa/src/branch/master/package.json#L10) such as Nodejs.org, IntelliJ Idea, Veramo.io, Vuejs.org, threejs.org |
updates. See `README-BUILD-GUARD.md` for complete details. |
||||
* [Bush 3D model](https://sketchfab.com/3d-models/lupine-plant-bf30f1110c174d4baedda0ed63778439) |
|
||||
* [Forest floor image](https://www.goodfreephotos.com/albums/textures/leafy-autumn-forest-floor.jpg) |
|
||||
* Time Safari logo assisted by [DALL-E in ChatGPT](https://chat.openai.com/g/g-2fkFE8rbu-dall-e) |
|
||||
* [DiceBear](https://www.dicebear.com/licenses/) and [Avataaars](https://www.dicebear.com/styles/avataaars/#details) for human-looking identicons |
|
||||
* Some gratitude prompts thanks to [Develop Good Habits](https://www.developgoodhabits.com/gratitude-journal-prompts/) |
|
||||
|
@ -0,0 +1,47 @@ |
|||||
|
# Build Architecture Guard PR Template |
||||
|
|
||||
|
## Change Level |
||||
|
|
||||
|
- [ ] Level: **L1** / **L2** / **L3** (pick one) |
||||
|
|
||||
|
**Why:** … |
||||
|
|
||||
|
## Scope & Impact |
||||
|
|
||||
|
- [ ] Files & platforms touched: … |
||||
|
- [ ] Risk triggers (env / script flow / packaging / SW+WASM / |
||||
|
Docker / signing): … |
||||
|
- [ ] Mitigations/validation done: … |
||||
|
|
||||
|
## Commands Run (paste exact logs/snips) |
||||
|
|
||||
|
- [ ] Web: `npm run build:web` / `:prod` |
||||
|
- [ ] Electron: `npm run build:electron:dev` / package step |
||||
|
- [ ] Mobile: `npm run build:android:test` / iOS equivalent |
||||
|
- [ ] Clean/auto-run impacted scripts |
||||
|
|
||||
|
## Artifacts |
||||
|
|
||||
|
- [ ] Names + **sha256** of artifacts/installers: |
||||
|
|
||||
|
Artifacts: |
||||
|
|
||||
|
```text |
||||
|
<name-1> <sha256-1> |
||||
|
<name-2> <sha256-2> |
||||
|
``` |
||||
|
|
||||
|
## Docs |
||||
|
|
||||
|
- [ ] **BUILDING.md** updated (sections): … |
||||
|
- [ ] Troubleshooting updated (if applicable) |
||||
|
|
||||
|
## Rollback |
||||
|
|
||||
|
- [ ] Verified steps (1–3 cmds) to restore previous behavior |
||||
|
|
||||
|
## L3 only |
||||
|
|
||||
|
- [ ] ADR link: |
||||
|
|
||||
|
ADR: https://… |
@ -0,0 +1,187 @@ |
|||||
|
#!/usr/bin/env bash |
||||
|
# |
||||
|
# Build Architecture Guard Script |
||||
|
# |
||||
|
# Author: Matthew Raymer |
||||
|
# Date: 2025-08-20 |
||||
|
# Purpose: Protects build-critical files by requiring BUILDING.md updates |
||||
|
# |
||||
|
# Usage: |
||||
|
# ./scripts/build-arch-guard.sh --staged # Check staged files (pre-commit) |
||||
|
# ./scripts/build-arch-guard.sh --range # Check range (pre-push) |
||||
|
# ./scripts/build-arch-guard.sh # Check working directory |
||||
|
# |
||||
|
|
||||
|
set -euo pipefail |
||||
|
|
||||
|
# Sensitive paths that require BUILDING.md updates when modified |
||||
|
SENSITIVE=( |
||||
|
"vite.config.*" |
||||
|
"scripts/**" |
||||
|
"electron/**" |
||||
|
"android/**" |
||||
|
"ios/**" |
||||
|
"sw_scripts/**" |
||||
|
"sw_combine.js" |
||||
|
"Dockerfile" |
||||
|
"docker/**" |
||||
|
"capacitor.config.ts" |
||||
|
"package.json" |
||||
|
"package-lock.json" |
||||
|
"yarn.lock" |
||||
|
"pnpm-lock.yaml" |
||||
|
) |
||||
|
|
||||
|
# Documentation files that must be updated alongside sensitive changes |
||||
|
DOCS_REQUIRED=("BUILDING.md") |
||||
|
|
||||
|
# Colors for output |
||||
|
RED='\033[0;31m' |
||||
|
GREEN='\033[0;32m' |
||||
|
YELLOW='\033[1;33m' |
||||
|
BLUE='\033[0;34m' |
||||
|
NC='\033[0m' # No Color |
||||
|
|
||||
|
log_info() { |
||||
|
echo -e "${BLUE}[guard]${NC} $1" |
||||
|
} |
||||
|
|
||||
|
log_warn() { |
||||
|
echo -e "${YELLOW}[guard]${NC} $1" |
||||
|
} |
||||
|
|
||||
|
log_error() { |
||||
|
echo -e "${RED}[guard]${NC} $1" |
||||
|
} |
||||
|
|
||||
|
log_success() { |
||||
|
echo -e "${GREEN}[guard]${NC} $1" |
||||
|
} |
||||
|
|
||||
|
# Collect files based on mode |
||||
|
collect_files() { |
||||
|
if [[ "${1:-}" == "--staged" ]]; then |
||||
|
# Pre-commit: check staged files |
||||
|
git diff --name-only --cached |
||||
|
elif [[ "${1:-}" == "--range" ]]; then |
||||
|
# Pre-push: check commits being pushed |
||||
|
RANGE="${2:-HEAD~1..HEAD}" |
||||
|
git diff --name-only "$RANGE" |
||||
|
else |
||||
|
# Default: check working directory changes |
||||
|
git diff --name-only HEAD |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
# Check if a file matches any sensitive pattern |
||||
|
matches_sensitive() { |
||||
|
local f="$1" |
||||
|
for pat in "${SENSITIVE[@]}"; do |
||||
|
# Convert glob pattern to regex |
||||
|
local rx="^${pat//\./\.}$" |
||||
|
rx="${rx//\*\*/.*}" |
||||
|
rx="${rx//\*/[^/]*}" |
||||
|
|
||||
|
if [[ "$f" =~ $rx ]]; then |
||||
|
return 0 |
||||
|
fi |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# Check if documentation was updated |
||||
|
check_docs_updated() { |
||||
|
local changed_files=("$@") |
||||
|
|
||||
|
for changed_file in "${changed_files[@]}"; do |
||||
|
for required_doc in "${DOCS_REQUIRED[@]}"; do |
||||
|
if [[ "$changed_file" == "$required_doc" ]]; then |
||||
|
return 0 |
||||
|
fi |
||||
|
done |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# Main guard logic |
||||
|
main() { |
||||
|
local mode="${1:-}" |
||||
|
local arg="${2:-}" |
||||
|
|
||||
|
log_info "Running Build Architecture Guard..." |
||||
|
|
||||
|
# Collect changed files |
||||
|
mapfile -t changed_files < <(collect_files "$mode" "$arg") |
||||
|
|
||||
|
if [[ ${#changed_files[@]} -eq 0 ]]; then |
||||
|
log_info "No files changed, guard check passed" |
||||
|
exit 0 |
||||
|
fi |
||||
|
|
||||
|
log_info "Checking ${#changed_files[@]} changed files..." |
||||
|
|
||||
|
# Find sensitive files that were touched |
||||
|
sensitive_touched=() |
||||
|
for file in "${changed_files[@]}"; do |
||||
|
if matches_sensitive "$file"; then |
||||
|
sensitive_touched+=("$file") |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
# If no sensitive files were touched, allow the change |
||||
|
if [[ ${#sensitive_touched[@]} -eq 0 ]]; then |
||||
|
log_success "No build-sensitive files changed, guard check passed" |
||||
|
exit 0 |
||||
|
fi |
||||
|
|
||||
|
# Sensitive files were touched, log them |
||||
|
log_warn "Build-sensitive paths changed:" |
||||
|
for file in "${sensitive_touched[@]}"; do |
||||
|
echo " - $file" |
||||
|
done |
||||
|
|
||||
|
# Check if required documentation was updated |
||||
|
if check_docs_updated "${changed_files[@]}"; then |
||||
|
log_success "BUILDING.md updated alongside build changes, guard check passed" |
||||
|
exit 0 |
||||
|
else |
||||
|
log_error "Build-sensitive files changed but BUILDING.md was not updated!" |
||||
|
echo |
||||
|
echo "The following build-sensitive files were modified:" |
||||
|
for file in "${sensitive_touched[@]}"; do |
||||
|
echo " - $file" |
||||
|
done |
||||
|
echo |
||||
|
echo "When modifying build-critical files, you must also update BUILDING.md" |
||||
|
echo "to document any changes to the build process." |
||||
|
echo |
||||
|
echo "Please:" |
||||
|
echo " 1. Update BUILDING.md with relevant changes" |
||||
|
echo " 2. Stage the BUILDING.md changes: git add BUILDING.md" |
||||
|
echo " 3. Retry your commit/push" |
||||
|
echo |
||||
|
exit 2 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
# Handle help flag |
||||
|
if [[ "${1:-}" =~ ^(-h|--help)$ ]]; then |
||||
|
echo "Build Architecture Guard Script" |
||||
|
echo |
||||
|
echo "Usage:" |
||||
|
echo " $0 [--staged|--range [RANGE]]" |
||||
|
echo |
||||
|
echo "Options:" |
||||
|
echo " --staged Check staged files (for pre-commit hook)" |
||||
|
echo " --range [RANGE] Check git range (for pre-push hook)" |
||||
|
echo " Default range: HEAD~1..HEAD" |
||||
|
echo " (no args) Check working directory changes" |
||||
|
echo |
||||
|
echo "Examples:" |
||||
|
echo " $0 --staged # Pre-commit check" |
||||
|
echo " $0 --range origin/main..HEAD # Pre-push check" |
||||
|
echo " $0 # Working directory check" |
||||
|
exit 0 |
||||
|
fi |
||||
|
|
||||
|
main "$@" |
@ -0,0 +1,19 @@ |
|||||
|
#!/usr/bin/env bash |
||||
|
set -euo pipefail |
||||
|
|
||||
|
echo "🔧 Auto-fixing markdown formatting..." |
||||
|
|
||||
|
# Check if markdownlint is available |
||||
|
if ! command -v npx &> /dev/null; then |
||||
|
echo "❌ npx not found. Please install Node.js and npm first." |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
# Run markdownlint with auto-fix on project markdown files (exclude node_modules) |
||||
|
echo "📝 Fixing project markdown files..." |
||||
|
npx markdownlint "*.md" "*.mdc" "scripts/**/*.md" "src/**/*.md" "test-playwright/**/*.md" "resources/**/*.md" --config .markdownlint.json --fix 2>/dev/null || { |
||||
|
echo "⚠️ Some issues could not be auto-fixed. Check manually." |
||||
|
} |
||||
|
|
||||
|
echo "✅ Markdown auto-fix complete!" |
||||
|
echo "💡 Run 'npm run markdown:check' to verify all issues are resolved." |
@ -0,0 +1,214 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
# Setup Markdown Pre-commit Hooks |
||||
|
# This script installs pre-commit hooks that automatically fix markdown formatting |
||||
|
|
||||
|
set -e |
||||
|
|
||||
|
echo "🔧 Setting up Markdown Pre-commit Hooks..." |
||||
|
|
||||
|
# Check if pre-commit is installed |
||||
|
if ! command -v pre-commit &> /dev/null; then |
||||
|
echo "📦 Installing pre-commit..." |
||||
|
pip install pre-commit |
||||
|
else |
||||
|
echo "✅ pre-commit already installed" |
||||
|
fi |
||||
|
|
||||
|
# Create .pre-commit-config.yaml if it doesn't exist |
||||
|
if [ ! -f .pre-commit-config.yaml ]; then |
||||
|
echo "📝 Creating .pre-commit-config.yaml..." |
||||
|
cat > .pre-commit-config.yaml << 'EOF' |
||||
|
repos: |
||||
|
- repo: https://github.com/igorshubovych/markdownlint-cli |
||||
|
rev: v0.38.0 |
||||
|
hooks: |
||||
|
- id: markdownlint |
||||
|
args: [--fix, --config, .markdownlint.json] |
||||
|
files: \.(md|mdc)$ |
||||
|
description: "Auto-fix markdown formatting issues" |
||||
|
stages: [commit] |
||||
|
additional_dependencies: [markdownlint-cli] |
||||
|
|
||||
|
- repo: local |
||||
|
hooks: |
||||
|
- id: markdown-format-check |
||||
|
name: Markdown Format Validation |
||||
|
entry: bash -c 'echo "Checking markdown files..." && npx markdownlint --config .markdownlint.json "$@"' |
||||
|
language: system |
||||
|
files: \.(md|mdc)$ |
||||
|
stages: [commit] |
||||
|
description: "Validate markdown formatting" |
||||
|
pass_filenames: true |
||||
|
|
||||
|
- repo: local |
||||
|
hooks: |
||||
|
- id: markdown-line-length |
||||
|
name: Markdown Line Length Check |
||||
|
entry: bash -c ' |
||||
|
for file in "$@"; do |
||||
|
if [[ "$file" =~ \.(md|mdc)$ ]]; then |
||||
|
echo "Checking line length in $file..." |
||||
|
if grep -q ".\{81,\}" "$file"; then |
||||
|
echo "❌ Line length violations found in $file" |
||||
|
echo "Lines exceeding 80 characters:" |
||||
|
grep -n ".\{81,\}" "$file" | head -5 |
||||
|
exit 1 |
||||
|
fi |
||||
|
fi |
||||
|
done |
||||
|
' |
||||
|
language: system |
||||
|
files: \.(md|mdc)$ |
||||
|
stages: [commit] |
||||
|
description: "Check markdown line length (80 chars max)" |
||||
|
pass_filenames: true |
||||
|
|
||||
|
- repo: local |
||||
|
hooks: |
||||
|
- id: markdown-blank-lines |
||||
|
name: Markdown Blank Line Validation |
||||
|
entry: bash -c ' |
||||
|
for file in "$@"; do |
||||
|
if [[ "$file" =~ \.(md|mdc)$ ]]; then |
||||
|
echo "Checking blank lines in $file..." |
||||
|
# Check for multiple consecutive blank lines |
||||
|
if grep -q "^$" "$file" && grep -A1 "^$" "$file" | grep -q "^$"; then |
||||
|
echo "❌ Multiple consecutive blank lines found in $file" |
||||
|
exit 1 |
||||
|
fi |
||||
|
# Check for missing blank lines around headings |
||||
|
if grep -B1 "^##" "$file" | grep -v "^##" | grep -v "^$" | grep -v "^--"; then |
||||
|
echo "❌ Missing blank line before heading in $file" |
||||
|
exit 1 |
||||
|
fi |
||||
|
fi |
||||
|
done |
||||
|
' |
||||
|
language: system |
||||
|
files: \.(md|mdc)$ |
||||
|
stages: [commit] |
||||
|
description: "Validate markdown blank line formatting" |
||||
|
pass_filenames: true |
||||
|
EOF |
||||
|
echo "✅ Created .pre-commit-config.yaml" |
||||
|
else |
||||
|
echo "✅ .pre-commit-config.yaml already exists" |
||||
|
fi |
||||
|
|
||||
|
# Install the pre-commit hooks |
||||
|
echo "🔗 Installing pre-commit hooks..." |
||||
|
pre-commit install |
||||
|
|
||||
|
# Install markdownlint if not present |
||||
|
if ! command -v npx &> /dev/null; then |
||||
|
echo "📦 Installing Node.js dependencies..." |
||||
|
npm install --save-dev markdownlint-cli |
||||
|
else |
||||
|
if ! npx markdownlint --version &> /dev/null; then |
||||
|
echo "📦 Installing markdownlint-cli..." |
||||
|
npm install --save-dev markdownlint-cli |
||||
|
else |
||||
|
echo "✅ markdownlint-cli already available" |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
# Create a markdown auto-fix script |
||||
|
echo "📝 Creating markdown auto-fix script..." |
||||
|
cat > scripts/fix-markdown.sh << 'EOF' |
||||
|
#!/bin/bash |
||||
|
|
||||
|
# Auto-fix markdown formatting issues |
||||
|
# Usage: ./scripts/fix-markdown.sh [file_or_directory] |
||||
|
|
||||
|
set -e |
||||
|
|
||||
|
FIX_MARKDOWN() { |
||||
|
local target="$1" |
||||
|
|
||||
|
if [ -f "$target" ]; then |
||||
|
# Fix single file |
||||
|
if [[ "$target" =~ \.(md|mdc)$ ]]; then |
||||
|
echo "🔧 Fixing markdown formatting in $target..." |
||||
|
npx markdownlint --fix "$target" || true |
||||
|
fi |
||||
|
elif [ -d "$target" ]; then |
||||
|
# Fix all markdown files in directory |
||||
|
echo "🔧 Fixing markdown formatting in $target..." |
||||
|
find "$target" -name "*.md" -o -name "*.mdc" | while read -r file; do |
||||
|
echo " Processing $file..." |
||||
|
npx markdownlint --fix "$file" || true |
||||
|
done |
||||
|
else |
||||
|
echo "❌ Target $target not found" |
||||
|
exit 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
# Default to current directory if no target specified |
||||
|
TARGET="${1:-.}" |
||||
|
FIX_MARKDOWN "$TARGET" |
||||
|
|
||||
|
echo "✅ Markdown formatting fixes applied!" |
||||
|
echo "💡 Run 'git diff' to see what was changed" |
||||
|
EOF |
||||
|
|
||||
|
chmod +x scripts/fix-markdown.sh |
||||
|
|
||||
|
# Create a markdown validation script |
||||
|
echo "📝 Creating markdown validation script..." |
||||
|
cat > scripts/validate-markdown.sh << 'EOF' |
||||
|
#!/bin/bash |
||||
|
|
||||
|
# Validate markdown formatting without auto-fixing |
||||
|
# Usage: ./scripts/validate-markdown.sh [file_or_directory] |
||||
|
|
||||
|
set -e |
||||
|
|
||||
|
VALIDATE_MARKDOWN() { |
||||
|
local target="$1" |
||||
|
|
||||
|
if [ -f "$target" ]; then |
||||
|
# Validate single file |
||||
|
if [[ "$target" =~ \.(md|mdc)$ ]]; then |
||||
|
echo "🔍 Validating markdown formatting in $target..." |
||||
|
npx markdownlint "$target" |
||||
|
fi |
||||
|
elif [ -d "$target" ]; then |
||||
|
# Validate all markdown files in directory |
||||
|
echo "🔍 Validating markdown formatting in $target..." |
||||
|
find "$target" -name "*.md" -o -name "*.mdc" | while read -r file; do |
||||
|
echo " Checking $file..." |
||||
|
npx markdownlint "$file" || true |
||||
|
done |
||||
|
else |
||||
|
echo "❌ Target $target not found" |
||||
|
exit 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
# Default to current directory if no target specified |
||||
|
TARGET="${1:-.}" |
||||
|
VALIDATE_MARKDOWN "$TARGET" |
||||
|
|
||||
|
echo "✅ Markdown validation complete!" |
||||
|
EOF |
||||
|
|
||||
|
chmod +x scripts/validate-markdown.sh |
||||
|
|
||||
|
echo "" |
||||
|
echo "🎉 Markdown Pre-commit Hooks Setup Complete!" |
||||
|
echo "" |
||||
|
echo "📋 What was installed:" |
||||
|
echo " ✅ pre-commit hooks for automatic markdown formatting" |
||||
|
echo " ✅ .pre-commit-config.yaml with markdown rules" |
||||
|
echo " ✅ scripts/fix-markdown.sh for manual fixes" |
||||
|
echo " ✅ scripts/validate-markdown.sh for validation" |
||||
|
echo "" |
||||
|
echo "🚀 Usage:" |
||||
|
echo " • Hooks run automatically on commit" |
||||
|
echo " • Manual fix: ./scripts/fix-markdown.sh [file/dir]" |
||||
|
echo " • Manual check: ./scripts/validate-markdown.sh [file/dir]" |
||||
|
echo " • Test hooks: pre-commit run --all-files" |
||||
|
echo "" |
||||
|
echo "💡 The hooks will now automatically fix markdown issues before commits!" |
@ -0,0 +1,19 @@ |
|||||
|
#!/usr/bin/env bash |
||||
|
set -euo pipefail |
||||
|
|
||||
|
echo "🔍 Validating markdown formatting..." |
||||
|
|
||||
|
# Check if markdownlint is available |
||||
|
if ! command -v npx &> /dev/null; then |
||||
|
echo "❌ npx not found. Please install Node.js and npm first." |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
# Run markdownlint on project markdown files (exclude node_modules) |
||||
|
echo "📝 Checking project markdown files..." |
||||
|
npx markdownlint "*.md" "*.mdc" "scripts/**/*.md" "src/**/*.md" "test-playwright/**/*.md" "resources/**/*.md" --config .markdownlint.json 2>/dev/null || { |
||||
|
echo "❌ Markdown validation failed. Run 'npm run markdown:fix' to auto-fix issues." |
||||
|
exit 1 |
||||
|
} |
||||
|
|
||||
|
echo "✅ All markdown files pass validation!" |
Loading…
Reference in new issue