microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.0.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/simulatorPlist.ts

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