@@ -6,14 +6,14 @@ import {
6
6
ICommandDispatcher ,
7
7
ICancellationService ,
8
8
ISysInfo ,
9
- IFileSystem ,
10
9
IFutureDispatcher ,
11
10
IQueue ,
12
11
IErrors ,
13
12
} from "./declarations" ;
14
- import { IOptions } from "../declarations" ;
13
+ import { IOptions , IPackageManager , IVersionsService } from "../declarations" ;
15
14
import { IInjector } from "./definitions/yok" ;
16
15
import { injector } from "./yok" ;
16
+ import { PackageManagers } from "../constants" ;
17
17
18
18
export class CommandDispatcher implements ICommandDispatcher {
19
19
constructor (
@@ -25,7 +25,9 @@ export class CommandDispatcher implements ICommandDispatcher {
25
25
private $staticConfig : Config . IStaticConfig ,
26
26
private $sysInfo : ISysInfo ,
27
27
private $options : IOptions ,
28
- private $fs : IFileSystem
28
+ private $versionsService : IVersionsService ,
29
+ private $packageManager : IPackageManager ,
30
+ private $terminalSpinnerService : ITerminalSpinnerService
29
31
) { }
30
32
31
33
public async dispatchCommand ( ) : Promise < void > {
@@ -99,14 +101,39 @@ export class CommandDispatcher implements ICommandDispatcher {
99
101
return "" ;
100
102
}
101
103
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
+ ) ;
108
136
}
109
- this . $logger . info ( version ) ;
110
137
}
111
138
}
112
139
injector . register ( "commandDispatcher" , CommandDispatcher ) ;
0 commit comments