microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/debugger/ios/plistBuddy.ts
36lines · 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 path from "path"; |
| 5 | import * as Q from "q"; |
| 6 | |
| 7 | import {Node} from "../../utils/node/node"; |
| 8 | import {Xcodeproj} from "./xcodeproj"; |
| 9 | |
| 10 | export class PlistBuddy { |
| 11 | private static plistBuddyExecutable = "/usr/libexec/PlistBuddy"; |
| 12 | |
| 13 | public getBundleId(projectRoot: string, simulator: boolean = true): Q.Promise<string> { |
| 14 | return new Xcodeproj().findXcodeprojFile(projectRoot).then((projectFile: string) => { |
| 15 | const appName = path.basename(projectFile, path.extname(projectFile)); |
| 16 | const infoPlistPath = path.join(projectRoot, "ios", "build", "Build", "Products", |
| 17 | simulator ? "Debug-iphonesimulator" : "Debug-iphoneos", |
| 18 | `${appName}.app`, "Info.plist"); |
| 19 | |
| 20 | return this.invokePlistBuddy("Print:CFBundleIdentifier", infoPlistPath); |
| 21 | }); |
| 22 | } |
| 23 | |
| 24 | public setPlistProperty(plistFile: string, property: string, value: string): Q.Promise<void> { |
| 25 | // Attempt to set the value, and if it fails due to the key not existing attempt to create the key |
| 26 | return this.invokePlistBuddy(`Set ${property} ${value}`, plistFile).fail(() => |
| 27 | this.invokePlistBuddy(`Add ${property} string ${value}`, plistFile) |
| 28 | ).then(() => {}); |
| 29 | } |
| 30 | |
| 31 | private invokePlistBuddy(command: string, plistFile: string): Q.Promise<string> { |
| 32 | return new Node.ChildProcess().exec(`${PlistBuddy.plistBuddyExecutable} -c '${command}' '${plistFile}'`).outcome.then((result: Buffer) => { |
| 33 | return result.toString().trim(); |
| 34 | }); |
| 35 | } |
| 36 | } |