@mallardbay/cursor-rules 1.0.10 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,10 +25,10 @@ Use theme values consistently across all components:
25
25
  - Use theme typography settings for text styles
26
26
  - Example: `theme.fontSizes.md` instead of `'16px'`
27
27
 
28
- ### Borders
28
+ ### Borders and border radius
29
29
 
30
30
  - Use theme border styles and radius values
31
- - Example: `theme.borders.sm` instead of `'1px solid'`
31
+ - Examples: `theme.borders.sm` instead of `'1px solid'`, `theme.radii.md` instead of using px values
32
32
 
33
33
  ## Component Structure
34
34
 
@@ -73,6 +73,12 @@ Ensure responsive and accessible design:
73
73
  - Optimize component rendering
74
74
  - Avoid unnecessary re-renders
75
75
  - Use React.memo and useMemo when appropriate
76
+ - Avoid defining functions inside components to prevent recreation on each render
77
+ - Move function definitions outside components or use useCallback for event handlers
78
+ - Use useCallback for functions passed as props to child components
79
+ - Use useMemo for expensive computations and complex data transformations
80
+ - Memoize filtered, sorted, or mapped arrays to avoid recalculation on every render
81
+ - Use useMemo for object/array creation that would otherwise be recreated on each render
76
82
 
77
83
  ## File Patterns
78
84
 
