microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/debugger/ios/simulatorPlist.ts
42lines · 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 | |
| 4 | import * as fs from "fs"; |
| 5 | import * as path from "path"; |
| 6 | import * as Q from "q"; |
| 7 | |
| 8 | import {PlistBuddy} from "./plistBuddy"; |
| 9 | import {Node} from "../../utils/node/node"; |
| 10 | import {Log} from "../../utils/commands/log"; |
| 11 | |
| 12 | export class SimulatorPlist { |
| 13 | private projectRoot: string; |
| 14 | |
| 15 | constructor(projectRoot: string) { |
| 16 | this.projectRoot = projectRoot; |
| 17 | } |
| 18 | |
| 19 | public findPlistFile(): Q.Promise<string> { |
| 20 | |
| 21 | return Q.all<any>([ |
| 22 | new PlistBuddy().getBundleId(this.projectRoot), // Find the name of the application |
| 23 | new Node.ChildProcess().exec("xcrun simctl getenv booted HOME").outcome]) // Find the path of the simulator we are running |
| 24 | .spread((bundleId: string, pathBuffer: Buffer) => { |
| 25 | const pathBefore = path.join(pathBuffer.toString().trim(), "Containers", "Data", "Application"); |
| 26 | const pathAfter = path.join("Library", "Preferences", `${bundleId}.plist`); |
| 27 | |
| 28 | // Look through $SIMULATOR_HOME/Containers/Data/Application/*/Library/Preferences to find $BUNDLEID.plist |
| 29 | return Q.nfcall(fs.readdir, pathBefore).then((apps: string[]) => { |
| 30 | const mockableFS = new Node.FileSystem(); |
| 31 | const plistCandidates = apps.map((app: string) => path.join(pathBefore, app, pathAfter)).filter(mockableFS.fileExistsSync); |
| 32 | if (plistCandidates.length === 0) { |
| 33 | throw new Error(`Unable to find plist file for ${bundleId}`); |
| 34 | } else if (plistCandidates.length > 1) { |
| 35 | Log.logMessage("Warning: Multiple plist candidates found. Application may not be in debug mode"); |
| 36 | } |
| 37 | |
| 38 | return plistCandidates[0]; |
| 39 | }); |
| 40 | }); |
| 41 | } |
| 42 | } |