microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
45944d15dab31409096b01c12901cd2131a68bbb

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/rn-extension.ts

60lines · 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
5import {FileSystem} from "./utils/node/fileSystem";
6import * as path from "path";
7import * as vscode from "vscode";
8
9import {ReactNativeCommandExecutor} from "./utils/reactNativeCommandExecutor";
10import {ReactNativeProjectHelper} from "./utils/reactNativeProjectHelper";
11
12export function activate(context: vscode.ExtensionContext): void {
13 let reactNativeProjectHelper = new ReactNativeProjectHelper(vscode.workspace.rootPath);
14 reactNativeProjectHelper.isReactNativeProject().then(isRNProject => {
15 if (isRNProject) {
16 setupReactNativeDebugger();
17 }
18 });
19
20 let reactNativeCommandExecutor = new ReactNativeCommandExecutor(vscode.workspace.rootPath);
21
22 // Register React Native commands
23 context.subscriptions.push(vscode.commands.registerCommand("reactNative.runAndroid",
24 () => reactNativeCommandExecutor.executeCommandInContext(() => reactNativeCommandExecutor.runAndroid())));
25 context.subscriptions.push(vscode.commands.registerCommand("reactNative.runIos",
26 () => reactNativeCommandExecutor.executeCommandInContext(() => reactNativeCommandExecutor.runIos())));
27 context.subscriptions.push(vscode.commands.registerCommand("reactNative.startPackager",
28 () => reactNativeCommandExecutor.executeCommandInContext(() => reactNativeCommandExecutor.startPackager())));
29 context.subscriptions.push(vscode.commands.registerCommand("reactNative.stopPackager",
30 () => reactNativeCommandExecutor.executeCommandInContext(() => reactNativeCommandExecutor.stopPackager())));
31}
32
33/**
34 * Sets up the debugger for the React Native project by dropping
35 * the debugger stub into the workspace
36 */
37function setupReactNativeDebugger(): void {
38 let launcherPath = require.resolve("./debugger/launcher");
39 const extensionVersionNumber = require("../package.json").version;
40
41 let debuggerEntryCode =
42 `// This file is automatically generated. version:${extensionVersionNumber}
43try {
44 var path = require("path");
45 var Launcher = require(${JSON.stringify(launcherPath)}).Launcher;
46 new Launcher(path.resolve(__dirname, "..")).launch();
47} catch (e) {
48 throw new Error("Unable to launch application. Try deleting .vscode/launchReactNative.js and restarting vscode.");
49}`;
50 let vscodeFolder = path.join(vscode.workspace.rootPath, ".vscode");
51 let debugStub = path.join(vscodeFolder, "launchReactNative.js");
52
53 let fsUtil = new FileSystem();
54
55 fsUtil.ensureDirectory(vscodeFolder).then(() => {
56 fsUtil.ensureFileWithContents(debugStub, debuggerEntryCode);
57 }).catch((err: Error) => {
58 vscode.window.showErrorMessage(err.message);
59 });
60}