mtrl-addons 0.1.0 → 0.1.2
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.
- package/.cursorrules +117 -0
- package/AI.md +241 -0
- package/build.js +148 -0
- package/bun.lock +792 -0
- package/index.ts +7 -0
- package/package.json +10 -17
- package/scripts/analyze-orphaned-functions.ts +387 -0
- package/src/components/index.ts +45 -0
- package/src/components/list/api.ts +314 -0
- package/src/components/list/config.ts +352 -0
- package/src/components/list/constants.ts +56 -0
- package/src/components/list/features/api.ts +428 -0
- package/src/components/list/features/index.ts +31 -0
- package/src/components/list/features/list-manager.ts +502 -0
- package/src/components/list/features.ts +112 -0
- package/src/components/list/index.ts +39 -0
- package/src/components/list/list.ts +234 -0
- package/src/components/list/types.ts +513 -0
- package/src/core/collection/base-collection.ts +100 -0
- package/src/core/collection/collection-composer.ts +178 -0
- package/src/core/collection/collection.ts +745 -0
- package/src/core/collection/constants.ts +172 -0
- package/src/core/collection/events.ts +428 -0
- package/src/core/collection/features/api/loading.ts +279 -0
- package/src/core/collection/features/operations/data-operations.ts +147 -0
- package/src/core/collection/index.ts +104 -0
- package/src/core/collection/state.ts +497 -0
- package/src/core/collection/types.ts +404 -0
- package/src/core/compose/features/collection.ts +119 -0
- package/src/core/compose/features/index.ts +39 -0
- package/src/core/compose/features/performance.ts +161 -0
- package/src/core/compose/features/selection.ts +213 -0
- package/src/core/compose/features/styling.ts +108 -0
- package/src/core/compose/index.ts +31 -0
- package/src/core/index.ts +167 -0
- package/src/core/layout/config.ts +102 -0
- package/src/core/layout/index.ts +168 -0
- package/src/core/layout/jsx.ts +174 -0
- package/src/core/layout/schema.ts +963 -0
- package/src/core/layout/types.ts +92 -0
- package/src/core/list-manager/api.ts +599 -0
- package/src/core/list-manager/config.ts +593 -0
- package/src/core/list-manager/constants.ts +268 -0
- package/src/core/list-manager/features/api.ts +58 -0
- package/src/core/list-manager/features/collection/collection.ts +705 -0
- package/src/core/list-manager/features/collection/index.ts +17 -0
- package/src/core/list-manager/features/viewport/constants.ts +42 -0
- package/src/core/list-manager/features/viewport/index.ts +16 -0
- package/src/core/list-manager/features/viewport/item-size.ts +274 -0
- package/src/core/list-manager/features/viewport/loading.ts +263 -0
- package/src/core/list-manager/features/viewport/placeholders.ts +281 -0
- package/src/core/list-manager/features/viewport/rendering.ts +575 -0
- package/src/core/list-manager/features/viewport/scrollbar.ts +495 -0
- package/src/core/list-manager/features/viewport/scrolling.ts +795 -0
- package/src/core/list-manager/features/viewport/template.ts +220 -0
- package/src/core/list-manager/features/viewport/viewport.ts +654 -0
- package/src/core/list-manager/features/viewport/virtual.ts +309 -0
- package/src/core/list-manager/index.ts +279 -0
- package/src/core/list-manager/list-manager.ts +206 -0
- package/src/core/list-manager/types.ts +439 -0
- package/src/core/list-manager/utils/calculations.ts +290 -0
- package/src/core/list-manager/utils/range-calculator.ts +349 -0
- package/src/core/list-manager/utils/speed-tracker.ts +273 -0
- package/src/index.ts +17 -0
- package/src/styles/components/_list.scss +244 -0
- package/src/styles/index.scss +12 -0
- package/src/types/mtrl.d.ts +6 -0
- package/test/benchmarks/layout/advanced.test.ts +656 -0
- package/test/benchmarks/layout/comparison.test.ts +519 -0
- package/test/benchmarks/layout/performance-comparison.test.ts +274 -0
- package/test/benchmarks/layout/real-components.test.ts +733 -0
- package/test/benchmarks/layout/simple.test.ts +321 -0
- package/test/benchmarks/layout/stress.test.ts +990 -0
- package/test/collection/basic.test.ts +304 -0
- package/test/components/list.test.ts +256 -0
- package/test/core/collection/collection.test.ts +394 -0
- package/test/core/collection/failed-ranges.test.ts +270 -0
- package/test/core/compose/features.test.ts +183 -0
- package/test/core/layout/layout.test.ts +201 -0
- package/test/core/list-manager/features/collection.test.ts +704 -0
- package/test/core/list-manager/features/viewport.test.ts +698 -0
- package/test/core/list-manager/list-manager.test.ts +593 -0
- package/test/core/list-manager/utils/calculations.test.ts +433 -0
- package/test/core/list-manager/utils/range-calculator.test.ts +569 -0
- package/test/core/list-manager/utils/speed-tracker.test.ts +530 -0
- package/test/utils/dom-helpers.ts +275 -0
- package/test/utils/performance-helpers.ts +392 -0
- package/tsconfig.build.json +23 -0
- package/tsconfig.json +20 -0
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -38
- package/dist/index.mjs +0 -8
package/.cursorrules
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# mtrl-addons Package Development Rules
|
|
2
|
+
|
|
3
|
+
## Package Overview
|
|
4
|
+
|
|
5
|
+
mtrl-addons is an extension library for the mtrl Material Design 3 component system, providing specialized elements and extended functionality for modern applications. It maintains the same "less is more" philosophy with zero external dependencies (mtrl as peer dependency only).
|
|
6
|
+
|
|
7
|
+
## Environment & Architecture
|
|
8
|
+
|
|
9
|
+
- Part of workspace alongside mtrl and mtrl-app packages
|
|
10
|
+
- mtrl-app serves as the information hub with documentation and showcases
|
|
11
|
+
- Follows mtrl core architecture patterns and conventions
|
|
12
|
+
- Primary dependency: mtrl
|
|
13
|
+
|
|
14
|
+
## Development Philosophy
|
|
15
|
+
|
|
16
|
+
- Follow "less is more" philosophy - minimalist but complete
|
|
17
|
+
- Optimize for size, memory usage, and speed
|
|
18
|
+
- Keep modules small and reusable for bundling
|
|
19
|
+
- Find root causes and fix problems elegantly with minimal code
|
|
20
|
+
- Avoid over-engineering and workarounds
|
|
21
|
+
|
|
22
|
+
## Pre-Development Checklist
|
|
23
|
+
|
|
24
|
+
1. Check if functionality already exists in mtrl (mtrl/src/core)
|
|
25
|
+
2. Check mtrl styles system (mtrl/src/styles) before creating new styles
|
|
26
|
+
3. Create tests first (mtrl-addons/test/) - test-driven development
|
|
27
|
+
4. Use mtrl-app/docs for all documentation (no .md files in this package)
|
|
28
|
+
|
|
29
|
+
## Code Standards
|
|
30
|
+
|
|
31
|
+
### TypeScript & Structure
|
|
32
|
+
|
|
33
|
+
- Use TypeScript for all components
|
|
34
|
+
- Follow mtrl component and core structure conventions
|
|
35
|
+
- Use pipe pattern for core and component composition
|
|
36
|
+
- Add comprehensive TypeDoc comments for all public APIs
|
|
37
|
+
- Maintain zero external dependencies policy
|
|
38
|
+
|
|
39
|
+
### CSS & Styling
|
|
40
|
+
|
|
41
|
+
- No inline CSS - use external SCSS files in src/styles/
|
|
42
|
+
- Follow BEM naming: mtrl-component\_\_element--modifier
|
|
43
|
+
- Use mtrl styles system as foundation
|
|
44
|
+
|
|
45
|
+
### File Management
|
|
46
|
+
|
|
47
|
+
- Prefer editing existing files over creating new ones
|
|
48
|
+
- Avoid hyphens in filenames if possible
|
|
49
|
+
- Prefer short filenames if clear enough
|
|
50
|
+
- If you need to create html or js debugging files, just ./debugging folder (will be .git ignored)
|
|
51
|
+
- No summary .md files for coding sessions
|
|
52
|
+
- Component and Core usual ts files: index, main(module name), types, constant, api(special feature), features
|
|
53
|
+
- If features become to large, create a folder and split the file by concern ans move api in it if appropriate
|
|
54
|
+
|
|
55
|
+
### Component Development
|
|
56
|
+
|
|
57
|
+
- Follow established mtrl component patterns (config, types, constants, features)
|
|
58
|
+
- Always use functional composition over class inheritance
|
|
59
|
+
- Implement proper lifecycle management
|
|
60
|
+
- Ensure accessibility compliance - this is important!
|
|
61
|
+
- Focus on the specific issue when fixing bugs - avoid enhancements during fixes
|
|
62
|
+
|
|
63
|
+
## Testing Rules
|
|
64
|
+
|
|
65
|
+
- Use Bun test runner for all tests
|
|
66
|
+
- Mock components to avoid circular dependencies
|
|
67
|
+
- Always use JSDOM for DOM testing
|
|
68
|
+
- Comprehensive but lightweight tests
|
|
69
|
+
- Follow test-first development approach
|
|
70
|
+
|
|
71
|
+
## Showcase & Documentation
|
|
72
|
+
|
|
73
|
+
- Create showcases in mtrl-app/client/content only and follow the hierarchy
|
|
74
|
+
- Always use mtrl components via layout system (mtrl-app/docs/layout/usages.md)
|
|
75
|
+
- Prefer array-based layout schema
|
|
76
|
+
- Format schema following the formatting convention (mtrl-app/docs/core/layout/array-schema.md)
|
|
77
|
+
- Avoid manual DOM element creation in showcases
|
|
78
|
+
- Never inline CSS in showcases
|
|
79
|
+
- Focus on demonstrating component capabilities
|
|
80
|
+
- Keep the showcases small, maintainable and readable
|
|
81
|
+
|
|
82
|
+
## Build & Deployment
|
|
83
|
+
|
|
84
|
+
- Build using `bun run build:app` not `bun run build`
|
|
85
|
+
- Fix TypeScript declaration errors immediately
|
|
86
|
+
- Do not start development servers (bun/node)
|
|
87
|
+
- Follow conventional commit format
|
|
88
|
+
- Use `bun run build` for package builds
|
|
89
|
+
- Ensure compatibility with both ES modules and CommonJS
|
|
90
|
+
|
|
91
|
+
## Performance & Optimization
|
|
92
|
+
|
|
93
|
+
- When enhancing/optimizing/refactoring: focus on size, memory usage, and speed
|
|
94
|
+
- Minimize bundle size impact
|
|
95
|
+
- Avoid unnecessary re-renders or DOM manipulations
|
|
96
|
+
- Use efficient algorithms and data structures
|
|
97
|
+
- Design for tree-shaking compatibility
|
|
98
|
+
|
|
99
|
+
## Extension Development
|
|
100
|
+
|
|
101
|
+
- Build upon mtrl core without duplicating functionality
|
|
102
|
+
- Create specialized components not found in base mtrl package
|
|
103
|
+
- Ensure seamless integration with mtrl component ecosystem
|
|
104
|
+
- Maintain API consistency with mtrl patterns
|
|
105
|
+
- Design for modularity - components should be importable individually
|
|
106
|
+
|
|
107
|
+
## Prohibited Actions
|
|
108
|
+
|
|
109
|
+
- Do not use React (pure TypeScript/JavaScript library)
|
|
110
|
+
- Do not create markdown documentation for enhancements
|
|
111
|
+
- Do not run server commands
|
|
112
|
+
- Do not create workarounds or hacks
|
|
113
|
+
- Do not duplicate mtrl core functionality
|
|
114
|
+
- Do not enhance during bug fixes - stay focused on the issue
|
|
115
|
+
- Do not harcode prefix
|
|
116
|
+
- Do not use global Window object to store things
|
|
117
|
+
- Do not build using bun run build (this is used for package build, use bun run build:app)
|
package/AI.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# MTRL-ADDONS - AI Assistant Guide
|
|
2
|
+
|
|
3
|
+
This document provides specific guidance for AI assistants working with the mtrl-addons package - the advanced features extension library for the mtrl ecosystem.
|
|
4
|
+
|
|
5
|
+
## 🎯 Package Purpose
|
|
6
|
+
|
|
7
|
+
mtrl-addons extends the main mtrl library with advanced features and performance-optimized components:
|
|
8
|
+
|
|
9
|
+
- **List Manager**: Virtual scrolling with intelligent data loading
|
|
10
|
+
- **Collection System**: Advanced data management with caching and state
|
|
11
|
+
- **Layout Schema**: Declarative UI composition system
|
|
12
|
+
- **Performance Utilities**: Optimized calculations and range management
|
|
13
|
+
|
|
14
|
+
## 🏗️ Architecture
|
|
15
|
+
|
|
16
|
+
### Core Systems
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
src/
|
|
20
|
+
├── components/ # Extended components
|
|
21
|
+
│ └── list/ # Advanced list component
|
|
22
|
+
├── core/ # Advanced core features
|
|
23
|
+
│ ├── collection/ # Collection management system
|
|
24
|
+
│ ├── list-manager/ # Virtual scrolling engine
|
|
25
|
+
│ └── layout/ # Layout schema system
|
|
26
|
+
└── styles/ # Extended component styles
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Key Features
|
|
30
|
+
|
|
31
|
+
1. **List Manager** (`src/core/list-manager/`)
|
|
32
|
+
- Virtual scrolling with viewport management
|
|
33
|
+
- Item size calculation and caching
|
|
34
|
+
- Custom scrollbar implementation
|
|
35
|
+
- Collection integration for data loading
|
|
36
|
+
|
|
37
|
+
2. **Collection System** (`src/core/collection/`)
|
|
38
|
+
- Data loading and caching strategies
|
|
39
|
+
- State management for large datasets
|
|
40
|
+
- Event-driven architecture
|
|
41
|
+
|
|
42
|
+
3. **Layout Schema** (`src/core/layout/`)
|
|
43
|
+
- Declarative UI composition
|
|
44
|
+
- JSX-like syntax for component creation
|
|
45
|
+
- Array-based schema system
|
|
46
|
+
|
|
47
|
+
## 🛠️ Development Guidelines
|
|
48
|
+
|
|
49
|
+
### Dependencies
|
|
50
|
+
- **Depends on mtrl main** - Import from `mtrl` package
|
|
51
|
+
- **Zero additional dependencies** - Maintain the zero-dependency philosophy
|
|
52
|
+
- **TypeScript first** - All features in TypeScript
|
|
53
|
+
|
|
54
|
+
### Component Enhancement Pattern
|
|
55
|
+
```typescript
|
|
56
|
+
// Use functional composition to enhance components
|
|
57
|
+
import { pipe } from 'mtrl/core/compose';
|
|
58
|
+
import { createList } from 'mtrl/components/list';
|
|
59
|
+
|
|
60
|
+
const enhancedList = pipe(
|
|
61
|
+
createList(config),
|
|
62
|
+
withCollection(collectionConfig),
|
|
63
|
+
withListManager(listManagerConfig),
|
|
64
|
+
withViewport(viewportConfig)
|
|
65
|
+
);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Performance Focus
|
|
69
|
+
- **Virtual scrolling** - Handle massive datasets efficiently
|
|
70
|
+
- **Memory optimization** - Minimize DOM elements and memory usage
|
|
71
|
+
- **Intelligent loading** - Load data on-demand based on viewport
|
|
72
|
+
- **Caching strategies** - Cache measured sizes and loaded data
|
|
73
|
+
|
|
74
|
+
## 📋 List Manager System
|
|
75
|
+
|
|
76
|
+
### Core Components
|
|
77
|
+
- **Viewport**: Virtual scrolling and item positioning
|
|
78
|
+
- **Collection**: Data loading and state management
|
|
79
|
+
- **Item Size Manager**: Dynamic size calculation and caching
|
|
80
|
+
- **Scrolling Manager**: Custom scrollbar and scroll handling
|
|
81
|
+
|
|
82
|
+
### Usage Pattern
|
|
83
|
+
```typescript
|
|
84
|
+
import { createListManager } from 'mtrl-addons/core/list-manager';
|
|
85
|
+
|
|
86
|
+
const listManager = createListManager({
|
|
87
|
+
collection: {
|
|
88
|
+
loadData: async (range) => fetchItems(range),
|
|
89
|
+
totalItems: 100000,
|
|
90
|
+
cacheSize: 1000
|
|
91
|
+
},
|
|
92
|
+
viewport: {
|
|
93
|
+
orientation: 'vertical',
|
|
94
|
+
estimatedItemSize: 60,
|
|
95
|
+
overscan: 5
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Event System
|
|
101
|
+
- **Data Loading**: `range:loaded`, `items:set`, `total:changed`
|
|
102
|
+
- **Viewport Changes**: `viewport:changed`, `range:rendered`
|
|
103
|
+
- **Performance**: `estimated-size:changed`, `dimensions:changed`
|
|
104
|
+
|
|
105
|
+
## 🎨 Styling System
|
|
106
|
+
|
|
107
|
+
### SCSS Architecture
|
|
108
|
+
- **Extends mtrl styles** - Build on core style system
|
|
109
|
+
- **BEM naming** - `mtrl-addon-component__element--modifier`
|
|
110
|
+
- **Performance CSS** - Optimize for virtual scrolling
|
|
111
|
+
|
|
112
|
+
### Virtual Scrolling Styles
|
|
113
|
+
```scss
|
|
114
|
+
.mtrl-list-manager {
|
|
115
|
+
&__viewport {
|
|
116
|
+
overflow: hidden;
|
|
117
|
+
position: relative;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
&__items {
|
|
121
|
+
position: absolute;
|
|
122
|
+
top: 0;
|
|
123
|
+
left: 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
&__scrollbar {
|
|
127
|
+
// Custom scrollbar styles
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## 🧪 Testing Strategy
|
|
133
|
+
|
|
134
|
+
### Test Focus Areas
|
|
135
|
+
- **Performance testing** - Measure virtual scrolling performance
|
|
136
|
+
- **Data loading** - Test collection loading strategies
|
|
137
|
+
- **Memory usage** - Monitor DOM element creation/destruction
|
|
138
|
+
- **Viewport calculations** - Test range calculations and positioning
|
|
139
|
+
|
|
140
|
+
### Test Structure
|
|
141
|
+
```typescript
|
|
142
|
+
// test/core/list-manager/list-manager.test.ts
|
|
143
|
+
describe('ListManager', () => {
|
|
144
|
+
it('should handle large datasets efficiently', () => {
|
|
145
|
+
// Performance test
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('should load data on demand', () => {
|
|
149
|
+
// Data loading test
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Mock Strategies
|
|
155
|
+
- **Mock data sources** - Simulate large datasets
|
|
156
|
+
- **Mock viewport** - Test different container sizes
|
|
157
|
+
- **Mock collection** - Test data loading patterns
|
|
158
|
+
|
|
159
|
+
## 🚀 Common Development Tasks
|
|
160
|
+
|
|
161
|
+
### Adding New List Manager Features
|
|
162
|
+
1. **Create feature module** in `src/core/list-manager/features/`
|
|
163
|
+
2. **Follow enhancement pattern** - Use functional composition
|
|
164
|
+
3. **Add event handling** - Integrate with event system
|
|
165
|
+
4. **Test performance** - Ensure no performance regression
|
|
166
|
+
|
|
167
|
+
### Extending Collection System
|
|
168
|
+
1. **Add to collection features** in `src/core/collection/features/`
|
|
169
|
+
2. **Maintain cache efficiency** - Don't break caching strategies
|
|
170
|
+
3. **Handle edge cases** - Empty datasets, loading failures
|
|
171
|
+
4. **Test data integrity** - Ensure data consistency
|
|
172
|
+
|
|
173
|
+
### Performance Optimization
|
|
174
|
+
1. **Profile virtual scrolling** - Use browser dev tools
|
|
175
|
+
2. **Minimize DOM operations** - Batch updates when possible
|
|
176
|
+
3. **Optimize calculations** - Cache expensive computations
|
|
177
|
+
4. **Monitor memory usage** - Prevent memory leaks
|
|
178
|
+
|
|
179
|
+
## 📊 Performance Benchmarks
|
|
180
|
+
|
|
181
|
+
### Target Metrics
|
|
182
|
+
- **Initial render**: < 100ms for 1000+ items
|
|
183
|
+
- **Scroll performance**: 60 FPS during scrolling
|
|
184
|
+
- **Memory usage**: < 50MB for 100k items
|
|
185
|
+
- **Data loading**: < 200ms for range requests
|
|
186
|
+
|
|
187
|
+
### Monitoring Tools
|
|
188
|
+
- **Performance tests** in `test/benchmarks/`
|
|
189
|
+
- **Memory profiling** with browser dev tools
|
|
190
|
+
- **Scroll performance** measurement utilities
|
|
191
|
+
|
|
192
|
+
## 🔧 Integration with mtrl-app
|
|
193
|
+
|
|
194
|
+
### Showcases
|
|
195
|
+
- **Create showcases** in `mtrl-app/client/content/components/`
|
|
196
|
+
- **Use layout schema** - Demonstrate declarative UI
|
|
197
|
+
- **Performance demos** - Show large dataset handling
|
|
198
|
+
- **Real-world examples** - Practical use cases
|
|
199
|
+
|
|
200
|
+
### Documentation
|
|
201
|
+
- **API documentation** in `mtrl-app/docs/`
|
|
202
|
+
- **Performance guides** - Optimization strategies
|
|
203
|
+
- **Integration examples** - How to use with mtrl core
|
|
204
|
+
|
|
205
|
+
## 🐛 Common Issues & Solutions
|
|
206
|
+
|
|
207
|
+
### Performance Issues
|
|
208
|
+
- **Too many DOM elements** - Increase virtual scrolling efficiency
|
|
209
|
+
- **Memory leaks** - Check event listener cleanup
|
|
210
|
+
- **Slow scrolling** - Optimize item positioning calculations
|
|
211
|
+
|
|
212
|
+
### Data Loading Issues
|
|
213
|
+
- **Loading loops** - Check range calculation logic
|
|
214
|
+
- **Missing data** - Verify collection loading strategies
|
|
215
|
+
- **Inconsistent state** - Review event handling order
|
|
216
|
+
|
|
217
|
+
### Integration Issues
|
|
218
|
+
- **Component composition** - Ensure proper enhancement order
|
|
219
|
+
- **Event conflicts** - Check event listener priorities
|
|
220
|
+
- **Style conflicts** - Verify CSS specificity
|
|
221
|
+
|
|
222
|
+
## 📚 Key Files Reference
|
|
223
|
+
|
|
224
|
+
### Core Systems
|
|
225
|
+
- `src/core/list-manager/list-manager.ts` - Main list manager
|
|
226
|
+
- `src/core/collection/collection.ts` - Collection management
|
|
227
|
+
- `src/core/layout/schema.ts` - Layout schema system
|
|
228
|
+
|
|
229
|
+
### Features
|
|
230
|
+
- `src/core/list-manager/features/viewport/` - Virtual scrolling
|
|
231
|
+
- `src/core/collection/features/` - Collection features
|
|
232
|
+
- `src/core/compose/features/` - Composition utilities
|
|
233
|
+
|
|
234
|
+
### Tests
|
|
235
|
+
- `test/core/list-manager/` - List manager tests
|
|
236
|
+
- `test/benchmarks/` - Performance benchmarks
|
|
237
|
+
- `test/components/` - Component integration tests
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
This guide focuses specifically on mtrl-addons development. For core mtrl development, see `mtrl/CLAUDE.md`. For showcase and documentation, see `mtrl-app/CLAUDE.md`.
|
package/build.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// build.js
|
|
2
|
+
import { mkdir } from "fs/promises";
|
|
3
|
+
import { existsSync } from "fs";
|
|
4
|
+
import { join, dirname } from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const isWatch = process.argv.includes("--watch");
|
|
9
|
+
const isProduction =
|
|
10
|
+
process.argv.includes("--production") ||
|
|
11
|
+
process.env.NODE_ENV === "production";
|
|
12
|
+
|
|
13
|
+
// Define consistent output paths
|
|
14
|
+
const DIST_DIR = join(__dirname, "dist");
|
|
15
|
+
const JS_OUTPUT = join(DIST_DIR, "index.js");
|
|
16
|
+
const MJS_OUTPUT = join(DIST_DIR, "index.mjs");
|
|
17
|
+
|
|
18
|
+
// Log build mode
|
|
19
|
+
console.log(`Building in ${isProduction ? "PRODUCTION" : "DEVELOPMENT"} mode`);
|
|
20
|
+
|
|
21
|
+
const buildApp = async () => {
|
|
22
|
+
try {
|
|
23
|
+
console.log("┌─────────────────────────────────────────");
|
|
24
|
+
console.log("│ JavaScript Build");
|
|
25
|
+
console.log("│ Mode:", isProduction ? "PRODUCTION" : "DEVELOPMENT");
|
|
26
|
+
console.log("│ Minify:", isProduction ? "Yes" : "No");
|
|
27
|
+
console.log("│ Sourcemaps:", isProduction ? "No" : "Yes (inline)");
|
|
28
|
+
console.log("└─────────────────────────────────────────");
|
|
29
|
+
|
|
30
|
+
// Create dist directory if it doesn't exist
|
|
31
|
+
await mkdir(DIST_DIR, { recursive: true });
|
|
32
|
+
|
|
33
|
+
// Build CJS version
|
|
34
|
+
const cjsResult = await Bun.build({
|
|
35
|
+
entrypoints: [join(__dirname, "src/index.ts")],
|
|
36
|
+
outdir: DIST_DIR,
|
|
37
|
+
minify: isProduction,
|
|
38
|
+
sourcemap: isProduction ? "none" : "inline",
|
|
39
|
+
format: "cjs",
|
|
40
|
+
target: "node",
|
|
41
|
+
external: ["mtrl"],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Build ESM version
|
|
45
|
+
const esmResult = await Bun.build({
|
|
46
|
+
entrypoints: [join(__dirname, "src/index.ts")],
|
|
47
|
+
outdir: DIST_DIR,
|
|
48
|
+
minify: isProduction,
|
|
49
|
+
sourcemap: isProduction ? "none" : "inline",
|
|
50
|
+
format: "esm",
|
|
51
|
+
target: "node",
|
|
52
|
+
naming: {
|
|
53
|
+
entry: "index.mjs",
|
|
54
|
+
},
|
|
55
|
+
external: ["mtrl"],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (!cjsResult.success || !esmResult.success) {
|
|
59
|
+
console.error("❌ JavaScript build failed");
|
|
60
|
+
console.error(cjsResult.logs);
|
|
61
|
+
console.error(esmResult.logs);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
console.log("✓ JavaScript build successful");
|
|
66
|
+
console.log(
|
|
67
|
+
` CJS bundle: ${((await Bun.file(JS_OUTPUT).size) / 1024).toFixed(2)} KB`
|
|
68
|
+
);
|
|
69
|
+
console.log(
|
|
70
|
+
` ESM bundle: ${((await Bun.file(MJS_OUTPUT).size) / 1024).toFixed(
|
|
71
|
+
2
|
|
72
|
+
)} KB`
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// Generate type definitions
|
|
76
|
+
console.log("Generating TypeScript declarations...");
|
|
77
|
+
const tscProcess = Bun.spawn(["tsc", "--project", "tsconfig.build.json"], {
|
|
78
|
+
cwd: __dirname,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const tscExitCode = await tscProcess.exited;
|
|
82
|
+
if (tscExitCode !== 0) {
|
|
83
|
+
console.error("❌ TypeScript declaration generation failed");
|
|
84
|
+
// Check if declaration files were actually generated despite errors
|
|
85
|
+
const declarationFile = join(DIST_DIR, "index.d.ts");
|
|
86
|
+
if (existsSync(declarationFile)) {
|
|
87
|
+
console.log("⚠️ Declaration files were generated despite errors");
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
console.log("✓ TypeScript declarations generated");
|
|
94
|
+
return true;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error("❌ JavaScript build error:", error);
|
|
97
|
+
console.error(error.stack);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const build = async () => {
|
|
103
|
+
try {
|
|
104
|
+
const startTime = Date.now();
|
|
105
|
+
|
|
106
|
+
console.log("┌───────────────────────────────────────────────");
|
|
107
|
+
console.log("│ 🚀 MTRL-Addons Build Process");
|
|
108
|
+
console.log("│ Mode:", isProduction ? "🏭 PRODUCTION" : "🔧 DEVELOPMENT");
|
|
109
|
+
console.log("│ Watch:", isWatch ? "✓ Enabled" : "✗ Disabled");
|
|
110
|
+
console.log("└───────────────────────────────────────────────");
|
|
111
|
+
console.log("");
|
|
112
|
+
|
|
113
|
+
// Create output directory
|
|
114
|
+
await mkdir(DIST_DIR, { recursive: true });
|
|
115
|
+
|
|
116
|
+
// Build JavaScript
|
|
117
|
+
const jsSuccess = await buildApp();
|
|
118
|
+
|
|
119
|
+
const buildTime = ((Date.now() - startTime) / 1000).toFixed(2);
|
|
120
|
+
|
|
121
|
+
if (isWatch && !isProduction) {
|
|
122
|
+
console.log("");
|
|
123
|
+
console.log("┌───────────────────────────────────────────────");
|
|
124
|
+
console.log("│ 👀 Watching for changes...");
|
|
125
|
+
console.log("└───────────────────────────────────────────────");
|
|
126
|
+
|
|
127
|
+
// Watch implementation would go here
|
|
128
|
+
} else {
|
|
129
|
+
console.log("");
|
|
130
|
+
console.log("┌───────────────────────────────────────────────");
|
|
131
|
+
console.log(`│ ✅ Build completed in ${buildTime}s`);
|
|
132
|
+
if (!jsSuccess) {
|
|
133
|
+
console.log("│ ⚠️ Build completed with some errors");
|
|
134
|
+
}
|
|
135
|
+
console.log("└───────────────────────────────────────────────");
|
|
136
|
+
|
|
137
|
+
// Only exit with error code in non-watch mode if there were failures
|
|
138
|
+
if (!isWatch && !jsSuccess) {
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
} catch (error) {
|
|
143
|
+
console.error("❌ Build failed with error:", error);
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
build();
|