@@ -4,14 +4,15 @@ import { getLiteral, getLiteralArray } from '@zenstackhq/language/utils';
44import { type CliPlugin } from '@zenstackhq/sdk' ;
55import colors from 'colors' ;
66import path from 'node:path' ;
7- import ora from 'ora' ;
7+ import ora , { type Ora } from 'ora' ;
88import { CliError } from '../cli-error' ;
99import * as corePlugins from '../plugins' ;
1010import { getPkgJsonConfig , getSchemaFile , loadSchemaDocument } from './action-utils' ;
1111
1212type Options = {
1313 schema ?: string ;
1414 output ?: string ;
15+ silent : boolean ;
1516} ;
1617
1718/**
@@ -25,10 +26,11 @@ export async function run(options: Options) {
2526 const model = await loadSchemaDocument ( schemaFile ) ;
2627 const outputPath = getOutputPath ( options , schemaFile ) ;
2728
28- await runPlugins ( schemaFile , model , outputPath ) ;
29+ await runPlugins ( schemaFile , model , outputPath , options ) ;
2930
30- console . log ( colors . green ( `Generation completed successfully in ${ Date . now ( ) - start } ms.\n` ) ) ;
31- console . log ( `You can now create a ZenStack client with it.
31+ if ( ! options . silent ) {
32+ console . log ( colors . green ( `Generation completed successfully in ${ Date . now ( ) - start } ms.\n` ) ) ;
33+ console . log ( `You can now create a ZenStack client with it.
3234
3335\`\`\`ts
3436import { ZenStackClient } from '@zenstackhq/runtime';
@@ -38,6 +40,7 @@ const client = new ZenStackClient(schema, {
3840 dialect: { ... }
3941});
4042\`\`\`` ) ;
43+ }
4144}
4245
4346function getOutputPath ( options : Options , schemaFile : string ) {
@@ -52,7 +55,7 @@ function getOutputPath(options: Options, schemaFile: string) {
5255 }
5356}
5457
55- async function runPlugins ( schemaFile : string , model : Model , outputPath : string ) {
58+ async function runPlugins ( schemaFile : string , model : Model , outputPath : string , options : Options ) {
5659 const plugins = model . declarations . filter ( isPlugin ) ;
5760 const processedPlugins : { cliPlugin : CliPlugin ; pluginOptions : Record < string , unknown > } [ ] = [ ] ;
5861
@@ -95,17 +98,21 @@ async function runPlugins(schemaFile: string, model: Model, outputPath: string)
9598 ) ;
9699
97100 // run plugin generator
98- const spinner = ora ( cliPlugin . statusText ?? `Running plugin ${ cliPlugin . name } ` ) . start ( ) ;
101+ let spinner : Ora | undefined ;
102+
103+ if ( ! options . silent ) {
104+ spinner = ora ( cliPlugin . statusText ?? `Running plugin ${ cliPlugin . name } ` ) . start ( ) ;
105+ }
99106 try {
100107 await cliPlugin . generate ( {
101108 schemaFile,
102109 model,
103110 defaultOutputPath : outputPath ,
104111 pluginOptions,
105112 } ) ;
106- spinner . succeed ( ) ;
113+ spinner ? .succeed ( ) ;
107114 } catch ( err ) {
108- spinner . fail ( ) ;
115+ spinner ? .fail ( ) ;
109116 console . error ( err ) ;
110117 }
111118 }
0 commit comments