|
1 | 1 | # Copilot Instructions for j26-components |
2 | 2 |
|
| 3 | +## Repository Overview |
| 4 | + |
| 5 | +This is the **Scouterna Design System Components** monorepo containing: |
| 6 | +- **Stencil Web Components** (packages/ui-webc) - source of truth for all components |
| 7 | +- **React Component Wrappers** (packages/ui-react) - auto-generated from Stencil |
| 8 | +- **Design Tokens** (packages/design-tokens) - CSS variables and theme values |
| 9 | +- **Storybook Documentation** (packages/storybook) - component demos and documentation |
| 10 | + |
| 11 | +**Languages**: TypeScript, CSS, React, Stencil |
| 12 | +**Tooling**: Biome (linting/formatting), Changesets (releases), Plop (generators) |
| 13 | + |
| 14 | +## Critical Build Requirements |
| 15 | + |
| 16 | +**ALWAYS run commands in this exact order to avoid build failures:** |
| 17 | + |
| 18 | +### 1. Initial Setup |
| 19 | +```bash |
| 20 | +pnpm install # Required before ANY other command |
| 21 | +``` |
| 22 | + |
| 23 | +### 2. Full Build (required after changes) |
| 24 | +```bash |
| 25 | +pnpm build # Builds design-tokens → ui-webc → ui-react in dependency order |
| 26 | +``` |
| 27 | + |
| 28 | +**Build sequence is critical:** |
| 29 | +- design-tokens MUST build first (generates CSS variables) |
| 30 | +- ui-webc depends on design-tokens being built |
| 31 | +- ui-react is auto-generated from ui-webc build output |
| 32 | +- Never run individual package builds unless explicitly testing |
| 33 | + |
| 34 | +### 3. Development Mode |
| 35 | +```bash |
| 36 | +pnpm dev # Runs all packages in watch mode, starts Storybook on :6006 |
| 37 | +``` |
| 38 | + |
| 39 | +### 4. Linting (CI runs this) |
| 40 | +```bash |
| 41 | +pnpm lint # Check for errors |
| 42 | +pnpm lint:fix # Auto-fix formatting/imports |
| 43 | +``` |
| 44 | + |
| 45 | +**CI Requirement**: Code MUST pass `biome ci --error-on-warnings .` - warnings are treated as errors in CI. |
| 46 | + |
| 47 | +## Project Architecture & File Locations |
| 48 | + |
| 49 | +### Component Structure |
| 50 | +Each component lives in `packages/ui-webc/src/components/{name}/`: |
| 51 | +- `{name}.tsx` - Stencil component (source of truth) |
| 52 | +- `{name}.css` - Component styles (uses design tokens) |
| 53 | +- `readme.md` - **AUTO-GENERATED** documentation (never edit manually) |
| 54 | + |
| 55 | +Component naming convention: All components use `scout-{name}` tag name (e.g., `scout-button`) |
| 56 | + |
| 57 | +### Key Configuration Files |
| 58 | +- `/package.json` - Root workspace scripts |
| 59 | +- `/pnpm-workspace.yaml` - Monorepo workspace config |
| 60 | +- `/biome.json` - Linting and formatting rules |
| 61 | +- `/.node-version` - Node version (24.5) |
| 62 | +- `/.changeset/config.json` - Release configuration |
| 63 | +- `/packages/ui-webc/stencil.config.ts` - Stencil build config with React output target |
| 64 | + |
| 65 | +### Generated Files (Never Edit Directly) |
| 66 | +- `packages/ui-react/lib/components/stencil-generated/**` - Auto-generated from Stencil |
| 67 | +- `packages/ui-webc/src/components.d.ts` - Auto-generated type definitions |
| 68 | +- `packages/ui-webc/src/components/*/readme.md` - Auto-generated docs |
| 69 | +- `packages/design-tokens/dist/**` - Generated from tokens/ JSON files |
| 70 | + |
| 71 | +### Design Tokens |
| 72 | +Source: `packages/design-tokens/tokens/**/*.json` |
| 73 | +Output: `packages/design-tokens/dist/tokens.css` (imported in components) |
| 74 | +Build warnings about "Unknown CSS Font Shorthand properties" are **expected and safe to ignore**. |
| 75 | + |
| 76 | +## Component Development Workflow |
| 77 | + |
| 78 | +### Creating New Components |
| 79 | +```bash |
| 80 | +pnpm plop # Interactive generator creates all boilerplate |
| 81 | +``` |
| 82 | + |
| 83 | +This creates: |
| 84 | +- Component in `packages/ui-webc/src/components/{name}/` |
| 85 | +- Storybook story in `packages/storybook/src/stories/{name}.stories.tsx` |
| 86 | + |
| 87 | +### Modifying Existing Components |
| 88 | + |
| 89 | +1. Edit source in `packages/ui-webc/src/components/{name}/{name}.tsx` |
| 90 | +2. Edit styles in `packages/ui-webc/src/components/{name}/{name}.css` |
| 91 | +3. **Rebuild**: `pnpm build` (triggers React wrapper regeneration) |
| 92 | +4. Test in Storybook: `pnpm dev` then visit http://localhost:6006 |
| 93 | +5. Add changeset: `pnpm changeset` (required for releases) |
| 94 | + |
| 95 | +**Component Props**: Use JSDoc comments in .tsx file - they auto-generate into readme.md tables. |
| 96 | + |
| 97 | +### Form Input Components Pattern |
| 98 | +Input-like components (checkbox, radio-button, select, input) follow this pattern: |
| 99 | +- Must have `name` prop for form submission |
| 100 | +- Must have `value` prop |
| 101 | +- Must emit `scoutChecked` or `scoutInputChange` events with `{ checked/value, element }` payload |
| 102 | +- Must support `disabled` prop |
| 103 | +- Must emit internal `_fieldId` event for field association |
| 104 | + |
| 105 | +## Testing |
| 106 | + |
| 107 | +### Unit Tests (Stencil) |
| 108 | +```bash |
| 109 | +cd packages/ui-webc |
| 110 | +pnpm test # Runs spec and e2e tests with Stencil's test runner |
| 111 | +``` |
| 112 | + |
| 113 | +Tests are rare in this codebase - only `utils.spec.ts` exists currently. |
| 114 | + |
| 115 | +### Visual Testing |
| 116 | +Use Storybook for manual visual testing. Build and preview with: |
| 117 | +```bash |
| 118 | +pnpm build # Build all packages first |
| 119 | +cd packages/storybook |
| 120 | +pnpm dev # Starts on port 6006 |
| 121 | +``` |
| 122 | + |
| 123 | +## Release Process (Changesets) |
| 124 | + |
| 125 | +**Every user-facing change REQUIRES a changeset:** |
| 126 | + |
| 127 | +1. After making changes, run: |
| 128 | +```bash |
| 129 | +pnpm changeset |
| 130 | +``` |
| 131 | + |
| 132 | +2. Select affected packages (usually `@scouterna/ui-webc` and `@scouterna/ui-react`) |
| 133 | +3. Choose version bump type (patch/minor/major) |
| 134 | +4. Describe changes (appears in changelog) |
| 135 | +5. Commit the generated `.changeset/*.md` file with your changes |
| 136 | + |
| 137 | +**Important**: Regular commits without changesets don't appear in changelogs or trigger releases. |
| 138 | + |
| 139 | +## CI/CD Pipelines |
| 140 | + |
| 141 | +### Code Quality Check (runs on all pushes/PRs) |
| 142 | +- Workflow: `.github/workflows/code-quality.yml` |
| 143 | +- Runs: `biome ci --error-on-warnings .` |
| 144 | +- **Warnings = Failure** - must fix before merge |
| 145 | + |
| 146 | +### Release Process (main branch only) |
| 147 | +- Workflow: `.github/workflows/release.yml` |
| 148 | +- Triggered: On push to `main` |
| 149 | +- Actions: |
| 150 | + 1. Runs `pnpm install` |
| 151 | + 2. Runs `pnpm build` |
| 152 | + 3. Creates release PR with version bumps (if changesets exist) |
| 153 | + 4. Publishes to npm when release PR is merged |
| 154 | + 5. Triggers Storybook deployment to GitHub Pages |
| 155 | + |
| 156 | +### Storybook Deployment |
| 157 | +- Workflow: `.github/workflows/deploy-github-pages.yml` |
| 158 | +- Builds Storybook from `packages/storybook/storybook-static` |
| 159 | +- Deploys to GitHub Pages |
| 160 | + |
| 161 | +**To replicate CI locally:** |
| 162 | +```bash |
| 163 | +pnpm install |
| 164 | +pnpm build |
| 165 | +biome ci --error-on-warnings . |
| 166 | +``` |
| 167 | + |
| 168 | +## Common Pitfalls & Workarounds |
| 169 | + |
| 170 | +1. **"Cannot find module" errors**: Run `pnpm install && pnpm build` - React types won't exist until Stencil builds. |
| 171 | + |
| 172 | +2. **Storybook shows old component**: After editing a component, MUST run `pnpm build` to regenerate React wrappers before Storybook reflects changes. |
| 173 | + |
| 174 | +3. **Biome errors about imports**: Run `pnpm lint:fix` - Biome auto-organizes imports. |
| 175 | + |
| 176 | +4. **Design token warnings**: Warnings about "Unknown CSS Font Shorthand properties" during token build are expected and can be ignored. |
| 177 | + |
| 178 | +5. **Component readme.md out of sync**: These are auto-generated - edit JSDoc in the .tsx file, then rebuild. |
| 179 | + |
| 180 | +6. **pnpm workspace resolution failures**: Ensure packages are built in order. Root `pnpm build` handles this automatically. |
| 181 | + |
3 | 182 | ## PR Review Guidelines |
4 | 183 |
|
5 | 184 | ### Component Documentation |
6 | 185 |
|
7 | | -When reviewing component readme.md files, **DO NOT** suggest adding comments to the props and events tables. These tables are auto-generated from the component source code and should remain comment-free to maintain consistency with the generation process. |
| 186 | +**DO NOT** suggest adding comments to the props and events tables in component readme.md files. These tables are auto-generated from the component source code and should remain comment-free to maintain consistency with the generation process. |
8 | 187 |
|
9 | 188 | Example of tables where comments should NOT be suggested: |
10 | 189 | - Props tables showing component properties |
11 | 190 | - Events tables documenting component events |
12 | 191 |
|
13 | 192 | The documentation for these items should be maintained in the source code itself, not in the generated tables. |
| 193 | + |
| 194 | +## Trust These Instructions |
| 195 | + |
| 196 | +These instructions are comprehensive and tested. Only search for additional information if: |
| 197 | +- Instructions are incomplete for your specific task |
| 198 | +- Instructions are found to be incorrect |
| 199 | +- You need to understand implementation details not covered here |
| 200 | + |
| 201 | +For component changes, always check existing components (e.g., button, checkbox) as reference implementations before searching extensively. |
0 commit comments