microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/windows/windowsPlatform.ts
82lines · modeblame
299883f9Artem Egorov8 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 | | |
| 4 | import * as Q from "q"; | |
7bc455e9Artem Egorov8 years ago | 5 | import * as semver from "semver"; |
299883f9Artem Egorov8 years ago | 6 | |
dd90a856Artem Egorov8 years ago | 7 | import {GeneralMobilePlatform, MobilePlatformDeps} from "../generalMobilePlatform"; |
299883f9Artem Egorov8 years ago | 8 | import {IWindowsRunOptions} from "../launchArgs"; |
| 9 | import {OutputVerifier, PatternToFailure} from "../../common/outputVerifier"; | |
| 10 | import {TelemetryHelper} from "../../common/telemetryHelper"; | |
| 11 | import {CommandExecutor} from "../../common/commandExecutor"; | |
| 12 | import {ReactNativeProjectHelper} from "../../common/reactNativeProjectHelper"; | |
d7d405aeYuri Skorokhodov7 years ago | 13 | import { InternalErrorCode } from "../../common/error/internalErrorCode"; |
299883f9Artem Egorov8 years ago | 14 | |
| 15 | /** | |
| 16 | * Windows specific platform implementation for debugging RN applications. | |
| 17 | */ | |
| 18 | export class WindowsPlatform extends GeneralMobilePlatform { | |
7bc455e9Artem Egorov8 years ago | 19 | protected static NO_PACKAGER_VERSION = "0.53.0"; |
299883f9Artem Egorov8 years ago | 20 | |
| 21 | private static SUCCESS_PATTERNS = [ | |
| 22 | "Installing new version of the app", | |
| 23 | "Starting the app", | |
| 24 | ]; | |
| 25 | private static FAILURE_PATTERNS: PatternToFailure[] = [ | |
| 26 | { | |
| 27 | pattern: "Unrecognized command 'run-windows'", | |
d7d405aeYuri Skorokhodov7 years ago | 28 | errorCode: InternalErrorCode.WinRNMPPluginIsNotInstalled, |
299883f9Artem Egorov8 years ago | 29 | }, |
| 30 | ]; | |
| 31 | | |
| 32 | constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) { | |
| 33 | super(runOptions, platformDeps); | |
| 34 | } | |
| 35 | | |
| 36 | public runApp(enableDebug: boolean = true): Q.Promise<void> { | |
031832ffArtem Egorov8 years ago | 37 | const extProps = { |
| 38 | platform: { | |
| 39 | value: "windows", | |
| 40 | isPii: false, | |
| 41 | }, | |
| 42 | }; | |
| 43 | | |
| 44 | return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => { | |
299883f9Artem Egorov8 years ago | 45 | const env = this.getEnvArgument(); |
| 46 | | |
| 47 | if (enableDebug) { | |
db6fd42aRuslan Bikkinin7 years ago | 48 | this.runArguments.push("--proxy"); |
299883f9Artem Egorov8 years ago | 49 | } |
| 50 | | |
| 51 | return ReactNativeProjectHelper.getReactNativeVersion(this.runOptions.projectRoot) | |
| 52 | .then(version => { | |
6786e358Artem Egorov8 years ago | 53 | if (!semver.valid(version) /*Custom RN implementations should support this flag*/ || semver.gte(version, WindowsPlatform.NO_PACKAGER_VERSION)) { |
db6fd42aRuslan Bikkinin7 years ago | 54 | this.runArguments.push("--no-packager"); |
7bc455e9Artem Egorov8 years ago | 55 | } |
299883f9Artem Egorov8 years ago | 56 | |
db6fd42aRuslan Bikkinin7 years ago | 57 | const runWindowsSpawn = new CommandExecutor(this.projectPath, this.logger).spawnReactCommand(`run-${this.platformName}`, this.runArguments, {env}); |
dd90a856Artem Egorov8 years ago | 58 | return new OutputVerifier(() => Q(WindowsPlatform.SUCCESS_PATTERNS), () => Q(WindowsPlatform.FAILURE_PATTERNS), this.platformName) |
299883f9Artem Egorov8 years ago | 59 | .process(runWindowsSpawn); |
| 60 | }); | |
| 61 | }); | |
| 62 | } | |
| 63 | | |
| 64 | public prewarmBundleCache(): Q.Promise<void> { | |
| 65 | return this.packager.prewarmBundleCache("windows"); | |
| 66 | } | |
| 67 | | |
cbc7ac5bArtem Egorov7 years ago | 68 | public getRunArguments(): string[] { |
299883f9Artem Egorov8 years ago | 69 | let runArguments: string[] = []; |
| 70 | | |
| 71 | if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) { | |
| 72 | runArguments.push(...this.runOptions.runArguments); | |
| 73 | } else { | |
dd90a856Artem Egorov8 years ago | 74 | let target = this.runOptions.target === WindowsPlatform.simulatorString ? "" : this.runOptions.target; |
| 75 | if (target) { | |
| 76 | runArguments.push(`--${target}`); | |
299883f9Artem Egorov8 years ago | 77 | } |
| 78 | } | |
| 79 | | |
| 80 | return runArguments; | |
| 81 | } | |
| 82 | } |