microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/ios/simulatorPlist.ts

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