mtrl-addons 0.2.1 → 0.2.3
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/{src/components/index.ts → dist/components/index.d.ts} +0 -2
- package/dist/components/vlist/config.d.ts +86 -0
- package/{src/components/vlist/constants.ts → dist/components/vlist/constants.d.ts} +10 -11
- package/dist/components/vlist/features/api.d.ts +7 -0
- package/{src/components/vlist/features/index.ts → dist/components/vlist/features/index.d.ts} +0 -2
- package/dist/components/vlist/features/selection.d.ts +6 -0
- package/dist/components/vlist/features/viewport.d.ts +9 -0
- package/dist/components/vlist/features.d.ts +31 -0
- package/{src/components/vlist/index.ts → dist/components/vlist/index.d.ts} +1 -9
- package/dist/components/vlist/types.d.ts +596 -0
- package/dist/components/vlist/vlist.d.ts +29 -0
- package/dist/core/compose/features/gestures/index.d.ts +86 -0
- package/dist/core/compose/features/gestures/longpress.d.ts +85 -0
- package/dist/core/compose/features/gestures/pan.d.ts +108 -0
- package/dist/core/compose/features/gestures/pinch.d.ts +111 -0
- package/dist/core/compose/features/gestures/rotate.d.ts +111 -0
- package/dist/core/compose/features/gestures/swipe.d.ts +149 -0
- package/dist/core/compose/features/gestures/tap.d.ts +79 -0
- package/{src/core/compose/features/index.ts → dist/core/compose/features/index.d.ts} +1 -2
- package/{src/core/compose/index.ts → dist/core/compose/index.d.ts} +2 -11
- package/{src/core/gestures/index.ts → dist/core/gestures/index.d.ts} +1 -20
- package/dist/core/gestures/longpress.d.ts +23 -0
- package/dist/core/gestures/manager.d.ts +14 -0
- package/dist/core/gestures/pan.d.ts +12 -0
- package/dist/core/gestures/pinch.d.ts +14 -0
- package/dist/core/gestures/rotate.d.ts +14 -0
- package/dist/core/gestures/swipe.d.ts +20 -0
- package/dist/core/gestures/tap.d.ts +12 -0
- package/dist/core/gestures/types.d.ts +320 -0
- package/dist/core/gestures/utils.d.ts +57 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/layout/config.d.ts +33 -0
- package/dist/core/layout/index.d.ts +51 -0
- package/dist/core/layout/jsx.d.ts +65 -0
- package/dist/core/layout/schema.d.ts +112 -0
- package/dist/core/layout/types.d.ts +69 -0
- package/dist/core/viewport/constants.d.ts +105 -0
- package/dist/core/viewport/features/base.d.ts +14 -0
- package/dist/core/viewport/features/collection.d.ts +41 -0
- package/dist/core/viewport/features/events.d.ts +13 -0
- package/{src/core/viewport/features/index.ts → dist/core/viewport/features/index.d.ts} +0 -7
- package/dist/core/viewport/features/item-size.d.ts +30 -0
- package/dist/core/viewport/features/loading.d.ts +34 -0
- package/dist/core/viewport/features/momentum.d.ts +17 -0
- package/dist/core/viewport/features/performance.d.ts +53 -0
- package/dist/core/viewport/features/placeholders.d.ts +38 -0
- package/dist/core/viewport/features/rendering.d.ts +16 -0
- package/dist/core/viewport/features/scrollbar.d.ts +26 -0
- package/dist/core/viewport/features/scrolling.d.ts +16 -0
- package/dist/core/viewport/features/utils.d.ts +43 -0
- package/dist/core/viewport/features/virtual.d.ts +18 -0
- package/{src/core/viewport/index.ts → dist/core/viewport/index.d.ts} +1 -17
- package/dist/core/viewport/types.d.ts +96 -0
- package/dist/core/viewport/utils/speed-tracker.d.ts +22 -0
- package/dist/core/viewport/viewport.d.ts +11 -0
- package/{src/index.ts → dist/index.d.ts} +0 -4
- package/dist/index.js +5143 -0
- package/dist/index.mjs +5111 -0
- package/dist/styles.css +254 -0
- package/dist/styles.css.map +1 -0
- package/package.json +6 -1
- package/src/styles/components/_vlist.scss +234 -213
- package/.cursorrules +0 -117
- package/AI.md +0 -241
- package/build.js +0 -201
- package/scripts/analyze-orphaned-functions.ts +0 -387
- package/scripts/debug/vlist-selection.ts +0 -121
- package/src/components/vlist/config.ts +0 -323
- package/src/components/vlist/features/api.ts +0 -322
- package/src/components/vlist/features/selection.ts +0 -444
- package/src/components/vlist/features/viewport.ts +0 -65
- package/src/components/vlist/features.ts +0 -112
- package/src/components/vlist/types.ts +0 -591
- package/src/components/vlist/vlist.ts +0 -92
- package/src/core/compose/features/gestures/index.ts +0 -227
- package/src/core/compose/features/gestures/longpress.ts +0 -383
- package/src/core/compose/features/gestures/pan.ts +0 -424
- package/src/core/compose/features/gestures/pinch.ts +0 -475
- package/src/core/compose/features/gestures/rotate.ts +0 -485
- package/src/core/compose/features/gestures/swipe.ts +0 -492
- package/src/core/compose/features/gestures/tap.ts +0 -334
- package/src/core/gestures/longpress.ts +0 -68
- package/src/core/gestures/manager.ts +0 -418
- package/src/core/gestures/pan.ts +0 -48
- package/src/core/gestures/pinch.ts +0 -58
- package/src/core/gestures/rotate.ts +0 -58
- package/src/core/gestures/swipe.ts +0 -66
- package/src/core/gestures/tap.ts +0 -45
- package/src/core/gestures/types.ts +0 -387
- package/src/core/gestures/utils.ts +0 -128
- package/src/core/index.ts +0 -43
- package/src/core/layout/config.ts +0 -102
- package/src/core/layout/index.ts +0 -168
- package/src/core/layout/jsx.ts +0 -174
- package/src/core/layout/schema.ts +0 -1001
- package/src/core/layout/types.ts +0 -95
- package/src/core/viewport/constants.ts +0 -140
- package/src/core/viewport/features/base.ts +0 -73
- package/src/core/viewport/features/collection.ts +0 -882
- package/src/core/viewport/features/events.ts +0 -130
- package/src/core/viewport/features/item-size.ts +0 -271
- package/src/core/viewport/features/loading.ts +0 -263
- package/src/core/viewport/features/momentum.ts +0 -260
- package/src/core/viewport/features/performance.ts +0 -161
- package/src/core/viewport/features/placeholders.ts +0 -335
- package/src/core/viewport/features/rendering.ts +0 -568
- package/src/core/viewport/features/scrollbar.ts +0 -434
- package/src/core/viewport/features/scrolling.ts +0 -618
- package/src/core/viewport/features/utils.ts +0 -88
- package/src/core/viewport/features/virtual.ts +0 -384
- package/src/core/viewport/types.ts +0 -133
- package/src/core/viewport/utils/speed-tracker.ts +0 -79
- package/src/core/viewport/viewport.ts +0 -246
- package/test/benchmarks/layout/advanced.test.ts +0 -656
- package/test/benchmarks/layout/comparison.test.ts +0 -519
- package/test/benchmarks/layout/performance-comparison.test.ts +0 -274
- package/test/benchmarks/layout/real-components.test.ts +0 -733
- package/test/benchmarks/layout/simple.test.ts +0 -321
- package/test/benchmarks/layout/stress.test.ts +0 -990
- package/test/collection/basic.test.ts +0 -304
- package/test/components/vlist-selection.test.ts +0 -240
- package/test/components/vlist.test.ts +0 -63
- package/test/core/collection/adapter.test.ts +0 -161
- package/test/core/collection/collection.test.ts +0 -394
- package/test/core/layout/layout.test.ts +0 -201
- package/test/utils/dom-helpers.ts +0 -275
- package/test/utils/performance-helpers.ts +0 -392
- package/tsconfig.json +0 -20
package/AI.md
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
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 with better error handling
|
|
76
|
-
console.log('Generating TypeScript declarations...')
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
const tscProcess = Bun.spawn(
|
|
80
|
-
['tsc', '--emitDeclarationOnly', '--outDir', DIST_DIR],
|
|
81
|
-
{
|
|
82
|
-
cwd: __dirname,
|
|
83
|
-
stdio: ['inherit', 'pipe', 'pipe']
|
|
84
|
-
}
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
// Capture stdout and stderr
|
|
88
|
-
const stdout = await new Response(tscProcess.stdout).text()
|
|
89
|
-
const stderr = await new Response(tscProcess.stderr).text()
|
|
90
|
-
|
|
91
|
-
const tscExitCode = await tscProcess.exited
|
|
92
|
-
|
|
93
|
-
if (tscExitCode !== 0) {
|
|
94
|
-
console.error('❌ TypeScript declaration generation failed')
|
|
95
|
-
console.error('Exit code:', tscExitCode)
|
|
96
|
-
if (stdout.trim()) {
|
|
97
|
-
console.error('STDOUT:', stdout)
|
|
98
|
-
}
|
|
99
|
-
if (stderr.trim()) {
|
|
100
|
-
console.error('STDERR:', stderr)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Check if tsc is available
|
|
104
|
-
const whichResult = Bun.spawn(['which', 'tsc'], { stdio: ['inherit', 'pipe', 'pipe'] })
|
|
105
|
-
const tscPath = await new Response(whichResult.stdout).text()
|
|
106
|
-
if (!tscPath.trim()) {
|
|
107
|
-
console.error('💡 TypeScript compiler (tsc) not found. Install it with:')
|
|
108
|
-
console.error(' npm install -g typescript')
|
|
109
|
-
console.error(' or')
|
|
110
|
-
console.error(' bun add -g typescript')
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return false
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
console.log('✓ TypeScript declarations generated')
|
|
117
|
-
if (stdout.trim()) {
|
|
118
|
-
console.log('TSC output:', stdout)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return true
|
|
122
|
-
} catch (tscError) {
|
|
123
|
-
console.error('❌ Error running TypeScript compiler:', tscError.message)
|
|
124
|
-
|
|
125
|
-
// Check if TypeScript is installed
|
|
126
|
-
try {
|
|
127
|
-
const checkTsc = Bun.spawn(['tsc', '--version'], { stdio: ['inherit', 'pipe', 'pipe'] })
|
|
128
|
-
const versionOutput = await new Response(checkTsc.stdout).text()
|
|
129
|
-
const versionExitCode = await checkTsc.exited
|
|
130
|
-
|
|
131
|
-
if (versionExitCode === 0) {
|
|
132
|
-
console.log('TypeScript version:', versionOutput.trim())
|
|
133
|
-
} else {
|
|
134
|
-
console.error('💡 TypeScript compiler not properly installed. Install with:')
|
|
135
|
-
console.error(' npm install -g typescript')
|
|
136
|
-
console.error(' or')
|
|
137
|
-
console.error(' bun add -g typescript')
|
|
138
|
-
}
|
|
139
|
-
} catch (versionError) {
|
|
140
|
-
console.error('💡 TypeScript compiler not found. Install it with:')
|
|
141
|
-
console.error(' npm install -g typescript')
|
|
142
|
-
console.error(' or')
|
|
143
|
-
console.error(' bun add -g typescript')
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return false
|
|
147
|
-
}
|
|
148
|
-
} catch (error) {
|
|
149
|
-
console.error('❌ JavaScript build error:', error)
|
|
150
|
-
console.error(error.stack)
|
|
151
|
-
return false
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const build = async () => {
|
|
156
|
-
try {
|
|
157
|
-
const startTime = Date.now()
|
|
158
|
-
|
|
159
|
-
console.log('┌───────────────────────────────────────────────')
|
|
160
|
-
console.log('│ 🚀 MTRL-Addons Build Process')
|
|
161
|
-
console.log('│ Mode:', isProduction ? '🏭 PRODUCTION' : '🔧 DEVELOPMENT')
|
|
162
|
-
console.log('│ Watch:', isWatch ? '✓ Enabled' : '✗ Disabled')
|
|
163
|
-
console.log('└───────────────────────────────────────────────')
|
|
164
|
-
console.log('')
|
|
165
|
-
|
|
166
|
-
// Create output directory
|
|
167
|
-
await mkdir(DIST_DIR, { recursive: true })
|
|
168
|
-
|
|
169
|
-
// Build JavaScript
|
|
170
|
-
const jsSuccess = await buildApp()
|
|
171
|
-
|
|
172
|
-
const buildTime = ((Date.now() - startTime) / 1000).toFixed(2)
|
|
173
|
-
|
|
174
|
-
if (isWatch && !isProduction) {
|
|
175
|
-
console.log('')
|
|
176
|
-
console.log('┌───────────────────────────────────────────────')
|
|
177
|
-
console.log('│ 👀 Watching for changes...')
|
|
178
|
-
console.log('└───────────────────────────────────────────────')
|
|
179
|
-
|
|
180
|
-
// Watch implementation would go here
|
|
181
|
-
} else {
|
|
182
|
-
console.log('')
|
|
183
|
-
console.log('┌───────────────────────────────────────────────')
|
|
184
|
-
console.log(`│ ✅ Build completed in ${buildTime}s`)
|
|
185
|
-
if (!jsSuccess) {
|
|
186
|
-
console.log('│ ⚠️ Build completed with some errors')
|
|
187
|
-
}
|
|
188
|
-
console.log('└───────────────────────────────────────────────')
|
|
189
|
-
|
|
190
|
-
// Only exit with error code in non-watch mode if there were failures
|
|
191
|
-
if (!isWatch && !jsSuccess) {
|
|
192
|
-
process.exit(1)
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
} catch (error) {
|
|
196
|
-
console.error('❌ Build failed with error:', error)
|
|
197
|
-
process.exit(1)
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
build()
|