microsoft/vscode-react-native

Public

mirrored from https://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 · modeblame

afc46a73Jimmy Thomson10 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
c4a42a32Jimmy Thomson9 years ago4import * as path from "path";
afc46a73Jimmy Thomson10 years ago5import * as Q from "q";
6
db80cd4eJimmy Thomson10 years ago7import {FileSystem} from "../../common/node/fileSystem";
afc46a73Jimmy Thomson10 years ago8
c4a42a32Jimmy Thomson9 years ago9export interface IXcodeProjFile {
81d6e05bJimmy Thomson9 years ago10fileName: string;
11fileType: string;
eec73ab5Jimmy Thomson9 years ago12projectName: string;
c4a42a32Jimmy Thomson9 years ago13}
14
afc46a73Jimmy Thomson10 years ago15export class Xcodeproj {
81226dceJimmy Thomson10 years ago16private nodeFileSystem: FileSystem;
17
18constructor({
cdf34447digeff10 years ago19nodeFileSystem = new FileSystem(),
81226dceJimmy Thomson10 years ago20} = {}) {
21this.nodeFileSystem = nodeFileSystem;
22}
23
c4a42a32Jimmy Thomson9 years ago24public findXcodeprojFile(projectRoot: string): Q.Promise<IXcodeProjFile> {
81226dceJimmy Thomson10 years ago25return this.nodeFileSystem
c4a42a32Jimmy Thomson9 years ago26.readDir(projectRoot)
27.then((files: string[]): IXcodeProjFile => {
67b4477aNathan Piper9 years ago28const extensions = [".xcworkspace", ".xcodeproj"];
c4a42a32Jimmy Thomson9 years ago29const sorted = files.sort();
67b4477aNathan Piper9 years ago30const candidates = sorted.filter((file: string) =>
31extensions.indexOf(path.extname(file)) !== -1
32).sort((a, b) =>
33extensions.indexOf(path.extname(a)) - extensions.indexOf(path.extname(b))
c4a42a32Jimmy Thomson9 years ago34);
67b4477aNathan Piper9 years ago35
36if (candidates.length === 0) {
c4a42a32Jimmy Thomson9 years ago37throw new Error("Unable to find any xcodeproj or xcworkspace files.");
38}
39
67b4477aNathan Piper9 years ago40const bestCandidate = candidates[0];
41
42const fileName = path.join(projectRoot, bestCandidate);
43const fileType = path.extname(bestCandidate);
44const projectName = path.basename(bestCandidate, fileType);
c4a42a32Jimmy Thomson9 years ago45return {
81d6e05bJimmy Thomson9 years ago46fileName,
47fileType,
eec73ab5Jimmy Thomson9 years ago48projectName,
49};
afc46a73Jimmy Thomson10 years ago50});
51}
52}