microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
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 | |
| 4 | import * as path from "path"; |
| 5 | import * as Q from "q"; |
| 6 | |
| 7 | import {FileSystem} from "../../common/node/fileSystem"; |
| 8 | |
| 9 | export interface IXcodeProjFile { |
| 10 | fileName: string; |
| 11 | fileType: string; |
| 12 | projectName: string; |
| 13 | } |
| 14 | |
| 15 | export 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 | } |