-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathiTunes-validator.ts
100 lines (89 loc) · 3.19 KB
/
iTunes-validator.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import * as path from "path";
import { IFileSystem, IHostInfo } from "../declarations";
import { injector } from "../yok";
export class ITunesValidator implements Mobile.IiTunesValidator {
private static NOT_INSTALLED_iTUNES_ERROR_MESSAGE =
"iTunes is not installed. Install it on your system and run this command again.";
private static BITNESS_MISMATCH_ERROR_MESSAGE =
"The bitness of Node.js and iTunes must match. Verify that both Node.js and iTunes are 32-bit or 64-bit and try again.";
private static UNSUPPORTED_OS_ERROR_MESSAGE =
"iTunes is not available for this operating system. You will not be able to work with connected iOS devices.";
constructor(private $fs: IFileSystem, private $hostInfo: IHostInfo) {}
public getError(): string {
if (this.$hostInfo.isWindows) {
let commonProgramFiles = "";
const isNode64 = process.arch === "x64";
if (isNode64) {
//x64-windows
commonProgramFiles = process.env.CommonProgramFiles;
if (
this.isiTunesInstalledOnWindows(
process.env["CommonProgramFiles(x86)"]
) &&
!this.isiTunesInstalledOnWindows(commonProgramFiles)
) {
return ITunesValidator.BITNESS_MISMATCH_ERROR_MESSAGE;
}
} else {
if (this.$hostInfo.isWindows32) {
// x86-node, x86-windows
commonProgramFiles = process.env.CommonProgramFiles;
} else {
// x86-node, x64-windows
// check for x64-iTunes
commonProgramFiles = process.env["CommonProgramFiles(x86)"];
if (
this.isiTunesInstalledOnWindows(process.env.CommonProgramFiles) &&
!this.isiTunesInstalledOnWindows(commonProgramFiles)
) {
return ITunesValidator.BITNESS_MISMATCH_ERROR_MESSAGE;
}
}
}
if (!this.isiTunesInstalledOnWindows(commonProgramFiles)) {
return ITunesValidator.NOT_INSTALLED_iTUNES_ERROR_MESSAGE;
}
return null;
} else if (this.$hostInfo.isDarwin) {
// Commented out check to get macOS Big Sur working
// by the looks of it - iTunes is no longer used by the CLI
// so we likely want to remove any legacy code related to it
// this is currently in progress
// TODO: remove this comment when no longer relevant.
return null;
// const coreFoundationDir =
// "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation";
// const mobileDeviceDir =
// "/System/Library/PrivateFrameworks/MobileDevice.framework/MobileDevice";
//
// if (!this.isiTunesInstalledCore(coreFoundationDir, mobileDeviceDir)) {
// return ITunesValidator.NOT_INSTALLED_iTUNES_ERROR_MESSAGE;
// }
//
// return null;
}
return ITunesValidator.UNSUPPORTED_OS_ERROR_MESSAGE;
}
private isiTunesInstalledOnWindows(commonProgramFiles: string): boolean {
const coreFoundationDir = path.join(
commonProgramFiles,
"Apple",
"Apple Application Support"
);
const mobileDeviceDir = path.join(
commonProgramFiles,
"Apple",
"Mobile Device Support"
);
return this.isiTunesInstalledCore(coreFoundationDir, mobileDeviceDir);
}
private isiTunesInstalledCore(
coreFoundationDir: string,
mobileDeviceDir: string
): boolean {
return (
this.$fs.exists(coreFoundationDir) && this.$fs.exists(mobileDeviceDir)
);
}
}
injector.register("iTunesValidator", ITunesValidator);