@@ -0,0 +1,147 @@
1
+ ---
2
+ alwaysApply: true
3
+ ---
4
+
5
+ # Storybook Performance Standards
6
+
7
+ ## Story Optimization
8
+
9
+ Optimize Storybook stories for better performance and developer experience:
10
+
11
+ ### Story Structure
12
+
13
+ - Use `StoryObj` type for better type safety
14
+ - Implement proper story parameters and controls
15
+ - Group related stories using `storiesOf` or CSF 3.0
16
+ - Use meaningful story names and descriptions
17
+ - Organize stories by component hierarchy (e.g., "Core/Button")
18
+
19
+ ### Story Organization
20
+
21
+ - Group stories by component or feature
22
+ - Use consistent naming conventions for stories
23
+ - Implement proper story hierarchy with nested folders
24
+ - Separate interactive and documentation stories
25
+ - Use helper functions like `renderStorySections` for consistent layouts
26
+ - Create reusable story section builders for component variants
27
+
28
+ ## Rendering Optimization
29
+
30
+ Prevent unnecessary re-renders in stories:
31
+
32
+ - Avoid inline styles in story args
33
+ - Prevent inline object creation in story parameters
34
+ - Use proper key props in story lists
35
+ - Memoize complex story args and callbacks
36
+ - Use `fn()` from `@storybook/test` for mock functions
37
+ - Spread args properly to avoid TypeScript errors
38
+
39
+ ### Story Dependencies
40
+
41
+ - Prefer existing dependencies over new ones
42
+ - Review [package.json](mdc:package.json) before adding new packages
43
+ - Consider bundle size impact of new story dependencies
44
+ - Use tree-shaking friendly imports for story utilities
45
+ - Import storybook helpers from dedicated helper files
46
+
47
+ ## Component Variant Management
48
+
49
+ - Use helper functions like `getStoryComponentVariantsAndColorSchemes` for systematic variant testing
50
+ - Create structured sections for different component states
51
+ - Implement consistent labeling for component variants
52
+ - Use TypeScript to ensure proper component prop spreading
53
+
54
+ ## Performance Best Practices
55
+
56
+ - Use `play` functions for complex interactions
57
+ - Implement proper story loading states
58
+ - Optimize story assets and images
59
+ - Use Storybook's performance monitoring tools
60
+ - Implement proper story caching strategies
61
+ - Avoid inline component creation in render functions
62
+
63
+ ## Story Development
64
+
65
+ - Write stories that cover all component states
66
+ - Use controls for interactive testing
67
+ - Implement proper accessibility testing in stories
68
+ - Use Storybook's built-in performance profiling
69
+ - Create comprehensive variant coverage (primary, secondary, etc.)
70
+ - Use meaningful labels for each component variant
71
+ - Implement proper TypeScript typing for story args
72
+
73
+ ## File Patterns
74
+
75
+ These rules apply to all Storybook story files (`.stories.ts`, `.stories.tsx`, `.stories.js`, `.stories.jsx`) in the project.
76
+
77
+ # Storybook Performance Standards
78
+
79
+ ## Story Optimization
80
+
81
+ Optimize Storybook stories for better performance and developer experience:
82
+
83
+ ### Story Structure
84
+
85
+ - Use `StoryObj` type for better type safety
86
+ - Implement proper story parameters and controls
87
+ - Group related stories using `storiesOf` or CSF 3.0
88
+ - Use meaningful story names and descriptions
89
+ - Organize stories by component hierarchy (e.g., "Core/Button")
90
+
91
+ ### Story Organization
92
+
93
+ - Group stories by component or feature
94
+ - Use consistent naming conventions for stories
95
+ - Implement proper story hierarchy with nested folders
96
+ - Separate interactive and documentation stories
97
+ - Use helper functions like `renderStorySections` for consistent layouts
98
+ - Create reusable story section builders for component variants
99
+
100
+ ## Rendering Optimization
101
+
102
+ Prevent unnecessary re-renders in stories:
103
+
104
+ - Avoid inline styles in story args
105
+ - Prevent inline object creation in story parameters
106
+ - Use proper key props in story lists
107
+ - Memoize complex story args and callbacks
108
+ - Use `fn()` from `@storybook/test` for mock functions
109
+ - Spread args properly to avoid TypeScript errors
110
+
111
+ ### Story Dependencies
112
+
113
+ - Prefer existing dependencies over new ones
114
+ - Review [package.json](mdc:package.json) before adding new packages
115
+ - Consider bundle size impact of new story dependencies
116
+ - Use tree-shaking friendly imports for story utilities
117
+ - Import storybook helpers from dedicated helper files
118
+
119
+ ## Component Variant Management
120
+
121
+ - Use helper functions like `getStoryComponentVariantsAndColorSchemes` for systematic variant testing
122
+ - Create structured sections for different component states
123
+ - Implement consistent labeling for component variants
124
+ - Use TypeScript to ensure proper component prop spreading
125
+
126
+ ## Performance Best Practices
127
+
128
+ - Use `play` functions for complex interactions
129
+ - Implement proper story loading states
130
+ - Optimize story assets and images
131
+ - Use Storybook's performance monitoring tools
132
+ - Implement proper story caching strategies
133
+ - Avoid inline component creation in render functions
134
+
135
+ ## Story Development
136
+
137
+ - Write stories that cover all component states
138
+ - Use controls for interactive testing
139
+ - Implement proper accessibility testing in stories
140
+ - Use Storybook's built-in performance profiling
141
+ - Create comprehensive variant coverage (primary, secondary, etc.)
142
+ - Use meaningful labels for each component variant
143
+ - Implement proper TypeScript typing for story args
144
+
145
+ ## File Patterns
146
+
147
+ These rules apply to all Storybook story files (`.stories.ts`, `.stories.tsx`, `.stories.js`, `.stories.jsx`) in the project.
@@ -1,48 +1,53 @@
1
1
  ---
2
2
  description: Defines structure, naming, reuse, and dependency guidelines to ensure clean, maintainable, and consistent TypeScript code across the project—favoring pragmatism, proven libraries, and shared conventions.
3
- globs:
4
3
  alwaysApply: false
5
4
  ---
5
+
6
6
  # Code Quality Standards
7
7
 
8
8
  ## Code Structure
9
- - Maximum file length: 200 lines
10
- - Maximum function length: 50 lines
11
- - Naming conventions:
12
- - Components: PascalCase
13
- - Functions: camelCase
14
- - Constants: UPPER_SNAKE_CASE
15
- - Types: PascalCase
16
- - Types should be defined at the bottom of files
17
- - PropTypes should be defined before component definitions
18
- - Prefer using alias for importing components. Only use relative for tests or when there's a direct sibling
9
+
10
+ - Maximum file length: 200 lines
11
+ - Maximum function length: 50 lines
12
+ - Naming conventions:
13
+ - Components: PascalCase
14
+ - Functions: camelCase
15
+ - Constants: UPPER_SNAKE_CASE
16
+ - Types: PascalCase
17
+ - Types should be defined at the bottom of files
18
+ - PropTypes should be defined before component definitions
19
+ - Prefer using alias for importing components. Only use relative for tests or when there's a direct sibling
19
20
 
