microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
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 | |
| 4 | import {Node} from "../node/node"; |
| 5 | import * as pathModule from "path"; |
| 6 | |
| 7 | export interface IPackageInformation { |
| 8 | name: string; |
| 9 | dependencies: { [name: string]: string }; |
| 10 | } |
| 11 | |
| 12 | export 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 | |