microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/ios/simulatorPlist.ts

45lines · 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 fs from "fs";
5import * as path from "path";
6import * as Q from "q";
7
8import {PlistBuddy} from "./plistBuddy";
9import {Node} from "../../common/node/node";
10import {Log} from "../../common/log";
11
12import {TelemetryHelper} from "../../common/telemetryHelper";
13
14export class SimulatorPlist {
15 private projectRoot: string;
16
17 constructor(projectRoot: string) {
18 this.projectRoot = projectRoot;
19 }
20
21 public findPlistFile(): Q.Promise<string> {
22
23 return Q.all<any>([
24 new PlistBuddy().getBundleId(this.projectRoot), // Find the name of the application
25 new Node.ChildProcess().exec("xcrun simctl getenv booted HOME").outcome]) // Find the path of the simulator we are running
26 .spread((bundleId: string, pathBuffer: Buffer) => {
27 const pathBefore = path.join(pathBuffer.toString().trim(), "Containers", "Data", "Application");
28 const pathAfter = path.join("Library", "Preferences", `${bundleId}.plist`);
29
30 // Look through $SIMULATOR_HOME/Containers/Data/Application/*/Library/Preferences to find $BUNDLEID.plist
31 return Q.nfcall(fs.readdir, pathBefore).then((apps: string[]) => {
32 const mockableFS = new Node.FileSystem();
33 const plistCandidates = apps.map((app: string) => path.join(pathBefore, app, pathAfter)).filter(mockableFS.existsSync);
34 if (plistCandidates.length === 0) {
35 throw new Error(`Unable to find plist file for ${bundleId}`);
36 } else if (plistCandidates.length > 1) {
37 TelemetryHelper.sendSimpleEvent("multipleDebugPlistFound");
38 Log.logMessage("Warning: Multiple plist candidates found. Application may not be in debug mode");
39 }
40
41 return plistCandidates[0];
42 });
43 });
44 }
45}