2
2
"use strict" ;
3
3
import * as constants from "../constants" ;
4
4
import * as semver from "semver" ;
5
+ import * as path from "path" ;
5
6
import { createTable } from "../common/helpers" ;
6
7
7
8
class VersionsService implements IVersionsService {
9
+ private static UP_TO_DATE_MESSAGE = "Up to date" . green . toString ( ) ;
10
+ private static UPDATE_AVAILABLE_MESSAGE = "Update available" . yellow . toString ( ) ;
11
+ private static NOT_INSTALLED_MESSAGE = "Not installed" . grey . toString ( ) ;
12
+
8
13
private projectData : IProjectData ;
9
14
10
15
constructor ( private $fs : IFileSystem ,
11
16
private $npmInstallationManager : INpmInstallationManager ,
12
17
private $injector : IInjector ,
13
- private $staticConfig : Config . IStaticConfig ) {
18
+ private $staticConfig : Config . IStaticConfig ,
19
+ private $pluginsService : IPluginsService ) {
14
20
this . projectData = this . getProjectData ( ) ;
15
21
}
16
22
@@ -36,7 +42,14 @@ class VersionsService implements IVersionsService {
36
42
} ;
37
43
38
44
if ( this . projectData ) {
39
- let currentTnsCoreModulesVersion = this . projectData . dependencies [ constants . TNS_CORE_MODULES_NAME ] ;
45
+ let nodeModulesPath = path . join ( this . projectData . projectDir , constants . NODE_MODULES_FOLDER_NAME ) ;
46
+ let tnsCoreModulesPath = path . join ( nodeModulesPath , constants . TNS_CORE_MODULES_NAME ) ;
47
+ if ( ! this . $fs . exists ( nodeModulesPath ) . wait ( ) ||
48
+ ! this . $fs . exists ( tnsCoreModulesPath ) . wait ( ) ) {
49
+ this . $pluginsService . ensureAllDependenciesAreInstalled ( ) . wait ( ) ;
50
+ }
51
+
52
+ let currentTnsCoreModulesVersion = this . $fs . readJson ( path . join ( tnsCoreModulesPath , constants . PACKAGE_JSON_FILE_NAME ) ) . wait ( ) . version ;
40
53
nativescriptCoreModulesInfo . currentVersion = currentTnsCoreModulesVersion ;
41
54
}
42
55
@@ -119,19 +132,18 @@ class VersionsService implements IVersionsService {
119
132
public createTableWithVersionsInformation ( versionsInformation : IVersionInformation [ ] ) : any {
120
133
let headers = [ "Component" , "Current version" , "Latest version" , "Information" ] ;
121
134
let data : string [ ] [ ] = [ ] ;
122
- let upToDate : string = "Up to date" . green . toString ( ) ;
123
135
124
136
_ . forEach ( versionsInformation , ( componentInformation : IVersionInformation ) => {
125
137
let row : string [ ] = [
126
138
componentInformation . componentName ,
127
- componentInformation . currentVersion || "" ,
139
+ componentInformation . currentVersion ,
128
140
componentInformation . latestVersion
129
141
] ;
130
142
131
- if ( componentInformation . currentVersion && semver . lt ( componentInformation . currentVersion , componentInformation . latestVersion ) ) {
132
- row . push ( "Update available" . yellow . toString ( ) ) ;
143
+ if ( componentInformation . currentVersion ) {
144
+ semver . lt ( componentInformation . currentVersion , componentInformation . latestVersion ) ? row . push ( VersionsService . UPDATE_AVAILABLE_MESSAGE ) : row . push ( VersionsService . UP_TO_DATE_MESSAGE ) ;
133
145
} else {
134
- row . push ( upToDate ) ;
146
+ row . push ( VersionsService . NOT_INSTALLED_MESSAGE ) ;
135
147
}
136
148
137
149
data . push ( row ) ;
0 commit comments