dorval 0.2.4 ā 0.2.5
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/README.md +109 -157
- package/dist/bin/dorval.cjs +1 -1
- package/dist/bin/dorval.cjs.map +1 -1
- package/dist/bin/dorval.js +1 -1
- package/dist/bin/dorval.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,11 +10,11 @@ CLI tool for generating type-safe Dart/Flutter API clients from OpenAPI specific
|
|
|
10
10
|
- šÆ **Type-safe API clients** - Generate strongly-typed Dart code from OpenAPI specs
|
|
11
11
|
- āļø **Freezed models** - Immutable data classes with copyWith, equality, and more
|
|
12
12
|
- š **JSON serialization** - Built-in fromJson/toJson with json_serializable
|
|
13
|
-
- š **Multiple HTTP clients** - Support for Dio
|
|
13
|
+
- š **Multiple HTTP clients** - Support for Dio (more clients coming soon)
|
|
14
14
|
- š **Full OpenAPI 3.0 support** - Handle complex schemas, references, and more
|
|
15
|
-
- š **Watch mode** - Auto-regenerate on spec changes during development
|
|
16
15
|
- šØ **Highly configurable** - Control every aspect of code generation
|
|
17
16
|
- ā” **Fast generation** - Optimized for large APIs
|
|
17
|
+
- š **Smart header consolidation** - Automatically reduces duplicate header classes
|
|
18
18
|
|
|
19
19
|
## Installation
|
|
20
20
|
|
|
@@ -31,8 +31,6 @@ npm install --save-dev dorval
|
|
|
31
31
|
|
|
32
32
|
## Quick Start
|
|
33
33
|
|
|
34
|
-
### 1. Basic Command Line Usage
|
|
35
|
-
|
|
36
34
|
```bash
|
|
37
35
|
# Generate from a local file
|
|
38
36
|
dorval generate -i ./openapi.yaml -o ./lib/api
|
|
@@ -40,97 +38,96 @@ dorval generate -i ./openapi.yaml -o ./lib/api
|
|
|
40
38
|
# Generate from a URL
|
|
41
39
|
dorval generate -i https://petstore.swagger.io/v2/swagger.json -o ./lib/api
|
|
42
40
|
|
|
43
|
-
#
|
|
44
|
-
dorval generate -
|
|
41
|
+
# Using configuration file (recommended)
|
|
42
|
+
dorval generate -c ./dorval.config.ts
|
|
45
43
|
```
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
## Configuration Guide
|
|
46
|
+
|
|
47
|
+
### Configuration File (Recommended)
|
|
48
48
|
|
|
49
|
-
Create a `dorval.config.ts` (or `.js`, `.json`):
|
|
49
|
+
Create a `dorval.config.ts` (or `.js`, `.json`) file:
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
52
52
|
export default {
|
|
53
53
|
petstore: {
|
|
54
|
-
input: './petstore.yaml',
|
|
54
|
+
input: './petstore.yaml', // Local file, URL, or OpenAPI object
|
|
55
55
|
output: {
|
|
56
|
-
target: './lib/api',
|
|
57
|
-
mode: 'split',
|
|
58
|
-
client: 'dio',
|
|
56
|
+
target: './lib/api', // Output directory
|
|
57
|
+
mode: 'split', // File organization: 'single' | 'split' | 'tags'
|
|
58
|
+
client: 'dio', // HTTP client (currently only 'dio' is supported)
|
|
59
59
|
override: {
|
|
60
60
|
generator: {
|
|
61
|
-
freezed: true,
|
|
62
|
-
jsonSerializable: true,
|
|
63
|
-
nullSafety: true
|
|
61
|
+
freezed: true, // Generate Freezed models (default: true)
|
|
62
|
+
jsonSerializable: true, // Add JSON serialization (default: true)
|
|
63
|
+
nullSafety: true, // Enable null safety (default: true)
|
|
64
|
+
partFiles: true, // Generate part files (default: true)
|
|
65
|
+
equatable: false // Add Equatable support (default: false)
|
|
64
66
|
},
|
|
65
|
-
methodNaming: 'methodPath'
|
|
67
|
+
methodNaming: 'operationId' // 'operationId' | 'methodPath'
|
|
66
68
|
}
|
|
69
|
+
},
|
|
70
|
+
hooks: {
|
|
71
|
+
afterAllFilesWrite: 'dart format .' // Commands to run after generation
|
|
67
72
|
}
|
|
68
73
|
}
|
|
69
74
|
};
|
|
70
75
|
```
|
|
71
76
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
```bash
|
|
75
|
-
dorval generate
|
|
76
|
-
|
|
77
|
-
# Or specify config path
|
|
78
|
-
dorval generate -c ./custom.config.ts
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## Complete Configuration Guide
|
|
82
|
-
|
|
83
|
-
### Configuration File Options
|
|
77
|
+
### Complete Configuration Reference
|
|
84
78
|
|
|
85
79
|
```typescript
|
|
86
80
|
export default {
|
|
87
81
|
apiName: { // You can have multiple APIs in one config
|
|
88
|
-
|
|
82
|
+
|
|
89
83
|
// INPUT OPTIONS
|
|
90
|
-
input:
|
|
91
|
-
|
|
84
|
+
input: {
|
|
85
|
+
target: './path/to/openapi.yaml', // File path or URL
|
|
86
|
+
// OR provide OpenAPI spec directly:
|
|
87
|
+
// target: { openapi: '3.0.0', info: {...}, paths: {...} }
|
|
88
|
+
},
|
|
89
|
+
|
|
92
90
|
// OUTPUT OPTIONS
|
|
93
91
|
output: {
|
|
94
92
|
target: './lib/generated/api', // Output directory
|
|
95
|
-
|
|
93
|
+
|
|
96
94
|
mode: 'split', // File organization
|
|
97
95
|
// 'single' - All code in one file
|
|
98
96
|
// 'split' - Separate models and services (default)
|
|
99
97
|
// 'tags' - Group by OpenAPI tags
|
|
100
|
-
|
|
101
|
-
client: 'dio', // HTTP client library
|
|
102
|
-
|
|
103
|
-
// 'http' - Lightweight, built-in Dart package
|
|
104
|
-
// 'chopper' - Code generation based
|
|
105
|
-
// 'retrofit' - Annotation-based (experimental)
|
|
106
|
-
|
|
98
|
+
|
|
99
|
+
client: 'dio', // HTTP client library (currently only 'dio')
|
|
100
|
+
|
|
107
101
|
override: {
|
|
108
102
|
// Generator options
|
|
109
103
|
generator: {
|
|
110
|
-
freezed: true, // Generate Freezed models
|
|
111
|
-
jsonSerializable: true, // Add JSON serialization
|
|
112
|
-
nullSafety: true, // Enable null safety
|
|
113
|
-
partFiles: true, // Generate part files
|
|
114
|
-
equatable: false
|
|
104
|
+
freezed: true, // Generate Freezed models
|
|
105
|
+
jsonSerializable: true, // Add JSON serialization
|
|
106
|
+
nullSafety: true, // Enable null safety
|
|
107
|
+
partFiles: true, // Generate part files
|
|
108
|
+
equatable: false, // Add Equatable support
|
|
109
|
+
copyWith: true, // Generate copyWith methods
|
|
110
|
+
toString: true, // Generate toString methods
|
|
111
|
+
equality: true // Generate equality operators
|
|
115
112
|
},
|
|
116
|
-
|
|
113
|
+
|
|
117
114
|
// Method naming strategy
|
|
118
115
|
methodNaming: 'operationId', // How to name service methods
|
|
119
116
|
// 'operationId' - Use OpenAPI operationId (default)
|
|
120
117
|
// 'methodPath' - Generate from HTTP method + path
|
|
121
|
-
|
|
122
|
-
// Dio-specific options
|
|
118
|
+
|
|
119
|
+
// Dio-specific options (future enhancement)
|
|
123
120
|
dio: {
|
|
124
121
|
baseUrl: 'https://api.example.com', // Override base URL
|
|
125
122
|
interceptors: ['AuthInterceptor'] // Custom interceptors
|
|
126
123
|
}
|
|
127
124
|
}
|
|
128
125
|
},
|
|
129
|
-
|
|
126
|
+
|
|
130
127
|
// POST-GENERATION HOOKS
|
|
131
128
|
hooks: {
|
|
132
129
|
afterAllFilesWrite: 'dart format .' // Commands to run after generation
|
|
133
|
-
// Can also be an array: ['dart format .', '
|
|
130
|
+
// Can also be an array: ['dart format .', 'dart analyze']
|
|
134
131
|
}
|
|
135
132
|
}
|
|
136
133
|
};
|
|
@@ -148,7 +145,7 @@ export default {
|
|
|
148
145
|
client: 'dio'
|
|
149
146
|
}
|
|
150
147
|
},
|
|
151
|
-
|
|
148
|
+
|
|
152
149
|
// Admin API with different settings
|
|
153
150
|
adminApi: {
|
|
154
151
|
input: './specs/admin-api.yaml',
|
|
@@ -156,7 +153,7 @@ export default {
|
|
|
156
153
|
target: './lib/api/admin',
|
|
157
154
|
client: 'dio',
|
|
158
155
|
override: {
|
|
159
|
-
methodNaming: '
|
|
156
|
+
methodNaming: 'methodPath',
|
|
160
157
|
generator: {
|
|
161
158
|
freezed: true,
|
|
162
159
|
equatable: true // Admin API uses Equatable
|
|
@@ -164,7 +161,7 @@ export default {
|
|
|
164
161
|
}
|
|
165
162
|
}
|
|
166
163
|
},
|
|
167
|
-
|
|
164
|
+
|
|
168
165
|
// Public API from URL
|
|
169
166
|
publicApi: {
|
|
170
167
|
input: 'https://api.example.com/public/openapi.json',
|
|
@@ -176,11 +173,7 @@ export default {
|
|
|
176
173
|
};
|
|
177
174
|
```
|
|
178
175
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
### generate
|
|
182
|
-
|
|
183
|
-
Generate Dart API client from OpenAPI specification.
|
|
176
|
+
### Command Line Options
|
|
184
177
|
|
|
185
178
|
```bash
|
|
186
179
|
dorval generate [options]
|
|
@@ -190,44 +183,10 @@ dorval generate [options]
|
|
|
190
183
|
- `-i, --input <path>` - Path or URL to OpenAPI specification
|
|
191
184
|
- `-o, --output <path>` - Output directory for generated code
|
|
192
185
|
- `-c, --config <path>` - Path to configuration file
|
|
193
|
-
- `--client <type>` - HTTP client type (dio
|
|
186
|
+
- `--client <type>` - HTTP client type (currently only 'dio')
|
|
194
187
|
- `-h, --help` - Display help
|
|
195
188
|
- `-V, --version` - Display version
|
|
196
189
|
|
|
197
|
-
**Examples:**
|
|
198
|
-
|
|
199
|
-
```bash
|
|
200
|
-
# Simple generation
|
|
201
|
-
dorval generate -i api.yaml -o ./lib
|
|
202
|
-
|
|
203
|
-
# With specific client
|
|
204
|
-
dorval generate -i api.yaml -o ./lib --client dio
|
|
205
|
-
|
|
206
|
-
# Using config file
|
|
207
|
-
dorval generate -c ./my-config.js
|
|
208
|
-
|
|
209
|
-
# From URL
|
|
210
|
-
dorval generate -i https://api.example.com/openapi.json -o ./lib
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
### watch
|
|
214
|
-
|
|
215
|
-
Watch OpenAPI spec for changes and regenerate automatically.
|
|
216
|
-
|
|
217
|
-
```bash
|
|
218
|
-
dorval watch [options]
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
**Options:**
|
|
222
|
-
- `-c, --config <path>` - Path to configuration file (required)
|
|
223
|
-
|
|
224
|
-
**Example:**
|
|
225
|
-
|
|
226
|
-
```bash
|
|
227
|
-
# Watch for changes
|
|
228
|
-
dorval watch -c ./dorval.config.ts
|
|
229
|
-
```
|
|
230
|
-
|
|
231
190
|
## Method Naming Strategies
|
|
232
191
|
|
|
233
192
|
Control how generated method names look with the `methodNaming` option:
|
|
@@ -242,7 +201,7 @@ paths:
|
|
|
242
201
|
/pets/{id}:
|
|
243
202
|
get:
|
|
244
203
|
operationId: showPetById
|
|
245
|
-
|
|
204
|
+
|
|
246
205
|
# Generated Dart method
|
|
247
206
|
Future<Pet> showPetById(String id);
|
|
248
207
|
```
|
|
@@ -272,16 +231,15 @@ Future<void> putV1LocationsLocationIdSettings(String locationId, SettingsDto bod
|
|
|
272
231
|
```
|
|
273
232
|
lib/api/
|
|
274
233
|
āāā api_client.dart # HTTP client wrapper
|
|
275
|
-
āāā api_config.dart # API configuration
|
|
276
234
|
āāā models/ # Data models
|
|
277
235
|
ā āāā user.f.dart # Freezed model
|
|
278
236
|
ā āāā user.f.freezed.dart # Generated Freezed code
|
|
279
237
|
ā āāā user.f.g.dart # Generated JSON serialization
|
|
280
|
-
ā āāā params/ # Request parameter models
|
|
238
|
+
ā āāā params/ # Request parameter models (if needed)
|
|
281
239
|
ā ā āāā get_users_params.f.dart
|
|
282
240
|
ā ā āāā index.dart
|
|
283
|
-
ā āāā headers/ # Header parameter models
|
|
284
|
-
ā ā āāā
|
|
241
|
+
ā āāā headers/ # Header parameter models (if needed)
|
|
242
|
+
ā ā āāā auth_headers.f.dart
|
|
285
243
|
ā ā āāā index.dart
|
|
286
244
|
ā āāā index.dart # Barrel exports
|
|
287
245
|
āāā services/ # API services
|
|
@@ -290,54 +248,6 @@ lib/api/
|
|
|
290
248
|
āāā index.dart # Barrel exports
|
|
291
249
|
```
|
|
292
250
|
|
|
293
|
-
## Integration Examples
|
|
294
|
-
|
|
295
|
-
### package.json Scripts
|
|
296
|
-
|
|
297
|
-
```json
|
|
298
|
-
{
|
|
299
|
-
"scripts": {
|
|
300
|
-
"generate": "dorval generate",
|
|
301
|
-
"generate:watch": "dorval watch -c dorval.config.ts",
|
|
302
|
-
"prebuild": "npm run generate"
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
### CI/CD Integration
|
|
308
|
-
|
|
309
|
-
```yaml
|
|
310
|
-
# GitHub Actions
|
|
311
|
-
- name: Generate API Client
|
|
312
|
-
run: |
|
|
313
|
-
npm install -g dorval
|
|
314
|
-
dorval generate -c ./dorval.config.ts
|
|
315
|
-
|
|
316
|
-
# GitLab CI
|
|
317
|
-
generate-api:
|
|
318
|
-
script:
|
|
319
|
-
- npx dorval generate -i $API_SPEC_URL -o ./lib/api
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
### With Environment Variables
|
|
323
|
-
|
|
324
|
-
```typescript
|
|
325
|
-
// dorval.config.ts
|
|
326
|
-
export default {
|
|
327
|
-
api: {
|
|
328
|
-
input: process.env.API_SPEC_URL || './openapi.yaml',
|
|
329
|
-
output: {
|
|
330
|
-
target: './lib/api',
|
|
331
|
-
override: {
|
|
332
|
-
dio: {
|
|
333
|
-
baseUrl: process.env.API_BASE_URL || 'https://api.example.com'
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
```
|
|
340
|
-
|
|
341
251
|
## Flutter/Dart Setup
|
|
342
252
|
|
|
343
253
|
After generating the API client, set up your Flutter project:
|
|
@@ -378,16 +288,16 @@ void main() async {
|
|
|
378
288
|
dio: Dio(),
|
|
379
289
|
baseUrl: 'https://api.example.com',
|
|
380
290
|
);
|
|
381
|
-
|
|
291
|
+
|
|
382
292
|
// Create service
|
|
383
293
|
final usersService = UsersService(apiClient);
|
|
384
|
-
|
|
294
|
+
|
|
385
295
|
// Make type-safe API calls
|
|
386
296
|
final List<User> users = await usersService.getUsers(
|
|
387
297
|
limit: 10,
|
|
388
298
|
offset: 0,
|
|
389
299
|
);
|
|
390
|
-
|
|
300
|
+
|
|
391
301
|
// Handle errors
|
|
392
302
|
try {
|
|
393
303
|
final user = await usersService.getUserById('123');
|
|
@@ -399,6 +309,54 @@ void main() async {
|
|
|
399
309
|
}
|
|
400
310
|
```
|
|
401
311
|
|
|
312
|
+
## Integration Examples
|
|
313
|
+
|
|
314
|
+
### package.json Scripts
|
|
315
|
+
|
|
316
|
+
```json
|
|
317
|
+
{
|
|
318
|
+
"scripts": {
|
|
319
|
+
"generate": "dorval generate",
|
|
320
|
+
"generate:watch": "dorval watch -c dorval.config.ts",
|
|
321
|
+
"prebuild": "npm run generate"
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### CI/CD Integration
|
|
327
|
+
|
|
328
|
+
```yaml
|
|
329
|
+
# GitHub Actions
|
|
330
|
+
- name: Generate API Client
|
|
331
|
+
run: |
|
|
332
|
+
npm install -g dorval
|
|
333
|
+
dorval generate -c ./dorval.config.ts
|
|
334
|
+
|
|
335
|
+
# GitLab CI
|
|
336
|
+
generate-api:
|
|
337
|
+
script:
|
|
338
|
+
- npx dorval generate -i $API_SPEC_URL -o ./lib/api
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### With Environment Variables
|
|
342
|
+
|
|
343
|
+
```typescript
|
|
344
|
+
// dorval.config.ts
|
|
345
|
+
export default {
|
|
346
|
+
api: {
|
|
347
|
+
input: process.env.API_SPEC_URL || './openapi.yaml',
|
|
348
|
+
output: {
|
|
349
|
+
target: './lib/api',
|
|
350
|
+
override: {
|
|
351
|
+
dio: {
|
|
352
|
+
baseUrl: process.env.API_BASE_URL || 'https://api.example.com'
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
```
|
|
359
|
+
|
|
402
360
|
## Advanced Usage
|
|
403
361
|
|
|
404
362
|
### Custom Interceptors
|
|
@@ -455,10 +413,6 @@ class MockUsersService implements UsersService {
|
|
|
455
413
|
|
|
456
414
|
### Common Issues
|
|
457
415
|
|
|
458
|
-
**"Missing loader for extension 'orval.config.mjs'" error**
|
|
459
|
-
- Use `.ts`, `.js`, or `.json` config files instead
|
|
460
|
-
- Or use command line options: `dorval generate -i spec.yaml -o ./lib`
|
|
461
|
-
|
|
462
416
|
**Generated methods return `Map<String, dynamic>` instead of models**
|
|
463
417
|
- Ensure your OpenAPI spec uses `$ref` for response schemas
|
|
464
418
|
- Check that models are defined in `components/schemas`
|
|
@@ -491,10 +445,10 @@ DEBUG=dorval* dorval generate -c dorval.config.ts
|
|
|
491
445
|
| Dart/Flutter Focus | ā
Native | ā ļø Generic | ā ļø Generic |
|
|
492
446
|
| Freezed Support | ā
Built-in | ā Manual | ā Manual |
|
|
493
447
|
| TypeScript Config | ā
Yes | ā Java/CLI | ā Java/CLI |
|
|
494
|
-
|
|
|
495
|
-
| Method Naming Control | ā
Yes | ā No | ā No |
|
|
448
|
+
| Method Naming Control | ā
Yes | ā ļø Limited | ā ļø Limited |
|
|
496
449
|
| NPM Package | ā
Yes | ā Docker/JAR | ā Docker/JAR |
|
|
497
|
-
| Bundle Size | ā
|
|
450
|
+
| Bundle Size | ā
~5MB | ā ~100MB+ | ā ~100MB+ |
|
|
451
|
+
| Header Consolidation | ā
Smart | ā No | ā No |
|
|
498
452
|
|
|
499
453
|
## Migration Guide
|
|
500
454
|
|
|
@@ -520,7 +474,6 @@ We welcome contributions! See [CONTRIBUTING.md](https://github.com/qwlong/dorval
|
|
|
520
474
|
- š [Documentation](https://github.com/qwlong/dorval#readme)
|
|
521
475
|
- š [Report Issues](https://github.com/qwlong/dorval/issues)
|
|
522
476
|
- š¬ [Discussions](https://github.com/qwlong/dorval/discussions)
|
|
523
|
-
- š§ [Email Support](mailto:support@dorval.dev)
|
|
524
477
|
|
|
525
478
|
## License
|
|
526
479
|
|
|
@@ -531,5 +484,4 @@ MIT Ā© 2025
|
|
|
531
484
|
- [GitHub Repository](https://github.com/qwlong/dorval)
|
|
532
485
|
- [NPM Package](https://www.npmjs.com/package/dorval)
|
|
533
486
|
- [Core Library](https://www.npmjs.com/package/@dorval/core)
|
|
534
|
-
- [Petstore Example](https://github.com/qwlong/dorval/tree/master/samples/petstore)
|
|
535
487
|
- [Changelog](https://github.com/qwlong/dorval/blob/master/CHANGELOG.md)
|
package/dist/bin/dorval.cjs
CHANGED
|
@@ -153,7 +153,7 @@ Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
// package.json
|
|
156
|
-
var version = "0.2.
|
|
156
|
+
var version = "0.2.4";
|
|
157
157
|
|
|
158
158
|
// src/bin/dorval.ts
|
|
159
159
|
import_commander.program.name("dorval").description("Generate Dart API clients from OpenAPI specifications").version(version);
|
package/dist/bin/dorval.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bin/dorval.ts","../../src/commands/generate.ts","../../src/config.ts","../../src/commands/watch.ts","../../package.json"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * Dorval CLI entry point\n */\n\nimport { program } from 'commander';\nimport chalk from 'chalk';\nimport { generateCommand } from '../commands/generate.js';\nimport { watchCommand } from '../commands/watch.js';\nimport { version } from '../../package.json';\n\nprogram\n .name('dorval')\n .description('Generate Dart API clients from OpenAPI specifications')\n .version(version);\n\n// Generate command\nprogram\n .command('generate')\n .alias('gen')\n .description('Generate Dart code from OpenAPI spec')\n .option('-c, --config <path>', 'Path to config file')\n .option('-i, --input <path>', 'OpenAPI spec file or URL')\n .option('-o, --output <path>', 'Output directory')\n .option('--client <type>', 'Client type (dio, http, chopper)', 'dio')\n .option('--watch', 'Watch for changes')\n .action(generateCommand);\n\n// Watch command\nprogram\n .command('watch')\n .description('Watch OpenAPI spec for changes and regenerate')\n .option('-c, --config <path>', 'Path to config file')\n .action(watchCommand);\n\n// Default action\nprogram\n .action(() => {\n console.log(chalk.cyan(`\nšÆ Dorval v${version}\nGenerate type-safe Dart API clients from OpenAPI specifications.\n\nUsage:\n dorval generate [options]\n dorval watch [options]\n\nRun 'dorval --help' for more information.\n `));\n });\n\n// Parse command line arguments\nprogram.parse(process.argv);\n\n// Show help if no arguments\nif (!process.argv.slice(2).length) {\n program.outputHelp();\n}","/**\n * Generate command implementation\n */\n\nimport chalk from 'chalk';\nimport { generateDartCode, DartGeneratorOptions } from '@dorval/core';\nimport { loadConfig } from '../config.js';\n\ninterface GenerateOptions {\n config?: string;\n input?: string;\n output?: string;\n client?: 'dio' | 'http' | 'chopper';\n watch?: boolean;\n}\n\nexport async function generateCommand(options: GenerateOptions) {\n // Dynamic import for ora to support both CJS and ESM\n const ora = await import('ora').then(m => m.default || m);\n const spinner = ora('Loading configuration...').start();\n \n try {\n // Load configuration\n let config: DartGeneratorOptions;\n \n if (options.input && options.output) {\n // Use command line options\n config = {\n input: options.input,\n output: {\n target: options.output,\n client: options.client || 'dio',\n mode: 'split',\n override: {\n generator: {\n freezed: true,\n jsonSerializable: true,\n nullSafety: true\n }\n }\n }\n };\n } else if (options.config) {\n config = await loadConfig(options.config);\n } else {\n // Try to load from default locations\n try {\n config = await loadConfig();\n } catch {\n throw new Error('Either provide a config file or use -i and -o options');\n }\n }\n \n spinner.text = 'Parsing OpenAPI specification...';\n \n // Generate code\n const files = await generateDartCode(config);\n \n spinner.succeed(chalk.green(`ā
Generated ${files.length} files`));\n \n // List generated files\n console.log(chalk.cyan('\\nGenerated files:'));\n files.forEach(file => {\n console.log(chalk.gray(` - ${file.path}`));\n });\n \n // Run post-generation hooks\n if (config.hooks?.afterAllFilesWrite) {\n spinner.start('Running post-generation hooks...');\n // TODO: Implement hook execution\n spinner.succeed('Hooks completed');\n }\n \n console.log(chalk.green('\\n⨠Generation completed successfully!'));\n \n } catch (error) {\n spinner.fail(chalk.red('Generation failed'));\n console.error(chalk.red(`\\nError: ${error instanceof Error ? error.message : String(error)}`));\n process.exit(1);\n }\n}","/**\n * Configuration loader\n */\n\nimport { cosmiconfigSync } from 'cosmiconfig';\nimport { DartGeneratorOptions } from '@dorval/core';\n\n// Create explorer lazily to avoid initialization issues\nfunction getExplorer() {\n return cosmiconfigSync('orval', {\n searchPlaces: [\n 'orval.config.ts',\n 'orval.config.js',\n 'orval.config.cjs',\n '.orvalrc',\n '.orvalrc.json',\n '.orvalrc.yaml',\n '.orvalrc.yml',\n 'package.json'\n ]\n });\n}\n\nexport async function loadConfig(configPath?: string): Promise<DartGeneratorOptions> {\n const explorer = getExplorer();\n const result = configPath\n ? explorer.load(configPath)\n : explorer.search();\n \n if (!result) {\n throw new Error('No configuration file found');\n }\n \n // Handle default export or direct config\n const config = result.config.default || result.config;\n \n // If config has multiple specs, use the first one\n if (typeof config === 'object' && !config.input) {\n const firstKey = Object.keys(config)[0];\n return config[firstKey];\n }\n \n return config;\n}","/**\n * Watch command implementation\n */\n\nimport chalk from 'chalk';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { generateDartCode } from '@dorval/core';\nimport { loadConfig } from '../config.js';\n\ninterface WatchOptions {\n config?: string;\n}\n\nexport async function watchCommand(options: WatchOptions) {\n // Dynamic import for ora to support both CJS and ESM\n const ora = await import('ora').then(m => m.default || m);\n const spinner = ora('Starting watch mode...').start();\n \n try {\n // Load configuration\n const config = await loadConfig(options.config);\n \n if (typeof config.input !== 'string') {\n throw new Error('Watch mode requires a file path input');\n }\n \n const inputPath = path.resolve(config.input);\n \n spinner.succeed(chalk.green(`Watching ${inputPath} for changes...`));\n \n // Initial generation\n await generateDartCode(config);\n console.log(chalk.cyan('ā
Initial generation completed'));\n \n // Watch for changes\n fs.watchFile(inputPath, async () => {\n console.log(chalk.yellow('\\nš File changed, regenerating...'));\n \n try {\n await generateDartCode(config);\n console.log(chalk.green('ā
Regeneration completed'));\n } catch (error) {\n console.error(chalk.red(`ā Regeneration failed: ${error instanceof Error ? error.message : String(error)}`));\n }\n });\n \n // Keep process alive\n process.stdin.resume();\n \n // Handle exit\n process.on('SIGINT', () => {\n console.log(chalk.yellow('\\nš Stopping watch mode...'));\n fs.unwatchFile(inputPath);\n process.exit(0);\n });\n \n } catch (error) {\n spinner.fail(chalk.red('Watch mode failed'));\n console.error(chalk.red(`\\nError: ${error instanceof Error ? error.message : String(error)}`));\n process.exit(1);\n }\n}","{\n \"name\": \"dorval\",\n \"version\": \"0.2.0\",\n \"description\": \"CLI tool for generating Dart/Flutter API clients from OpenAPI specifications\",\n \"keywords\": [\n \"cli\",\n \"dart\",\n \"flutter\",\n \"openapi\",\n \"swagger\",\n \"codegen\",\n \"code-generator\",\n \"api-client\",\n \"dio\",\n \"freezed\",\n \"rest-api\",\n \"orval\",\n \"dorval\",\n \"openapi3\",\n \"generator-cli\"\n ],\n \"homepage\": \"https://github.com/qwlong/dorval#readme\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/qwlong/dorval.git\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/qwlong/dorval/issues\"\n },\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\",\n \"types\": \"./dist/index.d.ts\"\n }\n },\n \"bin\": {\n \"dorval\": \"./dist/bin/dorval.js\"\n },\n \"files\": [\n \"dist\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup ./src/index.ts ./src/bin/dorval.ts --clean --sourcemap --watch src --dts\",\n \"lint\": \"eslint 'src/**/*.ts'\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@dorval/core\": \"0.2.0\",\n \"chalk\": \"^4.1.2\",\n \"commander\": \"^11.0.0\",\n \"cosmiconfig\": \"^8.2.0\",\n \"ora\": \"^8.1.1\",\n \"typescript\": \"^5.2.2\"\n },\n \"devDependencies\": {\n \"@types/fs-extra\": \"^11.0.4\",\n \"@types/node\": \"^20.13.0\",\n \"globals\": \"^16.3.0\",\n \"tsup\":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AO,WAAW,mBAAmB,EACrC,OAAO,eAAe;AAGzB,yBACG,QAAQ,OAAO,EACf,YAAY,+CAA+C,EAC3D,OAAO,uBAAuB,qBAAqB,EACnD,OAAO,YAAY;AAGtB,yBACG,OAAO,MAAM;AACZ,UAAQ,IAAI,cAAAC,QAAM,KAAK;AAAA,oBACd,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAQf,CAAC;AACJ,CAAC;AAGH,yBAAQ,MAAM,QAAQ,IAAI;AAG1B,IAAI,CAAC,QAAQ,KAAK,MAAM,CAAC,EAAE,QAAQ;AACjC,2BAAQ,WAAW;AACrB;","names":["import_chalk","chalk","import_chalk","import_core","chalk","chalk"]}
|
|
1
|
+
{"version":3,"sources":["../../src/bin/dorval.ts","../../src/commands/generate.ts","../../src/config.ts","../../src/commands/watch.ts","../../package.json"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * Dorval CLI entry point\n */\n\nimport { program } from 'commander';\nimport chalk from 'chalk';\nimport { generateCommand } from '../commands/generate.js';\nimport { watchCommand } from '../commands/watch.js';\nimport { version } from '../../package.json';\n\nprogram\n .name('dorval')\n .description('Generate Dart API clients from OpenAPI specifications')\n .version(version);\n\n// Generate command\nprogram\n .command('generate')\n .alias('gen')\n .description('Generate Dart code from OpenAPI spec')\n .option('-c, --config <path>', 'Path to config file')\n .option('-i, --input <path>', 'OpenAPI spec file or URL')\n .option('-o, --output <path>', 'Output directory')\n .option('--client <type>', 'Client type (dio, http, chopper)', 'dio')\n .option('--watch', 'Watch for changes')\n .action(generateCommand);\n\n// Watch command\nprogram\n .command('watch')\n .description('Watch OpenAPI spec for changes and regenerate')\n .option('-c, --config <path>', 'Path to config file')\n .action(watchCommand);\n\n// Default action\nprogram\n .action(() => {\n console.log(chalk.cyan(`\nšÆ Dorval v${version}\nGenerate type-safe Dart API clients from OpenAPI specifications.\n\nUsage:\n dorval generate [options]\n dorval watch [options]\n\nRun 'dorval --help' for more information.\n `));\n });\n\n// Parse command line arguments\nprogram.parse(process.argv);\n\n// Show help if no arguments\nif (!process.argv.slice(2).length) {\n program.outputHelp();\n}","/**\n * Generate command implementation\n */\n\nimport chalk from 'chalk';\nimport { generateDartCode, DartGeneratorOptions } from '@dorval/core';\nimport { loadConfig } from '../config.js';\n\ninterface GenerateOptions {\n config?: string;\n input?: string;\n output?: string;\n client?: 'dio' | 'http' | 'chopper';\n watch?: boolean;\n}\n\nexport async function generateCommand(options: GenerateOptions) {\n // Dynamic import for ora to support both CJS and ESM\n const ora = await import('ora').then(m => m.default || m);\n const spinner = ora('Loading configuration...').start();\n \n try {\n // Load configuration\n let config: DartGeneratorOptions;\n \n if (options.input && options.output) {\n // Use command line options\n config = {\n input: options.input,\n output: {\n target: options.output,\n client: options.client || 'dio',\n mode: 'split',\n override: {\n generator: {\n freezed: true,\n jsonSerializable: true,\n nullSafety: true\n }\n }\n }\n };\n } else if (options.config) {\n config = await loadConfig(options.config);\n } else {\n // Try to load from default locations\n try {\n config = await loadConfig();\n } catch {\n throw new Error('Either provide a config file or use -i and -o options');\n }\n }\n \n spinner.text = 'Parsing OpenAPI specification...';\n \n // Generate code\n const files = await generateDartCode(config);\n \n spinner.succeed(chalk.green(`ā
Generated ${files.length} files`));\n \n // List generated files\n console.log(chalk.cyan('\\nGenerated files:'));\n files.forEach(file => {\n console.log(chalk.gray(` - ${file.path}`));\n });\n \n // Run post-generation hooks\n if (config.hooks?.afterAllFilesWrite) {\n spinner.start('Running post-generation hooks...');\n // TODO: Implement hook execution\n spinner.succeed('Hooks completed');\n }\n \n console.log(chalk.green('\\n⨠Generation completed successfully!'));\n \n } catch (error) {\n spinner.fail(chalk.red('Generation failed'));\n console.error(chalk.red(`\\nError: ${error instanceof Error ? error.message : String(error)}`));\n process.exit(1);\n }\n}","/**\n * Configuration loader\n */\n\nimport { cosmiconfigSync } from 'cosmiconfig';\nimport { DartGeneratorOptions } from '@dorval/core';\n\n// Create explorer lazily to avoid initialization issues\nfunction getExplorer() {\n return cosmiconfigSync('orval', {\n searchPlaces: [\n 'orval.config.ts',\n 'orval.config.js',\n 'orval.config.cjs',\n '.orvalrc',\n '.orvalrc.json',\n '.orvalrc.yaml',\n '.orvalrc.yml',\n 'package.json'\n ]\n });\n}\n\nexport async function loadConfig(configPath?: string): Promise<DartGeneratorOptions> {\n const explorer = getExplorer();\n const result = configPath\n ? explorer.load(configPath)\n : explorer.search();\n \n if (!result) {\n throw new Error('No configuration file found');\n }\n \n // Handle default export or direct config\n const config = result.config.default || result.config;\n \n // If config has multiple specs, use the first one\n if (typeof config === 'object' && !config.input) {\n const firstKey = Object.keys(config)[0];\n return config[firstKey];\n }\n \n return config;\n}","/**\n * Watch command implementation\n */\n\nimport chalk from 'chalk';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { generateDartCode } from '@dorval/core';\nimport { loadConfig } from '../config.js';\n\ninterface WatchOptions {\n config?: string;\n}\n\nexport async function watchCommand(options: WatchOptions) {\n // Dynamic import for ora to support both CJS and ESM\n const ora = await import('ora').then(m => m.default || m);\n const spinner = ora('Starting watch mode...').start();\n \n try {\n // Load configuration\n const config = await loadConfig(options.config);\n \n if (typeof config.input !== 'string') {\n throw new Error('Watch mode requires a file path input');\n }\n \n const inputPath = path.resolve(config.input);\n \n spinner.succeed(chalk.green(`Watching ${inputPath} for changes...`));\n \n // Initial generation\n await generateDartCode(config);\n console.log(chalk.cyan('ā
Initial generation completed'));\n \n // Watch for changes\n fs.watchFile(inputPath, async () => {\n console.log(chalk.yellow('\\nš File changed, regenerating...'));\n \n try {\n await generateDartCode(config);\n console.log(chalk.green('ā
Regeneration completed'));\n } catch (error) {\n console.error(chalk.red(`ā Regeneration failed: ${error instanceof Error ? error.message : String(error)}`));\n }\n });\n \n // Keep process alive\n process.stdin.resume();\n \n // Handle exit\n process.on('SIGINT', () => {\n console.log(chalk.yellow('\\nš Stopping watch mode...'));\n fs.unwatchFile(inputPath);\n process.exit(0);\n });\n \n } catch (error) {\n spinner.fail(chalk.red('Watch mode failed'));\n console.error(chalk.red(`\\nError: ${error instanceof Error ? error.message : String(error)}`));\n process.exit(1);\n }\n}","{\n \"name\": \"dorval\",\n \"version\": \"0.2.4\",\n \"description\": \"CLI tool for generating Dart/Flutter API clients from OpenAPI specifications\",\n \"keywords\": [\n \"cli\",\n \"dart\",\n \"flutter\",\n \"openapi\",\n \"swagger\",\n \"codegen\",\n \"code-generator\",\n \"api-client\",\n \"dio\",\n \"freezed\",\n \"rest-api\",\n \"orval\",\n \"dorval\",\n \"openapi3\",\n \"generator-cli\"\n ],\n \"homepage\": \"https://github.com/qwlong/dorval#readme\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/qwlong/dorval.git\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/qwlong/dorval/issues\"\n },\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\",\n \"types\": \"./dist/index.d.ts\"\n }\n },\n \"bin\": {\n \"dorval\": \"./dist/bin/dorval.js\"\n },\n \"files\": [\n \"dist\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup ./src/index.ts ./src/bin/dorval.ts --clean --sourcemap --watch src --dts\",\n \"lint\": \"eslint 'src/**/*.ts'\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@dorval/core\": \"0.2.0\",\n \"chalk\": \"^4.1.2\",\n \"commander\": \"^11.0.0\",\n \"cosmiconfig\": \"^8.2.0\",\n \"ora\": \"^8.1.1\",\n \"typescript\": \"^5.2.2\"\n },\n \"devDependencies\": {\n \"@types/fs-extra\": \"^11.0.4\",\n \"@types/node\": \"^20.13.0\",\n \"globals\": \"^16.3.0\",\n \"tsup\": \"^8.5.0\",\n \"vitest\": \"^0.6.3\"\n },\n \"engines\": {\n \"node\": \">=20.8.1\"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AY,+CAA+C,EAC3D,OAAO,uBAAuB,qBAAqB,EACnD,OAAO,YAAY;AAGtB,yBACG,OAAO,MAAM;AACZ,UAAQ,IAAI,cAAAC,QAAM,KAAK;AAAA,oBACd,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAQf,CAAC;AACJ,CAAC;AAGH,yBAAQ,MAAM,QAAQ,IAAI;AAG1B,IAAI,CAAC,QAAQ,KAAK,MAAM,CAAC,EAAE,QAAQ;AACjC,2BAAQ,WAAW;AACrB;","names":["import_chalk","chalk","import_chalk","import_core","chalk","chalk"]}
|
package/dist/bin/dorval.js
CHANGED
|
@@ -130,7 +130,7 @@ Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
// package.json
|
|
133
|
-
var version = "0.2.
|
|
133
|
+
var version = "0.2.4";
|
|
134
134
|
|
|
135
135
|
// src/bin/dorval.ts
|
|
136
136
|
program.name("dorval").description("Generate Dart API clients from OpenAPI specifications").version(version);
|
package/dist/bin/dorval.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bin/dorval.ts","../../src/commands/generate.ts","../../src/config.ts","../../src/commands/watch.ts","../../package.json"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * Dorval CLI entry point\n */\n\nimport { program } from 'commander';\nimport chalk from 'chalk';\nimport { generateCommand } from '../commands/generate.js';\nimport { watchCommand } from '../commands/watch.js';\nimport { version } from '../../package.json';\n\nprogram\n .name('dorval')\n .description('Generate Dart API clients from OpenAPI specifications')\n .version(version);\n\n// Generate command\nprogram\n .command('generate')\n .alias('gen')\n .description('Generate Dart code from OpenAPI spec')\n .option('-c, --config <path>', 'Path to config file')\n .option('-i, --input <path>', 'OpenAPI spec file or URL')\n .option('-o, --output <path>', 'Output directory')\n .option('--client <type>', 'Client type (dio, http, chopper)', 'dio')\n .option('--watch', 'Watch for changes')\n .action(generateCommand);\n\n// Watch command\nprogram\n .command('watch')\n .description('Watch OpenAPI spec for changes and regenerate')\n .option('-c, --config <path>', 'Path to config file')\n .action(watchCommand);\n\n// Default action\nprogram\n .action(() => {\n console.log(chalk.cyan(`\nšÆ Dorval v${version}\nGenerate type-safe Dart API clients from OpenAPI specifications.\n\nUsage:\n dorval generate [options]\n dorval watch [options]\n\nRun 'dorval --help' for more information.\n `));\n });\n\n// Parse command line arguments\nprogram.parse(process.argv);\n\n// Show help if no arguments\nif (!process.argv.slice(2).length) {\n program.outputHelp();\n}","/**\n * Generate command implementation\n */\n\nimport chalk from 'chalk';\nimport { generateDartCode, DartGeneratorOptions } from '@dorval/core';\nimport { loadConfig } from '../config.js';\n\ninterface GenerateOptions {\n config?: string;\n input?: string;\n output?: string;\n client?: 'dio' | 'http' | 'chopper';\n watch?: boolean;\n}\n\nexport async function generateCommand(options: GenerateOptions) {\n // Dynamic import for ora to support both CJS and ESM\n const ora = await import('ora').then(m => m.default || m);\n const spinner = ora('Loading configuration...').start();\n \n try {\n // Load configuration\n let config: DartGeneratorOptions;\n \n if (options.input && options.output) {\n // Use command line options\n config = {\n input: options.input,\n output: {\n target: options.output,\n client: options.client || 'dio',\n mode: 'split',\n override: {\n generator: {\n freezed: true,\n jsonSerializable: true,\n nullSafety: true\n }\n }\n }\n };\n } else if (options.config) {\n config = await loadConfig(options.config);\n } else {\n // Try to load from default locations\n try {\n config = await loadConfig();\n } catch {\n throw new Error('Either provide a config file or use -i and -o options');\n }\n }\n \n spinner.text = 'Parsing OpenAPI specification...';\n \n // Generate code\n const files = await generateDartCode(config);\n \n spinner.succeed(chalk.green(`ā
Generated ${files.length} files`));\n \n // List generated files\n console.log(chalk.cyan('\\nGenerated files:'));\n files.forEach(file => {\n console.log(chalk.gray(` - ${file.path}`));\n });\n \n // Run post-generation hooks\n if (config.hooks?.afterAllFilesWrite) {\n spinner.start('Running post-generation hooks...');\n // TODO: Implement hook execution\n spinner.succeed('Hooks completed');\n }\n \n console.log(chalk.green('\\n⨠Generation completed successfully!'));\n \n } catch (error) {\n spinner.fail(chalk.red('Generation failed'));\n console.error(chalk.red(`\\nError: ${error instanceof Error ? error.message : String(error)}`));\n process.exit(1);\n }\n}","/**\n * Configuration loader\n */\n\nimport { cosmiconfigSync } from 'cosmiconfig';\nimport { DartGeneratorOptions } from '@dorval/core';\n\n// Create explorer lazily to avoid initialization issues\nfunction getExplorer() {\n return cosmiconfigSync('orval', {\n searchPlaces: [\n 'orval.config.ts',\n 'orval.config.js',\n 'orval.config.cjs',\n '.orvalrc',\n '.orvalrc.json',\n '.orvalrc.yaml',\n '.orvalrc.yml',\n 'package.json'\n ]\n });\n}\n\nexport async function loadConfig(configPath?: string): Promise<DartGeneratorOptions> {\n const explorer = getExplorer();\n const result = configPath\n ? explorer.load(configPath)\n : explorer.search();\n \n if (!result) {\n throw new Error('No configuration file found');\n }\n \n // Handle default export or direct config\n const config = result.config.default || result.config;\n \n // If config has multiple specs, use the first one\n if (typeof config === 'object' && !config.input) {\n const firstKey = Object.keys(config)[0];\n return config[firstKey];\n }\n \n return config;\n}","/**\n * Watch command implementation\n */\n\nimport chalk from 'chalk';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { generateDartCode } from '@dorval/core';\nimport { loadConfig } from '../config.js';\n\ninterface WatchOptions {\n config?: string;\n}\n\nexport async function watchCommand(options: WatchOptions) {\n // Dynamic import for ora to support both CJS and ESM\n const ora = await import('ora').then(m => m.default || m);\n const spinner = ora('Starting watch mode...').start();\n \n try {\n // Load configuration\n const config = await loadConfig(options.config);\n \n if (typeof config.input !== 'string') {\n throw new Error('Watch mode requires a file path input');\n }\n \n const inputPath = path.resolve(config.input);\n \n spinner.succeed(chalk.green(`Watching ${inputPath} for changes...`));\n \n // Initial generation\n await generateDartCode(config);\n console.log(chalk.cyan('ā
Initial generation completed'));\n \n // Watch for changes\n fs.watchFile(inputPath, async () => {\n console.log(chalk.yellow('\\nš File changed, regenerating...'));\n \n try {\n await generateDartCode(config);\n console.log(chalk.green('ā
Regeneration completed'));\n } catch (error) {\n console.error(chalk.red(`ā Regeneration failed: ${error instanceof Error ? error.message : String(error)}`));\n }\n });\n \n // Keep process alive\n process.stdin.resume();\n \n // Handle exit\n process.on('SIGINT', () => {\n console.log(chalk.yellow('\\nš Stopping watch mode...'));\n fs.unwatchFile(inputPath);\n process.exit(0);\n });\n \n } catch (error) {\n spinner.fail(chalk.red('Watch mode failed'));\n console.error(chalk.red(`\\nError: ${error instanceof Error ? error.message : String(error)}`));\n process.exit(1);\n }\n}","{\n \"name\": \"dorval\",\n \"version\": \"0.2.0\",\n \"description\": \"CLI tool for generating Dart/Flutter API clients from OpenAPI specifications\",\n \"keywords\": [\n \"cli\",\n \"dart\",\n \"flutter\",\n \"openapi\",\n \"swagger\",\n \"codegen\",\n \"code-generator\",\n \"api-client\",\n \"dio\",\n \"freezed\",\n \"rest-api\",\n \"orval\",\n \"dorval\",\n \"openapi3\",\n \"generator-cli\"\n ],\n \"homepage\": \"https://github.com/qwlong/dorval#readme\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/qwlong/dorval.git\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/qwlong/dorval/issues\"\n },\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\",\n \"types\": \"./dist/index.d.ts\"\n }\n },\n \"bin\": {\n \"dorval\": \"./dist/bin/dorval.js\"\n },\n \"files\": [\n \"dist\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup ./src/index.ts ./src/bin/dorval.ts --clean --sourcemap --watch src --dts\",\n \"lint\": \"eslint 'src/**/*.ts'\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@dorval/core\": \"0.2.0\",\n \"chalk\": \"^4.1.2\",\n \"commander\": \"^11.0.0\",\n \"cosmiconfig\": \"^8.2.0\",\n \"ora\": \"^8.1.1\",\n \"typescript\": \"^5.2.2\"\n },\n \"devDependencies\": {\n \"@types/fs-extra\": \"^11.0.4\",\n \"@types/node\": \"^20.13.0\",\n \"globals\": \"^16.3.0\",\n \"tsup\": \"^8.5.0\",\n \"vitest\": \"^0.6.3\"\n },\n \"engines\": {\n \"node\": \">=20.8.1\"\n }\n}\n"],"mappings":";;;AAMA,SAAS,eAAe;AACxB,OAAOA,YAAW;;;ACHlB,OAAO,WAAW;AAClB,SAAS,wBAA8C;;;ACDvD,SAAS,uBAAuB;AAIhC,SAAS,cAAc;AACrB,SAAO,gBAAgB,SAAS;AAAA,IAC9B,cAAc;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,eAAsB,WAAW,YAAoD;AACnF,QAAM,WAAW,YAAY;AAC7B,QAAM,SAAS,aACX,SAAS,KAAK,UAAU,IACxB,SAAS,OAAO;AAEpB,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AAGA,QAAM,SAAS,OAAO,OAAO,WAAW,OAAO;AAG/C,MAAI,OAAO,WAAW,YAAY,CAAC,OAAO,OAAO;AAC/C,UAAM,WAAW,OAAO,KAAK,MAAM,EAAE,CAAC;AACtC,WAAO,OAAO,QAAQ;AAAA,EACxB;AAEA,SAAO;AACT;;;AD3BA,eAAsB,gBAAgB,SAA0B;AAE9D,QAAM,MAAM,MAAM,OAAO,KAAK,EAAE,KAAK,OAAK,EAAE,WAAW,CAAC;AACxD,QAAM,UAAU,IAAI,0BAA0B,EAAE,MAAM;AAEtD,MAAI;AAEF,QAAI;AAEJ,QAAI,QAAQ,SAAS,QAAQ,QAAQ;AAEnC,eAAS;AAAA,QACP,OAAO,QAAQ;AAAA,QACf,QAAQ;AAAA,UACN,QAAQ,QAAQ;A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AAsB,0BAA0B,EACvD,OAAO,uBAAuB,kBAAkB,EAChD,OAAO,mBAAmB,oCAAoC,KAAK,EACnE,OAAO,WAAW,mBAAmB,EACrC,OAAO,eAAe;AAGzB,QACG,QAAQ,OAAO,EACf,YAAY,+CAA+C,EAC3D,OAAO,uBAAuB,qBAAqB,EACnD,OAAO,YAAY;AAGtB,QACG,OAAO,MAAM;AACZ,UAAQ,IAAIE,OAAM,KAAK;AAAA,oBACd,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAQf,CAAC;AACJ,CAAC;AAGH,QAAQ,MAAM,QAAQ,IAAI;AAG1B,IAAI,CAAC,QAAQ,KAAK,MAAM,CAAC,EAAE,QAAQ;AACjC,UAAQ,WAAW;AACrB;","names":["chalk","chalk","generateDartCode","chalk","generateDartCode","chalk"]}
|
|
1
|
+
{"version":3,"sources":["../../src/bin/dorval.ts","../../src/commands/generate.ts","../../src/config.ts","../../src/commands/watch.ts","../../package.json"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * Dorval CLI entry point\n */\n\nimport { program } from 'commander';\nimport chalk from 'chalk';\nimport { generateCommand } from '../commands/generate.js';\nimport { watchCommand } from '../commands/watch.js';\nimport { version } from '../../package.json';\n\nprogram\n .name('dorval')\n .description('Generate Dart API clients from OpenAPI specifications')\n .version(version);\n\n// Generate command\nprogram\n .command('generate')\n .alias('gen')\n .description('Generate Dart code from OpenAPI spec')\n .option('-c, --config <path>', 'Path to config file')\n .option('-i, --input <path>', 'OpenAPI spec file or URL')\n .option('-o, --output <path>', 'Output directory')\n .option('--client <type>', 'Client type (dio, http, chopper)', 'dio')\n .option('--watch', 'Watch for changes')\n .action(generateCommand);\n\n// Watch command\nprogram\n .command('watch')\n .description('Watch OpenAPI spec for changes and regenerate')\n .option('-c, --config <path>', 'Path to config file')\n .action(watchCommand);\n\n// Default action\nprogram\n .action(() => {\n console.log(chalk.cyan(`\nšÆ Dorval v${version}\nGenerate type-safe Dart API clients from OpenAPI specifications.\n\nUsage:\n dorval generate [options]\n dorval watch [options]\n\nRun 'dorval --help' for more information.\n `));\n });\n\n// Parse command line arguments\nprogram.parse(process.argv);\n\n// Show help if no arguments\nif (!process.argv.slice(2).length) {\n program.outputHelp();\n}","/**\n * Generate command implementation\n */\n\nimport chalk from 'chalk';\nimport { generateDartCode, DartGeneratorOptions } from '@dorval/core';\nimport { loadConfig } from '../config.js';\n\ninterface GenerateOptions {\n config?: string;\n input?: string;\n output?: string;\n client?: 'dio' | 'http' | 'chopper';\n watch?: boolean;\n}\n\nexport async function generateCommand(options: GenerateOptions) {\n // Dynamic import for ora to support both CJS and ESM\n const ora = await import('ora').then(m => m.default || m);\n const spinner = ora('Loading configuration...').start();\n \n try {\n // Load configuration\n let config: DartGeneratorOptions;\n \n if (options.input && options.output) {\n // Use command line options\n config = {\n input: options.input,\n output: {\n target: options.output,\n client: options.client || 'dio',\n mode: 'split',\n override: {\n generator: {\n freezed: true,\n jsonSerializable: true,\n nullSafety: true\n }\n }\n }\n };\n } else if (options.config) {\n config = await loadConfig(options.config);\n } else {\n // Try to load from default locations\n try {\n config = await loadConfig();\n } catch {\n throw new Error('Either provide a config file or use -i and -o options');\n }\n }\n \n spinner.text = 'Parsing OpenAPI specification...';\n \n // Generate code\n const files = await generateDartCode(config);\n \n spinner.succeed(chalk.green(`ā
Generated ${files.length} files`));\n \n // List generated files\n console.log(chalk.cyan('\\nGenerated files:'));\n files.forEach(file => {\n console.log(chalk.gray(` - ${file.path}`));\n });\n \n // Run post-generation hooks\n if (config.hooks?.afterAllFilesWrite) {\n spinner.start('Running post-generation hooks...');\n // TODO: Implement hook execution\n spinner.succeed('Hooks completed');\n }\n \n console.log(chalk.green('\\n⨠Generation completed successfully!'));\n \n } catch (error) {\n spinner.fail(chalk.red('Generation failed'));\n console.error(chalk.red(`\\nError: ${error instanceof Error ? error.message : String(error)}`));\n process.exit(1);\n }\n}","/**\n * Configuration loader\n */\n\nimport { cosmiconfigSync } from 'cosmiconfig';\nimport { DartGeneratorOptions } from '@dorval/core';\n\n// Create explorer lazily to avoid initialization issues\nfunction getExplorer() {\n return cosmiconfigSync('orval', {\n searchPlaces: [\n 'orval.config.ts',\n 'orval.config.js',\n 'orval.config.cjs',\n '.orvalrc',\n '.orvalrc.json',\n '.orvalrc.yaml',\n '.orvalrc.yml',\n 'package.json'\n ]\n });\n}\n\nexport async function loadConfig(configPath?: string): Promise<DartGeneratorOptions> {\n const explorer = getExplorer();\n const result = configPath\n ? explorer.load(configPath)\n : explorer.search();\n \n if (!result) {\n throw new Error('No configuration file found');\n }\n \n // Handle default export or direct config\n const config = result.config.default || result.config;\n \n // If config has multiple specs, use the first one\n if (typeof config === 'object' && !config.input) {\n const firstKey = Object.keys(config)[0];\n return config[firstKey];\n }\n \n return config;\n}","/**\n * Watch command implementation\n */\n\nimport chalk from 'chalk';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { generateDartCode } from '@dorval/core';\nimport { loadConfig } from '../config.js';\n\ninterface WatchOptions {\n config?: string;\n}\n\nexport async function watchCommand(options: WatchOptions) {\n // Dynamic import for ora to support both CJS and ESM\n const ora = await import('ora').then(m => m.default || m);\n const spinner = ora('Starting watch mode...').start();\n \n try {\n // Load configuration\n const config = await loadConfig(options.config);\n \n if (typeof config.input !== 'string') {\n throw new Error('Watch mode requires a file path input');\n }\n \n const inputPath = path.resolve(config.input);\n \n spinner.succeed(chalk.green(`Watching ${inputPath} for changes...`));\n \n // Initial generation\n await generateDartCode(config);\n console.log(chalk.cyan('ā
Initial generation completed'));\n \n // Watch for changes\n fs.watchFile(inputPath, async () => {\n console.log(chalk.yellow('\\nš File changed, regenerating...'));\n \n try {\n await generateDartCode(config);\n console.log(chalk.green('ā
Regeneration completed'));\n } catch (error) {\n console.error(chalk.red(`ā Regeneration failed: ${error instanceof Error ? error.message : String(error)}`));\n }\n });\n \n // Keep process alive\n process.stdin.resume();\n \n // Handle exit\n process.on('SIGINT', () => {\n console.log(chalk.yellow('\\nš Stopping watch mode...'));\n fs.unwatchFile(inputPath);\n process.exit(0);\n });\n \n } catch (error) {\n spinner.fail(chalk.red('Watch mode failed'));\n console.error(chalk.red(`\\nError: ${error instanceof Error ? error.message : String(error)}`));\n process.exit(1);\n }\n}","{\n \"name\": \"dorval\",\n \"version\": \"0.2.4\",\n \"description\": \"CLI tool for generating Dart/Flutter API clients from OpenAPI specifications\",\n \"keywords\": [\n \"cli\",\n \"dart\",\n \"flutter\",\n \"openapi\",\n \"swagger\",\n \"codegen\",\n \"code-generator\",\n \"api-client\",\n \"dio\",\n \"freezed\",\n \"rest-api\",\n \"orval\",\n \"dorval\",\n \"openapi3\",\n \"generator-cli\"\n ],\n \"homepage\": \"https://github.com/qwlong/dorval#readme\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/qwlong/dorval.git\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/qwlong/dorval/issues\"\n },\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\",\n \"types\": \"./dist/index.d.ts\"\n }\n },\n \"bin\": {\n \"dorval\": \"./dist/bin/dorval.js\"\n },\n \"files\": [\n \"dist\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup ./src/index.ts ./src/bin/dorval.ts --clean --sourcemap --watch src --dts\",\n \"lint\": \"eslint 'src/**/*.ts'\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@dorval/core\": \"0.2.0\",\n \"chalk\": \"^4.1.2\",\n \"commander\": \"^11.0.0\",\n \"cosmiconfig\": \"^8.2.0\",\n \"ora\": \"^8.1.1\",\n \"typescript\": \"^5.2.2\"\n },\n \"devDependencies\": {\n \"@types/fs-extra\": \"^11.0.4\",\n \"@types/node\": \"^20.13.0\",\n \"globals\": \"^16.3.0\",\n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