20
21
  ## Code Reuse
21
- - Use shared libraries to avoid duplication
22
- - Primary libraries to use:
23
- - [@mallardbay/lib-react-components](mdc:package.json)
24
- - [@mallardbay/lib-shared-helpers](mdc:package.json)
22
+
23
+ - Use shared libraries to avoid duplication
24
+ - Primary libraries to use:
25
+ - [@mallardbay/lib-react-components](mdc:package.json)
26
+ - [@mallardbay/lib-shared-helpers](mdc:package.json)
25
27
 
26
28
  ## Third party libraries
27
- - Favor battle-tested libraries over custom solutions. If a well-maintained, widely-used library solves the problem cleanly, use it. Reinventing functionality that’s already solid, reliable, and well-documented usually leads to more bugs, more maintenance, and wasted time.
28
- - Prioritize stability and ecosystem fit. Pick libraries that are actively maintained, have strong adoption, and fit well within our existing tech stack. Avoid fringe or unmaintained packages unless there’s a strong reason.
29
- - Suggest existing libraries during code review. If you spot hand-rolled code that could be replaced with a proven library, flag it. Examples:
30
- - Use zod or yup instead of custom input validation
31
- - Use date-fns instead of writing date math from scratch
32
- - Use radash for utility-heavy logic if readability or testability improves
33
- - Use react-hook-form for complex form state handling
34
- - Be pragmatic. Sometimes a simple custom solution is faster and easier than pulling in a heavy dependency—but always weigh short-term gains against long-term cost.
35
- - Make reuse easy. If we do build something custom, design it to be clean, reusable, and well-documented. That way, we’re not creating another wheel, but investing in something worth maintaining.
29
+
30
+ - Favor battle-tested libraries over custom solutions. If a well-maintained, widely-used library solves the problem cleanly, use it. Reinventing functionality that’s already solid, reliable, and well-documented usually leads to more bugs, more maintenance, and wasted time.
31
+ - Prioritize stability and ecosystem fit. Pick libraries that are actively maintained, have strong adoption, and fit well within our existing tech stack. Avoid fringe or unmaintained packages unless there’s a strong reason.
32
+ - Suggest existing libraries during code review. If you spot hand-rolled code that could be replaced with a proven library, flag it. Examples:
33
+ - Use zod or yup instead of custom input validation
34
+ - Use date-fns instead of writing date math from scratch
35
+ - Use radash for utility-heavy logic if readability or testability improves
36
+ - Use react-hook-form for complex form state handling
37
+ - Be pragmatic. Sometimes a simple custom solution is faster and easier than pulling in a heavy dependency—but always weigh short-term gains against long-term cost.
38
+ - Make reuse easy. If we do build something custom, design it to be clean, reusable, and well-documented. That way, we’re not creating another wheel, but investing in something worth maintaining.
36
39
 
37
40
  ## String Constants
38
- - Use constants instead of string literals for:
39
- - Copy text (UI content)
40
- - Test IDs
41
- - Error messages
42
- - URLs
43
- - Source constants from:
44
- - @mallardbay/lib-shared-helpers
45
- - Local constants files
41
+
42
+ - Use constants instead of string literals for:
43
+ - Copy text (UI content). Most projects have a `copy-constants` file
44
+ - Test IDs. Most projects have `TEST_IDS` defined
45
+ - Error messages
46
+ - URLs
47
+ - Source constants from:
48
+ - @mallardbay/lib-shared-helpers
49
+ - Local constants files
46
50
 
47
51
  ## Cursor Rules
48
- - Suggest cursor rules as needed
52
+
53
+ - Suggest cursor rules as needed
@@ -1,40 +1,46 @@
1
1
  ---
2
2
  description: Outlines expectations for pull request size, test coverage, documentation, and review process—promoting focused, well-tested, and maintainable contributions that align with team standards and improve review efficiency.
3
- globs:
4
3
  alwaysApply: false
5
4
  ---
5
+
6
6
  # Code Review Standards
7
7
 
