microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev/v-peq/removeNode10TodoComments

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 * as nls from "vscode-nls";
6import { ErrorHelper } from "../../common/error/errorHelper";
7import { OutputChannelLogger } from "../log/OutputChannelLogger";
8import { FileSystem } from "../../common/node/fileSystem";
9import { ChildProcess } from "../../common/node/childProcess";
10import { TelemetryHelper } from "../../common/telemetryHelper";
11import { PlatformType } from "../launchArgs";
12import { PlistBuddy } from "./plistBuddy";
13
14nls.config({
15 messageFormat: nls.MessageFormat.bundle,
16 bundleFormat: nls.BundleFormat.standalone,
17})();
18const localize = nls.loadMessageBundle();
19
20export class SimulatorPlist {
21 private iosProjectRoot: string;
22 private projectRoot: string;
23 private scheme?: string;
24 private logger: OutputChannelLogger = OutputChannelLogger.getMainChannel();
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 = undefined,
36 nodeChildProcess = new ChildProcess(),
37 } = {},
38 ) {
39 this.iosProjectRoot = iosProjectRoot;
40 this.projectRoot = projectRoot;
41 this.scheme = scheme;
42 this.nodeFileSystem = nodeFileSystem;
43 this.plistBuddy = plistBuddy || new PlistBuddy();
44 this.nodeChildProcess = nodeChildProcess;
45 }
46
47 public async findPlistFile(configuration?: string, productName?: string): Promise<string> {
48 const [bundleId, pathBuffer] = await Promise.all([
49 this.plistBuddy.getBundleId(
50 this.iosProjectRoot,
51 this.projectRoot,
52 PlatformType.iOS,
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 ]);
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 // Look through $SIMULATOR_HOME/Containers/Data/Application/*/Library/Preferences to find $BUNDLEID.plist
68 const apps = await this.nodeFileSystem.readDir(pathBefore);
69 this.logger.info(
70 `About to search for plist in base folder: ${pathBefore} pathAfter: ${pathAfter} in each of the apps: ${String(
71 apps,
72 )}`,
73 );
74 const plistCandidates = apps
75 .map((app: string) => path.join(pathBefore, app, pathAfter))
76 .filter(filePath => this.nodeFileSystem.existsSync(filePath));
77 if (plistCandidates.length === 0) {
78 throw new Error(`Unable to find plist file for ${bundleId}`);
79 } else if (plistCandidates.length > 1) {
80 TelemetryHelper.sendSimpleEvent("multipleDebugPlistFound");
81 this.logger.warning(
82 ErrorHelper.getWarning(
83 localize(
84 "MultiplePlistCandidatesFoundAppMayNotBeDebuggedInDebugMode",
85 "Multiple plist candidates found. Application may not be in debug mode.",
86 ),
87 ),
88 );
89 }
90 return plistCandidates[0];
91 }
92}