@@ -4,7 +4,7 @@ import { Command, CommanderError, Option } from 'commander';
44import * as actions from './actions' ;
55import { CliError } from './cli-error' ;
66import { telemetry } from './telemetry' ;
7- import { getVersion } from './utils/version-utils' ;
7+ import { checkNewVersion , getVersion } from './utils/version-utils' ;
88
99const generateAction = async ( options : Parameters < typeof actions . generate > [ 0 ] ) : Promise < void > => {
1010 await telemetry . trackCommand ( 'generate' , ( ) => actions . generate ( options ) ) ;
@@ -51,10 +51,13 @@ function createProgram() {
5151 `schema file (with extension ${ schemaExtensions } ). Defaults to "zenstack/schema.zmodel" unless specified in package.json.` ,
5252 ) ;
5353
54+ const noVersionCheckOption = new Option ( '--no-version-check' , 'do not check for new version' ) ;
55+
5456 program
5557 . command ( 'generate' )
5658 . description ( 'Run code generation plugins.' )
5759 . addOption ( schemaOption )
60+ . addOption ( noVersionCheckOption )
5861 . addOption ( new Option ( '-o, --output <path>' , 'default output directory for code generation' ) )
5962 . addOption ( new Option ( '--silent' , 'suppress all output except errors' ) . default ( false ) )
6063 . action ( generateAction ) ;
@@ -65,6 +68,7 @@ function createProgram() {
6568 migrateCommand
6669 . command ( 'dev' )
6770 . addOption ( schemaOption )
71+ . addOption ( noVersionCheckOption )
6872 . addOption ( new Option ( '-n, --name <name>' , 'migration name' ) )
6973 . addOption ( new Option ( '--create-only' , 'only create migration, do not apply' ) )
7074 . addOption ( migrationsOption )
@@ -76,26 +80,30 @@ function createProgram() {
7680 . addOption ( schemaOption )
7781 . addOption ( new Option ( '--force' , 'skip the confirmation prompt' ) )
7882 . addOption ( migrationsOption )
83+ . addOption ( noVersionCheckOption )
7984 . description ( 'Reset your database and apply all migrations, all data will be lost.' )
8085 . action ( ( options ) => migrateAction ( 'reset' , options ) ) ;
8186
8287 migrateCommand
8388 . command ( 'deploy' )
8489 . addOption ( schemaOption )
90+ . addOption ( noVersionCheckOption )
8591 . addOption ( migrationsOption )
8692 . description ( 'Deploy your pending migrations to your production/staging database.' )
8793 . action ( ( options ) => migrateAction ( 'deploy' , options ) ) ;
8894
8995 migrateCommand
9096 . command ( 'status' )
9197 . addOption ( schemaOption )
98+ . addOption ( noVersionCheckOption )
9299 . addOption ( migrationsOption )
93100 . description ( 'Check the status of your database migrations.' )
94101 . action ( ( options ) => migrateAction ( 'status' , options ) ) ;
95102
96103 migrateCommand
97104 . command ( 'resolve' )
98105 . addOption ( schemaOption )
106+ . addOption ( noVersionCheckOption )
99107 . addOption ( migrationsOption )
100108 . addOption ( new Option ( '--applied <migration>' , 'record a specific migration as applied' ) )
101109 . addOption ( new Option ( '--rolled-back <migration>' , 'record a specific migration as rolled back' ) )
@@ -108,6 +116,7 @@ function createProgram() {
108116 . command ( 'push' )
109117 . description ( 'Push the state from your schema to your database.' )
110118 . addOption ( schemaOption )
119+ . addOption ( noVersionCheckOption )
111120 . addOption ( new Option ( '--accept-data-loss' , 'ignore data loss warnings' ) )
112121 . addOption ( new Option ( '--force-reset' , 'force a reset of the database before push' ) )
113122 . action ( ( options ) => dbAction ( 'push' , options ) ) ;
@@ -116,20 +125,29 @@ function createProgram() {
116125 . command ( 'info' )
117126 . description ( 'Get information of installed ZenStack packages.' )
118127 . argument ( '[path]' , 'project path' , '.' )
128+ . addOption ( noVersionCheckOption )
119129 . action ( infoAction ) ;
120130
121131 program
122132 . command ( 'init' )
123133 . description ( 'Initialize an existing project for ZenStack.' )
124134 . argument ( '[path]' , 'project path' , '.' )
135+ . addOption ( noVersionCheckOption )
125136 . action ( initAction ) ;
126137
127138 program
128139 . command ( 'check' )
129140 . description ( 'Check a ZModel schema for syntax or semantic errors.' )
130141 . addOption ( schemaOption )
142+ . addOption ( noVersionCheckOption )
131143 . action ( checkAction ) ;
132144
145+ program . hook ( 'preAction' , async ( _thisCommand , actionCommand ) => {
146+ if ( actionCommand . getOptionValue ( 'versionCheck' ) !== false ) {
147+ await checkNewVersion ( ) ;
148+ }
149+ } ) ;
150+
133151 return program ;
134152}
135153
0 commit comments