microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
transitive-dependency-serialize-javascript

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/simulatorPlist.ts

92lines · modeblame

0a68f8dbArtem Egorov8 years ago1// 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";
09f6024fHeniker4 years ago5import * as nls from "vscode-nls";
34472878RedMickey5 years ago6import { 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";
1c2424f4RedMickey5 years ago11import { PlatformType } from "../launchArgs";
09f6024fHeniker4 years ago12import { PlistBuddy } from "./plistBuddy";
13
34472878RedMickey5 years ago14nls.config({
15messageFormat: nls.MessageFormat.bundle,
16bundleFormat: nls.BundleFormat.standalone,
17})();
d7d405aeYuri Skorokhodov7 years ago18const localize = nls.loadMessageBundle();
0a68f8dbArtem Egorov8 years ago19
20export class SimulatorPlist {
764655c9Yuri Skorokhodov6 years ago21private iosProjectRoot: string;
4dfb1c4cetatanova5 years ago22private projectRoot: string;
a949e43fRuslan Bikkinin7 years ago23private scheme?: string;
0a68f8dbArtem Egorov8 years ago24private logger: OutputChannelLogger = OutputChannelLogger.getMainChannel();
25private nodeFileSystem: FileSystem;
26private plistBuddy: PlistBuddy;
27private nodeChildProcess: ChildProcess;
28
34472878RedMickey5 years ago29constructor(
30iosProjectRoot: string,
31projectRoot: string,
32scheme?: string,
33{
34nodeFileSystem = new FileSystem(),
4dfb1c4cetatanova5 years ago35plistBuddy = undefined,
34472878RedMickey5 years ago36nodeChildProcess = new ChildProcess(),
37} = {},
38) {
764655c9Yuri Skorokhodov6 years ago39this.iosProjectRoot = iosProjectRoot;
4dfb1c4cetatanova5 years ago40this.projectRoot = projectRoot;
41this.scheme = scheme;
0a68f8dbArtem Egorov8 years ago42this.nodeFileSystem = nodeFileSystem;
4dfb1c4cetatanova5 years ago43this.plistBuddy = plistBuddy || new PlistBuddy();
0a68f8dbArtem Egorov8 years ago44this.nodeChildProcess = nodeChildProcess;
45}
46
0d77292aJiglioNero4 years ago47public async findPlistFile(configuration?: string, productName?: string): Promise<string> {
48const [bundleId, pathBuffer] = await Promise.all([
34472878RedMickey5 years ago49this.plistBuddy.getBundleId(
50this.iosProjectRoot,
51this.projectRoot,
1c2424f4RedMickey5 years ago52PlatformType.iOS,
34472878RedMickey5 years ago53true,
54configuration,
55productName,
56this.scheme,
57), // Find the name of the application
ce5e88eeYuri Skorokhodov5 years ago58this.nodeChildProcess.exec("xcrun simctl getenv booted HOME").then(res => res.outcome), // Find the path of the simulator we are running
0d77292aJiglioNero4 years ago59]);
60const pathBefore = path.join(
61pathBuffer.toString().trim(),
62"Containers",
63"Data",
64"Application",
65);
66const pathAfter = path.join("Library", "Preferences", `${bundleId}.plist`);
67// Look through $SIMULATOR_HOME/Containers/Data/Application/*/Library/Preferences to find $BUNDLEID.plist
68const apps = await this.nodeFileSystem.readDir(pathBefore);
69this.logger.info(
09f6024fHeniker4 years ago70`About to search for plist in base folder: ${pathBefore} pathAfter: ${pathAfter} in each of the apps: ${String(
71apps,
72)}`,
0d77292aJiglioNero4 years ago73);
74const plistCandidates = apps
75.map((app: string) => path.join(pathBefore, app, pathAfter))
76.filter(filePath => this.nodeFileSystem.existsSync(filePath));
77if (plistCandidates.length === 0) {
78throw new Error(`Unable to find plist file for ${bundleId}`);
79} else if (plistCandidates.length > 1) {
80TelemetryHelper.sendSimpleEvent("multipleDebugPlistFound");
81this.logger.warning(
82ErrorHelper.getWarning(
83localize(
84"MultiplePlistCandidatesFoundAppMayNotBeDebuggedInDebugMode",
85"Multiple plist candidates found. Application may not be in debug mode.",
86),
87),
34472878RedMickey5 years ago88);
0d77292aJiglioNero4 years ago89}
90return plistCandidates[0];
0a68f8dbArtem Egorov8 years ago91}
92}