-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathxcode-select-service.ts
44 lines (34 loc) · 1.34 KB
/
xcode-select-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as path from "path";
import { cache } from "../decorators";
export class XcodeSelectService implements IXcodeSelectService {
constructor(private $childProcess: IChildProcess,
private $errors: IErrors,
private $hostInfo: IHostInfo,
private $injector: IInjector) {
}
public async getDeveloperDirectoryPath(): Promise<string> {
if (!this.$hostInfo.isDarwin) {
this.$errors.fail("xcode-select is only available on Mac OS X.");
}
const childProcess = await this.$childProcess.spawnFromEvent("xcode-select", ["-print-path"], "close", {}, { throwError: false }),
result = childProcess.stdout.trim();
if (!result) {
this.$errors.fail("Cannot find path to Xcode.app - make sure you've installed Xcode correctly.");
}
return result;
}
public async getContentsDirectoryPath(): Promise<string> {
return path.join(await this.getDeveloperDirectoryPath(), "..");
}
@cache()
public async getXcodeVersion(): Promise<IVersionData> {
const sysInfo = this.$injector.resolve<ISysInfo>("sysInfo");
const xcodeVer = await sysInfo.getXcodeVersion();
if (!xcodeVer) {
this.$errors.fail("xcodebuild execution failed. Make sure that you have latest Xcode and tools installed.");
}
const [ major, minor, patch ] = xcodeVer.split(".");
return { major, minor, patch };
}
}
$injector.register("xcodeSelectService", XcodeSelectService);