microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/reactDirManager.ts
40lines · 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"; |
18d8ad2adigeff10 years ago | 11 | import {EntryPointHandler, ProcessType} 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 { | |
cc7d2e1bJimmy Thomson9 years ago | 18 | public static VscodeDirPath = path.join(vscode.workspace.rootPath || "", ".vscode"); |
| 19 | public static ReactDirPath = path.join(ReactDirManager.VscodeDirPath, ".react"); | |
b3a793eeNisheet Jain10 years ago | 20 | |
710f8655digeff10 years ago | 21 | public setup(): Q.Promise<void> { |
b3a793eeNisheet Jain10 years ago | 22 | let fs = new FileSystem(); |
| 23 | /* if the folder exists, remove it, then recreate it */ | |
10873e11digeff10 years ago | 24 | return fs.removePathRecursivelyAsync(ReactDirManager.ReactDirPath) |
cc7d2e1bJimmy Thomson9 years ago | 25 | .then(() => { |
| 26 | if (!fs.existsSync(ReactDirManager.VscodeDirPath)) { | |
| 27 | return fs.mkDir(ReactDirManager.VscodeDirPath); | |
| 28 | } | |
| 29 | }).then(() => | |
| 30 | fs.mkDir(ReactDirManager.ReactDirPath) | |
| 31 | ); | |
b3a793eeNisheet Jain10 years ago | 32 | } |
| 33 | | |
| 34 | public dispose(): void { | |
18d8ad2adigeff10 years ago | 35 | new EntryPointHandler(ProcessType.Extension, new OutputChannelLogger(vscode.window.createOutputChannel("React-Native"))).runFunction("extension.deleteTemporaryFolder", |
c2bf3c4fdigeff10 years ago | 36 | ErrorHelper.getInternalError(InternalErrorCode.RNTempFolderDeletionFailed, ReactDirManager.ReactDirPath), |
10873e11digeff10 years ago | 37 | () => |
ef24cc06digeff10 years ago | 38 | new FileSystem().removePathRecursivelySync(ReactDirManager.ReactDirPath)); |
b3a793eeNisheet Jain10 years ago | 39 | } |
| 40 | } |