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 · modeblame

488f1908Jimmy Thomson10 years ago1// 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
a4a7e387Meena Kunnathur Balakrishnan10 years ago7import {ErrorHelper} from "../../common/error/errorHelper";
bc7a32ceJimmy Thomson10 years ago8import {PlistBuddy} from "./plistBuddy";
190e393cMeena Kunnathur Balakrishnan10 years ago9import {Log} from "../../common/log/log";
db80cd4eJimmy Thomson10 years ago10import {FileSystem} from "../../common/node/fileSystem";
11import {ChildProcess} from "../../common/node/childProcess";
488f1908Jimmy Thomson10 years ago12
24c4c0aaJimmy Thomson10 years ago13import {TelemetryHelper} from "../../common/telemetryHelper";
14
488f1908Jimmy Thomson10 years ago15export class SimulatorPlist {
16private projectRoot: string;
17
db80cd4eJimmy Thomson10 years ago18private nodeFileSystem: FileSystem;
19private plistBuddy: PlistBuddy;
20private nodeChildProcess: ChildProcess;
21
22constructor(projectRoot: string, {
23nodeFileSystem = new FileSystem(),
24plistBuddy = new PlistBuddy(),
25nodeChildProcess = new ChildProcess()
26} = {}) {
488f1908Jimmy Thomson10 years ago27this.projectRoot = projectRoot;
db80cd4eJimmy Thomson10 years ago28
29this.nodeFileSystem = nodeFileSystem;
30this.plistBuddy = plistBuddy;
31this.nodeChildProcess = nodeChildProcess;
488f1908Jimmy Thomson10 years ago32}
33
34public findPlistFile(): Q.Promise<string> {
35
36return Q.all<any>([
db80cd4eJimmy Thomson10 years ago37this.plistBuddy.getBundleId(this.projectRoot), // Find the name of the application
38this.nodeChildProcess.exec("xcrun simctl getenv booted HOME").outcome]) // Find the path of the simulator we are running
b031edc7digeff10 years ago39.spread((bundleId: string, pathBuffer: Buffer) => {
40const pathBefore = path.join(pathBuffer.toString().trim(), "Containers", "Data", "Application");
41const pathAfter = path.join("Library", "Preferences", `${bundleId}.plist`);
42
43// Look through $SIMULATOR_HOME/Containers/Data/Application/*/Library/Preferences to find $BUNDLEID.plist
db80cd4eJimmy Thomson10 years ago44return this.nodeFileSystem.readDir(pathBefore).then((apps: string[]) => {
45const plistCandidates = apps.map((app: string) => path.join(pathBefore, app, pathAfter)).filter(this.nodeFileSystem.existsSync);
b031edc7digeff10 years ago46if (plistCandidates.length === 0) {
47throw new Error(`Unable to find plist file for ${bundleId}`);
48} else if (plistCandidates.length > 1) {
a6db1e9bJimmy Thomson10 years ago49TelemetryHelper.sendSimpleEvent("multipleDebugPlistFound");
a4a7e387Meena Kunnathur Balakrishnan10 years ago50Log.logWarning(ErrorHelper.getWarning("Multiple plist candidates found. Application may not be in debug mode."));
b031edc7digeff10 years ago51}
52
53return plistCandidates[0];
54});
ee21460bJimmy Thomson10 years ago55});
56}
488f1908Jimmy Thomson10 years ago57}