microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2ec44b6d62529aa08a88dc1dbe190833e1838036

Branches

Tags

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

Clone

HTTPS

Download ZIP

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
4import * as path from "path";
5import * as Q from "q";
6
7import {Node} from "../../utils/node/node";
8import {Xcodeproj} from "./xcodeproj";
9
10export 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}