microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
bb685befdbe7e88c8b5573661cf3dfa5d48a4001

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

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
5const opener = require("opener");
6// tslint:disable-next-line:no-var-requires
7const open = require("open");
8import * as Q from "q";
9import * as fs from "fs";
10import * as path from "path";
11import { Package, IPackageInformation } from "../../common/node/package";
12import { ACConstants } from "./appCenterConstants";
13import { DefaultApp } from "./command/commandParams";
14
15export 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