microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/appcenter/auth/tokenStore/index.ts
40lines · 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 { TokenStore } from "./tokenStore"; |
| 5 | import { createFileTokenStore } from "./fileTokenStore"; |
| 6 | import * as path from "path"; |
| 7 | import * as fs from "fs"; |
| 8 | import * as os from "os"; |
| 9 | |
| 10 | export * from "./tokenStore"; |
| 11 | export const tokenFile = "VSCodeAppCenterTokens.json"; |
| 12 | |
| 13 | let store: TokenStore; |
| 14 | |
| 15 | const tokenDirName: string = ".vscode-react-native"; |
| 16 | |
| 17 | function getTokenDir(): string { |
| 18 | const tokenDir = path.join(getTokenDirParent(), tokenDirName); |
| 19 | return tokenDir; |
| 20 | } |
| 21 | |
| 22 | function getTokenDirParent(): string { |
| 23 | if (os.platform() === "win32") { |
| 24 | return process.env.AppData; |
| 25 | } else { |
| 26 | return os.homedir(); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | // Currently only support file-base token store |
| 31 | const tokenFilePath = path.join(getTokenDir(), tokenFile); |
| 32 | if (!fs.existsSync(tokenFilePath)) { |
| 33 | if (!fs.existsSync(getTokenDir())) { |
| 34 | fs.mkdirSync(getTokenDir()); |
| 35 | } |
| 36 | fs.writeFileSync(tokenFilePath, /* create empty */ ""); |
| 37 | } |
| 38 | store = createFileTokenStore(tokenFilePath); |
| 39 | export const tokenStore = store; |
| 40 | |
| 41 | |