microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.3

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/ios/simulatorPlist.ts

60lines · 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";
5edb6e49Digeff10 years ago10import {LogLevel} from "../../common/log/logHelper";
db80cd4eJimmy Thomson10 years ago11import {FileSystem} from "../../common/node/fileSystem";
12import {ChildProcess} from "../../common/node/childProcess";
488f1908Jimmy Thomson10 years ago13
24c4c0aaJimmy Thomson10 years ago14import {TelemetryHelper} from "../../common/telemetryHelper";
15
488f1908Jimmy Thomson10 years ago16export class SimulatorPlist {
17private projectRoot: string;
18
db80cd4eJimmy Thomson10 years ago19private nodeFileSystem: FileSystem;
20private plistBuddy: PlistBuddy;
21private nodeChildProcess: ChildProcess;
22
23constructor(projectRoot: string, {
24nodeFileSystem = new FileSystem(),
25plistBuddy = new PlistBuddy(),
cdf34447digeff10 years ago26nodeChildProcess = new ChildProcess(),
db80cd4eJimmy Thomson10 years ago27} = {}) {
488f1908Jimmy Thomson10 years ago28this.projectRoot = projectRoot;
db80cd4eJimmy Thomson10 years ago29
30this.nodeFileSystem = nodeFileSystem;
31this.plistBuddy = plistBuddy;
32this.nodeChildProcess = nodeChildProcess;
488f1908Jimmy Thomson10 years ago33}
34
35public findPlistFile(): Q.Promise<string> {
36
37return Q.all<any>([
db80cd4eJimmy Thomson10 years ago38this.plistBuddy.getBundleId(this.projectRoot), // Find the name of the application
cdf34447digeff10 years ago39this.nodeChildProcess.exec("xcrun simctl getenv booted HOME").outcome, // Find the path of the simulator we are running
40]).spread((bundleId: string, pathBuffer: Buffer) => {
b031edc7digeff10 years ago41const pathBefore = path.join(pathBuffer.toString().trim(), "Containers", "Data", "Application");
42const pathAfter = path.join("Library", "Preferences", `${bundleId}.plist`);
43
44// Look through $SIMULATOR_HOME/Containers/Data/Application/*/Library/Preferences to find $BUNDLEID.plist
db80cd4eJimmy Thomson10 years ago45return this.nodeFileSystem.readDir(pathBefore).then((apps: string[]) => {
5edb6e49Digeff10 years ago46Log.logInternalMessage(LogLevel.Info, `About to search for plist in base folder: ${pathBefore} pathAfter: ${pathAfter} in each of the apps: ${apps}`);
47const plistCandidates = apps.map((app: string) => path.join(pathBefore, app, pathAfter)).filter(filePath =>
48this.nodeFileSystem.existsSync(filePath));
b031edc7digeff10 years ago49if (plistCandidates.length === 0) {
50throw new Error(`Unable to find plist file for ${bundleId}`);
51} else if (plistCandidates.length > 1) {
a6db1e9bJimmy Thomson10 years ago52TelemetryHelper.sendSimpleEvent("multipleDebugPlistFound");
a4a7e387Meena Kunnathur Balakrishnan10 years ago53Log.logWarning(ErrorHelper.getWarning("Multiple plist candidates found. Application may not be in debug mode."));
b031edc7digeff10 years ago54}
55
56return plistCandidates[0];
57});
ee21460bJimmy Thomson10 years ago58});
59}
488f1908Jimmy Thomson10 years ago60}