microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/macos/macOSPlatform.ts

94lines · modeblame

341dba36Yuri Skorokhodov5 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 semver from "semver";
5import { GeneralMobilePlatform, MobilePlatformDeps } from "../generalMobilePlatform";
6import { ImacOSRunOptions, PlatformType } from "../launchArgs";
7import { OutputVerifier, PatternToFailure } from "../../common/outputVerifier";
8import { TelemetryHelper } from "../../common/telemetryHelper";
9import { CommandExecutor } from "../../common/commandExecutor";
10import { InternalErrorCode } from "../../common/error/internalErrorCode";
11
12/**
13* macOS specific platform implementation for debugging RN applications.
14*/
15export class MacOSPlatform extends GeneralMobilePlatform {
34472878RedMickey5 years ago16private static SUCCESS_PATTERNS = ["Launching app"];
341dba36Yuri Skorokhodov5 years ago17private static FAILURE_PATTERNS: PatternToFailure[] = [
18{
19pattern: "Unrecognized command 'run-macos'",
20errorCode: InternalErrorCode.ReactNativemacOSIsNotInstalled,
21},
22];
23
24constructor(protected runOptions: ImacOSRunOptions, platformDeps: MobilePlatformDeps = {}) {
25super(runOptions, platformDeps);
26}
27
28public runApp(): Promise<void> {
29let extProps = {
30platform: {
31value: PlatformType.macOS,
32isPii: false,
33},
34};
35
34472878RedMickey5 years ago36extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(
37this.runOptions,
38this.runOptions.reactNativeVersions,
39extProps,
40);
341dba36Yuri Skorokhodov5 years ago41
42return TelemetryHelper.generate("MacOSPlatform.runApp", extProps, () => {
34472878RedMickey5 years ago43const env = GeneralMobilePlatform.getEnvArgument(
44process.env,
45this.runOptions.env,
46this.runOptions.envFile,
47);
341dba36Yuri Skorokhodov5 years ago48
34472878RedMickey5 years ago49if (
50!semver.valid(
51this.runOptions.reactNativeVersions.reactNativeVersion,
52) /*Custom RN implementations should support this flag*/ ||
53semver.gte(
54this.runOptions.reactNativeVersions.reactNativeVersion,
55MacOSPlatform.NO_PACKAGER_VERSION,
56)
57) {
341dba36Yuri Skorokhodov5 years ago58this.runArguments.push("--no-packager");
59}
60
34472878RedMickey5 years ago61const runmacOSSpawn = new CommandExecutor(
62this.projectPath,
63this.logger,
64).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env });
65return new OutputVerifier(
66() => Promise.resolve(MacOSPlatform.SUCCESS_PATTERNS),
67() => Promise.resolve(MacOSPlatform.FAILURE_PATTERNS),
68this.platformName,
69).process(runmacOSSpawn);
341dba36Yuri Skorokhodov5 years ago70});
71}
72
73public prewarmBundleCache(): Promise<void> {
74return this.packager.prewarmBundleCache(PlatformType.macOS);
75}
76
77public getRunArguments(): string[] {
78let runArguments: string[] = [];
79
80if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
81runArguments.push(...this.runOptions.runArguments);
82} else {
34472878RedMickey5 years ago83let target =
84this.runOptions.target === MacOSPlatform.simulatorString
85? ""
86: this.runOptions.target;
341dba36Yuri Skorokhodov5 years ago87if (target) {
88runArguments.push(`--${target}`);
89}
90}
91
92return runArguments;
93}
94}