microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.3.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/ios/xcodeproj.ts

46lines · 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 {FileSystem} from "../../common/node/fileSystem";
8
9export interface IXcodeProjFile {
10 fileName: string;
11 fileType: string;
12 projectName: string;
13}
14
15export class Xcodeproj {
16 private nodeFileSystem: FileSystem;
17
18 constructor({
19 nodeFileSystem = new FileSystem(),
20 } = {}) {
21 this.nodeFileSystem = nodeFileSystem;
22 }
23
24 public findXcodeprojFile(projectRoot: string): Q.Promise<IXcodeProjFile> {
25 return this.nodeFileSystem
26 .readDir(projectRoot)
27 .then((files: string[]): IXcodeProjFile => {
28 const sorted = files.sort();
29 const candidate = sorted.find((file: string) =>
30 [".xcodeproj", ".xcworkspace"].indexOf(path.extname(file)) !== -1
31 );
32 if (!candidate) {
33 throw new Error("Unable to find any xcodeproj or xcworkspace files.");
34 }
35
36 const fileName = path.join(projectRoot, candidate);
37 const fileType = path.extname(candidate);
38 const projectName = path.basename(candidate, fileType);
39 return {
40 fileName,
41 fileType,
42 projectName,
43 };
44 });
45 }
46}