8
8
  ## Pull Request Guidelines
9
9
 
10
10
  ### Size Requirements
11
- - Maximum PR size: 400 lines
12
- - Split large changes into smaller, focused PRs
13
- - Keep changes atomic and focused
14
- - Consider impact on review process
11
+
12
+ - Maximum PR size: 400 lines
13
+ - Split large changes into smaller, focused PRs
14
+ - Keep changes atomic and focused
15
+ - Consider impact on review process
15
16
 
16
17
  ## Testing Requirements
18
+
17
19
  Ensure comprehensive test coverage:
18
20
 
19
21
  ### Test Coverage
20
- - All new code must include tests
21
- - Follow testing standards in [testing.mdc](mdc:.cursor/rules/testing.mdc)
22
- - Include unit tests for new functionality
23
- - Avoid making a ton of changes to existing tests while refactoring
22
+
23
+ - All new code must include tests
24
+ - Follow testing standards in [testing.mdc](mdc:.cursor/rules/testing.mdc)
25
+ - Include unit tests for new functionality
26
+ - Avoid making a ton of changes to existing tests while refactoring
24
27
 
25
28
  ### Code Documentation
26
- - Document complex logic with comments
27
- - Explain non-obvious implementation details
28
- - Document features added and important caveats in README
29
+
30
+ - Document complex logic with comments
31
+ - Explain non-obvious implementation details
32
+ - Document features added and important caveats in README
29
33
 
30
34
  ### Review Process
31
- - Review for code quality
32
- - Check for test coverage
33
- - Verify documentation
34
- - Ensure adherence to project standards
35
+
36
+ - Review for code quality
37
+ - Check for test coverage
38
+ - Verify documentation
39
+ - Ensure adherence to project standards
35
40
 
36
41
  ## Best Practices
37
- - Keep PRs focused and manageable
38
- - Include clear PR descriptions
39
- - Reference related issues/tickets
40
- - Respond to review comments promptly
42
+
43
+ - Keep PRs focused and manageable
44
+ - Include clear PR descriptions
45
+ - Reference related issues/tickets
46
+ - Respond to review comments promptly
@@ -1,41 +1,48 @@
1
1
  ---
2
2
  description: Defines consistent patterns for API and form error handling—focusing on clear user feedback, robust validation, and reliable logging to improve user experience, developer debugging, and overall app resilience.
3
- globs:
4
3
  alwaysApply: false
5
4
  ---
5
+
6
6
  # Error Handling Standards
7
7
 
8
8
  ## API Error Handling
9
+
9
10
  Implement comprehensive API error handling
10
11
 
11
12
  ### Error Types
12
- - Handle network errors
13
- - Handle server errors
14
- - Handle validation errors
15
- - Handle Apollo-specific errors
13
+
14
+ - Handle network errors
15
+ - Handle server errors
16
+ - Handle validation errors
17
+ - Handle Apollo-specific errors
16
18
 
17
19
  ### Error Presentation
18
- - Show error toasts for user feedback
19
- - Use original error messages when appropriate
20
- - Provide clear, actionable error messages
21
- - Log errors for debugging
20
+
21
+ - Show error toasts for user feedback
22
+ - Use original error messages when appropriate
23
+ - Provide clear, actionable error messages
24
+ - Log errors for debugging
22
25
 
23
26
  ## Form Validation
27
+
24
28
  Implement robust form validation
25
- - Validate all user inputs
26
- - Show validation errors clearly
27
- - Handle form submission errors
28
- - Use [@hookform/resolvers](mdc:package.json) for validation
29
+
30
+ - Validate all user inputs
31
+ - Show validation errors clearly
32
+ - Handle form submission errors
33
+ - Use [@hookform/resolvers](mdc:package.json) for validation
29
34
 
30
35
  ### Error Display
31
- - Show validation errors inline
32
- - Provide clear error messages
33
- - Highlight invalid fields
34
- - Prevent form submission with invalid data
36
+
37
+ - Show validation errors inline
38
+ - Provide clear error messages
39
+ - Highlight invalid fields
40
+ - Prevent form submission with invalid data
35
41
 
36
42
  ## Best Practices
