microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.5.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/ios/plistBuddy.ts

64lines · 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 setPlistBooleanProperty(plistFile: string, property: string, value: boolean): Q.Promise<void> {
43 // Attempt to set the value, and if it fails due to the key not existing attempt to create the key
44 return this.invokePlistBuddy(`Set ${property} ${value}`, plistFile)
45 .fail(() =>
46 this.invokePlistBuddy(`Add ${property} bool ${value}`, plistFile)
47 )
48 .then(() => { });
49 }
50
51 public deletePlistProperty(plistFile: string, property: string): Q.Promise<void> {
52 return this.invokePlistBuddy(`Delete ${property}`, plistFile).then(() => { });
53 }
54
55 public readPlistProperty(plistFile: string, property: string): Q.Promise<string> {
56 return this.invokePlistBuddy(`Print ${property}`, plistFile);
57 }
58
59 private invokePlistBuddy(command: string, plistFile: string): Q.Promise<string> {
60 return this.nodeChildProcess.exec(`${PlistBuddy.plistBuddyExecutable} -c '${command}' '${plistFile}'`).outcome.then((result: string) => {
61 return result.toString().trim();
62 });
63 }
64}
65