microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
ff70c05a6c821e99785e3f91dca1daf27094e4fd

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/simulatorPlist.ts

67lines · 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 {OutputChannelLogger} from "../log/OutputChannelLogger";
10import {FileSystem} from "../../common/node/fileSystem";
11import {ChildProcess} from "../../common/node/childProcess";
12
13import {TelemetryHelper} from "../../common/telemetryHelper";
14import * as nls from "vscode-nls";
15nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
16const localize = nls.loadMessageBundle();
17
18export class SimulatorPlist {
19 private projectRoot: string;
20 private iosProjectRoot: string;
21 private scheme?: string;
22 private logger: OutputChannelLogger = OutputChannelLogger.getMainChannel();
23
24 private nodeFileSystem: FileSystem;
25 private plistBuddy: PlistBuddy;
26 private nodeChildProcess: ChildProcess;
27
28 constructor(iosProjectRoot: string, projectRoot: string, scheme?: string, {
29 nodeFileSystem = new FileSystem(),
30 plistBuddy = new PlistBuddy(),
31 nodeChildProcess = new ChildProcess(),
32 } = {}) {
33 this.projectRoot = projectRoot;
34 this.iosProjectRoot = iosProjectRoot;
35
36 this.nodeFileSystem = nodeFileSystem;
37 this.plistBuddy = plistBuddy;
38 this.nodeChildProcess = nodeChildProcess;
39 this.scheme = scheme;
40 }
41
42 public findPlistFile(configuration?: string, productName?: string): Q.Promise<string> {
43
44 return Q.all<any>([
45 this.plistBuddy.getBundleId(this.iosProjectRoot, this.projectRoot, true, configuration, productName, this.scheme), // Find the name of the application
46 this.nodeChildProcess.exec("xcrun simctl getenv booted HOME").outcome, // Find the path of the simulator we are running
47 ]).spread((bundleId: string, pathBuffer: Buffer) => {
48 const pathBefore = path.join(pathBuffer.toString().trim(), "Containers", "Data", "Application");
49 const pathAfter = path.join("Library", "Preferences", `${bundleId}.plist`);
50
51 // Look through $SIMULATOR_HOME/Containers/Data/Application/*/Library/Preferences to find $BUNDLEID.plist
52 return this.nodeFileSystem.readDir(pathBefore).then((apps: string[]) => {
53 this.logger.info(`About to search for plist in base folder: ${pathBefore} pathAfter: ${pathAfter} in each of the apps: ${apps}`);
54 const plistCandidates = apps.map((app: string) => path.join(pathBefore, app, pathAfter)).filter(filePath =>
55 this.nodeFileSystem.existsSync(filePath));
56 if (plistCandidates.length === 0) {
57 throw new Error(`Unable to find plist file for ${bundleId}`);
58 } else if (plistCandidates.length > 1) {
59 TelemetryHelper.sendSimpleEvent("multipleDebugPlistFound");
60 this.logger.warning(ErrorHelper.getWarning(localize("MultiplePlistCandidatesFoundAppMayNotBeDebuggedInDebugMode", "Multiple plist candidates found. Application may not be in debug mode.")));
61 }
62
63 return plistCandidates[0];
64 });
65 });
66 }
67}
68