Skip to content

Commit fc93e0c

Browse files
Fix get current tns-core-modules version
When getting the current version of the tns-core-modules the version in project's package.json can be ^<version> or * so the version in the package.json of the installed tns-core-modules is the correct version.
1 parent 2957ed1 commit fc93e0c

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lib/services/versions-service.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22
"use strict";
33
import * as constants from "../constants";
44
import * as semver from "semver";
5+
import * as path from "path";
56
import {createTable} from "../common/helpers";
67

78
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+
813
private projectData: IProjectData;
914

1015
constructor(private $fs: IFileSystem,
1116
private $npmInstallationManager: INpmInstallationManager,
1217
private $injector: IInjector,
13-
private $staticConfig: Config.IStaticConfig) {
18+
private $staticConfig: Config.IStaticConfig,
19+
private $pluginsService: IPluginsService) {
1420
this.projectData = this.getProjectData();
1521
}
1622

@@ -36,7 +42,14 @@ class VersionsService implements IVersionsService {
3642
};
3743

3844
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;
4053
nativescriptCoreModulesInfo.currentVersion = currentTnsCoreModulesVersion;
4154
}
4255

@@ -119,19 +132,18 @@ class VersionsService implements IVersionsService {
119132
public createTableWithVersionsInformation(versionsInformation: IVersionInformation[]): any {
120133
let headers = ["Component", "Current version", "Latest version", "Information"];
121134
let data: string[][] = [];
122-
let upToDate: string = "Up to date".green.toString();
123135

124136
_.forEach(versionsInformation, (componentInformation: IVersionInformation) => {
125137
let row: string[] = [
126138
componentInformation.componentName,
127-
componentInformation.currentVersion || "",
139+
componentInformation.currentVersion,
128140
componentInformation.latestVersion
129141
];
130142

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);
133145
} else {
134-
row.push(upToDate);
146+
row.push(VersionsService.NOT_INSTALLED_MESSAGE);
135147
}
136148

137149
data.push(row);

0 commit comments

Comments
 (0)