microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.1.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/extensionHelper.ts

52lines · modeblame

549baae2RedMickey6 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as path from "path";
5import * as fs from "fs";
6
7export function getExtensionVersion() {
2d8af448Yuri Skorokhodov6 years ago8const packageJsonPath = findFileInFolderHierarchy(__dirname, "package.json");
9if (packageJsonPath) {
10return JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")).version;
11} else {
12return null;
13}
14}
15
9928222cYuri Skorokhodov5 years ago16export function getExtensionName(): string | null {
17const packageJsonPath = findFileInFolderHierarchy(__dirname, "package.json");
18if (packageJsonPath) {
19return JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")).name;
20} else {
21return null;
22}
23}
24
2d8af448Yuri Skorokhodov6 years ago25export function findFileInFolderHierarchy(dir: string, filename: string): string | null {
26let parentPath: string;
27let projectRoot: string = dir;
28let atFsRoot: boolean = false;
29
30while (!fs.existsSync(path.join(projectRoot, filename))) {
31// Navigate up one level until either config.xml is found
32parentPath = path.resolve(projectRoot, "..");
33if (parentPath !== projectRoot) {
34projectRoot = parentPath;
35} else {
36// we have reached the filesystem root
37atFsRoot = true;
38break;
39}
40}
41
42if (atFsRoot) {
43// We reached the fs root
44return null;
45}
46
47return path.join(projectRoot, filename);
549baae2RedMickey6 years ago48}
f872f4d5RedMickey6 years ago49
50export function generateRandomPortNumber() {
51return Math.round(Math.random() * 40000 + 3000);
52}