microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.14.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/simulatorPlist.ts

66lines · 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";
5import * as Q from "q";
6
7import {ErrorHelper} from "../../common/error/errorHelper";
8import {PlistBuddy} from "./plistBuddy";
9import {OutputChannelLogger} from "../log/OutputChannelLogger";
10import {FileSystem} from "../../common/node/fileSystem";
11import {ChildProcess} from "../../common/node/childProcess";
12
13import {TelemetryHelper} from "../../common/telemetryHelper";
d7d405aeYuri Skorokhodov7 years ago14import * as nls from "vscode-nls";
15const localize = nls.loadMessageBundle();
0a68f8dbArtem Egorov8 years ago16
17export class SimulatorPlist {
18private projectRoot: string;
764655c9Yuri Skorokhodov6 years ago19private iosProjectRoot: string;
a949e43fRuslan Bikkinin7 years ago20private scheme?: string;
0a68f8dbArtem Egorov8 years ago21private logger: OutputChannelLogger = OutputChannelLogger.getMainChannel();
22
23private nodeFileSystem: FileSystem;
24private plistBuddy: PlistBuddy;
25private nodeChildProcess: ChildProcess;
26
764655c9Yuri Skorokhodov6 years ago27constructor(iosProjectRoot: string, projectRoot: string, scheme?: string, {
0a68f8dbArtem Egorov8 years ago28nodeFileSystem = new FileSystem(),
29plistBuddy = new PlistBuddy(),
30nodeChildProcess = new ChildProcess(),
31} = {}) {
32this.projectRoot = projectRoot;
764655c9Yuri Skorokhodov6 years ago33this.iosProjectRoot = iosProjectRoot;
0a68f8dbArtem Egorov8 years ago34
35this.nodeFileSystem = nodeFileSystem;
36this.plistBuddy = plistBuddy;
37this.nodeChildProcess = nodeChildProcess;
a949e43fRuslan Bikkinin7 years ago38this.scheme = scheme;
0a68f8dbArtem Egorov8 years ago39}
40
db6fd42aRuslan Bikkinin7 years ago41public findPlistFile(configuration?: string, productName?: string): Q.Promise<string> {
0a68f8dbArtem Egorov8 years ago42
43return Q.all<any>([
764655c9Yuri Skorokhodov6 years ago44this.plistBuddy.getBundleId(this.iosProjectRoot, this.projectRoot, true, configuration, productName, this.scheme), // Find the name of the application
0a68f8dbArtem Egorov8 years ago45this.nodeChildProcess.exec("xcrun simctl getenv booted HOME").outcome, // Find the path of the simulator we are running
46]).spread((bundleId: string, pathBuffer: Buffer) => {
47const pathBefore = path.join(pathBuffer.toString().trim(), "Containers", "Data", "Application");
48const pathAfter = path.join("Library", "Preferences", `${bundleId}.plist`);
49
50// Look through $SIMULATOR_HOME/Containers/Data/Application/*/Library/Preferences to find $BUNDLEID.plist
51return this.nodeFileSystem.readDir(pathBefore).then((apps: string[]) => {
52this.logger.info(`About to search for plist in base folder: ${pathBefore} pathAfter: ${pathAfter} in each of the apps: ${apps}`);
53const plistCandidates = apps.map((app: string) => path.join(pathBefore, app, pathAfter)).filter(filePath =>
54this.nodeFileSystem.existsSync(filePath));
55if (plistCandidates.length === 0) {
56throw new Error(`Unable to find plist file for ${bundleId}`);
57} else if (plistCandidates.length > 1) {
58TelemetryHelper.sendSimpleEvent("multipleDebugPlistFound");
d7d405aeYuri Skorokhodov7 years ago59this.logger.warning(ErrorHelper.getWarning(localize("MultiplePlistCandidatesFoundAppMayNotBeDebuggedInDebugMode", "Multiple plist candidates found. Application may not be in debug mode.")));
0a68f8dbArtem Egorov8 years ago60}
61
62return plistCandidates[0];
63});
64});
65}
66}