microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/utils/node/package.ts
37lines · 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 | } |
| 10 | |
| 11 | export class Package { |
| 12 | private _path: string; |
| 13 | private INFORMATION_PACKAGE_FILENAME = "package.json"; |
| 14 | |
| 15 | constructor(path: string) { |
| 16 | this._path = path; |
| 17 | } |
| 18 | |
| 19 | private informationJsonFilePath(): string { |
| 20 | return pathModule.resolve(this._path, this.INFORMATION_PACKAGE_FILENAME); |
| 21 | } |
| 22 | |
| 23 | public information(): Q.Promise<IPackageInformation> { |
| 24 | return new Node.FileSystem().readFile(this.informationJsonFilePath(), "utf8") |
| 25 | .then(data => |
| 26 | <IPackageInformation>JSON.parse(data)); |
| 27 | } |
| 28 | |
| 29 | public name(): Q.Promise<string> { |
| 30 | return this.information().then(information => |
| 31 | <string>information.name); |
| 32 | } |
| 33 | |
| 34 | public path() { |
| 35 | return this._path; |
| 36 | } |
| 37 | } |