1
+ import { log } from '@clack/prompts' ;
2
+ import pc from 'picocolors' ;
3
+
1
4
import { addApiExtensionCommand } from './api-extension/add-api-extension' ;
2
5
import { addCodegenCommand } from './codegen/add-codegen' ;
3
6
import { addEntityCommand } from './entity/add-entity' ;
@@ -145,7 +148,7 @@ export async function performAddOperation(options: AddOperationOptions): Promise
145
148
! options . selectedService . trim ( )
146
149
) {
147
150
throw new Error (
148
- 'Service name is required for job queue. Usage: vendure add -j [plugin-name] --name <job-name> --selectedService <service-name>' ,
151
+ 'Service name is required for job queue. Usage: vendure add -j [plugin-name] --name <job-name> --selected-service <service-name>' ,
149
152
) ;
150
153
}
151
154
await addJobQueueCommand . run ( {
@@ -191,16 +194,16 @@ export async function performAddOperation(options: AddOperationOptions): Promise
191
194
192
195
if ( ! hasValidQueryName && ! hasValidMutationName ) {
193
196
throw new Error (
194
- 'At least one of queryName or mutationName must be specified as a non-empty string. ' +
195
- 'Usage: vendure add -a [plugin-name] --queryName <name> --mutationName <name>' ,
197
+ 'At least one of query-name or mutation-name must be specified as a non-empty string. ' +
198
+ 'Usage: vendure add -a [plugin-name] --query-name <name> --mutation-name <name>' ,
196
199
) ;
197
200
}
198
201
199
202
// If a string is passed for apiExtension, it should be a valid plugin name
200
203
if ( typeof options . apiExtension === 'string' && ! options . apiExtension . trim ( ) ) {
201
204
throw new Error (
202
205
'Plugin name cannot be empty when specified. ' +
203
- 'Usage: vendure add -a [plugin-name] --queryName <name> --mutationName <name>' ,
206
+ 'Usage: vendure add -a [plugin-name] --query-name <name> --mutation-name <name>' ,
204
207
) ;
205
208
}
206
209
@@ -223,7 +226,7 @@ export async function performAddOperation(options: AddOperationOptions): Promise
223
226
// If a string is passed, it should be a valid plugin name
224
227
if ( typeof options . uiExtensions === 'string' && ! options . uiExtensions . trim ( ) ) {
225
228
throw new Error (
226
- 'Plugin name cannot be empty when specified. Usage: vendure add --uiExtensions [plugin-name]' ,
229
+ 'Plugin name cannot be empty when specified. Usage: vendure add --ui-extensions [plugin-name]' ,
227
230
) ;
228
231
}
229
232
await addUiExtensionsCommand . run ( {
@@ -250,9 +253,24 @@ export async function performAddOperation(options: AddOperationOptions): Promise
250
253
) {
251
254
throw error ;
252
255
}
253
- return {
254
- success : false ,
255
- message : error . message ?? 'Add operation failed' ,
256
- } ;
256
+ // For other errors, log them in a more user-friendly way
257
+ // For validation errors, show the full error with stack trace
258
+ if ( error . message . includes ( 'Plugin name is required' ) ) {
259
+ // Extract error message and stack trace
260
+ const errorMessage = error . message ;
261
+ const stackLines = error . stack . split ( '\n' ) ;
262
+ const stackTrace = stackLines . slice ( 1 ) . join ( '\n' ) ; // Remove first line (error message)
263
+
264
+ // Display stack trace first, then colored error message at the end
265
+ log . error ( stackTrace ) ;
266
+ log . error ( '' ) ; // Add empty line for better readability
267
+ log . error ( pc . red ( 'Error:' ) + ' ' + String ( errorMessage ) ) ;
268
+ } else {
269
+ log . error ( error . message as string ) ;
270
+ if ( error . stack ) {
271
+ log . error ( error . stack ) ;
272
+ }
273
+ }
274
+ process . exit ( 1 ) ;
257
275
}
258
276
}
0 commit comments