37
- - Use try-catch blocks appropriately
38
- - Implement proper error boundaries
39
- - Log errors for debugging
40
- - Provide user-friendly error messages
41
- - Handle edge cases gracefully
43
+
44
+ - Use try-catch blocks appropriately
45
+ - Implement proper error boundaries
46
+ - Log errors for debugging
47
+ - Provide user-friendly error messages
48
+ - Handle edge cases gracefully
@@ -1,38 +1,45 @@
1
1
  ---
2
2
  description: Defines best practices for optimizing React components, rendering efficiency, and dependency management—focusing on minimizing re-renders, reducing bundle size, and enabling smooth user experiences through memoization, lazy loading, and performance-aware development.
3
- globs:
4
3
  alwaysApply: false
5
4
  ---
5
+
6
6
  # Performance Standards
7
7
 
8
8
  ## React Optimization
9
+
9
10
  Optimize React components for better performance:
10
11
 
11
12
  ### Component Optimization
12
- - Use `React.memo` for pure components
13
- - Implement `useCallback` for function props
14
- - Use `useMemo` for expensive computations
15
- - Avoid inline function definitions in render
13
+
14
+ - Use `React.memo` for pure components
15
+ - Implement `useCallback` for function props
16
+ - Use `useMemo` for expensive computations
17
+ - Avoid inline function definitions in render
16
18
 
17
19
  ## Rendering Optimization
20
+
18
21
  Prevent unnecessary re-renders:
19
- - Avoid inline styles in components
20
- - Prevent inline object creation in render
21
- - Use proper key props in lists
22
- - Memoize complex objects and callbacks
22
+
23
+ - Avoid inline styles in components
24
+ - Prevent inline object creation in render
25
+ - Use proper key props in lists
26
+ - Memoize complex objects and callbacks
23
27
 
24
28
  ### Dependencies
25
- - Prefer existing dependencies over new ones
26
- - Review [package.json](mdc:package.json) before adding new packages
27
- - Consider bundle size impact of new dependencies
28
- - Use tree-shaking friendly imports
29
+
30
+ - Prefer existing dependencies over new ones
31
+ - Review [package.json](mdc:package.json) before adding new packages
32
+ - Consider bundle size impact of new dependencies
33
+ - Use tree-shaking friendly imports
29
34
 
30
35
  ## Best Practices
31
- - Implement proper code splitting
32
- - Use lazy loading for routes and large components
33
- - Optimize images and assets
34
- - Monitor performance metrics
35
- - Use React DevTools for performance profiling
36
+
37
+ - Implement proper code splitting
38
+ - Use lazy loading for routes and large components
39
+ - Optimize images and assets
40
+ - Monitor performance metrics
41
+ - Use React DevTools for performance profiling
36
42
 
37
43
  ## File Patterns
44
+
38
45
  These rules apply to all TypeScript and TSX files in the project.
@@ -32,7 +32,8 @@ Avoid e2e tests for UI. Favor unit tests.
32
32
 
33
33
  - Happy path testing
34
34
  - Error case handling
35
- - Edge case coverage
35
+ - Edge case coverage within reason. Optimize for branching logic, and avoid creating nearly identical tests
36
+ - Aim for simplicity
36
37
  - All tests must pass before completion
37
38
 
38
39
  ### Test Quality
@@ -1,24 +1,27 @@
1
1
  ---
2
- description: Outlines a pragmatic approach to TypeScript—favoring strict type safety where it adds real value in catching bugs and improving developer experience, without unnecessary overhead. Includes file organization, best practices, and consistent use of TypeScript to enforce clarity, maintainability, and confidence in the codebase.
3
- globs:
4
- alwaysApply: false
2
+ alwaysApply: true
5
3
  ---
4
+
6
5
  # TypeScript Development Standards
7
6
 
8
7
  ## Type Safety
8
+
9
9
  Enforce comprehensive type safety across the codebase:
10
10
 
11
11
  ### Strict Type Checking
12
+
12
13
  Be as strictly as possible where it delivers clear value—specifically in preventing bugs and improving the developer experience. The goal is to enforce strong types and catch issues early, without introducing excessive friction or overhead. If a strict setting improves safety, maintainability, or clarity, we’ll use it. If it creates noise or slows down iteration without real benefit, we’ll dial it back. This is about pragmatic strictness, not dogmatism.
