microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/appcenter/appCenterUtils.ts
55lines · 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 | // tslint:disable-next-line:no-var-requires |
| 5 | const opener = require("opener"); |
| 6 | // tslint:disable-next-line:no-var-requires |
| 7 | const open = require("open"); |
| 8 | import * as Q from "q"; |
| 9 | import * as fs from "fs"; |
| 10 | import * as path from "path"; |
| 11 | import { Package, IPackageInformation } from "../../common/node/package"; |
| 12 | import { ACConstants } from "./appCenterConstants"; |
| 13 | import { DefaultApp } from "./command/commandParams"; |
| 14 | |
| 15 | export class ACUtils { |
| 16 | private static validApp = /^([a-zA-Z0-9-_.]{1,100})\/([a-zA-Z0-9-_.]{1,100})$/; |
| 17 | |
| 18 | // Use open for Windows and Mac, opener for Linux |
| 19 | public static OpenUrl(url: string): void { |
| 20 | switch (process.platform) { |
| 21 | case "win32": |
| 22 | case "darwin": |
| 23 | open(url); |
| 24 | break; |
| 25 | default: |
| 26 | opener(url); |
| 27 | break; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | public static isCodePushProject(projectRoot: string): Q.Promise<boolean> { |
| 32 | if (!projectRoot || !fs.existsSync(path.join(projectRoot, "package.json"))) { |
| 33 | return Q<boolean>(false); |
| 34 | } |
| 35 | return new Package(projectRoot).parsePackageInformation().then((packageInfo: IPackageInformation) => { |
| 36 | if (packageInfo.dependencies && packageInfo.dependencies[ACConstants.CodePushNpmPackageName]) { |
| 37 | return Q<boolean>(true); |
| 38 | } else { |
| 39 | return Q<boolean>(false); |
| 40 | } |
| 41 | }); |
| 42 | } |
| 43 | |
| 44 | public static toDefaultApp(app: string): DefaultApp | null { |
| 45 | const matches = app.match(this.validApp); |
| 46 | if (matches !== null) { |
| 47 | return { |
| 48 | ownerName: matches[1], |
| 49 | appName: matches[2], |
| 50 | identifier: `${matches[1]}/${matches[2]}`, |
| 51 | }; |
| 52 | } |
| 53 | return null; |
| 54 | } |
| 55 | } |
| 56 | |