microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.6.9

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/ios/simulatorPlist.ts

60lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as path from "path";
5import * as Q from "q";
6
7import {ErrorHelper} from "../../common/error/errorHelper";
8import {PlistBuddy} from "./plistBuddy";
9import {OutputChannelLogger} from "../log/OutputChannelLogger";
10import {FileSystem} from "../../common/node/fileSystem";
11import {ChildProcess} from "../../common/node/childProcess";
12
13import {TelemetryHelper} from "../../common/telemetryHelper";
14
15export class SimulatorPlist {
16 private projectRoot: string;
17 private logger: OutputChannelLogger = OutputChannelLogger.getMainChannel();
18
19 private nodeFileSystem: FileSystem;
20 private plistBuddy: PlistBuddy;
21 private nodeChildProcess: ChildProcess;
22
23 constructor(projectRoot: string, {
24 nodeFileSystem = new FileSystem(),
25 plistBuddy = new PlistBuddy(),
26 nodeChildProcess = new ChildProcess(),
27 } = {}) {
28 this.projectRoot = projectRoot;
29
30 this.nodeFileSystem = nodeFileSystem;
31 this.plistBuddy = plistBuddy;
32 this.nodeChildProcess = nodeChildProcess;
33 }
34
35 public findPlistFile(): Q.Promise<string> {
36
37 return Q.all<any>([
38 this.plistBuddy.getBundleId(this.projectRoot), // Find the name of the application
39 this.nodeChildProcess.exec("xcrun simctl getenv booted HOME").outcome, // Find the path of the simulator we are running
40 ]).spread((bundleId: string, pathBuffer: Buffer) => {
41 const pathBefore = path.join(pathBuffer.toString().trim(), "Containers", "Data", "Application");
42 const pathAfter = path.join("Library", "Preferences", `${bundleId}.plist`);
43
44 // Look through $SIMULATOR_HOME/Containers/Data/Application/*/Library/Preferences to find $BUNDLEID.plist
45 return this.nodeFileSystem.readDir(pathBefore).then((apps: string[]) => {
46 this.logger.info(`About to search for plist in base folder: ${pathBefore} pathAfter: ${pathAfter} in each of the apps: ${apps}`);
47 const plistCandidates = apps.map((app: string) => path.join(pathBefore, app, pathAfter)).filter(filePath =>
48 this.nodeFileSystem.existsSync(filePath));
49 if (plistCandidates.length === 0) {
50 throw new Error(`Unable to find plist file for ${bundleId}`);
51 } else if (plistCandidates.length > 1) {
52 TelemetryHelper.sendSimpleEvent("multipleDebugPlistFound");
53 this.logger.warning(ErrorHelper.getWarning("Multiple plist candidates found. Application may not be in debug mode."));
54 }
55
56 return plistCandidates[0];
57 });
58 });
59 }
60}
61