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