microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/reactDirManager.ts
34lines · modeblame
b3a793eeNisheet Jain10 years ago | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. | |
| 3 | | |
10873e11digeff10 years ago | 4 | import * as Q from "q"; |
b3a793eeNisheet Jain10 years ago | 5 | import * as vscode from "vscode"; |
| 6 | import * as path from "path"; | |
c2bf3c4fdigeff10 years ago | 7 | import {OutputChannelLogger} from "./outputChannelLogger"; |
| 8 | import {ErrorHelper} from "../common/error/errorHelper"; | |
| 9 | import {InternalErrorCode} from "../common/error/internalErrorCode"; | |
10873e11digeff10 years ago | 10 | import {FileSystem} from "../common/node/fileSystem"; |
47958817digeff10 years ago | 11 | import {EntryPointHandler} from "../common/entryPointHandler"; |
b3a793eeNisheet Jain10 years ago | 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 | | |
710f8655digeff10 years ago | 20 | public setup(): Q.Promise<void> { |
b3a793eeNisheet Jain10 years ago | 21 | let fs = new FileSystem(); |
| 22 | /* if the folder exists, remove it, then recreate it */ | |
10873e11digeff10 years ago | 23 | return fs.removePathRecursivelyAsync(ReactDirManager.ReactDirPath) |
| 24 | .then(() => | |
| 25 | fs.mkDir(ReactDirManager.ReactDirPath)); | |
b3a793eeNisheet Jain10 years ago | 26 | } |
| 27 | | |
| 28 | public dispose(): void { | |
c2bf3c4fdigeff10 years ago | 29 | new EntryPointHandler(false, new OutputChannelLogger(vscode.window.createOutputChannel("React-Native"))).runFunction("extension.deleteTemporaryFolder", |
| 30 | ErrorHelper.getInternalError(InternalErrorCode.RNTempFolderDeletionFailed, ReactDirManager.ReactDirPath), | |
10873e11digeff10 years ago | 31 | () => |
ef24cc06digeff10 years ago | 32 | new FileSystem().removePathRecursivelySync(ReactDirManager.ReactDirPath)); |
b3a793eeNisheet Jain10 years ago | 33 | } |
| 34 | } |