Skip to content

Commit 275cac4

Browse files
Add get NativeScript CLI version method to the public API
1 parent 55cbe20 commit 275cac4

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

lib/sys-info.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class SysInfo {
3838
private gradleVerCache: string;
3939
private sysInfoCache: ISysInfoData;
4040
private isCocoaPodsWorkingCorrectlyCache: boolean = null;
41+
private nativeScriptCliVersion: string;
4142

4243
constructor(private childProcess: ChildProcess,
4344
private fileSystem: FileSystem,
@@ -252,6 +253,7 @@ export class SysInfo {
252253
result.gitVer = await this.getGitVersion();
253254
result.gradleVer = await this.getGradleVersion();
254255
result.isCocoaPodsWorkingCorrectly = await this.isCocoaPodsWorkingCorrectly();
256+
result.nativeScriptCliVersion = await this.getNativeScriptCliVersion();
255257

256258
this.sysInfoCache = result;
257259
}
@@ -284,6 +286,15 @@ export class SysInfo {
284286
return !!this.isCocoaPodsWorkingCorrectlyCache;
285287
}
286288

289+
public async getNativeScriptCliVersion(): Promise<string> {
290+
if (!this.nativeScriptCliVersion) {
291+
const output = await this.execCommand("tns --version");
292+
this.nativeScriptCliVersion = output.trim();
293+
}
294+
295+
return this.nativeScriptCliVersion;
296+
}
297+
287298
private async exec(cmd: string, execOptions?: ExecOptions): Promise<IProcessInfo> {
288299
if (cmd) {
289300
try {

test/sys-info.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ interface IChildProcessResults {
2626
gitVersion: IChildProcessResultDescription;
2727
podVersion: IChildProcessResultDescription;
2828
pod: IChildProcessResultDescription;
29+
nativeScriptCliVersion: IChildProcessResultDescription;
2930
}
3031

3132
interface IHostInfoMockOptions {
@@ -54,7 +55,8 @@ function createChildProcessResults(childProcessResult: IChildProcessResults): ID
5455
'android.bat': childProcessResult.androidInstalled, // for Windows
5556
"mono --version": childProcessResult.monoVersion,
5657
"git --version": childProcessResult.gitVersion,
57-
"gradle -v": childProcessResult.gradleVersion
58+
"gradle -v": childProcessResult.gradleVersion,
59+
"tns --version": childProcessResult.nativeScriptCliVersion
5860
};
5961
}
6062

@@ -182,7 +184,8 @@ describe("SysInfo unit tests", () => {
182184
gradleVersion: { result: setStdOut("Gradle 2.8") },
183185
gitVersion: { result: setStdOut("git version 1.9.5") },
184186
podVersion: { result: setStdOut("0.38.2") },
185-
pod: { result: setStdOut("success") }
187+
pod: { result: setStdOut("success") },
188+
nativeScriptCliVersion: { result: setStdOut("2.5.0") }
186189
};
187190

188191
delete process.env[JavaHomeName];
@@ -205,6 +208,7 @@ describe("SysInfo unit tests", () => {
205208
assert.deepEqual(result.monoVer, "1.0.6");
206209
assert.deepEqual(result.gradleVer, "2.8");
207210
assert.deepEqual(result.gitVer, "1.9.5");
211+
assert.deepEqual(result.nativeScriptCliVersion, childProcessResult.nativeScriptCliVersion.result.stdout);
208212
};
209213

210214
it("on Windows", async () => {
@@ -277,7 +281,8 @@ describe("SysInfo unit tests", () => {
277281
gradleVersion: { shouldThrowError: true },
278282
gitVersion: { shouldThrowError: true },
279283
podVersion: { shouldThrowError: true },
280-
pod: { shouldThrowError: true }
284+
pod: { shouldThrowError: true },
285+
nativeScriptCliVersion: { shouldThrowError: true }
281286
};
282287
});
283288

typings/nativescript-doctor.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ declare module NativeScriptDoctor {
9696
*/
9797
isCocoaPodsWorkingCorrectly(): Promise<boolean>;
9898

99+
/**
100+
* Returns the version of the globally installed NativeScript CLI.
101+
* @return {Promise<string>} Returns the version of the globally installed NativeScript CLI.
102+
*/
103+
getNativeScriptCliVersion(): Promise<string>;
104+
99105
/**
100106
* Returns the whole system information.
101107
* @return {Promise<ISysInfoData>} The system information.
@@ -244,6 +250,12 @@ declare module NativeScriptDoctor {
244250
* @type {boolean}
245251
*/
246252
isCocoaPodsWorkingCorrectly: boolean;
253+
254+
/**
255+
* NativeScript CLI version string, as returned by `tns --version`.
256+
* @type {string}
257+
*/
258+
nativeScriptCliVersion: string;
247259
}
248260

249261
/**

0 commit comments

Comments
 (0)