|
| 1 | +# Effect Patterns Publishing Pipeline |
| 2 | + |
| 3 | +This directory contains the scripts that power the Effect Patterns publishing pipeline. These scripts help maintain consistency between TypeScript source files and their corresponding MDX documentation. |
| 4 | + |
| 5 | +## Pipeline Overview |
| 6 | + |
| 7 | +The publishing pipeline consists of a 3-stage workflow: |
| 8 | + |
| 9 | +1. **New Patterns** (`content/new/`): Empty subdirectories for new patterns that haven't been published yet |
| 10 | +2. **Raw Patterns** (`content/raw/`): MDX files with TypeScript code replaced by `<Example />` components |
| 11 | +3. **Published Patterns** (`content/published/`): Final MDX files with embedded TypeScript code blocks |
| 12 | + |
| 13 | +## Available Scripts |
| 14 | + |
| 15 | +### 1. `process_patterns.ts` |
| 16 | + |
| 17 | +Processes MDX files by extracting TypeScript code blocks and replacing them with Example components. |
| 18 | + |
| 19 | +```bash |
| 20 | +npx tsx process_patterns.ts --indir <input_directory> --outdir <output_directory> [--srcdir <source_directory>] [--count <number>] |
| 21 | +``` |
| 22 | + |
| 23 | +**Arguments:** |
| 24 | +- `--indir`: Input directory containing MDX files (required) |
| 25 | +- `--outdir`: Output directory for processed MDX files (required) |
| 26 | +- `--srcdir`: Directory to write extracted TypeScript code (optional) |
| 27 | +- `--count`: Number of files to process (optional) |
| 28 | + |
| 29 | +**Example:** |
| 30 | +```bash |
| 31 | +npx tsx process_patterns.ts --indir content/published --outdir content/raw --srcdir content/src |
| 32 | +``` |
| 33 | + |
| 34 | +### 2. `publish-patterns.ts` |
| 35 | + |
| 36 | +Processes MDX files by replacing Example components with TypeScript code from source files. |
| 37 | + |
| 38 | +```bash |
| 39 | +npx tsx publish-patterns.ts --indir <input_directory> --outdir <output_directory> --srcdir <source_directory> [--count <number>] |
| 40 | +``` |
| 41 | + |
| 42 | +**Arguments:** |
| 43 | +- `--indir`: Input directory containing MDX files with Example components (required) |
| 44 | +- `--outdir`: Output directory for processed MDX files (required) |
| 45 | +- `--srcdir`: Directory containing TypeScript source files (required) |
| 46 | +- `--count`: Number of files to process (optional) |
| 47 | + |
| 48 | +**Example:** |
| 49 | +```bash |
| 50 | +npx tsx publish-patterns.ts --indir content/raw --outdir content/published --srcdir content/src |
| 51 | +``` |
| 52 | + |
| 53 | +### 3. `pattern-validator.ts` |
| 54 | + |
| 55 | +Validates that TypeScript code blocks in MDX files match their corresponding source files. |
| 56 | + |
| 57 | +```bash |
| 58 | +npx tsx pattern-validator.ts --indir <input_directory> --srcdir <source_directory> [--count <number>] |
| 59 | +``` |
| 60 | + |
| 61 | +**Arguments:** |
| 62 | +- `--indir`: Input directory containing MDX files (required) |
| 63 | +- `--srcdir`: Directory containing TypeScript source files (required) |
| 64 | +- `--count`: Number of files to process (optional) |
| 65 | + |
| 66 | +**Example:** |
| 67 | +```bash |
| 68 | +npx tsx pattern-validator.ts --indir content/published --srcdir content/src |
| 69 | +``` |
| 70 | + |
| 71 | +### 4. `generate_readme.ts` |
| 72 | + |
| 73 | +Generates the main README.md file with links to all patterns, organized by category. |
| 74 | + |
| 75 | +```bash |
| 76 | +npx tsx generate_readme.ts |
| 77 | +``` |
| 78 | + |
| 79 | +**Note:** This script looks for MDX files in the `content/published` directory. |
| 80 | + |
| 81 | +### 5. `validate_and_generate.ts` |
| 82 | + |
| 83 | +Combines validation and README generation in one step. |
| 84 | + |
| 85 | +```bash |
| 86 | +npx tsx validate_and_generate.ts |
| 87 | +``` |
| 88 | + |
| 89 | +This script: |
| 90 | +1. Validates all TypeScript code blocks against source files |
| 91 | +2. Generates the README.md with links to all patterns |
| 92 | +3. Ensures complete consistency between code, documentation, and README |
| 93 | + |
| 94 | +## Typical Workflow |
| 95 | + |
| 96 | +1. **Create new patterns** in `content/new/` |
| 97 | +2. **Process patterns** to extract TypeScript code: |
| 98 | + ```bash |
| 99 | + npx tsx process_patterns.ts --indir content/published --outdir content/raw --srcdir content/src |
| 100 | + ``` |
| 101 | +3. **Make changes** to TypeScript source files in `content/src/` |
| 102 | +4. **Publish patterns** to restore TypeScript code blocks: |
| 103 | + ```bash |
| 104 | + npx tsx publish-patterns.ts --indir content/raw --outdir content/published --srcdir content/src |
| 105 | + ``` |
| 106 | +5. **Validate patterns** to ensure consistency: |
| 107 | + ```bash |
| 108 | + npx tsx pattern-validator.ts --indir content/published --srcdir content/src |
| 109 | + ``` |
| 110 | +6. **Generate README** with links to all patterns: |
| 111 | + ```bash |
| 112 | + npx tsx generate_readme.ts |
| 113 | + ``` |
| 114 | + |
| 115 | +Or use the combined validation and generation script: |
| 116 | +```bash |
| 117 | +npx tsx validate_and_generate.ts |
| 118 | +``` |
| 119 | + |
| 120 | +## Future Automation |
| 121 | + |
| 122 | +Future enhancements to this pipeline could include: |
| 123 | + |
| 124 | +1. GitHub Actions workflow to automatically validate patterns on pull requests |
| 125 | +2. Automated tests for the pipeline scripts |
| 126 | +3. Integration with a CI/CD system for automated deployment |
| 127 | +4. Pre-commit hooks to ensure consistency before committing changes |
| 128 | + |
| 129 | +## Dependencies |
| 130 | + |
| 131 | +- TypeScript |
| 132 | +- Node.js |
| 133 | +- commander (for CLI argument parsing) |
| 134 | +- gray-matter (for parsing MDX frontmatter) |
| 135 | +- fs/promises (for file system operations) |
| 136 | +- path (for path manipulation) |
0 commit comments