13
14
 
14
15
  ### File Organization
15
- - Place types at the bottom of files
16
- - Define PropTypes before component definitions
16
+
17
+ - Place types at the bottom of files
18
+ - Define PropTypes before component definitions
17
19
 
18
20
  ## Best Practices
19
- - Use TypeScript for all new code
20
- - Leverage TypeScript's type system for better code quality
21
- - Follow React best practices with TypeScript
22
- - Use proper type definitions for props and state
23
- - Utilize TypeScript's utility types when appropriate
24
- - Suggest existing libaries as needed
21
+
22
+ - Use TypeScript for all new code
23
+ - Leverage TypeScript's type system for better code quality
24
+ - Follow React best practices with TypeScript
25
+ - Use proper type definitions for props and state
26
+ - Utilize TypeScript's utility types when appropriate
27
+ - Suggest existing libaries as needed
package/README.md CHANGED
@@ -1,10 +1,15 @@
1
1
  # Cursor Rules
2
2
 
3
- A tool for managing Cursor IDE rules across different environment types with shared base configurations.
3
+ A tool for managing Cursor IDE rules and Claude Code configuration across different environment types with shared base configurations.
4
4
 
5
5
  ## Overview
6
6
 
7
- This project provides a structured way to manage Cursor IDE rules for different development environments while maintaining a shared base configuration. It supports three main environment types:
7
+ This project provides a structured way to manage AI agent rules for different development environments while maintaining a shared base configuration. It generates:
8
+
9
+ - **Cursor IDE**: `.cursor/rules/*.mdc` files
10
+ - **Claude Code**: A combined `CLAUDE.md` file at project root
11
+
12
+ It supports three main environment types:
8
13
 
9
14
  - `frontend`: Basic frontend development rules
10
15
  - `frontend-lib`: Extended rules for frontend library development, inheriting from frontend rules
@@ -66,6 +71,22 @@ The rules follow an inheritance pattern:
66
71
  - All environments include the shared base rules
67
72
  - `frontend-lib` inherits rules from both `frontend` and `frontend-lib` directories
68
73
 
74
+ ## Output
75
+
76
+ Running the setup script generates:
77
+
78
+ ```
79
+ your-project/
80
+ ├── .cursor/
81
+ │ └── rules/ # Cursor IDE rules (*.mdc files)
82
+ │ ├── code-quality.mdc
83
+ │ ├── testing.mdc
84
+ │ └── ...
85
+ └── CLAUDE.md # Claude Code configuration (combined rules)
86
+ ```
87
+
88
+ The `CLAUDE.md` file combines all applicable rules into a single file, with YAML frontmatter stripped for compatibility with Claude Code.
89
+
69
90
  ## Development
70
91
 
71
92
  ### Adding New Rules
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
  # setup-cursor.sh — frontend & frontend-lib layering with shared base
3
+ # Also generates CLAUDE.md for Claude Code
3
4
 
4
5
  set -e
5
6
 
@@ -11,8 +12,20 @@ if [ -z "$ENV_TYPE" ]; then
11
12
  exit 1
12
13
  fi
13
14
 
