Skip to content

build script for rules - single source of truth#204

Open
ameerabuf wants to merge 21 commits intomasterfrom
rules-build-mechanism
Open

build script for rules - single source of truth#204
ameerabuf wants to merge 21 commits intomasterfrom
rules-build-mechanism

Conversation

@ameerabuf
Copy link
Copy Markdown
Contributor

@ameerabuf ameerabuf commented May 5, 2026

Description

Adds a build pipeline for packages/interact/rules/ that replaces manually-maintained markdown rule files with a structured source layer — YAML data + markdown fragments + JavaScript templates — eliminating content duplication and establishing a single source of truth.

Architecture

_content/data/*.yaml       ─┐
_content/fragments/*.md     ├─→  scripts/build-rules.mjs  ─→  rules/*.md  (7 files)
_content/templates/*.mjs   ─┘

Three source layers feed the build:

  1. Data files (_content/data/) — YAML definitions for all 9 triggers (field names pulled from actual TS types), effect metadata (presets, easings, ranges, composites), and package metadata.
  2. Fragments (_content/fragments/) — ~12 reusable markdown fragments (FOUC prevention, element resolution, pitfalls, quick-start, etc.) with <!-- #section --> markers for granular inclusion at different detail levels.
  3. Templates (_content/templates/) — .mjs files exporting render() functions that receive data + fragments and return complete markdown strings. One template per output file (or trigger family).

The build script (scripts/build-rules.mjs) loads YAML, parses fragment sections, calls each template, and writes the 7 output .md files to rules/.

Output files

Template Generates
event-trigger-rule.mjs click.md, hover.md
viewenter-rule.mjs viewenter.md
viewprogress-rule.mjs viewprogress.md
pointermove-rule.mjs pointermove.md
full-lean.mjs full-lean.md
integration.mjs integration.md

Typo fixes included

These existing issues are fixed as a natural consequence of single-source templating:

  • [EFFECT_DEFINTION][EFFECT_DEFINITION] in click/hover/viewenter sequence blocks
  • hitAeahitArea in pointermove.md centering section
  • Curly apostrophe normalized to ASCII in full-lean.md

Usage

yarn workspace @wix/interact build:rules
# or
cd packages/interact && node scripts/build-rules.mjs

Checklist

  • I have read the Contributing Guide
  • I have added/updated tests for my changes (if applicable)
  • I have updated documentation/rules/skills (if applicable)

Additional Notes

  • Adds js-yaml as a devDependency (already available as transitive dep)
  • Adds build:rules script to package.json
  • Generated rules/*.md files are committed so the npm package always includes them; CI can verify freshness with build:rules && git diff --exit-code rules/
  • All 7 generated files were diffed against the originals — zero information loss beyond the planned typo fixes

ameerabuf and others added 21 commits May 5, 2026 14:34
- Refactor PROSE in event-trigger-rule.mjs: base + overrides pattern
  eliminates duplication, unifies minor wording inconsistencies
- Move fillGuidance/compositeOperations prose from effects.yaml into
  full-lean.mjs (YAML for structured data, not prose)
- Unify render() signature to (data, fragments) across all templates
- Import capitalize helper in full-lean.mjs instead of inlining
- Add --check flag to build-rules.mjs for CI freshness verification
  without modifying the working tree
- Remove unused aliasOf entries from triggers.yaml
- Add _content/fragments/ to .prettierignore (section markers are
  build pipeline syntax)
- Apply Prettier formatting to all source files

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant