microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.0.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/common/extensionHelper.ts

43lines · 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
16export function findFileInFolderHierarchy(dir: string, filename: string): string | null {
17let parentPath: string;
18let projectRoot: string = dir;
19let atFsRoot: boolean = false;
20
21while (!fs.existsSync(path.join(projectRoot, filename))) {
22// Navigate up one level until either config.xml is found
23parentPath = path.resolve(projectRoot, "..");
24if (parentPath !== projectRoot) {
25projectRoot = parentPath;
26} else {
27// we have reached the filesystem root
28atFsRoot = true;
29break;
30}
31}
32
33if (atFsRoot) {
34// We reached the fs root
35return null;
36}
37
38return path.join(projectRoot, filename);
549baae2RedMickey6 years ago39}
f872f4d5RedMickey6 years ago40
41export function generateRandomPortNumber() {
42return Math.round(Math.random() * 40000 + 3000);
43}