microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
efbe1ba61ca71887b3fa9a2d1ae3afb9a78cb87e

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/simulatorPlist.ts

62lines · 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";
14import * as nls from "vscode-nls";
15const localize = nls.loadMessageBundle();
16
17export class SimulatorPlist {
18 private projectRoot: string;
19 private logger: OutputChannelLogger = OutputChannelLogger.getMainChannel();
20
21 private nodeFileSystem: FileSystem;
22 private plistBuddy: PlistBuddy;
23 private nodeChildProcess: ChildProcess;
24
25 constructor(projectRoot: string, {
26 nodeFileSystem = new FileSystem(),
27 plistBuddy = new PlistBuddy(),
28 nodeChildProcess = new ChildProcess(),
29 } = {}) {
30 this.projectRoot = projectRoot;
31
32 this.nodeFileSystem = nodeFileSystem;
33 this.plistBuddy = plistBuddy;
34 this.nodeChildProcess = nodeChildProcess;
35 }
36
37 public findPlistFile(configuration?: string, productName?: string): Q.Promise<string> {
38
39 return Q.all<any>([
40 this.plistBuddy.getBundleId(this.projectRoot, true, configuration, productName), // Find the name of the application
41 this.nodeChildProcess.exec("xcrun simctl getenv booted HOME").outcome, // Find the path of the simulator we are running
42 ]).spread((bundleId: string, pathBuffer: Buffer) => {
43 const pathBefore = path.join(pathBuffer.toString().trim(), "Containers", "Data", "Application");
44 const pathAfter = path.join("Library", "Preferences", `${bundleId}.plist`);
45
46 // Look through $SIMULATOR_HOME/Containers/Data/Application/*/Library/Preferences to find $BUNDLEID.plist
47 return this.nodeFileSystem.readDir(pathBefore).then((apps: string[]) => {
48 this.logger.info(`About to search for plist in base folder: ${pathBefore} pathAfter: ${pathAfter} in each of the apps: ${apps}`);
49 const plistCandidates = apps.map((app: string) => path.join(pathBefore, app, pathAfter)).filter(filePath =>
50 this.nodeFileSystem.existsSync(filePath));
51 if (plistCandidates.length === 0) {
52 throw new Error(`Unable to find plist file for ${bundleId}`);
53 } else if (plistCandidates.length > 1) {
54 TelemetryHelper.sendSimpleEvent("multipleDebugPlistFound");
55 this.logger.warning(ErrorHelper.getWarning(localize("MultiplePlistCandidatesFoundAppMayNotBeDebuggedInDebugMode", "Multiple plist candidates found. Application may not be in debug mode.")));
56 }
57
58 return plistCandidates[0];
59 });
60 });
61 }
62}
63