microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.10.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

82lines · modeblame

299883f9Artem Egorov8 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
4import * as Q from "q";
7bc455e9Artem Egorov8 years ago5import * as semver from "semver";
299883f9Artem Egorov8 years ago6
dd90a856Artem Egorov8 years ago7import {GeneralMobilePlatform, MobilePlatformDeps} from "../generalMobilePlatform";
299883f9Artem Egorov8 years ago8import {IWindowsRunOptions} from "../launchArgs";
9import {OutputVerifier, PatternToFailure} from "../../common/outputVerifier";
10import {TelemetryHelper} from "../../common/telemetryHelper";
11import {CommandExecutor} from "../../common/commandExecutor";
12import {ReactNativeProjectHelper} from "../../common/reactNativeProjectHelper";
d7d405aeYuri Skorokhodov7 years ago13import { InternalErrorCode } from "../../common/error/internalErrorCode";
299883f9Artem Egorov8 years ago14
15/**
16* Windows specific platform implementation for debugging RN applications.
17*/
18export class WindowsPlatform extends GeneralMobilePlatform {
7bc455e9Artem Egorov8 years ago19protected static NO_PACKAGER_VERSION = "0.53.0";
299883f9Artem Egorov8 years ago20
21private static SUCCESS_PATTERNS = [
22"Installing new version of the app",
23"Starting the app",
24];
25private static FAILURE_PATTERNS: PatternToFailure[] = [
26{
27pattern: "Unrecognized command 'run-windows'",
d7d405aeYuri Skorokhodov7 years ago28errorCode: InternalErrorCode.WinRNMPPluginIsNotInstalled,
299883f9Artem Egorov8 years ago29},
30];
31
32constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
33super(runOptions, platformDeps);
34}
35
36public runApp(enableDebug: boolean = true): Q.Promise<void> {
031832ffArtem Egorov8 years ago37const extProps = {
38platform: {
39value: "windows",
40isPii: false,
41},
42};
43
44return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => {
299883f9Artem Egorov8 years ago45const env = this.getEnvArgument();
46
47if (enableDebug) {
db6fd42aRuslan Bikkinin7 years ago48this.runArguments.push("--proxy");
299883f9Artem Egorov8 years ago49}
50
51return ReactNativeProjectHelper.getReactNativeVersion(this.runOptions.projectRoot)
52.then(version => {
6786e358Artem Egorov8 years ago53if (!semver.valid(version) /*Custom RN implementations should support this flag*/ || semver.gte(version, WindowsPlatform.NO_PACKAGER_VERSION)) {
db6fd42aRuslan Bikkinin7 years ago54this.runArguments.push("--no-packager");
7bc455e9Artem Egorov8 years ago55}
299883f9Artem Egorov8 years ago56
db6fd42aRuslan Bikkinin7 years ago57const runWindowsSpawn = new CommandExecutor(this.projectPath, this.logger).spawnReactCommand(`run-${this.platformName}`, this.runArguments, {env});
dd90a856Artem Egorov8 years ago58return new OutputVerifier(() => Q(WindowsPlatform.SUCCESS_PATTERNS), () => Q(WindowsPlatform.FAILURE_PATTERNS), this.platformName)
299883f9Artem Egorov8 years ago59.process(runWindowsSpawn);
60});
61});
62}
63
64public prewarmBundleCache(): Q.Promise<void> {
65return this.packager.prewarmBundleCache("windows");
66}
67
cbc7ac5bArtem Egorov7 years ago68public getRunArguments(): string[] {
299883f9Artem Egorov8 years ago69let runArguments: string[] = [];
70
71if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
72runArguments.push(...this.runOptions.runArguments);
73} else {
dd90a856Artem Egorov8 years ago74let target = this.runOptions.target === WindowsPlatform.simulatorString ? "" : this.runOptions.target;
75if (target) {
76runArguments.push(`--${target}`);
299883f9Artem Egorov8 years ago77}
78}
79
80return runArguments;
81}
82}