microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/extension/reactDirManager.ts
31lines · 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 | import * as Q from "q"; |
| 5 | import * as vscode from "vscode"; |
| 6 | import * as path from "path"; |
| 7 | import {FileSystem} from "../common/node/fileSystem"; |
| 8 | import {EntryPointHandler} from "../common/entryPointHandler"; |
| 9 | |
| 10 | /** |
| 11 | * Manages the lifecycle of the .vscode/.react folder, which hosts the temporary source/map files we need for debugging. |
| 12 | * We use synchronous operations here because we want to return after the init/cleanup has been done. |
| 13 | */ |
| 14 | export class ReactDirManager implements vscode.Disposable { |
| 15 | public static ReactDirPath = path.join(vscode.workspace.rootPath, ".vscode", ".react"); |
| 16 | |
| 17 | public create(): Q.Promise<void> { |
| 18 | let fs = new FileSystem(); |
| 19 | /* if the folder exists, remove it, then recreate it */ |
| 20 | return fs.removePathRecursivelyAsync(ReactDirManager.ReactDirPath) |
| 21 | .then(() => |
| 22 | fs.mkDir(ReactDirManager.ReactDirPath)); |
| 23 | } |
| 24 | |
| 25 | public dispose(): void { |
| 26 | new EntryPointHandler(vscode.window.createOutputChannel("React-Native")).runFunction("extension.deleteTemporaryFolder", |
| 27 | "Couldn't delete the temporary folder ${ReactDirManager.ReactDirPath}", |
| 28 | () => |
| 29 | new FileSystem().removePathRecursivelySync(ReactDirManager.ReactDirPath)); |
| 30 | } |
| 31 | } |