@@ -59,17 +59,33 @@ export interface APIBuilderOptions {
5959 */
6060export type ProgressCallback = ( phase : string , current : number , total : number , message ?: string ) => void ;
6161
62- /**
63- * Generation result information
64- */
65- export interface GenerationResult {
62+ export type GenerationReport = {
6663 success : boolean ;
6764 outputDir : string ;
6865 filesGenerated : Record < string , string > ;
6966 errors : string [ ] ;
7067 warnings : string [ ] ;
7168 duration : number ;
72- }
69+ } ;
70+
71+ export const prettyReport = ( report : GenerationReport ) : string => {
72+ const { success, filesGenerated, errors, warnings, duration } = report ;
73+ const errorsStr = errors . length > 0 ? `Errors: ${ errors . join ( ", " ) } ` : undefined ;
74+ const warningsStr = warnings . length > 0 ? `Warnings: ${ warnings . join ( ", " ) } ` : undefined ;
75+ const files = Object . entries ( filesGenerated )
76+ . map ( ( [ path , content ] ) => ` - ${ path } (${ content . split ( "\n" ) . length } loc)` )
77+ . join ( "\n" ) ;
78+ return [
79+ "Generated files:" ,
80+ files ,
81+ errorsStr ,
82+ warningsStr ,
83+ `Duration: ${ Math . round ( duration ) } ms` ,
84+ `Status: ${ success ? "🟩 Success" : "🟥 Failure" } ` ,
85+ ]
86+ . filter ( ( e ) => e )
87+ . join ( "\n" ) ;
88+ } ;
7389
7490export interface GeneratedFile {
7591 fullFileName : string ;
@@ -400,9 +416,9 @@ export class APIBuilder {
400416 return this ;
401417 }
402418
403- async generate ( ) : Promise < GenerationResult > {
419+ async generate ( ) : Promise < GenerationReport > {
404420 const startTime = performance . now ( ) ;
405- const result : GenerationResult = {
421+ const result : GenerationReport = {
406422 success : false ,
407423 outputDir : this . options . outputDir ,
408424 filesGenerated : { } ,
@@ -512,7 +528,7 @@ export class APIBuilder {
512528 return Array . from ( this . generators . keys ( ) ) ;
513529 }
514530
515- private async executeGenerators ( result : GenerationResult , tsIndex : TypeSchemaIndex ) : Promise < void > {
531+ private async executeGenerators ( result : GenerationReport , tsIndex : TypeSchemaIndex ) : Promise < void > {
516532 for ( const [ type , generator ] of this . generators . entries ( ) ) {
517533 this . logger . info ( `Generating ${ type } ...` ) ;
518534
0 commit comments