microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/extension/appcenter/helpers/utils.ts
77lines · 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, AppCenterOS, CurrentAppDeployments } 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 formatDeploymentNameForStatusBar(deployment: CurrentAppDeployments): string { |
| 45 | return deployment.currentDeploymentName; |
| 46 | } |
| 47 | |
| 48 | public static formatAppName(app: DefaultApp): string | null { |
| 49 | if (app) { |
| 50 | return `${app.appName} (${app.os})`; |
| 51 | } |
| 52 | return null; |
| 53 | } |
| 54 | |
| 55 | public static toDefaultApp(app: string, |
| 56 | appOS: AppCenterOS, |
| 57 | appDeployment: CurrentAppDeployments | null, |
| 58 | targetBinaryVersion: string, |
| 59 | isMandatory: boolean): DefaultApp | null { |
| 60 | const matches = app.match(this.validApp); |
| 61 | if (matches !== null) { |
| 62 | return { |
| 63 | ownerName: matches[1], |
| 64 | appName: matches[2], |
| 65 | identifier: `${matches[1]}/${matches[2]}`, |
| 66 | os: appOS, |
| 67 | targetBinaryVersion: targetBinaryVersion, |
| 68 | isMandatory: isMandatory, |
| 69 | currentAppDeployments: appDeployment ? appDeployment : { |
| 70 | codePushDeployments: new Array(), |
| 71 | currentDeploymentName: "", |
| 72 | }, |
| 73 | }; |
| 74 | } |
| 75 | return null; |
| 76 | } |
| 77 | } |
| 78 | |