@@ -6,14 +6,14 @@ import {
66 ICommandDispatcher ,
77 ICancellationService ,
88 ISysInfo ,
9- IFileSystem ,
109 IFutureDispatcher ,
1110 IQueue ,
1211 IErrors ,
1312} from "./declarations" ;
14- import { IOptions } from "../declarations" ;
13+ import { IOptions , IPackageManager , IVersionsService } from "../declarations" ;
1514import { IInjector } from "./definitions/yok" ;
1615import { injector } from "./yok" ;
16+ import { PackageManagers } from "../constants" ;
1717
1818export class CommandDispatcher implements ICommandDispatcher {
1919 constructor (
@@ -25,7 +25,9 @@ export class CommandDispatcher implements ICommandDispatcher {
2525 private $staticConfig : Config . IStaticConfig ,
2626 private $sysInfo : ISysInfo ,
2727 private $options : IOptions ,
28- private $fs : IFileSystem
28+ private $versionsService : IVersionsService ,
29+ private $packageManager : IPackageManager ,
30+ private $terminalSpinnerService : ITerminalSpinnerService
2931 ) { }
3032
3133 public async dispatchCommand ( ) : Promise < void > {
@@ -99,14 +101,39 @@ export class CommandDispatcher implements ICommandDispatcher {
99101 return "" ;
100102 }
101103
102- private printVersion ( ) : void {
103- let version = this . $staticConfig . version ;
104-
105- const json = this . $fs . readJson ( this . $staticConfig . pathToPackageJson ) ;
106- if ( json && json . buildVersion ) {
107- version = `${ version } -${ json . buildVersion } ` ;
104+ private async printVersion ( ) : Promise < void > {
105+ this . $logger . info ( this . $staticConfig . version ) ;
106+
107+ const spinner = this . $terminalSpinnerService . createSpinner ( ) ;
108+ spinner . start ( "Checking for updates..." ) ;
109+ const nativescriptCliVersion = await this . $versionsService . getNativescriptCliVersion ( ) ;
110+ spinner . stop ( ) ;
111+
112+ const packageManagerName = await this . $packageManager . getPackageManagerName ( ) ;
113+ let updateCommand = "" ;
114+
115+ switch ( packageManagerName ) {
116+ case PackageManagers . npm :
117+ updateCommand = "npm i -g nativescript" ;
118+ break ;
119+ case PackageManagers . yarn :
120+ updateCommand = "yarn global add nativescript" ;
121+ break ;
122+ case PackageManagers . pnpm :
123+ updateCommand = "pnpm i -g nativescript" ;
124+ break ;
125+ }
126+ if (
127+ nativescriptCliVersion . currentVersion ===
128+ nativescriptCliVersion . latestVersion
129+ ) {
130+ // up-to-date
131+ spinner . succeed ( "Up to date." ) ;
132+ } else {
133+ spinner . info (
134+ `New version of NativeScript CLI is available (${ nativescriptCliVersion . latestVersion } ), run '${ updateCommand } ' to update.`
135+ ) ;
108136 }
109- this . $logger . info ( version ) ;
110137 }
111138}
112139injector . register ( "commandDispatcher" , CommandDispatcher ) ;
0 commit comments