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/xcodeproj.ts

52lines · 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 extensions = [".xcworkspace", ".xcodeproj"];
29 const sorted = files.sort();
30 const candidates = sorted.filter((file: string) =>
31 extensions.indexOf(path.extname(file)) !== -1
32 ).sort((a, b) =>
33 extensions.indexOf(path.extname(a)) - extensions.indexOf(path.extname(b))
34 );
35
36 if (candidates.length === 0) {
37 throw new Error("Unable to find any xcodeproj or xcworkspace files.");
38 }
39
40 const bestCandidate = candidates[0];
41
42 const fileName = path.join(projectRoot, bestCandidate);
43 const fileType = path.extname(bestCandidate);
44 const projectName = path.basename(bestCandidate, fileType);
45 return {
46 fileName,
47 fileType,
48 projectName,
49 };
50 });
51 }
52}