microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.13.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/simulatorPlist.ts

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