microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.4.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/simulatorPlist.ts

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