microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/common/ios/xcodeproj.ts
46lines · modeblame
afc46a73Jimmy Thomson10 years ago | 1 | // 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 ago | 4 | import * as path from "path"; |
afc46a73Jimmy Thomson10 years ago | 5 | import * as Q from "q"; |
| 6 | | |
db80cd4eJimmy Thomson10 years ago | 7 | import {FileSystem} from "../../common/node/fileSystem"; |
afc46a73Jimmy Thomson10 years ago | 8 | |
c4a42a32Jimmy Thomson9 years ago | 9 | export interface IXcodeProjFile { |
81d6e05bJimmy Thomson9 years ago | 10 | fileName: string; |
| 11 | fileType: string; | |
eec73ab5Jimmy Thomson9 years ago | 12 | projectName: string; |
c4a42a32Jimmy Thomson9 years ago | 13 | } |
| 14 | | |
afc46a73Jimmy Thomson10 years ago | 15 | export class Xcodeproj { |
81226dceJimmy Thomson10 years ago | 16 | private nodeFileSystem: FileSystem; |
| 17 | | |
| 18 | constructor({ | |
cdf34447digeff10 years ago | 19 | nodeFileSystem = new FileSystem(), |
81226dceJimmy Thomson10 years ago | 20 | } = {}) { |
| 21 | this.nodeFileSystem = nodeFileSystem; | |
| 22 | } | |
| 23 | | |
c4a42a32Jimmy Thomson9 years ago | 24 | public findXcodeprojFile(projectRoot: string): Q.Promise<IXcodeProjFile> { |
81226dceJimmy Thomson10 years ago | 25 | return this.nodeFileSystem |
c4a42a32Jimmy Thomson9 years ago | 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 | | |
81d6e05bJimmy Thomson9 years ago | 36 | const fileName = path.join(projectRoot, candidate); |
| 37 | const fileType = path.extname(candidate); | |
| 38 | const projectName = path.basename(candidate, fileType); | |
c4a42a32Jimmy Thomson9 years ago | 39 | return { |
81d6e05bJimmy Thomson9 years ago | 40 | fileName, |
| 41 | fileType, | |
eec73ab5Jimmy Thomson9 years ago | 42 | projectName, |
| 43 | }; | |
afc46a73Jimmy Thomson10 years ago | 44 | }); |
| 45 | } | |
| 46 | } |