microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.4

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/ios/plistBuddy.ts

56lines · 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} 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: string) => {
27 const appName = path.basename(projectFile, path.extname(projectFile));
28 const infoPlistPath = path.join(projectRoot, "ios", "build", "Build", "Products",
29 simulator ? "Debug-iphonesimulator" : "Debug-iphoneos",
30 `${appName}.app`, "Info.plist");
31
32 return this.invokePlistBuddy("Print:CFBundleIdentifier", infoPlistPath);
33 });
34 }
35
36 public setPlistProperty(plistFile: string, property: string, value: string): Q.Promise<void> {
37 // Attempt to set the value, and if it fails due to the key not existing attempt to create the key
38 return this.invokePlistBuddy(`Set ${property} ${value}`, plistFile).fail(() =>
39 this.invokePlistBuddy(`Add ${property} string ${value}`, plistFile)
40 ).then(() => { });
41 }
42
43 public deletePlistProperty(plistFile: string, property: string): Q.Promise<void> {
44 return this.invokePlistBuddy(`Delete ${property}`, plistFile).then(() => { });
45 }
46
47 public readPlistProperty(plistFile: string, property: string): Q.Promise<string> {
48 return this.invokePlistBuddy(`Print ${property}`, plistFile);
49 }
50
51 private invokePlistBuddy(command: string, plistFile: string): Q.Promise<string> {
52 return this.nodeChildProcess.exec(`${PlistBuddy.plistBuddyExecutable} -c '${command}' '${plistFile}'`).outcome.then((result: Buffer) => {
53 return result.toString().trim();
54 });
55 }
56}