microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
5b782b052bb35ad8372c07dd4c4529a79919fa31

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/rn-extension.ts

54lines · 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 vscode from "vscode";
5import {FileSystem} from "./utils/node/fileSystem";
6import * as fs from "fs";
7import * as path from "path";
8import {PackageJsonWatcher} from "./utils/packageJsonWatcher";
9import {ReactNativeCommandHelper} from "./utils/reactNativeCommandHelper";
10
11export function activate(context: vscode.ExtensionContext): void {
12 // TODO: Get the project root (vscode.workspace.rootPath) and return if it is not a react-native project
13 // check if package.json of user project has dependency on react-native
14
15 let reactDir = new ReactDirManager();
16 reactDir.init();
17 context.subscriptions.push(reactDir);
18
19 let packageJsonWatcher = new PackageJsonWatcher();
20 packageJsonWatcher.startWatching();
21
22
23 // TODO: Change to a foreach if this implementation is appropriate
24 // Register react native commands
25 context.subscriptions.push(vscode.commands.registerCommand("reactNative.runAndroid",
26 () => ReactNativeCommandHelper.executeReactNativeCommand(vscode.workspace.rootPath, "runAndroid")));
27 context.subscriptions.push(vscode.commands.registerCommand("reactNative.runIos",
28 () => ReactNativeCommandHelper.executeReactNativeCommand(vscode.workspace.rootPath, "runIos")));
29 context.subscriptions.push(vscode.commands.registerCommand("reactNative.startPackager",
30 () => ReactNativeCommandHelper.executeReactNativeCommand(vscode.workspace.rootPath, "startPackager")));
31 context.subscriptions.push(vscode.commands.registerCommand("reactNative.stopPackager",
32 () => ReactNativeCommandHelper.executeReactNativeCommand(vscode.workspace.rootPath, "stopPackager")));
33}
34
35/**
36 * Manages the lifecycle of the .vscode/.react folder, which hosts the temporary source/map files we need for debugging.
37 * We use synchronous operations here because we want to return after the init/cleanup has been done.
38 */
39class ReactDirManager implements vscode.Disposable {
40 public static ReactDirPath = path.join(vscode.workspace.rootPath, ".vscode", ".react");
41
42 public init(): void {
43 if (fs.existsSync(ReactDirManager.ReactDirPath)) {
44 /* delete old files, if any */
45 this.dispose();
46 }
47
48 fs.mkdirSync(ReactDirManager.ReactDirPath);
49 }
50
51 public dispose(): void {
52 new FileSystem().removePathRecursivelySync(ReactDirManager.ReactDirPath);
53 }
54}