Skip to content

Commit 5143ee8

Browse files
brcristaDanny McCormick
authored andcommitted
Add getPlatform function (microsoft#374)
* Add `getPlatform` function * Clean up
1 parent f46409f commit 5143ee8

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

node/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
"loc.messages.LIB_PathHasNullByte": "Path cannot contain null bytes",
3030
"loc.messages.LIB_OperationFailed": "Failed %s: %s",
3131
"loc.messages.LIB_UseFirstGlobMatch": "Multiple workspace matches. using first.",
32-
"loc.messages.LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS."
32+
"loc.messages.LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.",
33+
"loc.messages.LIB_PlatformNotSupported": "Platform not supported: %s"
3334
}

node/lib.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"LIB_PathHasNullByte": "Path cannot contain null bytes",
3131
"LIB_OperationFailed": "Failed %s: %s",
3232
"LIB_UseFirstGlobMatch": "Multiple workspace matches. using first.",
33-
"LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS."
33+
"LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.",
34+
"LIB_PlatformNotSupported": "Platform not supported: %s"
3435
}
3536
}

node/task.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import fs = require('fs');
44
import path = require('path');
55
import os = require('os');
66
import minimatch = require('minimatch');
7-
import util = require('util');
87
import im = require('./internal');
98
import tcm = require('./taskcommand');
109
import trm = require('./toolrunner');
11-
import vm = require('./vault');
1210
import semver = require('semver');
1311

1412
export enum TaskResult {
@@ -45,6 +43,13 @@ export enum FieldType {
4543
Url
4644
}
4745

46+
/** Platforms supported by our build agent */
47+
export enum Platform {
48+
Windows,
49+
MacOS,
50+
Linux
51+
}
52+
4853
//-----------------------------------------------------
4954
// General Helpers
5055
//-----------------------------------------------------
@@ -563,6 +568,7 @@ export function writeFile(file: string, data: string | Buffer, options?: string
563568
}
564569

565570
/**
571+
* @deprecated Use `getPlatform`
566572
* Useful for determining the host operating system.
567573
* see [os.type](https://nodejs.org/api/os.html#os_os_type)
568574
*
@@ -572,6 +578,20 @@ export function osType(): string {
572578
return os.type();
573579
}
574580

581+
/**
582+
* Determine the operating system the build agent is running on.
583+
* @returns {Platform}
584+
* @throws {Error} Platform is not supported by our agent
585+
*/
586+
export function getPlatform(): Platform {
587+
switch (process.platform) {
588+
case 'win32': return Platform.Windows;
589+
case 'darwin': return Platform.MacOS;
590+
case 'linux': return Platform.Linux;
591+
default: throw Error(loc('LIB_PlatformNotSupported', process.platform));
592+
}
593+
}
594+
575595
/**
576596
* Returns the process's current working directory.
577597
* see [process.cwd](https://nodejs.org/api/process.html#process_process_cwd)

0 commit comments

Comments
 (0)