microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
efd8fbff90ccf6d8b6743b251723b1ee27e9a2bb

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/utils/node/package.ts

40lines · 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
4import {Node} from "../node/node";
5import * as pathModule from "path";
6
7export interface IPackageInformation {
8 name: string;
9 dependencies: { [name: string]: string };
10}
11
12export class Package {
13 private _path: string;
14 private INFORMATION_PACKAGE_FILENAME = "package.json";
15
16 constructor(path: string) {
17 this._path = path;
18 }
19
20 private informationJsonFilePath(): string {
21 return pathModule.resolve(this._path, this.INFORMATION_PACKAGE_FILENAME);
22 }
23
24 public parsePackageInformation(): Q.Promise<IPackageInformation> {
25 return new Node.FileSystem().readFile(this.informationJsonFilePath(), "utf8")
26 .then(data =>
27 <IPackageInformation>JSON.parse(data));
28 }
29
30 public name(): Q.Promise<string> {
31 return this.parsePackageInformation()
32 .then(packageInformation =>
33 packageInformation.name);
34 }
35
36 public dependencies(): Q.Promise<{ [name: string]: string }> {
37 return this.parsePackageInformation()
38 .then(packageInformation => packageInformation.dependencies);
39 }
40}
41