microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.11.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/commands/reloadApp.ts

72lines · 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
4import * as assert from "assert";
5import * as nls from "vscode-nls";
6import { ErrorHelper } from "../../common/error/errorHelper";
7import { InternalErrorCode } from "../../common/error/internalErrorCode";
8import { ProjectVersionHelper, REACT_NATIVE_PACKAGES } from "../../common/projectVersionHelper";
9import { PlatformType } from "../launchArgs";
10import { AndroidPlatform } from "../android/androidPlatform";
11import { IOSPlatform } from "../ios/iOSPlatform";
12import { WindowsPlatform } from "../windows/windowsPlatform";
13import { getRunOptions } from "./util";
14import { Command } from "./util/command";
15
16nls.config({
17 messageFormat: nls.MessageFormat.bundle,
18 bundleFormat: nls.BundleFormat.standalone,
19})();
20const localize = nls.loadMessageBundle();
21
22export class ReloadApp extends Command {
23 codeName = "reloadApp";
24 requiresTrust = false;
25 label = "ReloadApp";
26 error = ErrorHelper.getInternalError(
27 InternalErrorCode.CommandFailed,
28 localize("ReactNativeReloadApp", "React Native: Reload App"),
29 );
30
31 async baseFn(): Promise<void> {
32 assert(this.project);
33
34 const androidPlatform = new AndroidPlatform(
35 getRunOptions(this.project, PlatformType.Android),
36 {
37 packager: this.project.getPackager(),
38 },
39 );
40
41 androidPlatform.reloadApp().catch(() => {});
42
43 if (process.platform === "win32") {
44 const nodeModulesRoot = this.project.getOrUpdateNodeModulesRoot();
45 const RNPackageVersions =
46 await ProjectVersionHelper.getReactNativePackageVersionsFromNodeModules(
47 nodeModulesRoot,
48 [REACT_NATIVE_PACKAGES.REACT_NATIVE_WINDOWS],
49 );
50
51 const isRNWProject = !ProjectVersionHelper.isVersionError(
52 RNPackageVersions.reactNativeWindowsVersion,
53 );
54
55 if (isRNWProject) {
56 const windowsPlatform = new WindowsPlatform(
57 getRunOptions(this.project, PlatformType.Windows),
58 {
59 packager: this.project.getPackager(),
60 },
61 );
62 windowsPlatform.reloadApp(this.project).catch(() => {});
63 }
64 } else if (process.platform === "darwin") {
65 const iosPlatform = new IOSPlatform(getRunOptions(this.project, PlatformType.iOS), {
66 packager: this.project.getPackager(),
67 });
68
69 iosPlatform.reloadApp(this.project).catch(() => {});
70 }
71 }
72}
73