microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.5.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/simulatorPlist.ts

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