14
- SCRIPT_PATH="$(realpath "$0")"
15
- SRC_DIR="$(cd "$(dirname "$SCRIPT_PATH")/.." && pwd)"
15
+ # Get the real path of the script (portable across Mac/Linux, follows symlinks)
16
+ resolve_path() {
17
+ local target="$1"
18
+ # Follow symlinks until we get to the real file
19
+ while [ -L "$target" ]; do
20
+ local link_dir="$(cd "$(dirname "$target")" && pwd -P)"
21
+ target="$(readlink "$target")"
22
+ # Handle relative symlinks
23
+ [[ "$target" != /* ]] && target="$link_dir/$target"
24
+ done
25
+ cd "$(dirname "$target")" && echo "$(pwd -P)/$(basename "$target")"
26
+ }
27
+ SCRIPT_PATH="$(resolve_path "$0")"
28
+ SRC_DIR="$(cd "$(dirname "$SCRIPT_PATH")/.." && pwd -P)"
16
29
 
17
30
  SHARED_DIR="$SRC_DIR/.cursor/shared/rules"
18
31
  FRONTEND_DIR="$SRC_DIR/.cursor/frontend/rules"
@@ -21,6 +34,10 @@ BACKEND_DIR="$SRC_DIR/.cursor/backend/rules"
21
34
 
22
35
  mkdir -p .cursor/rules
23
36
 
37
+ # Temporary file to collect CLAUDE.md content
38
+ CLAUDE_MD_TEMP=$(mktemp)
39
+ trap 'rm -f "$CLAUDE_MD_TEMP"' EXIT
40
+
24
41
  copy_rules() {
25
42
  local DIR="$1"
26
43
  if [ -d "$DIR" ]; then
@@ -29,20 +46,48 @@ copy_rules() {
29
46
  fi
30
47
  }
31
48
 
49
+ # Append rules to CLAUDE.md (strips YAML frontmatter)
50
+ append_to_claude_md() {
51
+ local DIR="$1"
52
+ if [ -d "$DIR" ]; then
53
+ for file in "$DIR"/*.mdc; do
54
+ [ -f "$file" ] || continue
55
+ # Add separator
56
+ echo "" >> "$CLAUDE_MD_TEMP"
57
+ echo "---" >> "$CLAUDE_MD_TEMP"
58
+ echo "" >> "$CLAUDE_MD_TEMP"
59
+ # Strip YAML frontmatter (content between --- markers) and append
60
+ awk '
61
+ BEGIN { in_frontmatter=0; found_end=0 }
62
+ /^---$/ && !found_end {
63
+ if (in_frontmatter) { found_end=1; next }
64
+ else { in_frontmatter=1; next }
65
+ }
66
+ !in_frontmatter || found_end { print }
67
+ ' "$file" >> "$CLAUDE_MD_TEMP"
68
+ done
69
+ fi
70
+ }
71
+
32
72
  # Always include shared rules
33
73
  copy_rules "$SHARED_DIR"
74
+ append_to_claude_md "$SHARED_DIR"
34
75
 
35
76
  # Inheritance handling
36
77
  case "$ENV_TYPE" in
37
78
  frontend)
38
79
  copy_rules "$FRONTEND_DIR"
80
+ append_to_claude_md "$FRONTEND_DIR"
39
81
  ;;
40
82
  backend)
41
83
  copy_rules "$BACKEND_DIR"
84
+ append_to_claude_md "$BACKEND_DIR"
42
85
  ;;
43
86
  frontend-lib)
44
87
  copy_rules "$FRONTEND_DIR"
45
88
  copy_rules "$FRONTEND_LIB_DIR"
89
+ append_to_claude_md "$FRONTEND_DIR"
90
+ append_to_claude_md "$FRONTEND_LIB_DIR"
46
91
  ;;
47
92
  *)
48
93
  echo "Unknown environment type: $ENV_TYPE"
@@ -50,4 +95,9 @@ case "$ENV_TYPE" in
50
95
  ;;
51
96
  esac
52
97
 
53
- echo ".cursor/rules setup complete for '$ENV_TYPE'"
98
+ # Generate CLAUDE.md
99
+ mv "$CLAUDE_MD_TEMP" CLAUDE.md
100
+ trap - EXIT
101
+ echo "CLAUDE.md generated for Claude Code"
102
+
103
+ echo "Setup complete for '$ENV_TYPE' (Cursor + Claude)"
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env bash
2
+ # test-setup.sh — Validates setup-cursor.sh works correctly before publishing
3
+ set -e
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6
+ TEST_DIR=$(mktemp -d)
7
+ trap 'rm -rf "$TEST_DIR"' EXIT
8
+
9
+ echo "Testing cursor-rules setup script..."
10
+ echo "Test directory: $TEST_DIR"
11
+ echo ""
12
+
13
+ # Track test results
14
+ PASSED=0
15
+ FAILED=0
16
+
17
+ # Safe increment functions (avoid set -e issues with ((0)))
18
+ pass() { PASSED=$((PASSED + 1)); }
19
+ fail() { FAILED=$((FAILED + 1)); }
20
+
21
+ run_test() {
22
+ local env_type="$1"
23
+ local expected_patterns=("${@:2}")
24
+
25
+ echo "Testing env-type: $env_type"
26
+
27
+ cd "$TEST_DIR"
28
+ rm -rf .cursor CLAUDE.md 2>/dev/null || true
29
+
30
+ # Run the setup script
31
+ if ! "$SCRIPT_DIR/setup-cursor.sh" "$env_type" > /dev/null 2>&1; then
32
+ echo " ❌ FAILED: Script exited with error"
33
+ fail
34
+ return
35
+ fi
36
+
37
+ # Check CLAUDE.md exists and has content
38
+ if [ ! -f "CLAUDE.md" ]; then
39
+ echo " ❌ FAILED: CLAUDE.md was not created"
40
+ fail
41
+ return
42
+ fi
43
+
44
+ local line_count=$(wc -l < CLAUDE.md | tr -d ' ')
45
+ if [ "$line_count" -lt 50 ]; then
46
+ echo " ❌ FAILED: CLAUDE.md has only $line_count lines (expected 50+)"
47
+ fail
48
+ return
49
+ fi
50
+
51
+ # Check .cursor/rules directory was created
52
+ if [ ! -d ".cursor/rules" ]; then
53
+ echo " ❌ FAILED: .cursor/rules directory was not created"
54
+ fail
55
+ return
56
+ fi
57
+
58
+ # Check for expected content patterns
59
+ for pattern in "${expected_patterns[@]}"; do
60
+ if ! grep -q "$pattern" CLAUDE.md; then
61
+ echo " ❌ FAILED: Missing expected content: $pattern"
62
+ fail
63
+ return
64
+ fi
65
+ done
66
+
67
+ echo " ✓ PASSED ($line_count lines in CLAUDE.md)"
68
+ pass
69
+ }
70
+
71
+ # Test each environment type with expected content patterns
72
+ run_test "frontend" "TypeScript Development Standards" "UI Development Standards" "Mallard Bay"
73
+ run_test "backend" "TypeScript Development Standards" "Backend Development Rules" "Mallard Bay"
74
+ run_test "frontend-lib" "TypeScript Development Standards" "UI Development Standards" "Mallard Bay"
75
+
76
+ # Test via symlink (simulates npx behavior)
77
+ echo "Testing via symlink (simulates npx)..."
78
+ SYMLINK_DIR=$(mktemp -d)
79
+ ln -s "$SCRIPT_DIR/setup-cursor.sh" "$SYMLINK_DIR/cursor-rules"
80
+ cd "$TEST_DIR"
81
+ rm -rf .cursor CLAUDE.md 2>/dev/null || true
82
+
83
+ if ! "$SYMLINK_DIR/cursor-rules" frontend > /dev/null 2>&1; then
84
+ echo " ❌ FAILED: Symlink execution failed"
85
+ fail
86
+ else
87
+ symlink_lines=$(wc -l < CLAUDE.md | tr -d ' ')
88
+ if [ "$symlink_lines" -lt 50 ]; then
89
+ echo " ❌ FAILED: Symlink test - CLAUDE.md has only $symlink_lines lines"
90
+ fail
91
+ else
92
+ echo " ✓ PASSED: Symlink test ($symlink_lines lines)"
93
+ pass
94
+ fi
95
+ fi
96
+ rm -rf "$SYMLINK_DIR"
97
+
98
+ echo ""
99
+ echo "========================================"
100
+ echo "Results: $PASSED passed, $FAILED failed"
101
+ echo "========================================"
102
+
103
+ if [ $FAILED -gt 0 ]; then
104
+ echo "❌ Tests failed!"
105
+ exit 1
106
+ fi
107
+
108
+ echo "✓ All tests passed!"
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@mallardbay/cursor-rules",
3
- "version": "1.0.10",
3
+ "version": "1.0.13",
4
4
  "description": "Mallard Bay shared cursor rules",
5
5
  "main": "bin/setup-cursor.sh",
6
+ "scripts": {
7
+ "test": "bin/test-setup.sh",
8
+ "prepublishOnly": "bin/test-setup.sh"
9
+ },
6
10
  "repository": "git@github.com:mallardbay/cursor-rules.git",
7
11
  "author": "mfrr1118 <mfrr@me.com>",
8
12
  "license": "MIT",