microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/ios/plistBuddy.ts

44lines · 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 "../../common/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 public deletePlistProperty(plistFile: string, property: string): Q.Promise<void> {
32 return this.invokePlistBuddy(`Delete ${property}`, plistFile).then(() => { });
33 }
34
35 public readPlistProperty(plistFile: string, property: string): Q.Promise<string> {
36 return this.invokePlistBuddy(`Print ${property}`, plistFile);
37 }
38
39 private invokePlistBuddy(command: string, plistFile: string): Q.Promise<string> {
40 return new Node.ChildProcess().exec(`${PlistBuddy.plistBuddyExecutable} -c '${command}' '${plistFile}'`).outcome.then((result: Buffer) => {
41 return result.toString().trim();
42 });
43 }
44}