microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
f8d3243916133136da9c1d8eedef7428db609d7d

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/ios/simulatorPlist.ts

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