microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.3.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/ios/plistBuddy.ts

55lines · 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 {ChildProcess} from "../../common/node/childProcess";
9import {Xcodeproj, IXcodeProjFile} from "./xcodeproj";
10
11export class PlistBuddy {
12 private static plistBuddyExecutable = "/usr/libexec/PlistBuddy";
13
14 private nodeChildProcess: ChildProcess;
15 private xcodeproj: Xcodeproj;
16
17 constructor({
18 nodeChildProcess = new Node.ChildProcess(),
19 xcodeproj = new Xcodeproj(),
20 } = {}) {
21 this.nodeChildProcess = nodeChildProcess;
22 this.xcodeproj = xcodeproj;
23 }
24
25 public getBundleId(projectRoot: string, simulator: boolean = true): Q.Promise<string> {
26 return this.xcodeproj.findXcodeprojFile(projectRoot).then((projectFile: IXcodeProjFile) => {
27 const infoPlistPath = path.join(projectRoot, "build", "Build", "Products",
28 simulator ? "Debug-iphonesimulator" : "Debug-iphoneos",
29 `${projectFile.projectName}.app`, "Info.plist");
30
31 return this.invokePlistBuddy("Print:CFBundleIdentifier", infoPlistPath);
32 });
33 }
34
35 public setPlistProperty(plistFile: string, property: string, value: string): Q.Promise<void> {
36 // Attempt to set the value, and if it fails due to the key not existing attempt to create the key
37 return this.invokePlistBuddy(`Set ${property} ${value}`, plistFile).fail(() =>
38 this.invokePlistBuddy(`Add ${property} string ${value}`, plistFile)
39 ).then(() => { });
40 }
41
42 public deletePlistProperty(plistFile: string, property: string): Q.Promise<void> {
43 return this.invokePlistBuddy(`Delete ${property}`, plistFile).then(() => { });
44 }
45
46 public readPlistProperty(plistFile: string, property: string): Q.Promise<string> {
47 return this.invokePlistBuddy(`Print ${property}`, plistFile);
48 }
49
50 private invokePlistBuddy(command: string, plistFile: string): Q.Promise<string> {
51 return this.nodeChildProcess.exec(`${PlistBuddy.plistBuddyExecutable} -c '${command}' '${plistFile}'`).outcome.then((result: string) => {
52 return result.toString().trim();
53 });
54 }
55}