microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/debugger/ios/compiler.ts
42lines · 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 {CommandExecutor} from "../../utils/commands/commandExecutor"; |
| 8 | import {Xcodeproj} from "./xcodeproj"; |
| 9 | |
| 10 | export class Compiler { |
| 11 | private projectRoot: string; |
| 12 | private simulator: boolean; |
| 13 | |
| 14 | constructor(projectRoot: string, simulator: boolean) { |
| 15 | this.projectRoot = projectRoot; |
| 16 | this.simulator = simulator; |
| 17 | } |
| 18 | |
| 19 | public compile(): Q.Promise<void> { |
| 20 | return this.xcodeBuildArguments().then((xcodeArguments: string[]) => { |
| 21 | return new CommandExecutor(this.projectRoot).spawnAndWaitForCompletion("xcodebuild", xcodeArguments); |
| 22 | }); |
| 23 | } |
| 24 | |
| 25 | /* |
| 26 | Return the appropriate arguments for compiling a react native project |
| 27 | */ |
| 28 | private xcodeBuildArguments(): Q.Promise<string[]> { |
| 29 | if (this.simulator) { |
| 30 | return Q.reject<string[]>(new Error("Error: Compiling for simulator; should be using 'react-native run-ios' instead")); |
| 31 | } |
| 32 | return new Xcodeproj().findXcodeprojFile(this.projectRoot).then((projectFile: string) => { |
| 33 | const projectName = path.basename(projectFile, path.extname(projectFile)); |
| 34 | return [ |
| 35 | "-project", path.join(this.projectRoot, "ios", projectFile), |
| 36 | "-scheme", projectName, |
| 37 | "-destination", "generic/platform=iOS", // Build for a generic iOS device |
| 38 | "-derivedDataPath", path.join(this.projectRoot, "ios", "build") |
| 39 | ]; |
| 40 | }); |
| 41 | } |
| 42 | } |